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