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 {
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 _demonstrateApplyLayerFilter();
37 _demonstrateDebugFlags();
38 _demonstrateZoomProperties();
39 }
40
44 void _demonstrateDebugFlags() {
45 print("--- Debug flags ---");
46
47 // [dart_DebugFlag_enum]
48 final allFlags = [
49 DebugFlag.NONE,
50 DebugFlag.INFOS,
51 DebugFlag.STATS,
52 DebugFlag.LABELS,
53 DebugFlag.DRAW_ALL_LABELS,
54 DebugFlag.SELECTION_BUFFER,
55 ];
56 print("Debug flag enum values: ${allFlags.length}");
57 // [dart_DebugFlag_enum]
58
59 // [dart_LocationWindow_setDebugFlag]
60 LocationWindow.setDebugFlag(DebugFlag.INFOS, true);
61 LocationWindow.setDebugFlag(DebugFlag.STATS, false);
62 print("Updated debug flags on LocationWindow");
63 // [dart_LocationWindow_setDebugFlag]
64
65 // [dart_LocationWindow_getDebugFlag]
66 bool infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS);
67 print("Debug flag INFOS enabled: $infosOn");
68 // [dart_LocationWindow_getDebugFlag]
69 }
70
74 void _demonstrateSetSublocationId() {
75 print("--- setSublocationId Method ---");
76
77 if (_locationWindow == null) {
78 print("LocationWindow not available yet");
79 return;
80 }
81
82 // [dart_LocationWindow_setSublocationId]
83 // Set sublocation ID to switch between floors
84 _locationWindow!.setSublocationId(1);
85 print("Set sublocation ID to 1 (first floor)");
86 // [dart_LocationWindow_setSublocationId]
87
88 // [dart_LocationWindow_setSublocationId_2]
89 // Set sublocation ID to another floor
90 _locationWindow!.setSublocationId(2);
91 print("Set sublocation ID to 2 (second floor)");
92 // [dart_LocationWindow_setSublocationId_2]
93
94 // [dart_LocationWindow_setSublocationId_3]
95 // Set sublocation ID to ground floor
96 _locationWindow!.setSublocationId(0);
97 print("Set sublocation ID to 0 (ground floor)");
98 // [dart_LocationWindow_setSublocationId_3]
99
100 // Test with different sublocation IDs
101 List<int> sublocationIds = [1, 2, 3, 0, 5];
102 for (int id in sublocationIds) {
103 _locationWindow!.setSublocationId(id);
104 print("Switched to sublocation ID: $id");
105 }
106 }
107
111 void _demonstrateSublocationQueries() {
112 print("--- getSublocationId & getEnclosingCamera ---");
113
114 if (_locationWindow == null) {
115 print("LocationWindow not available yet");
116 return;
117 }
118
119 // [dart_LocationWindow_getSublocationId]
120 int? currentId = _locationWindow!.getSublocationId();
121 if (currentId != null) {
122 print("Current sublocation id: $currentId");
123 } else {
124 print("Current sublocation id is not set");
125 }
126 // [dart_LocationWindow_getSublocationId]
127
128 // [dart_LocationWindow_getEnclosingCamera]
129 BoundingBox boundingBox = BoundingBox(Point(0.0, 0.0), Point(20.0, 30.0));
130 Camera camera = _locationWindow!.getEnclosingCamera(boundingBox);
131 print("Camera that fits bounding box: $camera");
132 // [dart_LocationWindow_getEnclosingCamera]
133 }
134
138 void _demonstrateSublocationChangeListener() {
139 print("--- Sublocation Change Listener ---");
140
141 if (_locationWindow == null) {
142 print("LocationWindow not available yet");
143 return;
144 }
145
146 DemoSublocationChangeListener listener = DemoSublocationChangeListener();
147
148 // [dart_LocationWindow_addSublocationChangeListener]
149 _locationWindow!.addSublocationChangeListener(listener);
150 print("Added sublocation change listener");
151 // [dart_LocationWindow_addSublocationChangeListener]
152
153 _locationWindow!.setSublocationId(1);
154 _locationWindow!.setSublocationId(2);
155
156 // [dart_LocationWindow_removeSublocationChangeListener]
157 _locationWindow!.removeSublocationChangeListener(listener);
158 print("Removed sublocation change listener");
159 // [dart_LocationWindow_removeSublocationChangeListener]
160 }
161
165 void _demonstrateUserLocationView() {
166 print("--- UserLocationView ---");
167
168 if (_userLocationView == null) {
169 print("UserLocationView not available yet");
170 return;
171 }
172
173 // [dart_UserLocationView_getArrow]
174 IconMapObject arrow = _userLocationView!.arrow;
175 print("Arrow icon object: $arrow");
176 // [dart_UserLocationView_getArrow]
177
178 // [dart_UserLocationView_getAccuracyCircle]
179 CircleMapObject accuracyCircle = _userLocationView!.accuracyCircle;
180 print("Accuracy circle object: $accuracyCircle");
181 // [dart_UserLocationView_getAccuracyCircle]
182 }
183
187 void _demonstrateUserLocationLayer() {
188 print("--- UserLocationLayer ---");
189
190 if (_userLocationLayer == null) {
191 print("UserLocationLayer not available yet");
192 return;
193 }
194
195 // [dart_UserLocationLayer_setVisible]
196 _userLocationLayer!.setVisible(true);
197 print("User location layer set visible");
198 // [dart_UserLocationLayer_setVisible]
199
200 // [dart_UserLocationLayer_isVisible]
201 bool visible = _userLocationLayer!.isVisible();
202 print("User location layer is visible: $visible");
203 // [dart_UserLocationLayer_isVisible]
204
205 // [dart_UserLocationLayer_setAnchor]
206 ScreenPoint anchor = ScreenPoint(100.0, 200.0);
207 _userLocationLayer!.setAnchor(anchor);
208 print("Set user location anchor to: (${anchor.x}, ${anchor.y})");
209 // [dart_UserLocationLayer_setAnchor]
210
211 // [dart_UserLocationLayer_anchorEnabled]
212 bool anchorEnabled = _userLocationLayer!.anchorEnabled();
213 print("Anchor enabled: $anchorEnabled");
214 // [dart_UserLocationLayer_anchorEnabled]
215
216 // [dart_UserLocationLayer_resetAnchor]
217 _userLocationLayer!.resetAnchor();
218 print("Anchor reset to default");
219 // [dart_UserLocationLayer_resetAnchor]
220 }
221
225 void _demonstrateCoordinateConversion() {
226 print("--- Coordinate Conversion Methods ---");
227
228 if (_locationWindow == null) {
229 print("LocationWindow not available yet");
230 return;
231 }
232
233 // [dart_LocationWindow_screenPositionToMeters]
234 // Convert screen position to meters
235 Point screenPoint = Point(100.0, 200.0);
236 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
237 print("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})");
238 // [dart_LocationWindow_screenPositionToMeters]
239
240 // [dart_LocationWindow_screenPositionToMeters_2]
241 // Convert another screen position to meters
242 Point screenPoint2 = Point(500.0, 300.0);
243 Point metersPoint2 = _locationWindow!.screenPositionToMeters(screenPoint2);
244 print("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})");
245 // [dart_LocationWindow_screenPositionToMeters_2]
246
247 // [dart_LocationWindow_metersToScreenPosition]
248 // Convert meters to screen position with clipping
249 Point metersPoint3 = Point(50.0, 75.0);
250 Point screenPoint3 = _locationWindow!.metersToScreenPosition(metersPoint3, true);
251 print("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})");
252 // [dart_LocationWindow_metersToScreenPosition]
253
254 // [dart_LocationWindow_metersToScreenPosition_2]
255 // Convert meters to screen position without clipping
256 Point metersPoint4 = Point(150.0, 200.0);
257 Point screenPoint4 = _locationWindow!.metersToScreenPosition(metersPoint4, false);
258 print("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})");
259 // [dart_LocationWindow_metersToScreenPosition_2]
260
261 // Test coordinate conversion with different values
262 List<Point> testScreenPoints = [
263 Point(0.0, 0.0),
264 Point(250.0, 250.0),
265 Point(1000.0, 600.0),
266 ];
267
268 for (int i = 0; i < testScreenPoints.length; i++) {
269 Point screenPoint = testScreenPoints[i];
270 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
271 Point backToScreen = _locationWindow!.metersToScreenPosition(metersPoint, false);
272 print("Test $i: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})");
273 }
274 }
275
279 void _demonstrateMapFeatureSelection() {
280 print("--- Map Feature Selection Methods ---");
281
282 if (_locationWindow == null) {
283 print("LocationWindow not available yet");
284 return;
285 }
286
287 // [dart_LocationWindow_selectMapFeature]
288 // Select map feature by ID
289 String featureId = "room_101";
290 bool selected = _locationWindow!.selectMapFeature(featureId);
291 print("Selected map feature $featureId: $selected");
292 // [dart_LocationWindow_selectMapFeature]
293
294 // [dart_LocationWindow_selectMapFeature_2]
295 // Select another map feature
296 String featureId2 = "office_205";
297 bool selected2 = _locationWindow!.selectMapFeature(featureId2);
298 print("Selected map feature $featureId2: $selected2");
299 // [dart_LocationWindow_selectMapFeature_2]
300
301 // [dart_LocationWindow_getSelectedMapFeatures]
302 // Get list of selected map features
303 List<String> selectedFeatures = _locationWindow!.selectedMapFeatures;
304 print("Currently selected map features: ${selectedFeatures.length} features");
305 for (String feature in selectedFeatures) {
306 print(" - $feature");
307 }
308 // [dart_LocationWindow_getSelectedMapFeatures]
309
310 // [dart_LocationWindow_deselectMapFeature]
311 // Deselect specific map feature
312 bool deselected = _locationWindow!.deselectMapFeature(featureId);
313 print("Deselected map feature $featureId: $deselected");
314 // [dart_LocationWindow_deselectMapFeature]
315
316 // [dart_LocationWindow_deselectMapFeature_2]
317 // Deselect another map feature
318 bool deselected2 = _locationWindow!.deselectMapFeature(featureId2);
319 print("Deselected map feature $featureId2: $deselected2");
320 // [dart_LocationWindow_deselectMapFeature_2]
321
322 // [dart_LocationWindow_deselectAllMapFeatures]
323 // Deselect all map features
324 _locationWindow!.deselectAllMapFeatures();
325 print("Deselected all map features");
326 // [dart_LocationWindow_deselectAllMapFeatures]
327
328 // [dart_LocationWindow_getSelectedMapFeatures_2]
329 // Verify all features are deselected
330 List<String> remainingFeatures = _locationWindow!.selectedMapFeatures;
331 print("Remaining selected features after deselect all: ${remainingFeatures.length} features");
332 // [dart_LocationWindow_getSelectedMapFeatures_2]
333
334 // Test multiple feature selection and deselection
335 List<String> testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"];
336
337 // Select multiple features
338 for (String featureId in testFeatureIds) {
339 bool success = _locationWindow!.selectMapFeature(featureId);
340 print("Selected feature $featureId: $success");
341 }
342
343 // Check selected features
344 List<String> allSelected = _locationWindow!.selectedMapFeatures;
345 print("All selected features: ${allSelected.length} features");
346
347 // Deselect all at once
348 _locationWindow!.deselectAllMapFeatures();
349 print("Deselected all features at once");
350 }
351
355 void _demonstrateApplyLayerFilter() {
356 print("--- applyLayerFilter Method ---");
357
358 if (_locationWindow == null) {
359 print("LocationWindow not available yet");
360 return;
361 }
362
363 // [dart_MapFilterCondition_constructor]
364 // Create filter condition: show only venues with category "Toilet" or "Cafe"
365 final condition = MapFilterCondition(property: "category", values: ["Toilet", "Cafe"]);
366 // [dart_MapFilterCondition_constructor]
367
368 // [dart_LocationWindow_applyLayerFilter]
369 // Apply filter to venues layer
370 final conditions = [MapFilterCondition(property: "category", values: ["Toilet", "Cafe"])];
371 _locationWindow!.applyLayerFilter("venues", conditions);
372 print("Applied layer filter: show venues with category Toilet or Cafe");
373 // [dart_LocationWindow_applyLayerFilter]
374
375 // Reset filter (show all venues)
376 _locationWindow!.applyLayerFilter("venues", []);
377 print("Reset layer filter: show all venues");
378 }
379
383 void _demonstrateZoomProperties() {
384 print("--- Zoom Properties ---");
385
386 if (_locationWindow == null) {
387 print("LocationWindow not available yet");
388 return;
389 }
390
391 // [dart_LocationWindow_getZoomFactor]
392 // Get current zoom factor
393 double currentZoom = _locationWindow!.zoomFactor;
394 print("Current zoom factor: $currentZoom");
395 // [dart_LocationWindow_getZoomFactor]
396
397 // [dart_LocationWindow_setZoomFactor]
398 // Set zoom factor
399 _locationWindow!.zoomFactor = 150.0;
400 print("Set zoom factor to 150.0");
401 // [dart_LocationWindow_setZoomFactor]
402
403 // [dart_LocationWindow_getMinZoomFactor]
404 // Get minimum zoom factor
405 double minZoomFactor = _locationWindow!.minZoomFactor;
406 print("Minimum zoom factor: $minZoomFactor");
407 // [dart_LocationWindow_getMinZoomFactor]
408
409 // [dart_LocationWindow_setMinZoomFactor]
410 // Set minimum zoom factor
411 _locationWindow!.minZoomFactor = 50.0;
412 print("Set minimum zoom factor to 50.0");
413 // [dart_LocationWindow_setMinZoomFactor]
414
415 // [dart_LocationWindow_getMaxZoomFactor]
416 // Get maximum zoom factor
417 double maxZoomFactor = _locationWindow!.maxZoomFactor;
418 print("Maximum zoom factor: $maxZoomFactor");
419 // [dart_LocationWindow_getMaxZoomFactor]
420
421 // [dart_LocationWindow_setMaxZoomFactor]
422 // Set maximum zoom factor
423 _locationWindow!.maxZoomFactor = 300.0;
424 print("Set maximum zoom factor to 300.0");
425 // [dart_LocationWindow_setMaxZoomFactor]
426
427 // Test zoom factor changes
428 List<double> testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0];
429 for (double zoom in testZoomFactors) {
430 _locationWindow!.zoomFactor = zoom;
431 print("Changed zoom factor to: ${_locationWindow!.zoomFactor}");
432 }
433
434 // Test zoom limits
435 print("Testing zoom limits...");
436 _locationWindow!.zoomFactor = _locationWindow!.minZoomFactor;
437 print("Set to minimum zoom: ${_locationWindow!.zoomFactor}");
438
439 _locationWindow!.zoomFactor = _locationWindow!.maxZoomFactor;
440 print("Set to maximum zoom: ${_locationWindow!.zoomFactor}");
441
442 // Reset to default
443 _locationWindow!.zoomFactor = 100.0;
444 print("Reset zoom factor to default: ${_locationWindow!.zoomFactor}");
445 }
446
450 Future<void> runExample() async {
451 print("=== LocationWindowCommon Example ===");
452
453 // Simulate LocationWindow initialization
454 await Future.delayed(Duration(milliseconds: 500));
455
456 // TODO: User will implement LocationWindow initialization here
457 // _locationWindow = await getLocationWindow();
458
459 // Run demonstrations
460 _demonstrateLocationWindowCommonMethods();
461
462 print("=== Example completed ===");
463 }
464}
465
469Future<void> main() async {
471 await example.runExample();
472}
473
474class DemoSublocationChangeListener implements SublocationChangeListener {
475 // [dart_SublocationChangeListener_onActiveSublocationChanged]
476 @override
477 void onActiveSublocationChanged(int sublocationId) {
478 print("Active sublocation changed to: $sublocationId");
479 }
480 // [dart_SublocationChangeListener_onActiveSublocationChanged]
481}