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
17 LocationWindowCommonExample() {
18 _demonstrateLocationWindowCommonMethods();
19 }
20
24 void _demonstrateLocationWindowCommonMethods() {
25 print("=== LocationWindowCommon Methods ===");
26
27 _demonstrateSetSublocationId();
28 _demonstrateCoordinateConversion();
29 _demonstrateMapFeatureSelection();
30 _demonstrateZoomProperties();
31 }
32
36 void _demonstrateSetSublocationId() {
37 print("--- setSublocationId Method ---");
38
39 if (_locationWindow == null) {
40 print("LocationWindow not available yet");
41 return;
42 }
43
44 // [dart_LocationWindow_setSublocationId]
45 // Set sublocation ID to switch between floors
46 _locationWindow!.setSublocationId(1);
47 print("Set sublocation ID to 1 (first floor)");
48 // [dart_LocationWindow_setSublocationId]
49
50 // [dart_LocationWindow_setSublocationId_2]
51 // Set sublocation ID to another floor
52 _locationWindow!.setSublocationId(2);
53 print("Set sublocation ID to 2 (second floor)");
54 // [dart_LocationWindow_setSublocationId_2]
55
56 // [dart_LocationWindow_setSublocationId_3]
57 // Set sublocation ID to ground floor
58 _locationWindow!.setSublocationId(0);
59 print("Set sublocation ID to 0 (ground floor)");
60 // [dart_LocationWindow_setSublocationId_3]
61
62 // Test with different sublocation IDs
63 List<int> sublocationIds = [1, 2, 3, 0, 5];
64 for (int id in sublocationIds) {
65 _locationWindow!.setSublocationId(id);
66 print("Switched to sublocation ID: $id");
67 }
68 }
69
73 void _demonstrateCoordinateConversion() {
74 print("--- Coordinate Conversion Methods ---");
75
76 if (_locationWindow == null) {
77 print("LocationWindow not available yet");
78 return;
79 }
80
81 // [dart_LocationWindow_screenPositionToMeters]
82 // Convert screen position to meters
83 Point screenPoint = Point(100.0, 200.0);
84 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
85 print("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})");
86 // [dart_LocationWindow_screenPositionToMeters]
87
88 // [dart_LocationWindow_screenPositionToMeters_2]
89 // Convert another screen position to meters
90 Point screenPoint2 = Point(500.0, 300.0);
91 Point metersPoint2 = _locationWindow!.screenPositionToMeters(screenPoint2);
92 print("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})");
93 // [dart_LocationWindow_screenPositionToMeters_2]
94
95 // [dart_LocationWindow_metersToScreenPosition]
96 // Convert meters to screen position with clipping
97 Point metersPoint3 = Point(50.0, 75.0);
98 Point screenPoint3 = _locationWindow!.metersToScreenPosition(metersPoint3, true);
99 print("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})");
100 // [dart_LocationWindow_metersToScreenPosition]
101
102 // [dart_LocationWindow_metersToScreenPosition_2]
103 // Convert meters to screen position without clipping
104 Point metersPoint4 = Point(150.0, 200.0);
105 Point screenPoint4 = _locationWindow!.metersToScreenPosition(metersPoint4, false);
106 print("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})");
107 // [dart_LocationWindow_metersToScreenPosition_2]
108
109 // Test coordinate conversion with different values
110 List<Point> testScreenPoints = [
111 Point(0.0, 0.0),
112 Point(250.0, 250.0),
113 Point(1000.0, 600.0),
114 ];
115
116 for (int i = 0; i < testScreenPoints.length; i++) {
117 Point screenPoint = testScreenPoints[i];
118 Point metersPoint = _locationWindow!.screenPositionToMeters(screenPoint);
119 Point backToScreen = _locationWindow!.metersToScreenPosition(metersPoint, false);
120 print("Test $i: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})");
121 }
122 }
123
127 void _demonstrateMapFeatureSelection() {
128 print("--- Map Feature Selection Methods ---");
129
130 if (_locationWindow == null) {
131 print("LocationWindow not available yet");
132 return;
133 }
134
135 // [dart_LocationWindow_selectMapFeature]
136 // Select map feature by ID
137 String featureId = "room_101";
138 bool selected = _locationWindow!.selectMapFeature(featureId);
139 print("Selected map feature $featureId: $selected");
140 // [dart_LocationWindow_selectMapFeature]
141
142 // [dart_LocationWindow_selectMapFeature_2]
143 // Select another map feature
144 String featureId2 = "office_205";
145 bool selected2 = _locationWindow!.selectMapFeature(featureId2);
146 print("Selected map feature $featureId2: $selected2");
147 // [dart_LocationWindow_selectMapFeature_2]
148
149 // [dart_LocationWindow_getSelectedMapFeatures]
150 // Get list of selected map features
151 List<String> selectedFeatures = _locationWindow!.selectedMapFeatures;
152 print("Currently selected map features: ${selectedFeatures.length} features");
153 for (String feature in selectedFeatures) {
154 print(" - $feature");
155 }
156 // [dart_LocationWindow_getSelectedMapFeatures]
157
158 // [dart_LocationWindow_deselectMapFeature]
159 // Deselect specific map feature
160 bool deselected = _locationWindow!.deselectMapFeature(featureId);
161 print("Deselected map feature $featureId: $deselected");
162 // [dart_LocationWindow_deselectMapFeature]
163
164 // [dart_LocationWindow_deselectMapFeature_2]
165 // Deselect another map feature
166 bool deselected2 = _locationWindow!.deselectMapFeature(featureId2);
167 print("Deselected map feature $featureId2: $deselected2");
168 // [dart_LocationWindow_deselectMapFeature_2]
169
170 // [dart_LocationWindow_deselectAllMapFeatures]
171 // Deselect all map features
172 _locationWindow!.deselectAllMapFeatures();
173 print("Deselected all map features");
174 // [dart_LocationWindow_deselectAllMapFeatures]
175
176 // [dart_LocationWindow_getSelectedMapFeatures_2]
177 // Verify all features are deselected
178 List<String> remainingFeatures = _locationWindow!.selectedMapFeatures;
179 print("Remaining selected features after deselect all: ${remainingFeatures.length} features");
180 // [dart_LocationWindow_getSelectedMapFeatures_2]
181
182 // Test multiple feature selection and deselection
183 List<String> testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"];
184
185 // Select multiple features
186 for (String featureId in testFeatureIds) {
187 bool success = _locationWindow!.selectMapFeature(featureId);
188 print("Selected feature $featureId: $success");
189 }
190
191 // Check selected features
192 List<String> allSelected = _locationWindow!.selectedMapFeatures;
193 print("All selected features: ${allSelected.length} features");
194
195 // Deselect all at once
196 _locationWindow!.deselectAllMapFeatures();
197 print("Deselected all features at once");
198 }
199
203 void _demonstrateZoomProperties() {
204 print("--- Zoom Properties ---");
205
206 if (_locationWindow == null) {
207 print("LocationWindow not available yet");
208 return;
209 }
210
211 // [dart_LocationWindow_getZoomFactor]
212 // Get current zoom factor
213 double currentZoom = _locationWindow!.zoomFactor;
214 print("Current zoom factor: $currentZoom");
215 // [dart_LocationWindow_getZoomFactor]
216
217 // [dart_LocationWindow_setZoomFactor]
218 // Set zoom factor
219 _locationWindow!.zoomFactor = 150.0;
220 print("Set zoom factor to 150.0");
221 // [dart_LocationWindow_setZoomFactor]
222
223 // [dart_LocationWindow_getMinZoomFactor]
224 // Get minimum zoom factor
225 double minZoomFactor = _locationWindow!.minZoomFactor;
226 print("Minimum zoom factor: $minZoomFactor");
227 // [dart_LocationWindow_getMinZoomFactor]
228
229 // [dart_LocationWindow_setMinZoomFactor]
230 // Set minimum zoom factor
231 _locationWindow!.minZoomFactor = 50.0;
232 print("Set minimum zoom factor to 50.0");
233 // [dart_LocationWindow_setMinZoomFactor]
234
235 // [dart_LocationWindow_getMaxZoomFactor]
236 // Get maximum zoom factor
237 double maxZoomFactor = _locationWindow!.maxZoomFactor;
238 print("Maximum zoom factor: $maxZoomFactor");
239 // [dart_LocationWindow_getMaxZoomFactor]
240
241 // [dart_LocationWindow_setMaxZoomFactor]
242 // Set maximum zoom factor
243 _locationWindow!.maxZoomFactor = 300.0;
244 print("Set maximum zoom factor to 300.0");
245 // [dart_LocationWindow_setMaxZoomFactor]
246
247 // Test zoom factor changes
248 List<double> testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0];
249 for (double zoom in testZoomFactors) {
250 _locationWindow!.zoomFactor = zoom;
251 print("Changed zoom factor to: ${_locationWindow!.zoomFactor}");
252 }
253
254 // Test zoom limits
255 print("Testing zoom limits...");
256 _locationWindow!.zoomFactor = _locationWindow!.minZoomFactor;
257 print("Set to minimum zoom: ${_locationWindow!.zoomFactor}");
258
259 _locationWindow!.zoomFactor = _locationWindow!.maxZoomFactor;
260 print("Set to maximum zoom: ${_locationWindow!.zoomFactor}");
261
262 // Reset to default
263 _locationWindow!.zoomFactor = 100.0;
264 print("Reset zoom factor to default: ${_locationWindow!.zoomFactor}");
265 }
266
270 Future<void> runExample() async {
271 print("=== LocationWindowCommon Example ===");
272
273 // Simulate LocationWindow initialization
274 await Future.delayed(Duration(milliseconds: 500));
275
276 // TODO: User will implement LocationWindow initialization here
277 // _locationWindow = await getLocationWindow();
278
279 // Run demonstrations
280 _demonstrateLocationWindowCommonMethods();
281
282 print("=== Example completed ===");
283 }
284}
285
289Future<void> main() async {
291 await example.runExample();
292}