Loading...
Searching...
No Matches
LocationWindowCommonExample.java
Go to the documentation of this file.
1package com.navigine.examples;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.List;
6
7import com.navigine.idl.java.DebugFlag;
8
16
17 private LocationWindow locationWindow;
18 private UserLocationView userLocationView;
19 private UserLocationLayer userLocationLayer;
20
24
42
46 public void demonstrateDebugFlags() {
47 System.out.println("--- Debug flags ---");
48
49 // [java_DebugFlag_enum]
50 DebugFlag[] allFlags = new DebugFlag[] {
57 };
58 System.out.println("Debug flag enum values: " + allFlags.length);
59 // [java_DebugFlag_enum]
60
61 // [java_LocationWindow_setDebugFlag]
64 System.out.println("Updated debug flags on LocationWindow");
65 // [java_LocationWindow_setDebugFlag]
66
67 // [java_LocationWindow_getDebugFlag]
68 boolean infosOn = LocationWindow.getDebugFlag(DebugFlag.INFOS);
69 System.out.println("Debug flag INFOS enabled: " + infosOn);
70 // [java_LocationWindow_getDebugFlag]
71 }
72
77 System.out.println("--- setSublocationId Method ---");
78
79 if (locationWindow == null) {
80 System.out.println("LocationWindow not available yet");
81 return;
82 }
83
84 // [java_LocationWindow_setSublocationId]
85 // Set sublocation ID to switch between floors
86 locationWindow.setSublocationId(1);
87 System.out.println("Set sublocation ID to 1 (first floor)");
88 // [java_LocationWindow_setSublocationId]
89
90 // [java_LocationWindow_setSublocationId_2]
91 // Set sublocation ID to another floor
92 locationWindow.setSublocationId(2);
93 System.out.println("Set sublocation ID to 2 (second floor)");
94 // [java_LocationWindow_setSublocationId_2]
95
96 // [java_LocationWindow_setSublocationId_3]
97 // Set sublocation ID to ground floor
98 locationWindow.setSublocationId(0);
99 System.out.println("Set sublocation ID to 0 (ground floor)");
100 // [java_LocationWindow_setSublocationId_3]
101
102 // Test with different sublocation IDs
103 List<Integer> sublocationIds = Arrays.asList(1, 2, 3, 0, 5);
104 for (Integer id : sublocationIds) {
105 locationWindow.setSublocationId(id);
106 System.out.println("Switched to sublocation ID: " + id);
107 }
108 }
109
114 System.out.println("--- getSublocationId & getEnclosingCamera ---");
115
116 if (locationWindow == null) {
117 System.out.println("LocationWindow not available yet");
118 return;
119 }
120
121 // [java_LocationWindow_getSublocationId]
122 Integer currentId = locationWindow.getSublocationId();
123 if (currentId != null) {
124 System.out.println("Current sublocation id: " + currentId);
125 } else {
126 System.out.println("Current sublocation id is not set");
127 }
128 // [java_LocationWindow_getSublocationId]
129
130 // [java_LocationWindow_getEnclosingCamera]
131 BoundingBox boundingBox = new BoundingBox(new Point(0.0, 0.0), new Point(20.0, 30.0));
132 Camera camera = locationWindow.getEnclosingCamera(boundingBox);
133 System.out.println("Camera that fits bounding box: " + camera);
134 // [java_LocationWindow_getEnclosingCamera]
135 }
136
141 System.out.println("--- Sublocation Change Listener ---");
142
143 if (locationWindow == null) {
144 System.out.println("LocationWindow not available yet");
145 return;
146 }
147
148 DemoSublocationChangeListener listener = new DemoSublocationChangeListener();
149
150 // [java_LocationWindow_addSublocationChangeListener]
151 locationWindow.addSublocationChangeListener(listener);
152 System.out.println("Added sublocation change listener");
153 // [java_LocationWindow_addSublocationChangeListener]
154
155 locationWindow.setSublocationId(1);
156 locationWindow.setSublocationId(2);
157
158 // [java_LocationWindow_removeSublocationChangeListener]
159 locationWindow.removeSublocationChangeListener(listener);
160 System.out.println("Removed sublocation change listener");
161 // [java_LocationWindow_removeSublocationChangeListener]
162 }
163
168 System.out.println("--- UserLocationView ---");
169
170 if (userLocationView == null) {
171 System.out.println("UserLocationView not available yet");
172 return;
173 }
174
175 // [java_UserLocationView_getArrow]
176 IconMapObject arrow = userLocationView.getArrow();
177 System.out.println("Arrow icon object: " + arrow);
178 // [java_UserLocationView_getArrow]
179
180 // [java_UserLocationView_getAccuracyCircle]
181 CircleMapObject accuracyCircle = userLocationView.getAccuracyCircle();
182 System.out.println("Accuracy circle object: " + accuracyCircle);
183 // [java_UserLocationView_getAccuracyCircle]
184 }
185
190 System.out.println("--- UserLocationLayer ---");
191
192 if (userLocationLayer == null) {
193 System.out.println("UserLocationLayer not available yet");
194 return;
195 }
196
197 // [java_UserLocationLayer_setVisible]
198 userLocationLayer.setVisible(true);
199 System.out.println("User location layer set visible");
200 // [java_UserLocationLayer_setVisible]
201
202 // [java_UserLocationLayer_isVisible]
203 boolean visible = userLocationLayer.isVisible();
204 System.out.println("User location layer is visible: " + visible);
205 // [java_UserLocationLayer_isVisible]
206
207 // [java_UserLocationLayer_setAnchor]
208 ScreenPoint anchor = new ScreenPoint(100.0f, 200.0f);
209 userLocationLayer.setAnchor(anchor);
210 System.out.println("Set user location anchor to: (" + anchor.getX() + ", " + anchor.getY() + ")");
211 // [java_UserLocationLayer_setAnchor]
212
213 // [java_UserLocationLayer_anchorEnabled]
214 boolean anchorEnabled = userLocationLayer.anchorEnabled();
215 System.out.println("Anchor enabled: " + anchorEnabled);
216 // [java_UserLocationLayer_anchorEnabled]
217
218 // [java_UserLocationLayer_resetAnchor]
219 userLocationLayer.resetAnchor();
220 System.out.println("Anchor reset to default");
221 // [java_UserLocationLayer_resetAnchor]
222 }
223
228 System.out.println("--- Coordinate Conversion Methods ---");
229
230 if (locationWindow == null) {
231 System.out.println("LocationWindow not available yet");
232 return;
233 }
234
235 // [java_LocationWindow_screenPositionToMeters]
236 // Convert screen position to meters
237 Point screenPoint = new Point(100.0, 200.0);
238 Point metersPoint = locationWindow.screenPositionToMeters(screenPoint);
239 System.out.printf("Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)%n",
240 screenPoint.getX(), screenPoint.getY(), metersPoint.getX(), metersPoint.getY());
241 // [java_LocationWindow_screenPositionToMeters]
242
243 // [java_LocationWindow_screenPositionToMeters_2]
244 // Convert another screen position to meters
245 Point screenPoint2 = new Point(500.0, 300.0);
246 Point metersPoint2 = locationWindow.screenPositionToMeters(screenPoint2);
247 System.out.printf("Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)%n",
248 screenPoint2.getX(), screenPoint2.getY(), metersPoint2.getX(), metersPoint2.getY());
249 // [java_LocationWindow_screenPositionToMeters_2]
250
251 // [java_LocationWindow_metersToScreenPosition]
252 // Convert meters to screen position with clipping
253 Point metersPoint3 = new Point(50.0, 75.0);
254 Point screenPoint3 = locationWindow.metersToScreenPosition(metersPoint3, true);
255 System.out.printf("Meters position (%.1f, %.1f) converted to screen with clipping: (%.1f, %.1f)%n",
256 metersPoint3.getX(), metersPoint3.getY(), screenPoint3.getX(), screenPoint3.getY());
257 // [java_LocationWindow_metersToScreenPosition]
258
259 // [java_LocationWindow_metersToScreenPosition_2]
260 // Convert meters to screen position without clipping
261 Point metersPoint4 = new Point(150.0, 200.0);
262 Point screenPoint4 = locationWindow.metersToScreenPosition(metersPoint4, false);
263 System.out.printf("Meters position (%.1f, %.1f) converted to screen without clipping: (%.1f, %.1f)%n",
264 metersPoint4.getX(), metersPoint4.getY(), screenPoint4.getX(), screenPoint4.getY());
265 // [java_LocationWindow_metersToScreenPosition_2]
266
267 // Test coordinate conversion with different values
268 List<Point> testScreenPoints = Arrays.asList(
269 new Point(0.0, 0.0),
270 new Point(250.0, 250.0),
271 new Point(1000.0, 600.0)
272 );
273
274 for (int i = 0; i < testScreenPoints.size(); i++) {
275 Point screenPoint = testScreenPoints.get(i);
276 Point metersPoint = locationWindow.screenPositionToMeters(screenPoint);
277 Point backToScreen = locationWindow.metersToScreenPosition(metersPoint, false);
278 System.out.printf("Test %d: Screen (%.1f, %.1f) -> Meters (%.1f, %.1f) -> Screen (%.1f, %.1f)%n",
279 i, screenPoint.getX(), screenPoint.getY(),
280 metersPoint.getX(), metersPoint.getY(),
281 backToScreen.getX(), backToScreen.getY());
282 }
283 }
284
289 System.out.println("--- Map Feature Selection Methods ---");
290
291 if (locationWindow == null) {
292 System.out.println("LocationWindow not available yet");
293 return;
294 }
295
296 // [java_LocationWindow_selectMapFeature]
297 // Select map feature by ID
298 String featureId = "room_101";
299 boolean selected = locationWindow.selectMapFeature(featureId);
300 System.out.println("Selected map feature " + featureId + ": " + selected);
301 // [java_LocationWindow_selectMapFeature]
302
303 // [java_LocationWindow_selectMapFeature_2]
304 // Select another map feature
305 String featureId2 = "office_205";
306 boolean selected2 = locationWindow.selectMapFeature(featureId2);
307 System.out.println("Selected map feature " + featureId2 + ": " + selected2);
308 // [java_LocationWindow_selectMapFeature_2]
309
310 // [java_LocationWindow_getSelectedMapFeatures]
311 // Get list of selected map features
312 List<String> selectedFeatures = locationWindow.getSelectedMapFeatures();
313 System.out.println("Currently selected map features: " + selectedFeatures.size() + " features");
314 for (String feature : selectedFeatures) {
315 System.out.println(" - " + feature);
316 }
317 // [java_LocationWindow_getSelectedMapFeatures]
318
319 // [java_LocationWindow_deselectMapFeature]
320 // Deselect specific map feature
321 boolean deselected = locationWindow.deselectMapFeature(featureId);
322 System.out.println("Deselected map feature " + featureId + ": " + deselected);
323 // [java_LocationWindow_deselectMapFeature]
324
325 // [java_LocationWindow_deselectMapFeature_2]
326 // Deselect another map feature
327 boolean deselected2 = locationWindow.deselectMapFeature(featureId2);
328 System.out.println("Deselected map feature " + featureId2 + ": " + deselected2);
329 // [java_LocationWindow_deselectMapFeature_2]
330
331 // [java_LocationWindow_deselectAllMapFeatures]
332 // Deselect all map features
333 locationWindow.deselectAllMapFeatures();
334 System.out.println("Deselected all map features");
335 // [java_LocationWindow_deselectAllMapFeatures]
336
337 // [java_LocationWindow_getSelectedMapFeatures_2]
338 // Verify all features are deselected
339 List<String> remainingFeatures = locationWindow.getSelectedMapFeatures();
340 System.out.println("Remaining selected features after deselect all: " + remainingFeatures.size() + " features");
341 // [java_LocationWindow_getSelectedMapFeatures_2]
342
343 // Test multiple feature selection and deselection
344 List<String> testFeatureIds = Arrays.asList("room_101", "office_205", "meeting_room_301", "cafe_401");
345
346 // Select multiple features
347 for (String featureId : testFeatureIds) {
348 boolean success = locationWindow.selectMapFeature(featureId);
349 System.out.println("Selected feature " + featureId + ": " + success);
350 }
351
352 // Check selected features
353 List<String> allSelected = locationWindow.getSelectedMapFeatures();
354 System.out.println("All selected features: " + allSelected.size() + " features");
355
356 // Deselect all at once
357 locationWindow.deselectAllMapFeatures();
358 System.out.println("Deselected all features at once");
359 }
360
365 System.out.println("--- applyLayerFilter Method ---");
366
367 if (locationWindow == null) {
368 System.out.println("LocationWindow not available yet");
369 return;
370 }
371
372 // [java_MapFilterCondition_constructor]
373 // Create filter condition: show only venues with category "Toilet" or "Cafe"
374 MapFilterCondition condition = new MapFilterCondition("category", Arrays.asList("Toilet", "Cafe"));
375 // [java_MapFilterCondition_constructor]
376
377 // [java_LocationWindow_applyLayerFilter]
378 // Apply filter to venues layer
379 List<MapFilterCondition> conditions = new ArrayList<>();
380 conditions.add(new MapFilterCondition("category", Arrays.asList("Toilet", "Cafe")));
381 locationWindow.applyLayerFilter("venues", conditions);
382 System.out.println("Applied layer filter: show venues with category Toilet or Cafe");
383 // [java_LocationWindow_applyLayerFilter]
384
385 // Reset filter (show all venues)
386 locationWindow.applyLayerFilter("venues", new ArrayList<>());
387 System.out.println("Reset layer filter: show all venues");
388 }
389
394 System.out.println("--- Zoom Properties ---");
395
396 if (locationWindow == null) {
397 System.out.println("LocationWindow not available yet");
398 return;
399 }
400
401 // [java_LocationWindow_getZoomFactor]
402 // Get current zoom factor
403 double currentZoom = locationWindow.getZoomFactor();
404 System.out.println("Current zoom factor: " + currentZoom);
405 // [java_LocationWindow_getZoomFactor]
406
407 // [java_LocationWindow_setZoomFactor]
408 // Set zoom factor
409 locationWindow.setZoomFactor(150.0);
410 System.out.println("Set zoom factor to 150.0");
411 // [java_LocationWindow_setZoomFactor]
412
413 // [java_LocationWindow_getMinZoomFactor]
414 // Get minimum zoom factor
415 double minZoomFactor = locationWindow.getMinZoomFactor();
416 System.out.println("Minimum zoom factor: " + minZoomFactor);
417 // [java_LocationWindow_getMinZoomFactor]
418
419 // [java_LocationWindow_setMinZoomFactor]
420 // Set minimum zoom factor
421 locationWindow.setMinZoomFactor(50.0);
422 System.out.println("Set minimum zoom factor to 50.0");
423 // [java_LocationWindow_setMinZoomFactor]
424
425 // [java_LocationWindow_getMaxZoomFactor]
426 // Get maximum zoom factor
427 double maxZoomFactor = locationWindow.getMaxZoomFactor();
428 System.out.println("Maximum zoom factor: " + maxZoomFactor);
429 // [java_LocationWindow_getMaxZoomFactor]
430
431 // [java_LocationWindow_setMaxZoomFactor]
432 // Set maximum zoom factor
433 locationWindow.setMaxZoomFactor(300.0);
434 System.out.println("Set maximum zoom factor to 300.0");
435 // [java_LocationWindow_setMaxZoomFactor]
436
437 // Test zoom factor changes
438 List<Double> testZoomFactors = Arrays.asList(100.0, 125.0, 150.0, 200.0, 250.0);
439 for (Double zoom : testZoomFactors) {
440 locationWindow.setZoomFactor(zoom);
441 System.out.println("Changed zoom factor to: " + locationWindow.getZoomFactor());
442 }
443
444 // Test zoom limits
445 System.out.println("Testing zoom limits...");
446 locationWindow.setZoomFactor(locationWindow.getMinZoomFactor());
447 System.out.println("Set to minimum zoom: " + locationWindow.getZoomFactor());
448
449 locationWindow.setZoomFactor(locationWindow.getMaxZoomFactor());
450 System.out.println("Set to maximum zoom: " + locationWindow.getZoomFactor());
451
452 // Reset to default
453 locationWindow.setZoomFactor(100.0);
454 System.out.println("Reset zoom factor to default: " + locationWindow.getZoomFactor());
455 }
456
460 public void runExample() {
461 System.out.println("=== LocationWindowCommon Example ===");
462
463 // Simulate LocationWindow initialization
464 try {
465 Thread.sleep(500);
466 } catch (InterruptedException e) {
467 Thread.currentThread().interrupt();
468 }
469
470 // TODO: User will implement LocationWindow initialization here
471 // locationWindow = getLocationWindow();
472
473 // Run demonstrations
475
476 System.out.println("=== Example completed ===");
477 }
478
482 public static void main(String[] args) {
484 example.runExample();
485 }
486}
487
488class DemoSublocationChangeListener implements SublocationChangeListener {
489 // [java_SublocationChangeListener_onActiveSublocationChanged]
490 @Override
491 public void onActiveSublocationChanged(int sublocationId) {
492 System.out.println("Active sublocation changed to: " + sublocationId);
493 }
494 // [java_SublocationChangeListener_onActiveSublocationChanged]
495}