Loading...
Searching...
No Matches
LocationWindowCommonExample.kt
Go to the documentation of this file.
1import kotlinx.coroutines.delay
2import kotlinx.coroutines.runBlocking
3
4import com.navigine.idl.kotlin.DebugFlag
5import com.navigine.idl.kotlin.LocationWindow
6
7/**
8 * LocationWindowCommon usage example for Kotlin
9 * Demonstrates specific methods: setSublocationId, screenPositionToGlobal, globalToScreenPosition,
10 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
11 * zoomFactor, minZoomFactor, maxZoomFactor
12 */
13class LocationWindowCommonExample {
14
15 private var locationWindow: LocationWindow? = null
16 private var userLocationLayer: UserLocationLayer? = null
17 private var routeLayer: RouteLayer? = null
18 private var routeLayerListener: RouteLayerListener? = null
19 private var routeViewListener: RouteViewListener? = null
20
21 init {
22 demonstrateLocationWindowCommonMethods()
23 }
24
25 /**
26 * Demonstrate LocationWindowCommon methods
27 */
28 fun demonstrateLocationWindowCommonMethods() {
29 println("=== LocationWindowCommon Methods ===")
30
31 demonstrateSetSublocationId()
32 demonstrateOperatingMode()
33 demonstrateSublocationQueries()
34 demonstrateSublocationChangeListener()
35 demonstrateUserLocationLayer()
36 demonstrateRouteLayer()
37 demonstrateCoordinateConversion()
38 demonstrateMapFeatureSelection()
39 demonstrateApplyLayerFilter()
40 demonstrateDebugFlags()
41 demonstrateZoomProperties()
42 }
43
44 /**
45 * Demonstrate debug overlay flags (static LocationWindow API).
46 */
47 fun demonstrateDebugFlags() {
48 println("--- Debug flags ---")
49
50 // [kotlin_DebugFlag_enum]
51 val allFlags = listOf(
52 DebugFlag.NONE,
53 DebugFlag.INFOS,
54 DebugFlag.STATS,
55 DebugFlag.LABELS,
56 DebugFlag.DRAW_ALL_LABELS,
57 DebugFlag.SELECTION_BUFFER
58 )
59 println("Debug flag enum values: ${allFlags.size}")
60 // [kotlin_DebugFlag_enum]
61
62 // [kotlin_LocationWindow_setDebugFlag]
63 LocationWindow.setDebugFlag(DebugFlag.INFOS, true)
64 LocationWindow.setDebugFlag(DebugFlag.STATS, false)
65 println("Updated debug flags on LocationWindow")
66 // [kotlin_LocationWindow_setDebugFlag]
67
68 // [kotlin_LocationWindow_getDebugFlag]
69 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
70 println("Debug flag INFOS enabled: $infosOn")
71 // [kotlin_LocationWindow_getDebugFlag]
72 }
73
74
75 /**
76 * Demonstrate operating mode (indoor / outdoor basemap).
77 */
78 fun demonstrateOperatingMode() {
79 println("--- Operating Mode ---")
80
81 if (locationWindow == null) {
82 println("LocationWindow not available yet")
83 return
84 }
85
86 // [kotlin_OperatingMode_enum]
87 val modes = listOf(
88 OperatingMode.INDOOR_ONLY,
89 OperatingMode.OUTDOOR,
90 OperatingMode.OUTDOOR_INDOOR
91 )
92 println("Operating modes: ${modes.size}")
93 // [kotlin_OperatingMode_enum]
94
95 // [kotlin_LocationWindow_setOperatingMode]
96 locationWindow!!.setOperatingMode(OperatingMode.OUTDOOR_INDOOR)
97 println("Set operating mode to OUTDOOR_INDOOR")
98 // [kotlin_LocationWindow_setOperatingMode]
99
100 // [kotlin_LocationWindow_getOperatingMode]
101 val currentMode = locationWindow!!.operatingMode
102 println("Current operating mode: $currentMode")
103 // [kotlin_LocationWindow_getOperatingMode]
104
105 // [kotlin_MapTheme_enum]
106 val themes = listOf(MapTheme.LIGHT, MapTheme.DARK)
107 println("Map themes: ${themes.size}")
108 // [kotlin_MapTheme_enum]
109
110 // [kotlin_LocationWindow_setMapTheme]
111 locationWindow!!.mapTheme = MapTheme.DARK
112 println("Set map theme to DARK")
113 // [kotlin_LocationWindow_setMapTheme]
114
115 // [kotlin_LocationWindow_getMapTheme]
116 val currentTheme = locationWindow!!.mapTheme
117 println("Current map theme: $currentTheme")
118 // [kotlin_LocationWindow_getMapTheme]
119
120 // [kotlin_TileKind_enum]
121 val kinds = listOf(TileKind.VECTOR, TileKind.RASTER)
122 println("Tile kinds: ${kinds.size}")
123 // [kotlin_TileKind_enum]
124
125 // [kotlin_TileSchema_enum]
126 val schemas = listOf(TileSchema.SHORTBREAD, TileSchema.OPEN_MAP_TILES, TileSchema.MAPBOX_STREETS)
127 println("Tile schemas: ${schemas.size}")
128 // [kotlin_TileSchema_enum]
129
130 // [kotlin_HttpTileSource_record]
131 val http = HttpTileSource(
132 "https://api.maptiler.com/tiles/v3-openmaptiles/{z}/{x}/{y}.pbf",
133 null,
134 mapOf("key" to "YOUR_MAPTILER_KEY"))
135 // [kotlin_HttpTileSource_record]
136
137 // [kotlin_MbtilesTileSource_record]
138 val offline = MbtilesTileSource("/path/to/map.mbtiles")
139 // [kotlin_MbtilesTileSource_record]
140
141 // [kotlin_TileProvider_record]
142 val osmHttp = TileProvider(
143 TileSchema.OPEN_MAP_TILES,
144 http,
145 null,
146 0,
147 14,
148 null,
149 TileKind.VECTOR)
150 val mbtiles = TileProvider(
151 TileSchema.SHORTBREAD,
152 null,
153 offline,
154 0,
155 14,
156 null,
157 TileKind.VECTOR)
158 // [kotlin_TileProvider_record]
159
160 // [kotlin_LocationWindow_setTileProvider]
161 locationWindow!!.tileProvider = osmHttp
162 locationWindow!!.tileProvider = null
163 val imagery = TileProvider(
164 TileSchema.SHORTBREAD,
165 HttpTileSource(
166 "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
167 null,
168 null),
169 null,
170 0,
171 19,
172 "© OpenStreetMap contributors",
173 TileKind.RASTER)
174 locationWindow!!.tileProvider = imagery
175 // [kotlin_LocationWindow_setTileProvider]
176
177 // [kotlin_AttributionAlignment_record]
178 val alignment = AttributionAlignment(
179 AttributionHorizontalAlignment.RIGHT,
180 AttributionVerticalAlignment.BOTTOM)
181 // [kotlin_AttributionAlignment_record]
182
183 // [kotlin_LocationWindow_setAttributionAlignment]
184 locationWindow!!.attributionAlignment = alignment
185 // [kotlin_LocationWindow_setAttributionAlignment]
186
187 // [kotlin_LocationWindow_getAttribution]
188 val attribution = locationWindow!!.attribution
189 println("Attribution: $attribution")
190 // [kotlin_LocationWindow_getAttribution]
191 }
192
193 /**
194 * Demonstrate setSublocationId method
195 */
196 fun demonstrateSetSublocationId() {
197 println("--- setSublocationId Method ---")
198
199 if (locationWindow == null) {
200 println("LocationWindow not available yet")
201 return
202 }
203
204 // [kotlin_LocationWindow_setSublocationId]
205 // Set sublocation ID to switch between floors
206 locationWindow!!.setSublocationId(1)
207 println("Set sublocation ID to 1 (first floor)")
208 // [kotlin_LocationWindow_setSublocationId]
209
210 // [kotlin_LocationWindow_setSublocationId_2]
211 // Set sublocation ID to another floor
212 locationWindow!!.setSublocationId(2)
213 println("Set sublocation ID to 2 (second floor)")
214 // [kotlin_LocationWindow_setSublocationId_2]
215
216 // [kotlin_LocationWindow_setSublocationId_3]
217 // Set sublocation ID to ground floor
218 locationWindow!!.setSublocationId(0)
219 println("Set sublocation ID to 0 (ground floor)")
220 // [kotlin_LocationWindow_setSublocationId_3]
221
222 // Test with different sublocation IDs
223 val sublocationIds = listOf(1, 2, 3, 0, 5)
224 for (id in sublocationIds) {
225 locationWindow!!.setSublocationId(id)
226 println("Switched to sublocation ID: $id")
227 }
228 }
229
230 /**
231 * Demonstrate getters for sublocation and enclosing camera
232 */
233 fun demonstrateSublocationQueries() {
234 println("--- getSublocationId & getEnclosingCamera ---")
235
236 if (locationWindow == null) {
237 println("LocationWindow not available yet")
238 return
239 }
240
241 // [kotlin_LocationWindow_getSublocationId]
242 val currentId = locationWindow!!.getSublocationId()
243 if (currentId != null) {
244 println("Current sublocation id: $currentId")
245 } else {
246 println("Current sublocation id is not set")
247 }
248 // [kotlin_LocationWindow_getSublocationId]
249
250 // [kotlin_LocationWindow_getEnclosingCamera]
251 val boundingBox = BoundingBox(GlobalPoint(55.75, 37.61), GlobalPoint(55.76, 37.63))
252 val camera = locationWindow!!.getEnclosingCamera(boundingBox)
253 println("Camera that fits bounding box: $camera")
254 // [kotlin_LocationWindow_getEnclosingCamera]
255
256 // [kotlin_LocationWindow_setFocusRect]
257 val focus = ScreenRect(ScreenPoint(0.0, 0.0), ScreenPoint(1000.0, 1600.0))
258 locationWindow!!.focusRect = focus
259 // [kotlin_LocationWindow_setFocusRect]
260
261 // [kotlin_LocationWindow_getEnclosingCameraWithFocus]
262 val padded = locationWindow!!.getEnclosingCameraWithFocus(boundingBox, focus, null, null)
263 println("Camera that fits bounding box in focus rect: $padded")
264 // [kotlin_LocationWindow_getEnclosingCameraWithFocus]
265 }
266
267 /**
268 * Demonstrate sublocation change listener usage
269 */
270 fun demonstrateSublocationChangeListener() {
271 println("--- Sublocation Change Listener ---")
272
273 if (locationWindow == null) {
274 println("LocationWindow not available yet")
275 return
276 }
277
278 val listener = DemoSublocationChangeListener()
279
280 // [kotlin_LocationWindow_addSublocationChangeListener]
281 locationWindow!!.addSublocationChangeListener(listener)
282 println("Added sublocation change listener")
283 // [kotlin_LocationWindow_addSublocationChangeListener]
284
285 locationWindow!!.setSublocationId(1)
286 locationWindow!!.setSublocationId(2)
287
288 // [kotlin_LocationWindow_removeSublocationChangeListener]
289 locationWindow!!.removeSublocationChangeListener(listener)
290 println("Removed sublocation change listener")
291 // [kotlin_LocationWindow_removeSublocationChangeListener]
292 }
293
294 /**
295 * Demonstrate user location layer controls
296 */
297 fun demonstrateUserLocationLayer() {
298 println("--- UserLocationLayer ---")
299
300 if (userLocationLayer == null) {
301 println("UserLocationLayer not available yet")
302 return
303 }
304
305 // [kotlin_UserLocationLayer_setVisible]
306 userLocationLayer!!.setVisible(true)
307 println("User location layer set visible")
308 // [kotlin_UserLocationLayer_setVisible]
309
310 // [kotlin_UserLocationLayer_isVisible]
311 val visible = userLocationLayer!!.isVisible
312 println("User location layer is visible: $visible")
313 // [kotlin_UserLocationLayer_isVisible]
314
315 // [kotlin_UserLocationLayer_setAnchor]
316 val anchor = ScreenPoint(100.0f, 200.0f)
317 userLocationLayer!!.setAnchor(anchor)
318 println("Set user location anchor to: (${anchor.x}, ${anchor.y})")
319 // [kotlin_UserLocationLayer_setAnchor]
320
321 // [kotlin_UserLocationLayer_anchorEnabled]
322 val anchorEnabled = userLocationLayer!!.anchorEnabled
323 println("Anchor enabled: $anchorEnabled")
324 // [kotlin_UserLocationLayer_anchorEnabled]
325
326 // [kotlin_UserLocationLayer_setHeadingModeActive]
327 userLocationLayer!!.setHeadingModeActive(true)
328 println("Heading-up mode enabled")
329 // [kotlin_UserLocationLayer_setHeadingModeActive]
330
331 // [kotlin_UserLocationLayer_headingModeActive]
332 val headingModeActive = userLocationLayer!!.headingModeActive
333 println("Heading-up mode active: $headingModeActive")
334 // [kotlin_UserLocationLayer_headingModeActive]
335
336 // [kotlin_UserLocationLayer_setFollowMode]
337 userLocationLayer!!.setFollowMode(UserLocationFollowMode.HEADING)
338 println("Follow mode set to heading")
339 // [kotlin_UserLocationLayer_setFollowMode]
340
341 // [kotlin_UserLocationLayer_followMode]
342 val followMode = userLocationLayer!!.followMode
343 println("Follow mode: $followMode")
344 // [kotlin_UserLocationLayer_followMode]
345
346 // [kotlin_UserLocationLayer_setArrowBitmap]
347 userLocationLayer!!.setArrowBitmap(ImageProvider.fromFile("/path/to/arrow.png", true))
348 userLocationLayer!!.setArrowBitmap(null)
349 println("Custom arrow bitmap cleared")
350 // [kotlin_UserLocationLayer_setArrowBitmap]
351
352 // [kotlin_UserLocationLayer_setAccuracyColor]
353 userLocationLayer!!.setAccuracyColor(0x4230AAD9)
354 println("Accuracy circle color updated")
355 // [kotlin_UserLocationLayer_setAccuracyColor]
356
357 // [kotlin_UserLocationLayer_resetAnchor]
358 userLocationLayer!!.resetAnchor()
359 println("Anchor reset to default")
360 // [kotlin_UserLocationLayer_resetAnchor]
361 }
362
363 /**
364 * Demonstrate route layer controls
365 */
366 fun demonstrateRouteLayer() {
367 println("--- RouteLayer ---")
368
369 if (routeLayer == null) {
370 println("RouteLayer not available yet")
371 return
372 }
373
374 // [kotlin_RouteLayer_setVisible]
375 routeLayer!!.setVisible(true)
376 println("Route layer set visible")
377 // [kotlin_RouteLayer_setVisible]
378
379 // [kotlin_RouteLayer_isVisible]
380 val visible = routeLayer!!.isVisible
381 println("Route layer is visible: $visible")
382 // [kotlin_RouteLayer_isVisible]
383
384 // [kotlin_RouteLayer_setTraveledColor]
385 routeLayer!!.setTraveledColor(0xB4787878.toInt())
386 println("Traveled color updated")
387 // [kotlin_RouteLayer_setTraveledColor]
388
389 // [kotlin_RouteLayer_setRemainingColor]
390 routeLayer!!.setRemainingColor(0xFF30AAD9.toInt())
391 println("Remaining color updated")
392 // [kotlin_RouteLayer_setRemainingColor]
393
394 // [kotlin_RouteLayer_setWidth]
395 routeLayer!!.setWidth(8.0f)
396 println("Route width updated")
397 // [kotlin_RouteLayer_setWidth]
398
399 // [kotlin_RouteLayer_setRemainingStyle]
400 routeLayer!!.setRemainingStyle(RouteRemainingStyle.DOTTED)
401 println("Remaining style set to DOTTED")
402 // [kotlin_RouteLayer_setRemainingStyle]
403
404 // [kotlin_RouteLayer_remainingStyle]
405 val remainingStyle = routeLayer!!.remainingStyle
406 println("Remaining style: $remainingStyle")
407 // [kotlin_RouteLayer_remainingStyle]
408
409 // [kotlin_RouteLayer_setRemainingPointSize]
410 routeLayer!!.setRemainingPointSize(8.0f, 8.0f)
411 println("Remaining point size updated")
412 // [kotlin_RouteLayer_setRemainingPointSize]
413
414 // [kotlin_RouteLayer_setRemainingPlacement]
415 routeLayer!!.setRemainingPlacement(Placement.SPACED)
416 println("Remaining placement updated")
417 // [kotlin_RouteLayer_setRemainingPlacement]
418
419 // [kotlin_RouteLayer_setRemainingPlacementSpacing]
420 routeLayer!!.setRemainingPlacementSpacing(8.0f)
421 println("Remaining placement spacing updated")
422 // [kotlin_RouteLayer_setRemainingPlacementSpacing]
423
424 // [kotlin_RouteLayer_setRemainingPlacementMinRatio]
425 routeLayer!!.setRemainingPlacementMinRatio(0.0f)
426 println("Remaining placement min ratio updated")
427 // [kotlin_RouteLayer_setRemainingPlacementMinRatio]
428
429 // [kotlin_RouteLayer_setRemainingCollisionEnabled]
430 routeLayer!!.setRemainingCollisionEnabled(false)
431 println("Remaining collision disabled")
432 // [kotlin_RouteLayer_setRemainingCollisionEnabled]
433
434 // [kotlin_RouteLayer_setRemainingDashLength]
435 routeLayer!!.setRemainingDashLength(0.5f)
436 println("Remaining dash length updated")
437 // [kotlin_RouteLayer_setRemainingDashLength]
438
439 // [kotlin_RouteLayer_setRemainingGapLength]
440 routeLayer!!.setRemainingGapLength(0.4f)
441 println("Remaining gap length updated")
442 // [kotlin_RouteLayer_setRemainingGapLength]
443
444 val from = RouteEndpoint(
445 GlobalPoint(55.751244, 37.618423),
446 1) // null for outdoor point
447 val to = RouteEndpoint(
448 GlobalPoint(55.751700, 37.619000),
449 2) // null for outdoor point
450
451 // [kotlin_RouteLayer_setRoute]
452 routeLayer!!.setRoute(from, to)
453 println("Static route applied")
454 // [kotlin_RouteLayer_setRoute]
455
456 // [kotlin_RouteLayer_setTarget]
457 routeLayer!!.setTarget(to)
458 println("Guidance target applied")
459 // [kotlin_RouteLayer_setTarget]
460
461 // [kotlin_RouteLayer_routes]
462 val routes = routeLayer!!.routes()
463 println("Visible routes: ${routes.size}")
464 // [kotlin_RouteLayer_routes]
465
466 // [kotlin_RouteLayer_selectedRoute]
467 val selectedRoute = routeLayer!!.selectedRoute()
468 if (selectedRoute != null) {
469 println("Selected route length: ${selectedRoute.length()}")
470 }
471 // [kotlin_RouteLayer_selectedRoute]
472
473 // [kotlin_RouteLayer_selectRoute]
474 routes.firstOrNull()?.let { routeLayer!!.selectRoute(it) }
475 // [kotlin_RouteLayer_selectRoute]
476
477 // [kotlin_RouteLayer_addRouteLayerListener]
478 routeLayerListener = object : RouteLayerListener {
479 override fun onRouteChanged(status: RouteLayerStatus, route: RouteView?) {
480 println("Route status: $status")
481 }
482
483 override fun onRouteAdvanced(progress: RouteProgress) {
484 println("Remaining distance: ${progress.remainingDistance}, time: ${progress.remainingTime}s")
485 }
486
487 override fun onRouteTargetReached() {
488 println("Route target reached")
489 }
490 }
491 routeLayer!!.addRouteLayerListener(routeLayerListener!!)
492 // [kotlin_RouteLayer_addRouteLayerListener]
493
494 // [kotlin_RouteLayer_addRouteViewListener]
495 routeViewListener = object : RouteViewListener {
496 override fun onRouteViewsChanged() {
497 println("Route views changed")
498 }
499
500 override fun onSelectedRouteChanged(route: RouteView?) {
501 println("Selected route changed")
502 }
503
504 override fun onRouteViewTap(route: RouteView) {
505 routeLayer!!.selectRoute(route)
506 }
507 }
508 routeLayer!!.addRouteViewListener(routeViewListener!!)
509 // [kotlin_RouteLayer_addRouteViewListener]
510
511 // [kotlin_RouteLayer_clear]
512 routeLayer!!.clear()
513 println("Route layer cleared")
514 // [kotlin_RouteLayer_clear]
515 }
516
517 /**
518 * Demonstrate coordinate conversion methods
519 */
520 fun demonstrateCoordinateConversion() {
521 println("--- Coordinate Conversion Methods ---")
522
523 if (locationWindow == null) {
524 println("LocationWindow not available yet")
525 return
526 }
527
528 // [kotlin_LocationWindow_screenPositionToGlobal]
529 val screenPoint = ScreenPoint(100.0, 200.0)
530 val globalPoint = locationWindow!!.screenPositionToGlobal(screenPoint)
531 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to WGS84: (${globalPoint.latitude}, ${globalPoint.longitude})")
532 // [kotlin_LocationWindow_screenPositionToGlobal]
533
534 // [kotlin_LocationWindow_getVisibleRegion]
535 val visibleRegion = locationWindow!!.visibleRegion
536 println("Viewport top-left: ${visibleRegion.topLeft}")
537 // [kotlin_LocationWindow_getVisibleRegion]
538
539 // [kotlin_LocationWindow_getFocusRegion]
540 val focusRegion = locationWindow!!.focusRegion
541 println("Focus-rect top-left: ${focusRegion.topLeft}")
542 // [kotlin_LocationWindow_getFocusRegion]
543
544 // [kotlin_LocationWindow_globalToScreenPosition]
545 val globalPoint2 = GlobalPoint(55.7558, 37.6176)
546 val screenPoint2 = locationWindow!!.globalToScreenPosition(globalPoint2, true)
547 println("WGS84 (${globalPoint2.latitude}, ${globalPoint2.longitude}) converted to screen with clipping: (${screenPoint2.x}, ${screenPoint2.y})")
548 // [kotlin_LocationWindow_globalToScreenPosition]
549
550 // Test coordinate conversion with different values
551 val testScreenPoints = listOf(
552 ScreenPoint(0.0, 0.0),
553 ScreenPoint(250.0, 250.0),
554 ScreenPoint(1000.0, 600.0)
555 )
556
557 for ((index, screenPoint) in testScreenPoints.withIndex()) {
558 val global = locationWindow!!.screenPositionToGlobal(screenPoint)
559 val backToScreen = locationWindow!!.globalToScreenPosition(global, false)
560 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> WGS84 (${global.latitude}, ${global.longitude}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
561 }
562 }
563
564 /**
565 * Demonstrate map feature selection methods
566 */
567 fun demonstrateMapFeatureSelection() {
568 println("--- Map Feature Selection Methods ---")
569
570 if (locationWindow == null) {
571 println("LocationWindow not available yet")
572 return
573 }
574
575 // [kotlin_LocationWindow_selectMapFeature]
576 // Select map feature by ID
577 val featureId = "room_101"
578 val selected = locationWindow!!.selectMapFeature(featureId)
579 println("Selected map feature $featureId: $selected")
580 // [kotlin_LocationWindow_selectMapFeature]
581
582 // [kotlin_LocationWindow_selectMapFeature_2]
583 // Select another map feature
584 val featureId2 = "office_205"
585 val selected2 = locationWindow!!.selectMapFeature(featureId2)
586 println("Selected map feature $featureId2: $selected2")
587 // [kotlin_LocationWindow_selectMapFeature_2]
588
589 // [kotlin_LocationWindow_getSelectedMapFeatures]
590 // Get list of selected map features
591 val selectedFeatures = locationWindow!!.selectedMapFeatures
592 println("Currently selected map features: ${selectedFeatures.size} features")
593 for (feature in selectedFeatures) {
594 println(" - $feature")
595 }
596 // [kotlin_LocationWindow_getSelectedMapFeatures]
597
598 // [kotlin_LocationWindow_deselectMapFeature]
599 // Deselect specific map feature
600 val deselected = locationWindow!!.deselectMapFeature(featureId)
601 println("Deselected map feature $featureId: $deselected")
602 // [kotlin_LocationWindow_deselectMapFeature]
603
604 // [kotlin_LocationWindow_deselectMapFeature_2]
605 // Deselect another map feature
606 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
607 println("Deselected map feature $featureId2: $deselected2")
608 // [kotlin_LocationWindow_deselectMapFeature_2]
609
610 // [kotlin_LocationWindow_deselectAllMapFeatures]
611 // Deselect all map features
612 locationWindow!!.deselectAllMapFeatures()
613 println("Deselected all map features")
614 // [kotlin_LocationWindow_deselectAllMapFeatures]
615
616 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
617 // Verify all features are deselected
618 val remainingFeatures = locationWindow!!.selectedMapFeatures
619 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
620 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
621
622 // Test multiple feature selection and deselection
623 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
624
625 // Select multiple features
626 for (featureId in testFeatureIds) {
627 val success = locationWindow!!.selectMapFeature(featureId)
628 println("Selected feature $featureId: $success")
629 }
630
631 // Check selected features
632 val allSelected = locationWindow!!.selectedMapFeatures
633 println("All selected features: ${allSelected.size} features")
634
635 // Deselect all at once
636 locationWindow!!.deselectAllMapFeatures()
637 println("Deselected all features at once")
638 }
639
640 /**
641 * Demonstrate applyLayerFilter method
642 */
643 fun demonstrateApplyLayerFilter() {
644 println("--- applyLayerFilter Method ---")
645
646 if (locationWindow == null) {
647 println("LocationWindow not available yet")
648 return
649 }
650
651 // [kotlin_MapFilterCondition_constructor]
652 // Create filter condition: show only venues with category "Toilet" or "Cafe"
653 val condition = MapFilterCondition("category", listOf("Toilet", "Cafe"))
654 // [kotlin_MapFilterCondition_constructor]
655
656 // [kotlin_LocationWindow_applyLayerFilter]
657 // Apply filter to venues layer
658 val conditions = listOf(MapFilterCondition("category", listOf("Toilet", "Cafe")))
659 locationWindow!!.applyLayerFilter("venues", conditions)
660 println("Applied layer filter: show venues with category Toilet or Cafe")
661 // [kotlin_LocationWindow_applyLayerFilter]
662
663 // Reset filter (show all venues)
664 locationWindow!!.applyLayerFilter("venues", emptyList())
665 println("Reset layer filter: show all venues")
666 }
667
668 /**
669 * Demonstrate zoom properties
670 */
671 fun demonstrateZoomProperties() {
672 println("--- Zoom Properties ---")
673
674 if (locationWindow == null) {
675 println("LocationWindow not available yet")
676 return
677 }
678
679 // [kotlin_LocationWindow_getZoomFactor]
680 // Get current zoom factor
681 val currentZoom = locationWindow!!.zoomFactor
682 println("Current zoom factor: $currentZoom")
683 // [kotlin_LocationWindow_getZoomFactor]
684
685 // [kotlin_LocationWindow_setZoomFactor]
686 // Set zoom factor
687 locationWindow!!.zoomFactor = 150.0
688 println("Set zoom factor to 150.0")
689 // [kotlin_LocationWindow_setZoomFactor]
690
691 // [kotlin_LocationWindow_getMinZoomFactor]
692 // Get minimum zoom factor
693 val minZoomFactor = locationWindow!!.minZoomFactor
694 println("Minimum zoom factor: $minZoomFactor")
695 // [kotlin_LocationWindow_getMinZoomFactor]
696
697 // [kotlin_LocationWindow_setMinZoomFactor]
698 // Set minimum zoom factor
699 locationWindow!!.minZoomFactor = 50.0
700 println("Set minimum zoom factor to 50.0")
701 // [kotlin_LocationWindow_setMinZoomFactor]
702
703 // [kotlin_LocationWindow_getMaxZoomFactor]
704 // Get maximum zoom factor
705 val maxZoomFactor = locationWindow!!.maxZoomFactor
706 println("Maximum zoom factor: $maxZoomFactor")
707 // [kotlin_LocationWindow_getMaxZoomFactor]
708
709 // [kotlin_LocationWindow_setMaxZoomFactor]
710 // Set maximum zoom factor
711 locationWindow!!.maxZoomFactor = 300.0
712 println("Set maximum zoom factor to 300.0")
713 // [kotlin_LocationWindow_setMaxZoomFactor]
714
715 // Test zoom factor changes
716 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
717 for (zoom in testZoomFactors) {
718 locationWindow!!.zoomFactor = zoom
719 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
720 }
721
722 // Test zoom limits
723 println("Testing zoom limits...")
724 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
725 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
726
727 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
728 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
729
730 // Reset to default
731 locationWindow!!.zoomFactor = 100.0
732 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
733 }
734
735 /**
736 * Main demonstration method
737 */
738 suspend fun runExample() {
739 println("=== LocationWindowCommon Example ===")
740
741 // Simulate LocationWindow initialization
742 delay(500)
743
744 // TODO: User will implement LocationWindow initialization here
745 // locationWindow = getLocationWindow()
746
747 // Run demonstrations
748 demonstrateLocationWindowCommonMethods()
749
750 println("=== Example completed ===")
751 }
752}
753
754/**
755 * Function to run the example
756 */
757fun main() = runBlocking {
758 val example = LocationWindowCommonExample()
759 example.runExample()
760}
761
762class DemoSublocationChangeListener : SublocationChangeListener {
763 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
764 override fun onActiveSublocationChanged(sublocationId: Int) {
765 println("Active sublocation changed to: $sublocationId")
766 }
767 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
768}