5 * LocationWindowCommon usage example for Swift
6 * Demonstrates specific methods: setSublocationId, screenPositionToMeters, metersToScreenPosition,
7 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
8 * zoomFactor, minZoomFactor, maxZoomFactor
10class LocationWindowCommonExample {
12 private var locationWindow: LocationWindow?
13 private var userLocationView: UserLocationView?
14 private var userLocationLayer: UserLocationLayer?
17 demonstrateLocationWindowCommonMethods()
21 * Demonstrate LocationWindowCommon methods
23 func demonstrateLocationWindowCommonMethods() {
24 print("=== LocationWindowCommon Methods ===")
26 demonstrateSetSublocationId()
27 demonstrateSublocationQueries()
28 demonstrateSublocationChangeListener()
29 demonstrateUserLocationView()
30 demonstrateUserLocationLayer()
31 demonstrateCoordinateConversion()
32 demonstrateMapFeatureSelection()
33 demonstrateZoomProperties()
37 * Demonstrate setSublocationId method
39 func demonstrateSetSublocationId() {
40 print("--- setSublocationId Method ---")
42 guard let locationWindow = locationWindow else {
43 print("LocationWindow not available yet")
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]
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]
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]
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)")
74 * Demonstrate getters for sublocation and enclosing camera
76 func demonstrateSublocationQueries() {
77 print("--- getSublocationId & getEnclosingCamera ---")
79 guard let locationWindow = locationWindow else {
80 print("LocationWindow not available yet")
84 // [swift_LocationWindow_getSublocationId]
85 if let currentId = locationWindow.getSublocationId() {
86 print("Current sublocation id: \(currentId)")
88 print("Current sublocation id is not set")
90 // [swift_LocationWindow_getSublocationId]
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]
101 * Demonstrate sublocation change listener usage
103 func demonstrateSublocationChangeListener() {
104 print("--- Sublocation Change Listener ---")
106 guard let locationWindow = locationWindow else {
107 print("LocationWindow not available yet")
111 let listener = DemoSublocationChangeListener()
113 // [swift_LocationWindow_addSublocationChangeListener]
114 locationWindow.addSublocationChangeListener(listener)
115 print("Added sublocation change listener")
116 // [swift_LocationWindow_addSublocationChangeListener]
118 locationWindow.setSublocationId(1)
119 locationWindow.setSublocationId(2)
121 // [swift_LocationWindow_removeSublocationChangeListener]
122 locationWindow.removeSublocationChangeListener(listener)
123 print("Removed sublocation change listener")
124 // [swift_LocationWindow_removeSublocationChangeListener]
128 * Demonstrate user location view properties
130 func demonstrateUserLocationView() {
131 print("--- UserLocationView ---")
133 guard let userLocationView = userLocationView else {
134 print("UserLocationView not available yet")
138 // [swift_UserLocationView_getArrow]
139 let arrow = userLocationView.arrow
140 print("Arrow icon object: \(arrow)")
141 // [swift_UserLocationView_getArrow]
143 // [swift_UserLocationView_getAccuracyCircle]
144 let accuracyCircle = userLocationView.accuracyCircle
145 print("Accuracy circle object: \(accuracyCircle)")
146 // [swift_UserLocationView_getAccuracyCircle]
150 * Demonstrate user location layer controls
152 func demonstrateUserLocationLayer() {
153 print("--- UserLocationLayer ---")
155 guard let userLocationLayer = userLocationLayer else {
156 print("UserLocationLayer not available yet")
160 // [swift_UserLocationLayer_setVisible]
161 userLocationLayer.setVisible(true)
162 print("User location layer set visible")
163 // [swift_UserLocationLayer_setVisible]
165 // [swift_UserLocationLayer_isVisible]
166 let visible = userLocationLayer.isVisible()
167 print("User location layer is visible: \(visible)")
168 // [swift_UserLocationLayer_isVisible]
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]
176 // [swift_UserLocationLayer_anchorEnabled]
177 let anchorEnabled = userLocationLayer.anchorEnabled()
178 print("Anchor enabled: \(anchorEnabled)")
179 // [swift_UserLocationLayer_anchorEnabled]
181 // [swift_UserLocationLayer_resetAnchor]
182 userLocationLayer.resetAnchor()
183 print("Anchor reset to default")
184 // [swift_UserLocationLayer_resetAnchor]
188 * Demonstrate coordinate conversion methods
190 func demonstrateCoordinateConversion() {
191 print("--- Coordinate Conversion Methods ---")
193 guard let locationWindow = locationWindow else {
194 print("LocationWindow not available yet")
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]
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]
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]
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]
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)
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))")
241 * Demonstrate map feature selection methods
243 func demonstrateMapFeatureSelection() {
244 print("--- Map Feature Selection Methods ---")
246 guard let locationWindow = locationWindow else {
247 print("LocationWindow not available yet")
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]
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]
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)")
272 // [swift_LocationWindow_getSelectedMapFeatures]
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]
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]
286 // [swift_LocationWindow_deselectAllMapFeatures]
287 // Deselect all map features
288 locationWindow.deselectAllMapFeatures()
289 print("Deselected all map features")
290 // [swift_LocationWindow_deselectAllMapFeatures]
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]
298 // Test multiple feature selection and deselection
299 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
301 // Select multiple features
302 for featureId in testFeatureIds {
303 let success = locationWindow.selectMapFeature(featureId)
304 print("Selected feature \(featureId): \(success)")
307 // Check selected features
308 let allSelected = locationWindow.selectedMapFeatures
309 print("All selected features: \(allSelected.count) features")
311 // Deselect all at once
312 locationWindow.deselectAllMapFeatures()
313 print("Deselected all features at once")
317 * Demonstrate zoom properties
319 func demonstrateZoomProperties() {
320 print("--- Zoom Properties ---")
322 guard let locationWindow = locationWindow else {
323 print("LocationWindow not available yet")
327 // [swift_LocationWindow_getZoomFactor]
328 // Get current zoom factor
329 let currentZoom = locationWindow.zoomFactor
330 print("Current zoom factor: \(currentZoom)")
331 // [swift_LocationWindow_getZoomFactor]
333 // [swift_LocationWindow_setZoomFactor]
335 locationWindow.zoomFactor = 150.0
336 print("Set zoom factor to 150.0")
337 // [swift_LocationWindow_setZoomFactor]
339 // [swift_LocationWindow_getMinZoomFactor]
340 // Get minimum zoom factor
341 let minZoomFactor = locationWindow.minZoomFactor
342 print("Minimum zoom factor: \(minZoomFactor)")
343 // [swift_LocationWindow_getMinZoomFactor]
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]
351 // [swift_LocationWindow_getMaxZoomFactor]
352 // Get maximum zoom factor
353 let maxZoomFactor = locationWindow.maxZoomFactor
354 print("Maximum zoom factor: \(maxZoomFactor)")
355 // [swift_LocationWindow_getMaxZoomFactor]
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]
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)")
371 print("Testing zoom limits...")
372 locationWindow.zoomFactor = locationWindow.minZoomFactor
373 print("Set to minimum zoom: \(locationWindow.zoomFactor)")
375 locationWindow.zoomFactor = locationWindow.maxZoomFactor
376 print("Set to maximum zoom: \(locationWindow.zoomFactor)")
379 locationWindow.zoomFactor = 100.0
380 print("Reset zoom factor to default: \(locationWindow.zoomFactor)")
384 * Main demonstration method
387 print("=== LocationWindowCommon Example ===")
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()
394 // Run demonstrations
395 self.demonstrateLocationWindowCommonMethods()
397 print("=== Example completed ===")
403 * Function to run the example
406 let example = LocationWindowCommonExample()
409 // Keep the program running for a bit to see the output
410 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
416class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
417 // [swift_SublocationChangeListener_onActiveSublocationChanged]
418 func onActiveSublocationChanged(_ sublocationId: Int32) {
419 print("Active sublocation changed to: \(sublocationId)")
421 // [swift_SublocationChangeListener_onActiveSublocationChanged]