Loading...
Searching...
No Matches
LocationWindowInteractionExample.swift
Go to the documentation of this file.
1import Foundation
2import NavigineSDK
3
4/**
5 * LocationWindowInteraction usage example for Swift
6 * Demonstrates specific methods: stickToBorder, rotateGestureEnabled, tiltGesturesEnabled,
7 * scrollGesturesEnabled, zoomGesturesEnabled, pickRadius, pickMapObjectAt, pickMapFeatureAt,
8 * addPickListener, addInputListener, removeInputListener
9 */
10class LocationWindowInteractionExample {
11 private var locationWindow: NCLocationWindow?
12 private var inputListener: NCInputListener?
13 private var pickListener: NCPickListener?
14
15 init() {
16 demonstrateLocationWindowInteractionMethods()
17 }
18
19 /**
20 * Demonstrate LocationWindowInteraction methods
21 */
22 private func demonstrateLocationWindowInteractionMethods() {
23 print("=== LocationWindowInteraction Example ===")
24
25 demonstrateGestureProperties()
26 demonstratePickProperties()
27 demonstratePickMethods()
28 demonstrateInputListeners()
29 demonstratePickListeners()
30 cleanup()
31 }
32
33 /**
34 * Demonstrate gesture properties
35 */
36 private func demonstrateGestureProperties() {
37 print("--- Gesture Properties ---")
38
39 guard let locationWindow = locationWindow else {
40 print("LocationWindow not available yet")
41 return
42 }
43
44 // [swift_LocationWindow_setStickToBorder]
45 // Set stick to border property
46 locationWindow.stickToBorder = true
47 print("Set stick to border to true")
48 // [swift_LocationWindow_setStickToBorder]
49
50 // [swift_LocationWindow_setRotateGestureEnabled]
51 // Set rotate gesture enabled
52 locationWindow.rotateGestureEnabled = true
53 print("Set rotate gesture enabled to true")
54 // [swift_LocationWindow_setRotateGestureEnabled]
55
56 // [swift_LocationWindow_setTiltGesturesEnabled]
57 // Set tilt gestures enabled
58 locationWindow.tiltGesturesEnabled = true
59 print("Set tilt gestures enabled to true")
60 // [swift_LocationWindow_setTiltGesturesEnabled]
61
62 // [swift_LocationWindow_setScrollGesturesEnabled]
63 // Set scroll gestures enabled
64 locationWindow.scrollGesturesEnabled = true
65 print("Set scroll gestures enabled to true")
66 // [swift_LocationWindow_setScrollGesturesEnabled]
67
68 // [swift_LocationWindow_setZoomGesturesEnabled]
69 // Set zoom gestures enabled
70 locationWindow.zoomGesturesEnabled = true
71 print("Set zoom gestures enabled to true")
72 // [swift_LocationWindow_setZoomGesturesEnabled]
73
74 // Test different gesture combinations
75 let gestureTests = [
76 [true, true, true, true, true],
77 [false, true, true, true, false],
78 [true, false, true, false, true],
79 [false, false, false, false, false],
80 ]
81
82 for (i, test) in gestureTests.enumerated() {
83 let rotate = test[0]
84 let tilt = test[1]
85 let scroll = test[2]
86 let zoom = test[3]
87 let stick = test[4]
88
89 locationWindow.rotateGestureEnabled = rotate
90 locationWindow.tiltGesturesEnabled = tilt
91 locationWindow.scrollGesturesEnabled = scroll
92 locationWindow.zoomGesturesEnabled = zoom
93 locationWindow.stickToBorder = stick
94 print("Gesture test \‍(i): Rotate=\‍(rotate), Tilt=\‍(tilt), Scroll=\‍(scroll), Zoom=\‍(zoom), Stick=\‍(stick)")
95 }
96 }
97
98 /**
99 * Demonstrate pick properties
100 */
101 private func demonstratePickProperties() {
102 print("--- Pick Properties ---")
103
104 guard let locationWindow = locationWindow else {
105 print("LocationWindow not available yet")
106 return
107 }
108
109 // [swift_LocationWindow_setPickRadius]
110 // Set pick radius
111 locationWindow.pickRadius = 10.0
112 print("Set pick radius to 10.0 pixels")
113 // [swift_LocationWindow_setPickRadius]
114
115 // Test different pick radius values
116 let pickRadiusTests = [5.0, 10.0, 20.0, 50.0, 100.0]
117
118 for (i, radius) in pickRadiusTests.enumerated() {
119 locationWindow.pickRadius = radius
120 print("Pick radius test \‍(i): \‍(radius) pixels")
121 }
122 }
123
124 /**
125 * Demonstrate pick methods
126 */
127 private func demonstratePickMethods() {
128 print("--- Pick Methods ---")
129
130 guard let locationWindow = locationWindow else {
131 print("LocationWindow not available yet")
132 return
133 }
134
135 // [swift_LocationWindow_pickMapObjectAt]
136 // Pick map object at screen position
137 let screenPoint = NCPoint(x: 100.0, y: 200.0)
138 locationWindow.pickMapObject(at: screenPoint)
139 print("Picked map object at screen position (\‍(screenPoint.x), \‍(screenPoint.y))")
140 // [swift_LocationWindow_pickMapObjectAt]
141
142 // [swift_LocationWindow_pickMapFeatureAt]
143 // Pick map feature at screen position
144 let featurePoint = NCPoint(x: 150.0, y: 250.0)
145 locationWindow.pickMapFeature(at: featurePoint)
146 print("Picked map feature at screen position (\‍(featurePoint.x), \‍(featurePoint.y))")
147 // [swift_LocationWindow_pickMapFeatureAt]
148
149 // Test pick at different positions
150 let pickTests = [
151 NCPoint(x: 50.0, y: 50.0),
152 NCPoint(x: 200.0, y: 300.0),
153 NCPoint(x: 400.0, y: 100.0),
154 NCPoint(x: 300.0, y: 400.0),
155 ]
156
157 for (i, point) in pickTests.enumerated() {
158 locationWindow.pickMapObject(at: point)
159 locationWindow.pickMapFeature(at: point)
160 print("Pick test \‍(i): Object and feature at (\‍(point.x), \‍(point.y))")
161 }
162 }
163
164 /**
165 * Demonstrate input listeners
166 */
167 private func demonstrateInputListeners() {
168 print("--- Input Listeners ---")
169
170 guard let locationWindow = locationWindow else {
171 print("LocationWindow not available yet")
172 return
173 }
174
175 // [swift_LocationWindow_addInputListener]
176 // Add input listener
177 inputListener = InputListenerImpl()
178 locationWindow.addInputListener(inputListener!)
179 print("Added input listener")
180 // [swift_LocationWindow_addInputListener]
181
182 // [swift_LocationWindow_removeInputListener]
183 // Remove input listener
184 locationWindow.removeInputListener(inputListener!)
185 inputListener = nil
186 print("Removed input listener")
187 // [swift_LocationWindow_removeInputListener]
188
189 // Test multiple listeners
190 let listeners = [
191 InputListenerImpl(),
192 InputListenerImpl(),
193 InputListenerImpl(),
194 ]
195
196 for (i, listener) in listeners.enumerated() {
197 locationWindow.addInputListener(listener)
198 print("Added input listener \‍(i)")
199 }
200
201 for (i, listener) in listeners.enumerated() {
202 locationWindow.removeInputListener(listener)
203 print("Removed input listener \‍(i)")
204 }
205 }
206
207 /**
208 * Demonstrate pick listeners
209 */
210 private func demonstratePickListeners() {
211 print("--- Pick Listeners ---")
212
213 guard let locationWindow = locationWindow else {
214 print("LocationWindow not available yet")
215 return
216 }
217
218 // [swift_LocationWindow_addPickListener]
219 // Add pick listener
220 pickListener = PickListenerImpl()
221 locationWindow.addPickListener(pickListener!)
222 print("Added pick listener")
223 // [swift_LocationWindow_addPickListener]
224
225 // Test multiple pick listeners
226 let listeners = [
227 PickListenerImpl(),
228 PickListenerImpl(),
229 PickListenerImpl(),
230 ]
231
232 for (i, listener) in listeners.enumerated() {
233 locationWindow.addPickListener(listener)
234 print("Added pick listener \‍(i)")
235 }
236
237 for (i, listener) in listeners.enumerated() {
238 // [swift_LocationWindow_removePickListener]
239 locationWindow.removePickListener(listener)
240 print("Removed pick listener \‍(i)")
241 // [swift_LocationWindow_removePickListener]
242 }
243 }
244
245 /**
246 * Cleanup resources
247 */
248 private func cleanup() {
249 if let inputListener = inputListener {
250 locationWindow?.removeInputListener(inputListener)
251 self.inputListener = nil
252 }
253 if let pickListener = pickListener {
254 locationWindow?.removePickListener(pickListener)
255 self.pickListener = nil
256 }
257 print("LocationWindowInteraction example cleanup completed")
258 }
259}
260
261// Input listener implementation
262class InputListenerImpl: NSObject, NCInputListener {
263 // [swift_InputListener_onViewTap]
264 func onViewTap(screenPoint: NCPoint) {
265 print("View tapped at screen position (\‍(screenPoint.x), \‍(screenPoint.y))")
266 }
267 // [swift_InputListener_onViewTap]
268
269 // [swift_InputListener_onViewDoubleTap]
270 func onViewDoubleTap(screenPoint: NCPoint) {
271 print("View double tapped at screen position (\‍(screenPoint.x), \‍(screenPoint.y))")
272 }
273 // [swift_InputListener_onViewDoubleTap]
274
275 // [swift_InputListener_onViewLongTap]
276 func onViewLongTap(screenPoint: NCPoint) {
277 print("View long tapped at screen position (\‍(screenPoint.x), \‍(screenPoint.y))")
278 }
279 // [swift_InputListener_onViewLongTap]
280}
281
282// Pick listener implementation
283class PickListenerImpl: NSObject, NCPickListener {
284 // [swift_PickListener_onMapObjectPickComplete]
285 func onMapObjectPickComplete(mapObjectPickResult: NCMapObjectPickResult?, screenPosition: NCPoint) {
286 if let result = mapObjectPickResult {
287 // [swift_MapObjectPickResult_getPoint]
288 let point = result.point
289 print("Map object picked at screen position (\‍(screenPosition.x), \‍(screenPosition.y))")
290 print(" Object location: (\‍(point.x), \‍(point.y))")
291 // [swift_MapObjectPickResult_getPoint]
292
293 // [swift_MapObjectPickResult_getMapObject]
294 let mapObject = result.mapObject
295 print(" Object type: \‍(type(of: mapObject))")
296 // [swift_MapObjectPickResult_getMapObject]
297 } else {
298 print("No map object found at screen position (\‍(screenPosition.x), \‍(screenPosition.y))")
299 }
300 }
301 // [swift_PickListener_onMapObjectPickComplete]
302
303 // [swift_PickListener_onMapFeaturePickComplete]
304 func onMapFeaturePickComplete(mapFeaturePickResult: [String: String]?, screenPosition: NCPoint) {
305 if let result = mapFeaturePickResult {
306 print("Map feature picked at screen position (\‍(screenPosition.x), \‍(screenPosition.y))")
307 print(" Feature properties: \‍(result)")
308 } else {
309 print("No map feature found at screen position (\‍(screenPosition.x), \‍(screenPosition.y))")
310 }
311 }
312 // [swift_PickListener_onMapFeaturePickComplete]
313}
314
315// Main function
316let example = LocationWindowInteractionExample()