5 * LocationWindowCommon usage example for Swift
6 * Demonstrates specific methods: setSublocationId, screenPositionToGlobal, globalToScreenPosition,
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 demonstrateOperatingMode()
27 demonstrateSublocationQueries()
28 demonstrateSublocationChangeListener()
29 demonstrateUserLocationLayer()
30 demonstrateCoordinateConversion()
31 demonstrateMapFeatureSelection()
32 demonstrateApplyLayerFilter()
33 demonstrateDebugFlags()
34 demonstrateZoomProperties()
38 * Demonstrate debug overlay flags (static NCLocationWindow API).
40 func demonstrateDebugFlags() {
41 print("--- Debug flags ---")
43 // [swift_DebugFlag_enum]
44 let allFlags: [NCDebugFlag] = [.none, .infos, .stats, .labels, .drawAllLabels, .selectionBuffer]
45 print("Debug flag enum values: \(allFlags.count)")
46 // [swift_DebugFlag_enum]
48 // [swift_LocationWindow_setDebugFlag]
49 NCLocationWindow.setDebugFlag(.infos, on: true)
50 NCLocationWindow.setDebugFlag(.stats, on: false)
51 print("Updated debug flags on LocationWindow")
52 // [swift_LocationWindow_setDebugFlag]
54 // [swift_LocationWindow_getDebugFlag]
55 let infosOn = NCLocationWindow.getDebugFlag(.infos)
56 print("Debug flag INFOS enabled: \(infosOn)")
57 // [swift_LocationWindow_getDebugFlag]
62 * Demonstrate operating mode (indoor / outdoor basemap).
64 func demonstrateOperatingMode() {
65 print("--- Operating Mode ---")
67 guard let locationWindow = locationWindow else {
68 print("LocationWindow not available yet")
72 // [swift_OperatingMode_enum]
73 let modes: [NCOperatingMode] = [.indoorOnly, .outdoor, .outdoorIndoor]
74 print("Operating modes: \(modes.count)")
75 // [swift_OperatingMode_enum]
77 // [swift_LocationWindow_setOperatingMode]
78 locationWindow.setOperatingMode(.outdoorIndoor)
79 print("Set operating mode to outdoorIndoor")
80 // [swift_LocationWindow_setOperatingMode]
82 // [swift_LocationWindow_getOperatingMode]
83 let currentMode = locationWindow.getOperatingMode()
84 print("Current operating mode: \(currentMode)")
85 // [swift_LocationWindow_getOperatingMode]
87 // [swift_AttributionAlignment_record]
88 let alignment = NCAttributionAlignment(
89 horizontalAlignment: .right,
90 verticalAlignment: .bottom)
91 // [swift_AttributionAlignment_record]
93 // [swift_LocationWindow_setAttributionAlignment]
94 locationWindow.setAttributionAlignment(alignment)
95 // [swift_LocationWindow_setAttributionAlignment]
97 // [swift_LocationWindow_getAttribution]
98 let attribution = locationWindow.getAttribution()
99 print("Attribution: \(attribution)")
100 // [swift_LocationWindow_getAttribution]
104 * Demonstrate setSublocationId method
106 func demonstrateSetSublocationId() {
107 print("--- setSublocationId Method ---")
109 guard let locationWindow = locationWindow else {
110 print("LocationWindow not available yet")
114 // [swift_LocationWindow_setSublocationId]
115 // Set sublocation ID to switch between floors
116 locationWindow.setSublocationId(1)
117 print("Set sublocation ID to 1 (first floor)")
118 // [swift_LocationWindow_setSublocationId]
120 // [swift_LocationWindow_setSublocationId_2]
121 // Set sublocation ID to another floor
122 locationWindow.setSublocationId(2)
123 print("Set sublocation ID to 2 (second floor)")
124 // [swift_LocationWindow_setSublocationId_2]
126 // [swift_LocationWindow_setSublocationId_3]
127 // Set sublocation ID to ground floor
128 locationWindow.setSublocationId(0)
129 print("Set sublocation ID to 0 (ground floor)")
130 // [swift_LocationWindow_setSublocationId_3]
132 // Test with different sublocation IDs
133 let sublocationIds = [1, 2, 3, 0, 5]
134 for id in sublocationIds {
135 locationWindow.setSublocationId(id)
136 print("Switched to sublocation ID: \(id)")
141 * Demonstrate getters for sublocation and enclosing camera
143 func demonstrateSublocationQueries() {
144 print("--- getSublocationId & getEnclosingCamera ---")
146 guard let locationWindow = locationWindow else {
147 print("LocationWindow not available yet")
151 // [swift_LocationWindow_getSublocationId]
152 if let currentId = locationWindow.getSublocationId() {
153 print("Current sublocation id: \(currentId)")
155 print("Current sublocation id is not set")
157 // [swift_LocationWindow_getSublocationId]
159 // [swift_LocationWindow_getEnclosingCamera]
160 let boundingBox = BoundingBox(
161 bottomLeft: GlobalPoint(latitude: 55.75, longitude: 37.61),
162 topRight: GlobalPoint(latitude: 55.76, longitude: 37.63))
163 let camera = locationWindow.getEnclosingCamera(boundingBox)
164 print("Camera that fits bounding box: \(camera)")
165 // [swift_LocationWindow_getEnclosingCamera]
169 * Demonstrate sublocation change listener usage
171 func demonstrateSublocationChangeListener() {
172 print("--- Sublocation Change Listener ---")
174 guard let locationWindow = locationWindow else {
175 print("LocationWindow not available yet")
179 let listener = DemoSublocationChangeListener()
181 // [swift_LocationWindow_addSublocationChangeListener]
182 locationWindow.addSublocationChangeListener(listener)
183 print("Added sublocation change listener")
184 // [swift_LocationWindow_addSublocationChangeListener]
186 locationWindow.setSublocationId(1)
187 locationWindow.setSublocationId(2)
189 // [swift_LocationWindow_removeSublocationChangeListener]
190 locationWindow.removeSublocationChangeListener(listener)
191 print("Removed sublocation change listener")
192 // [swift_LocationWindow_removeSublocationChangeListener]
196 * Demonstrate user location layer controls
198 func demonstrateUserLocationLayer() {
199 print("--- UserLocationLayer ---")
201 guard let userLocationLayer = userLocationLayer else {
202 print("UserLocationLayer not available yet")
206 // [swift_UserLocationLayer_setVisible]
207 userLocationLayer.setVisible(true)
208 print("User location layer set visible")
209 // [swift_UserLocationLayer_setVisible]
211 // [swift_UserLocationLayer_isVisible]
212 let visible = userLocationLayer.isVisible()
213 print("User location layer is visible: \(visible)")
214 // [swift_UserLocationLayer_isVisible]
216 // [swift_UserLocationLayer_setAnchor]
217 let anchor = ScreenPoint(x: 100.0, y: 200.0)
218 userLocationLayer.setAnchor(anchor)
219 print("Set user location anchor to: (\(anchor.x), \(anchor.y))")
220 // [swift_UserLocationLayer_setAnchor]
222 // [swift_UserLocationLayer_anchorEnabled]
223 let anchorEnabled = userLocationLayer.anchorEnabled()
224 print("Anchor enabled: \(anchorEnabled)")
225 // [swift_UserLocationLayer_anchorEnabled]
227 // [swift_UserLocationLayer_resetAnchor]
228 userLocationLayer.resetAnchor()
229 print("Anchor reset to default")
230 // [swift_UserLocationLayer_resetAnchor]
234 * Demonstrate coordinate conversion methods
236 func demonstrateCoordinateConversion() {
237 print("--- Coordinate Conversion Methods ---")
239 guard let locationWindow = locationWindow else {
240 print("LocationWindow not available yet")
244 // [swift_LocationWindow_screenPositionToGlobal]
245 let screenPoint = ScreenPoint(x: 100.0, y: 200.0)
246 let globalPoint = locationWindow.screenPositionToGlobal(screenPoint)
247 print("Screen position (\(screenPoint.x), \(screenPoint.y)) converted to WGS84: (\(globalPoint.latitude), \(globalPoint.longitude))")
248 // [swift_LocationWindow_screenPositionToGlobal]
250 // [swift_LocationWindow_globalToScreenPosition]
251 let globalPoint2 = GlobalPoint(latitude: 55.7558, longitude: 37.6176)
252 let screenPoint2 = locationWindow.globalToScreenPosition(globalPoint2, clipToViewport: true)
253 print("WGS84 (\(globalPoint2.latitude), \(globalPoint2.longitude)) converted to screen with clipping: (\(screenPoint2.x), \(screenPoint2.y))")
254 // [swift_LocationWindow_globalToScreenPosition]
256 let testScreenPoints = [
257 ScreenPoint(x: 0.0, y: 0.0),
258 ScreenPoint(x: 250.0, y: 250.0),
259 ScreenPoint(x: 1000.0, y: 600.0)
262 for (index, screenPoint) in testScreenPoints.enumerated() {
263 let global = locationWindow.screenPositionToGlobal(screenPoint)
264 let backToScreen = locationWindow.globalToScreenPosition(global, clipToViewport: false)
265 print("Test \(index): Screen (\(screenPoint.x), \(screenPoint.y)) -> WGS84 (\(global.latitude), \(global.longitude)) -> Screen (\(backToScreen.x), \(backToScreen.y))")
270 * Demonstrate map feature selection methods
272 func demonstrateMapFeatureSelection() {
273 print("--- Map Feature Selection Methods ---")
275 guard let locationWindow = locationWindow else {
276 print("LocationWindow not available yet")
280 // [swift_LocationWindow_selectMapFeature]
281 // Select map feature by ID
282 let featureId = "room_101"
283 let selected = locationWindow.selectMapFeature(featureId)
284 print("Selected map feature \(featureId): \(selected)")
285 // [swift_LocationWindow_selectMapFeature]
287 // [swift_LocationWindow_selectMapFeature_2]
288 // Select another map feature
289 let featureId2 = "office_205"
290 let selected2 = locationWindow.selectMapFeature(featureId2)
291 print("Selected map feature \(featureId2): \(selected2)")
292 // [swift_LocationWindow_selectMapFeature_2]
294 // [swift_LocationWindow_getSelectedMapFeatures]
295 // Get list of selected map features
296 let selectedFeatures = locationWindow.selectedMapFeatures
297 print("Currently selected map features: \(selectedFeatures.count) features")
298 for feature in selectedFeatures {
299 print(" - \(feature)")
301 // [swift_LocationWindow_getSelectedMapFeatures]
303 // [swift_LocationWindow_deselectMapFeature]
304 // Deselect specific map feature
305 let deselected = locationWindow.deselectMapFeature(featureId)
306 print("Deselected map feature \(featureId): \(deselected)")
307 // [swift_LocationWindow_deselectMapFeature]
309 // [swift_LocationWindow_deselectMapFeature_2]
310 // Deselect another map feature
311 let deselected2 = locationWindow.deselectMapFeature(featureId2)
312 print("Deselected map feature \(featureId2): \(deselected2)")
313 // [swift_LocationWindow_deselectMapFeature_2]
315 // [swift_LocationWindow_deselectAllMapFeatures]
316 // Deselect all map features
317 locationWindow.deselectAllMapFeatures()
318 print("Deselected all map features")
319 // [swift_LocationWindow_deselectAllMapFeatures]
321 // [swift_LocationWindow_getSelectedMapFeatures_2]
322 // Verify all features are deselected
323 let remainingFeatures = locationWindow.selectedMapFeatures
324 print("Remaining selected features after deselect all: \(remainingFeatures.count) features")
325 // [swift_LocationWindow_getSelectedMapFeatures_2]
327 // Test multiple feature selection and deselection
328 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
330 // Select multiple features
331 for featureId in testFeatureIds {
332 let success = locationWindow.selectMapFeature(featureId)
333 print("Selected feature \(featureId): \(success)")
336 // Check selected features
337 let allSelected = locationWindow.selectedMapFeatures
338 print("All selected features: \(allSelected.count) features")
340 // Deselect all at once
341 locationWindow.deselectAllMapFeatures()
342 print("Deselected all features at once")
346 * Demonstrate applyLayerFilter method
348 func demonstrateApplyLayerFilter() {
349 print("--- applyLayerFilter Method ---")
351 guard let locationWindow = locationWindow else {
352 print("LocationWindow not available yet")
356 // [swift_MapFilterCondition_constructor]
357 // Create filter condition: show only venues with category "Toilet" or "Cafe"
358 let condition = NCMapFilterCondition(property: "category", values: ["Toilet", "Cafe"])
359 // [swift_MapFilterCondition_constructor]
361 // [swift_LocationWindow_applyLayerFilter]
362 // Apply filter to venues layer
363 let conditions = [NCMapFilterCondition(property: "category", values: ["Toilet", "Cafe"])]
364 locationWindow.applyLayerFilter("venues", conditions: conditions)
365 print("Applied layer filter: show venues with category Toilet or Cafe")
366 // [swift_LocationWindow_applyLayerFilter]
368 // Reset filter (show all venues)
369 locationWindow.applyLayerFilter("venues", conditions: [])
370 print("Reset layer filter: show all venues")
374 * Demonstrate zoom properties
376 func demonstrateZoomProperties() {
377 print("--- Zoom Properties ---")
379 guard let locationWindow = locationWindow else {
380 print("LocationWindow not available yet")
384 // [swift_LocationWindow_getZoomFactor]
385 // Get current zoom factor
386 let currentZoom = locationWindow.zoomFactor
387 print("Current zoom factor: \(currentZoom)")
388 // [swift_LocationWindow_getZoomFactor]
390 // [swift_LocationWindow_setZoomFactor]
392 locationWindow.zoomFactor = 150.0
393 print("Set zoom factor to 150.0")
394 // [swift_LocationWindow_setZoomFactor]
396 // [swift_LocationWindow_getMinZoomFactor]
397 // Get minimum zoom factor
398 let minZoomFactor = locationWindow.minZoomFactor
399 print("Minimum zoom factor: \(minZoomFactor)")
400 // [swift_LocationWindow_getMinZoomFactor]
402 // [swift_LocationWindow_setMinZoomFactor]
403 // Set minimum zoom factor
404 locationWindow.minZoomFactor = 50.0
405 print("Set minimum zoom factor to 50.0")
406 // [swift_LocationWindow_setMinZoomFactor]
408 // [swift_LocationWindow_getMaxZoomFactor]
409 // Get maximum zoom factor
410 let maxZoomFactor = locationWindow.maxZoomFactor
411 print("Maximum zoom factor: \(maxZoomFactor)")
412 // [swift_LocationWindow_getMaxZoomFactor]
414 // [swift_LocationWindow_setMaxZoomFactor]
415 // Set maximum zoom factor
416 locationWindow.maxZoomFactor = 300.0
417 print("Set maximum zoom factor to 300.0")
418 // [swift_LocationWindow_setMaxZoomFactor]
420 // Test zoom factor changes
421 let testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0]
422 for zoom in testZoomFactors {
423 locationWindow.zoomFactor = zoom
424 print("Changed zoom factor to: \(locationWindow.zoomFactor)")
428 print("Testing zoom limits...")
429 locationWindow.zoomFactor = locationWindow.minZoomFactor
430 print("Set to minimum zoom: \(locationWindow.zoomFactor)")
432 locationWindow.zoomFactor = locationWindow.maxZoomFactor
433 print("Set to maximum zoom: \(locationWindow.zoomFactor)")
436 locationWindow.zoomFactor = 100.0
437 print("Reset zoom factor to default: \(locationWindow.zoomFactor)")
441 * Main demonstration method
444 print("=== LocationWindowCommon Example ===")
446 // Simulate LocationWindow initialization
447 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
448 // TODO: User will implement LocationWindow initialization here
449 // self.locationWindow = self.getLocationWindow()
451 // Run demonstrations
452 self.demonstrateLocationWindowCommonMethods()
454 print("=== Example completed ===")
460 * Function to run the example
463 let example = LocationWindowCommonExample()
466 // Keep the program running for a bit to see the output
467 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
473class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
474 // [swift_SublocationChangeListener_onActiveSublocationChanged]
475 func onActiveSublocationChanged(_ sublocationId: Int32) {
476 print("Active sublocation changed to: \(sublocationId)")
478 // [swift_SublocationChangeListener_onActiveSublocationChanged]