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 {
21 LocationWindow? _locationWindow;
22 CameraListener? _cameraListener;
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 List<AnimationType> animationTypes = [
300 AnimationType.LINEAR,
301 AnimationType.CUBIC,
302 AnimationType.QUINT,
303 AnimationType.SINE,
304 AnimationType.NONE,
305 ];
306
307 for (int i = 0; i < animationTypes.length; i++) {
308 AnimationType animationType = animationTypes[i];
309 Point testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0);
310 Camera testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0);
311 CameraCallback testCallback = CameraCallback(
312 onMoveFinished: (completed) {
313 print("Move to test with ${animationType.name} animation ${completed ? 'completed' : 'cancelled'}");
314 },
315 );
316 _locationWindow!.moveTo(testCamera, 1000, animationType, testCallback);
317 print("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})");
318 }
319 }
320
324 void _demonstrateZoomProperties() {
325 print("--- Zoom Properties ---");
326
327 if (_locationWindow == null) {
328 print("LocationWindow not available yet");
329 return;
330 }
331
332 // [dart_LocationWindow_getZoomFactor]
333 // Get current zoom factor
334 double currentZoom = _locationWindow!.zoomFactor;
335 print("Current zoom factor: $currentZoom pixels per meter");
336 // [dart_LocationWindow_getZoomFactor]
337
338 // [dart_LocationWindow_setZoomFactor]
339 // Set new zoom factor
340 _locationWindow!.zoomFactor = 200.0;
341 print("Set zoom factor to 200.0 pixels per meter");
342 // [dart_LocationWindow_setZoomFactor]
343
344 // [dart_LocationWindow_getMinZoomFactor]
345 // Get minimum zoom factor
346 double minZoom = _locationWindow!.minZoomFactor;
347 print("Minimum zoom factor: $minZoom pixels per meter");
348 // [dart_LocationWindow_getMinZoomFactor]
349
350 // [dart_LocationWindow_getMaxZoomFactor]
351 // Get maximum zoom factor
352 double maxZoom = _locationWindow!.maxZoomFactor;
353 print("Maximum zoom factor: $maxZoom pixels per meter");
354 // [dart_LocationWindow_getMaxZoomFactor]
355
356 // Test zoom factor changes
357 List<double> zoomLevels = [50.0, 100.0, 150.0, 300.0, 500.0, 800.0];
358
359 for (int i = 0; i < zoomLevels.length; i++) {
360 double zoom = zoomLevels[i];
361 _locationWindow!.zoomFactor = zoom;
362 print("Set zoom factor to $zoom pixels per meter");
363
364 // Verify the change
365 double actualZoom = _locationWindow!.zoomFactor;
366 print("Actual zoom factor: $actualZoom pixels per meter");
367 }
368 }
369
373 void _demonstrateCameraScenarios() {
374 print("--- Camera Scenarios ---");
375
376 if (_locationWindow == null) {
377 print("LocationWindow not available yet");
378 return;
379 }
380
381 // [dart_LocationWindow_camera_scenarios]
382 // Create cameras for different scenarios
383 Camera overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0);
384 Camera detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0);
385 Camera angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0);
386
387 print("Created cameras for different scenarios:");
388 print(" Overview camera: zoom ${overviewCamera.zoom}");
389 print(" Detail camera: zoom ${detailCamera.zoom}");
390 print(" Angled camera: rotation ${angledCamera.rotation}°");
391 // [dart_LocationWindow_camera_scenarios]
392
393 // Test scenario transitions
394 List<Camera> scenarios = [overviewCamera, detailCamera, angledCamera];
395 List<String> scenarioNames = ["Overview", "Detail", "Angled"];
396
397 for (int i = 0; i < scenarios.length; i++) {
398 Camera scenario = scenarios[i];
399 String name = scenarioNames[i];
400
401 CameraCallback scenarioCallback = CameraCallback(
402 onMoveFinished: (completed) {
403 print("Transition to $name scenario ${completed ? 'completed' : 'cancelled'}");
404 },
405 );
406
407 _locationWindow!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback);
408 print("Transitioning to $name scenario");
409 }
410 }
411
415 void cleanup() {
416 if (_cameraListener != null && _locationWindow != null) {
417 _locationWindow!.removeCameraListener(_cameraListener!);
418 _cameraListener = null;
419 print("Camera listener removed");
420 }
421 }
422}
423
427class CameraListenerImpl implements CameraListener {
428 // [dart_CameraListener_onCameraPositionChanged]
429 @override
430 void onCameraPositionChanged(CameraUpdateReason reason, bool finished) {
431 String reasonText = reason == CameraUpdateReason.GESTURES ? "user gestures" : "application";
432 String statusText = finished ? "finished" : "in progress";
433
434 print("Camera position changed: $reasonText, status: $statusText");
435
436 if (finished) {
437 print("Camera movement completed");
438 }
439 }
440 // [dart_CameraListener_onCameraPositionChanged]
441}
442
450 static Camera createCenteredCamera(double x, double y, double zoom) {
451 return Camera(Point(x, y), zoom, 0.0);
452 }
453
457 static Camera createRotatedCamera(double x, double y, double zoom, double rotation) {
458 return Camera(Point(x, y), zoom, rotation);
459 }
460
464 static bool isValidCamera(Camera camera) {
465 return camera.zoom > 0 &&
466 camera.rotation >= 0 && camera.rotation < 360;
467 }
468
472 static Camera createAreaCamera(double centerX, double centerY, double width, double height) {
473 // Calculate zoom based on area size
474 double zoom = 100.0 / math.max(width, height);
475 return Camera(Point(centerX, centerY), zoom, 0.0);
476 }
477}
478
482void main() {
483 // Create example instance
485
486 // Assume we have LocationWindow
487 // LocationWindow locationWindow = getLocationWindow();
488 // example._locationWindow = locationWindow;
489
490 // Demonstrate methods
491 print("=== LocationWindowCamera Examples ===");
492
493 // Cleanup
494 example.cleanup();
495
496 print("Examples ready to use!");
497}