Loading...
Searching...
No Matches
location_window_common_example.dart
Go to the documentation of this file.
1import 'dart:async';
2import 'dart:io';
3import 'dart:math';
4import 'package:flutter/material.dart';
5import 'package:navigine_sdk/navigine_sdk.dart';
6
13class LocationWindowCommonExample {
14 LocationWindow? _locationWindow;
15 LocationView? _locationView;
16 UserLocationView? _userLocationView;
17 UserLocationLayer? _userLocationLayer;
18
19 LocationWindowCommonExample() {
20 _demonstrateLocationWindowCommonMethods();
21 }
22
26 void _demonstrateLocationWindowCommonMethods() {
27 print("=== LocationWindowCommon Methods ===");
28
29 _demonstrateSetSublocationId();
30 _demonstrateSublocationQueries();
31 _demonstrateSublocationChangeListener();
32 _demonstrateUserLocationView();
33 _demonstrateUserLocationLayer();
34 _demonstrateCoordinateConversion();
35 _demonstrateMapFeatureSelection();
36 _demonstrateZoomProperties();
37 }
38
42 void _demonstrateSetSublocationId() {
43 print("--- setSublocationId Method ---");
44
45 if (_locationWindow == null) {
46 print("LocationWindow not available yet");
47 return;
48 }
49
50 // [dart_LocationWindow_setSublocationId]
51 // Set sublocation ID to switch between floors
52 _locationWindow!.setSublocationId(1);
53 print("Set sublocation ID to 1 (first floor)");
54 // [dart_LocationWindow_setSublocationId]
55
56 // [dart_LocationWindow_setSublocationId_2]
57 // Set sublocation ID to another floor
58 _locationWindow!.setSublocationId(2);
59 print("Set sublocation ID to 2 (second floor)");
60 // [dart_LocationWindow_setSublocationId_2]
61
62 // [dart_LocationWindow_setSublocationId_3]
63 // Set sublocation ID to ground floor
64 _locationWindow!.setSublocationId(0);
65 print("Set sublocation ID to 0 (ground floor)");
66 // [dart_LocationWindow_setSublocationId_3]
67
68 // Test with different sublocation IDs
69 List<int> sublocationIds = [1, 2, 3, 0, 5];
70 for (int id in sublocationIds) {
71 _locationWindow!.setSublocationId(id);
72 print("Switched to sublocation ID: $id");
73 }
74 }
75
79 void _demonstrateSublocationQueries() {
80 print("--- getSublocationId & getEnclosingCamera ---");
81
82 if (_locationWindow == null) {
83 print("LocationWindow not available yet");
84 return;
85 }
86
87 // [dart_LocationWindow_getSublocationId]
88 int? currentId = _locationWindow!.getSublocationId();
89 if (currentId != null) {
90 print("Current sublocation id: $currentId");
91 } else {
92 print("Current sublocation id is not set");
93 }
94 // [dart_LocationWindow_getSublocationId]
95
96 // [dart_LocationWindow_getEnclosingCamera]
97 BoundingBox boundingBox = BoundingBox(Point(0.0, 0.0), Point(20.0, 30.0));
98 Camera camera = _locationWindow!.getEnclosingCamera(boundingBox);
99 print("Camera that fits bounding box: $camera");
100 // [dart_LocationWindow_getEnclosingCamera]
101 }
102
106 void _demonstrateSublocationChangeListener() {
107 print("--- Sublocation Change Listener ---");
108
109 if (_locationWindow == null) {
110 print("LocationWindow not available yet");
111 return;
112 }
113
114 DemoSublocationChangeListener listener = DemoSublocationChangeListener();
115
116 // [dart_LocationWindow_addSublocationChangeListener]
117 _locationWindow!.addSublocationChangeListener(listener);
118 print("Added sublocation change listener");
119 // [dart_LocationWindow_addSublocationChangeListener]
120
121 _locationWindow!.setSublocationId(1);
122 _locationWindow!.setSublocationId(2);
123
124 // [dart_LocationWindow_removeSublocationChangeListener]
125 _locationWindow!.removeSublocationChangeListener(listener);
126 print("Removed sublocation change listener");
127 // [dart_LocationWindow_removeSublocationChangeListener]
128 }
129
133 void _demonstrateUserLocationView() {
134 print("--- UserLocationView ---");
135
136 if (_userLocationView == null) {
137 print("UserLocationView not available yet");
138 return;
139 }
140
141 // [dart_UserLocationView_getArrow]
142 IconMapObject arrow = _userLocationView!.arrow;
143 print("Arrow icon object: $arrow");
144 // [dart_UserLocationView_getArrow]
145
146 // [dart_UserLocationView_getAccuracyCircle]
147 CircleMapObject accuracyCircle = _userLocationView!.accuracyCircle;
148 print("Accuracy circle object: $accuracyCircle");
149 // [dart_UserLocationView_getAccuracyCircle]
150 }
151
155 void _demonstrateUserLocationLayer() {
156 print("--- UserLocationLayer ---");
157
158 if (_userLocationLayer == null) {
159 print("UserLocationLayer not available yet");
160 return;
161 }
162
163 // [dart_UserLocationLayer_setVisible]
164 _userLocationLayer!.setVisible(true);
165 print("User location layer set visible");
166 // [dart_UserLocationLayer_setVisible]
167
168 // [dart_UserLocationLayer_isVisible]
169 bool visible = _userLocationLayer!.isVisible();
170 print("User location layer is visible: $visible");
171 // [dart_UserLocationLayer_isVisible]
172
173 // [dart_UserLocationLayer_setAnchor]
174 ScreenPoint anchor = ScreenPoint(100.0, 200.0);
175 _userLocationLayer!.setAnchor(anchor);
176 print("Set user location anchor to: (${anchor.x}, ${anchor.y})");
177 // [dart_UserLocationLayer_setAnchor]
178
179 // [dart_UserLocationLayer_anchorEnabled]
180 bool anchorEnabled = _userLocationLayer!.anchorEnabled();
181 print("Anchor enabled: $anchorEnabled");
182 // [dart_UserLocationLayer_anchorEnabled]
183
184 // [dart_UserLocationLayer_resetAnchor]
185 _userLocationLayer!.resetAnchor();
186 print("Anchor reset to default");
187 // [dart_UserLocationLayer_resetAnchor]
188 }
189
193 void _demonstrateCoordinateConversion() {
194 print("--- Coordinate Conversion Methods ---");
195
196 if (_locationWindow == null) {
197 print("LocationWindow not available yet");
198 return;
199 }
200
201 // [dart_LocationWindow_screenPositionToMeters]
202 // Convert screen position to meters
203 Point screenPoint = Point(100.0, 200.0);
204 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
205 print("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})");
206 // [dart_LocationWindow_screenPositionToMeters]
207
208 // [dart_LocationWindow_screenPositionToMeters_2]
209 // Convert another screen position to meters
210 Point screenPoint2 = Point(500.0, 300.0);
211 Point metersPoint2 = _locationWindow!.screenPositionToMeters(screenPoint2);
212 print("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})");
213 // [dart_LocationWindow_screenPositionToMeters_2]
214
215 // [dart_LocationWindow_metersToScreenPosition]
216 // Convert meters to screen position with clipping
217 Point metersPoint3 = Point(50.0, 75.0);
218 Point screenPoint3 = _locationWindow!.metersToScreenPosition(metersPoint3, true);
219 print("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})");
220 // [dart_LocationWindow_metersToScreenPosition]
221
222 // [dart_LocationWindow_metersToScreenPosition_2]
223 // Convert meters to screen position without clipping
224 Point metersPoint4 = Point(150.0, 200.0);
225 Point screenPoint4 = _locationWindow!.metersToScreenPosition(metersPoint4, false);
226 print("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})");
227 // [dart_LocationWindow_metersToScreenPosition_2]
228
229 // Test coordinate conversion with different values
230 List<Point> testScreenPoints = [
231 Point(0.0, 0.0),
232 Point(250.0, 250.0),
233 Point(1000.0, 600.0),
234 ];
235
236 for (int i = 0; i < testScreenPoints.length; i++) {
237 Point screenPoint = testScreenPoints[i];
238 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
239 Point backToScreen = _locationWindow!.metersToScreenPosition(metersPoint, false);
240 print("Test $i: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})");
241 }
242 }
243
247 void _demonstrateMapFeatureSelection() {
248 print("--- Map Feature Selection Methods ---");
249
250 if (_locationWindow == null) {
251 print("LocationWindow not available yet");
252 return;
253 }
254
255 // [dart_LocationWindow_selectMapFeature]
256 // Select map feature by ID
257 String featureId = "room_101";
258 bool selected = _locationWindow!.selectMapFeature(featureId);
259 print("Selected map feature $featureId: $selected");
260 // [dart_LocationWindow_selectMapFeature]
261
262 // [dart_LocationWindow_selectMapFeature_2]
263 // Select another map feature
264 String featureId2 = "office_205";
265 bool selected2 = _locationWindow!.selectMapFeature(featureId2);
266 print("Selected map feature $featureId2: $selected2");
267 // [dart_LocationWindow_selectMapFeature_2]
268
269 // [dart_LocationWindow_getSelectedMapFeatures]
270 // Get list of selected map features
271 List<String> selectedFeatures = _locationWindow!.selectedMapFeatures;
272 print("Currently selected map features: ${selectedFeatures.length} features");
273 for (String feature in selectedFeatures) {
274 print(" - $feature");
275 }
276 // [dart_LocationWindow_getSelectedMapFeatures]
277
278 // [dart_LocationWindow_deselectMapFeature]
279 // Deselect specific map feature
280 bool deselected = _locationWindow!.deselectMapFeature(featureId);
281 print("Deselected map feature $featureId: $deselected");
282 // [dart_LocationWindow_deselectMapFeature]
283
284 // [dart_LocationWindow_deselectMapFeature_2]
285 // Deselect another map feature
286 bool deselected2 = _locationWindow!.deselectMapFeature(featureId2);
287 print("Deselected map feature $featureId2: $deselected2");
288 // [dart_LocationWindow_deselectMapFeature_2]
289
290 // [dart_LocationWindow_deselectAllMapFeatures]
291 // Deselect all map features
292 _locationWindow!.deselectAllMapFeatures();
293 print("Deselected all map features");
294 // [dart_LocationWindow_deselectAllMapFeatures]
295
296 // [dart_LocationWindow_getSelectedMapFeatures_2]
297 // Verify all features are deselected
298 List<String> remainingFeatures = _locationWindow!.selectedMapFeatures;
299 print("Remaining selected features after deselect all: ${remainingFeatures.length} features");
300 // [dart_LocationWindow_getSelectedMapFeatures_2]
301
302 // Test multiple feature selection and deselection
303 List<String> testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"];
304
305 // Select multiple features
306 for (String featureId in testFeatureIds) {
307 bool success = _locationWindow!.selectMapFeature(featureId);
308 print("Selected feature $featureId: $success");
309 }
310
311 // Check selected features
312 List<String> allSelected = _locationWindow!.selectedMapFeatures;
313 print("All selected features: ${allSelected.length} features");
314
315 // Deselect all at once
316 _locationWindow!.deselectAllMapFeatures();
317 print("Deselected all features at once");
318 }
319
323 void _demonstrateZoomProperties() {
324 print("--- Zoom Properties ---");
325
326 if (_locationWindow == null) {
327 print("LocationWindow not available yet");
328 return;
329 }
330
331 // [dart_LocationWindow_getZoomFactor]
332 // Get current zoom factor
333 double currentZoom = _locationWindow!.zoomFactor;
334 print("Current zoom factor: $currentZoom");
335 // [dart_LocationWindow_getZoomFactor]
336
337 // [dart_LocationWindow_setZoomFactor]
338 // Set zoom factor
339 _locationWindow!.zoomFactor = 150.0;
340 print("Set zoom factor to 150.0");
341 // [dart_LocationWindow_setZoomFactor]
342
343 // [dart_LocationWindow_getMinZoomFactor]
344 // Get minimum zoom factor
345 double minZoomFactor = _locationWindow!.minZoomFactor;
346 print("Minimum zoom factor: $minZoomFactor");
347 // [dart_LocationWindow_getMinZoomFactor]
348
349 // [dart_LocationWindow_setMinZoomFactor]
350 // Set minimum zoom factor
351 _locationWindow!.minZoomFactor = 50.0;
352 print("Set minimum zoom factor to 50.0");
353 // [dart_LocationWindow_setMinZoomFactor]
354
355 // [dart_LocationWindow_getMaxZoomFactor]
356 // Get maximum zoom factor
357 double maxZoomFactor = _locationWindow!.maxZoomFactor;
358 print("Maximum zoom factor: $maxZoomFactor");
359 // [dart_LocationWindow_getMaxZoomFactor]
360
361 // [dart_LocationWindow_setMaxZoomFactor]
362 // Set maximum zoom factor
363 _locationWindow!.maxZoomFactor = 300.0;
364 print("Set maximum zoom factor to 300.0");
365 // [dart_LocationWindow_setMaxZoomFactor]
366
367 // Test zoom factor changes
368 List<double> testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0];
369 for (double zoom in testZoomFactors) {
370 _locationWindow!.zoomFactor = zoom;
371 print("Changed zoom factor to: ${_locationWindow!.zoomFactor}");
372 }
373
374 // Test zoom limits
375 print("Testing zoom limits...");
376 _locationWindow!.zoomFactor = _locationWindow!.minZoomFactor;
377 print("Set to minimum zoom: ${_locationWindow!.zoomFactor}");
378
379 _locationWindow!.zoomFactor = _locationWindow!.maxZoomFactor;
380 print("Set to maximum zoom: ${_locationWindow!.zoomFactor}");
381
382 // Reset to default
383 _locationWindow!.zoomFactor = 100.0;
384 print("Reset zoom factor to default: ${_locationWindow!.zoomFactor}");
385 }
386
390 Future<void> runExample() async {
391 print("=== LocationWindowCommon Example ===");
392
393 // Simulate LocationWindow initialization
394 await Future.delayed(Duration(milliseconds: 500));
395
396 // TODO: User will implement LocationWindow initialization here
397 // _locationWindow = await getLocationWindow();
398
399 // Run demonstrations
400 _demonstrateLocationWindowCommonMethods();
401
402 print("=== Example completed ===");
403 }
404}
405
409Future<void> main() async {
411 await example.runExample();
412}
413
414class DemoSublocationChangeListener implements SublocationChangeListener {
415 // [dart_SublocationChangeListener_onActiveSublocationChanged]
416 @override
417 void onActiveSublocationChanged(int sublocationId) {
418 print("Active sublocation changed to: $sublocationId");
419 }
420 // [dart_SublocationChangeListener_onActiveSublocationChanged]
421}