Loading...
Searching...
No Matches
LocationWindowCommonExample.kt
Go to the documentation of this file.
1import kotlinx.coroutines.delay
2import kotlinx.coroutines.runBlocking
3
4/**
5 * LocationWindowCommon usage example for Kotlin
6 * Demonstrates specific methods: setSublocationId, screenPositionToMeters, metersToScreenPosition,
7 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
8 * zoomFactor, minZoomFactor, maxZoomFactor
9 */
10class LocationWindowCommonExample {
11
12 private var locationWindow: LocationWindow? = null
13
14 init {
15 demonstrateLocationWindowCommonMethods()
16 }
17
18 /**
19 * Demonstrate LocationWindowCommon methods
20 */
21 fun demonstrateLocationWindowCommonMethods() {
22 println("=== LocationWindowCommon Methods ===")
23
24 demonstrateSetSublocationId()
25 demonstrateCoordinateConversion()
26 demonstrateMapFeatureSelection()
27 demonstrateZoomProperties()
28 }
29
30 /**
31 * Demonstrate setSublocationId method
32 */
33 fun demonstrateSetSublocationId() {
34 println("--- setSublocationId Method ---")
35
36 if (locationWindow == null) {
37 println("LocationWindow not available yet")
38 return
39 }
40
41 // [kotlin_LocationWindow_setSublocationId]
42 // Set sublocation ID to switch between floors
43 locationWindow!!.setSublocationId(1)
44 println("Set sublocation ID to 1 (first floor)")
45 // [kotlin_LocationWindow_setSublocationId]
46
47 // [kotlin_LocationWindow_setSublocationId_2]
48 // Set sublocation ID to another floor
49 locationWindow!!.setSublocationId(2)
50 println("Set sublocation ID to 2 (second floor)")
51 // [kotlin_LocationWindow_setSublocationId_2]
52
53 // [kotlin_LocationWindow_setSublocationId_3]
54 // Set sublocation ID to ground floor
55 locationWindow!!.setSublocationId(0)
56 println("Set sublocation ID to 0 (ground floor)")
57 // [kotlin_LocationWindow_setSublocationId_3]
58
59 // Test with different sublocation IDs
60 val sublocationIds = listOf(1, 2, 3, 0, 5)
61 for (id in sublocationIds) {
62 locationWindow!!.setSublocationId(id)
63 println("Switched to sublocation ID: $id")
64 }
65 }
66
67 /**
68 * Demonstrate coordinate conversion methods
69 */
70 fun demonstrateCoordinateConversion() {
71 println("--- Coordinate Conversion Methods ---")
72
73 if (locationWindow == null) {
74 println("LocationWindow not available yet")
75 return
76 }
77
78 // [kotlin_LocationWindow_screenPositionToMeters]
79 // Convert screen position to meters
80 val screenPoint = Point(100.0, 200.0)
81 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
82 println("Screen position (${screenPoint.x}, ${screenPoint.y}) converted to meters: (${metersPoint.x}, ${metersPoint.y})")
83 // [kotlin_LocationWindow_screenPositionToMeters]
84
85 // [kotlin_LocationWindow_screenPositionToMeters_2]
86 // Convert another screen position to meters
87 val screenPoint2 = Point(500.0, 300.0)
88 val metersPoint2 = locationWindow!!.screenPositionToMeters(screenPoint2)
89 println("Screen position (${screenPoint2.x}, ${screenPoint2.y}) converted to meters: (${metersPoint2.x}, ${metersPoint2.y})")
90 // [kotlin_LocationWindow_screenPositionToMeters_2]
91
92 // [kotlin_LocationWindow_metersToScreenPosition]
93 // Convert meters to screen position with clipping
94 val metersPoint3 = Point(50.0, 75.0)
95 val screenPoint3 = locationWindow!!.metersToScreenPosition(metersPoint3, true)
96 println("Meters position (${metersPoint3.x}, ${metersPoint3.y}) converted to screen with clipping: (${screenPoint3.x}, ${screenPoint3.y})")
97 // [kotlin_LocationWindow_metersToScreenPosition]
98
99 // [kotlin_LocationWindow_metersToScreenPosition_2]
100 // Convert meters to screen position without clipping
101 val metersPoint4 = Point(150.0, 200.0)
102 val screenPoint4 = locationWindow!!.metersToScreenPosition(metersPoint4, false)
103 println("Meters position (${metersPoint4.x}, ${metersPoint4.y}) converted to screen without clipping: (${screenPoint4.x}, ${screenPoint4.y})")
104 // [kotlin_LocationWindow_metersToScreenPosition_2]
105
106 // Test coordinate conversion with different values
107 val testScreenPoints = listOf(
108 Point(0.0, 0.0),
109 Point(250.0, 250.0),
110 Point(1000.0, 600.0)
111 )
112
113 for ((index, screenPoint) in testScreenPoints.withIndex()) {
114 val metersPoint = locationWindow!!.screenPositionToMeters(screenPoint)
115 val backToScreen = locationWindow!!.metersToScreenPosition(metersPoint, false)
116 println("Test $index: Screen (${screenPoint.x}, ${screenPoint.y}) -> Meters (${metersPoint.x}, ${metersPoint.y}) -> Screen (${backToScreen.x}, ${backToScreen.y})")
117 }
118 }
119
120 /**
121 * Demonstrate map feature selection methods
122 */
123 fun demonstrateMapFeatureSelection() {
124 println("--- Map Feature Selection Methods ---")
125
126 if (locationWindow == null) {
127 println("LocationWindow not available yet")
128 return
129 }
130
131 // [kotlin_LocationWindow_selectMapFeature]
132 // Select map feature by ID
133 val featureId = "room_101"
134 val selected = locationWindow!!.selectMapFeature(featureId)
135 println("Selected map feature $featureId: $selected")
136 // [kotlin_LocationWindow_selectMapFeature]
137
138 // [kotlin_LocationWindow_selectMapFeature_2]
139 // Select another map feature
140 val featureId2 = "office_205"
141 val selected2 = locationWindow!!.selectMapFeature(featureId2)
142 println("Selected map feature $featureId2: $selected2")
143 // [kotlin_LocationWindow_selectMapFeature_2]
144
145 // [kotlin_LocationWindow_getSelectedMapFeatures]
146 // Get list of selected map features
147 val selectedFeatures = locationWindow!!.selectedMapFeatures
148 println("Currently selected map features: ${selectedFeatures.size} features")
149 for (feature in selectedFeatures) {
150 println(" - $feature")
151 }
152 // [kotlin_LocationWindow_getSelectedMapFeatures]
153
154 // [kotlin_LocationWindow_deselectMapFeature]
155 // Deselect specific map feature
156 val deselected = locationWindow!!.deselectMapFeature(featureId)
157 println("Deselected map feature $featureId: $deselected")
158 // [kotlin_LocationWindow_deselectMapFeature]
159
160 // [kotlin_LocationWindow_deselectMapFeature_2]
161 // Deselect another map feature
162 val deselected2 = locationWindow!!.deselectMapFeature(featureId2)
163 println("Deselected map feature $featureId2: $deselected2")
164 // [kotlin_LocationWindow_deselectMapFeature_2]
165
166 // [kotlin_LocationWindow_deselectAllMapFeatures]
167 // Deselect all map features
168 locationWindow!!.deselectAllMapFeatures()
169 println("Deselected all map features")
170 // [kotlin_LocationWindow_deselectAllMapFeatures]
171
172 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
173 // Verify all features are deselected
174 val remainingFeatures = locationWindow!!.selectedMapFeatures
175 println("Remaining selected features after deselect all: ${remainingFeatures.size} features")
176 // [kotlin_LocationWindow_getSelectedMapFeatures_2]
177
178 // Test multiple feature selection and deselection
179 val testFeatureIds = listOf("room_101", "office_205", "meeting_room_301", "cafe_401")
180
181 // Select multiple features
182 for (featureId in testFeatureIds) {
183 val success = locationWindow!!.selectMapFeature(featureId)
184 println("Selected feature $featureId: $success")
185 }
186
187 // Check selected features
188 val allSelected = locationWindow!!.selectedMapFeatures
189 println("All selected features: ${allSelected.size} features")
190
191 // Deselect all at once
192 locationWindow!!.deselectAllMapFeatures()
193 println("Deselected all features at once")
194 }
195
196 /**
197 * Demonstrate zoom properties
198 */
199 fun demonstrateZoomProperties() {
200 println("--- Zoom Properties ---")
201
202 if (locationWindow == null) {
203 println("LocationWindow not available yet")
204 return
205 }
206
207 // [kotlin_LocationWindow_getZoomFactor]
208 // Get current zoom factor
209 val currentZoom = locationWindow!!.zoomFactor
210 println("Current zoom factor: $currentZoom")
211 // [kotlin_LocationWindow_getZoomFactor]
212
213 // [kotlin_LocationWindow_setZoomFactor]
214 // Set zoom factor
215 locationWindow!!.zoomFactor = 150.0
216 println("Set zoom factor to 150.0")
217 // [kotlin_LocationWindow_setZoomFactor]
218
219 // [kotlin_LocationWindow_getMinZoomFactor]
220 // Get minimum zoom factor
221 val minZoomFactor = locationWindow!!.minZoomFactor
222 println("Minimum zoom factor: $minZoomFactor")
223 // [kotlin_LocationWindow_getMinZoomFactor]
224
225 // [kotlin_LocationWindow_setMinZoomFactor]
226 // Set minimum zoom factor
227 locationWindow!!.minZoomFactor = 50.0
228 println("Set minimum zoom factor to 50.0")
229 // [kotlin_LocationWindow_setMinZoomFactor]
230
231 // [kotlin_LocationWindow_getMaxZoomFactor]
232 // Get maximum zoom factor
233 val maxZoomFactor = locationWindow!!.maxZoomFactor
234 println("Maximum zoom factor: $maxZoomFactor")
235 // [kotlin_LocationWindow_getMaxZoomFactor]
236
237 // [kotlin_LocationWindow_setMaxZoomFactor]
238 // Set maximum zoom factor
239 locationWindow!!.maxZoomFactor = 300.0
240 println("Set maximum zoom factor to 300.0")
241 // [kotlin_LocationWindow_setMaxZoomFactor]
242
243 // Test zoom factor changes
244 val testZoomFactors = listOf(100.0, 125.0, 150.0, 200.0, 250.0)
245 for (zoom in testZoomFactors) {
246 locationWindow!!.zoomFactor = zoom
247 println("Changed zoom factor to: ${locationWindow!!.zoomFactor}")
248 }
249
250 // Test zoom limits
251 println("Testing zoom limits...")
252 locationWindow!!.zoomFactor = locationWindow!!.minZoomFactor
253 println("Set to minimum zoom: ${locationWindow!!.zoomFactor}")
254
255 locationWindow!!.zoomFactor = locationWindow!!.maxZoomFactor
256 println("Set to maximum zoom: ${locationWindow!!.zoomFactor}")
257
258 // Reset to default
259 locationWindow!!.zoomFactor = 100.0
260 println("Reset zoom factor to default: ${locationWindow!!.zoomFactor}")
261 }
262
263 /**
264 * Main demonstration method
265 */
266 suspend fun runExample() {
267 println("=== LocationWindowCommon Example ===")
268
269 // Simulate LocationWindow initialization
270 delay(500)
271
272 // TODO: User will implement LocationWindow initialization here
273 // locationWindow = getLocationWindow()
274
275 // Run demonstrations
276 demonstrateLocationWindowCommonMethods()
277
278 println("=== Example completed ===")
279 }
280}
281
282/**
283 * Function to run the example
284 */
285fun main() = runBlocking {
286 val example = LocationWindowCommonExample()
287 example.runExample()
288}