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 print(" Tilt: ${currentCamera.tilt}° (0° = straight downward / map from above)");
86 // [dart_LocationWindow_getCamera]
87
88 // [dart_Camera_constructor]
89 // Create camera with constructor
90 Point newPoint = Point(100.0, 200.0);
91 Camera newCamera = Camera(newPoint, 50.0, 0.0, 0.0);
92 print("Created camera with point (${newPoint.x}, ${newPoint.y}), zoom 50.0, rotation 0°, tilt 0°");
93 // [dart_Camera_constructor]
94
95 // [dart_Camera_access]
96 // Access camera properties
97 print("Camera properties:");
98 print(" Point: (${newCamera.point.x}, ${newCamera.point.y})");
99 print(" Zoom: ${newCamera.zoom}");
100 print(" Rotation: ${newCamera.rotation}°");
101 print(" Tilt: ${newCamera.tilt}°");
102 // [dart_Camera_access]
103
104 // [dart_LocationWindow_setCamera]
105 // Set camera position without animation
106 _locationWindow!.camera = newCamera;
107 print("Set camera position to (${newPoint.x}, ${newPoint.y}) with zoom 50.0, rotation 0°, tilt 0°");
108 // [dart_LocationWindow_setCamera]
109
110 // [dart_LocationWindow_setCamera_2]
111 // Set camera position with rotation
112 Point rotatedPoint = Point(150.0, 250.0);
113 Camera rotatedCamera = Camera(rotatedPoint, 75.0, 45.0, 0.0);
114 _locationWindow!.camera = rotatedCamera;
115 print("Set camera position to (${rotatedPoint.x}, ${rotatedPoint.y}) with zoom 75.0 and rotation 45°");
116 // [dart_LocationWindow_setCamera_2]
117
118 // Tilt: oblique view toward the horizon (clamped by the engine to a safe range)
119 Camera tiltedCamera = Camera(rotatedPoint, 75.0, 45.0, 40.0);
120 _locationWindow!.camera = tiltedCamera;
121 print("Set camera with tilt ${tiltedCamera.tilt}° for a perspective view");
122
123 // Test different camera positions
124 List<Camera> testCameras = [
125 Camera(Point(0.0, 0.0), 10.0, 0.0, 0.0), // Overview camera
126 Camera(Point(50.0, 75.0), 500.0, 0.0, 0.0), // Detail camera
127 Camera(Point(100.0, 150.0), 100.0, 30.0, 0.0), // Angled camera
128 ];
129
130 for (int i = 0; i < testCameras.length; i++) {
131 Camera camera = testCameras[i];
132 _locationWindow!.camera = camera;
133 print("Test camera $i: Point (${camera.point.x}, ${camera.point.y}), Zoom ${camera.zoom}, Rotation ${camera.rotation}°, Tilt ${camera.tilt}°");
134 }
135 }
136
140 void _demonstrateCameraListeners() {
141 print("--- Camera Listener Methods ---");
142
143 if (_locationWindow == null) {
144 print("LocationWindow not available yet");
145 return;
146 }
147
148 // [dart_LocationWindow_addCameraListener]
149 // Add camera listener
150 _cameraListener = CameraListenerImpl();
151 _locationWindow!.addCameraListener(_cameraListener!);
152 print("Added camera listener");
153 // [dart_LocationWindow_addCameraListener]
154
155 // [dart_LocationWindow_removeCameraListener]
156 // Remove camera listener
157 _locationWindow!.removeCameraListener(_cameraListener!);
158 _cameraListener = null;
159 print("Removed camera listener");
160 // [dart_LocationWindow_removeCameraListener]
161
162 // Test multiple listeners
163 List<CameraListener> listeners = [
164 CameraListenerImpl(),
165 CameraListenerImpl(),
166 CameraListenerImpl(),
167 ];
168
169 for (int i = 0; i < listeners.length; i++) {
170 _locationWindow!.addCameraListener(listeners[i]);
171 print("Added camera listener $i");
172 }
173
174 for (int i = 0; i < listeners.length; i++) {
175 _locationWindow!.removeCameraListener(listeners[i]);
176 print("Removed camera listener $i");
177 }
178 }
179
183 void _demonstrateFlyToMethod() {
184 print("--- flyTo Method ---");
185
186 if (_locationWindow == null) {
187 print("LocationWindow not available yet");
188 return;
189 }
190
191 // [dart_LocationWindow_flyTo]
192 // Fly to position with smooth animation
193 Point targetPoint = Point(150.0, 250.0);
194 Camera targetCamera = Camera(targetPoint, 75.0, 45.0, 30.0);
195 CameraCallback callback = CameraCallback(
196 onMoveFinished: (completed) {
197 if (completed) {
198 print("Fly to animation completed successfully");
199 } else {
200 print("Fly to animation was cancelled");
201 }
202 },
203 );
204 _locationWindow!.flyTo(targetCamera, 2000, callback);
205 print("Started fly to animation to point (${targetPoint.x}, ${targetPoint.y})");
206 // [dart_LocationWindow_flyTo]
207
208 // [dart_LocationWindow_flyTo_2]
209 // Fly to another position with different duration
210 Point targetPoint2 = Point(300.0, 400.0);
211 Camera targetCamera2 = Camera(targetPoint2, 25.0, 180.0, 0.0);
212 CameraCallback callback2 = CameraCallback(
213 onMoveFinished: (completed) {
214 print("Second fly to animation ${completed ? 'completed' : 'cancelled'}");
215 },
216 );
217 _locationWindow!.flyTo(targetCamera2, 3000, callback2);
218 print("Started fly to animation to point (${targetPoint2.x}, ${targetPoint2.y}) with 3 second duration");
219 // [dart_LocationWindow_flyTo_2]
220
221 // Test fly to with different parameters
222 List<Map<String, dynamic>> flyToTests = [
223 {"point": Point(50.0, 50.0), "zoom": 100.0, "rotation": 0.0, "duration": 1000},
224 {"point": Point(200.0, 300.0), "zoom": 200.0, "rotation": 90.0, "duration": 1500},
225 {"point": Point(400.0, 100.0), "zoom": 50.0, "rotation": 270.0, "duration": 2500},
226 ];
227
228 for (int i = 0; i < flyToTests.length; i++) {
229 Map<String, dynamic> test = flyToTests[i];
230 Point point = test["point"];
231 double zoom = test["zoom"];
232 double rotation = test["rotation"];
233 int duration = test["duration"];
234
235 Camera camera = Camera(point, zoom, rotation, 0.0);
236 CameraCallback testCallback = CameraCallback(
237 onMoveFinished: (completed) {
238 print("Fly to test $i ${completed ? 'completed' : 'cancelled'}");
239 },
240 );
241 _locationWindow!.flyTo(camera, duration, testCallback);
242 print("Fly to test $i: Point (${point.x}, ${point.y}), Zoom $zoom, Rotation ${rotation}°, Duration ${duration}ms");
243 }
244 }
245
249 void _demonstrateMoveToMethod() {
250 print("--- moveTo Method ---");
251
252 if (_locationWindow == null) {
253 print("LocationWindow not available yet");
254 return;
255 }
256
257 // [dart_LocationWindow_moveTo]
258 // Move to position with linear animation
259 Point targetPoint = Point(200.0, 300.0);
260 Camera targetCamera = Camera(targetPoint, 100.0, 90.0, 0.0);
261 CameraCallback callback = CameraCallback(
262 onMoveFinished: (completed) {
263 print("Move to with linear animation ${completed ? 'completed' : 'cancelled'}");
264 },
265 );
266 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback);
267 print("Started move to with linear animation");
268 // [dart_LocationWindow_moveTo]
269
270 // [dart_LocationWindow_moveTo_2]
271 // Move to position with cubic animation
272 CameraCallback callback2 = CameraCallback(
273 onMoveFinished: (completed) {
274 print("Move to with cubic animation ${completed ? 'completed' : 'cancelled'}");
275 },
276 );
277 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2);
278 print("Started move to with cubic animation");
279 // [dart_LocationWindow_moveTo_2]
280
281 // [dart_LocationWindow_moveTo_3]
282 // Move to position with sine animation
283 CameraCallback callback3 = CameraCallback(
284 onMoveFinished: (completed) {
285 print("Move to with sine animation ${completed ? 'completed' : 'cancelled'}");
286 },
287 );
288 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.SINE, callback3);
289 print("Started move to with sine animation");
290 // [dart_LocationWindow_moveTo_3]
291
292 // [dart_LocationWindow_moveTo_4]
293 // Move to position without animation
294 Point instantPoint = Point(300.0, 400.0);
295 Camera instantCamera = Camera(instantPoint, 25.0, 180.0, 0.0);
296 CameraCallback instantCallback = CameraCallback(
297 onMoveFinished: (completed) {
298 print("Instant move to completed");
299 },
300 );
301 _locationWindow!.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback);
302 print("Executed instant move to position (${instantPoint.x}, ${instantPoint.y})");
303 // [dart_LocationWindow_moveTo_4]
304
305 // Test move to with different animation types
306 // [dart_AnimationType_enum]
307 List<AnimationType> animationTypes = [
308 AnimationType.LINEAR,
309 AnimationType.CUBIC,
310 AnimationType.QUINT,
311 AnimationType.SINE,
312 AnimationType.NONE,
313 ];
314 // [dart_AnimationType_enum]
315
316 for (int i = 0; i < animationTypes.length; i++) {
317 AnimationType animationType = animationTypes[i];
318 Point testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0);
319 Camera testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0, 0.0);
320 CameraCallback testCallback = CameraCallback(
321 onMoveFinished: (completed) {
322 print("Move to test with ${animationType.name} animation ${completed ? 'completed' : 'cancelled'}");
323 },
324 );
325 _locationWindow!.moveTo(testCamera, 1000, animationType, testCallback);
326 print("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})");
327 }
328 }
329
333 void _demonstrateZoomProperties() {
334 print("--- Zoom Properties ---");
335
336 if (_locationWindow == null) {
337 print("LocationWindow not available yet");
338 return;
339 }
340
341 // [dart_LocationWindow_getZoomFactor]
342 // Get current zoom factor
343 double currentZoom = _locationWindow!.zoomFactor;
344 print("Current zoom factor: $currentZoom pixels per meter");
345 // [dart_LocationWindow_getZoomFactor]
346
347 // [dart_LocationWindow_setZoomFactor]
348 // Set new zoom factor
349 _locationWindow!.zoomFactor = 200.0;
350 print("Set zoom factor to 200.0 pixels per meter");
351 // [dart_LocationWindow_setZoomFactor]
352
353 // [dart_LocationWindow_getMinZoomFactor]
354 // Get minimum zoom factor
355 double minZoom = _locationWindow!.minZoomFactor;
356 print("Minimum zoom factor: $minZoom pixels per meter");
357 // [dart_LocationWindow_getMinZoomFactor]
358
359 // [dart_LocationWindow_getMaxZoomFactor]
360 // Get maximum zoom factor
361 double maxZoom = _locationWindow!.maxZoomFactor;
362 print("Maximum zoom factor: $maxZoom pixels per meter");
363 // [dart_LocationWindow_getMaxZoomFactor]
364
365 // Test zoom factor changes
366 List<double> zoomLevels = [50.0, 100.0, 150.0, 300.0, 500.0, 800.0];
367
368 for (int i = 0; i < zoomLevels.length; i++) {
369 double zoom = zoomLevels[i];
370 _locationWindow!.zoomFactor = zoom;
371 print("Set zoom factor to $zoom pixels per meter");
372
373 // Verify the change
374 double actualZoom = _locationWindow!.zoomFactor;
375 print("Actual zoom factor: $actualZoom pixels per meter");
376 }
377 }
378
382 void _demonstrateCameraScenarios() {
383 print("--- Camera Scenarios ---");
384
385 if (_locationWindow == null) {
386 print("LocationWindow not available yet");
387 return;
388 }
389
390 // [dart_LocationWindow_camera_scenarios]
391 // Create cameras for different scenarios
392 Camera overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0, 0.0);
393 Camera detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0, 0.0);
394 Camera angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0, 25.0);
395
396 print("Created cameras for different scenarios:");
397 print(" Overview camera: zoom ${overviewCamera.zoom}");
398 print(" Detail camera: zoom ${detailCamera.zoom}");
399 print(" Angled camera: rotation ${angledCamera.rotation}°, tilt ${angledCamera.tilt}°");
400 // [dart_LocationWindow_camera_scenarios]
401
402 // Test scenario transitions
403 List<Camera> scenarios = [overviewCamera, detailCamera, angledCamera];
404 List<String> scenarioNames = ["Overview", "Detail", "Angled"];
405
406 for (int i = 0; i < scenarios.length; i++) {
407 Camera scenario = scenarios[i];
408 String name = scenarioNames[i];
409
410 CameraCallback scenarioCallback = CameraCallback(
411 onMoveFinished: (completed) {
412 print("Transition to $name scenario ${completed ? 'completed' : 'cancelled'}");
413 },
414 );
415
416 _locationWindow!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback);
417 print("Transitioning to $name scenario");
418 }
419 }
420
424 void cleanup() {
425 if (_cameraListener != null && _locationWindow != null) {
426 _locationWindow!.removeCameraListener(_cameraListener!);
427 _cameraListener = null;
428 print("Camera listener removed");
429 }
430 }
431}
432
436class CameraListenerImpl implements CameraListener {
437 // [dart_CameraListener_onCameraPositionChanged]
438 @override
439 void onCameraPositionChanged(CameraUpdateReason reason, bool finished) {
440 String reasonText = reason == CameraUpdateReason.GESTURES ? "user gestures" : "application";
441 String statusText = finished ? "finished" : "in progress";
442
443 print("Camera position changed: $reasonText, status: $statusText");
444
445 if (finished) {
446 print("Camera movement completed");
447 }
448 }
449 // [dart_CameraListener_onCameraPositionChanged]
450}
451
456 static CameraCallback create() {
457 return CameraCallback(
458 // [dart_CameraCallback_onMoveFinished]
459 onMoveFinished: (bool completed) {
460 if (completed) {
461 print("Camera movement completed successfully");
462 } else {
463 print("Camera movement was cancelled");
464 }
465 },
466 // [dart_CameraCallback_onMoveFinished]
467 );
468 }
469}
470
478 static Camera createCenteredCamera(double x, double y, double zoom) {
479 return Camera(Point(x, y), zoom, 0.0, 0.0);
480 }
481
485 static Camera createRotatedCamera(double x, double y, double zoom, double rotation) {
486 return Camera(Point(x, y), zoom, rotation, 0.0);
487 }
488
492 static Camera createTiltedCamera(double x, double y, double zoom, double rotation, double tilt) {
493 return Camera(Point(x, y), zoom, rotation, tilt);
494 }
495
499 static bool isValidCamera(Camera camera) {
500 return camera.zoom > 0 &&
501 camera.rotation >= 0 &&
502 camera.rotation < 360 &&
503 camera.tilt >= 0;
504 }
505
509 static Camera createAreaCamera(double centerX, double centerY, double width, double height) {
510 // Calculate zoom based on area size
511 double zoom = 100.0 / math.max(width, height);
512 return Camera(Point(centerX, centerY), zoom, 0.0, 0.0);
513 }
514}
515
519void main() {
520 // Create example instance
522
523 // Assume we have LocationWindow
524 // LocationWindow locationWindow = getLocationWindow();
525 // example._locationWindow = locationWindow;
526
527 // Demonstrate methods
528 print("=== LocationWindowCamera Examples ===");
529
530 // Cleanup
531 example.cleanup();
532
533 print("Examples ready to use!");
534}