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 userLocationLayer: UserLocationLayer?
16 demonstrateLocationWindowCommonMethods()
20 * Demonstrate LocationWindowCommon methods
22 func demonstrateLocationWindowCommonMethods() {
23 print("=== LocationWindowCommon Methods ===")
25 demonstrateSetSublocationId()
26 demonstrateSublocationQueries()
27 demonstrateSublocationChangeListener()
28 demonstrateUserLocationLayer()
29 demonstrateCoordinateConversion()
30 demonstrateMapFeatureSelection()
31 demonstrateApplyLayerFilter()
32 demonstrateDebugFlags()
33 demonstrateZoomProperties()
37 * Demonstrate debug overlay flags (static NCLocationWindow API).
39 func demonstrateDebugFlags() {
40 print("--- Debug flags ---")
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]
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]
53 // [swift_LocationWindow_getDebugFlag]
54 let infosOn = NCLocationWindow.getDebugFlag(.infos)
55 print("Debug flag INFOS enabled: \(infosOn)")
56 // [swift_LocationWindow_getDebugFlag]
60 * Demonstrate setSublocationId method
62 func demonstrateSetSublocationId() {
63 print("--- setSublocationId Method ---")
65 guard let locationWindow = locationWindow else {
66 print("LocationWindow not available yet")
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]
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]
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]
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)")
97 * Demonstrate getters for sublocation and enclosing camera
99 func demonstrateSublocationQueries() {
100 print("--- getSublocationId & getEnclosingCamera ---")
102 guard let locationWindow = locationWindow else {
103 print("LocationWindow not available yet")
107 // [swift_LocationWindow_getSublocationId]
108 if let currentId = locationWindow.getSublocationId() {
109 print("Current sublocation id: \(currentId)")
111 print("Current sublocation id is not set")
113 // [swift_LocationWindow_getSublocationId]
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]
124 * Demonstrate sublocation change listener usage
126 func demonstrateSublocationChangeListener() {
127 print("--- Sublocation Change Listener ---")
129 guard let locationWindow = locationWindow else {
130 print("LocationWindow not available yet")
134 let listener = DemoSublocationChangeListener()
136 // [swift_LocationWindow_addSublocationChangeListener]
137 locationWindow.addSublocationChangeListener(listener)
138 print("Added sublocation change listener")
139 // [swift_LocationWindow_addSublocationChangeListener]
141 locationWindow.setSublocationId(1)
142 locationWindow.setSublocationId(2)
144 // [swift_LocationWindow_removeSublocationChangeListener]
145 locationWindow.removeSublocationChangeListener(listener)
146 print("Removed sublocation change listener")
147 // [swift_LocationWindow_removeSublocationChangeListener]
151 * Demonstrate user location layer controls
153 func demonstrateUserLocationLayer() {
154 print("--- UserLocationLayer ---")
156 guard let userLocationLayer = userLocationLayer else {
157 print("UserLocationLayer not available yet")
161 // [swift_UserLocationLayer_setVisible]
162 userLocationLayer.setVisible(true)
163 print("User location layer set visible")
164 // [swift_UserLocationLayer_setVisible]
166 // [swift_UserLocationLayer_isVisible]
167 let visible = userLocationLayer.isVisible()
168 print("User location layer is visible: \(visible)")
169 // [swift_UserLocationLayer_isVisible]
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]
177 // [swift_UserLocationLayer_anchorEnabled]
178 let anchorEnabled = userLocationLayer.anchorEnabled()
179 print("Anchor enabled: \(anchorEnabled)")
180 // [swift_UserLocationLayer_anchorEnabled]
182 // [swift_UserLocationLayer_resetAnchor]
183 userLocationLayer.resetAnchor()
184 print("Anchor reset to default")
185 // [swift_UserLocationLayer_resetAnchor]
189 * Demonstrate coordinate conversion methods
191 func demonstrateCoordinateConversion() {
192 print("--- Coordinate Conversion Methods ---")
194 guard let locationWindow = locationWindow else {
195 print("LocationWindow not available yet")
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]
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]
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]
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]
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)
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))")
242 * Demonstrate map feature selection methods
244 func demonstrateMapFeatureSelection() {
245 print("--- Map Feature Selection Methods ---")
247 guard let locationWindow = locationWindow else {
248 print("LocationWindow not available yet")
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]
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]
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)")
273 // [swift_LocationWindow_getSelectedMapFeatures]
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]
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]
287 // [swift_LocationWindow_deselectAllMapFeatures]
288 // Deselect all map features
289 locationWindow.deselectAllMapFeatures()
290 print("Deselected all map features")
291 // [swift_LocationWindow_deselectAllMapFeatures]
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]
299 // Test multiple feature selection and deselection
300 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
302 // Select multiple features
303 for featureId in testFeatureIds {
304 let success = locationWindow.selectMapFeature(featureId)
305 print("Selected feature \(featureId): \(success)")
308 // Check selected features
309 let allSelected = locationWindow.selectedMapFeatures
310 print("All selected features: \(allSelected.count) features")
312 // Deselect all at once
313 locationWindow.deselectAllMapFeatures()
314 print("Deselected all features at once")
318 * Demonstrate applyLayerFilter method
320 func demonstrateApplyLayerFilter() {
321 print("--- applyLayerFilter Method ---")
323 guard let locationWindow = locationWindow else {
324 print("LocationWindow not available yet")
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]
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]
340 // Reset filter (show all venues)
341 locationWindow.applyLayerFilter("venues", conditions: [])
342 print("Reset layer filter: show all venues")
346 * Demonstrate zoom properties
348 func demonstrateZoomProperties() {
349 print("--- Zoom Properties ---")
351 guard let locationWindow = locationWindow else {
352 print("LocationWindow not available yet")
356 // [swift_LocationWindow_getZoomFactor]
357 // Get current zoom factor
358 let currentZoom = locationWindow.zoomFactor
359 print("Current zoom factor: \(currentZoom)")
360 // [swift_LocationWindow_getZoomFactor]
362 // [swift_LocationWindow_setZoomFactor]
364 locationWindow.zoomFactor = 150.0
365 print("Set zoom factor to 150.0")
366 // [swift_LocationWindow_setZoomFactor]
368 // [swift_LocationWindow_getMinZoomFactor]
369 // Get minimum zoom factor
370 let minZoomFactor = locationWindow.minZoomFactor
371 print("Minimum zoom factor: \(minZoomFactor)")
372 // [swift_LocationWindow_getMinZoomFactor]
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]
380 // [swift_LocationWindow_getMaxZoomFactor]
381 // Get maximum zoom factor
382 let maxZoomFactor = locationWindow.maxZoomFactor
383 print("Maximum zoom factor: \(maxZoomFactor)")
384 // [swift_LocationWindow_getMaxZoomFactor]
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]
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)")
400 print("Testing zoom limits...")
401 locationWindow.zoomFactor = locationWindow.minZoomFactor
402 print("Set to minimum zoom: \(locationWindow.zoomFactor)")
404 locationWindow.zoomFactor = locationWindow.maxZoomFactor
405 print("Set to maximum zoom: \(locationWindow.zoomFactor)")
408 locationWindow.zoomFactor = 100.0
409 print("Reset zoom factor to default: \(locationWindow.zoomFactor)")
413 * Main demonstration method
416 print("=== LocationWindowCommon Example ===")
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()
423 // Run demonstrations
424 self.demonstrateLocationWindowCommonMethods()
426 print("=== Example completed ===")
432 * Function to run the example
435 let example = LocationWindowCommonExample()
438 // Keep the program running for a bit to see the output
439 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
445class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
446 // [swift_SublocationChangeListener_onActiveSublocationChanged]
447 func onActiveSublocationChanged(_ sublocationId: Int32) {
448 print("Active sublocation changed to: \(sublocationId)")
450 // [swift_SublocationChangeListener_onActiveSublocationChanged]