Loading...
Searching...
No Matches
LocationWindowCommonExample.swift
Go to the documentation of this file.
1import Foundation
2import Dispatch
3
4/**
5 * LocationWindowCommon usage example for Swift
6 * Demonstrates specific methods: setSublocationId, screenPositionToMeters, metersToScreenPosition,
7 * selectMapFeature, deselectMapFeature, deselectAllMapFeatures, selectedMapFeatures,
8 * zoomFactor, minZoomFactor, maxZoomFactor
9 */
10class LocationWindowCommonExample {
11
12 private var locationWindow: LocationWindow?
13
14 init() {
15 demonstrateLocationWindowCommonMethods()
16 }
17
18 /**
19 * Demonstrate LocationWindowCommon methods
20 */
21 func demonstrateLocationWindowCommonMethods() {
22 print("=== LocationWindowCommon Methods ===")
23
24 demonstrateSetSublocationId()
25 demonstrateCoordinateConversion()
26 demonstrateMapFeatureSelection()
27 demonstrateZoomProperties()
28 }
29
30 /**
31 * Demonstrate setSublocationId method
32 */
33 func demonstrateSetSublocationId() {
34 print("--- setSublocationId Method ---")
35
36 guard let locationWindow = locationWindow else {
37 print("LocationWindow not available yet")
38 return
39 }
40
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]
46
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]
52
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]
58
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)")
64 }
65 }
66
67 /**
68 * Demonstrate coordinate conversion methods
69 */
70 func demonstrateCoordinateConversion() {
71 print("--- Coordinate Conversion Methods ---")
72
73 guard let locationWindow = locationWindow else {
74 print("LocationWindow not available yet")
75 return
76 }
77
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]
84
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]
91
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]
98
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]
105
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)
111 ]
112
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))")
117 }
118 }
119
120 /**
121 * Demonstrate map feature selection methods
122 */
123 func demonstrateMapFeatureSelection() {
124 print("--- Map Feature Selection Methods ---")
125
126 guard let locationWindow = locationWindow else {
127 print("LocationWindow not available yet")
128 return
129 }
130
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]
137
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]
144
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)")
151 }
152 // [swift_LocationWindow_getSelectedMapFeatures]
153
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]
159
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]
165
166 // [swift_LocationWindow_deselectAllMapFeatures]
167 // Deselect all map features
168 locationWindow.deselectAllMapFeatures()
169 print("Deselected all map features")
170 // [swift_LocationWindow_deselectAllMapFeatures]
171
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]
177
178 // Test multiple feature selection and deselection
179 let testFeatureIds = ["room_101", "office_205", "meeting_room_301", "cafe_401"]
180
181 // Select multiple features
182 for featureId in testFeatureIds {
183 let success = locationWindow.selectMapFeature(featureId)
184 print("Selected feature \‍(featureId): \‍(success)")
185 }
186
187 // Check selected features
188 let allSelected = locationWindow.selectedMapFeatures
189 print("All selected features: \‍(allSelected.count) features")
190
191 // Deselect all at once
192 locationWindow.deselectAllMapFeatures()
193 print("Deselected all features at once")
194 }
195
196 /**
197 * Demonstrate zoom properties
198 */
199 func demonstrateZoomProperties() {
200 print("--- Zoom Properties ---")
201
202 guard let locationWindow = locationWindow else {
203 print("LocationWindow not available yet")
204 return
205 }
206
207 // [swift_LocationWindow_getZoomFactor]
208 // Get current zoom factor
209 let currentZoom = locationWindow.zoomFactor
210 print("Current zoom factor: \‍(currentZoom)")
211 // [swift_LocationWindow_getZoomFactor]
212
213 // [swift_LocationWindow_setZoomFactor]
214 // Set zoom factor
215 locationWindow.zoomFactor = 150.0
216 print("Set zoom factor to 150.0")
217 // [swift_LocationWindow_setZoomFactor]
218
219 // [swift_LocationWindow_getMinZoomFactor]
220 // Get minimum zoom factor
221 let minZoomFactor = locationWindow.minZoomFactor
222 print("Minimum zoom factor: \‍(minZoomFactor)")
223 // [swift_LocationWindow_getMinZoomFactor]
224
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]
230
231 // [swift_LocationWindow_getMaxZoomFactor]
232 // Get maximum zoom factor
233 let maxZoomFactor = locationWindow.maxZoomFactor
234 print("Maximum zoom factor: \‍(maxZoomFactor)")
235 // [swift_LocationWindow_getMaxZoomFactor]
236
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]
242
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)")
248 }
249
250 // Test zoom limits
251 print("Testing zoom limits...")
252 locationWindow.zoomFactor = locationWindow.minZoomFactor
253 print("Set to minimum zoom: \‍(locationWindow.zoomFactor)")
254
255 locationWindow.zoomFactor = locationWindow.maxZoomFactor
256 print("Set to maximum zoom: \‍(locationWindow.zoomFactor)")
257
258 // Reset to default
259 locationWindow.zoomFactor = 100.0
260 print("Reset zoom factor to default: \‍(locationWindow.zoomFactor)")
261 }
262
263 /**
264 * Main demonstration method
265 */
266 func runExample() {
267 print("=== LocationWindowCommon Example ===")
268
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()
273
274 // Run demonstrations
275 self.demonstrateLocationWindowCommonMethods()
276
277 print("=== Example completed ===")
278 }
279 }
280}
281
282/**
283 * Function to run the example
284 */
285func main() {
286 let example = LocationWindowCommonExample()
287 example.runExample()
288
289 // Keep the program running for a bit to see the output
290 RunLoop.main.run(until: Date().addingTimeInterval(2.0))
291}
292
293// Run the example
294main()