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