Loading...
Searching...
No Matches
LocationWindowCameraExample.java
Go to the documentation of this file.
1package com.navigine.examples;
2
3import com.navigine.idl.java.LocationWindow;
4import com.navigine.idl.java.Camera;
5import com.navigine.idl.java.CameraListener;
6import com.navigine.idl.java.CameraCallback;
7import com.navigine.idl.java.AnimationType;
8import com.navigine.idl.java.CameraUpdateReason;
9import com.navigine.idl.java.Point;
10
11import java.util.ArrayList;
12
19 private LocationWindow locationWindow;
20 private CameraListener cameraListener;
21
23 demonstrateLocationWindowCameraMethods();
24 }
25
29 private void demonstrateLocationWindowCameraMethods() {
30 System.out.println("=== LocationWindowCamera Methods ===");
31
32 demonstrateCameraProperties();
33 demonstrateGetSetCamera();
34 demonstrateCameraListeners();
35 demonstrateFlyToMethod();
36 demonstrateMoveToMethod();
37 demonstrateZoomProperties();
38 demonstrateCameraScenarios();
39 }
40
44 private void demonstrateCameraProperties() {
45 System.out.println("--- Camera Properties Setup ---");
46
47 if (locationWindow == null) {
48 System.out.println("LocationWindow not available yet");
49 return;
50 }
51
52 // [java_LocationWindow_minZoomFactor]
53 // Set minimum zoom factor
54 locationWindow.setMinZoomFactor(10.0f);
55 System.out.println("Set minimum zoom factor to 10.0 pixels per meter");
56 // [java_LocationWindow_minZoomFactor]
57
58 // [java_LocationWindow_maxZoomFactor]
59 // Set maximum zoom factor
60 locationWindow.setMaxZoomFactor(1000.0f);
61 System.out.println("Set maximum zoom factor to 1000.0 pixels per meter");
62 // [java_LocationWindow_maxZoomFactor]
63 }
64
68 private void demonstrateGetSetCamera() {
69 System.out.println("--- getCamera and setCamera Methods ---");
70
71 if (locationWindow == null) {
72 System.out.println("LocationWindow not available yet");
73 return;
74 }
75
76 // [java_LocationWindow_getCamera]
77 // Get current camera position
78 Camera currentCamera = locationWindow.getCamera();
79 System.out.println("Current camera position:");
80 System.out.println(" Point: (" + currentCamera.point.x + ", " + currentCamera.point.y + ")");
81 System.out.println(" Zoom: " + currentCamera.zoom);
82 System.out.println(" Rotation: " + currentCamera.rotation + "°");
83 // [java_LocationWindow_getCamera]
84
85 // [java_Camera_constructor]
86 // Create camera with constructor
87 Point newPoint = new Point(100.0, 200.0);
88 Camera newCamera = new Camera(newPoint, 50.0, 0.0);
89 System.out.println("Created camera with point (" + newPoint.x + ", " + newPoint.y + "), zoom 50.0, rotation 0°");
90 // [java_Camera_constructor]
91
92 // [java_Camera_access]
93 // Access camera properties
94 System.out.println("Camera properties:");
95 System.out.println(" Point: (" + newCamera.point.x + ", " + newCamera.point.y + ")");
96 System.out.println(" Zoom: " + newCamera.zoom);
97 System.out.println(" Rotation: " + newCamera.rotation + "°");
98 // [java_Camera_access]
99
100 // [java_LocationWindow_setCamera]
101 // Set camera position without animation
102 locationWindow.setCamera(newCamera);
103 System.out.println("Set camera position to (" + newPoint.x + ", " + newPoint.y + ") with zoom 50.0 and rotation 0°");
104 // [java_LocationWindow_setCamera]
105
106 // [java_LocationWindow_setCamera_2]
107 // Set camera position with rotation
108 Point rotatedPoint = new Point(150.0, 250.0);
109 Camera rotatedCamera = new Camera(rotatedPoint, 75.0, 45.0);
110 locationWindow.setCamera(rotatedCamera);
111 System.out.println("Set camera position to (" + rotatedPoint.x + ", " + rotatedPoint.y + ") with zoom 75.0 and rotation 45°");
112 // [java_LocationWindow_setCamera_2]
113
114 // Test different camera positions
115 Camera[] testCameras = {
116 new Camera(new Point(0.0, 0.0), 10.0, 0.0), // Overview camera
117 new Camera(new Point(50.0, 75.0), 500.0, 0.0), // Detail camera
118 new Camera(new Point(100.0, 150.0), 100.0, 30.0), // Angled camera
119 };
120
121 for (int i = 0; i < testCameras.length; i++) {
122 Camera camera = testCameras[i];
123 locationWindow.setCamera(camera);
124 System.out.println("Test camera " + i + ": Point (" + camera.point.x + ", " + camera.point.y + "), Zoom " + camera.zoom + ", Rotation " + camera.rotation + "°");
125 }
126 }
127
131 private void demonstrateCameraListeners() {
132 System.out.println("--- Camera Listener Methods ---");
133
134 if (locationWindow == null) {
135 System.out.println("LocationWindow not available yet");
136 return;
137 }
138
139 // [java_LocationWindow_addCameraListener]
140 // Add camera listener
141 cameraListener = new CameraListenerImpl();
142 locationWindow.addCameraListener(cameraListener);
143 System.out.println("Added camera listener");
144 // [java_LocationWindow_addCameraListener]
145
146 // [java_LocationWindow_removeCameraListener]
147 // Remove camera listener
148 locationWindow.removeCameraListener(cameraListener);
149 cameraListener = null;
150 System.out.println("Removed camera listener");
151 // [java_LocationWindow_removeCameraListener]
152
153 // Test multiple listeners
154 CameraListener[] listeners = {
155 new CameraListenerImpl(),
156 new CameraListenerImpl(),
157 new CameraListenerImpl(),
158 };
159
160 for (int i = 0; i < listeners.length; i++) {
161 locationWindow.addCameraListener(listeners[i]);
162 System.out.println("Added camera listener " + i);
163 }
164
165 for (int i = 0; i < listeners.length; i++) {
166 locationWindow.removeCameraListener(listeners[i]);
167 System.out.println("Removed camera listener " + i);
168 }
169 }
170
174 private void demonstrateFlyToMethod() {
175 System.out.println("--- flyTo Method ---");
176
177 if (locationWindow == null) {
178 System.out.println("LocationWindow not available yet");
179 return;
180 }
181
182 // [java_LocationWindow_flyTo]
183 // Fly to position with smooth animation
184 Point targetPoint = new Point(150.0, 250.0);
185 Camera targetCamera = new Camera(targetPoint, 75.0, 45.0);
186 CameraCallback callback = new CameraCallbackImpl();
187 locationWindow.flyTo(targetCamera, 2000, callback);
188 System.out.println("Started fly to animation to point (" + targetPoint.x + ", " + targetPoint.y + ")");
189 // [java_LocationWindow_flyTo]
190
191 // [java_LocationWindow_flyTo_2]
192 // Fly to another position with different duration
193 Point targetPoint2 = new Point(300.0, 400.0);
194 Camera targetCamera2 = new Camera(targetPoint2, 25.0, 180.0);
195 CameraCallback callback2 = new CameraCallbackImpl();
196 locationWindow.flyTo(targetCamera2, 3000, callback2);
197 System.out.println("Started fly to animation to point (" + targetPoint2.x + ", " + targetPoint2.y + ") with 3 second duration");
198 // [java_LocationWindow_flyTo_2]
199
200 // Test fly to with different parameters
201 Object[][] flyToTests = {
202 {new Point(50.0, 50.0), 100.0, 0.0, 1000},
203 {new Point(200.0, 300.0), 200.0, 90.0, 1500},
204 {new Point(400.0, 100.0), 50.0, 270.0, 2500},
205 };
206
207 for (int i = 0; i < flyToTests.length; i++) {
208 Point point = (Point) flyToTests[i][0];
209 double zoom = (Double) flyToTests[i][1];
210 double rotation = (Double) flyToTests[i][2];
211 int duration = (Integer) flyToTests[i][3];
212
213 Camera camera = new Camera(point, zoom, rotation);
214 CameraCallback testCallback = new CameraCallbackImpl();
215 locationWindow.flyTo(camera, duration, testCallback);
216 System.out.println("Fly to test " + i + ": Point (" + point.x + ", " + point.y + "), Zoom " + zoom + ", Rotation " + rotation + "°, Duration " + duration + "ms");
217 }
218 }
219
223 private void demonstrateMoveToMethod() {
224 System.out.println("--- moveTo Method ---");
225
226 if (locationWindow == null) {
227 System.out.println("LocationWindow not available yet");
228 return;
229 }
230
231 // [java_LocationWindow_moveTo]
232 // Move to position with linear animation
233 Point targetPoint = new Point(200.0, 300.0);
234 Camera targetCamera = new Camera(targetPoint, 100.0, 90.0);
235 CameraCallback callback = new CameraCallbackImpl();
236 locationWindow.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback);
237 System.out.println("Started move to with linear animation");
238 // [java_LocationWindow_moveTo]
239
240 // [java_LocationWindow_moveTo_2]
241 // Move to position with cubic animation
242 CameraCallback callback2 = new CameraCallbackImpl();
243 locationWindow.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2);
244 System.out.println("Started move to with cubic animation");
245 // [java_LocationWindow_moveTo_2]
246
247 // [java_LocationWindow_moveTo_3]
248 // Move to position with sine animation
249 CameraCallback callback3 = new CameraCallbackImpl();
250 locationWindow.moveTo(targetCamera, 1500, AnimationType.SINE, callback3);
251 System.out.println("Started move to with sine animation");
252 // [java_LocationWindow_moveTo_3]
253
254 // [java_LocationWindow_moveTo_4]
255 // Move to position without animation
256 Point instantPoint = new Point(300.0, 400.0);
257 Camera instantCamera = new Camera(instantPoint, 25.0, 180.0);
258 CameraCallback instantCallback = new CameraCallbackImpl();
259 locationWindow.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback);
260 System.out.println("Executed instant move to position (" + instantPoint.x + ", " + instantPoint.y + ")");
261 // [java_LocationWindow_moveTo_4]
262
263 // Test move to with different animation types
264 // [java_AnimationType_enum]
265 AnimationType[] animationTypes = {
266 AnimationType.LINEAR,
267 AnimationType.CUBIC,
268 AnimationType.QUINT,
269 AnimationType.SINE,
270 AnimationType.NONE,
271 };
272 // [java_AnimationType_enum]
273
274 for (int i = 0; i < animationTypes.length; i++) {
275 AnimationType animationType = animationTypes[i];
276 Point testPoint = new Point(100.0 + i * 50.0, 200.0 + i * 50.0);
277 Camera testCamera = new Camera(testPoint, 50.0 + i * 10.0, i * 30.0);
278 CameraCallback testCallback = new CameraCallbackImpl();
279 locationWindow.moveTo(testCamera, 1000, animationType, testCallback);
280 System.out.println("Move to test " + i + ": Animation " + animationType.name() + ", Point (" + testPoint.x + ", " + testPoint.y + ")");
281 }
282 }
283
287 private void demonstrateZoomProperties() {
288 System.out.println("--- Zoom Properties ---");
289
290 if (locationWindow == null) {
291 System.out.println("LocationWindow not available yet");
292 return;
293 }
294
295 // [java_LocationWindow_getZoomFactor]
296 // Get current zoom factor
297 float currentZoom = locationWindow.getZoomFactor();
298 System.out.println("Current zoom factor: " + currentZoom + " pixels per meter");
299 // [java_LocationWindow_getZoomFactor]
300
301 // [java_LocationWindow_setZoomFactor]
302 // Set new zoom factor
303 locationWindow.setZoomFactor(200.0f);
304 System.out.println("Set zoom factor to 200.0 pixels per meter");
305 // [java_LocationWindow_setZoomFactor]
306
307 // [java_LocationWindow_getMinZoomFactor]
308 // Get minimum zoom factor
309 float minZoom = locationWindow.getMinZoomFactor();
310 System.out.println("Minimum zoom factor: " + minZoom + " pixels per meter");
311 // [java_LocationWindow_getMinZoomFactor]
312
313 // [java_LocationWindow_getMaxZoomFactor]
314 // Get maximum zoom factor
315 float maxZoom = locationWindow.getMaxZoomFactor();
316 System.out.println("Maximum zoom factor: " + maxZoom + " pixels per meter");
317 // [java_LocationWindow_getMaxZoomFactor]
318
319 // Test zoom factor changes
320 float[] zoomLevels = {50.0f, 100.0f, 150.0f, 300.0f, 500.0f, 800.0f};
321
322 for (int i = 0; i < zoomLevels.length; i++) {
323 float zoom = zoomLevels[i];
324 locationWindow.setZoomFactor(zoom);
325 System.out.println("Set zoom factor to " + zoom + " pixels per meter");
326
327 // Verify the change
328 float actualZoom = locationWindow.getZoomFactor();
329 System.out.println("Actual zoom factor: " + actualZoom + " pixels per meter");
330 }
331 }
332
336 private void demonstrateCameraScenarios() {
337 System.out.println("--- Camera Scenarios ---");
338
339 if (locationWindow == null) {
340 System.out.println("LocationWindow not available yet");
341 return;
342 }
343
344 // [java_LocationWindow_camera_scenarios]
345 // Create cameras for different scenarios
346 Camera overviewCamera = new Camera(new Point(0.0, 0.0), 10.0, 0.0);
347 Camera detailCamera = new Camera(new Point(50.0, 75.0), 500.0, 0.0);
348 Camera angledCamera = new Camera(new Point(100.0, 150.0), 100.0, 30.0);
349
350 System.out.println("Created cameras for different scenarios:");
351 System.out.println(" Overview camera: zoom " + overviewCamera.zoom);
352 System.out.println(" Detail camera: zoom " + detailCamera.zoom);
353 System.out.println(" Angled camera: rotation " + angledCamera.rotation + "°");
354 // [java_LocationWindow_camera_scenarios]
355
356 // Test scenario transitions
357 Camera[] scenarios = {overviewCamera, detailCamera, angledCamera};
358 String[] scenarioNames = {"Overview", "Detail", "Angled"};
359
360 for (int i = 0; i < scenarios.length; i++) {
361 Camera scenario = scenarios[i];
362 String name = scenarioNames[i];
363
364 CameraCallback scenarioCallback = new CameraCallbackImpl();
365 locationWindow.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback);
366 System.out.println("Transitioning to " + name + " scenario");
367 }
368 }
369
373 public void cleanup() {
374 if (cameraListener != null && locationWindow != null) {
375 locationWindow.removeCameraListener(cameraListener);
376 cameraListener = null;
377 System.out.println("Camera listener removed");
378 }
379 }
380}
381
385class CameraListenerImpl implements CameraListener {
386 // [java_CameraListener_onCameraPositionChanged]
387 @Override
388 public void onCameraPositionChanged(CameraUpdateReason reason, boolean finished) {
389 String reasonText = (reason == CameraUpdateReason.GESTURES) ? "user gestures" : "application";
390 String statusText = finished ? "finished" : "in progress";
391
392 System.out.println("Camera position changed: " + reasonText + ", status: " + statusText);
393
394 if (finished) {
395 System.out.println("Camera movement completed");
396 }
397 }
398 // [java_CameraListener_onCameraPositionChanged]
399}
400
404class CameraCallbackImpl implements CameraCallback {
405 // [java_CameraCallback_onMoveFinished]
406 @Override
407 public void onMoveFinished(boolean completed) {
408 if (completed) {
409 System.out.println("Camera movement completed successfully");
410 } else {
411 System.out.println("Camera movement was cancelled");
412 }
413 }
414 // [java_CameraCallback_onMoveFinished]
415}
416
420class CameraUtils {
424 public static Camera createCenteredCamera(double x, double y, double zoom) {
425 return new Camera(new Point(x, y), zoom, 0.0);
426 }
427
431 public static Camera createRotatedCamera(double x, double y, double zoom, double rotation) {
432 return new Camera(new Point(x, y), zoom, rotation);
433 }
434
438 public static boolean isValidCamera(Camera camera) {
439 return camera.zoom > 0 &&
440 camera.rotation >= 0 && camera.rotation < 360;
441 }
442
446 public static Camera createAreaCamera(double centerX, double centerY, double width, double height) {
447 // Calculate zoom based on area size
448 double zoom = 100.0 / Math.max(width, height);
449 return new Camera(new Point(centerX, centerY), zoom, 0.0);
450 }
451
455 public static Camera createPathCamera(ArrayList<Point> points) {
456 if (points.isEmpty()) {
457 return new Camera(new Point(0.0, 0.0), 100.0, 0.0);
458 }
459
460 // Find path center
461 double centerX = 0.0, centerY = 0.0;
462 for (Point point : points) {
463 centerX += point.x;
464 centerY += point.y;
465 }
466 centerX /= points.size();
467 centerY /= points.size();
468
469 // Calculate area size
470 double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE;
471 double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;
472
473 for (Point point : points) {
474 minX = Math.min(minX, point.x);
475 minY = Math.min(minY, point.y);
476 maxX = Math.max(maxX, point.x);
477 maxY = Math.max(maxY, point.y);
478 }
479
480 double width = maxX - minX;
481 double height = maxY - minY;
482
483 return createAreaCamera(centerX, centerY, width, height);
484 }
485}
486
490class Main {
491 public static void main(String[] args) {
492 // Create example instance
493 LocationWindowCameraExample example = new LocationWindowCameraExample();
494
495 // Assume we have LocationWindow
496 // LocationWindow locationWindow = getLocationWindow();
497 // example.locationWindow = locationWindow;
498
499 // Demonstrate methods
500 System.out.println("=== LocationWindowCamera Examples ===");
501
502 // Cleanup
503 example.cleanup();
504
505 System.out.println("Examples ready to use!");
506 }
507}