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 // [kotlin_AnimationType_enum]
262 val animationTypes = listOf(
263 AnimationType.LINEAR,
269 // [kotlin_AnimationType_enum]
271 animationTypes.forEachIndexed { i, animationType ->
272 val testPoint = Point(100.0 + i * 50.0, 200.0 + i * 50.0)
273 val testCamera = Camera(testPoint, 50.0 + i * 10.0, i * 30.0)
274 val testCallback = CameraCallbackImpl()
275 locationWindow!!.moveTo(testCamera, 1000, animationType, testCallback)
276 println("Move to test $i: Animation ${animationType.name}, Point (${testPoint.x}, ${testPoint.y})")
281 * Demonstrate zoom properties
283 private fun demonstrateZoomProperties() {
284 println("--- Zoom Properties ---")
286 if (locationWindow == null) {
287 println("LocationWindow not available yet")
291 // [kotlin_LocationWindow_getZoomFactor]
292 // Get current zoom factor
293 val currentZoom = locationWindow!!.zoomFactor
294 println("Current zoom factor: $currentZoom pixels per meter")
295 // [kotlin_LocationWindow_getZoomFactor]
297 // [kotlin_LocationWindow_setZoomFactor]
298 // Set new zoom factor
299 locationWindow!!.zoomFactor = 200.0f
300 println("Set zoom factor to 200.0 pixels per meter")
301 // [kotlin_LocationWindow_setZoomFactor]
303 // [kotlin_LocationWindow_getMinZoomFactor]
304 // Get minimum zoom factor
305 val minZoom = locationWindow!!.minZoomFactor
306 println("Minimum zoom factor: $minZoom pixels per meter")
307 // [kotlin_LocationWindow_getMinZoomFactor]
309 // [kotlin_LocationWindow_getMaxZoomFactor]
310 // Get maximum zoom factor
311 val maxZoom = locationWindow!!.maxZoomFactor
312 println("Maximum zoom factor: $maxZoom pixels per meter")
313 // [kotlin_LocationWindow_getMaxZoomFactor]
315 // Test zoom factor changes
316 val zoomLevels = listOf(50.0f, 100.0f, 150.0f, 300.0f, 500.0f, 800.0f)
318 zoomLevels.forEach { zoom ->
319 locationWindow!!.zoomFactor = zoom
320 println("Set zoom factor to $zoom pixels per meter")
323 val actualZoom = locationWindow!!.zoomFactor
324 println("Actual zoom factor: $actualZoom pixels per meter")
329 * Demonstrate camera scenarios
331 private fun demonstrateCameraScenarios() {
332 println("--- Camera Scenarios ---")
334 if (locationWindow == null) {
335 println("LocationWindow not available yet")
339 // [kotlin_LocationWindow_camera_scenarios]
340 // Create cameras for different scenarios
341 val overviewCamera = Camera(Point(0.0, 0.0), 10.0, 0.0)
342 val detailCamera = Camera(Point(50.0, 75.0), 500.0, 0.0)
343 val angledCamera = Camera(Point(100.0, 150.0), 100.0, 30.0)
345 println("Created cameras for different scenarios:")
346 println(" Overview camera: zoom ${overviewCamera.zoom}")
347 println(" Detail camera: zoom ${detailCamera.zoom}")
348 println(" Angled camera: rotation ${angledCamera.rotation}°")
349 // [kotlin_LocationWindow_camera_scenarios]
351 // Test scenario transitions
352 val scenarios = listOf(overviewCamera, detailCamera, angledCamera)
353 val scenarioNames = listOf("Overview", "Detail", "Angled")
355 scenarios.forEachIndexed { i, scenario ->
356 val name = scenarioNames[i]
357 val scenarioCallback = CameraCallbackImpl()
358 locationWindow!!.moveTo(scenario, 2000, AnimationType.CUBIC, scenarioCallback)
359 println("Transitioning to $name scenario")
367 cameraListener?.let { listener ->
368 locationWindow?.removeCameraListener(listener)
369 cameraListener = null
370 println("Camera listener removed")
376 * Camera listener implementation
378class CameraListenerImpl : CameraListener {
379 // [kotlin_CameraListener_onCameraPositionChanged]
380 override fun onCameraPositionChanged(reason: CameraUpdateReason, finished: Boolean) {
381 val reasonText = if (reason == CameraUpdateReason.GESTURES) "user gestures" else "application"
382 val statusText = if (finished) "finished" else "in progress"
384 println("Camera position changed: $reasonText, status: $statusText")
387 println("Camera movement completed")
390 // [kotlin_CameraListener_onCameraPositionChanged]
394 * Camera callback implementation
396class CameraCallbackImpl : CameraCallback {
397 // [kotlin_CameraCallback_onMoveFinished]
398 override fun onMoveFinished(completed: Boolean) {
400 println("Camera movement completed successfully")
402 println("Camera movement was cancelled")
405 // [kotlin_CameraCallback_onMoveFinished]
413 * Create camera for centered point with given zoom
415 fun createCenteredCamera(x: Double, y: Double, zoom: Double): Camera {
416 return Camera(Point(x, y), zoom, 0.0)
420 * Create camera with rotation
422 fun createRotatedCamera(x: Double, y: Double, zoom: Double, rotation: Double): Camera {
423 return Camera(Point(x, y), zoom, rotation)
427 * Validate camera position
429 fun isValidCamera(camera: Camera): Boolean {
430 return camera.zoom > 0 &&
431 camera.rotation >= 0 && camera.rotation < 360
435 * Create camera for showing area
437 fun createAreaCamera(centerX: Double, centerY: Double, width: Double, height: Double): Camera {
438 // Calculate zoom based on area size
439 val zoom = 100.0 / maxOf(width, height)
440 return Camera(Point(centerX, centerY), zoom, 0.0)
444 * Create camera for showing path
446 fun createPathCamera(points: List<Point>): Camera {
447 if (points.isEmpty()) {
448 return Camera(Point(0.0, 0.0), 100.0, 0.0)
452 val centerX = points.map { it.x }.average()
453 val centerY = points.map { it.y }.average()
455 // Calculate area size
456 val minX = points.minOf { it.x }
457 val minY = points.minOf { it.y }
458 val maxX = points.maxOf { it.x }
459 val maxY = points.maxOf { it.y }
461 val width = maxX - minX
462 val height = maxY - minY
464 return createAreaCamera(centerX, centerY, width, height)
468 * Create camera for showing multiple points
470 fun createMultiPointCamera(points: List<Point>, padding: Double = 10.0): Camera {
471 if (points.isEmpty()) {
472 return Camera(Point(0.0, 0.0), 100.0, 0.0)
476 val centerX = points.map { it.x }.average()
477 val centerY = points.map { it.y }.average()
479 // Calculate area size with padding
480 val minX = points.minOf { it.x } - padding
481 val minY = points.minOf { it.y } - padding
482 val maxX = points.maxOf { it.x } + padding
483 val maxY = points.maxOf { it.y } + padding
485 val width = maxX - minX
486 val height = maxY - minY
488 return createAreaCamera(centerX, centerY, width, height)
493 * Extensions for convenient camera operations
495fun LocationWindow.zoomTo(point: Point, zoom: Double, duration: Int = 1000) {
496 val camera = Camera(point, zoom, 0.0)
497 val callback = CameraCallbackImpl()
498 moveTo(camera, duration, AnimationType.CUBIC, callback)
501fun LocationWindow.panTo(point: Point, duration: Int = 1000) {
502 val currentCamera = camera
503 val newCamera = Camera(point, currentCamera.zoom, currentCamera.rotation)
504 val callback = CameraCallbackImpl()
505 moveTo(newCamera, duration, AnimationType.LINEAR, callback)
508fun LocationWindow.rotateTo(rotation: Double, duration: Int = 1000) {
509 val currentCamera = camera
510 val newCamera = Camera(currentCamera.point, currentCamera.zoom, rotation)
511 val callback = CameraCallbackImpl()
512 moveTo(newCamera, duration, AnimationType.SINE, callback)
519 // Create example instance
520 val example = LocationWindowCameraExample()
522 // Assume we have LocationWindow
523 // val locationWindow: LocationWindow = getLocationWindow()
524 // example.locationWindow = locationWindow
526 // Demonstrate methods
527 println("=== LocationWindowCamera Examples ===")
532 println("Examples ready to use!")