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 userLocationLayer: UserLocationLayer? = null
19 demonstrateLocationWindowCommonMethods()
23 * Demonstrate LocationWindowCommon methods
25 fun demonstrateLocationWindowCommonMethods() {
26 println("=== LocationWindowCommon Methods ===")
28 demonstrateSetSublocationId()
29 demonstrateSublocationQueries()
30 demonstrateSublocationChangeListener()
31 demonstrateUserLocationLayer()
32 demonstrateCoordinateConversion()
33 demonstrateMapFeatureSelection()
34 demonstrateApplyLayerFilter()
35 demonstrateDebugFlags()
36 demonstrateZoomProperties()
40 * Demonstrate debug overlay flags (static LocationWindow API).
42 fun demonstrateDebugFlags() {
43 println("--- Debug flags ---")
45 // [kotlin_DebugFlag_enum]
46 val allFlags = listOf(
51 DebugFlag.DRAW_ALL_LABELS,
52 DebugFlag.SELECTION_BUFFER
54 println("Debug flag enum values: ${allFlags.size}")
55 // [kotlin_DebugFlag_enum]
57 // [kotlin_LocationWindow_setDebugFlag]
58 LocationWindow.setDebugFlag(DebugFlag.INFOS, true)
59 LocationWindow.setDebugFlag(DebugFlag.STATS, false)
60 println("Updated debug flags on LocationWindow")
61 // [kotlin_LocationWindow_setDebugFlag]
63 // [kotlin_LocationWindow_getDebugFlag]
64 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
65 println("Debug flag INFOS enabled: $infosOn")
66 // [kotlin_LocationWindow_getDebugFlag]
70 * Demonstrate setSublocationId method
72 fun demonstrateSetSublocationId() {
73 println("--- setSublocationId Method ---")
75 if (locationWindow == null) {
76 println("LocationWindow not available yet")
80 // [kotlin_LocationWindow_setSublocationId]
81 // Set sublocation ID to switch between floors
82 locationWindow!!.setSublocationId(1)
83 println("Set sublocation ID to 1 (first floor)")
84 // [kotlin_LocationWindow_setSublocationId]
86 // [kotlin_LocationWindow_setSublocationId_2]
87 // Set sublocation ID to another floor
88 locationWindow!!.setSublocationId(2)
89 println("Set sublocation ID to 2 (second floor)")
90 // [kotlin_LocationWindow_setSublocationId_2]
92 // [kotlin_LocationWindow_setSublocationId_3]
93 // Set sublocation ID to ground floor
94 locationWindow!!.setSublocationId(0)
95 println("Set sublocation ID to 0 (ground floor)")
96 // [kotlin_LocationWindow_setSublocationId_3]
98 // Test with different sublocation IDs
99 val sublocationIds = listOf(1, 2, 3, 0, 5)
100 for (id in sublocationIds) {
101 locationWindow!!.setSublocationId(id)
102 println("Switched to sublocation ID: $id")
107 * Demonstrate getters for sublocation and enclosing camera
109 fun demonstrateSublocationQueries() {
110 println("--- getSublocationId & getEnclosingCamera ---")
112 if (locationWindow == null) {
113 println("LocationWindow not available yet")
117 // [kotlin_LocationWindow_getSublocationId]
118 val currentId = locationWindow!!.getSublocationId()
119 if (currentId != null) {
120 println("Current sublocation id: $currentId")
122 println("Current sublocation id is not set")
124 // [kotlin_LocationWindow_getSublocationId]
126 // [kotlin_LocationWindow_getEnclosingCamera]
127 val boundingBox = BoundingBox(Point(0.0, 0.0), Point(20.0, 30.0))
128 val camera = locationWindow!!.getEnclosingCamera(boundingBox)
129 println("Camera that fits bounding box: $camera")
130 // [kotlin_LocationWindow_getEnclosingCamera]
134 * Demonstrate sublocation change listener usage
136 fun demonstrateSublocationChangeListener() {
137 println("--- Sublocation Change Listener ---")
139 if (locationWindow == null) {
140 println("LocationWindow not available yet")
144 val listener = DemoSublocationChangeListener()
146 // [kotlin_LocationWindow_addSublocationChangeListener]
147 locationWindow!!.addSublocationChangeListener(listener)
148 println("Added sublocation change listener")
149 // [kotlin_LocationWindow_addSublocationChangeListener]
151 locationWindow!!.setSublocationId(1)
152 locationWindow!!.setSublocationId(2)
154 // [kotlin_LocationWindow_removeSublocationChangeListener]
155 locationWindow!!.removeSublocationChangeListener(listener)
156 println("Removed sublocation change listener")
157 // [kotlin_LocationWindow_removeSublocationChangeListener]
161 * Demonstrate user location layer controls
163 fun demonstrateUserLocationLayer() {
164 println("--- UserLocationLayer ---")
166 if (userLocationLayer == null) {
167 println("UserLocationLayer not available yet")
171 // [kotlin_UserLocationLayer_setVisible]
172 userLocationLayer!!.setVisible(true)
173 println("User location layer set visible")
174 // [kotlin_UserLocationLayer_setVisible]
176 // [kotlin_UserLocationLayer_isVisible]
177 val visible = userLocationLayer!!.isVisible
178 println("User location layer is visible: $visible")
179 // [kotlin_UserLocationLayer_isVisible]
181 // [kotlin_UserLocationLayer_setAnchor]
182 val anchor = ScreenPoint(100.0f, 200.0f)
183 userLocationLayer!!.setAnchor(anchor)
184 println("Set user location anchor to: (${anchor.x}, ${anchor.y})")
185 // [kotlin_UserLocationLayer_setAnchor]
187 // [kotlin_UserLocationLayer_anchorEnabled]
188 val anchorEnabled = userLocationLayer!!.anchorEnabled
189 println("Anchor enabled: $anchorEnabled")
190 // [kotlin_UserLocationLayer_anchorEnabled]
192 // [kotlin_UserLocationLayer_resetAnchor]
193 userLocationLayer!!.resetAnchor()
194 println("Anchor reset to default")
195 // [kotlin_UserLocationLayer_resetAnchor]
199 * Demonstrate coordinate conversion methods
201 fun demonstrateCoordinateConversion() {
202 println("--- Coordinate Conversion Methods ---")
204 if (locationWindow == null) {
205 println("LocationWindow not available yet")
209 // [kotlin_LocationWindow_screenPositionToMeters]
210 // Convert screen position to meters
211 val screenPoint = Point(100.0, 200.0)
212 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
213 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})")
214 // [kotlin_LocationWindow_screenPositionToMeters]
216 // [kotlin_LocationWindow_screenPositionToMeters_2]
217 // Convert another screen position to meters
218 val screenPoint2 = Point(500.0, 300.0)
219 val metersPoint2 = locationWindow!!.screenPositionToMeters(screenPoint2)
220 println("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})")
221 // [kotlin_LocationWindow_screenPositionToMeters_2]
223 // [kotlin_LocationWindow_metersToScreenPosition]
224 // Convert meters to screen position with clipping
225 val metersPoint3 = Point(50.0, 75.0)
226 val screenPoint3 = locationWindow!!.metersToScreenPosition(metersPoint3, true)
227 println("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})")
228 // [kotlin_LocationWindow_metersToScreenPosition]
230 // [kotlin_LocationWindow_metersToScreenPosition_2]
231 // Convert meters to screen position without clipping
232 val metersPoint4 = Point(150.0, 200.0)
233 val screenPoint4 = locationWindow!!.metersToScreenPosition(metersPoint4, false)
234 println("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})")
235 // [kotlin_LocationWindow_metersToScreenPosition_2]
237 // Test coordinate conversion with different values
238 val testScreenPoints = listOf(
244 for ((index, screenPoint) in testScreenPoints.withIndex()) {
245 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
246 val backToScreen = locationWindow!!.metersToScreenPosition(metersPoint, false)
247 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
252 * Demonstrate map feature selection methods
254 fun demonstrateMapFeatureSelection() {
255 println("--- Map Feature Selection Methods ---")
257 if (locationWindow == null) {
258 println("LocationWindow not available yet")
262 // [kotlin_LocationWindow_selectMapFeature]
263 // Select map feature by ID
264 val featureId = "room_101"
265 val selected = locationWindow!!.selectMapFeature(featureId)
266 println("Selected map feature $featureId: $selected")
267 // [kotlin_LocationWindow_selectMapFeature]
269 // [kotlin_LocationWindow_selectMapFeature_2]
270 // Select another map feature
271 val featureId2 = "office_205"
272 val selected2 = locationWindow!!.selectMapFeature(featureId2)
273 println("Selected map feature $featureId2: $selected2")
274 // [kotlin_LocationWindow_selectMapFeature_2]
276 // [kotlin_LocationWindow_getSelectedMapFeatures]
277 // Get list of selected map features
278 val selectedFeatures = locationWindow!!.selectedMapFeatures
279 println("Currently selected map features: ${selectedFeatures.size} features")
280 for (feature in selectedFeatures) {
281 println(" - $feature")
283 // [kotlin_LocationWindow_getSelectedMapFeatures]
285 // [kotlin_LocationWindow_deselectMapFeature]
286 // Deselect specific map feature
287 val deselected = locationWindow!!.deselectMapFeature(featureId)
288 println("Deselected map feature $featureId: $deselected")
289 // [kotlin_LocationWindow_deselectMapFeature]
291 // [kotlin_LocationWindow_deselectMapFeature_2]
292 // Deselect another map feature
293 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
294 println("Deselected map feature $featureId2: $deselected2")
295 // [kotlin_LocationWindow_deselectMapFeature_2]
297 // [kotlin_LocationWindow_deselectAllMapFeatures]
298 // Deselect all map features
299 locationWindow!!.deselectAllMapFeatures()
300 println("Deselected all map features")
301 // [kotlin_LocationWindow_deselectAllMapFeatures]
303 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
304 // Verify all features are deselected
305 val remainingFeatures = locationWindow!!.selectedMapFeatures
306 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
307 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
309 // Test multiple feature selection and deselection
310 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
312 // Select multiple features
313 for (featureId in testFeatureIds) {
314 val success = locationWindow!!.selectMapFeature(featureId)
315 println("Selected feature $featureId: $success")
318 // Check selected features
319 val allSelected = locationWindow!!.selectedMapFeatures
320 println("All selected features: ${allSelected.size} features")
322 // Deselect all at once
323 locationWindow!!.deselectAllMapFeatures()
324 println("Deselected all features at once")
328 * Demonstrate applyLayerFilter method
330 fun demonstrateApplyLayerFilter() {
331 println("--- applyLayerFilter Method ---")
333 if (locationWindow == null) {
334 println("LocationWindow not available yet")
338 // [kotlin_MapFilterCondition_constructor]
339 // Create filter condition: show only venues with category "Toilet" or "Cafe"
340 val condition = MapFilterCondition("category", listOf("Toilet", "Cafe"))
341 // [kotlin_MapFilterCondition_constructor]
343 // [kotlin_LocationWindow_applyLayerFilter]
344 // Apply filter to venues layer
345 val conditions = listOf(MapFilterCondition("category", listOf("Toilet", "Cafe")))
346 locationWindow!!.applyLayerFilter("venues", conditions)
347 println("Applied layer filter: show venues with category Toilet or Cafe")
348 // [kotlin_LocationWindow_applyLayerFilter]
350 // Reset filter (show all venues)
351 locationWindow!!.applyLayerFilter("venues", emptyList())
352 println("Reset layer filter: show all venues")
356 * Demonstrate zoom properties
358 fun demonstrateZoomProperties() {
359 println("--- Zoom Properties ---")
361 if (locationWindow == null) {
362 println("LocationWindow not available yet")
366 // [kotlin_LocationWindow_getZoomFactor]
367 // Get current zoom factor
368 val currentZoom = locationWindow!!.zoomFactor
369 println("Current zoom factor: $currentZoom")
370 // [kotlin_LocationWindow_getZoomFactor]
372 // [kotlin_LocationWindow_setZoomFactor]
374 locationWindow!!.zoomFactor = 150.0
375 println("Set zoom factor to 150.0")
376 // [kotlin_LocationWindow_setZoomFactor]
378 // [kotlin_LocationWindow_getMinZoomFactor]
379 // Get minimum zoom factor
380 val minZoomFactor = locationWindow!!.minZoomFactor
381 println("Minimum zoom factor: $minZoomFactor")
382 // [kotlin_LocationWindow_getMinZoomFactor]
384 // [kotlin_LocationWindow_setMinZoomFactor]
385 // Set minimum zoom factor
386 locationWindow!!.minZoomFactor = 50.0
387 println("Set minimum zoom factor to 50.0")
388 // [kotlin_LocationWindow_setMinZoomFactor]
390 // [kotlin_LocationWindow_getMaxZoomFactor]
391 // Get maximum zoom factor
392 val maxZoomFactor = locationWindow!!.maxZoomFactor
393 println("Maximum zoom factor: $maxZoomFactor")
394 // [kotlin_LocationWindow_getMaxZoomFactor]
396 // [kotlin_LocationWindow_setMaxZoomFactor]
397 // Set maximum zoom factor
398 locationWindow!!.maxZoomFactor = 300.0
399 println("Set maximum zoom factor to 300.0")
400 // [kotlin_LocationWindow_setMaxZoomFactor]
402 // Test zoom factor changes
403 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
404 for (zoom in testZoomFactors) {
405 locationWindow!!.zoomFactor = zoom
406 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
410 println("Testing zoom limits...")
411 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
412 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
414 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
415 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
418 locationWindow!!.zoomFactor = 100.0
419 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
423 * Main demonstration method
425 suspend fun runExample() {
426 println("=== LocationWindowCommon Example ===")
428 // Simulate LocationWindow initialization
431 // TODO: User will implement LocationWindow initialization here
432 // locationWindow = getLocationWindow()
434 // Run demonstrations
435 demonstrateLocationWindowCommonMethods()
437 println("=== Example completed ===")
442 * Function to run the example
444fun main() = runBlocking {
445 val example = LocationWindowCommonExample()
449class DemoSublocationChangeListener : SublocationChangeListener {
450 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
451 override fun onActiveSublocationChanged(sublocationId: Int) {
452 println("Active sublocation changed to: $sublocationId")
454 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]