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