20class LocationWindowCameraExample {
21 LocationWindow? _locationWindow;
22 CameraListener? _cameraListener;
24 LocationWindowCameraExample() {
25 _demonstrateLocationWindowCameraMethods();
31 void _demonstrateLocationWindowCameraMethods() {
32 print(
"=== LocationWindowCamera Methods ===");
34 _demonstrateCameraProperties();
35 _demonstrateGetSetCamera();
36 _demonstrateCameraListeners();
37 _demonstrateFlyToMethod();
38 _demonstrateMoveToMethod();
39 _demonstrateZoomProperties();
40 _demonstrateCameraScenarios();
46 void _demonstrateCameraProperties() {
47 print(
"--- Camera Properties Setup ---");
49 if (_locationWindow ==
null) {
50 print(
"LocationWindow not available yet");
56 _locationWindow!.minZoomFactor = 10.0;
57 print(
"Set minimum zoom factor to 10.0 pixels per meter");
62 _locationWindow!.maxZoomFactor = 1000.0;
63 print(
"Set maximum zoom factor to 1000.0 pixels per meter");
70 void _demonstrateGetSetCamera() {
71 print(
"--- getCamera and setCamera Methods ---");
73 if (_locationWindow ==
null) {
74 print(
"LocationWindow not available yet");
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}°");
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°");
96 print(
"Camera properties:");
97 print(
" Point: (${newCamera.point.x}, ${newCamera.point.y})");
98 print(
" Zoom: ${newCamera.zoom}");
99 print(
" Rotation: ${newCamera.rotation}°");
104 _locationWindow!.camera = newCamera;
105 print(
"Set camera position to (${newPoint.x}, ${newPoint.y}) with zoom 50.0 and rotation 0°");
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°");
117 List<Camera> testCameras = [
118 Camera(Point(0.0, 0.0), 10.0, 0.0),
119 Camera(Point(50.0, 75.0), 500.0, 0.0),
120 Camera(Point(100.0, 150.0), 100.0, 30.0),
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}°");
133 void _demonstrateCameraListeners() {
134 print(
"--- Camera Listener Methods ---");
136 if (_locationWindow ==
null) {
137 print(
"LocationWindow not available yet");
143 _cameraListener = CameraListenerImpl();
144 _locationWindow!.addCameraListener(_cameraListener!);
145 print(
"Added camera listener");
150 _locationWindow!.removeCameraListener(_cameraListener!);
151 _cameraListener =
null;
152 print(
"Removed camera listener");
156 List<CameraListener> listeners = [
157 CameraListenerImpl(),
158 CameraListenerImpl(),
159 CameraListenerImpl(),
162 for (
int i = 0; i < listeners.length; i++) {
163 _locationWindow!.addCameraListener(listeners[i]);
164 print(
"Added camera listener $i");
167 for (
int i = 0; i < listeners.length; i++) {
168 _locationWindow!.removeCameraListener(listeners[i]);
169 print(
"Removed camera listener $i");
176 void _demonstrateFlyToMethod() {
177 print(
"--- flyTo Method ---");
179 if (_locationWindow ==
null) {
180 print(
"LocationWindow not available yet");
186 Point targetPoint = Point(150.0, 250.0);
187 Camera targetCamera = Camera(targetPoint, 75.0, 45.0);
188 CameraCallback callback = CameraCallback(
189 onMoveFinished: (completed) {
191 print(
"Fly to animation completed successfully");
193 print(
"Fly to animation was cancelled");
197 _locationWindow!.flyTo(targetCamera, 2000, callback);
198 print(
"Started fly to animation to point (${targetPoint.x}, ${targetPoint.y})");
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'}");
210 _locationWindow!.flyTo(targetCamera2, 3000, callback2);
211 print(
"Started fly to animation to point (${targetPoint2.x}, ${targetPoint2.y}) with 3 second duration");
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},
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"];
228 Camera camera = Camera(point, zoom, rotation);
229 CameraCallback testCallback = CameraCallback(
230 onMoveFinished: (completed) {
231 print(
"Fly to test $i ${completed ? 'completed' : 'cancelled'}");
234 _locationWindow!.flyTo(camera, duration, testCallback);
235 print(
"Fly to test $i: Point (${point.x}, ${point.y}), Zoom $zoom, Rotation ${rotation}°, Duration ${duration}ms");
242 void _demonstrateMoveToMethod() {
243 print(
"--- moveTo Method ---");
245 if (_locationWindow ==
null) {
246 print(
"LocationWindow not available yet");
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'}");
259 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback);
260 print(
"Started move to with linear animation");
265 CameraCallback callback2 = CameraCallback(
266 onMoveFinished: (completed) {
267 print(
"Move to with cubic animation ${completed ? 'completed' : 'cancelled'}");
270 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2);
271 print(
"Started move to with cubic animation");
276 CameraCallback callback3 = CameraCallback(
277 onMoveFinished: (completed) {
278 print(
"Move to with sine animation ${completed ? 'completed' : 'cancelled'}");
281 _locationWindow!.moveTo(targetCamera, 1500, AnimationType.SINE, callback3);
282 print(
"Started move to with sine 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");
294 _locationWindow!.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback);
295 print(
"Executed instant move to position (${instantPoint.x}, ${instantPoint.y})");
299 List<AnimationType> animationTypes = [
300 AnimationType.LINEAR,
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'}");
316 _locationWindow!.moveTo(testCamera, 1000, animationType, testCallback);
317 print(
"Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})");
324 void _demonstrateZoomProperties() {
325 print(
"--- Zoom Properties ---");
327 if (_locationWindow ==
null) {
328 print(
"LocationWindow not available yet");
334 double currentZoom = _locationWindow!.zoomFactor;
335 print(
"Current zoom factor: $currentZoom pixels per meter");
340 _locationWindow!.zoomFactor = 200.0;
341 print(
"Set zoom factor to 200.0 pixels per meter");
346 double minZoom = _locationWindow!.minZoomFactor;
347 print(
"Minimum zoom factor: $minZoom pixels per meter");
352 double maxZoom = _locationWindow!.maxZoomFactor;
353 print(
"Maximum zoom factor: $maxZoom pixels per meter");
357 List<double> zoomLevels = [50.0, 100.0, 150.0, 300.0, 500.0, 800.0];
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");
365 double actualZoom = _locationWindow!.zoomFactor;
366 print(
"Actual zoom factor: $actualZoom pixels per meter");
373 void _demonstrateCameraScenarios() {
374 print(
"--- Camera Scenarios ---");
376 if (_locationWindow ==
null) {
377 print(
"LocationWindow not available yet");
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);
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}°");
394 List<Camera> scenarios = [overviewCamera, detailCamera, angledCamera];
395 List<String> scenarioNames = [
"Overview",
"Detail",
"Angled"];
397 for (
int i = 0; i < scenarios.length; i++) {
398 Camera scenario = scenarios[i];
399 String name = scenarioNames[i];
401 CameraCallback scenarioCallback = CameraCallback(
402 onMoveFinished: (completed) {
403 print(
"Transition to $name scenario ${completed ? 'completed' : 'cancelled'}");
407 _locationWindow!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback);
408 print(
"Transitioning to $name scenario");
416 if (_cameraListener !=
null && _locationWindow !=
null) {
417 _locationWindow!.removeCameraListener(_cameraListener!);
418 _cameraListener =
null;
419 print(
"Camera listener removed");