1import kotlinx.coroutines.delay
2import kotlinx.coroutines.runBlocking
5 * LocationWindowCommon usage example for Kotlin
6 * Demonstrates specific methods: setSublocationId, screenPositionToMeters, metersToScreenPosition,
7 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
8 * zoomFactor, minZoomFactor, maxZoomFactor
10class LocationWindowCommonExample {
12 private var locationWindow: LocationWindow? = null
13 private var userLocationView: UserLocationView? = null
14 private var userLocationLayer: UserLocationLayer? = null
17 demonstrateLocationWindowCommonMethods()
21 * Demonstrate LocationWindowCommon methods
23 fun demonstrateLocationWindowCommonMethods() {
24 println("=== LocationWindowCommon Methods ===")
26 demonstrateSetSublocationId()
27 demonstrateSublocationQueries()
28 demonstrateSublocationChangeListener()
29 demonstrateUserLocationView()
30 demonstrateUserLocationLayer()
31 demonstrateCoordinateConversion()
32 demonstrateMapFeatureSelection()
33 demonstrateZoomProperties()
37 * Demonstrate setSublocationId method
39 fun demonstrateSetSublocationId() {
40 println("--- setSublocationId Method ---")
42 if (locationWindow == null) {
43 println("LocationWindow not available yet")
47 // [kotlin_LocationWindow_setSublocationId]
48 // Set sublocation ID to switch between floors
49 locationWindow!!.setSublocationId(1)
50 println("Set sublocation ID to 1 (first floor)")
51 // [kotlin_LocationWindow_setSublocationId]
53 // [kotlin_LocationWindow_setSublocationId_2]
54 // Set sublocation ID to another floor
55 locationWindow!!.setSublocationId(2)
56 println("Set sublocation ID to 2 (second floor)")
57 // [kotlin_LocationWindow_setSublocationId_2]
59 // [kotlin_LocationWindow_setSublocationId_3]
60 // Set sublocation ID to ground floor
61 locationWindow!!.setSublocationId(0)
62 println("Set sublocation ID to 0 (ground floor)")
63 // [kotlin_LocationWindow_setSublocationId_3]
65 // Test with different sublocation IDs
66 val sublocationIds = listOf(1, 2, 3, 0, 5)
67 for (id in sublocationIds) {
68 locationWindow!!.setSublocationId(id)
69 println("Switched to sublocation ID: $id")
74 * Demonstrate getters for sublocation and enclosing camera
76 fun demonstrateSublocationQueries() {
77 println("--- getSublocationId & getEnclosingCamera ---")
79 if (locationWindow == null) {
80 println("LocationWindow not available yet")
84 // [kotlin_LocationWindow_getSublocationId]
85 val currentId = locationWindow!!.getSublocationId()
86 if (currentId != null) {
87 println("Current sublocation id: $currentId")
89 println("Current sublocation id is not set")
91 // [kotlin_LocationWindow_getSublocationId]
93 // [kotlin_LocationWindow_getEnclosingCamera]
94 val boundingBox = BoundingBox(Point(0.0, 0.0), Point(20.0, 30.0))
95 val camera = locationWindow!!.getEnclosingCamera(boundingBox)
96 println("Camera that fits bounding box: $camera")
97 // [kotlin_LocationWindow_getEnclosingCamera]
101 * Demonstrate sublocation change listener usage
103 fun demonstrateSublocationChangeListener() {
104 println("--- Sublocation Change Listener ---")
106 if (locationWindow == null) {
107 println("LocationWindow not available yet")
111 val listener = DemoSublocationChangeListener()
113 // [kotlin_LocationWindow_addSublocationChangeListener]
114 locationWindow!!.addSublocationChangeListener(listener)
115 println("Added sublocation change listener")
116 // [kotlin_LocationWindow_addSublocationChangeListener]
118 locationWindow!!.setSublocationId(1)
119 locationWindow!!.setSublocationId(2)
121 // [kotlin_LocationWindow_removeSublocationChangeListener]
122 locationWindow!!.removeSublocationChangeListener(listener)
123 println("Removed sublocation change listener")
124 // [kotlin_LocationWindow_removeSublocationChangeListener]
128 * Demonstrate user location view properties
130 fun demonstrateUserLocationView() {
131 println("--- UserLocationView ---")
133 if (userLocationView == null) {
134 println("UserLocationView not available yet")
138 // [kotlin_UserLocationView_getArrow]
139 val arrow = userLocationView!!.arrow
140 println("Arrow icon object: $arrow")
141 // [kotlin_UserLocationView_getArrow]
143 // [kotlin_UserLocationView_getAccuracyCircle]
144 val accuracyCircle = userLocationView!!.accuracyCircle
145 println("Accuracy circle object: $accuracyCircle")
146 // [kotlin_UserLocationView_getAccuracyCircle]
150 * Demonstrate user location layer controls
152 fun demonstrateUserLocationLayer() {
153 println("--- UserLocationLayer ---")
155 if (userLocationLayer == null) {
156 println("UserLocationLayer not available yet")
160 // [kotlin_UserLocationLayer_setVisible]
161 userLocationLayer!!.setVisible(true)
162 println("User location layer set visible")
163 // [kotlin_UserLocationLayer_setVisible]
165 // [kotlin_UserLocationLayer_isVisible]
166 val visible = userLocationLayer!!.isVisible
167 println("User location layer is visible: $visible")
168 // [kotlin_UserLocationLayer_isVisible]
170 // [kotlin_UserLocationLayer_setAnchor]
171 val anchor = ScreenPoint(100.0f, 200.0f)
172 userLocationLayer!!.setAnchor(anchor)
173 println("Set user location anchor to: (${anchor.x}, ${anchor.y})")
174 // [kotlin_UserLocationLayer_setAnchor]
176 // [kotlin_UserLocationLayer_anchorEnabled]
177 val anchorEnabled = userLocationLayer!!.anchorEnabled
178 println("Anchor enabled: $anchorEnabled")
179 // [kotlin_UserLocationLayer_anchorEnabled]
181 // [kotlin_UserLocationLayer_resetAnchor]
182 userLocationLayer!!.resetAnchor()
183 println("Anchor reset to default")
184 // [kotlin_UserLocationLayer_resetAnchor]
188 * Demonstrate coordinate conversion methods
190 fun demonstrateCoordinateConversion() {
191 println("--- Coordinate Conversion Methods ---")
193 if (locationWindow == null) {
194 println("LocationWindow not available yet")
198 // [kotlin_LocationWindow_screenPositionToMeters]
199 // Convert screen position to meters
200 val screenPoint = Point(100.0, 200.0)
201 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
202 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})")
203 // [kotlin_LocationWindow_screenPositionToMeters]
205 // [kotlin_LocationWindow_screenPositionToMeters_2]
206 // Convert another screen position to meters
207 val screenPoint2 = Point(500.0, 300.0)
208 val metersPoint2 = locationWindow!!.screenPositionToMeters(screenPoint2)
209 println("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})")
210 // [kotlin_LocationWindow_screenPositionToMeters_2]
212 // [kotlin_LocationWindow_metersToScreenPosition]
213 // Convert meters to screen position with clipping
214 val metersPoint3 = Point(50.0, 75.0)
215 val screenPoint3 = locationWindow!!.metersToScreenPosition(metersPoint3, true)
216 println("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})")
217 // [kotlin_LocationWindow_metersToScreenPosition]
219 // [kotlin_LocationWindow_metersToScreenPosition_2]
220 // Convert meters to screen position without clipping
221 val metersPoint4 = Point(150.0, 200.0)
222 val screenPoint4 = locationWindow!!.metersToScreenPosition(metersPoint4, false)
223 println("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})")
224 // [kotlin_LocationWindow_metersToScreenPosition_2]
226 // Test coordinate conversion with different values
227 val testScreenPoints = listOf(
233 for ((index, screenPoint) in testScreenPoints.withIndex()) {
234 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
235 val backToScreen = locationWindow!!.metersToScreenPosition(metersPoint, false)
236 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
241 * Demonstrate map feature selection methods
243 fun demonstrateMapFeatureSelection() {
244 println("--- Map Feature Selection Methods ---")
246 if (locationWindow == null) {
247 println("LocationWindow not available yet")
251 // [kotlin_LocationWindow_selectMapFeature]
252 // Select map feature by ID
253 val featureId = "room_101"
254 val selected = locationWindow!!.selectMapFeature(featureId)
255 println("Selected map feature $featureId: $selected")
256 // [kotlin_LocationWindow_selectMapFeature]
258 // [kotlin_LocationWindow_selectMapFeature_2]
259 // Select another map feature
260 val featureId2 = "office_205"
261 val selected2 = locationWindow!!.selectMapFeature(featureId2)
262 println("Selected map feature $featureId2: $selected2")
263 // [kotlin_LocationWindow_selectMapFeature_2]
265 // [kotlin_LocationWindow_getSelectedMapFeatures]
266 // Get list of selected map features
267 val selectedFeatures = locationWindow!!.selectedMapFeatures
268 println("Currently selected map features: ${selectedFeatures.size} features")
269 for (feature in selectedFeatures) {
270 println(" - $feature")
272 // [kotlin_LocationWindow_getSelectedMapFeatures]
274 // [kotlin_LocationWindow_deselectMapFeature]
275 // Deselect specific map feature
276 val deselected = locationWindow!!.deselectMapFeature(featureId)
277 println("Deselected map feature $featureId: $deselected")
278 // [kotlin_LocationWindow_deselectMapFeature]
280 // [kotlin_LocationWindow_deselectMapFeature_2]
281 // Deselect another map feature
282 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
283 println("Deselected map feature $featureId2: $deselected2")
284 // [kotlin_LocationWindow_deselectMapFeature_2]
286 // [kotlin_LocationWindow_deselectAllMapFeatures]
287 // Deselect all map features
288 locationWindow!!.deselectAllMapFeatures()
289 println("Deselected all map features")
290 // [kotlin_LocationWindow_deselectAllMapFeatures]
292 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
293 // Verify all features are deselected
294 val remainingFeatures = locationWindow!!.selectedMapFeatures
295 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
296 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
298 // Test multiple feature selection and deselection
299 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
301 // Select multiple features
302 for (featureId in testFeatureIds) {
303 val success = locationWindow!!.selectMapFeature(featureId)
304 println("Selected feature $featureId: $success")
307 // Check selected features
308 val allSelected = locationWindow!!.selectedMapFeatures
309 println("All selected features: ${allSelected.size} features")
311 // Deselect all at once
312 locationWindow!!.deselectAllMapFeatures()
313 println("Deselected all features at once")
317 * Demonstrate zoom properties
319 fun demonstrateZoomProperties() {
320 println("--- Zoom Properties ---")
322 if (locationWindow == null) {
323 println("LocationWindow not available yet")
327 // [kotlin_LocationWindow_getZoomFactor]
328 // Get current zoom factor
329 val currentZoom = locationWindow!!.zoomFactor
330 println("Current zoom factor: $currentZoom")
331 // [kotlin_LocationWindow_getZoomFactor]
333 // [kotlin_LocationWindow_setZoomFactor]
335 locationWindow!!.zoomFactor = 150.0
336 println("Set zoom factor to 150.0")
337 // [kotlin_LocationWindow_setZoomFactor]
339 // [kotlin_LocationWindow_getMinZoomFactor]
340 // Get minimum zoom factor
341 val minZoomFactor = locationWindow!!.minZoomFactor
342 println("Minimum zoom factor: $minZoomFactor")
343 // [kotlin_LocationWindow_getMinZoomFactor]
345 // [kotlin_LocationWindow_setMinZoomFactor]
346 // Set minimum zoom factor
347 locationWindow!!.minZoomFactor = 50.0
348 println("Set minimum zoom factor to 50.0")
349 // [kotlin_LocationWindow_setMinZoomFactor]
351 // [kotlin_LocationWindow_getMaxZoomFactor]
352 // Get maximum zoom factor
353 val maxZoomFactor = locationWindow!!.maxZoomFactor
354 println("Maximum zoom factor: $maxZoomFactor")
355 // [kotlin_LocationWindow_getMaxZoomFactor]
357 // [kotlin_LocationWindow_setMaxZoomFactor]
358 // Set maximum zoom factor
359 locationWindow!!.maxZoomFactor = 300.0
360 println("Set maximum zoom factor to 300.0")
361 // [kotlin_LocationWindow_setMaxZoomFactor]
363 // Test zoom factor changes
364 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
365 for (zoom in testZoomFactors) {
366 locationWindow!!.zoomFactor = zoom
367 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
371 println("Testing zoom limits...")
372 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
373 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
375 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
376 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
379 locationWindow!!.zoomFactor = 100.0
380 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
384 * Main demonstration method
386 suspend fun runExample() {
387 println("=== LocationWindowCommon Example ===")
389 // Simulate LocationWindow initialization
392 // TODO: User will implement LocationWindow initialization here
393 // locationWindow = getLocationWindow()
395 // Run demonstrations
396 demonstrateLocationWindowCommonMethods()
398 println("=== Example completed ===")
403 * Function to run the example
405fun main() = runBlocking {
406 val example = LocationWindowCommonExample()
410class DemoSublocationChangeListener : SublocationChangeListener {
411 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]
412 override fun onActiveSublocationChanged(sublocationId: Int) {
413 println("Active sublocation changed to: $sublocationId")
415 // [kotlin_SublocationChangeListener_onActiveSublocationChanged]