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 {
17
18 LocationWindowCommonExample() {
19 _demonstrateLocationWindowCommonMethods();
20 }
21
25 void _demonstrateLocationWindowCommonMethods() {
26 print("=== LocationWindowCommon Methods ===");
27
28 _demonstrateSetSublocationId();
29 _demonstrateOperatingMode();
30 _demonstrateSublocationQueries();
31 _demonstrateSublocationChangeListener();
32 _demonstrateUserLocationLayer();
33 _demonstrateCoordinateConversion();
34 _demonstrateMapFeatureSelection();
35 _demonstrateApplyLayerFilter();
36 _demonstrateDebugFlags();
37 _demonstrateZoomProperties();
38 }
39
43 void _demonstrateDebugFlags() {
44 print("--- Debug flags ---");
45
46 // [dart_DebugFlag_enum]
47 final allFlags = [
48 DebugFlag.NONE,
49 DebugFlag.INFOS,
50 DebugFlag.STATS,
51 DebugFlag.LABELS,
52 DebugFlag.DRAW_ALL_LABELS,
53 DebugFlag.SELECTION_BUFFER,
54 ];
55 print("Debug flag enum values: ${allFlags.length}");
56 // [dart_DebugFlag_enum]
57
58 // [dart_LocationWindow_setDebugFlag]
59 LocationWindow.setDebugFlag(DebugFlag.INFOS, true);
60 LocationWindow.setDebugFlag(DebugFlag.STATS, false);
61 print("Updated debug flags on LocationWindow");
62 // [dart_LocationWindow_setDebugFlag]
63
64 // [dart_LocationWindow_getDebugFlag]
65 bool infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS);
66 print("Debug flag INFOS enabled: $infosOn");
67 // [dart_LocationWindow_getDebugFlag]
68 }
69
70
71 void _demonstrateOperatingMode() {
72 print("--- Operating Mode ---");
73
74 if (_locationWindow == null) {
75 print("LocationWindow not available yet");
76 return;
77 }
78
79 // [dart_OperatingMode_enum]
80 final modes = [
81 OperatingMode.INDOOR_ONLY,
82 OperatingMode.OUTDOOR,
83 OperatingMode.OUTDOOR_INDOOR,
84 ];
85 print("Operating modes: ${modes.length}");
86 // [dart_OperatingMode_enum]
87
88 // [dart_LocationWindow_setOperatingMode]
89 _locationWindow!.setOperatingMode(OperatingMode.OUTDOOR_INDOOR);
90 print("Set operating mode to OUTDOOR_INDOOR");
91 // [dart_LocationWindow_setOperatingMode]
92
93 // [dart_LocationWindow_getOperatingMode]
94 OperatingMode currentMode = _locationWindow!.getOperatingMode();
95 print("Current operating mode: $currentMode");
96 // [dart_LocationWindow_getOperatingMode]
97
98 // [dart_AttributionAlignment_record]
99 final alignment = AttributionAlignment(
100 AttributionHorizontalAlignment.RIGHT,
101 AttributionVerticalAlignment.BOTTOM,
102 );
103 // [dart_AttributionAlignment_record]
104
105 // [dart_LocationWindow_setAttributionAlignment]
106 _locationWindow!.setAttributionAlignment(alignment);
107 // [dart_LocationWindow_setAttributionAlignment]
108
109 // [dart_LocationWindow_getAttribution]
110 final attribution = _locationWindow!.getAttribution();
111 print("Attribution: $attribution");
112 // [dart_LocationWindow_getAttribution]
113 }
114
118 void _demonstrateSetSublocationId() {
119 print("--- setSublocationId Method ---");
120
121 if (_locationWindow == null) {
122 print("LocationWindow not available yet");
123 return;
124 }
125
126 // [dart_LocationWindow_setSublocationId]
127 // Set sublocation ID to switch between floors
128 _locationWindow!.setSublocationId(1);
129 print("Set sublocation ID to 1 (first floor)");
130 // [dart_LocationWindow_setSublocationId]
131
132 // [dart_LocationWindow_setSublocationId_2]
133 // Set sublocation ID to another floor
134 _locationWindow!.setSublocationId(2);
135 print("Set sublocation ID to 2 (second floor)");
136 // [dart_LocationWindow_setSublocationId_2]
137
138 // [dart_LocationWindow_setSublocationId_3]
139 // Set sublocation ID to ground floor
140 _locationWindow!.setSublocationId(0);
141 print("Set sublocation ID to 0 (ground floor)");
142 // [dart_LocationWindow_setSublocationId_3]
143
144 // Test with different sublocation IDs
145 List<int> sublocationIds = [1, 2, 3, 0, 5];
146 for (int id in sublocationIds) {
147 _locationWindow!.setSublocationId(id);
148 print("Switched to sublocation ID: $id");
149 }
150 }
151
155 void _demonstrateSublocationQueries() {
156 print("--- getSublocationId & getEnclosingCamera ---");
157
158 if (_locationWindow == null) {
159 print("LocationWindow not available yet");
160 return;
161 }
162
163 // [dart_LocationWindow_getSublocationId]
164 int? currentId = _locationWindow!.getSublocationId();
165 if (currentId != null) {
166 print("Current sublocation id: $currentId");
167 } else {
168 print("Current sublocation id is not set");
169 }
170 // [dart_LocationWindow_getSublocationId]
171
172 // [dart_LocationWindow_getEnclosingCamera]
173 BoundingBox boundingBox = BoundingBox(
174 GlobalPoint(55.75, 37.61), GlobalPoint(55.76, 37.63));
175 Camera camera = _locationWindow!.getEnclosingCamera(boundingBox);
176 print("Camera that fits bounding box: $camera");
177 // [dart_LocationWindow_getEnclosingCamera]
178 }
179
183 void _demonstrateSublocationChangeListener() {
184 print("--- Sublocation Change Listener ---");
185
186 if (_locationWindow == null) {
187 print("LocationWindow not available yet");
188 return;
189 }
190
191 DemoSublocationChangeListener listener = DemoSublocationChangeListener();
192
193 // [dart_LocationWindow_addSublocationChangeListener]
194 _locationWindow!.addSublocationChangeListener(listener);
195 print("Added sublocation change listener");
196 // [dart_LocationWindow_addSublocationChangeListener]
197
198 _locationWindow!.setSublocationId(1);
199 _locationWindow!.setSublocationId(2);
200
201 // [dart_LocationWindow_removeSublocationChangeListener]
202 _locationWindow!.removeSublocationChangeListener(listener);
203 print("Removed sublocation change listener");
204 // [dart_LocationWindow_removeSublocationChangeListener]
205 }
206
210 void _demonstrateUserLocationLayer() {
211 print("--- UserLocationLayer ---");
212
213 if (_userLocationLayer == null) {
214 print("UserLocationLayer not available yet");
215 return;
216 }
217
218 // [dart_UserLocationLayer_setVisible]
219 _userLocationLayer!.setVisible(true);
220 print("User location layer set visible");
221 // [dart_UserLocationLayer_setVisible]
222
223 // [dart_UserLocationLayer_isVisible]
224 bool visible = _userLocationLayer!.isVisible();
225 print("User location layer is visible: $visible");
226 // [dart_UserLocationLayer_isVisible]
227
228 // [dart_UserLocationLayer_setAnchor]
229 ScreenPoint anchor = ScreenPoint(100.0, 200.0);
230 _userLocationLayer!.setAnchor(anchor);
231 print("Set user location anchor to: (${anchor.x}, ${anchor.y})");
232 // [dart_UserLocationLayer_setAnchor]
233
234 // [dart_UserLocationLayer_anchorEnabled]
235 bool anchorEnabled = _userLocationLayer!.anchorEnabled();
236 print("Anchor enabled: $anchorEnabled");
237 // [dart_UserLocationLayer_anchorEnabled]
238
239 // [dart_UserLocationLayer_resetAnchor]
240 _userLocationLayer!.resetAnchor();
241 print("Anchor reset to default");
242 // [dart_UserLocationLayer_resetAnchor]
243 }
244
248 void _demonstrateCoordinateConversion() {
249 print("--- Coordinate Conversion Methods ---");
250
251 if (_locationWindow == null) {
252 print("LocationWindow not available yet");
253 return;
254 }
255
256 // [dart_LocationWindow_screenPositionToGlobal]
257 ScreenPoint screenPoint = ScreenPoint(100.0, 200.0);
258 GlobalPoint globalPoint = _locationWindow!.screenPositionToGlobal(screenPoint);
259 print("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to WGS84: (${globalPoint.latitude}, ${globalPoint.longitude})");
260 // [dart_LocationWindow_screenPositionToGlobal]
261
262 // [dart_LocationWindow_globalToScreenPosition]
263 GlobalPoint globalPoint2 = GlobalPoint(55.7558, 37.6176);
264 ScreenPoint screenPoint2 = _locationWindow!.globalToScreenPosition(globalPoint2, true);
265 print("WGS84 (${globalPoint2.latitude}, ${globalPoint2.longitude}) converted to screen with clipping: (${screenPoint2.x}, ${screenPoint2.y})");
266 // [dart_LocationWindow_globalToScreenPosition]
267
268 List<ScreenPoint> testScreenPoints = [
269 ScreenPoint(0.0, 0.0),
270 ScreenPoint(250.0, 250.0),
271 ScreenPoint(1000.0, 600.0),
272 ];
273
274 for (int i = 0; i < testScreenPoints.length; i++) {
275 ScreenPoint sp = testScreenPoints[i];
276 GlobalPoint gp = _locationWindow!.screenPositionToGlobal(sp);
277 ScreenPoint backToScreen = _locationWindow!.globalToScreenPosition(gp, false);
278 print("Test $i: Screen (${sp.x}, ${sp.y}) -> WGS84 (${gp.latitude}, ${gp.longitude}) -> Screen (${backToScreen.x}, ${backToScreen.y})");
279 }
280 }
281
285 void _demonstrateMapFeatureSelection() {
286 print("--- Map Feature Selection Methods ---");
287
288 if (_locationWindow == null) {
289 print("LocationWindow not available yet");
290 return;
291 }
292
293 // [dart_LocationWindow_selectMapFeature]
294 // Select map feature by ID
295 String featureId = "room_101";
296 bool selected = _locationWindow!.selectMapFeature(featureId);
297 print("Selected map feature $featureId: $selected");
298 // [dart_LocationWindow_selectMapFeature]
299
300 // [dart_LocationWindow_selectMapFeature_2]
301 // Select another map feature
302 String featureId2 = "office_205";
303 bool selected2 = _locationWindow!.selectMapFeature(featureId2);
304 print("Selected map feature $featureId2: $selected2");
305 // [dart_LocationWindow_selectMapFeature_2]
306
307 // [dart_LocationWindow_getSelectedMapFeatures]
308 // Get list of selected map features
309 List<String> selectedFeatures = _locationWindow!.selectedMapFeatures;
310 print("Currently selected map features: ${selectedFeatures.length} features");
311 for (String feature in selectedFeatures) {
312 print(" - $feature");
313 }
314 // [dart_LocationWindow_getSelectedMapFeatures]
315
316 // [dart_LocationWindow_deselectMapFeature]
317 // Deselect specific map feature
318 bool deselected = _locationWindow!.deselectMapFeature(featureId);
319 print("Deselected map feature $featureId: $deselected");
320 // [dart_LocationWindow_deselectMapFeature]
321
322 // [dart_LocationWindow_deselectMapFeature_2]
323 // Deselect another map feature
324 bool deselected2 = _locationWindow!.deselectMapFeature(featureId2);
325 print("Deselected map feature $featureId2: $deselected2");
326 // [dart_LocationWindow_deselectMapFeature_2]
327
328 // [dart_LocationWindow_deselectAllMapFeatures]
329 // Deselect all map features
330 _locationWindow!.deselectAllMapFeatures();
331 print("Deselected all map features");
332 // [dart_LocationWindow_deselectAllMapFeatures]
333
334 // [dart_LocationWindow_getSelectedMapFeatures_2]
335 // Verify all features are deselected
336 List<String> remainingFeatures = _locationWindow!.selectedMapFeatures;
337 print("Remaining selected features after deselect all: ${remainingFeatures.length} features");
338 // [dart_LocationWindow_getSelectedMapFeatures_2]
339
340 // Test multiple feature selection and deselection
341 List<String> testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"];
342
343 // Select multiple features
344 for (String featureId in testFeatureIds) {
345 bool success = _locationWindow!.selectMapFeature(featureId);
346 print("Selected feature $featureId: $success");
347 }
348
349 // Check selected features
350 List<String> allSelected = _locationWindow!.selectedMapFeatures;
351 print("All selected features: ${allSelected.length} features");
352
353 // Deselect all at once
354 _locationWindow!.deselectAllMapFeatures();
355 print("Deselected all features at once");
356 }
357
361 void _demonstrateApplyLayerFilter() {
362 print("--- applyLayerFilter Method ---");
363
364 if (_locationWindow == null) {
365 print("LocationWindow not available yet");
366 return;
367 }
368
369 // [dart_MapFilterCondition_constructor]
370 // Create filter condition: show only venues with category "Toilet" or "Cafe"
371 final condition = MapFilterCondition(property: "category", values: ["Toilet", "Cafe"]);
372 // [dart_MapFilterCondition_constructor]
373
374 // [dart_LocationWindow_applyLayerFilter]
375 // Apply filter to venues layer
376 final conditions = [MapFilterCondition(property: "category", values: ["Toilet", "Cafe"])];
377 _locationWindow!.applyLayerFilter("venues", conditions);
378 print("Applied layer filter: show venues with category Toilet or Cafe");
379 // [dart_LocationWindow_applyLayerFilter]
380
381 // Reset filter (show all venues)
382 _locationWindow!.applyLayerFilter("venues", []);
383 print("Reset layer filter: show all venues");
384 }
385
389 void _demonstrateZoomProperties() {
390 print("--- Zoom Properties ---");
391
392 if (_locationWindow == null) {
393 print("LocationWindow not available yet");
394 return;
395 }
396
397 // [dart_LocationWindow_getZoomFactor]
398 // Get current zoom factor
399 double currentZoom = _locationWindow!.zoomFactor;
400 print("Current zoom factor: $currentZoom");
401 // [dart_LocationWindow_getZoomFactor]
402
403 // [dart_LocationWindow_setZoomFactor]
404 // Set zoom factor
405 _locationWindow!.zoomFactor = 150.0;
406 print("Set zoom factor to 150.0");
407 // [dart_LocationWindow_setZoomFactor]
408
409 // [dart_LocationWindow_getMinZoomFactor]
410 // Get minimum zoom factor
411 double minZoomFactor = _locationWindow!.minZoomFactor;
412 print("Minimum zoom factor: $minZoomFactor");
413 // [dart_LocationWindow_getMinZoomFactor]
414
415 // [dart_LocationWindow_setMinZoomFactor]
416 // Set minimum zoom factor
417 _locationWindow!.minZoomFactor = 50.0;
418 print("Set minimum zoom factor to 50.0");
419 // [dart_LocationWindow_setMinZoomFactor]
420
421 // [dart_LocationWindow_getMaxZoomFactor]
422 // Get maximum zoom factor
423 double maxZoomFactor = _locationWindow!.maxZoomFactor;
424 print("Maximum zoom factor: $maxZoomFactor");
425 // [dart_LocationWindow_getMaxZoomFactor]
426
427 // [dart_LocationWindow_setMaxZoomFactor]
428 // Set maximum zoom factor
429 _locationWindow!.maxZoomFactor = 300.0;
430 print("Set maximum zoom factor to 300.0");
431 // [dart_LocationWindow_setMaxZoomFactor]
432
433 // Test zoom factor changes
434 List<double> testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0];
435 for (double zoom in testZoomFactors) {
436 _locationWindow!.zoomFactor = zoom;
437 print("Changed zoom factor to: ${_locationWindow!.zoomFactor}");
438 }
439
440 // Test zoom limits
441 print("Testing zoom limits...");
442 _locationWindow!.zoomFactor = _locationWindow!.minZoomFactor;
443 print("Set to minimum zoom: ${_locationWindow!.zoomFactor}");
444
445 _locationWindow!.zoomFactor = _locationWindow!.maxZoomFactor;
446 print("Set to maximum zoom: ${_locationWindow!.zoomFactor}");
447
448 // Reset to default
449 _locationWindow!.zoomFactor = 100.0;
450 print("Reset zoom factor to default: ${_locationWindow!.zoomFactor}");
451 }
452
456 Future<void> runExample() async {
457 print("=== LocationWindowCommon Example ===");
458
459 // Simulate LocationWindow initialization
460 await Future.delayed(Duration(milliseconds: 500));
461
462 // TODO: User will implement LocationWindow initialization here
463 // _locationWindow = await getLocationWindow();
464
465 // Run demonstrations
466 _demonstrateLocationWindowCommonMethods();
467
468 print("=== Example completed ===");
469 }
470}
471
475Future<void> main() async {
477 await example.runExample();
478}
479
480class DemoSublocationChangeListener implements SublocationChangeListener {
481 // [dart_SublocationChangeListener_onActiveSublocationChanged]
482 @override
483 void onActiveSublocationChanged(int sublocationId) {
484 print("Active sublocation changed to: $sublocationId");
485 }
486 // [dart_SublocationChangeListener_onActiveSublocationChanged]
487}