Loading...
Searching...
No Matches
LocationWindowCommonExample.m
Go to the documentation of this file.
2#import <NCLocationWindow.h>
3#import <NCPoint.h>
4#import <NCBoundingBox.h>
5#import <NCCamera.h>
7#import <NCDebugFlag.h>
8
15
16@interface DemoSublocationChangeListener : NSObject <NCSublocationChangeListener>
17@end
18
19@implementation DemoSublocationChangeListener
20// [objc_SublocationChangeListener_onActiveSublocationChanged]
21- (void)onActiveSublocationChanged:(int32_t)sublocationId {
22 NSLog(@"Active sublocation changed to: %d", sublocationId);
23}
24// [objc_SublocationChangeListener_onActiveSublocationChanged]
25@end
26
27@implementation LocationWindowCommonExample {
28 NCLocationWindow *_locationWindow;
31}
32
33- (instancetype)init {
34 self = [super init];
35 if (self) {
37 }
38 return self;
39}
40
45 NSLog(@"=== LocationWindowCommon Methods ===");
46
47 [self demonstrateSetSublocationId];
48 [self demonstrateSublocationQueries];
49 [self demonstrateSublocationChangeListener];
50 [self demonstrateUserLocationView];
51 [self demonstrateUserLocationLayer];
52 [self demonstrateCoordinateConversion];
53 [self demonstrateMapFeatureSelection];
54 [self demonstrateApplyLayerFilter];
55 [self demonstrateDebugFlags];
56 [self demonstrateZoomProperties];
57}
58
62- (void)demonstrateDebugFlags {
63 NSLog(@"--- Debug flags ---");
64
65 // [objc_DebugFlag_enum]
66 NSArray<NSNumber *> *allFlags = @[
67 @(NCDebugFlagNone),
68 @(NCDebugFlagInfos),
69 @(NCDebugFlagStats),
70 @(NCDebugFlagLabels),
71 @(NCDebugFlagDrawAllLabels),
72 @(NCDebugFlagSelectionBuffer)
73 ];
74 NSLog(@"Debug flag enum values: %lu", (unsigned long)allFlags.count);
75 // [objc_DebugFlag_enum]
76
77 // [objc_LocationWindow_setDebugFlag]
78 [NCLocationWindow setDebugFlag:NCDebugFlagInfos on:YES];
79 [NCLocationWindow setDebugFlag:NCDebugFlagStats on:NO];
80 NSLog(@"Updated debug flags on LocationWindow");
81 // [objc_LocationWindow_setDebugFlag]
82
83 // [objc_LocationWindow_getDebugFlag]
84 BOOL infosOn = [NCLocationWindow getDebugFlag:NCDebugFlagInfos];
85 NSLog(@"Debug flag INFOS enabled: %@", infosOn ? @"YES" : @"NO");
86 // [objc_LocationWindow_getDebugFlag]
87}
88
92- (void)demonstrateSetSublocationId {
93 NSLog(@"--- setSublocationId Method ---");
94
95 if (_locationWindow == nil) {
96 NSLog(@"LocationWindow not available yet");
97 return;
98 }
99
100 // [objc_LocationWindow_setSublocationId]
101 // Set sublocation ID to switch between floors
102 [_locationWindow setSublocationId:1];
103 NSLog(@"Set sublocation ID to 1 (first floor)");
104 // [objc_LocationWindow_setSublocationId]
105
106 // [objc_LocationWindow_setSublocationId_2]
107 // Set sublocation ID to another floor
108 [_locationWindow setSublocationId:2];
109 NSLog(@"Set sublocation ID to 2 (second floor)");
110 // [objc_LocationWindow_setSublocationId_2]
111
112 // [objc_LocationWindow_setSublocationId_3]
113 // Set sublocation ID to ground floor
114 [_locationWindow setSublocationId:0];
115 NSLog(@"Set sublocation ID to 0 (ground floor)");
116 // [objc_LocationWindow_setSublocationId_3]
117
118 // Test with different sublocation IDs
119 NSArray<NSNumber *> *sublocationIds = @[@1, @2, @3, @0, @5];
120 for (NSNumber *idNumber in sublocationIds) {
121 [_locationWindow setSublocationId:idNumber.intValue];
122 NSLog(@"Switched to sublocation ID: %d", idNumber.intValue);
123 }
124}
125
129- (void)demonstrateSublocationQueries {
130 NSLog(@"--- getSublocationId & getEnclosingCamera ---");
131
132 if (_locationWindow == nil) {
133 NSLog(@"LocationWindow not available yet");
134 return;
135 }
136
137 // [objc_LocationWindow_getSublocationId]
138 NSNumber *currentId = [_locationWindow getSublocationId];
139 if (currentId != nil) {
140 NSLog(@"Current sublocation id: %@", currentId);
141 } else {
142 NSLog(@"Current sublocation id is not set");
143 }
144 // [objc_LocationWindow_getSublocationId]
145
146 // [objc_LocationWindow_getEnclosingCamera]
147 NCBoundingBox *boundingBox = [[NCBoundingBox alloc] initWithBottomLeft:[[NCPoint alloc] initWithX:0.0 y:0.0]
148 topRight:[[NCPoint alloc] initWithX:20.0 y:30.0]];
149 NCCamera *camera = [_locationWindow getEnclosingCamera:boundingBox];
150 NSLog(@"Camera that fits bounding box: %@", camera);
151 // [objc_LocationWindow_getEnclosingCamera]
152}
153
157- (void)demonstrateSublocationChangeListener {
158 NSLog(@"--- Sublocation Change Listener ---");
159
160 if (_locationWindow == nil) {
161 NSLog(@"LocationWindow not available yet");
162 return;
163 }
164
165 DemoSublocationChangeListener *listener = [[DemoSublocationChangeListener alloc] init];
166
167 // [objc_LocationWindow_addSublocationChangeListener]
168 [_locationWindow addSublocationChangeListener:listener];
169 NSLog(@"Added sublocation change listener");
170 // [objc_LocationWindow_addSublocationChangeListener]
171
172 [_locationWindow setSublocationId:1];
173 [_locationWindow setSublocationId:2];
174
175 // [objc_LocationWindow_removeSublocationChangeListener]
176 [_locationWindow removeSublocationChangeListener:listener];
177 NSLog(@"Removed sublocation change listener");
178 // [objc_LocationWindow_removeSublocationChangeListener]
179}
180
184- (void)demonstrateUserLocationView {
185 NSLog(@"--- UserLocationView ---");
186
187 if (_userLocationView == nil) {
188 NSLog(@"UserLocationView not available yet");
189 return;
190 }
191
192 // [objc_UserLocationView_getArrow]
194 NSLog(@"Arrow icon object: %@", arrow);
195 // [objc_UserLocationView_getArrow]
196
197 // [objc_UserLocationView_getAccuracyCircle]
199 NSLog(@"Accuracy circle object: %@", accuracyCircle);
200 // [objc_UserLocationView_getAccuracyCircle]
201}
202
206- (void)demonstrateUserLocationLayer {
207 NSLog(@"--- UserLocationLayer ---");
208
209 if (_userLocationLayer == nil) {
210 NSLog(@"UserLocationLayer not available yet");
211 return;
212 }
213
214 // [objc_UserLocationLayer_setVisible]
216 NSLog(@"User location layer set visible");
217 // [objc_UserLocationLayer_setVisible]
218
219 // [objc_UserLocationLayer_isVisible]
220 BOOL visible = [_userLocationLayer isVisible];
221 NSLog(@"User location layer is visible: %@", visible ? @"YES" : @"NO");
222 // [objc_UserLocationLayer_isVisible]
223
224 // [objc_UserLocationLayer_setAnchor]
225 NCScreenPoint *anchor = [[NCScreenPoint alloc] initWithX:100.0f y:200.0f];
227 NSLog(@"Set user location anchor to: (%.1f, %.1f)", anchor.x, anchor.y);
228 // [objc_UserLocationLayer_setAnchor]
229
230 // [objc_UserLocationLayer_anchorEnabled]
231 BOOL anchorEnabled = [_userLocationLayer anchorEnabled];
232 NSLog(@"Anchor enabled: %@", anchorEnabled ? @"YES" : @"NO");
233 // [objc_UserLocationLayer_anchorEnabled]
234
235 // [objc_UserLocationLayer_resetAnchor]
237 NSLog(@"Anchor reset to default");
238 // [objc_UserLocationLayer_resetAnchor]
239}
240
244- (void)demonstrateCoordinateConversion {
245 NSLog(@"--- Coordinate Conversion Methods ---");
246
247 if (_locationWindow == nil) {
248 NSLog(@"LocationWindow not available yet");
249 return;
250 }
251
252 // [objc_LocationWindow_screenPositionToMeters]
253 // Convert screen position to meters
254 NCPoint *screenPoint = [[NCPoint alloc] initWithX:100.0 y:200.0];
255 NCPoint *metersPoint = [_locationWindow screenPositionToMeters:screenPoint];
256 NSLog(@"Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)",
257 screenPoint.x, screenPoint.y, metersPoint.x, metersPoint.y);
258 // [objc_LocationWindow_screenPositionToMeters]
259
260 // [objc_LocationWindow_screenPositionToMeters_2]
261 // Convert another screen position to meters
262 NCPoint *screenPoint2 = [[NCPoint alloc] initWithX:500.0 y:300.0];
263 NCPoint *metersPoint2 = [_locationWindow screenPositionToMeters:screenPoint2];
264 NSLog(@"Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)",
265 screenPoint2.x, screenPoint2.y, metersPoint2.x, metersPoint2.y);
266 // [objc_LocationWindow_screenPositionToMeters_2]
267
268 // [objc_LocationWindow_metersToScreenPosition]
269 // Convert meters to screen position with clipping
270 NCPoint *metersPoint3 = [[NCPoint alloc] initWithX:50.0 y:75.0];
271 NCPoint *screenPoint3 = [_locationWindow metersToScreenPosition:metersPoint3 clipToViewport:YES];
272 NSLog(@"Meters position (%.1f, %.1f) converted to screen with clipping: (%.1f, %.1f)",
273 metersPoint3.x, metersPoint3.y, screenPoint3.x, screenPoint3.y);
274 // [objc_LocationWindow_metersToScreenPosition]
275
276 // [objc_LocationWindow_metersToScreenPosition_2]
277 // Convert meters to screen position without clipping
278 NCPoint *metersPoint4 = [[NCPoint alloc] initWithX:150.0 y:200.0];
279 NCPoint *screenPoint4 = [_locationWindow metersToScreenPosition:metersPoint4 clipToViewport:NO];
280 NSLog(@"Meters position (%.1f, %.1f) converted to screen without clipping: (%.1f, %.1f)",
281 metersPoint4.x, metersPoint4.y, screenPoint4.x, screenPoint4.y);
282 // [objc_LocationWindow_metersToScreenPosition_2]
283
284 // Test coordinate conversion with different values
285 NSArray<NCPoint *> *testScreenPoints = @[
286 [[NCPoint alloc] initWithX:0.0 y:0.0],
287 [[NCPoint alloc] initWithX:250.0 y:250.0],
288 [[NCPoint alloc] initWithX:1000.0 y:600.0]
289 ];
290
291 for (int i = 0; i < testScreenPoints.count; i++) {
292 NCPoint *screenPoint = testScreenPoints[i];
293 NCPoint *metersPoint = [_locationWindow screenPositionToMeters:screenPoint];
294 NCPoint *backToScreen = [_locationWindow metersToScreenPosition:metersPoint clipToViewport:NO];
295 NSLog(@"Test %d: Screen (%.1f, %.1f) -> Meters (%.1f, %.1f) -> Screen (%.1f, %.1f)",
296 i, screenPoint.x, screenPoint.y,
297 metersPoint.x, metersPoint.y,
298 backToScreen.x, backToScreen.y);
299 }
300}
301
305- (void)demonstrateMapFeatureSelection {
306 NSLog(@"--- Map Feature Selection Methods ---");
307
308 if (_locationWindow == nil) {
309 NSLog(@"LocationWindow not available yet");
310 return;
311 }
312
313 // [objc_LocationWindow_selectMapFeature]
314 // Select map feature by ID
315 NSString *featureId = "room_101";
316 BOOL selected = [_locationWindow selectMapFeature:featureId];
317 NSLog(@"Selected map feature %@: %@", featureId, selected ? @"YES" : @"NO");
318 // [objc_LocationWindow_selectMapFeature]
319
320 // [objc_LocationWindow_selectMapFeature_2]
321 // Select another map feature
322 NSString *featureId2 = "office_205";
323 BOOL selected2 = [_locationWindow selectMapFeature:featureId2];
324 NSLog(@"Selected map feature %@: %@", featureId2, selected2 ? @"YES" : @"NO");
325 // [objc_LocationWindow_selectMapFeature_2]
326
327 // [objc_LocationWindow_getSelectedMapFeatures]
328 // Get list of selected map features
329 NSArray<NSString *> *selectedFeatures = [_locationWindow selectedMapFeatures];
330 NSLog(@"Currently selected map features: %lu features", (unsigned long)selectedFeatures.count);
331 for (NSString *feature in selectedFeatures) {
332 NSLog(@" - %@", feature);
333 }
334 // [objc_LocationWindow_getSelectedMapFeatures]
335
336 // [objc_LocationWindow_deselectMapFeature]
337 // Deselect specific map feature
338 BOOL deselected = [_locationWindow deselectMapFeature:featureId];
339 NSLog(@"Deselected map feature %@: %@", featureId, deselected ? @"YES" : @"NO");
340 // [objc_LocationWindow_deselectMapFeature]
341
342 // [objc_LocationWindow_deselectMapFeature_2]
343 // Deselect another map feature
344 BOOL deselected2 = [_locationWindow deselectMapFeature:featureId2];
345 NSLog(@"Deselected map feature %@: %@", featureId2, deselected2 ? @"YES" : @"NO");
346 // [objc_LocationWindow_deselectMapFeature_2]
347
348 // [objc_LocationWindow_deselectAllMapFeatures]
349 // Deselect all map features
350 [_locationWindow deselectAllMapFeatures];
351 NSLog(@"Deselected all map features");
352 // [objc_LocationWindow_deselectAllMapFeatures]
353
354 // [objc_LocationWindow_getSelectedMapFeatures_2]
355 // Verify all features are deselected
356 NSArray<NSString *> *remainingFeatures = [_locationWindow selectedMapFeatures];
357 NSLog(@"Remaining selected features after deselect all: %lu features", (unsigned long)remainingFeatures.count);
358 // [objc_LocationWindow_getSelectedMapFeatures_2]
359
360 // Test multiple feature selection and deselection
361 NSArray<NSString *> *testFeatureIds = @[@"room_101", @"office_205", @"meeting_room_301", @"cafe_401"];
362
363 // Select multiple features
364 for (NSString *featureId in testFeatureIds) {
365 BOOL success = [_locationWindow selectMapFeature:featureId];
366 NSLog(@"Selected feature %@: %@", featureId, success ? @"YES" : @"NO");
367 }
368
369 // Check selected features
370 NSArray<NSString *> *allSelected = [_locationWindow selectedMapFeatures];
371 NSLog(@"All selected features: %lu features", (unsigned long)allSelected.count);
372
373 // Deselect all at once
374 [_locationWindow deselectAllMapFeatures];
375 NSLog(@"Deselected all features at once");
376}
377
381- (void)demonstrateApplyLayerFilter {
382 NSLog(@"--- applyLayerFilter Method ---");
383
384 if (_locationWindow == nil) {
385 NSLog(@"LocationWindow not available yet");
386 return;
387 }
388
389 // [objc_MapFilterCondition_constructor]
390 // Create filter condition: show only venues with category "Toilet" or "Cafe"
391 NCMapFilterCondition *condition = [[NCMapFilterCondition alloc] initWithProperty:@"category" values:@[@"Toilet", @"Cafe"]];
392 // [objc_MapFilterCondition_constructor]
393
394 // [objc_LocationWindow_applyLayerFilter]
395 // Apply filter to venues layer
396 NSArray<NCMapFilterCondition *> *conditions = @[[[NCMapFilterCondition alloc] initWithProperty:@"category" values:@[@"Toilet", @"Cafe"]]];
397 [_locationWindow applyLayerFilterWithLayer:@"venues" conditions:conditions];
398 NSLog(@"Applied layer filter: show venues with category Toilet or Cafe");
399 // [objc_LocationWindow_applyLayerFilter]
400
401 // Reset filter (show all venues)
402 [_locationWindow applyLayerFilterWithLayer:@"venues" conditions:@[]];
403 NSLog(@"Reset layer filter: show all venues");
404}
405
409- (void)demonstrateZoomProperties {
410 NSLog(@"--- Zoom Properties ---");
411
412 if (_locationWindow == nil) {
413 NSLog(@"LocationWindow not available yet");
414 return;
415 }
416
417 // [objc_LocationWindow_getZoomFactor]
418 // Get current zoom factor
419 double currentZoom = [_locationWindow zoomFactor];
420 NSLog(@"Current zoom factor: %.1f", currentZoom);
421 // [objc_LocationWindow_getZoomFactor]
422
423 // [objc_LocationWindow_setZoomFactor]
424 // Set zoom factor
425 [_locationWindow setZoomFactor:150.0];
426 NSLog(@"Set zoom factor to 150.0");
427 // [objc_LocationWindow_setZoomFactor]
428
429 // [objc_LocationWindow_getMinZoomFactor]
430 // Get minimum zoom factor
431 double minZoomFactor = [_locationWindow minZoomFactor];
432 NSLog(@"Minimum zoom factor: %.1f", minZoomFactor);
433 // [objc_LocationWindow_getMinZoomFactor]
434
435 // [objc_LocationWindow_setMinZoomFactor]
436 // Set minimum zoom factor
437 [_locationWindow setMinZoomFactor:50.0];
438 NSLog(@"Set minimum zoom factor to 50.0");
439 // [objc_LocationWindow_setMinZoomFactor]
440
441 // [objc_LocationWindow_getMaxZoomFactor]
442 // Get maximum zoom factor
443 double maxZoomFactor = [_locationWindow maxZoomFactor];
444 NSLog(@"Maximum zoom factor: %.1f", maxZoomFactor);
445 // [objc_LocationWindow_getMaxZoomFactor]
446
447 // [objc_LocationWindow_setMaxZoomFactor]
448 // Set maximum zoom factor
449 [_locationWindow setMaxZoomFactor:300.0];
450 NSLog(@"Set maximum zoom factor to 300.0");
451 // [objc_LocationWindow_setMaxZoomFactor]
452
453 // Test zoom factor changes
454 NSArray<NSNumber *> *testZoomFactors = @[@100.0, @125.0, @150.0, @200.0, @250.0];
455 for (NSNumber *zoom in testZoomFactors) {
456 [_locationWindow setZoomFactor:zoom.doubleValue];
457 NSLog(@"Changed zoom factor to: %.1f", [_locationWindow zoomFactor]);
458 }
459
460 // Test zoom limits
461 NSLog(@"Testing zoom limits...");
462 [_locationWindow setZoomFactor:[_locationWindow minZoomFactor]];
463 NSLog(@"Set to minimum zoom: %.1f", [_locationWindow zoomFactor]);
464
465 [_locationWindow setZoomFactor:[_locationWindow maxZoomFactor]];
466 NSLog(@"Set to maximum zoom: %.1f", [_locationWindow zoomFactor]);
467
468 // Reset to default
469 [_locationWindow setZoomFactor:100.0];
470 NSLog(@"Reset zoom factor to default: %.1f", [_locationWindow zoomFactor]);
471}
472
476- (void)runExample {
477 NSLog(@"=== LocationWindowCommon Example ===");
478
479 // Simulate LocationWindow initialization
480 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
481 // TODO: User will implement LocationWindow initialization here
482 // self->_locationWindow = [self getLocationWindow];
483
484 // Run demonstrations
485 [self demonstrateLocationWindowCommonMethods];
486
487 NSLog(@"=== Example completed ===");
488 });
489}
490
491@end
492
496int main(int argc, const char * argv[]) {
497 @autoreleasepool {
499 [example runExample];
500
501 // Keep the program running for a bit to see the output
502 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
503 }
504 return 0;
505}