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
18 init {
19 demonstrateLocationWindowCommonMethods()
20 }
21
22 /**
23 * Demonstrate LocationWindowCommon methods
24 */
25 fun demonstrateLocationWindowCommonMethods() {
26 println("=== LocationWindowCommon Methods ===")
27
28 demonstrateSetSublocationId()
29 demonstrateOperatingMode()
30 demonstrateSublocationQueries()
31 demonstrateSublocationChangeListener()
32 demonstrateUserLocationLayer()
33 demonstrateCoordinateConversion()
34 demonstrateMapFeatureSelection()
35 demonstrateApplyLayerFilter()
36 demonstrateDebugFlags()
37 demonstrateZoomProperties()
38 }
39
40 /**
41 * Demonstrate debug overlay flags (static LocationWindow API).
42 */
43 fun demonstrateDebugFlags() {
44 println("--- Debug flags ---")
45
46 // [kotlin_DebugFlag_enum]
47 val allFlags = listOf(
48 DebugFlag.NONE,
49 DebugFlag.INFOS,
50 DebugFlag.STATS,
51 DebugFlag.LABELS,
52 DebugFlag.DRAW_ALL_LABELS,
53 DebugFlag.SELECTION_BUFFER
54 )
55 println("Debug flag enum values: ${allFlags.size}")
56 // [kotlin_DebugFlag_enum]
57
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]
63
64 // [kotlin_LocationWindow_getDebugFlag]
65 val infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS)
66 println("Debug flag INFOS enabled: $infosOn")
67 // [kotlin_LocationWindow_getDebugFlag]
68 }
69
70
71 /**
72 * Demonstrate operating mode (indoor / outdoor basemap).
73 */
74 fun demonstrateOperatingMode() {
75 println("--- Operating Mode ---")
76
77 if (locationWindow == null) {
78 println("LocationWindow not available yet")
79 return
80 }
81
82 // [kotlin_OperatingMode_enum]
83 val modes = listOf(
84 OperatingMode.INDOOR_ONLY,
85 OperatingMode.OUTDOOR,
86 OperatingMode.OUTDOOR_INDOOR
87 )
88 println("Operating modes: ${modes.size}")
89 // [kotlin_OperatingMode_enum]
90
91 // [kotlin_LocationWindow_setOperatingMode]
92 locationWindow!!.setOperatingMode(OperatingMode.OUTDOOR_INDOOR)
93 println("Set operating mode to OUTDOOR_INDOOR")
94 // [kotlin_LocationWindow_setOperatingMode]
95
96 // [kotlin_LocationWindow_getOperatingMode]
97 val currentMode = locationWindow!!.operatingMode
98 println("Current operating mode: $currentMode")
99 // [kotlin_LocationWindow_getOperatingMode]
100
101 // [kotlin_AttributionAlignment_record]
102 val alignment = AttributionAlignment(
103 AttributionHorizontalAlignment.RIGHT,
104 AttributionVerticalAlignment.BOTTOM)
105 // [kotlin_AttributionAlignment_record]
106
107 // [kotlin_LocationWindow_setAttributionAlignment]
108 locationWindow!!.attributionAlignment = alignment
109 // [kotlin_LocationWindow_setAttributionAlignment]
110
111 // [kotlin_LocationWindow_getAttribution]
112 val attribution = locationWindow!!.attribution
113 println("Attribution: $attribution")
114 // [kotlin_LocationWindow_getAttribution]
115 }
116
117 /**
118 * Demonstrate setSublocationId method
119 */
120 fun demonstrateSetSublocationId() {
121 println("--- setSublocationId Method ---")
122
123 if (locationWindow == null) {
124 println("LocationWindow not available yet")
125 return
126 }
127
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]
133
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]
139
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]
145
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")
151 }
152 }
153
154 /**
155 * Demonstrate getters for sublocation and enclosing camera
156 */
157 fun demonstrateSublocationQueries() {
158 println("--- getSublocationId & getEnclosingCamera ---")
159
160 if (locationWindow == null) {
161 println("LocationWindow not available yet")
162 return
163 }
164
165 // [kotlin_LocationWindow_getSublocationId]
166 val currentId = locationWindow!!.getSublocationId()
167 if (currentId != null) {
168 println("Current sublocation id: $currentId")
169 } else {
170 println("Current sublocation id is not set")
171 }
172 // [kotlin_LocationWindow_getSublocationId]
173
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]
179 }
180
181 /**
182 * Demonstrate sublocation change listener usage
183 */
184 fun demonstrateSublocationChangeListener() {
185 println("--- Sublocation Change Listener ---")
186
187 if (locationWindow == null) {
188 println("LocationWindow not available yet")
189 return
190 }
191
192 val listener = DemoSublocationChangeListener()
193
194 // [kotlin_LocationWindow_addSublocationChangeListener]
195 locationWindow!!.addSublocationChangeListener(listener)
196 println("Added sublocation change listener")
197 // [kotlin_LocationWindow_addSublocationChangeListener]
198
199 locationWindow!!.setSublocationId(1)
200 locationWindow!!.setSublocationId(2)
201
202 // [kotlin_LocationWindow_removeSublocationChangeListener]
203 locationWindow!!.removeSublocationChangeListener(listener)
204 println("Removed sublocation change listener")
205 // [kotlin_LocationWindow_removeSublocationChangeListener]
206 }
207
208 /**
209 * Demonstrate user location layer controls
210 */
211 fun demonstrateUserLocationLayer() {
212 println("--- UserLocationLayer ---")
213
214 if (userLocationLayer == null) {
215 println("UserLocationLayer not available yet")
216 return
217 }
218
219 // [kotlin_UserLocationLayer_setVisible]
220 userLocationLayer!!.setVisible(true)
221 println("User location layer set visible")
222 // [kotlin_UserLocationLayer_setVisible]
223
224 // [kotlin_UserLocationLayer_isVisible]
225 val visible = userLocationLayer!!.isVisible
226 println("User location layer is visible: $visible")
227 // [kotlin_UserLocationLayer_isVisible]
228
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]
234
235 // [kotlin_UserLocationLayer_anchorEnabled]
236 val anchorEnabled = userLocationLayer!!.anchorEnabled
237 println("Anchor enabled: $anchorEnabled")
238 // [kotlin_UserLocationLayer_anchorEnabled]
239
240 // [kotlin_UserLocationLayer_resetAnchor]
241 userLocationLayer!!.resetAnchor()
242 println("Anchor reset to default")
243 // [kotlin_UserLocationLayer_resetAnchor]
244 }
245
246 /**
247 * Demonstrate coordinate conversion methods
248 */
249 fun demonstrateCoordinateConversion() {
250 println("--- Coordinate Conversion Methods ---")
251
252 if (locationWindow == null) {
253 println("LocationWindow not available yet")
254 return
255 }
256
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]
262
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]
268
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)
274 )
275
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})")
280 }
281 }
282
283 /**
284 * Demonstrate map feature selection methods
285 */
286 fun demonstrateMapFeatureSelection() {
287 println("--- Map Feature Selection Methods ---")
288
289 if (locationWindow == null) {
290 println("LocationWindow not available yet")
291 return
292 }
293
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]
300
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]
307
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")
314 }
315 // [kotlin_LocationWindow_getSelectedMapFeatures]
316
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]
322
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]
328
329 // [kotlin_LocationWindow_deselectAllMapFeatures]
330 // Deselect all map features
331 locationWindow!!.deselectAllMapFeatures()
332 println("Deselected all map features")
333 // [kotlin_LocationWindow_deselectAllMapFeatures]
334
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]
340
341 // Test multiple feature selection and deselection
342 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
343
344 // Select multiple features
345 for (featureId in testFeatureIds) {
346 val success = locationWindow!!.selectMapFeature(featureId)
347 println("Selected feature $featureId: $success")
348 }
349
350 // Check selected features
351 val allSelected = locationWindow!!.selectedMapFeatures
352 println("All selected features: ${allSelected.size} features")
353
354 // Deselect all at once
355 locationWindow!!.deselectAllMapFeatures()
356 println("Deselected all features at once")
357 }
358
359 /**
360 * Demonstrate applyLayerFilter method
361 */
362 fun demonstrateApplyLayerFilter() {
363 println("--- applyLayerFilter Method ---")
364
365 if (locationWindow == null) {
366 println("LocationWindow not available yet")
367 return
368 }
369
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]
374
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]
381
382 // Reset filter (show all venues)
383 locationWindow!!.applyLayerFilter("venues", emptyList())
384 println("Reset layer filter: show all venues")
385 }
386
387 /**
388 * Demonstrate zoom properties
389 */
390 fun demonstrateZoomProperties() {
391 println("--- Zoom Properties ---")
392
393 if (locationWindow == null) {
394 println("LocationWindow not available yet")
395 return
396 }
397
398 // [kotlin_LocationWindow_getZoomFactor]
399 // Get current zoom factor
400 val currentZoom = locationWindow!!.zoomFactor
401 println("Current zoom factor: $currentZoom")
402 // [kotlin_LocationWindow_getZoomFactor]
403
404 // [kotlin_LocationWindow_setZoomFactor]
405 // Set zoom factor
406 locationWindow!!.zoomFactor = 150.0
407 println("Set zoom factor to 150.0")
408 // [kotlin_LocationWindow_setZoomFactor]
409
410 // [kotlin_LocationWindow_getMinZoomFactor]
411 // Get minimum zoom factor
412 val minZoomFactor = locationWindow!!.minZoomFactor
413 println("Minimum zoom factor: $minZoomFactor")
414 // [kotlin_LocationWindow_getMinZoomFactor]
415
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]
421
422 // [kotlin_LocationWindow_getMaxZoomFactor]
423 // Get maximum zoom factor
424 val maxZoomFactor = locationWindow!!.maxZoomFactor
425 println("Maximum zoom factor: $maxZoomFactor")
426 // [kotlin_LocationWindow_getMaxZoomFactor]
427
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]
433
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}")
439 }
440
441 // Test zoom limits
442 println("Testing zoom limits...")
443 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
444 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
445
446 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
447 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
448
449 // Reset to default
450 locationWindow!!.zoomFactor = 100.0
451 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
452 }
453
454 /**
455 * Main demonstration method
456 */
457 suspend fun runExample() {
458 println("=== LocationWindowCommon Example ===")
459
460 // Simulate LocationWindow initialization
461 delay(500)
462
463 // TODO: User will implement LocationWindow initialization here
464 // locationWindow = getLocationWindow()
465
466 // Run demonstrations
467 demonstrateLocationWindowCommonMethods()
468
469 println("=== Example completed ===")
470 }
471}
472
473/**
474 * Function to run the example
475 */
476fun main() = runBlocking {
477 val example = LocationWindowCommonExample()
478 example.runExample()
479}
480
481class DemoSublocationChangeListener : SublocationChangeListener {
482 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
483 override fun onActiveSublocationChanged(sublocationId: Int) {
484 println("Active sublocation changed to: $sublocationId")
485 }
486 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
487}