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, screenPositionToGlobal, globalToScreenPosition,
10 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
11 * zoomFactor, minZoomFactor, maxZoomFactor
13class LocationWindowCommonExample {
15 private var locationWindow: LocationWindow? = null
16 private var userLocationLayer: UserLocationLayer? = null
19 demonstrateLocationWindowCommonMethods()
23 * Demonstrate LocationWindowCommon methods
25 fun demonstrateLocationWindowCommonMethods() {
26 println("=== LocationWindowCommon Methods ===")
28 demonstrateSetSublocationId()
29 demonstrateOperatingMode()
30 demonstrateSublocationQueries()
31 demonstrateSublocationChangeListener()
32 demonstrateUserLocationLayer()
33 demonstrateCoordinateConversion()
34 demonstrateMapFeatureSelection()
35 demonstrateApplyLayerFilter()
36 demonstrateDebugFlags()
37 demonstrateZoomProperties()
41 * Demonstrate debug overlay flags (static LocationWindow API).
43 fun demonstrateDebugFlags() {
44 println("--- Debug flags ---")
46 // [kotlin_DebugFlag_enum]
47 val allFlags = listOf(
52 DebugFlag.DRAW_ALL_LABELS,
53 DebugFlag.SELECTION_BUFFER
55 println("Debug flag enum values: ${allFlags.size}")
56 // [kotlin_DebugFlag_enum]
58 // [kotlin_LocationWindow_setDebugFlag]
59 LocationWindow.setDebugFlag(DebugFlag.INFOS, true)
60 LocationWindow.setDebugFlag(DebugFlag.STATS, false)
61 println("Updated debug flags on LocationWindow")
62 // [kotlin_LocationWindow_setDebugFlag]
64 // [kotlin_LocationWindow_getDebugFlag]
65 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
66 println("Debug flag INFOS enabled: $infosOn")
67 // [kotlin_LocationWindow_getDebugFlag]
72 * Demonstrate operating mode (indoor / outdoor basemap).
74 fun demonstrateOperatingMode() {
75 println("--- Operating Mode ---")
77 if (locationWindow == null) {
78 println("LocationWindow not available yet")
82 // [kotlin_OperatingMode_enum]
84 OperatingMode.INDOOR_ONLY,
85 OperatingMode.OUTDOOR,
86 OperatingMode.OUTDOOR_INDOOR
88 println("Operating modes: ${modes.size}")
89 // [kotlin_OperatingMode_enum]
91 // [kotlin_LocationWindow_setOperatingMode]
92 locationWindow!!.setOperatingMode(OperatingMode.OUTDOOR_INDOOR)
93 println("Set operating mode to OUTDOOR_INDOOR")
94 // [kotlin_LocationWindow_setOperatingMode]
96 // [kotlin_LocationWindow_getOperatingMode]
97 val currentMode = locationWindow!!.operatingMode
98 println("Current operating mode: $currentMode")
99 // [kotlin_LocationWindow_getOperatingMode]
101 // [kotlin_AttributionAlignment_record]
102 val alignment = AttributionAlignment(
103 AttributionHorizontalAlignment.RIGHT,
104 AttributionVerticalAlignment.BOTTOM)
105 // [kotlin_AttributionAlignment_record]
107 // [kotlin_LocationWindow_setAttributionAlignment]
108 locationWindow!!.attributionAlignment = alignment
109 // [kotlin_LocationWindow_setAttributionAlignment]
111 // [kotlin_LocationWindow_getAttribution]
112 val attribution = locationWindow!!.attribution
113 println("Attribution: $attribution")
114 // [kotlin_LocationWindow_getAttribution]
118 * Demonstrate setSublocationId method
120 fun demonstrateSetSublocationId() {
121 println("--- setSublocationId Method ---")
123 if (locationWindow == null) {
124 println("LocationWindow not available yet")
128 // [kotlin_LocationWindow_setSublocationId]
129 // Set sublocation ID to switch between floors
130 locationWindow!!.setSublocationId(1)
131 println("Set sublocation ID to 1 (first floor)")
132 // [kotlin_LocationWindow_setSublocationId]
134 // [kotlin_LocationWindow_setSublocationId_2]
135 // Set sublocation ID to another floor
136 locationWindow!!.setSublocationId(2)
137 println("Set sublocation ID to 2 (second floor)")
138 // [kotlin_LocationWindow_setSublocationId_2]
140 // [kotlin_LocationWindow_setSublocationId_3]
141 // Set sublocation ID to ground floor
142 locationWindow!!.setSublocationId(0)
143 println("Set sublocation ID to 0 (ground floor)")
144 // [kotlin_LocationWindow_setSublocationId_3]
146 // Test with different sublocation IDs
147 val sublocationIds = listOf(1, 2, 3, 0, 5)
148 for (id in sublocationIds) {
149 locationWindow!!.setSublocationId(id)
150 println("Switched to sublocation ID: $id")
155 * Demonstrate getters for sublocation and enclosing camera
157 fun demonstrateSublocationQueries() {
158 println("--- getSublocationId & getEnclosingCamera ---")
160 if (locationWindow == null) {
161 println("LocationWindow not available yet")
165 // [kotlin_LocationWindow_getSublocationId]
166 val currentId = locationWindow!!.getSublocationId()
167 if (currentId != null) {
168 println("Current sublocation id: $currentId")
170 println("Current sublocation id is not set")
172 // [kotlin_LocationWindow_getSublocationId]
174 // [kotlin_LocationWindow_getEnclosingCamera]
175 val boundingBox = BoundingBox(GlobalPoint(55.75, 37.61), GlobalPoint(55.76, 37.63))
176 val camera = locationWindow!!.getEnclosingCamera(boundingBox)
177 println("Camera that fits bounding box: $camera")
178 // [kotlin_LocationWindow_getEnclosingCamera]
182 * Demonstrate sublocation change listener usage
184 fun demonstrateSublocationChangeListener() {
185 println("--- Sublocation Change Listener ---")
187 if (locationWindow == null) {
188 println("LocationWindow not available yet")
192 val listener = DemoSublocationChangeListener()
194 // [kotlin_LocationWindow_addSublocationChangeListener]
195 locationWindow!!.addSublocationChangeListener(listener)
196 println("Added sublocation change listener")
197 // [kotlin_LocationWindow_addSublocationChangeListener]
199 locationWindow!!.setSublocationId(1)
200 locationWindow!!.setSublocationId(2)
202 // [kotlin_LocationWindow_removeSublocationChangeListener]
203 locationWindow!!.removeSublocationChangeListener(listener)
204 println("Removed sublocation change listener")
205 // [kotlin_LocationWindow_removeSublocationChangeListener]
209 * Demonstrate user location layer controls
211 fun demonstrateUserLocationLayer() {
212 println("--- UserLocationLayer ---")
214 if (userLocationLayer == null) {
215 println("UserLocationLayer not available yet")
219 // [kotlin_UserLocationLayer_setVisible]
220 userLocationLayer!!.setVisible(true)
221 println("User location layer set visible")
222 // [kotlin_UserLocationLayer_setVisible]
224 // [kotlin_UserLocationLayer_isVisible]
225 val visible = userLocationLayer!!.isVisible
226 println("User location layer is visible: $visible")
227 // [kotlin_UserLocationLayer_isVisible]
229 // [kotlin_UserLocationLayer_setAnchor]
230 val anchor = ScreenPoint(100.0f, 200.0f)
231 userLocationLayer!!.setAnchor(anchor)
232 println("Set user location anchor to: (${anchor.x}, ${anchor.y})")
233 // [kotlin_UserLocationLayer_setAnchor]
235 // [kotlin_UserLocationLayer_anchorEnabled]
236 val anchorEnabled = userLocationLayer!!.anchorEnabled
237 println("Anchor enabled: $anchorEnabled")
238 // [kotlin_UserLocationLayer_anchorEnabled]
240 // [kotlin_UserLocationLayer_resetAnchor]
241 userLocationLayer!!.resetAnchor()
242 println("Anchor reset to default")
243 // [kotlin_UserLocationLayer_resetAnchor]
247 * Demonstrate coordinate conversion methods
249 fun demonstrateCoordinateConversion() {
250 println("--- Coordinate Conversion Methods ---")
252 if (locationWindow == null) {
253 println("LocationWindow not available yet")
257 // [kotlin_LocationWindow_screenPositionToGlobal]
258 val screenPoint = ScreenPoint(100.0, 200.0)
259 val globalPoint = locationWindow!!.screenPositionToGlobal(screenPoint)
260 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to WGS84: (${globalPoint.latitude}, ${globalPoint.longitude})")
261 // [kotlin_LocationWindow_screenPositionToGlobal]
263 // [kotlin_LocationWindow_globalToScreenPosition]
264 val globalPoint2 = GlobalPoint(55.7558, 37.6176)
265 val screenPoint2 = locationWindow!!.globalToScreenPosition(globalPoint2, true)
266 println("WGS84 (${globalPoint2.latitude}, ${globalPoint2.longitude}) converted to screen with clipping: (${screenPoint2.x}, ${screenPoint2.y})")
267 // [kotlin_LocationWindow_globalToScreenPosition]
269 // Test coordinate conversion with different values
270 val testScreenPoints = listOf(
271 ScreenPoint(0.0, 0.0),
272 ScreenPoint(250.0, 250.0),
273 ScreenPoint(1000.0, 600.0)
276 for ((index, screenPoint) in testScreenPoints.withIndex()) {
277 val global = locationWindow!!.screenPositionToGlobal(screenPoint)
278 val backToScreen = locationWindow!!.globalToScreenPosition(global, false)
279 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> WGS84 (${global.latitude}, ${global.longitude}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
284 * Demonstrate map feature selection methods
286 fun demonstrateMapFeatureSelection() {
287 println("--- Map Feature Selection Methods ---")
289 if (locationWindow == null) {
290 println("LocationWindow not available yet")
294 // [kotlin_LocationWindow_selectMapFeature]
295 // Select map feature by ID
296 val featureId = "room_101"
297 val selected = locationWindow!!.selectMapFeature(featureId)
298 println("Selected map feature $featureId: $selected")
299 // [kotlin_LocationWindow_selectMapFeature]
301 // [kotlin_LocationWindow_selectMapFeature_2]
302 // Select another map feature
303 val featureId2 = "office_205"
304 val selected2 = locationWindow!!.selectMapFeature(featureId2)
305 println("Selected map feature $featureId2: $selected2")
306 // [kotlin_LocationWindow_selectMapFeature_2]
308 // [kotlin_LocationWindow_getSelectedMapFeatures]
309 // Get list of selected map features
310 val selectedFeatures = locationWindow!!.selectedMapFeatures
311 println("Currently selected map features: ${selectedFeatures.size} features")
312 for (feature in selectedFeatures) {
313 println(" - $feature")
315 // [kotlin_LocationWindow_getSelectedMapFeatures]
317 // [kotlin_LocationWindow_deselectMapFeature]
318 // Deselect specific map feature
319 val deselected = locationWindow!!.deselectMapFeature(featureId)
320 println("Deselected map feature $featureId: $deselected")
321 // [kotlin_LocationWindow_deselectMapFeature]
323 // [kotlin_LocationWindow_deselectMapFeature_2]
324 // Deselect another map feature
325 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
326 println("Deselected map feature $featureId2: $deselected2")
327 // [kotlin_LocationWindow_deselectMapFeature_2]
329 // [kotlin_LocationWindow_deselectAllMapFeatures]
330 // Deselect all map features
331 locationWindow!!.deselectAllMapFeatures()
332 println("Deselected all map features")
333 // [kotlin_LocationWindow_deselectAllMapFeatures]
335 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
336 // Verify all features are deselected
337 val remainingFeatures = locationWindow!!.selectedMapFeatures
338 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
339 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
341 // Test multiple feature selection and deselection
342 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
344 // Select multiple features
345 for (featureId in testFeatureIds) {
346 val success = locationWindow!!.selectMapFeature(featureId)
347 println("Selected feature $featureId: $success")
350 // Check selected features
351 val allSelected = locationWindow!!.selectedMapFeatures
352 println("All selected features: ${allSelected.size} features")
354 // Deselect all at once
355 locationWindow!!.deselectAllMapFeatures()
356 println("Deselected all features at once")
360 * Demonstrate applyLayerFilter method
362 fun demonstrateApplyLayerFilter() {
363 println("--- applyLayerFilter Method ---")
365 if (locationWindow == null) {
366 println("LocationWindow not available yet")
370 // [kotlin_MapFilterCondition_constructor]
371 // Create filter condition: show only venues with category "Toilet" or "Cafe"
372 val condition = MapFilterCondition("category", listOf("Toilet", "Cafe"))
373 // [kotlin_MapFilterCondition_constructor]
375 // [kotlin_LocationWindow_applyLayerFilter]
376 // Apply filter to venues layer
377 val conditions = listOf(MapFilterCondition("category", listOf("Toilet", "Cafe")))
378 locationWindow!!.applyLayerFilter("venues", conditions)
379 println("Applied layer filter: show venues with category Toilet or Cafe")
380 // [kotlin_LocationWindow_applyLayerFilter]
382 // Reset filter (show all venues)
383 locationWindow!!.applyLayerFilter("venues", emptyList())
384 println("Reset layer filter: show all venues")
388 * Demonstrate zoom properties
390 fun demonstrateZoomProperties() {
391 println("--- Zoom Properties ---")
393 if (locationWindow == null) {
394 println("LocationWindow not available yet")
398 // [kotlin_LocationWindow_getZoomFactor]
399 // Get current zoom factor
400 val currentZoom = locationWindow!!.zoomFactor
401 println("Current zoom factor: $currentZoom")
402 // [kotlin_LocationWindow_getZoomFactor]
404 // [kotlin_LocationWindow_setZoomFactor]
406 locationWindow!!.zoomFactor = 150.0
407 println("Set zoom factor to 150.0")
408 // [kotlin_LocationWindow_setZoomFactor]
410 // [kotlin_LocationWindow_getMinZoomFactor]
411 // Get minimum zoom factor
412 val minZoomFactor = locationWindow!!.minZoomFactor
413 println("Minimum zoom factor: $minZoomFactor")
414 // [kotlin_LocationWindow_getMinZoomFactor]
416 // [kotlin_LocationWindow_setMinZoomFactor]
417 // Set minimum zoom factor
418 locationWindow!!.minZoomFactor = 50.0
419 println("Set minimum zoom factor to 50.0")
420 // [kotlin_LocationWindow_setMinZoomFactor]
422 // [kotlin_LocationWindow_getMaxZoomFactor]
423 // Get maximum zoom factor
424 val maxZoomFactor = locationWindow!!.maxZoomFactor
425 println("Maximum zoom factor: $maxZoomFactor")
426 // [kotlin_LocationWindow_getMaxZoomFactor]
428 // [kotlin_LocationWindow_setMaxZoomFactor]
429 // Set maximum zoom factor
430 locationWindow!!.maxZoomFactor = 300.0
431 println("Set maximum zoom factor to 300.0")
432 // [kotlin_LocationWindow_setMaxZoomFactor]
434 // Test zoom factor changes
435 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
436 for (zoom in testZoomFactors) {
437 locationWindow!!.zoomFactor = zoom
438 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
442 println("Testing zoom limits...")
443 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
444 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
446 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
447 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
450 locationWindow!!.zoomFactor = 100.0
451 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
455 * Main demonstration method
457 suspend fun runExample() {
458 println("=== LocationWindowCommon Example ===")
460 // Simulate LocationWindow initialization
463 // TODO: User will implement LocationWindow initialization here
464 // locationWindow = getLocationWindow()
466 // Run demonstrations
467 demonstrateLocationWindowCommonMethods()
469 println("=== Example completed ===")
474 * Function to run the example
476fun main() = runBlocking {
477 val example = LocationWindowCommonExample()
481class DemoSublocationChangeListener : SublocationChangeListener {
482 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
483 override fun onActiveSublocationChanged(sublocationId: Int) {
484 println("Active sublocation changed to: $sublocationId")
486 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]