Loading...
Searching...
No Matches
LocationWindowCommonExample.swift
Go to the documentation of this file.
1import Foundation
2import Dispatch
3
4/**
5 * LocationWindowCommon usage example for Swift
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?
13 private var userLocationView: UserLocationView?
14 private var userLocationLayer: UserLocationLayer?
15
16 init() {
17 demonstrateLocationWindowCommonMethods()
18 }
19
20 /**
21 * Demonstrate LocationWindowCommon methods
22 */
23 func demonstrateLocationWindowCommonMethods() {
24 print("=== LocationWindowCommon Methods ===")
25
26 demonstrateSetSublocationId()
27 demonstrateSublocationQueries()
28 demonstrateSublocationChangeListener()
29 demonstrateUserLocationView()
30 demonstrateUserLocationLayer()
31 demonstrateCoordinateConversion()
32 demonstrateMapFeatureSelection()
33 demonstrateZoomProperties()
34 }
35
36 /**
37 * Demonstrate setSublocationId method
38 */
39 func demonstrateSetSublocationId() {
40 print("--- setSublocationId Method ---")
41
42 guard let locationWindow = locationWindow else {
43 print("LocationWindow not available yet")
44 return
45 }
46
47 // [swift_LocationWindow_setSublocationId]
48 // Set sublocation ID to switch between floors
49 locationWindow.setSublocationId(1)
50 print("Set sublocation ID to 1 (first floor)")
51 // [swift_LocationWindow_setSublocationId]
52
53 // [swift_LocationWindow_setSublocationId_2]
54 // Set sublocation ID to another floor
55 locationWindow.setSublocationId(2)
56 print("Set sublocation ID to 2 (second floor)")
57 // [swift_LocationWindow_setSublocationId_2]
58
59 // [swift_LocationWindow_setSublocationId_3]
60 // Set sublocation ID to ground floor
61 locationWindow.setSublocationId(0)
62 print("Set sublocation ID to 0 (ground floor)")
63 // [swift_LocationWindow_setSublocationId_3]
64
65 // Test with different sublocation IDs
66 let sublocationIds = [1, 2, 3, 0, 5]
67 for id in sublocationIds {
68 locationWindow.setSublocationId(id)
69 print("Switched to sublocation ID: \‍(id)")
70 }
71 }
72
73 /**
74 * Demonstrate getters for sublocation and enclosing camera
75 */
76 func demonstrateSublocationQueries() {
77 print("--- getSublocationId & getEnclosingCamera ---")
78
79 guard let locationWindow = locationWindow else {
80 print("LocationWindow not available yet")
81 return
82 }
83
84 // [swift_LocationWindow_getSublocationId]
85 if let currentId = locationWindow.getSublocationId() {
86 print("Current sublocation id: \‍(currentId)")
87 } else {
88 print("Current sublocation id is not set")
89 }
90 // [swift_LocationWindow_getSublocationId]
91
92 // [swift_LocationWindow_getEnclosingCamera]
93 let boundingBox = BoundingBox(bottomLeft: Point(x: 0.0, y: 0.0),
94 topRight: Point(x: 20.0, y: 30.0))
95 let camera = locationWindow.getEnclosingCamera(boundingBox)
96 print("Camera that fits bounding box: \‍(camera)")
97 // [swift_LocationWindow_getEnclosingCamera]
98 }
99
100 /**
101 * Demonstrate sublocation change listener usage
102 */
103 func demonstrateSublocationChangeListener() {
104 print("--- Sublocation Change Listener ---")
105
106 guard let locationWindow = locationWindow else {
107 print("LocationWindow not available yet")
108 return
109 }
110
111 let listener = DemoSublocationChangeListener()
112
113 // [swift_LocationWindow_addSublocationChangeListener]
114 locationWindow.addSublocationChangeListener(listener)
115 print("Added sublocation change listener")
116 // [swift_LocationWindow_addSublocationChangeListener]
117
118 locationWindow.setSublocationId(1)
119 locationWindow.setSublocationId(2)
120
121 // [swift_LocationWindow_removeSublocationChangeListener]
122 locationWindow.removeSublocationChangeListener(listener)
123 print("Removed sublocation change listener")
124 // [swift_LocationWindow_removeSublocationChangeListener]
125 }
126
127 /**
128 * Demonstrate user location view properties
129 */
130 func demonstrateUserLocationView() {
131 print("--- UserLocationView ---")
132
133 guard let userLocationView = userLocationView else {
134 print("UserLocationView not available yet")
135 return
136 }
137
138 // [swift_UserLocationView_getArrow]
139 let arrow = userLocationView.arrow
140 print("Arrow icon object: \‍(arrow)")
141 // [swift_UserLocationView_getArrow]
142
143 // [swift_UserLocationView_getAccuracyCircle]
144 let accuracyCircle = userLocationView.accuracyCircle
145 print("Accuracy circle object: \‍(accuracyCircle)")
146 // [swift_UserLocationView_getAccuracyCircle]
147 }
148
149 /**
150 * Demonstrate user location layer controls
151 */
152 func demonstrateUserLocationLayer() {
153 print("--- UserLocationLayer ---")
154
155 guard let userLocationLayer = userLocationLayer else {
156 print("UserLocationLayer not available yet")
157 return
158 }
159
160 // [swift_UserLocationLayer_setVisible]
161 userLocationLayer.setVisible(true)
162 print("User location layer set visible")
163 // [swift_UserLocationLayer_setVisible]
164
165 // [swift_UserLocationLayer_isVisible]
166 let visible = userLocationLayer.isVisible()
167 print("User location layer is visible: \‍(visible)")
168 // [swift_UserLocationLayer_isVisible]
169
170 // [swift_UserLocationLayer_setAnchor]
171 let anchor = ScreenPoint(x: 100.0, y: 200.0)
172 userLocationLayer.setAnchor(anchor)
173 print("Set user location anchor to: (\‍(anchor.x), \‍(anchor.y))")
174 // [swift_UserLocationLayer_setAnchor]
175
176 // [swift_UserLocationLayer_anchorEnabled]
177 let anchorEnabled = userLocationLayer.anchorEnabled()
178 print("Anchor enabled: \‍(anchorEnabled)")
179 // [swift_UserLocationLayer_anchorEnabled]
180
181 // [swift_UserLocationLayer_resetAnchor]
182 userLocationLayer.resetAnchor()
183 print("Anchor reset to default")
184 // [swift_UserLocationLayer_resetAnchor]
185 }
186
187 /**
188 * Demonstrate coordinate conversion methods
189 */
190 func demonstrateCoordinateConversion() {
191 print("--- Coordinate Conversion Methods ---")
192
193 guard let locationWindow = locationWindow else {
194 print("LocationWindow not available yet")
195 return
196 }
197
198 // [swift_LocationWindow_screenPositionToMeters]
199 // Convert screen position to meters
200 let screenPoint = Point(x: 100.0, y: 200.0)
201 let metersPoint = locationWindow.screenPositionToMeters(screenPoint)
202 print("Screen position (\‍(screenPoint.x), \‍(screenPoint.y)) converted to meters: (\‍(metersPoint.x), \‍(metersPoint.y))")
203 // [swift_LocationWindow_screenPositionToMeters]
204
205 // [swift_LocationWindow_screenPositionToMeters_2]
206 // Convert another screen position to meters
207 let screenPoint2 = Point(x: 500.0, y: 300.0)
208 let metersPoint2 = locationWindow.screenPositionToMeters(screenPoint2)
209 print("Screen position (\‍(screenPoint2.x), \‍(screenPoint2.y)) converted to meters: (\‍(metersPoint2.x), \‍(metersPoint2.y))")
210 // [swift_LocationWindow_screenPositionToMeters_2]
211
212 // [swift_LocationWindow_metersToScreenPosition]
213 // Convert meters to screen position with clipping
214 let metersPoint3 = Point(x: 50.0, y: 75.0)
215 let screenPoint3 = locationWindow.metersToScreenPosition(metersPoint3, clipToViewport: true)
216 print("Meters position (\‍(metersPoint3.x), \‍(metersPoint3.y)) converted to screen with clipping: (\‍(screenPoint3.x), \‍(screenPoint3.y))")
217 // [swift_LocationWindow_metersToScreenPosition]
218
219 // [swift_LocationWindow_metersToScreenPosition_2]
220 // Convert meters to screen position without clipping
221 let metersPoint4 = Point(x: 150.0, y: 200.0)
222 let screenPoint4 = locationWindow.metersToScreenPosition(metersPoint4, clipToViewport: false)
223 print("Meters position (\‍(metersPoint4.x), \‍(metersPoint4.y)) converted to screen without clipping: (\‍(screenPoint4.x), \‍(screenPoint4.y))")
224 // [swift_LocationWindow_metersToScreenPosition_2]
225
226 // Test coordinate conversion with different values
227 let testScreenPoints = [
228 Point(x: 0.0, y: 0.0),
229 Point(x: 250.0, y: 250.0),
230 Point(x: 1000.0, y: 600.0)
231 ]
232
233 for (index, screenPoint) in testScreenPoints.enumerated() {
234 let metersPoint = locationWindow.screenPositionToMeters(screenPoint)
235 let backToScreen = locationWindow.metersToScreenPosition(metersPoint, clipToViewport: false)
236 print("Test \‍(index): Screen (\‍(screenPoint.x), \‍(screenPoint.y)) -> Meters (\‍(metersPoint.x), \‍(metersPoint.y)) -> Screen (\‍(backToScreen.x), \‍(backToScreen.y))")
237 }
238 }
239
240 /**
241 * Demonstrate map feature selection methods
242 */
243 func demonstrateMapFeatureSelection() {
244 print("--- Map Feature Selection Methods ---")
245
246 guard let locationWindow = locationWindow else {
247 print("LocationWindow not available yet")
248 return
249 }
250
251 // [swift_LocationWindow_selectMapFeature]
252 // Select map feature by ID
253 let featureId = "room_101"
254 let selected = locationWindow.selectMapFeature(featureId)
255 print("Selected map feature \‍(featureId): \‍(selected)")
256 // [swift_LocationWindow_selectMapFeature]
257
258 // [swift_LocationWindow_selectMapFeature_2]
259 // Select another map feature
260 let featureId2 = "office_205"
261 let selected2 = locationWindow.selectMapFeature(featureId2)
262 print("Selected map feature \‍(featureId2): \‍(selected2)")
263 // [swift_LocationWindow_selectMapFeature_2]
264
265 // [swift_LocationWindow_getSelectedMapFeatures]
266 // Get list of selected map features
267 let selectedFeatures = locationWindow.selectedMapFeatures
268 print("Currently selected map features: \‍(selectedFeatures.count) features")
269 for feature in selectedFeatures {
270 print(" - \‍(feature)")
271 }
272 // [swift_LocationWindow_getSelectedMapFeatures]
273
274 // [swift_LocationWindow_deselectMapFeature]
275 // Deselect specific map feature
276 let deselected = locationWindow.deselectMapFeature(featureId)
277 print("Deselected map feature \‍(featureId): \‍(deselected)")
278 // [swift_LocationWindow_deselectMapFeature]
279
280 // [swift_LocationWindow_deselectMapFeature_2]
281 // Deselect another map feature
282 let deselected2 = locationWindow.deselectMapFeature(featureId2)
283 print("Deselected map feature \‍(featureId2): \‍(deselected2)")
284 // [swift_LocationWindow_deselectMapFeature_2]
285
286 // [swift_LocationWindow_deselectAllMapFeatures]
287 // Deselect all map features
288 locationWindow.deselectAllMapFeatures()
289 print("Deselected all map features")
290 // [swift_LocationWindow_deselectAllMapFeatures]
291
292 // [swift_LocationWindow_getSelectedMapFeatures_2]
293 // Verify all features are deselected
294 let remainingFeatures = locationWindow.selectedMapFeatures
295 print("Remaining selected features after deselect all: \‍(remainingFeatures.count) features")
296 // [swift_LocationWindow_getSelectedMapFeatures_2]
297
298 // Test multiple feature selection and deselection
299 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
300
301 // Select multiple features
302 for featureId in testFeatureIds {
303 let success = locationWindow.selectMapFeature(featureId)
304 print("Selected feature \‍(featureId): \‍(success)")
305 }
306
307 // Check selected features
308 let allSelected = locationWindow.selectedMapFeatures
309 print("All selected features: \‍(allSelected.count) features")
310
311 // Deselect all at once
312 locationWindow.deselectAllMapFeatures()
313 print("Deselected all features at once")
314 }
315
316 /**
317 * Demonstrate zoom properties
318 */
319 func demonstrateZoomProperties() {
320 print("--- Zoom Properties ---")
321
322 guard let locationWindow = locationWindow else {
323 print("LocationWindow not available yet")
324 return
325 }
326
327 // [swift_LocationWindow_getZoomFactor]
328 // Get current zoom factor
329 let currentZoom = locationWindow.zoomFactor
330 print("Current zoom factor: \‍(currentZoom)")
331 // [swift_LocationWindow_getZoomFactor]
332
333 // [swift_LocationWindow_setZoomFactor]
334 // Set zoom factor
335 locationWindow.zoomFactor = 150.0
336 print("Set zoom factor to 150.0")
337 // [swift_LocationWindow_setZoomFactor]
338
339 // [swift_LocationWindow_getMinZoomFactor]
340 // Get minimum zoom factor
341 let minZoomFactor = locationWindow.minZoomFactor
342 print("Minimum zoom factor: \‍(minZoomFactor)")
343 // [swift_LocationWindow_getMinZoomFactor]
344
345 // [swift_LocationWindow_setMinZoomFactor]
346 // Set minimum zoom factor
347 locationWindow.minZoomFactor = 50.0
348 print("Set minimum zoom factor to 50.0")
349 // [swift_LocationWindow_setMinZoomFactor]
350
351 // [swift_LocationWindow_getMaxZoomFactor]
352 // Get maximum zoom factor
353 let maxZoomFactor = locationWindow.maxZoomFactor
354 print("Maximum zoom factor: \‍(maxZoomFactor)")
355 // [swift_LocationWindow_getMaxZoomFactor]
356
357 // [swift_LocationWindow_setMaxZoomFactor]
358 // Set maximum zoom factor
359 locationWindow.maxZoomFactor = 300.0
360 print("Set maximum zoom factor to 300.0")
361 // [swift_LocationWindow_setMaxZoomFactor]
362
363 // Test zoom factor changes
364 let testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0]
365 for zoom in testZoomFactors {
366 locationWindow.zoomFactor = zoom
367 print("Changed zoom factor to: \‍(locationWindow.zoomFactor)")
368 }
369
370 // Test zoom limits
371 print("Testing zoom limits...")
372 locationWindow.zoomFactor = locationWindow.minZoomFactor
373 print("Set to minimum zoom: \‍(locationWindow.zoomFactor)")
374
375 locationWindow.zoomFactor = locationWindow.maxZoomFactor
376 print("Set to maximum zoom: \‍(locationWindow.zoomFactor)")
377
378 // Reset to default
379 locationWindow.zoomFactor = 100.0
380 print("Reset zoom factor to default: \‍(locationWindow.zoomFactor)")
381 }
382
383 /**
384 * Main demonstration method
385 */
386 func runExample() {
387 print("=== LocationWindowCommon Example ===")
388
389 // Simulate LocationWindow initialization
390 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
391 // TODO: User will implement LocationWindow initialization here
392 // self.locationWindow = self.getLocationWindow()
393
394 // Run demonstrations
395 self.demonstrateLocationWindowCommonMethods()
396
397 print("=== Example completed ===")
398 }
399 }
400}
401
402/**
403 * Function to run the example
404 */
405func main() {
406 let example = LocationWindowCommonExample()
407 example.runExample()
408
409 // Keep the program running for a bit to see the output
410 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
411}
412
413// Run the example
414main()
415
416class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
417 // [swift_SublocationChangeListener_onActiveSublocationChanged]
418 func onActiveSublocationChanged(_ sublocationId: Int32) {
419 print("Active sublocation changed to: \‍(sublocationId)")
420 }
421 // [swift_SublocationChangeListener_onActiveSublocationChanged]
422}