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?
15 demonstrateLocationWindowCommonMethods()
19 * Demonstrate LocationWindowCommon methods
21 func demonstrateLocationWindowCommonMethods() {
22 print("=== LocationWindowCommon Methods ===")
24 demonstrateSetSublocationId()
25 demonstrateCoordinateConversion()
26 demonstrateMapFeatureSelection()
27 demonstrateZoomProperties()
31 * Demonstrate setSublocationId method
33 func demonstrateSetSublocationId() {
34 print("--- setSublocationId Method ---")
36 guard let locationWindow = locationWindow else {
37 print("LocationWindow not available yet")
41 // [swift_LocationWindow_setSublocationId]
42 // Set sublocation ID to switch between floors
43 locationWindow.setSublocationId(1)
44 print("Set sublocation ID to 1 (first floor)")
45 // [swift_LocationWindow_setSublocationId]
47 // [swift_LocationWindow_setSublocationId_2]
48 // Set sublocation ID to another floor
49 locationWindow.setSublocationId(2)
50 print("Set sublocation ID to 2 (second floor)")
51 // [swift_LocationWindow_setSublocationId_2]
53 // [swift_LocationWindow_setSublocationId_3]
54 // Set sublocation ID to ground floor
55 locationWindow.setSublocationId(0)
56 print("Set sublocation ID to 0 (ground floor)")
57 // [swift_LocationWindow_setSublocationId_3]
59 // Test with different sublocation IDs
60 let sublocationIds = [1, 2, 3, 0, 5]
61 for id in sublocationIds {
62 locationWindow.setSublocationId(id)
63 print("Switched to sublocation ID: \(id)")
68 * Demonstrate coordinate conversion methods
70 func demonstrateCoordinateConversion() {
71 print("--- Coordinate Conversion Methods ---")
73 guard let locationWindow = locationWindow else {
74 print("LocationWindow not available yet")
78 // [swift_LocationWindow_screenPositionToMeters]
79 // Convert screen position to meters
80 let screenPoint = Point(x: 100.0, y: 200.0)
81 let metersPoint = locationWindow.screenPositionToMeters(screenPoint)
82 print("Screen position (\(screenPoint.x), \(screenPoint.y)) converted to meters: (\(metersPoint.x), \(metersPoint.y))")
83 // [swift_LocationWindow_screenPositionToMeters]
85 // [swift_LocationWindow_screenPositionToMeters_2]
86 // Convert another screen position to meters
87 let screenPoint2 = Point(x: 500.0, y: 300.0)
88 let metersPoint2 = locationWindow.screenPositionToMeters(screenPoint2)
89 print("Screen position (\(screenPoint2.x), \(screenPoint2.y)) converted to meters: (\(metersPoint2.x), \(metersPoint2.y))")
90 // [swift_LocationWindow_screenPositionToMeters_2]
92 // [swift_LocationWindow_metersToScreenPosition]
93 // Convert meters to screen position with clipping
94 let metersPoint3 = Point(x: 50.0, y: 75.0)
95 let screenPoint3 = locationWindow.metersToScreenPosition(metersPoint3, clipToViewport: true)
96 print("Meters position (\(metersPoint3.x), \(metersPoint3.y)) converted to screen with clipping: (\(screenPoint3.x), \(screenPoint3.y))")
97 // [swift_LocationWindow_metersToScreenPosition]
99 // [swift_LocationWindow_metersToScreenPosition_2]
100 // Convert meters to screen position without clipping
101 let metersPoint4 = Point(x: 150.0, y: 200.0)
102 let screenPoint4 = locationWindow.metersToScreenPosition(metersPoint4, clipToViewport: false)
103 print("Meters position (\(metersPoint4.x), \(metersPoint4.y)) converted to screen without clipping: (\(screenPoint4.x), \(screenPoint4.y))")
104 // [swift_LocationWindow_metersToScreenPosition_2]
106 // Test coordinate conversion with different values
107 let testScreenPoints = [
108 Point(x: 0.0, y: 0.0),
109 Point(x: 250.0, y: 250.0),
110 Point(x: 1000.0, y: 600.0)
113 for (index, screenPoint) in testScreenPoints.enumerated() {
114 let metersPoint = locationWindow.screenPositionToMeters(screenPoint)
115 let backToScreen = locationWindow.metersToScreenPosition(metersPoint, clipToViewport: false)
116 print("Test \(index): Screen (\(screenPoint.x), \(screenPoint.y)) -> Meters (\(metersPoint.x), \(metersPoint.y)) -> Screen (\(backToScreen.x), \(backToScreen.y))")
121 * Demonstrate map feature selection methods
123 func demonstrateMapFeatureSelection() {
124 print("--- Map Feature Selection Methods ---")
126 guard let locationWindow = locationWindow else {
127 print("LocationWindow not available yet")
131 // [swift_LocationWindow_selectMapFeature]
132 // Select map feature by ID
133 let featureId = "room_101"
134 let selected = locationWindow.selectMapFeature(featureId)
135 print("Selected map feature \(featureId): \(selected)")
136 // [swift_LocationWindow_selectMapFeature]
138 // [swift_LocationWindow_selectMapFeature_2]
139 // Select another map feature
140 let featureId2 = "office_205"
141 let selected2 = locationWindow.selectMapFeature(featureId2)
142 print("Selected map feature \(featureId2): \(selected2)")
143 // [swift_LocationWindow_selectMapFeature_2]
145 // [swift_LocationWindow_getSelectedMapFeatures]
146 // Get list of selected map features
147 let selectedFeatures = locationWindow.selectedMapFeatures
148 print("Currently selected map features: \(selectedFeatures.count) features")
149 for feature in selectedFeatures {
150 print(" - \(feature)")
152 // [swift_LocationWindow_getSelectedMapFeatures]
154 // [swift_LocationWindow_deselectMapFeature]
155 // Deselect specific map feature
156 let deselected = locationWindow.deselectMapFeature(featureId)
157 print("Deselected map feature \(featureId): \(deselected)")
158 // [swift_LocationWindow_deselectMapFeature]
160 // [swift_LocationWindow_deselectMapFeature_2]
161 // Deselect another map feature
162 let deselected2 = locationWindow.deselectMapFeature(featureId2)
163 print("Deselected map feature \(featureId2): \(deselected2)")
164 // [swift_LocationWindow_deselectMapFeature_2]
166 // [swift_LocationWindow_deselectAllMapFeatures]
167 // Deselect all map features
168 locationWindow.deselectAllMapFeatures()
169 print("Deselected all map features")
170 // [swift_LocationWindow_deselectAllMapFeatures]
172 // [swift_LocationWindow_getSelectedMapFeatures_2]
173 // Verify all features are deselected
174 let remainingFeatures = locationWindow.selectedMapFeatures
175 print("Remaining selected features after deselect all: \(remainingFeatures.count) features")
176 // [swift_LocationWindow_getSelectedMapFeatures_2]
178 // Test multiple feature selection and deselection
179 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
181 // Select multiple features
182 for featureId in testFeatureIds {
183 let success = locationWindow.selectMapFeature(featureId)
184 print("Selected feature \(featureId): \(success)")
187 // Check selected features
188 let allSelected = locationWindow.selectedMapFeatures
189 print("All selected features: \(allSelected.count) features")
191 // Deselect all at once
192 locationWindow.deselectAllMapFeatures()
193 print("Deselected all features at once")
197 * Demonstrate zoom properties
199 func demonstrateZoomProperties() {
200 print("--- Zoom Properties ---")
202 guard let locationWindow = locationWindow else {
203 print("LocationWindow not available yet")
207 // [swift_LocationWindow_getZoomFactor]
208 // Get current zoom factor
209 let currentZoom = locationWindow.zoomFactor
210 print("Current zoom factor: \(currentZoom)")
211 // [swift_LocationWindow_getZoomFactor]
213 // [swift_LocationWindow_setZoomFactor]
215 locationWindow.zoomFactor = 150.0
216 print("Set zoom factor to 150.0")
217 // [swift_LocationWindow_setZoomFactor]
219 // [swift_LocationWindow_getMinZoomFactor]
220 // Get minimum zoom factor
221 let minZoomFactor = locationWindow.minZoomFactor
222 print("Minimum zoom factor: \(minZoomFactor)")
223 // [swift_LocationWindow_getMinZoomFactor]
225 // [swift_LocationWindow_setMinZoomFactor]
226 // Set minimum zoom factor
227 locationWindow.minZoomFactor = 50.0
228 print("Set minimum zoom factor to 50.0")
229 // [swift_LocationWindow_setMinZoomFactor]
231 // [swift_LocationWindow_getMaxZoomFactor]
232 // Get maximum zoom factor
233 let maxZoomFactor = locationWindow.maxZoomFactor
234 print("Maximum zoom factor: \(maxZoomFactor)")
235 // [swift_LocationWindow_getMaxZoomFactor]
237 // [swift_LocationWindow_setMaxZoomFactor]
238 // Set maximum zoom factor
239 locationWindow.maxZoomFactor = 300.0
240 print("Set maximum zoom factor to 300.0")
241 // [swift_LocationWindow_setMaxZoomFactor]
243 // Test zoom factor changes
244 let testZoomFactors = [100.0, 125.0, 150.0, 200.0, 250.0]
245 for zoom in testZoomFactors {
246 locationWindow.zoomFactor = zoom
247 print("Changed zoom factor to: \(locationWindow.zoomFactor)")
251 print("Testing zoom limits...")
252 locationWindow.zoomFactor = locationWindow.minZoomFactor
253 print("Set to minimum zoom: \(locationWindow.zoomFactor)")
255 locationWindow.zoomFactor = locationWindow.maxZoomFactor
256 print("Set to maximum zoom: \(locationWindow.zoomFactor)")
259 locationWindow.zoomFactor = 100.0
260 print("Reset zoom factor to default: \(locationWindow.zoomFactor)")
264 * Main demonstration method
267 print("=== LocationWindowCommon Example ===")
269 // Simulate LocationWindow initialization
270 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
271 // TODO: User will implement LocationWindow initialization here
272 // self.locationWindow = self.getLocationWindow()
274 // Run demonstrations
275 self.demonstrateLocationWindowCommonMethods()
277 print("=== Example completed ===")
283 * Function to run the example
286 let example = LocationWindowCommonExample()
289 // Keep the program running for a bit to see the output
290 RunLoop.main.run(until: Date().addingTimeInterval(2.0))