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 demonstrateApplyLayerFilter()
34 demonstrateDebugFlags()
35 demonstrateZoomProperties()
39 * Demonstrate debug overlay flags (static NCLocationWindow API).
41 func demonstrateDebugFlags() {
42 print("--- Debug flags ---")
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]
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]
55 // [swift_LocationWindow_getDebugFlag]
56 let infosOn = NCLocationWindow.getDebugFlag(.infos)
57 print("Debug flag INFOS enabled: \(infosOn)")
58 // [swift_LocationWindow_getDebugFlag]
62 * Demonstrate setSublocationId method
64 func demonstrateSetSublocationId() {
65 print("--- setSublocationId Method ---")
67 guard let locationWindow = locationWindow else {
68 print("LocationWindow not available yet")
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]
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]
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]
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)")
99 * Demonstrate getters for sublocation and enclosing camera
101 func demonstrateSublocationQueries() {
102 print("--- getSublocationId & getEnclosingCamera ---")
104 guard let locationWindow = locationWindow else {
105 print("LocationWindow not available yet")
109 // [swift_LocationWindow_getSublocationId]
110 if let currentId = locationWindow.getSublocationId() {
111 print("Current sublocation id: \(currentId)")
113 print("Current sublocation id is not set")
115 // [swift_LocationWindow_getSublocationId]
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]
126 * Demonstrate sublocation change listener usage
128 func demonstrateSublocationChangeListener() {
129 print("--- Sublocation Change Listener ---")
131 guard let locationWindow = locationWindow else {
132 print("LocationWindow not available yet")
136 let listener = DemoSublocationChangeListener()
138 // [swift_LocationWindow_addSublocationChangeListener]
139 locationWindow.addSublocationChangeListener(listener)
140 print("Added sublocation change listener")
141 // [swift_LocationWindow_addSublocationChangeListener]
143 locationWindow.setSublocationId(1)
144 locationWindow.setSublocationId(2)
146 // [swift_LocationWindow_removeSublocationChangeListener]
147 locationWindow.removeSublocationChangeListener(listener)
148 print("Removed sublocation change listener")
149 // [swift_LocationWindow_removeSublocationChangeListener]
153 * Demonstrate user location view properties
155 func demonstrateUserLocationView() {
156 print("--- UserLocationView ---")
158 guard let userLocationView = userLocationView else {
159 print("UserLocationView not available yet")
163 // [swift_UserLocationView_getArrow]
164 let arrow = userLocationView.arrow
165 print("Arrow icon object: \(arrow)")
166 // [swift_UserLocationView_getArrow]
168 // [swift_UserLocationView_getAccuracyCircle]
169 let accuracyCircle = userLocationView.accuracyCircle
170 print("Accuracy circle object: \(accuracyCircle)")
171 // [swift_UserLocationView_getAccuracyCircle]
175 * Demonstrate user location layer controls
177 func demonstrateUserLocationLayer() {
178 print("--- UserLocationLayer ---")
180 guard let userLocationLayer = userLocationLayer else {
181 print("UserLocationLayer not available yet")
185 // [swift_UserLocationLayer_setVisible]
186 userLocationLayer.setVisible(true)
187 print("User location layer set visible")
188 // [swift_UserLocationLayer_setVisible]
190 // [swift_UserLocationLayer_isVisible]
191 let visible = userLocationLayer.isVisible()
192 print("User location layer is visible: \(visible)")
193 // [swift_UserLocationLayer_isVisible]
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]
201 // [swift_UserLocationLayer_anchorEnabled]
202 let anchorEnabled = userLocationLayer.anchorEnabled()
203 print("Anchor enabled: \(anchorEnabled)")
204 // [swift_UserLocationLayer_anchorEnabled]
206 // [swift_UserLocationLayer_resetAnchor]
207 userLocationLayer.resetAnchor()
208 print("Anchor reset to default")
209 // [swift_UserLocationLayer_resetAnchor]
213 * Demonstrate coordinate conversion methods
215 func demonstrateCoordinateConversion() {
216 print("--- Coordinate Conversion Methods ---")
218 guard let locationWindow = locationWindow else {
219 print("LocationWindow not available yet")
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]
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]
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]
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]
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)
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))")
266 * Demonstrate map feature selection methods
268 func demonstrateMapFeatureSelection() {
269 print("--- Map Feature Selection Methods ---")
271 guard let locationWindow = locationWindow else {
272 print("LocationWindow not available yet")
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]
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]
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)")
297 // [swift_LocationWindow_getSelectedMapFeatures]
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]
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]
311 // [swift_LocationWindow_deselectAllMapFeatures]
312 // Deselect all map features
313 locationWindow.deselectAllMapFeatures()
314 print("Deselected all map features")
315 // [swift_LocationWindow_deselectAllMapFeatures]
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]
323 // Test multiple feature selection and deselection
324 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
326 // Select multiple features
327 for featureId in testFeatureIds {
328 let success = locationWindow.selectMapFeature(featureId)
329 print("Selected feature \(featureId): \(success)")
332 // Check selected features
333 let allSelected = locationWindow.selectedMapFeatures
334 print("All selected features: \(allSelected.count) features")
336 // Deselect all at once
337 locationWindow.deselectAllMapFeatures()
338 print("Deselected all features at once")
342 * Demonstrate applyLayerFilter method
344 func demonstrateApplyLayerFilter() {
345 print("--- applyLayerFilter Method ---")
347 guard let locationWindow = locationWindow else {
348 print("LocationWindow not available yet")
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]
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]
364 // Reset filter (show all venues)
365 locationWindow.applyLayerFilter("venues", conditions: [])
366 print("Reset layer filter: show all venues")
370 * Demonstrate zoom properties
372 func demonstrateZoomProperties() {
373 print("--- Zoom Properties ---")
375 guard let locationWindow = locationWindow else {
376 print("LocationWindow not available yet")
380 // [swift_LocationWindow_getZoomFactor]
381 // Get current zoom factor
382 let currentZoom = locationWindow.zoomFactor
383 print("Current zoom factor: \(currentZoom)")
384 // [swift_LocationWindow_getZoomFactor]
386 // [swift_LocationWindow_setZoomFactor]
388 locationWindow.zoomFactor = 150.0
389 print("Set zoom factor to 150.0")
390 // [swift_LocationWindow_setZoomFactor]
392 // [swift_LocationWindow_getMinZoomFactor]
393 // Get minimum zoom factor
394 let minZoomFactor = locationWindow.minZoomFactor
395 print("Minimum zoom factor: \(minZoomFactor)")
396 // [swift_LocationWindow_getMinZoomFactor]
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]
404 // [swift_LocationWindow_getMaxZoomFactor]
405 // Get maximum zoom factor
406 let maxZoomFactor = locationWindow.maxZoomFactor
407 print("Maximum zoom factor: \(maxZoomFactor)")
408 // [swift_LocationWindow_getMaxZoomFactor]
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]
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)")
424 print("Testing zoom limits...")
425 locationWindow.zoomFactor = locationWindow.minZoomFactor
426 print("Set to minimum zoom: \(locationWindow.zoomFactor)")
428 locationWindow.zoomFactor = locationWindow.maxZoomFactor
429 print("Set to maximum zoom: \(locationWindow.zoomFactor)")
432 locationWindow.zoomFactor = 100.0
433 print("Reset zoom factor to default: \(locationWindow.zoomFactor)")
437 * Main demonstration method
440 print("=== LocationWindowCommon Example ===")
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()
447 // Run demonstrations
448 self.demonstrateLocationWindowCommonMethods()
450 print("=== Example completed ===")
456 * Function to run the example
459 let example = LocationWindowCommonExample()
462 // Keep the program running for a bit to see the output
463 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
469class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
470 // [swift_SublocationChangeListener_onActiveSublocationChanged]
471 func onActiveSublocationChanged(_ sublocationId: Int32) {
472 print("Active sublocation changed to: \(sublocationId)")
474 // [swift_SublocationChangeListener_onActiveSublocationChanged]