Loading...
Searching...
No Matches
location_window_camera_example.dart
Go to the documentation of this file.
1import 'dart:ffi';
2import 'dart:math' as math;
3import 'package:meta/meta.dart';
4import 'package:navigine_sdk/com/_library_context.dart' as __lib;
5import 'package:navigine_sdk/com/_native_base.dart' as __lib;
6import 'package:navigine_sdk/com/_weak_map.dart';
7import 'package:navigine_sdk/com/builtin_types__conversion.dart';
8import 'package:navigine_sdk/com/navigine/idl/animation_type.dart';
9import 'package:navigine_sdk/com/navigine/idl/camera.dart';
10import 'package:navigine_sdk/com/navigine/idl/camera_callback.dart';
11import 'package:navigine_sdk/com/navigine/idl/camera_listener.dart';
12import 'package:navigine_sdk/com/navigine/idl/camera_update_reason.dart';
13import 'package:navigine_sdk/com/navigine/idl/point.dart';
14
20class LocationWindowCameraExample {
23
24 LocationWindowCameraExample() {
25 _demonstrateLocationWindowCameraMethods();
26 }
27
31 void _demonstrateLocationWindowCameraMethods() {
32 print("=== LocationWindowCamera Methods ===");
33
34 _demonstrateCameraProperties();
35 _demonstrateGetSetCamera();
36 _demonstrateCameraListeners();
37 _demonstrateFlyToMethod();
38 _demonstrateMoveToMethod();
39 _demonstrateZoomProperties();
40 _demonstrateCameraScenarios();
41 }
42
46 void _demonstrateCameraProperties() {
47 print("--- Camera Properties Setup ---");
48
49 if (_locationWindow == null) {
50 print("LocationWindow not available yet");
51 return;
52 }
53
54 // [dart_LocationWindow_minZoomFactor]
55 // Set minimum zoom factor
56 _locationWindow!.minZoomFactor = 10.0;
57 print("Set minimum zoom factor to 10.0 pixels per meter");
58 // [dart_LocationWindow_minZoomFactor]
59
60 // [dart_LocationWindow_maxZoomFactor]
61 // Set maximum zoom factor
62 _locationWindow!.maxZoomFactor = 1000.0;
63 print("Set maximum zoom factor to 1000.0 pixels per meter");
64 // [dart_LocationWindow_maxZoomFactor]
65 }
66
70 void _demonstrateGetSetCamera() {
71 print("--- getCamera and setCamera Methods ---");
72
73 if (_locationWindow == null) {
74 print("LocationWindow not available yet");
75 return;
76 }
77
78 // [dart_LocationWindow_getCamera]
79 // Get current camera position
80 Camera currentCamera = _locationWindow!.camera;
81 print("Current camera position:");
82 print(" Point: (${currentCamera.point.x}, ${currentCamera.point.y})");
83 print(" Zoom: ${currentCamera.zoom}");
84 print(" Rotation: ${currentCamera.rotation}°");
85 // [dart_LocationWindow_getCamera]
86
87 // [dart_Camera_constructor]
88 // Create camera with constructor
89 Point newPoint = Point(100.0, 200.0);
90 Camera newCamera = Camera(newPoint, 50.0, 0.0);
91 print("Created camera with point (${newPoint.x}, ${newPoint.y}), zoom 50.0, rotation 0°");
92 // [dart_Camera_constructor]
93
94 // [dart_Camera_access]
95 // Access camera properties
96 print("Camera properties:");
97 print(" Point: (${newCamera.point.x}, ${newCamera.point.y})");
98 print(" Zoom: ${newCamera.zoom}");
99 print(" Rotation: ${newCamera.rotation}°");
100 // [dart_Camera_access]
101
102 // [dart_LocationWindow_setCamera]
103 // Set camera position without animation
104 _locationWindow!.camera = newCamera;
105 print("Set camera position to (${newPoint.x}, ${newPoint.y}) with zoom 50.0 and rotation 0°");
106 // [dart_LocationWindow_setCamera]
107
108 // [dart_LocationWindow_setCamera_2]
109 // Set camera position with rotation
110 Point rotatedPoint = Point(150.0, 250.0);
111 Camera rotatedCamera = Camera(rotatedPoint, 75.0, 45.0);
112 _locationWindow!.camera = rotatedCamera;
113 print("Set camera position to (${rotatedPoint.x}, ${rotatedPoint.y}) with zoom 75.0 and rotation 45°");
114 // [dart_LocationWindow_setCamera_2]
115
116 // Test different camera positions
117 List<Camera> testCameras = [
118 Camera(Point(0.0, 0.0), 10.0, 0.0), // Overview camera
119 Camera(Point(50.0, 75.0), 500.0, 0.0), // Detail camera
120 Camera(Point(100.0, 150.0), 100.0, 30.0), // Angled camera
121 ];
122
123 for (int i = 0; i < testCameras.length; i++) {
124 Camera camera = testCameras[i];
125 _locationWindow!.camera = camera;
126 print("Test camera $i: Point (${camera.point.x}, ${camera.point.y}), Zoom ${camera.zoom}, Rotation ${camera.rotation}°");
127 }
128 }
129
133 void _demonstrateCameraListeners() {
134 print("--- Camera Listener Methods ---");
135
136 if (_locationWindow == null) {
137 print("LocationWindow not available yet");
138 return;
139 }
140
141 // [dart_LocationWindow_addCameraListener]
142 // Add camera listener
143 _cameraListener = CameraListenerImpl();
144 _locationWindow!.addCameraListener(_cameraListener!);
145 print("Added camera listener");
146 // [dart_LocationWindow_addCameraListener]
147
148 // [dart_LocationWindow_removeCameraListener]
149 // Remove camera listener
150 _locationWindow!.removeCameraListener(_cameraListener!);
151 _cameraListener = null;
152 print("Removed camera listener");
153 // [dart_LocationWindow_removeCameraListener]
154
155 // Test multiple listeners
156 List<CameraListener> listeners = [
157 CameraListenerImpl(),
158 CameraListenerImpl(),
159 CameraListenerImpl(),
160 ];
161
162 for (int i = 0; i < listeners.length; i++) {
163 _locationWindow!.addCameraListener(listeners[i]);
164 print("Added camera listener $i");
165 }
166
167 for (int i = 0; i < listeners.length; i++) {
168 _locationWindow!.removeCameraListener(listeners[i]);
169 print("Removed camera listener $i");
170 }
171 }
172
176 void _demonstrateFlyToMethod() {
177 print("--- flyTo Method ---");
178
179 if (_locationWindow == null) {
180 print("LocationWindow not available yet");
181 return;
182 }
183
184 // [dart_LocationWindow_flyTo]
185 // Fly to position with smooth animation
186 Point targetPoint = Point(150.0, 250.0);
187 Camera targetCamera = Camera(targetPoint, 75.0, 45.0);
188 CameraCallback callback = CameraCallback(
189 onMoveFinished: (completed) {
190 if (completed) {
191 print("Fly to animation completed successfully");
192 } else {
193 print("Fly to animation was cancelled");
194 }
195 },
196 );
197 _locationWindow!.flyTo(targetCamera, 2000, callback);
198 print("Started fly to animation to point (${targetPoint.x}, ${targetPoint.y})");
199 // [dart_LocationWindow_flyTo]
200
201 // [dart_LocationWindow_flyTo_2]
202 // Fly to another position with different duration
203 Point targetPoint2 = Point(300.0, 400.0);
204 Camera targetCamera2 = Camera(targetPoint2, 25.0, 180.0);
205 CameraCallback callback2 = CameraCallback(
206 onMoveFinished: (completed) {
207 print("Second fly to animation ${completed ? 'completed' : 'cancelled'}");
208 },
209 );
210 _locationWindow!.flyTo(targetCamera2, 3000, callback2);
211 print("Started fly to animation to point (${targetPoint2.x}, ${targetPoint2.y}) with 3 second duration");
212 // [dart_LocationWindow_flyTo_2]
213
214 // Test fly to with different parameters
215 List<Map<String, dynamic>> flyToTests = [
216 {"point": Point(50.0, 50.0), "zoom": 100.0, "rotation": 0.0, "duration": 1000},
217 {"point": Point(200.0, 300.0), "zoom": 200.0, "rotation": 90.0, "duration": 1500},
218 {"point": Point(400.0, 100.0), "zoom": 50.0, "rotation": 270.0, "duration": 2500},
219 ];
220
221 for (int i = 0; i < flyToTests.length; i++) {
222 Map<String, dynamic> test = flyToTests[i];
223 Point point = test["point"];
224 double zoom = test["zoom"];
225 double rotation = test["rotation"];
226 int duration = test["duration"];
227
228 Camera camera = Camera(point, zoom, rotation);
229 CameraCallback testCallback = CameraCallback(
230 onMoveFinished: (completed) {
231 print("Fly to test $i ${completed ? 'completed' : 'cancelled'}");
232 },
233 );
234 _locationWindow!.flyTo(camera, duration, testCallback);
235 print("Fly to test $i: Point (${point.x}, ${point.y}), Zoom $zoom, Rotation ${rotation}°, Duration ${duration}ms");
236 }
237 }
238
242 void _demonstrateMoveToMethod() {
243 print("--- moveTo Method ---");
244
245 if (_locationWindow == null) {
246 print("LocationWindow not available yet");
247 return;
248 }
249
250 // [dart_LocationWindow_moveTo]
251 // Move to position with linear animation
252 Point targetPoint = Point(200.0, 300.0);
253 Camera targetCamera = Camera(targetPoint, 100.0, 90.0);
254 CameraCallback callback = CameraCallback(
255 onMoveFinished: (completed) {
256 print("Move to with linear animation ${completed ? 'completed' : 'cancelled'}");
257 },
258 );
259 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback);
260 print("Started move to with linear animation");
261 // [dart_LocationWindow_moveTo]
262
263 // [dart_LocationWindow_moveTo_2]
264 // Move to position with cubic animation
265 CameraCallback callback2 = CameraCallback(
266 onMoveFinished: (completed) {
267 print("Move to with cubic animation ${completed ? 'completed' : 'cancelled'}");
268 },
269 );
270 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2);
271 print("Started move to with cubic animation");
272 // [dart_LocationWindow_moveTo_2]
273
274 // [dart_LocationWindow_moveTo_3]
275 // Move to position with sine animation
276 CameraCallback callback3 = CameraCallback(
277 onMoveFinished: (completed) {
278 print("Move to with sine animation ${completed ? 'completed' : 'cancelled'}");
279 },
280 );
281 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.SINE, callback3);
282 print("Started move to with sine animation");
283 // [dart_LocationWindow_moveTo_3]
284
285 // [dart_LocationWindow_moveTo_4]
286 // Move to position without animation
287 Point instantPoint = Point(300.0, 400.0);
288 Camera instantCamera = Camera(instantPoint, 25.0, 180.0);
289 CameraCallback instantCallback = CameraCallback(
290 onMoveFinished: (completed) {
291 print("Instant move to completed");
292 },
293 );
294 _locationWindow!.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback);
295 print("Executed instant move to position (${instantPoint.x}, ${instantPoint.y})");
296 // [dart_LocationWindow_moveTo_4]
297
298 // Test move to with different animation types
299 // [dart_AnimationType_enum]
300 List<AnimationType> animationTypes = [
301 AnimationType.LINEAR,
302 AnimationType.CUBIC,
303 AnimationType.QUINT,
304 AnimationType.SINE,
305 AnimationType.NONE,
306 ];
307 // [dart_AnimationType_enum]
308
309 for (int i = 0; i < animationTypes.length; i++) {
310 AnimationType animationType = animationTypes[i];
311 Point testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0);
312 Camera testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0);
313 CameraCallback testCallback = CameraCallback(
314 onMoveFinished: (completed) {
315 print("Move to test with ${animationType.name} animation ${completed ? 'completed' : 'cancelled'}");
316 },
317 );
318 _locationWindow!.moveTo(testCamera, 1000, animationType, testCallback);
319 print("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})");
320 }
321 }
322
326 void _demonstrateZoomProperties() {
327 print("--- Zoom Properties ---");
328
329 if (_locationWindow == null) {
330 print("LocationWindow not available yet");
331 return;
332 }
333
334 // [dart_LocationWindow_getZoomFactor]
335 // Get current zoom factor
336 double currentZoom = _locationWindow!.zoomFactor;
337 print("Current zoom factor: $currentZoom pixels per meter");
338 // [dart_LocationWindow_getZoomFactor]
339
340 // [dart_LocationWindow_setZoomFactor]
341 // Set new zoom factor
342 _locationWindow!.zoomFactor = 200.0;
343 print("Set zoom factor to 200.0 pixels per meter");
344 // [dart_LocationWindow_setZoomFactor]
345
346 // [dart_LocationWindow_getMinZoomFactor]
347 // Get minimum zoom factor
348 double minZoom = _locationWindow!.minZoomFactor;
349 print("Minimum zoom factor: $minZoom pixels per meter");
350 // [dart_LocationWindow_getMinZoomFactor]
351
352 // [dart_LocationWindow_getMaxZoomFactor]
353 // Get maximum zoom factor
354 double maxZoom = _locationWindow!.maxZoomFactor;
355 print("Maximum zoom factor: $maxZoom pixels per meter");
356 // [dart_LocationWindow_getMaxZoomFactor]
357
358 // Test zoom factor changes
359 List<double> zoomLevels = [50.0, 100.0, 150.0, 300.0, 500.0, 800.0];
360
361 for (int i = 0; i < zoomLevels.length; i++) {
362 double zoom = zoomLevels[i];
363 _locationWindow!.zoomFactor = zoom;
364 print("Set zoom factor to $zoom pixels per meter");
365
366 // Verify the change
367 double actualZoom = _locationWindow!.zoomFactor;
368 print("Actual zoom factor: $actualZoom pixels per meter");
369 }
370 }
371
375 void _demonstrateCameraScenarios() {
376 print("--- Camera Scenarios ---");
377
378 if (_locationWindow == null) {
379 print("LocationWindow not available yet");
380 return;
381 }
382
383 // [dart_LocationWindow_camera_scenarios]
384 // Create cameras for different scenarios
385 Camera overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0);
386 Camera detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0);
387 Camera angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0);
388
389 print("Created cameras for different scenarios:");
390 print(" Overview camera: zoom ${overviewCamera.zoom}");
391 print(" Detail camera: zoom ${detailCamera.zoom}");
392 print(" Angled camera: rotation ${angledCamera.rotation}°");
393 // [dart_LocationWindow_camera_scenarios]
394
395 // Test scenario transitions
396 List<Camera> scenarios = [overviewCamera, detailCamera, angledCamera];
397 List<String> scenarioNames = ["Overview", "Detail", "Angled"];
398
399 for (int i = 0; i < scenarios.length; i++) {
400 Camera scenario = scenarios[i];
401 String name = scenarioNames[i];
402
403 CameraCallback scenarioCallback = CameraCallback(
404 onMoveFinished: (completed) {
405 print("Transition to $name scenario ${completed ? 'completed' : 'cancelled'}");
406 },
407 );
408
409 _locationWindow!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback);
410 print("Transitioning to $name scenario");
411 }
412 }
413
417 void cleanup() {
418 if (_cameraListener != null && _locationWindow != null) {
419 _locationWindow!.removeCameraListener(_cameraListener!);
420 _cameraListener = null;
421 print("Camera listener removed");
422 }
423 }
424}
425
429class CameraListenerImpl implements CameraListener {
430 // [dart_CameraListener_onCameraPositionChanged]
431 @override
432 void onCameraPositionChanged(CameraUpdateReason reason, bool finished) {
433 String reasonText = reason == CameraUpdateReason.GESTURES ? "user gestures" : "application";
434 String statusText = finished ? "finished" : "in progress";
435
436 print("Camera position changed: $reasonText, status: $statusText");
437
438 if (finished) {
439 print("Camera movement completed");
440 }
441 }
442 // [dart_CameraListener_onCameraPositionChanged]
443}
444
449 static CameraCallback create() {
450 return CameraCallback(
451 // [dart_CameraCallback_onMoveFinished]
452 onMoveFinished: (bool completed) {
453 if (completed) {
454 print("Camera movement completed successfully");
455 } else {
456 print("Camera movement was cancelled");
457 }
458 },
459 // [dart_CameraCallback_onMoveFinished]
460 );
461 }
462}
463
471 static Camera createCenteredCamera(double x, double y, double zoom) {
472 return Camera(Point(x, y), zoom, 0.0);
473 }
474
478 static Camera createRotatedCamera(double x, double y, double zoom, double rotation) {
479 return Camera(Point(x, y), zoom, rotation);
480 }
481
485 static bool isValidCamera(Camera camera) {
486 return camera.zoom > 0 &&
487 camera.rotation >= 0 && camera.rotation < 360;
488 }
489
493 static Camera createAreaCamera(double centerX, double centerY, double width, double height) {
494 // Calculate zoom based on area size
495 double zoom = 100.0 / math.max(width, height);
496 return Camera(Point(centerX, centerY), zoom, 0.0);
497 }
498}
499
503void main() {
504 // Create example instance
506
507 // Assume we have LocationWindow
508 // LocationWindow locationWindow = getLocationWindow();
509 // example._locationWindow = locationWindow;
510
511 // Demonstrate methods
512 print("=== LocationWindowCamera Examples ===");
513
514 // Cleanup
515 example.cleanup();
516
517 print("Examples ready to use!");
518}