Loading...
Searching...
No Matches
LocationWindowCommonExample.swift
Go to the documentation of this file.
1import Foundation
2import Dispatch
3import UIKit
4
5class DemoRouteLayerListener: NSObject, RouteLayerListener {
6 func onRouteChanged(_ status: RouteLayerStatus, route: RouteView?) {
7 print("Route status: \‍(status)")
8 }
9
10 func onRouteAdvanced(_ progress: RouteProgress) {
11 print("Remaining distance: \‍(progress.remainingDistance), time: \‍(progress.remainingTime)s")
12 }
13
14 func onRouteTargetReached() {
15 print("Route target reached")
16 }
17}
18
19class DemoRouteViewListener: NSObject, RouteViewListener {
20 private weak var routeLayer: RouteLayer?
21
22 init(routeLayer: RouteLayer) {
23 self.routeLayer = routeLayer
24 }
25
26 func onRouteViewsChanged() {
27 print("Route views changed")
28 }
29
30 func onSelectedRouteChanged(_ route: RouteView?) {
31 print("Selected route changed")
32 }
33
34 func onRouteViewTap(_ route: RouteView) {
35 routeLayer?.selectRoute(route)
36 }
37}
38
39/**
40 * LocationWindowCommon usage example for Swift
41 * Demonstrates specific methods: setSublocationId, screenPositionToGlobal, globalToScreenPosition,
42 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
43 * zoomFactor, minZoomFactor, maxZoomFactor
44 */
45class LocationWindowCommonExample {
46
47 private var locationWindow: LocationWindow?
48 private var userLocationLayer: UserLocationLayer?
49 private var routeLayer: RouteLayer?
50 private var routeLayerListener: RouteLayerListener?
51 private var routeViewListener: RouteViewListener?
52
53 init() {
54 demonstrateLocationWindowCommonMethods()
55 }
56
57 /**
58 * Demonstrate LocationWindowCommon methods
59 */
60 func demonstrateLocationWindowCommonMethods() {
61 print("=== LocationWindowCommon Methods ===")
62
63 demonstrateSetSublocationId()
64 demonstrateOperatingMode()
65 demonstrateSublocationQueries()
66 demonstrateSublocationChangeListener()
67 demonstrateUserLocationLayer()
68 demonstrateRouteLayer()
69 demonstrateCoordinateConversion()
70 demonstrateMapFeatureSelection()
71 demonstrateApplyLayerFilter()
72 demonstrateDebugFlags()
73 demonstrateZoomProperties()
74 }
75
76 /**
77 * Demonstrate debug overlay flags (static NCLocationWindow API).
78 */
79 func demonstrateDebugFlags() {
80 print("--- Debug flags ---")
81
82 // [swift_DebugFlag_enum]
83 let allFlags: [NCDebugFlag] = [.none, .infos, .stats, .labels, .drawAllLabels, .selectionBuffer]
84 print("Debug flag enum values: \‍(allFlags.count)")
85 // [swift_DebugFlag_enum]
86
87 // [swift_LocationWindow_setDebugFlag]
88 NCLocationWindow.setDebugFlag(.infos, on: true)
89 NCLocationWindow.setDebugFlag(.stats, on: false)
90 print("Updated debug flags on LocationWindow")
91 // [swift_LocationWindow_setDebugFlag]
92
93 // [swift_LocationWindow_getDebugFlag]
94 let infosOn = NCLocationWindow.getDebugFlag(.infos)
95 print("Debug flag INFOS enabled: \‍(infosOn)")
96 // [swift_LocationWindow_getDebugFlag]
97 }
98
99
100 /**
101 * Demonstrate operating mode (indoor / outdoor basemap).
102 */
103 func demonstrateOperatingMode() {
104 print("--- Operating Mode ---")
105
106 guard let locationWindow = locationWindow else {
107 print("LocationWindow not available yet")
108 return
109 }
110
111 // [swift_OperatingMode_enum]
112 let modes: [NCOperatingMode] = [.indoorOnly, .outdoor, .outdoorIndoor]
113 print("Operating modes: \‍(modes.count)")
114 // [swift_OperatingMode_enum]
115
116 // [swift_LocationWindow_setOperatingMode]
117 locationWindow.setOperatingMode(.outdoorIndoor)
118 print("Set operating mode to outdoorIndoor")
119 // [swift_LocationWindow_setOperatingMode]
120
121 // [swift_LocationWindow_getOperatingMode]
122 let currentMode = locationWindow.getOperatingMode()
123 print("Current operating mode: \‍(currentMode)")
124 // [swift_LocationWindow_getOperatingMode]
125
126 // [swift_MapTheme_enum]
127 let themes: [NCMapTheme] = [.light, .dark]
128 print("Map themes: \‍(themes.count)")
129 // [swift_MapTheme_enum]
130
131 // [swift_LocationWindow_setMapTheme]
132 locationWindow.setMapTheme(.dark)
133 print("Set map theme to dark")
134 // [swift_LocationWindow_setMapTheme]
135
136 // [swift_LocationWindow_getMapTheme]
137 let currentTheme = locationWindow.getMapTheme()
138 print("Current map theme: \‍(currentTheme)")
139 // [swift_LocationWindow_getMapTheme]
140
141 // [swift_TileKind_enum]
142 let kinds: [NCTileKind] = [.vector, .raster]
143 print("Tile kinds: \‍(kinds.count)")
144 // [swift_TileKind_enum]
145
146 // [swift_TileSchema_enum]
147 let schemas: [NCTileSchema] = [.shortbread, .openMapTiles, .mapboxStreets]
148 print("Tile schemas: \‍(schemas.count)")
149 // [swift_TileSchema_enum]
150
151 // [swift_HttpTileSource_record]
152 let http = NCHttpTileSource(
153 urlTemplate: "https://api.maptiler.com/tiles/v3-openmaptiles/{z}/{x}/{y}.pbf",
154 headers: nil,
155 queryParameters: ["key": "YOUR_MAPTILER_KEY"])
156 // [swift_HttpTileSource_record]
157
158 // [swift_MbtilesTileSource_record]
159 let offline = NCMbtilesTileSource(path: "/path/to/map.mbtiles")
160 // [swift_MbtilesTileSource_record]
161
162 // [swift_TileProvider_record]
163 let osmHttp = NCTileProvider(
164 schema: .openMapTiles,
165 http: http,
166 mbtiles: nil,
167 minZoom: 0,
168 maxZoom: 14,
169 attribution: nil,
170 kind: .vector)
171 let mbtiles = NCTileProvider(
172 schema: .shortbread,
173 http: nil,
174 mbtiles: offline,
175 minZoom: 0,
176 maxZoom: 14,
177 attribution: nil,
178 kind: .vector)
179 // [swift_TileProvider_record]
180
181 // [swift_LocationWindow_setTileProvider]
182 locationWindow.setTileProvider(osmHttp)
183 locationWindow.setTileProvider(nil)
184 let imageryHttp = NCHttpTileSource(
185 urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
186 headers: nil,
187 queryParameters: nil)
188 let imagery = NCTileProvider(
189 schema: .shortbread,
190 http: imageryHttp,
191 mbtiles: nil,
192 minZoom: 0,
193 maxZoom: 19,
194 attribution: "© OpenStreetMap contributors",
195 kind: .raster)
196 locationWindow.setTileProvider(imagery)
197 // [swift_LocationWindow_setTileProvider]
198
199 // [swift_AttributionAlignment_record]
200 let alignment = NCAttributionAlignment(
201 horizontalAlignment: .right,
202 verticalAlignment: .bottom)
203 // [swift_AttributionAlignment_record]
204
205 // [swift_LocationWindow_setAttributionAlignment]
206 locationWindow.setAttributionAlignment(alignment)
207 // [swift_LocationWindow_setAttributionAlignment]
208
209 // [swift_LocationWindow_getAttribution]
210 let attribution = locationWindow.getAttribution()
211 print("Attribution: \‍(attribution)")
212 // [swift_LocationWindow_getAttribution]
213 }
214
215 /**
216 * Demonstrate setSublocationId method
217 */
218 func demonstrateSetSublocationId() {
219 print("--- setSublocationId Method ---")
220
221 guard let locationWindow = locationWindow else {
222 print("LocationWindow not available yet")
223 return
224 }
225
226 // [swift_LocationWindow_setSublocationId]
227 // Set sublocation ID to switch between floors
228 locationWindow.setSublocationId(1)
229 print("Set sublocation ID to 1 (first floor)")
230 // [swift_LocationWindow_setSublocationId]
231
232 // [swift_LocationWindow_setSublocationId_2]
233 // Set sublocation ID to another floor
234 locationWindow.setSublocationId(2)
235 print("Set sublocation ID to 2 (second floor)")
236 // [swift_LocationWindow_setSublocationId_2]
237
238 // [swift_LocationWindow_setSublocationId_3]
239 // Set sublocation ID to ground floor
240 locationWindow.setSublocationId(0)
241 print("Set sublocation ID to 0 (ground floor)")
242 // [swift_LocationWindow_setSublocationId_3]
243
244 // Test with different sublocation IDs
245 let sublocationIds = [1, 2, 3, 0, 5]
246 for id in sublocationIds {
247 locationWindow.setSublocationId(id)
248 print("Switched to sublocation ID: \‍(id)")
249 }
250 }
251
252 /**
253 * Demonstrate getters for sublocation and enclosing camera
254 */
255 func demonstrateSublocationQueries() {
256 print("--- getSublocationId & getEnclosingCamera ---")
257
258 guard let locationWindow = locationWindow else {
259 print("LocationWindow not available yet")
260 return
261 }
262
263 // [swift_LocationWindow_getSublocationId]
264 if let currentId = locationWindow.getSublocationId() {
265 print("Current sublocation id: \‍(currentId)")
266 } else {
267 print("Current sublocation id is not set")
268 }
269 // [swift_LocationWindow_getSublocationId]
270
271 // [swift_LocationWindow_getEnclosingCamera]
272 let boundingBox = BoundingBox(
273 bottomLeft: GlobalPoint(latitude: 55.75, longitude: 37.61),
274 topRight: GlobalPoint(latitude: 55.76, longitude: 37.63))
275 let camera = locationWindow.getEnclosingCamera(boundingBox)
276 print("Camera that fits bounding box: \‍(camera)")
277 // [swift_LocationWindow_getEnclosingCamera]
278
279 // [swift_LocationWindow_setFocusRect]
280 let focus = ScreenRect(
281 topLeft: ScreenPoint(x: 0, y: 0),
282 bottomRight: ScreenPoint(x: 1000, y: 1600))
283 locationWindow.setFocusRect(focus)
284 // [swift_LocationWindow_setFocusRect]
285
286 // [swift_LocationWindow_getEnclosingCameraWithFocus]
287 let padded = locationWindow.getEnclosingCameraWithFocus(
288 boundingBox, focusRect: focus, azimuth: nil, tilt: nil)
289 print("Camera that fits bounding box in focus rect: \‍(padded)")
290 // [swift_LocationWindow_getEnclosingCameraWithFocus]
291 }
292
293 /**
294 * Demonstrate sublocation change listener usage
295 */
296 func demonstrateSublocationChangeListener() {
297 print("--- Sublocation Change Listener ---")
298
299 guard let locationWindow = locationWindow else {
300 print("LocationWindow not available yet")
301 return
302 }
303
304 let listener = DemoSublocationChangeListener()
305
306 // [swift_LocationWindow_addSublocationChangeListener]
307 locationWindow.addSublocationChangeListener(listener)
308 print("Added sublocation change listener")
309 // [swift_LocationWindow_addSublocationChangeListener]
310
311 locationWindow.setSublocationId(1)
312 locationWindow.setSublocationId(2)
313
314 // [swift_LocationWindow_removeSublocationChangeListener]
315 locationWindow.removeSublocationChangeListener(listener)
316 print("Removed sublocation change listener")
317 // [swift_LocationWindow_removeSublocationChangeListener]
318 }
319
320 /**
321 * Demonstrate user location layer controls
322 */
323 func demonstrateUserLocationLayer() {
324 print("--- UserLocationLayer ---")
325
326 guard let userLocationLayer = userLocationLayer else {
327 print("UserLocationLayer not available yet")
328 return
329 }
330
331 // [swift_UserLocationLayer_setVisible]
332 userLocationLayer.setVisible(true)
333 print("User location layer set visible")
334 // [swift_UserLocationLayer_setVisible]
335
336 // [swift_UserLocationLayer_isVisible]
337 let visible = userLocationLayer.isVisible()
338 print("User location layer is visible: \‍(visible)")
339 // [swift_UserLocationLayer_isVisible]
340
341 // [swift_UserLocationLayer_setAnchor]
342 let anchor = ScreenPoint(x: 100.0, y: 200.0)
343 userLocationLayer.setAnchor(anchor)
344 print("Set user location anchor to: (\‍(anchor.x), \‍(anchor.y))")
345 // [swift_UserLocationLayer_setAnchor]
346
347 // [swift_UserLocationLayer_anchorEnabled]
348 let anchorEnabled = userLocationLayer.anchorEnabled()
349 print("Anchor enabled: \‍(anchorEnabled)")
350 // [swift_UserLocationLayer_anchorEnabled]
351
352 // [swift_UserLocationLayer_setHeadingModeActive]
353 userLocationLayer.setHeadingModeActive(true)
354 print("Heading-up mode enabled")
355 // [swift_UserLocationLayer_setHeadingModeActive]
356
357 // [swift_UserLocationLayer_headingModeActive]
358 let headingModeActive = userLocationLayer.headingModeActive()
359 print("Heading-up mode active: \‍(headingModeActive)")
360 // [swift_UserLocationLayer_headingModeActive]
361
362 // [swift_UserLocationLayer_setFollowMode]
363 userLocationLayer.setFollowMode(.HEADING)
364 print("Follow mode set to heading")
365 // [swift_UserLocationLayer_setFollowMode]
366
367 // [swift_UserLocationLayer_followMode]
368 let followMode = userLocationLayer.followMode()
369 print("Follow mode: \‍(followMode)")
370 // [swift_UserLocationLayer_followMode]
371
372 // [swift_UserLocationLayer_setArrowBitmap]
373 if let arrow = UIImage(contentsOfFile: "/path/to/arrow.png") {
374 userLocationLayer.setArrowBitmap(arrow)
375 }
376 userLocationLayer.setArrowBitmap(nil)
377 print("Custom arrow bitmap cleared")
378 // [swift_UserLocationLayer_setArrowBitmap]
379
380 // [swift_UserLocationLayer_setAccuracyColor]
381 userLocationLayer.setAccuracyColor(UIColor(red: 0.19, green: 0.67, blue: 0.85, alpha: 0.26))
382 print("Accuracy circle color updated")
383 // [swift_UserLocationLayer_setAccuracyColor]
384
385 // [swift_UserLocationLayer_resetAnchor]
386 userLocationLayer.resetAnchor()
387 print("Anchor reset to default")
388 // [swift_UserLocationLayer_resetAnchor]
389 }
390
391 /**
392 * Demonstrate route layer controls
393 */
394 func demonstrateRouteLayer() {
395 print("--- RouteLayer ---")
396
397 guard let routeLayer = routeLayer else {
398 print("RouteLayer not available yet")
399 return
400 }
401
402 // [swift_RouteLayer_setVisible]
403 routeLayer.setVisible(true)
404 print("Route layer set visible")
405 // [swift_RouteLayer_setVisible]
406
407 // [swift_RouteLayer_isVisible]
408 let visible = routeLayer.isVisible()
409 print("Route layer is visible: \‍(visible)")
410 // [swift_RouteLayer_isVisible]
411
412 // [swift_RouteLayer_setTraveledColor]
413 routeLayer.setTraveledColor(UIColor(red: 0.47, green: 0.47, blue: 0.47, alpha: 0.7))
414 print("Traveled color updated")
415 // [swift_RouteLayer_setTraveledColor]
416
417 // [swift_RouteLayer_setRemainingColor]
418 routeLayer.setRemainingColor(UIColor(red: 0.19, green: 0.67, blue: 0.85, alpha: 1.0))
419 print("Remaining color updated")
420 // [swift_RouteLayer_setRemainingColor]
421
422 // [swift_RouteLayer_setWidth]
423 routeLayer.setWidth(8.0)
424 print("Route width updated")
425 // [swift_RouteLayer_setWidth]
426
427 // [swift_RouteLayer_setRemainingStyle]
428 routeLayer.setRemainingStyle(.DOTTED)
429 print("Remaining style set to DOTTED")
430 // [swift_RouteLayer_setRemainingStyle]
431
432 // [swift_RouteLayer_remainingStyle]
433 let remainingStyle = routeLayer.remainingStyle()
434 print("Remaining style: \‍(remainingStyle)")
435 // [swift_RouteLayer_remainingStyle]
436
437 // [swift_RouteLayer_setRemainingPointSize]
438 routeLayer.setRemainingPointSize(8.0, height: 8.0)
439 print("Remaining point size updated")
440 // [swift_RouteLayer_setRemainingPointSize]
441
442 // [swift_RouteLayer_setRemainingPlacement]
443 routeLayer.setRemainingPlacement(.SPACED)
444 print("Remaining placement updated")
445 // [swift_RouteLayer_setRemainingPlacement]
446
447 // [swift_RouteLayer_setRemainingPlacementSpacing]
448 routeLayer.setRemainingPlacementSpacing(8.0)
449 print("Remaining placement spacing updated")
450 // [swift_RouteLayer_setRemainingPlacementSpacing]
451
452 // [swift_RouteLayer_setRemainingPlacementMinRatio]
453 routeLayer.setRemainingPlacementMinRatio(0.0)
454 print("Remaining placement min ratio updated")
455 // [swift_RouteLayer_setRemainingPlacementMinRatio]
456
457 // [swift_RouteLayer_setRemainingCollisionEnabled]
458 routeLayer.setRemainingCollisionEnabled(false)
459 print("Remaining collision disabled")
460 // [swift_RouteLayer_setRemainingCollisionEnabled]
461
462 // [swift_RouteLayer_setRemainingDashLength]
463 routeLayer.setRemainingDashLength(0.5)
464 print("Remaining dash length updated")
465 // [swift_RouteLayer_setRemainingDashLength]
466
467 // [swift_RouteLayer_setRemainingGapLength]
468 routeLayer.setRemainingGapLength(0.4)
469 print("Remaining gap length updated")
470 // [swift_RouteLayer_setRemainingGapLength]
471
472 let from = RouteEndpoint(
473 point: GlobalPoint(latitude: 55.751244, longitude: 37.618423),
474 sublocationId: NSNumber(value: 1)) // nil for outdoor point
475 let to = RouteEndpoint(
476 point: GlobalPoint(latitude: 55.751700, longitude: 37.619000),
477 sublocationId: NSNumber(value: 2)) // nil for outdoor point
478
479 // [swift_RouteLayer_setRoute]
480 routeLayer.setRoute(from, to: to)
481 print("Static route applied")
482 // [swift_RouteLayer_setRoute]
483
484 // [swift_RouteLayer_setTarget]
485 routeLayer.setTarget(to)
486 print("Guidance target applied")
487 // [swift_RouteLayer_setTarget]
488
489 // [swift_RouteLayer_routes]
490 let routes = routeLayer.routes()
491 print("Visible routes: \‍(routes.count)")
492 // [swift_RouteLayer_routes]
493
494 // [swift_RouteLayer_selectedRoute]
495 if let selectedRoute = routeLayer.selectedRoute() {
496 print("Selected route length: \‍(selectedRoute.length())")
497 }
498 // [swift_RouteLayer_selectedRoute]
499
500 // [swift_RouteLayer_selectRoute]
501 if let firstRoute = routes.first {
502 routeLayer.selectRoute(firstRoute)
503 }
504 // [swift_RouteLayer_selectRoute]
505
506 // [swift_RouteLayer_addRouteLayerListener]
507 routeLayerListener = DemoRouteLayerListener()
508 routeLayer.addRouteLayerListener(routeLayerListener)
509 // [swift_RouteLayer_addRouteLayerListener]
510
511 // [swift_RouteLayer_addRouteViewListener]
512 routeViewListener = DemoRouteViewListener(routeLayer: routeLayer)
513 routeLayer.addRouteViewListener(routeViewListener)
514 // [swift_RouteLayer_addRouteViewListener]
515
516 // [swift_RouteLayer_clear]
517 routeLayer.clear()
518 print("Route layer cleared")
519 // [swift_RouteLayer_clear]
520 }
521
522 /**
523 * Demonstrate coordinate conversion methods
524 */
525 func demonstrateCoordinateConversion() {
526 print("--- Coordinate Conversion Methods ---")
527
528 guard let locationWindow = locationWindow else {
529 print("LocationWindow not available yet")
530 return
531 }
532
533 // [swift_LocationWindow_screenPositionToGlobal]
534 let screenPoint = ScreenPoint(x: 100.0, y: 200.0)
535 let globalPoint = locationWindow.screenPositionToGlobal(screenPoint)
536 print("Screen position (\‍(screenPoint.x), \‍(screenPoint.y)) converted to WGS84: (\‍(globalPoint.latitude), \‍(globalPoint.longitude))")
537 // [swift_LocationWindow_screenPositionToGlobal]
538
539 // [swift_LocationWindow_getVisibleRegion]
540 let visibleRegion = locationWindow.visibleRegion
541 print("Viewport top-left: \‍(visibleRegion.topLeft)")
542 // [swift_LocationWindow_getVisibleRegion]
543
544 // [swift_LocationWindow_getFocusRegion]
545 let focusRegion = locationWindow.focusRegion
546 print("Focus-rect top-left: \‍(focusRegion.topLeft)")
547 // [swift_LocationWindow_getFocusRegion]
548
549 // [swift_LocationWindow_globalToScreenPosition]
550 let globalPoint2 = GlobalPoint(latitude: 55.7558, longitude: 37.6176)
551 let screenPoint2 = locationWindow.globalToScreenPosition(globalPoint2, clipToViewport: true)
552 print("WGS84 (\‍(globalPoint2.latitude), \‍(globalPoint2.longitude)) converted to screen with clipping: (\‍(screenPoint2.x), \‍(screenPoint2.y))")
553 // [swift_LocationWindow_globalToScreenPosition]
554
555 let testScreenPoints = [
556 ScreenPoint(x: 0.0, y: 0.0),
557 ScreenPoint(x: 250.0, y: 250.0),
558 ScreenPoint(x: 1000.0, y: 600.0)
559 ]
560
561 for (index, screenPoint) in testScreenPoints.enumerated() {
562 let global = locationWindow.screenPositionToGlobal(screenPoint)
563 let backToScreen = locationWindow.globalToScreenPosition(global, clipToViewport: false)
564 print("Test \‍(index): Screen (\‍(screenPoint.x), \‍(screenPoint.y)) -> WGS84 (\‍(global.latitude), \‍(global.longitude)) -> Screen (\‍(backToScreen.x), \‍(backToScreen.y))")
565 }
566 }
567
568 /**
569 * Demonstrate map feature selection methods
570 */
571 func demonstrateMapFeatureSelection() {
572 print("--- Map Feature Selection Methods ---")
573
574 guard let locationWindow = locationWindow else {
575 print("LocationWindow not available yet")
576 return
577 }
578
579 // [swift_LocationWindow_selectMapFeature]
580 // Select map feature by ID
581 let featureId = "room_101"
582 let selected = locationWindow.selectMapFeature(featureId)
583 print("Selected map feature \‍(featureId): \‍(selected)")
584 // [swift_LocationWindow_selectMapFeature]
585
586 // [swift_LocationWindow_selectMapFeature_2]
587 // Select another map feature
588 let featureId2 = "office_205"
589 let selected2 = locationWindow.selectMapFeature(featureId2)
590 print("Selected map feature \‍(featureId2): \‍(selected2)")
591 // [swift_LocationWindow_selectMapFeature_2]
592
593 // [swift_LocationWindow_getSelectedMapFeatures]
594 // Get list of selected map features
595 let selectedFeatures = locationWindow.selectedMapFeatures
596 print("Currently selected map features: \‍(selectedFeatures.count) features")
597 for feature in selectedFeatures {
598 print(" - \‍(feature)")
599 }
600 // [swift_LocationWindow_getSelectedMapFeatures]
601
602 // [swift_LocationWindow_deselectMapFeature]
603 // Deselect specific map feature
604 let deselected = locationWindow.deselectMapFeature(featureId)
605 print("Deselected map feature \‍(featureId): \‍(deselected)")
606 // [swift_LocationWindow_deselectMapFeature]
607
608 // [swift_LocationWindow_deselectMapFeature_2]
609 // Deselect another map feature
610 let deselected2 = locationWindow.deselectMapFeature(featureId2)
611 print("Deselected map feature \‍(featureId2): \‍(deselected2)")
612 // [swift_LocationWindow_deselectMapFeature_2]
613
614 // [swift_LocationWindow_deselectAllMapFeatures]
615 // Deselect all map features
616 locationWindow.deselectAllMapFeatures()
617 print("Deselected all map features")
618 // [swift_LocationWindow_deselectAllMapFeatures]
619
620 // [swift_LocationWindow_getSelectedMapFeatures_2]
621 // Verify all features are deselected
622 let remainingFeatures = locationWindow.selectedMapFeatures
623 print("Remaining selected features after deselect all: \‍(remainingFeatures.count) features")
624 // [swift_LocationWindow_getSelectedMapFeatures_2]
625
626 // Test multiple feature selection and deselection
627 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
628
629 // Select multiple features
630 for featureId in testFeatureIds {
631 let success = locationWindow.selectMapFeature(featureId)
632 print("Selected feature \‍(featureId): \‍(success)")
633 }
634
635 // Check selected features
636 let allSelected = locationWindow.selectedMapFeatures
637 print("All selected features: \‍(allSelected.count) features")
638
639 // Deselect all at once
640 locationWindow.deselectAllMapFeatures()
641 print("Deselected all features at once")
642 }
643
644 /**
645 * Demonstrate applyLayerFilter method
646 */
647 func demonstrateApplyLayerFilter() {
648 print("--- applyLayerFilter Method ---")
649
650 guard let locationWindow = locationWindow else {
651 print("LocationWindow not available yet")
652 return
653 }
654
655 // [swift_MapFilterCondition_constructor]
656 // Create filter condition: show only venues with category "Toilet" or "Cafe"
657 let condition = NCMapFilterCondition(property: "category", values: ["Toilet", "Cafe"])
658 // [swift_MapFilterCondition_constructor]
659
660 // [swift_LocationWindow_applyLayerFilter]
661 // Apply filter to venues layer
662 let conditions = [NCMapFilterCondition(property: "category", values: ["Toilet", "Cafe"])]
663 locationWindow.applyLayerFilter("venues", conditions: conditions)
664 print("Applied layer filter: show venues with category Toilet or Cafe")
665 // [swift_LocationWindow_applyLayerFilter]
666
667 // Reset filter (show all venues)
668 locationWindow.applyLayerFilter("venues", conditions: [])
669 print("Reset layer filter: show all venues")
670 }
671
672 /**
673 * Demonstrate zoom properties
674 */
675 func demonstrateZoomProperties() {
676 print("--- Zoom Properties ---")
677
678 guard let locationWindow = locationWindow else {
679 print("LocationWindow not available yet")
680 return
681 }
682
683 // [swift_LocationWindow_getZoomFactor]
684 // Get current zoom factor
685 let currentZoom = locationWindow.zoomFactor
686 print("Current zoom factor: \‍(currentZoom)")
687 // [swift_LocationWindow_getZoomFactor]
688
689 // [swift_LocationWindow_setZoomFactor]
690 // Set zoom factor
691 locationWindow.zoomFactor = 150.0
692 print("Set zoom factor to 150.0")
693 // [swift_LocationWindow_setZoomFactor]
694
695 // [swift_LocationWindow_getMinZoomFactor]
696 // Get minimum zoom factor
697 let minZoomFactor = locationWindow.minZoomFactor
698 print("Minimum zoom factor: \‍(minZoomFactor)")
699 // [swift_LocationWindow_getMinZoomFactor]
700
701 // [swift_LocationWindow_setMinZoomFactor]
702 // Set minimum zoom factor
703 locationWindow.minZoomFactor = 50.0
704 print("Set minimum zoom factor to 50.0")
705 // [swift_LocationWindow_setMinZoomFactor]
706
707 // [swift_LocationWindow_getMaxZoomFactor]
708 // Get maximum zoom factor
709 let maxZoomFactor = locationWindow.maxZoomFactor
710 print("Maximum zoom factor: \‍(maxZoomFactor)")
711 // [swift_LocationWindow_getMaxZoomFactor]
712
713 // [swift_LocationWindow_setMaxZoomFactor]
714 // Set maximum zoom factor
715 locationWindow.maxZoomFactor = 300.0
716 print("Set maximum zoom factor to 300.0")
717 // [swift_LocationWindow_setMaxZoomFactor]
718
719 // Test zoom factor changes
720 let testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0]
721 for zoom in testZoomFactors {
722 locationWindow.zoomFactor = zoom
723 print("Changed zoom factor to: \‍(locationWindow.zoomFactor)")
724 }
725
726 // Test zoom limits
727 print("Testing zoom limits...")
728 locationWindow.zoomFactor = locationWindow.minZoomFactor
729 print("Set to minimum zoom: \‍(locationWindow.zoomFactor)")
730
731 locationWindow.zoomFactor = locationWindow.maxZoomFactor
732 print("Set to maximum zoom: \‍(locationWindow.zoomFactor)")
733
734 // Reset to default
735 locationWindow.zoomFactor = 100.0
736 print("Reset zoom factor to default: \‍(locationWindow.zoomFactor)")
737 }
738
739 /**
740 * Main demonstration method
741 */
742 func runExample() {
743 print("=== LocationWindowCommon Example ===")
744
745 // Simulate LocationWindow initialization
746 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
747 // TODO: User will implement LocationWindow initialization here
748 // self.locationWindow = self.getLocationWindow()
749
750 // Run demonstrations
751 self.demonstrateLocationWindowCommonMethods()
752
753 print("=== Example completed ===")
754 }
755 }
756}
757
758/**
759 * Function to run the example
760 */
761func main() {
762 let example = LocationWindowCommonExample()
763 example.runExample()
764
765 // Keep the program running for a bit to see the output
766 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
767}
768
769// Run the example
770main()
771
772class DemoSublocationChangeListener: NSObject, SublocationChangeListener {
773 // [swift_SublocationChangeListener_onActiveSublocationChanged]
774 func onActiveSublocationChanged(_ sublocationId: Int32) {
775 print("Active sublocation changed to: \‍(sublocationId)")
776 }
777 // [swift_SublocationChangeListener_onActiveSublocationChanged]
778}