1import kotlinx.coroutines.delay
2import kotlinx.coroutines.runBlocking
4import com.navigine.idl.kotlin.DebugFlag
5import com.navigine.idl.kotlin.LocationWindow
8 * LocationWindowCommon usage example for Kotlin
9 * Demonstrates specific methods: setSublocationId, screenPositionToMeters, metersToScreenPosition,
10 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
11 * zoomFactor, minZoomFactor, maxZoomFactor
13class LocationWindowCommonExample {
15 private var locationWindow: LocationWindow? = null
16 private var userLocationView: UserLocationView? = null
17 private var userLocationLayer: UserLocationLayer? = null
20 demonstrateLocationWindowCommonMethods()
24 * Demonstrate LocationWindowCommon methods
26 fun demonstrateLocationWindowCommonMethods() {
27 println("=== LocationWindowCommon Methods ===")
29 demonstrateSetSublocationId()
30 demonstrateSublocationQueries()
31 demonstrateSublocationChangeListener()
32 demonstrateUserLocationView()
33 demonstrateUserLocationLayer()
34 demonstrateCoordinateConversion()
35 demonstrateMapFeatureSelection()
36 demonstrateApplyLayerFilter()
37 demonstrateDebugFlags()
38 demonstrateZoomProperties()
42 * Demonstrate debug overlay flags (static LocationWindow API).
44 fun demonstrateDebugFlags() {
45 println("--- Debug flags ---")
47 // [kotlin_DebugFlag_enum]
48 val allFlags = listOf(
53 DebugFlag.DRAW_ALL_LABELS,
54 DebugFlag.SELECTION_BUFFER
56 println("Debug flag enum values: ${allFlags.size}")
57 // [kotlin_DebugFlag_enum]
59 // [kotlin_LocationWindow_setDebugFlag]
60 LocationWindow.setDebugFlag(DebugFlag.INFOS, true)
61 LocationWindow.setDebugFlag(DebugFlag.STATS, false)
62 println("Updated debug flags on LocationWindow")
63 // [kotlin_LocationWindow_setDebugFlag]
65 // [kotlin_LocationWindow_getDebugFlag]
66 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
67 println("Debug flag INFOS enabled: $infosOn")
68 // [kotlin_LocationWindow_getDebugFlag]
72 * Demonstrate setSublocationId method
74 fun demonstrateSetSublocationId() {
75 println("--- setSublocationId Method ---")
77 if (locationWindow == null) {
78 println("LocationWindow not available yet")
82 // [kotlin_LocationWindow_setSublocationId]
83 // Set sublocation ID to switch between floors
84 locationWindow!!.setSublocationId(1)
85 println("Set sublocation ID to 1 (first floor)")
86 // [kotlin_LocationWindow_setSublocationId]
88 // [kotlin_LocationWindow_setSublocationId_2]
89 // Set sublocation ID to another floor
90 locationWindow!!.setSublocationId(2)
91 println("Set sublocation ID to 2 (second floor)")
92 // [kotlin_LocationWindow_setSublocationId_2]
94 // [kotlin_LocationWindow_setSublocationId_3]
95 // Set sublocation ID to ground floor
96 locationWindow!!.setSublocationId(0)
97 println("Set sublocation ID to 0 (ground floor)")
98 // [kotlin_LocationWindow_setSublocationId_3]
100 // Test with different sublocation IDs
101 val sublocationIds = listOf(1, 2, 3, 0, 5)
102 for (id in sublocationIds) {
103 locationWindow!!.setSublocationId(id)
104 println("Switched to sublocation ID: $id")
109 * Demonstrate getters for sublocation and enclosing camera
111 fun demonstrateSublocationQueries() {
112 println("--- getSublocationId & getEnclosingCamera ---")
114 if (locationWindow == null) {
115 println("LocationWindow not available yet")
119 // [kotlin_LocationWindow_getSublocationId]
120 val currentId = locationWindow!!.getSublocationId()
121 if (currentId != null) {
122 println("Current sublocation id: $currentId")
124 println("Current sublocation id is not set")
126 // [kotlin_LocationWindow_getSublocationId]
128 // [kotlin_LocationWindow_getEnclosingCamera]
129 val boundingBox = BoundingBox(Point(0.0, 0.0), Point(20.0, 30.0))
130 val camera = locationWindow!!.getEnclosingCamera(boundingBox)
131 println("Camera that fits bounding box: $camera")
132 // [kotlin_LocationWindow_getEnclosingCamera]
136 * Demonstrate sublocation change listener usage
138 fun demonstrateSublocationChangeListener() {
139 println("--- Sublocation Change Listener ---")
141 if (locationWindow == null) {
142 println("LocationWindow not available yet")
146 val listener = DemoSublocationChangeListener()
148 // [kotlin_LocationWindow_addSublocationChangeListener]
149 locationWindow!!.addSublocationChangeListener(listener)
150 println("Added sublocation change listener")
151 // [kotlin_LocationWindow_addSublocationChangeListener]
153 locationWindow!!.setSublocationId(1)
154 locationWindow!!.setSublocationId(2)
156 // [kotlin_LocationWindow_removeSublocationChangeListener]
157 locationWindow!!.removeSublocationChangeListener(listener)
158 println("Removed sublocation change listener")
159 // [kotlin_LocationWindow_removeSublocationChangeListener]
163 * Demonstrate user location view properties
165 fun demonstrateUserLocationView() {
166 println("--- UserLocationView ---")
168 if (userLocationView == null) {
169 println("UserLocationView not available yet")
173 // [kotlin_UserLocationView_getArrow]
174 val arrow = userLocationView!!.arrow
175 println("Arrow icon object: $arrow")
176 // [kotlin_UserLocationView_getArrow]
178 // [kotlin_UserLocationView_getAccuracyCircle]
179 val accuracyCircle = userLocationView!!.accuracyCircle
180 println("Accuracy circle object: $accuracyCircle")
181 // [kotlin_UserLocationView_getAccuracyCircle]
185 * Demonstrate user location layer controls
187 fun demonstrateUserLocationLayer() {
188 println("--- UserLocationLayer ---")
190 if (userLocationLayer == null) {
191 println("UserLocationLayer not available yet")
195 // [kotlin_UserLocationLayer_setVisible]
196 userLocationLayer!!.setVisible(true)
197 println("User location layer set visible")
198 // [kotlin_UserLocationLayer_setVisible]
200 // [kotlin_UserLocationLayer_isVisible]
201 val visible = userLocationLayer!!.isVisible
202 println("User location layer is visible: $visible")
203 // [kotlin_UserLocationLayer_isVisible]
205 // [kotlin_UserLocationLayer_setAnchor]
206 val anchor = ScreenPoint(100.0f, 200.0f)
207 userLocationLayer!!.setAnchor(anchor)
208 println("Set user location anchor to: (${anchor.x}, ${anchor.y})")
209 // [kotlin_UserLocationLayer_setAnchor]
211 // [kotlin_UserLocationLayer_anchorEnabled]
212 val anchorEnabled = userLocationLayer!!.anchorEnabled
213 println("Anchor enabled: $anchorEnabled")
214 // [kotlin_UserLocationLayer_anchorEnabled]
216 // [kotlin_UserLocationLayer_resetAnchor]
217 userLocationLayer!!.resetAnchor()
218 println("Anchor reset to default")
219 // [kotlin_UserLocationLayer_resetAnchor]
223 * Demonstrate coordinate conversion methods
225 fun demonstrateCoordinateConversion() {
226 println("--- Coordinate Conversion Methods ---")
228 if (locationWindow == null) {
229 println("LocationWindow not available yet")
233 // [kotlin_LocationWindow_screenPositionToMeters]
234 // Convert screen position to meters
235 val screenPoint = Point(100.0, 200.0)
236 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
237 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})")
238 // [kotlin_LocationWindow_screenPositionToMeters]
240 // [kotlin_LocationWindow_screenPositionToMeters_2]
241 // Convert another screen position to meters
242 val screenPoint2 = Point(500.0, 300.0)
243 val metersPoint2 = locationWindow!!.screenPositionToMeters(screenPoint2)
244 println("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})")
245 // [kotlin_LocationWindow_screenPositionToMeters_2]
247 // [kotlin_LocationWindow_metersToScreenPosition]
248 // Convert meters to screen position with clipping
249 val metersPoint3 = Point(50.0, 75.0)
250 val screenPoint3 = locationWindow!!.metersToScreenPosition(metersPoint3, true)
251 println("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})")
252 // [kotlin_LocationWindow_metersToScreenPosition]
254 // [kotlin_LocationWindow_metersToScreenPosition_2]
255 // Convert meters to screen position without clipping
256 val metersPoint4 = Point(150.0, 200.0)
257 val screenPoint4 = locationWindow!!.metersToScreenPosition(metersPoint4, false)
258 println("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})")
259 // [kotlin_LocationWindow_metersToScreenPosition_2]
261 // Test coordinate conversion with different values
262 val testScreenPoints = listOf(
268 for ((index, screenPoint) in testScreenPoints.withIndex()) {
269 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
270 val backToScreen = locationWindow!!.metersToScreenPosition(metersPoint, false)
271 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
276 * Demonstrate map feature selection methods
278 fun demonstrateMapFeatureSelection() {
279 println("--- Map Feature Selection Methods ---")
281 if (locationWindow == null) {
282 println("LocationWindow not available yet")
286 // [kotlin_LocationWindow_selectMapFeature]
287 // Select map feature by ID
288 val featureId = "room_101"
289 val selected = locationWindow!!.selectMapFeature(featureId)
290 println("Selected map feature $featureId: $selected")
291 // [kotlin_LocationWindow_selectMapFeature]
293 // [kotlin_LocationWindow_selectMapFeature_2]
294 // Select another map feature
295 val featureId2 = "office_205"
296 val selected2 = locationWindow!!.selectMapFeature(featureId2)
297 println("Selected map feature $featureId2: $selected2")
298 // [kotlin_LocationWindow_selectMapFeature_2]
300 // [kotlin_LocationWindow_getSelectedMapFeatures]
301 // Get list of selected map features
302 val selectedFeatures = locationWindow!!.selectedMapFeatures
303 println("Currently selected map features: ${selectedFeatures.size} features")
304 for (feature in selectedFeatures) {
305 println(" - $feature")
307 // [kotlin_LocationWindow_getSelectedMapFeatures]
309 // [kotlin_LocationWindow_deselectMapFeature]
310 // Deselect specific map feature
311 val deselected = locationWindow!!.deselectMapFeature(featureId)
312 println("Deselected map feature $featureId: $deselected")
313 // [kotlin_LocationWindow_deselectMapFeature]
315 // [kotlin_LocationWindow_deselectMapFeature_2]
316 // Deselect another map feature
317 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
318 println("Deselected map feature $featureId2: $deselected2")
319 // [kotlin_LocationWindow_deselectMapFeature_2]
321 // [kotlin_LocationWindow_deselectAllMapFeatures]
322 // Deselect all map features
323 locationWindow!!.deselectAllMapFeatures()
324 println("Deselected all map features")
325 // [kotlin_LocationWindow_deselectAllMapFeatures]
327 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
328 // Verify all features are deselected
329 val remainingFeatures = locationWindow!!.selectedMapFeatures
330 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
331 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
333 // Test multiple feature selection and deselection
334 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
336 // Select multiple features
337 for (featureId in testFeatureIds) {
338 val success = locationWindow!!.selectMapFeature(featureId)
339 println("Selected feature $featureId: $success")
342 // Check selected features
343 val allSelected = locationWindow!!.selectedMapFeatures
344 println("All selected features: ${allSelected.size} features")
346 // Deselect all at once
347 locationWindow!!.deselectAllMapFeatures()
348 println("Deselected all features at once")
352 * Demonstrate applyLayerFilter method
354 fun demonstrateApplyLayerFilter() {
355 println("--- applyLayerFilter Method ---")
357 if (locationWindow == null) {
358 println("LocationWindow not available yet")
362 // [kotlin_MapFilterCondition_constructor]
363 // Create filter condition: show only venues with category "Toilet" or "Cafe"
364 val condition = MapFilterCondition("category", listOf("Toilet", "Cafe"))
365 // [kotlin_MapFilterCondition_constructor]
367 // [kotlin_LocationWindow_applyLayerFilter]
368 // Apply filter to venues layer
369 val conditions = listOf(MapFilterCondition("category", listOf("Toilet", "Cafe")))
370 locationWindow!!.applyLayerFilter("venues", conditions)
371 println("Applied layer filter: show venues with category Toilet or Cafe")
372 // [kotlin_LocationWindow_applyLayerFilter]
374 // Reset filter (show all venues)
375 locationWindow!!.applyLayerFilter("venues", emptyList())
376 println("Reset layer filter: show all venues")
380 * Demonstrate zoom properties
382 fun demonstrateZoomProperties() {
383 println("--- Zoom Properties ---")
385 if (locationWindow == null) {
386 println("LocationWindow not available yet")
390 // [kotlin_LocationWindow_getZoomFactor]
391 // Get current zoom factor
392 val currentZoom = locationWindow!!.zoomFactor
393 println("Current zoom factor: $currentZoom")
394 // [kotlin_LocationWindow_getZoomFactor]
396 // [kotlin_LocationWindow_setZoomFactor]
398 locationWindow!!.zoomFactor = 150.0
399 println("Set zoom factor to 150.0")
400 // [kotlin_LocationWindow_setZoomFactor]
402 // [kotlin_LocationWindow_getMinZoomFactor]
403 // Get minimum zoom factor
404 val minZoomFactor = locationWindow!!.minZoomFactor
405 println("Minimum zoom factor: $minZoomFactor")
406 // [kotlin_LocationWindow_getMinZoomFactor]
408 // [kotlin_LocationWindow_setMinZoomFactor]
409 // Set minimum zoom factor
410 locationWindow!!.minZoomFactor = 50.0
411 println("Set minimum zoom factor to 50.0")
412 // [kotlin_LocationWindow_setMinZoomFactor]
414 // [kotlin_LocationWindow_getMaxZoomFactor]
415 // Get maximum zoom factor
416 val maxZoomFactor = locationWindow!!.maxZoomFactor
417 println("Maximum zoom factor: $maxZoomFactor")
418 // [kotlin_LocationWindow_getMaxZoomFactor]
420 // [kotlin_LocationWindow_setMaxZoomFactor]
421 // Set maximum zoom factor
422 locationWindow!!.maxZoomFactor = 300.0
423 println("Set maximum zoom factor to 300.0")
424 // [kotlin_LocationWindow_setMaxZoomFactor]
426 // Test zoom factor changes
427 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
428 for (zoom in testZoomFactors) {
429 locationWindow!!.zoomFactor = zoom
430 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
434 println("Testing zoom limits...")
435 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
436 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
438 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
439 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
442 locationWindow!!.zoomFactor = 100.0
443 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
447 * Main demonstration method
449 suspend fun runExample() {
450 println("=== LocationWindowCommon Example ===")
452 // Simulate LocationWindow initialization
455 // TODO: User will implement LocationWindow initialization here
456 // locationWindow = getLocationWindow()
458 // Run demonstrations
459 demonstrateLocationWindowCommonMethods()
461 println("=== Example completed ===")
466 * Function to run the example
468fun main() = runBlocking {
469 val example = LocationWindowCommonExample()
473class DemoSublocationChangeListener : SublocationChangeListener {
474 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
475 override fun onActiveSublocationChanged(sublocationId: Int) {
476 println("Active sublocation changed to: $sublocationId")
478 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]