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