Loading...
Searching...
No Matches
LocationWindowInteractionExample.java
Go to the documentation of this file.
1package com.navigine.examples;
2
3import com.navigine.idl.java.LocationWindow;
4import com.navigine.idl.java.InputListener;
5import com.navigine.idl.java.PickListener;
6import com.navigine.idl.java.MapObjectPickResult;
7import com.navigine.idl.java.LocationPoint;
8import com.navigine.idl.java.MapObject;
9import com.navigine.idl.java.Point;
10
11import java.util.ArrayList;
12import java.util.HashMap;
13import java.util.List;
14import java.util.Map;
15
23 private LocationWindow locationWindow;
24 private InputListener inputListener;
25 private PickListener pickListener;
26
28 demonstrateLocationWindowInteractionMethods();
29 }
30
34 private void demonstrateLocationWindowInteractionMethods() {
35 System.out.println("=== LocationWindowInteraction Example ===");
36
37 demonstrateGestureProperties();
38 demonstratePickProperties();
39 demonstratePickMethods();
40 demonstrateInputListeners();
41 demonstratePickListeners();
42 cleanup();
43 }
44
48 private void demonstrateGestureProperties() {
49 System.out.println("--- Gesture Properties ---");
50
51 if (locationWindow == null) {
52 System.out.println("LocationWindow not available yet");
53 return;
54 }
55
56 // [java_LocationWindow_setStickToBorder]
57 // Set stick to border property
58 locationWindow.setStickToBorder(true);
59 System.out.println("Set stick to border to true");
60 // [java_LocationWindow_setStickToBorder]
61
62 // [java_LocationWindow_setRotateGestureEnabled]
63 // Set rotate gesture enabled
64 locationWindow.setRotateGestureEnabled(true);
65 System.out.println("Set rotate gesture enabled to true");
66 // [java_LocationWindow_setRotateGestureEnabled]
67
68 // [java_LocationWindow_setTiltGesturesEnabled]
69 // Set tilt gestures enabled
70 locationWindow.setTiltGesturesEnabled(true);
71 System.out.println("Set tilt gestures enabled to true");
72 // [java_LocationWindow_setTiltGesturesEnabled]
73
74 // [java_LocationWindow_setScrollGesturesEnabled]
75 // Set scroll gestures enabled
76 locationWindow.setScrollGesturesEnabled(true);
77 System.out.println("Set scroll gestures enabled to true");
78 // [java_LocationWindow_setScrollGesturesEnabled]
79
80 // [java_LocationWindow_setZoomGesturesEnabled]
81 // Set zoom gestures enabled
82 locationWindow.setZoomGesturesEnabled(true);
83 System.out.println("Set zoom gestures enabled to true");
84 // [java_LocationWindow_setZoomGesturesEnabled]
85
86 // Test different gesture combinations
87 Object[][] gestureTests = {
88 {true, true, true, true, true},
89 {false, true, true, true, false},
90 {true, false, true, false, true},
91 {false, false, false, false, false},
92 };
93
94 for (int i = 0; i < gestureTests.length; i++) {
95 boolean rotate = (Boolean) gestureTests[i][0];
96 boolean tilt = (Boolean) gestureTests[i][1];
97 boolean scroll = (Boolean) gestureTests[i][2];
98 boolean zoom = (Boolean) gestureTests[i][3];
99 boolean stick = (Boolean) gestureTests[i][4];
100
101 locationWindow.setRotateGestureEnabled(rotate);
102 locationWindow.setTiltGesturesEnabled(tilt);
103 locationWindow.setScrollGesturesEnabled(scroll);
104 locationWindow.setZoomGesturesEnabled(zoom);
105 locationWindow.setStickToBorder(stick);
106 System.out.println("Gesture test " + i + ": Rotate=" + rotate + ", Tilt=" + tilt + ", Scroll=" + scroll + ", Zoom=" + zoom + ", Stick=" + stick);
107 }
108 }
109
113 private void demonstratePickProperties() {
114 System.out.println("--- Pick Properties ---");
115
116 if (locationWindow == null) {
117 System.out.println("LocationWindow not available yet");
118 return;
119 }
120
121 // [java_LocationWindow_setPickRadius]
122 // Set pick radius
123 locationWindow.setPickRadius(10.0);
124 System.out.println("Set pick radius to 10.0 pixels");
125 // [java_LocationWindow_setPickRadius]
126
127 // Test different pick radius values
128 double[] pickRadiusTests = {5.0, 10.0, 20.0, 50.0, 100.0};
129
130 for (int i = 0; i < pickRadiusTests.length; i++) {
131 double radius = pickRadiusTests[i];
132 locationWindow.setPickRadius(radius);
133 System.out.println("Pick radius test " + i + ": " + radius + " pixels");
134 }
135 }
136
140 private void demonstratePickMethods() {
141 System.out.println("--- Pick Methods ---");
142
143 if (locationWindow == null) {
144 System.out.println("LocationWindow not available yet");
145 return;
146 }
147
148 // [java_LocationWindow_pickMapObjectAt]
149 // Pick map object at screen position
150 Point screenPoint = new Point(100.0, 200.0);
151 locationWindow.pickMapObjectAt(screenPoint);
152 System.out.println("Picked map object at screen position (" + screenPoint.x + ", " + screenPoint.y + ")");
153 // [java_LocationWindow_pickMapObjectAt]
154
155 // [java_LocationWindow_pickMapFeatureAt]
156 // Pick map feature at screen position
157 Point featurePoint = new Point(150.0, 250.0);
158 locationWindow.pickMapFeatureAt(featurePoint);
159 System.out.println("Picked map feature at screen position (" + featurePoint.x + ", " + featurePoint.y + ")");
160 // [java_LocationWindow_pickMapFeatureAt]
161
162 // Test pick at different positions
163 Point[] pickTests = {
164 new Point(50.0, 50.0),
165 new Point(200.0, 300.0),
166 new Point(400.0, 100.0),
167 new Point(300.0, 400.0),
168 };
169
170 for (int i = 0; i < pickTests.length; i++) {
171 Point point = pickTests[i];
172 locationWindow.pickMapObjectAt(point);
173 locationWindow.pickMapFeatureAt(point);
174 System.out.println("Pick test " + i + ": Object and feature at (" + point.x + ", " + point.y + ")");
175 }
176 }
177
181 private void demonstrateInputListeners() {
182 System.out.println("--- Input Listeners ---");
183
184 if (locationWindow == null) {
185 System.out.println("LocationWindow not available yet");
186 return;
187 }
188
189 // [java_LocationWindow_addInputListener]
190 // Add input listener
191 inputListener = new InputListenerImpl();
192 locationWindow.addInputListener(inputListener);
193 System.out.println("Added input listener");
194 // [java_LocationWindow_addInputListener]
195
196 // [java_LocationWindow_removeInputListener]
197 // Remove input listener
198 locationWindow.removeInputListener(inputListener);
199 inputListener = null;
200 System.out.println("Removed input listener");
201 // [java_LocationWindow_removeInputListener]
202
203 // Test multiple listeners
204 InputListener[] listeners = {
205 new InputListenerImpl(),
206 new InputListenerImpl(),
207 new InputListenerImpl(),
208 };
209
210 for (int i = 0; i < listeners.length; i++) {
211 locationWindow.addInputListener(listeners[i]);
212 System.out.println("Added input listener " + i);
213 }
214
215 for (int i = 0; i < listeners.length; i++) {
216 locationWindow.removeInputListener(listeners[i]);
217 System.out.println("Removed input listener " + i);
218 }
219 }
220
224 private void demonstratePickListeners() {
225 System.out.println("--- Pick Listeners ---");
226
227 if (locationWindow == null) {
228 System.out.println("LocationWindow not available yet");
229 return;
230 }
231
232 // [java_LocationWindow_addPickListener]
233 // Add pick listener
234 pickListener = new PickListenerImpl();
235 locationWindow.addPickListener(pickListener);
236 System.out.println("Added pick listener");
237 // [java_LocationWindow_addPickListener]
238
239 // Test multiple pick listeners
240 PickListener[] listeners = {
241 new PickListenerImpl(),
242 new PickListenerImpl(),
243 new PickListenerImpl(),
244 };
245
246 for (int i = 0; i < listeners.length; i++) {
247 locationWindow.addPickListener(listeners[i]);
248 System.out.println("Added pick listener " + i);
249 }
250
251 for (int i = 0; i < listeners.length; i++) {
252 // [java_LocationWindow_removePickListener]
253 locationWindow.removePickListener(listeners[i]);
254 System.out.println("Removed pick listener " + i);
255 // [java_LocationWindow_removePickListener]
256 }
257 }
258
262 public void cleanup() {
263 if (inputListener != null) {
264 locationWindow.removeInputListener(inputListener);
265 inputListener = null;
266 }
267 if (pickListener != null) {
268 locationWindow.removePickListener(pickListener);
269 pickListener = null;
270 }
271 System.out.println("LocationWindowInteraction example cleanup completed");
272 }
273}
274
275// Input listener implementation
276class InputListenerImpl implements InputListener {
277 // [java_InputListener_onViewTap]
278 @Override
279 public void onViewTap(Point screenPoint) {
280 System.out.println("View tapped at screen position (" + screenPoint.x + ", " + screenPoint.y + ")");
281 }
282 // [java_InputListener_onViewTap]
283
284 // [java_InputListener_onViewDoubleTap]
285 @Override
286 public void onViewDoubleTap(Point screenPoint) {
287 System.out.println("View double tapped at screen position (" + screenPoint.x + ", " + screenPoint.y + ")");
288 }
289 // [java_InputListener_onViewDoubleTap]
290
291 // [java_InputListener_onViewLongTap]
292 @Override
293 public void onViewLongTap(Point screenPoint) {
294 System.out.println("View long tapped at screen position (" + screenPoint.x + ", " + screenPoint.y + ")");
295 }
296 // [java_InputListener_onViewLongTap]
297}
298
299// Pick listener implementation
300class PickListenerImpl implements PickListener {
301 // [java_PickListener_onMapObjectPickComplete]
302 @Override
303 public void onMapObjectPickComplete(MapObjectPickResult mapObjectPickResult, Point screenPosition) {
304 if (mapObjectPickResult != null) {
305 // [java_MapObjectPickResult_getPoint]
306 LocationPoint point = mapObjectPickResult.getPoint();
307 System.out.println("Map object picked at screen position (" + screenPosition.x + ", " + screenPosition.y + ")");
308 System.out.println(" Object location: (" + point.getX() + ", " + point.getY() + ")");
309 // [java_MapObjectPickResult_getPoint]
310
311 // [java_MapObjectPickResult_getMapObject]
312 MapObject mapObject = mapObjectPickResult.getMapObject();
313 System.out.println(" Object type: " + mapObject.getClass().getSimpleName());
314 // [java_MapObjectPickResult_getMapObject]
315 } else {
316 System.out.println("No map object found at screen position (" + screenPosition.x + ", " + screenPosition.y + ")");
317 }
318 }
319 // [java_PickListener_onMapObjectPickComplete]
320
321 // [java_PickListener_onMapFeaturePickComplete]
322 @Override
323 public void onMapFeaturePickComplete(Map<String, String> mapFeaturePickResult, Point screenPosition) {
324 if (mapFeaturePickResult != null) {
325 System.out.println("Map feature picked at screen position (" + screenPosition.x + ", " + screenPosition.y + ")");
326 System.out.println(" Feature properties: " + mapFeaturePickResult);
327 } else {
328 System.out.println("No map feature found at screen position (" + screenPosition.x + ", " + screenPosition.y + ")");
329 }
330 }
331 // [java_PickListener_onMapFeaturePickComplete]
332}
333
334// Main class
335class Main {
336 public static void main(String[] args) {
338 }
339}