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, screenPositionToMeters, metersToScreenPosition,
10 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
11 * zoomFactor, minZoomFactor, maxZoomFactor
12 */
13class LocationWindowCommonExample {
14
15 private var locationWindow: LocationWindow? = null
16 private var userLocationView: UserLocationView? = null
17 private var userLocationLayer: UserLocationLayer? = null
18
19 init {
20 demonstrateLocationWindowCommonMethods()
21 }
22
23 /**
24 * Demonstrate LocationWindowCommon methods
25 */
26 fun demonstrateLocationWindowCommonMethods() {
27 println("=== LocationWindowCommon Methods ===")
28
29 demonstrateSetSublocationId()
30 demonstrateSublocationQueries()
31 demonstrateSublocationChangeListener()
32 demonstrateUserLocationView()
33 demonstrateUserLocationLayer()
34 demonstrateCoordinateConversion()
35 demonstrateMapFeatureSelection()
36 demonstrateApplyLayerFilter()
37 demonstrateDebugFlags()
38 demonstrateZoomProperties()
39 }
40
41 /**
42 * Demonstrate debug overlay flags (static LocationWindow API).
43 */
44 fun demonstrateDebugFlags() {
45 println("--- Debug flags ---")
46
47 // [kotlin_DebugFlag_enum]
48 val allFlags = listOf(
49 DebugFlag.NONE,
50 DebugFlag.INFOS,
51 DebugFlag.STATS,
52 DebugFlag.LABELS,
53 DebugFlag.DRAW_ALL_LABELS,
54 DebugFlag.SELECTION_BUFFER
55 )
56 println("Debug flag enum values: ${allFlags.size}")
57 // [kotlin_DebugFlag_enum]
58
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]
64
65 // [kotlin_LocationWindow_getDebugFlag]
66 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
67 println("Debug flag INFOS enabled: $infosOn")
68 // [kotlin_LocationWindow_getDebugFlag]
69 }
70
71 /**
72 * Demonstrate setSublocationId method
73 */
74 fun demonstrateSetSublocationId() {
75 println("--- setSublocationId Method ---")
76
77 if (locationWindow == null) {
78 println("LocationWindow not available yet")
79 return
80 }
81
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]
87
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]
93
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]
99
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")
105 }
106 }
107
108 /**
109 * Demonstrate getters for sublocation and enclosing camera
110 */
111 fun demonstrateSublocationQueries() {
112 println("--- getSublocationId & getEnclosingCamera ---")
113
114 if (locationWindow == null) {
115 println("LocationWindow not available yet")
116 return
117 }
118
119 // [kotlin_LocationWindow_getSublocationId]
120 val currentId = locationWindow!!.getSublocationId()
121 if (currentId != null) {
122 println("Current sublocation id: $currentId")
123 } else {
124 println("Current sublocation id is not set")
125 }
126 // [kotlin_LocationWindow_getSublocationId]
127
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]
133 }
134
135 /**
136 * Demonstrate sublocation change listener usage
137 */
138 fun demonstrateSublocationChangeListener() {
139 println("--- Sublocation Change Listener ---")
140
141 if (locationWindow == null) {
142 println("LocationWindow not available yet")
143 return
144 }
145
146 val listener = DemoSublocationChangeListener()
147
148 // [kotlin_LocationWindow_addSublocationChangeListener]
149 locationWindow!!.addSublocationChangeListener(listener)
150 println("Added sublocation change listener")
151 // [kotlin_LocationWindow_addSublocationChangeListener]
152
153 locationWindow!!.setSublocationId(1)
154 locationWindow!!.setSublocationId(2)
155
156 // [kotlin_LocationWindow_removeSublocationChangeListener]
157 locationWindow!!.removeSublocationChangeListener(listener)
158 println("Removed sublocation change listener")
159 // [kotlin_LocationWindow_removeSublocationChangeListener]
160 }
161
162 /**
163 * Demonstrate user location view properties
164 */
165 fun demonstrateUserLocationView() {
166 println("--- UserLocationView ---")
167
168 if (userLocationView == null) {
169 println("UserLocationView not available yet")
170 return
171 }
172
173 // [kotlin_UserLocationView_getArrow]
174 val arrow = userLocationView!!.arrow
175 println("Arrow icon object: $arrow")
176 // [kotlin_UserLocationView_getArrow]
177
178 // [kotlin_UserLocationView_getAccuracyCircle]
179 val accuracyCircle = userLocationView!!.accuracyCircle
180 println("Accuracy circle object: $accuracyCircle")
181 // [kotlin_UserLocationView_getAccuracyCircle]
182 }
183
184 /**
185 * Demonstrate user location layer controls
186 */
187 fun demonstrateUserLocationLayer() {
188 println("--- UserLocationLayer ---")
189
190 if (userLocationLayer == null) {
191 println("UserLocationLayer not available yet")
192 return
193 }
194
195 // [kotlin_UserLocationLayer_setVisible]
196 userLocationLayer!!.setVisible(true)
197 println("User location layer set visible")
198 // [kotlin_UserLocationLayer_setVisible]
199
200 // [kotlin_UserLocationLayer_isVisible]
201 val visible = userLocationLayer!!.isVisible
202 println("User location layer is visible: $visible")
203 // [kotlin_UserLocationLayer_isVisible]
204
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]
210
211 // [kotlin_UserLocationLayer_anchorEnabled]
212 val anchorEnabled = userLocationLayer!!.anchorEnabled
213 println("Anchor enabled: $anchorEnabled")
214 // [kotlin_UserLocationLayer_anchorEnabled]
215
216 // [kotlin_UserLocationLayer_resetAnchor]
217 userLocationLayer!!.resetAnchor()
218 println("Anchor reset to default")
219 // [kotlin_UserLocationLayer_resetAnchor]
220 }
221
222 /**
223 * Demonstrate coordinate conversion methods
224 */
225 fun demonstrateCoordinateConversion() {
226 println("--- Coordinate Conversion Methods ---")
227
228 if (locationWindow == null) {
229 println("LocationWindow not available yet")
230 return
231 }
232
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]
239
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]
246
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]
253
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]
260
261 // Test coordinate conversion with different values
262 val testScreenPoints = listOf(
263 Point(0.0, 0.0),
264 Point(250.0, 250.0),
265 Point(1000.0, 600.0)
266 )
267
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})")
272 }
273 }
274
275 /**
276 * Demonstrate map feature selection methods
277 */
278 fun demonstrateMapFeatureSelection() {
279 println("--- Map Feature Selection Methods ---")
280
281 if (locationWindow == null) {
282 println("LocationWindow not available yet")
283 return
284 }
285
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]
292
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]
299
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")
306 }
307 // [kotlin_LocationWindow_getSelectedMapFeatures]
308
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]
314
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]
320
321 // [kotlin_LocationWindow_deselectAllMapFeatures]
322 // Deselect all map features
323 locationWindow!!.deselectAllMapFeatures()
324 println("Deselected all map features")
325 // [kotlin_LocationWindow_deselectAllMapFeatures]
326
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]
332
333 // Test multiple feature selection and deselection
334 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
335
336 // Select multiple features
337 for (featureId in testFeatureIds) {
338 val success = locationWindow!!.selectMapFeature(featureId)
339 println("Selected feature $featureId: $success")
340 }
341
342 // Check selected features
343 val allSelected = locationWindow!!.selectedMapFeatures
344 println("All selected features: ${allSelected.size} features")
345
346 // Deselect all at once
347 locationWindow!!.deselectAllMapFeatures()
348 println("Deselected all features at once")
349 }
350
351 /**
352 * Demonstrate applyLayerFilter method
353 */
354 fun demonstrateApplyLayerFilter() {
355 println("--- applyLayerFilter Method ---")
356
357 if (locationWindow == null) {
358 println("LocationWindow not available yet")
359 return
360 }
361
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]
366
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]
373
374 // Reset filter (show all venues)
375 locationWindow!!.applyLayerFilter("venues", emptyList())
376 println("Reset layer filter: show all venues")
377 }
378
379 /**
380 * Demonstrate zoom properties
381 */
382 fun demonstrateZoomProperties() {
383 println("--- Zoom Properties ---")
384
385 if (locationWindow == null) {
386 println("LocationWindow not available yet")
387 return
388 }
389
390 // [kotlin_LocationWindow_getZoomFactor]
391 // Get current zoom factor
392 val currentZoom = locationWindow!!.zoomFactor
393 println("Current zoom factor: $currentZoom")
394 // [kotlin_LocationWindow_getZoomFactor]
395
396 // [kotlin_LocationWindow_setZoomFactor]
397 // Set zoom factor
398 locationWindow!!.zoomFactor = 150.0
399 println("Set zoom factor to 150.0")
400 // [kotlin_LocationWindow_setZoomFactor]
401
402 // [kotlin_LocationWindow_getMinZoomFactor]
403 // Get minimum zoom factor
404 val minZoomFactor = locationWindow!!.minZoomFactor
405 println("Minimum zoom factor: $minZoomFactor")
406 // [kotlin_LocationWindow_getMinZoomFactor]
407
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]
413
414 // [kotlin_LocationWindow_getMaxZoomFactor]
415 // Get maximum zoom factor
416 val maxZoomFactor = locationWindow!!.maxZoomFactor
417 println("Maximum zoom factor: $maxZoomFactor")
418 // [kotlin_LocationWindow_getMaxZoomFactor]
419
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]
425
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}")
431 }
432
433 // Test zoom limits
434 println("Testing zoom limits...")
435 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
436 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
437
438 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
439 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
440
441 // Reset to default
442 locationWindow!!.zoomFactor = 100.0
443 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
444 }
445
446 /**
447 * Main demonstration method
448 */
449 suspend fun runExample() {
450 println("=== LocationWindowCommon Example ===")
451
452 // Simulate LocationWindow initialization
453 delay(500)
454
455 // TODO: User will implement LocationWindow initialization here
456 // locationWindow = getLocationWindow()
457
458 // Run demonstrations
459 demonstrateLocationWindowCommonMethods()
460
461 println("=== Example completed ===")
462 }
463}
464
465/**
466 * Function to run the example
467 */
468fun main() = runBlocking {
469 val example = LocationWindowCommonExample()
470 example.runExample()
471}
472
473class DemoSublocationChangeListener : SublocationChangeListener {
474 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
475 override fun onActiveSublocationChanged(sublocationId: Int) {
476 println("Active sublocation changed to: $sublocationId")
477 }
478 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
479}