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 // [kotlin_LocationWindow_getCamera]
83 // [kotlin_Camera_constructor]
84 // Create camera with constructor
85 val newPoint = Point(100.0, 200.0)
86 val newCamera = Camera(newPoint, 50.0, 0.0)
87 println("Created camera with point (${newPoint.x}, ${newPoint.y}), zoom 50.0, rotation 0°")
88 // [kotlin_Camera_constructor]
90 // [kotlin_Camera_access]
91 // Access camera properties
92 println("Camera properties:")
93 println(" Point: (${newCamera.point.x}, ${newCamera.point.y})")
94 println(" Zoom: ${newCamera.zoom}")
95 println(" Rotation: ${newCamera.rotation}°")
96 // [kotlin_Camera_access]
98 // [kotlin_LocationWindow_setCamera]
99 // Set camera position without animation
100 locationWindow!!.camera = newCamera
101 println("Set camera position to (${newPoint.x}, ${newPoint.y}) with zoom 50.0 and rotation 0°")
102 // [kotlin_LocationWindow_setCamera]
104 // [kotlin_LocationWindow_setCamera_2]
105 // Set camera position with rotation
106 val rotatedPoint = Point(150.0, 250.0)
107 val rotatedCamera = Camera(rotatedPoint, 75.0, 45.0)
108 locationWindow!!.camera = rotatedCamera
109 println("Set camera position to (${rotatedPoint.x}, ${rotatedPoint.y}) with zoom 75.0 and rotation 45°")
110 // [kotlin_LocationWindow_setCamera_2]
112 // Test different camera positions
113 val testCameras = listOf(
114 Camera(Point(0.0, 0.0), 10.0, 0.0), // Overview camera
115 Camera(Point(50.0, 75.0), 500.0, 0.0), // Detail camera
116 Camera(Point(100.0, 150.0), 100.0, 30.0), // Angled camera
119 testCameras.forEachIndexed { i, camera ->
120 locationWindow!!.camera = camera
121 println("Test camera $i: Point (${camera.point.x}, ${camera.point.y}), Zoom ${camera.zoom}, Rotation ${camera.rotation}°")
126 * Demonstrate camera listener methods
128 private fun demonstrateCameraListeners() {
129 println("--- Camera Listener Methods ---")
131 if (locationWindow == null) {
132 println("LocationWindow not available yet")
136 // [kotlin_LocationWindow_addCameraListener]
137 // Add camera listener
138 cameraListener = CameraListenerImpl()
139 locationWindow!!.addCameraListener(cameraListener!!)
140 println("Added camera listener")
141 // [kotlin_LocationWindow_addCameraListener]
143 // [kotlin_LocationWindow_removeCameraListener]
144 // Remove camera listener
145 locationWindow!!.removeCameraListener(cameraListener!!)
146 cameraListener = null
147 println("Removed camera listener")
148 // [kotlin_LocationWindow_removeCameraListener]
150 // Test multiple listeners
151 val listeners = listOf(
152 CameraListenerImpl(),
153 CameraListenerImpl(),
154 CameraListenerImpl(),
157 listeners.forEachIndexed { i, listener ->
158 locationWindow!!.addCameraListener(listener)
159 println("Added camera listener $i")
162 listeners.forEachIndexed { i, listener ->
163 locationWindow!!.removeCameraListener(listener)
164 println("Removed camera listener $i")
169 * Demonstrate flyTo method
171 private fun demonstrateFlyToMethod() {
172 println("--- flyTo Method ---")
174 if (locationWindow == null) {
175 println("LocationWindow not available yet")
179 // [kotlin_LocationWindow_flyTo]
180 // Fly to position with smooth animation
181 val targetPoint = Point(150.0, 250.0)
182 val targetCamera = Camera(targetPoint, 75.0, 45.0)
183 val callback = CameraCallbackImpl()
184 locationWindow!!.flyTo(targetCamera, 2000, callback)
185 println("Started fly to animation to point (${targetPoint.x}, ${targetPoint.y})")
186 // [kotlin_LocationWindow_flyTo]
188 // [kotlin_LocationWindow_flyTo_2]
189 // Fly to another position with different duration
190 val targetPoint2 = Point(300.0, 400.0)
191 val targetCamera2 = Camera(targetPoint2, 25.0, 180.0)
192 val callback2 = CameraCallbackImpl()
193 locationWindow!!.flyTo(targetCamera2, 3000, callback2)
194 println("Started fly to animation to point (${targetPoint2.x}, ${targetPoint2.y}) with 3 second duration")
195 // [kotlin_LocationWindow_flyTo_2]
197 // Test fly to with different parameters
198 val flyToTests = listOf(
199 mapOf("point" to Point(50.0, 50.0), "zoom" to 100.0, "rotation" to 0.0, "duration" to 1000),
200 mapOf("point" to Point(200.0, 300.0), "zoom" to 200.0, "rotation" to 90.0, "duration" to 1500),
201 mapOf("point" to Point(400.0, 100.0), "zoom" to 50.0, "rotation" to 270.0, "duration" to 2500),
204 flyToTests.forEachIndexed { i, test ->
205 val point = test["point"] as Point
206 val zoom = test["zoom"] as Double
207 val rotation = test["rotation"] as Double
208 val duration = test["duration"] as Int
210 val camera = Camera(point, zoom, rotation)
211 val testCallback = CameraCallbackImpl()
212 locationWindow!!.flyTo(camera, duration, testCallback)
213 println("Fly to test $i: Point (${point.x}, ${point.y}), Zoom $zoom, Rotation ${rotation}°, Duration ${duration}ms")
218 * Demonstrate moveTo method
220 private fun demonstrateMoveToMethod() {
221 println("--- moveTo Method ---")
223 if (locationWindow == null) {
224 println("LocationWindow not available yet")
228 // [kotlin_LocationWindow_moveTo]
229 // Move to position with linear animation
230 val targetPoint = Point(200.0, 300.0)
231 val targetCamera = Camera(targetPoint, 100.0, 90.0)
232 val callback = CameraCallbackImpl()
233 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.LINEAR, callback)
234 println("Started move to with linear animation")
235 // [kotlin_LocationWindow_moveTo]
237 // [kotlin_LocationWindow_moveTo_2]
238 // Move to position with cubic animation
239 val callback2 = CameraCallbackImpl()
240 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.CUBIC, callback2)
241 println("Started move to with cubic animation")
242 // [kotlin_LocationWindow_moveTo_2]
244 // [kotlin_LocationWindow_moveTo_3]
245 // Move to position with sine animation
246 val callback3 = CameraCallbackImpl()
247 locationWindow!!.moveTo(targetCamera, 1500, AnimationType.SINE, callback3)
248 println("Started move to with sine animation")
249 // [kotlin_LocationWindow_moveTo_3]
251 // [kotlin_LocationWindow_moveTo_4]
252 // Move to position without animation
253 val instantPoint = Point(300.0, 400.0)
254 val instantCamera = Camera(instantPoint, 25.0, 180.0)
255 val instantCallback = CameraCallbackImpl()
256 locationWindow!!.moveTo(instantCamera, 0, AnimationType.NONE, instantCallback)
257 println("Executed instant move to position (${instantPoint.x}, ${instantPoint.y})")
258 // [kotlin_LocationWindow_moveTo_4]
260 // Test move to with different animation types
261 val animationTypes = listOf(
262 AnimationType.LINEAR,
269 animationTypes.forEachIndexed { i, animationType ->
270 val testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0)
271 val testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0)
272 val testCallback = CameraCallbackImpl()
273 locationWindow!!.moveTo(testCamera, 1000, animationType, testCallback)
274 println("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})")
279 * Demonstrate zoom properties
281 private fun demonstrateZoomProperties() {
282 println("--- Zoom Properties ---")
284 if (locationWindow == null) {
285 println("LocationWindow not available yet")
289 // [kotlin_LocationWindow_getZoomFactor]
290 // Get current zoom factor
291 val currentZoom = locationWindow!!.zoomFactor
292 println("Current zoom factor: $currentZoom pixels per meter")
293 // [kotlin_LocationWindow_getZoomFactor]
295 // [kotlin_LocationWindow_setZoomFactor]
296 // Set new zoom factor
297 locationWindow!!.zoomFactor = 200.0f
298 println("Set zoom factor to 200.0 pixels per meter")
299 // [kotlin_LocationWindow_setZoomFactor]
301 // [kotlin_LocationWindow_getMinZoomFactor]
302 // Get minimum zoom factor
303 val minZoom = locationWindow!!.minZoomFactor
304 println("Minimum zoom factor: $minZoom pixels per meter")
305 // [kotlin_LocationWindow_getMinZoomFactor]
307 // [kotlin_LocationWindow_getMaxZoomFactor]
308 // Get maximum zoom factor
309 val maxZoom = locationWindow!!.maxZoomFactor
310 println("Maximum zoom factor: $maxZoom pixels per meter")
311 // [kotlin_LocationWindow_getMaxZoomFactor]
313 // Test zoom factor changes
314 val zoomLevels = listOf(50.0f, 100.0f, 150.0f, 300.0f, 500.0f, 800.0f)
316 zoomLevels.forEach { zoom ->
317 locationWindow!!.zoomFactor = zoom
318 println("Set zoom factor to $zoom pixels per meter")
321 val actualZoom = locationWindow!!.zoomFactor
322 println("Actual zoom factor: $actualZoom pixels per meter")
327 * Demonstrate camera scenarios
329 private fun demonstrateCameraScenarios() {
330 println("--- Camera Scenarios ---")
332 if (locationWindow == null) {
333 println("LocationWindow not available yet")
337 // [kotlin_LocationWindow_camera_scenarios]
338 // Create cameras for different scenarios
339 val overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0)
340 val detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0)
341 val angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0)
343 println("Created cameras for different scenarios:")
344 println(" Overview camera: zoom ${overviewCamera.zoom}")
345 println(" Detail camera: zoom ${detailCamera.zoom}")
346 println(" Angled camera: rotation ${angledCamera.rotation}°")
347 // [kotlin_LocationWindow_camera_scenarios]
349 // Test scenario transitions
350 val scenarios = listOf(overviewCamera, detailCamera, angledCamera)
351 val scenarioNames = listOf("Overview", "Detail", "Angled")
353 scenarios.forEachIndexed { i, scenario ->
354 val name = scenarioNames[i]
355 val scenarioCallback = CameraCallbackImpl()
356 locationWindow!!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback)
357 println("Transitioning to $name scenario")
365 cameraListener?.let { listener ->
366 locationWindow?.removeCameraListener(listener)
367 cameraListener = null
368 println("Camera listener removed")
374 * Camera listener implementation
376class CameraListenerImpl : CameraListener {
377 // [kotlin_CameraListener_onCameraPositionChanged]
378 override fun onCameraPositionChanged(reason: CameraUpdateReason, finished: Boolean) {
379 val reasonText = if (reason == CameraUpdateReason.GESTURES) "user gestures" else "application"
380 val statusText = if (finished) "finished" else "in progress"
382 println("Camera position changed: $reasonText, status: $statusText")
385 println("Camera movement completed")
388 // [kotlin_CameraListener_onCameraPositionChanged]
392 * Camera callback implementation
394class CameraCallbackImpl : CameraCallback {
395 override fun onMoveFinished(completed: Boolean) {
397 println("Camera movement completed successfully")
399 println("Camera movement was cancelled")
409 * Create camera for centered point with given zoom
411 fun createCenteredCamera(x: Double, y: Double, zoom: Double): Camera {
412 return Camera(Point(x, y), zoom, 0.0)
416 * Create camera with rotation
418 fun createRotatedCamera(x: Double, y: Double, zoom: Double, rotation: Double): Camera {
419 return Camera(Point(x, y), zoom, rotation)
423 * Validate camera position
425 fun isValidCamera(camera: Camera): Boolean {
426 return camera.zoom > 0 &&
427 camera.rotation >= 0 && camera.rotation < 360
431 * Create camera for showing area
433 fun createAreaCamera(centerX: Double, centerY: Double, width: Double, height: Double): Camera {
434 // Calculate zoom based on area size
435 val zoom = 100.0 / maxOf(width, height)
436 return Camera(Point(centerX, centerY), zoom, 0.0)
440 * Create camera for showing path
442 fun createPathCamera(points: List<Point>): Camera {
443 if (points.isEmpty()) {
444 return Camera(Point(0.0, 0.0), 100.0, 0.0)
448 val centerX = points.map { it.x }.average()
449 val centerY = points.map { it.y }.average()
451 // Calculate area size
452 val minX = points.minOf { it.x }
453 val minY = points.minOf { it.y }
454 val maxX = points.maxOf { it.x }
455 val maxY = points.maxOf { it.y }
457 val width = maxX - minX
458 val height = maxY - minY
460 return createAreaCamera(centerX, centerY, width, height)
464 * Create camera for showing multiple points
466 fun createMultiPointCamera(points: List<Point>, padding: Double = 10.0): Camera {
467 if (points.isEmpty()) {
468 return Camera(Point(0.0, 0.0), 100.0, 0.0)
472 val centerX = points.map { it.x }.average()
473 val centerY = points.map { it.y }.average()
475 // Calculate area size with padding
476 val minX = points.minOf { it.x } - padding
477 val minY = points.minOf { it.y } - padding
478 val maxX = points.maxOf { it.x } + padding
479 val maxY = points.maxOf { it.y } + padding
481 val width = maxX - minX
482 val height = maxY - minY
484 return createAreaCamera(centerX, centerY, width, height)
489 * Extensions for convenient camera operations
491fun LocationWindow.zoomTo(point: Point, zoom: Double, duration: Int = 1000) {
492 val camera = Camera(point, zoom, 0.0)
493 val callback = CameraCallbackImpl()
494 moveTo(camera, duration, AnimationType.CUBIC, callback)
497fun LocationWindow.panTo(point: Point, duration: Int = 1000) {
498 val currentCamera = camera
499 val newCamera = Camera(point, currentCamera.zoom, currentCamera.rotation)
500 val callback = CameraCallbackImpl()
501 moveTo(newCamera, duration, AnimationType.LINEAR, callback)
504fun LocationWindow.rotateTo(rotation: Double, duration: Int = 1000) {
505 val currentCamera = camera
506 val newCamera = Camera(currentCamera.point, currentCamera.zoom, rotation)
507 val callback = CameraCallbackImpl()
508 moveTo(newCamera, duration, AnimationType.SINE, callback)
515 // Create example instance
516 val example = LocationWindowCameraExample()
518 // Assume we have LocationWindow
519 // val locationWindow: LocationWindow = getLocationWindow()
520 // example.locationWindow = locationWindow
522 // Demonstrate methods
523 println("=== LocationWindowCamera Examples ===")
528 println("Examples ready to use!")