1package com.navigine.examples
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
12 * LocationWindowCamera usage example for Kotlin
13 * Demonstrates specific methods: getCamera, setCamera, addCameraListener, removeCameraListener,
14 * flyTo, moveTo, zoomFactor, minZoomFactor, maxZoomFactor
16class LocationWindowCameraExample {
17 private var locationWindow: LocationWindow? = null
18 private var cameraListener: CameraListener? = null
21 demonstrateLocationWindowCameraMethods()
25 * Demonstrate LocationWindowCamera methods
27 private fun demonstrateLocationWindowCameraMethods() {
28 println("=== LocationWindowCamera Methods ===")
30 demonstrateCameraProperties()
31 demonstrateGetSetCamera()
32 demonstrateCameraListeners()
33 demonstrateFlyToMethod()
34 demonstrateMoveToMethod()
35 demonstrateZoomProperties()
36 demonstrateCameraScenarios()
40 * Demonstrate camera properties setup
42 private fun demonstrateCameraProperties() {
43 println("--- Camera Properties Setup ---")
45 if (locationWindow == null) {
46 println("LocationWindow not available yet")
50 // [kotlin_LocationWindow_minZoomFactor]
51 // Set minimum zoom factor
52 locationWindow!!.minZoomFactor = 10.0f
53 println("Set minimum zoom factor to 10.0 pixels per meter")
54 // [kotlin_LocationWindow_minZoomFactor]
56 // [kotlin_LocationWindow_maxZoomFactor]
57 // Set maximum zoom factor
58 locationWindow!!.maxZoomFactor = 1000.0f
59 println("Set maximum zoom factor to 1000.0 pixels per meter")
60 // [kotlin_LocationWindow_maxZoomFactor]
64 * Demonstrate getCamera and setCamera methods
66 private fun demonstrateGetSetCamera() {
67 println("--- getCamera and setCamera Methods ---")
69 if (locationWindow == null) {
70 println("LocationWindow not available yet")
74 // [kotlin_LocationWindow_getCamera]
75 // Get current camera position
76 val currentCamera = locationWindow!!.camera
77 println("Current camera position:")
78 println(" Point: (${currentCamera.point.x}, ${currentCamera.point.y})")
79 println(" Zoom: ${currentCamera.zoom}")
80 println(" Rotation: ${currentCamera.rotation}°")
81 println(" Tilt: ${currentCamera.tilt}° (0° = straight downward / map from above)")
82 // [kotlin_LocationWindow_getCamera]
84 // [kotlin_Camera_constructor]
85 // Create camera with constructor
86 val newPoint = Point(100.0, 200.0)
87 val newCamera = Camera(newPoint, 50.0, 0.0, 0.0)
88 println("Created camera with point (${newPoint.x}, ${newPoint.y}), zoom 50.0, rotation 0°, tilt 0°")
89 // [kotlin_Camera_constructor]
91 // [kotlin_Camera_access]
92 // Access camera properties
93 println("Camera properties:")
94 println(" Point: (${newCamera.point.x}, ${newCamera.point.y})")
95 println(" Zoom: ${newCamera.zoom}")
96 println(" Rotation: ${newCamera.rotation}°")
97 println(" Tilt: ${newCamera.tilt}°")
98 // [kotlin_Camera_access]
100 // [kotlin_LocationWindow_setCamera]
101 // Set camera position without animation
102 locationWindow!!.camera = newCamera
103 println("Set camera position to (${newPoint.x}, ${newPoint.y}) with zoom 50.0, rotation 0°, tilt 0°")
104 // [kotlin_LocationWindow_setCamera]
106 // [kotlin_LocationWindow_setCamera_2]
107 // Set camera position with rotation
108 val rotatedPoint = Point(150.0, 250.0)
109 val rotatedCamera = Camera(rotatedPoint, 75.0, 45.0, 0.0)
110 locationWindow!!.camera = rotatedCamera
111 println("Set camera position to (${rotatedPoint.x}, ${rotatedPoint.y}) with zoom 75.0 and rotation 45°")
112 // [kotlin_LocationWindow_setCamera_2]
114 val tiltedCamera = Camera(rotatedPoint, 75.0, 45.0, 40.0)
115 locationWindow!!.camera = tiltedCamera
116 println("Set camera with tilt ${tiltedCamera.tilt}° for a perspective view")
118 // Test different camera positions
119 val testCameras = listOf(
120 Camera(Point(0.0, 0.0), 10.0, 0.0, 0.0), // Overview camera
121 Camera(Point(50.0, 75.0), 500.0, 0.0, 0.0), // Detail camera
122 Camera(Point(100.0, 150.0), 100.0, 30.0, 0.0), // Angled camera
125 testCameras.forEachIndexed { i, camera ->
126 locationWindow!!.camera = camera
127 println("Test camera $i: Point (${camera.point.x}, ${camera.point.y}), Zoom ${camera.zoom}, Rotation ${camera.rotation}°, Tilt ${camera.tilt}°")
132 * Demonstrate camera listener methods
134 private fun demonstrateCameraListeners() {
135 println("--- Camera Listener Methods ---")
137 if (locationWindow == null) {
138 println("LocationWindow not available yet")
142 // [kotlin_LocationWindow_addCameraListener]
143 // Add camera listener
144 cameraListener = CameraListenerImpl()
145 locationWindow!!.addCameraListener(cameraListener!!)
146 println("Added camera listener")
147 // [kotlin_LocationWindow_addCameraListener]
149 // [kotlin_LocationWindow_removeCameraListener]
150 // Remove camera listener
151 locationWindow!!.removeCameraListener(cameraListener!!)
152 cameraListener = null
153 println("Removed camera listener")
154 // [kotlin_LocationWindow_removeCameraListener]
156 // Test multiple listeners
157 val listeners = listOf(
158 CameraListenerImpl(),
159 CameraListenerImpl(),
160 CameraListenerImpl(),
163 listeners.forEachIndexed { i, listener ->
164 locationWindow!!.addCameraListener(listener)
165 println("Added camera listener $i")
168 listeners.forEachIndexed { i, listener ->
169 locationWindow!!.removeCameraListener(listener)
170 println("Removed camera listener $i")
175 * Demonstrate flyTo method
177 private fun demonstrateFlyToMethod() {
178 println("--- flyTo Method ---")
180 if (locationWindow == null) {
181 println("LocationWindow not available yet")
185 // [kotlin_LocationWindow_flyTo]
186 // Fly to position with smooth animation
187 val targetPoint = Point(150.0, 250.0)
188 val targetCamera = Camera(targetPoint, 75.0, 45.0, 30.0)
189 val callback = CameraCallbackImpl()
190 locationWindow!!.flyTo(targetCamera, 2000, callback)
191 println("Started fly to animation to point (${targetPoint.x}, ${targetPoint.y})")
192 // [kotlin_LocationWindow_flyTo]
194 // [kotlin_LocationWindow_flyTo_2]
195 // Fly to another position with different duration
196 val targetPoint2 = Point(300.0, 400.0)
197 val targetCamera2 = Camera(targetPoint2, 25.0, 180.0, 0.0)
198 val callback2 = CameraCallbackImpl()
199 locationWindow!!.flyTo(targetCamera2, 3000, callback2)
200 println("Started fly to animation to point (${targetPoint2.x}, ${targetPoint2.y}) with 3 second duration")
201 // [kotlin_LocationWindow_flyTo_2]
203 // Test fly to with different parameters
204 val flyToTests = listOf(
205 mapOf("point" to Point(50.0, 50.0), "zoom" to 100.0, "rotation" to 0.0, "duration" to 1000),
206 mapOf("point" to Point(200.0, 300.0), "zoom" to 200.0, "rotation" to 90.0, "duration" to 1500),
207 mapOf("point" to Point(400.0, 100.0), "zoom" to 50.0, "rotation" to 270.0, "duration" to 2500),
210 flyToTests.forEachIndexed { i, test ->
211 val point = test["point"] as Point
212 val zoom = test["zoom"] as Double
213 val rotation = test["rotation"] as Double
214 val duration = test["duration"] as Int
216 val camera = Camera(point, zoom, rotation, 0.0)
217 val testCallback = CameraCallbackImpl()
218 locationWindow!!.flyTo(camera, duration, testCallback)
219 println("Fly to test $i: Point (${point.x}, ${point.y}), Zoom $zoom, Rotation ${rotation}°, Duration ${duration}ms")
224 * Demonstrate moveTo method
226 private fun demonstrateMoveToMethod() {
227 println("--- moveTo Method ---")
229 if (locationWindow == null) {
230 println("LocationWindow not available yet")
234 // [kotlin_LocationWindow_moveTo]
235 // Move to position with linear animation
236 val targetPoint = Point(200.0, 300.0)
237 val targetCamera = Camera(targetPoint, 100.0, 90.0, 0.0)
238 val callback = CameraCallbackImpl()
239 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback)
240 println("Started move to with linear animation")
241 // [kotlin_LocationWindow_moveTo]
243 // [kotlin_LocationWindow_moveTo_2]
244 // Move to position with cubic animation
245 val callback2 = CameraCallbackImpl()
246 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2)
247 println("Started move to with cubic animation")
248 // [kotlin_LocationWindow_moveTo_2]
250 // [kotlin_LocationWindow_moveTo_3]
251 // Move to position with sine animation
252 val callback3 = CameraCallbackImpl()
253 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.SINE, callback3)
254 println("Started move to with sine animation")
255 // [kotlin_LocationWindow_moveTo_3]
257 // [kotlin_LocationWindow_moveTo_4]
258 // Move to position without animation
259 val instantPoint = Point(300.0, 400.0)
260 val instantCamera = Camera(instantPoint, 25.0, 180.0, 0.0)
261 val instantCallback = CameraCallbackImpl()
262 locationWindow!!.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback)
263 println("Executed instant move to position (${instantPoint.x}, ${instantPoint.y})")
264 // [kotlin_LocationWindow_moveTo_4]
266 // Test move to with different animation types
267 // [kotlin_AnimationType_enum]
268 val animationTypes = listOf(
269 AnimationType.LINEAR,
275 // [kotlin_AnimationType_enum]
277 animationTypes.forEachIndexed { i, animationType ->
278 val testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0)
279 val testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0, 0.0)
280 val testCallback = CameraCallbackImpl()
281 locationWindow!!.moveTo(testCamera, 1000, animationType, testCallback)
282 println("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})")
287 * Demonstrate zoom properties
289 private fun demonstrateZoomProperties() {
290 println("--- Zoom Properties ---")
292 if (locationWindow == null) {
293 println("LocationWindow not available yet")
297 // [kotlin_LocationWindow_getZoomFactor]
298 // Get current zoom factor
299 val currentZoom = locationWindow!!.zoomFactor
300 println("Current zoom factor: $currentZoom pixels per meter")
301 // [kotlin_LocationWindow_getZoomFactor]
303 // [kotlin_LocationWindow_setZoomFactor]
304 // Set new zoom factor
305 locationWindow!!.zoomFactor = 200.0f
306 println("Set zoom factor to 200.0 pixels per meter")
307 // [kotlin_LocationWindow_setZoomFactor]
309 // [kotlin_LocationWindow_getMinZoomFactor]
310 // Get minimum zoom factor
311 val minZoom = locationWindow!!.minZoomFactor
312 println("Minimum zoom factor: $minZoom pixels per meter")
313 // [kotlin_LocationWindow_getMinZoomFactor]
315 // [kotlin_LocationWindow_getMaxZoomFactor]
316 // Get maximum zoom factor
317 val maxZoom = locationWindow!!.maxZoomFactor
318 println("Maximum zoom factor: $maxZoom pixels per meter")
319 // [kotlin_LocationWindow_getMaxZoomFactor]
321 // Test zoom factor changes
322 val zoomLevels = listOf(50.0f, 100.0f, 150.0f, 300.0f, 500.0f, 800.0f)
324 zoomLevels.forEach { zoom ->
325 locationWindow!!.zoomFactor = zoom
326 println("Set zoom factor to $zoom pixels per meter")
329 val actualZoom = locationWindow!!.zoomFactor
330 println("Actual zoom factor: $actualZoom pixels per meter")
335 * Demonstrate camera scenarios
337 private fun demonstrateCameraScenarios() {
338 println("--- Camera Scenarios ---")
340 if (locationWindow == null) {
341 println("LocationWindow not available yet")
345 // [kotlin_LocationWindow_camera_scenarios]
346 // Create cameras for different scenarios
347 val overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0, 0.0)
348 val detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0, 0.0)
349 val angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0, 25.0)
351 println("Created cameras for different scenarios:")
352 println(" Overview camera: zoom ${overviewCamera.zoom}")
353 println(" Detail camera: zoom ${detailCamera.zoom}")
354 println(" Angled camera: rotation ${angledCamera.rotation}°, tilt ${angledCamera.tilt}°")
355 // [kotlin_LocationWindow_camera_scenarios]
357 // Test scenario transitions
358 val scenarios = listOf(overviewCamera, detailCamera, angledCamera)
359 val scenarioNames = listOf("Overview", "Detail", "Angled")
361 scenarios.forEachIndexed { i, scenario ->
362 val name = scenarioNames[i]
363 val scenarioCallback = CameraCallbackImpl()
364 locationWindow!!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback)
365 println("Transitioning to $name scenario")
373 cameraListener?.let { listener ->
374 locationWindow?.removeCameraListener(listener)
375 cameraListener = null
376 println("Camera listener removed")
382 * Camera listener implementation
384class CameraListenerImpl : CameraListener {
385 // [kotlin_CameraListener_onCameraPositionChanged]
386 override fun onCameraPositionChanged(reason: CameraUpdateReason, finished: Boolean) {
387 val reasonText = if (reason == CameraUpdateReason.GESTURES) "user gestures" else "application"
388 val statusText = if (finished) "finished" else "in progress"
390 println("Camera position changed: $reasonText, status: $statusText")
393 println("Camera movement completed")
396 // [kotlin_CameraListener_onCameraPositionChanged]
400 * Camera callback implementation
402class CameraCallbackImpl : CameraCallback {
403 // [kotlin_CameraCallback_onMoveFinished]
404 override fun onMoveFinished(completed: Boolean) {
406 println("Camera movement completed successfully")
408 println("Camera movement was cancelled")
411 // [kotlin_CameraCallback_onMoveFinished]
419 * Create camera for centered point with given zoom
421 fun createCenteredCamera(x: Double, y: Double, zoom: Double): Camera {
422 return Camera(Point(x, y), zoom, 0.0, 0.0)
426 * Create camera with rotation
428 fun createRotatedCamera(x: Double, y: Double, zoom: Double, rotation: Double): Camera {
429 return Camera(Point(x, y), zoom, rotation, 0.0)
433 * Create camera with tilt in degrees (see [Camera.tilt]).
435 fun createTiltedCamera(x: Double, y: Double, zoom: Double, rotation: Double, tilt: Double): Camera {
436 return Camera(Point(x, y), zoom, rotation, tilt)
440 * Validate camera position
442 fun isValidCamera(camera: Camera): Boolean {
443 return camera.zoom > 0 &&
444 camera.rotation >= 0 && camera.rotation < 360 &&
449 * Create camera for showing area
451 fun createAreaCamera(centerX: Double, centerY: Double, width: Double, height: Double): Camera {
452 // Calculate zoom based on area size
453 val zoom = 100.0 / maxOf(width, height)
454 return Camera(Point(centerX, centerY), zoom, 0.0, 0.0)
458 * Create camera for showing path
460 fun createPathCamera(points: List<Point>): Camera {
461 if (points.isEmpty()) {
462 return Camera(Point(0.0, 0.0), 100.0, 0.0, 0.0)
466 val centerX = points.map { it.x }.average()
467 val centerY = points.map { it.y }.average()
469 // Calculate area size
470 val minX = points.minOf { it.x }
471 val minY = points.minOf { it.y }
472 val maxX = points.maxOf { it.x }
473 val maxY = points.maxOf { it.y }
475 val width = maxX - minX
476 val height = maxY - minY
478 return createAreaCamera(centerX, centerY, width, height)
482 * Create camera for showing multiple points
484 fun createMultiPointCamera(points: List<Point>, padding: Double = 10.0): Camera {
485 if (points.isEmpty()) {
486 return Camera(Point(0.0, 0.0), 100.0, 0.0, 0.0)
490 val centerX = points.map { it.x }.average()
491 val centerY = points.map { it.y }.average()
493 // Calculate area size with padding
494 val minX = points.minOf { it.x } - padding
495 val minY = points.minOf { it.y } - padding
496 val maxX = points.maxOf { it.x } + padding
497 val maxY = points.maxOf { it.y } + padding
499 val width = maxX - minX
500 val height = maxY - minY
502 return createAreaCamera(centerX, centerY, width, height)
507 * Extensions for convenient camera operations
509fun LocationWindow.zoomTo(point: Point, zoom: Double, duration: Int = 1000) {
511 val nextCamera = Camera(point, zoom, c.rotation, c.tilt)
512 val callback = CameraCallbackImpl()
513 moveTo(nextCamera, duration, AnimationType.CUBIC, callback)
516fun LocationWindow.panTo(point: Point, duration: Int = 1000) {
517 val currentCamera = camera
518 val newCamera = Camera(point, currentCamera.zoom, currentCamera.rotation, currentCamera.tilt)
519 val callback = CameraCallbackImpl()
520 moveTo(newCamera, duration, AnimationType.LINEAR, callback)
523fun LocationWindow.rotateTo(rotation: Double, duration: Int = 1000) {
524 val currentCamera = camera
525 val newCamera = Camera(currentCamera.point, currentCamera.zoom, rotation, currentCamera.tilt)
526 val callback = CameraCallbackImpl()
527 moveTo(newCamera, duration, AnimationType.SINE, callback)
534 // Create example instance
535 val example = LocationWindowCameraExample()
537 // Assume we have LocationWindow
538 // val locationWindow: LocationWindow = getLocationWindow()
539 // example.locationWindow = locationWindow
541 // Demonstrate methods
542 println("=== LocationWindowCamera Examples ===")
547 println("Examples ready to use!")