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