Loading...
Searching...
No Matches
LocationWindowCommonExample.java
Go to the documentation of this file.
1package com.navigine.examples;
2
3import java.util.Arrays;
4import java.util.List;
5
13
14 private LocationWindow locationWindow;
15 private UserLocationView userLocationView;
16 private UserLocationLayer userLocationLayer;
17
21
37
42 System.out.println("--- setSublocationId Method ---");
43
44 if (locationWindow == null) {
45 System.out.println("LocationWindow not available yet");
46 return;
47 }
48
49 // [java_LocationWindow_setSublocationId]
50 // Set sublocation ID to switch between floors
51 locationWindow.setSublocationId(1);
52 System.out.println("Set sublocation ID to 1 (first floor)");
53 // [java_LocationWindow_setSublocationId]
54
55 // [java_LocationWindow_setSublocationId_2]
56 // Set sublocation ID to another floor
57 locationWindow.setSublocationId(2);
58 System.out.println("Set sublocation ID to 2 (second floor)");
59 // [java_LocationWindow_setSublocationId_2]
60
61 // [java_LocationWindow_setSublocationId_3]
62 // Set sublocation ID to ground floor
63 locationWindow.setSublocationId(0);
64 System.out.println("Set sublocation ID to 0 (ground floor)");
65 // [java_LocationWindow_setSublocationId_3]
66
67 // Test with different sublocation IDs
68 List<Integer> sublocationIds = Arrays.asList(1, 2, 3, 0, 5);
69 for (Integer id : sublocationIds) {
70 locationWindow.setSublocationId(id);
71 System.out.println("Switched to sublocation ID: " + id);
72 }
73 }
74
79 System.out.println("--- getSublocationId & getEnclosingCamera ---");
80
81 if (locationWindow == null) {
82 System.out.println("LocationWindow not available yet");
83 return;
84 }
85
86 // [java_LocationWindow_getSublocationId]
87 Integer currentId = locationWindow.getSublocationId();
88 if (currentId != null) {
89 System.out.println("Current sublocation id: " + currentId);
90 } else {
91 System.out.println("Current sublocation id is not set");
92 }
93 // [java_LocationWindow_getSublocationId]
94
95 // [java_LocationWindow_getEnclosingCamera]
96 BoundingBox boundingBox = new BoundingBox(new Point(0.0, 0.0), new Point(20.0, 30.0));
97 Camera camera = locationWindow.getEnclosingCamera(boundingBox);
98 System.out.println("Camera that fits bounding box: " + camera);
99 // [java_LocationWindow_getEnclosingCamera]
100 }
101
106 System.out.println("--- Sublocation Change Listener ---");
107
108 if (locationWindow == null) {
109 System.out.println("LocationWindow not available yet");
110 return;
111 }
112
113 DemoSublocationChangeListener listener = new DemoSublocationChangeListener();
114
115 // [java_LocationWindow_addSublocationChangeListener]
116 locationWindow.addSublocationChangeListener(listener);
117 System.out.println("Added sublocation change listener");
118 // [java_LocationWindow_addSublocationChangeListener]
119
120 locationWindow.setSublocationId(1);
121 locationWindow.setSublocationId(2);
122
123 // [java_LocationWindow_removeSublocationChangeListener]
124 locationWindow.removeSublocationChangeListener(listener);
125 System.out.println("Removed sublocation change listener");
126 // [java_LocationWindow_removeSublocationChangeListener]
127 }
128
133 System.out.println("--- UserLocationView ---");
134
135 if (userLocationView == null) {
136 System.out.println("UserLocationView not available yet");
137 return;
138 }
139
140 // [java_UserLocationView_getArrow]
141 IconMapObject arrow = userLocationView.getArrow();
142 System.out.println("Arrow icon object: " + arrow);
143 // [java_UserLocationView_getArrow]
144
145 // [java_UserLocationView_getAccuracyCircle]
146 CircleMapObject accuracyCircle = userLocationView.getAccuracyCircle();
147 System.out.println("Accuracy circle object: " + accuracyCircle);
148 // [java_UserLocationView_getAccuracyCircle]
149 }
150
155 System.out.println("--- UserLocationLayer ---");
156
157 if (userLocationLayer == null) {
158 System.out.println("UserLocationLayer not available yet");
159 return;
160 }
161
162 // [java_UserLocationLayer_setVisible]
163 userLocationLayer.setVisible(true);
164 System.out.println("User location layer set visible");
165 // [java_UserLocationLayer_setVisible]
166
167 // [java_UserLocationLayer_isVisible]
168 boolean visible = userLocationLayer.isVisible();
169 System.out.println("User location layer is visible: " + visible);
170 // [java_UserLocationLayer_isVisible]
171
172 // [java_UserLocationLayer_setAnchor]
173 ScreenPoint anchor = new ScreenPoint(100.0f, 200.0f);
174 userLocationLayer.setAnchor(anchor);
175 System.out.println("Set user location anchor to: (" + anchor.getX() + ", " + anchor.getY() + ")");
176 // [java_UserLocationLayer_setAnchor]
177
178 // [java_UserLocationLayer_anchorEnabled]
179 boolean anchorEnabled = userLocationLayer.anchorEnabled();
180 System.out.println("Anchor enabled: " + anchorEnabled);
181 // [java_UserLocationLayer_anchorEnabled]
182
183 // [java_UserLocationLayer_resetAnchor]
184 userLocationLayer.resetAnchor();
185 System.out.println("Anchor reset to default");
186 // [java_UserLocationLayer_resetAnchor]
187 }
188
193 System.out.println("--- Coordinate Conversion Methods ---");
194
195 if (locationWindow == null) {
196 System.out.println("LocationWindow not available yet");
197 return;
198 }
199
200 // [java_LocationWindow_screenPositionToMeters]
201 // Convert screen position to meters
202 Point screenPoint = new Point(100.0, 200.0);
203 Point metersPoint = locationWindow.screenPositionToMeters(screenPoint);
204 System.out.printf("Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)%n",
205 screenPoint.getX(), screenPoint.getY(), metersPoint.getX(), metersPoint.getY());
206 // [java_LocationWindow_screenPositionToMeters]
207
208 // [java_LocationWindow_screenPositionToMeters_2]
209 // Convert another screen position to meters
210 Point screenPoint2 = new Point(500.0, 300.0);
211 Point metersPoint2 = locationWindow.screenPositionToMeters(screenPoint2);
212 System.out.printf("Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)%n",
213 screenPoint2.getX(), screenPoint2.getY(), metersPoint2.getX(), metersPoint2.getY());
214 // [java_LocationWindow_screenPositionToMeters_2]
215
216 // [java_LocationWindow_metersToScreenPosition]
217 // Convert meters to screen position with clipping
218 Point metersPoint3 = new Point(50.0, 75.0);
219 Point screenPoint3 = locationWindow.metersToScreenPosition(metersPoint3, true);
220 System.out.printf("Meters position (%.1f, %.1f) converted to screen with clipping: (%.1f, %.1f)%n",
221 metersPoint3.getX(), metersPoint3.getY(), screenPoint3.getX(), screenPoint3.getY());
222 // [java_LocationWindow_metersToScreenPosition]
223
224 // [java_LocationWindow_metersToScreenPosition_2]
225 // Convert meters to screen position without clipping
226 Point metersPoint4 = new Point(150.0, 200.0);
227 Point screenPoint4 = locationWindow.metersToScreenPosition(metersPoint4, false);
228 System.out.printf("Meters position (%.1f, %.1f) converted to screen without clipping: (%.1f, %.1f)%n",
229 metersPoint4.getX(), metersPoint4.getY(), screenPoint4.getX(), screenPoint4.getY());
230 // [java_LocationWindow_metersToScreenPosition_2]
231
232 // Test coordinate conversion with different values
233 List<Point> testScreenPoints = Arrays.asList(
234 new Point(0.0, 0.0),
235 new Point(250.0, 250.0),
236 new Point(1000.0, 600.0)
237 );
238
239 for (int i = 0; i < testScreenPoints.size(); i++) {
240 Point screenPoint = testScreenPoints.get(i);
241 Point metersPoint = locationWindow.screenPositionToMeters(screenPoint);
242 Point backToScreen = locationWindow.metersToScreenPosition(metersPoint, false);
243 System.out.printf("Test %d: Screen (%.1f, %.1f) -> Meters (%.1f, %.1f) -> Screen (%.1f, %.1f)%n",
244 i, screenPoint.getX(), screenPoint.getY(),
245 metersPoint.getX(), metersPoint.getY(),
246 backToScreen.getX(), backToScreen.getY());
247 }
248 }
249
254 System.out.println("--- Map Feature Selection Methods ---");
255
256 if (locationWindow == null) {
257 System.out.println("LocationWindow not available yet");
258 return;
259 }
260
261 // [java_LocationWindow_selectMapFeature]
262 // Select map feature by ID
263 String featureId = "room_101";
264 boolean selected = locationWindow.selectMapFeature(featureId);
265 System.out.println("Selected map feature " + featureId + ": " + selected);
266 // [java_LocationWindow_selectMapFeature]
267
268 // [java_LocationWindow_selectMapFeature_2]
269 // Select another map feature
270 String featureId2 = "office_205";
271 boolean selected2 = locationWindow.selectMapFeature(featureId2);
272 System.out.println("Selected map feature " + featureId2 + ": " + selected2);
273 // [java_LocationWindow_selectMapFeature_2]
274
275 // [java_LocationWindow_getSelectedMapFeatures]
276 // Get list of selected map features
277 List<String> selectedFeatures = locationWindow.getSelectedMapFeatures();
278 System.out.println("Currently selected map features: " + selectedFeatures.size() + " features");
279 for (String feature : selectedFeatures) {
280 System.out.println(" - " + feature);
281 }
282 // [java_LocationWindow_getSelectedMapFeatures]
283
284 // [java_LocationWindow_deselectMapFeature]
285 // Deselect specific map feature
286 boolean deselected = locationWindow.deselectMapFeature(featureId);
287 System.out.println("Deselected map feature " + featureId + ": " + deselected);
288 // [java_LocationWindow_deselectMapFeature]
289
290 // [java_LocationWindow_deselectMapFeature_2]
291 // Deselect another map feature
292 boolean deselected2 = locationWindow.deselectMapFeature(featureId2);
293 System.out.println("Deselected map feature " + featureId2 + ": " + deselected2);
294 // [java_LocationWindow_deselectMapFeature_2]
295
296 // [java_LocationWindow_deselectAllMapFeatures]
297 // Deselect all map features
298 locationWindow.deselectAllMapFeatures();
299 System.out.println("Deselected all map features");
300 // [java_LocationWindow_deselectAllMapFeatures]
301
302 // [java_LocationWindow_getSelectedMapFeatures_2]
303 // Verify all features are deselected
304 List<String> remainingFeatures = locationWindow.getSelectedMapFeatures();
305 System.out.println("Remaining selected features after deselect all: " + remainingFeatures.size() + " features");
306 // [java_LocationWindow_getSelectedMapFeatures_2]
307
308 // Test multiple feature selection and deselection
309 List<String> testFeatureIds = Arrays.asList("room_101", "office_205", "meeting_room_301", "cafe_401");
310
311 // Select multiple features
312 for (String featureId : testFeatureIds) {
313 boolean success = locationWindow.selectMapFeature(featureId);
314 System.out.println("Selected feature " + featureId + ": " + success);
315 }
316
317 // Check selected features
318 List<String> allSelected = locationWindow.getSelectedMapFeatures();
319 System.out.println("All selected features: " + allSelected.size() + " features");
320
321 // Deselect all at once
322 locationWindow.deselectAllMapFeatures();
323 System.out.println("Deselected all features at once");
324 }
325
330 System.out.println("--- Zoom Properties ---");
331
332 if (locationWindow == null) {
333 System.out.println("LocationWindow not available yet");
334 return;
335 }
336
337 // [java_LocationWindow_getZoomFactor]
338 // Get current zoom factor
339 double currentZoom = locationWindow.getZoomFactor();
340 System.out.println("Current zoom factor: " + currentZoom);
341 // [java_LocationWindow_getZoomFactor]
342
343 // [java_LocationWindow_setZoomFactor]
344 // Set zoom factor
345 locationWindow.setZoomFactor(150.0);
346 System.out.println("Set zoom factor to 150.0");
347 // [java_LocationWindow_setZoomFactor]
348
349 // [java_LocationWindow_getMinZoomFactor]
350 // Get minimum zoom factor
351 double minZoomFactor = locationWindow.getMinZoomFactor();
352 System.out.println("Minimum zoom factor: " + minZoomFactor);
353 // [java_LocationWindow_getMinZoomFactor]
354
355 // [java_LocationWindow_setMinZoomFactor]
356 // Set minimum zoom factor
357 locationWindow.setMinZoomFactor(50.0);
358 System.out.println("Set minimum zoom factor to 50.0");
359 // [java_LocationWindow_setMinZoomFactor]
360
361 // [java_LocationWindow_getMaxZoomFactor]
362 // Get maximum zoom factor
363 double maxZoomFactor = locationWindow.getMaxZoomFactor();
364 System.out.println("Maximum zoom factor: " + maxZoomFactor);
365 // [java_LocationWindow_getMaxZoomFactor]
366
367 // [java_LocationWindow_setMaxZoomFactor]
368 // Set maximum zoom factor
369 locationWindow.setMaxZoomFactor(300.0);
370 System.out.println("Set maximum zoom factor to 300.0");
371 // [java_LocationWindow_setMaxZoomFactor]
372
373 // Test zoom factor changes
374 List<Double> testZoomFactors = Arrays.asList(100.0, 125.0, 150.0, 200.0, 250.0);
375 for (Double zoom : testZoomFactors) {
376 locationWindow.setZoomFactor(zoom);
377 System.out.println("Changed zoom factor to: " + locationWindow.getZoomFactor());
378 }
379
380 // Test zoom limits
381 System.out.println("Testing zoom limits...");
382 locationWindow.setZoomFactor(locationWindow.getMinZoomFactor());
383 System.out.println("Set to minimum zoom: " + locationWindow.getZoomFactor());
384
385 locationWindow.setZoomFactor(locationWindow.getMaxZoomFactor());
386 System.out.println("Set to maximum zoom: " + locationWindow.getZoomFactor());
387
388 // Reset to default
389 locationWindow.setZoomFactor(100.0);
390 System.out.println("Reset zoom factor to default: " + locationWindow.getZoomFactor());
391 }
392
396 public void runExample() {
397 System.out.println("=== LocationWindowCommon Example ===");
398
399 // Simulate LocationWindow initialization
400 try {
401 Thread.sleep(500);
402 } catch (InterruptedException e) {
403 Thread.currentThread().interrupt();
404 }
405
406 // TODO: User will implement LocationWindow initialization here
407 // locationWindow = getLocationWindow();
408
409 // Run demonstrations
411
412 System.out.println("=== Example completed ===");
413 }
414
418 public static void main(String[] args) {
420 example.runExample();
421 }
422}
423
424class DemoSublocationChangeListener implements SublocationChangeListener {
425 // [java_SublocationChangeListener_onActiveSublocationChanged]
426 @Override
427 public void onActiveSublocationChanged(int sublocationId) {
428 System.out.println("Active sublocation changed to: " + sublocationId);
429 }
430 // [java_SublocationChangeListener_onActiveSublocationChanged]
431}