Loading...
Searching...
No Matches
LocationWindowCommonExample.m
Go to the documentation of this file.
2#import <NCLocationWindow.h>
3#import <NCGlobalPoint.h>
4#import <NCScreenPoint.h>
5#import <NCBoundingBox.h>
6#import <NCCamera.h>
8#import <NCDebugFlag.h>
9
16
17@interface DemoSublocationChangeListener : NSObject <NCSublocationChangeListener>
18@end
19
20@implementation DemoSublocationChangeListener
21// [objc_SublocationChangeListener_onActiveSublocationChanged]
22- (void)onActiveSublocationChanged:(int32_t)sublocationId {
23 NSLog(@"Active sublocation changed to: %d", sublocationId);
24}
25// [objc_SublocationChangeListener_onActiveSublocationChanged]
26@end
27
28@implementation LocationWindowCommonExample {
29 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 demonstrateOperatingMode];
49 [self demonstrateSublocationQueries];
50 [self demonstrateSublocationChangeListener];
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
89
93- (void)demonstrateOperatingMode {
94 NSLog(@"--- Operating Mode ---");
95
96 if (_locationWindow == nil) {
97 NSLog(@"LocationWindow not available yet");
98 return;
99 }
100
101 // [objc_OperatingMode_enum]
102 NSArray<NSNumber *> *modes = @[@(NCOperatingModeIndoorOnly), @(NCOperatingModeOutdoor), @(NCOperatingModeOutdoorIndoor)];
103 NSLog(@"Operating modes: %lu", (unsigned long)modes.count);
104 // [objc_OperatingMode_enum]
105
106 // [objc_LocationWindow_setOperatingMode]
107 [_locationWindow setOperatingMode:NCOperatingModeOutdoorIndoor];
108 NSLog(@"Set operating mode to OUTDOOR_INDOOR");
109 // [objc_LocationWindow_setOperatingMode]
110
111 // [objc_LocationWindow_getOperatingMode]
112 NCOperatingMode currentMode = [_locationWindow getOperatingMode];
113 NSLog(@"Current operating mode: %ld", (long)currentMode);
114 // [objc_LocationWindow_getOperatingMode]
115
116 // [objc_AttributionAlignment_record]
118 initWithHorizontalAlignment:NCAttributionHorizontalAlignmentRight
119 verticalAlignment:NCAttributionVerticalAlignmentBottom];
120 // [objc_AttributionAlignment_record]
121
122 // [objc_LocationWindow_setAttributionAlignment]
123 [_locationWindow setAttributionAlignment:alignment];
124 // [objc_LocationWindow_setAttributionAlignment]
125
126 // [objc_LocationWindow_getAttribution]
127 NSString *attribution = [_locationWindow getAttribution];
128 NSLog(@"Attribution: %@", attribution);
129 // [objc_LocationWindow_getAttribution]
130}
131
135- (void)demonstrateSetSublocationId {
136 NSLog(@"--- setSublocationId Method ---");
137
138 if (_locationWindow == nil) {
139 NSLog(@"LocationWindow not available yet");
140 return;
141 }
142
143 // [objc_LocationWindow_setSublocationId]
144 // Set sublocation ID to switch between floors
145 [_locationWindow setSublocationId:1];
146 NSLog(@"Set sublocation ID to 1 (first floor)");
147 // [objc_LocationWindow_setSublocationId]
148
149 // [objc_LocationWindow_setSublocationId_2]
150 // Set sublocation ID to another floor
151 [_locationWindow setSublocationId:2];
152 NSLog(@"Set sublocation ID to 2 (second floor)");
153 // [objc_LocationWindow_setSublocationId_2]
154
155 // [objc_LocationWindow_setSublocationId_3]
156 // Set sublocation ID to ground floor
157 [_locationWindow setSublocationId:0];
158 NSLog(@"Set sublocation ID to 0 (ground floor)");
159 // [objc_LocationWindow_setSublocationId_3]
160
161 // Test with different sublocation IDs
162 NSArray<NSNumber *> *sublocationIds = @[@1, @2, @3, @0, @5];
163 for (NSNumber *idNumber in sublocationIds) {
164 [_locationWindow setSublocationId:idNumber.intValue];
165 NSLog(@"Switched to sublocation ID: %d", idNumber.intValue);
166 }
167}
168
172- (void)demonstrateSublocationQueries {
173 NSLog(@"--- getSublocationId & getEnclosingCamera ---");
174
175 if (_locationWindow == nil) {
176 NSLog(@"LocationWindow not available yet");
177 return;
178 }
179
180 // [objc_LocationWindow_getSublocationId]
181 NSNumber *currentId = [_locationWindow getSublocationId];
182 if (currentId != nil) {
183 NSLog(@"Current sublocation id: %@", currentId);
184 } else {
185 NSLog(@"Current sublocation id is not set");
186 }
187 // [objc_LocationWindow_getSublocationId]
188
189 // [objc_LocationWindow_getEnclosingCamera]
190 NCBoundingBox *boundingBox = [[NCBoundingBox alloc] initWithBottomLeft:[[NCGlobalPoint alloc] initWithLatitude:55.75 longitude:37.61]
191 topRight:[[NCGlobalPoint alloc] initWithLatitude:55.76 longitude:37.63]];
192 NCCamera *camera = [_locationWindow getEnclosingCamera:boundingBox];
193 NSLog(@"Camera that fits bounding box: %@", camera);
194 // [objc_LocationWindow_getEnclosingCamera]
195}
196
200- (void)demonstrateSublocationChangeListener {
201 NSLog(@"--- Sublocation Change Listener ---");
202
203 if (_locationWindow == nil) {
204 NSLog(@"LocationWindow not available yet");
205 return;
206 }
207
208 DemoSublocationChangeListener *listener = [[DemoSublocationChangeListener alloc] init];
209
210 // [objc_LocationWindow_addSublocationChangeListener]
211 [_locationWindow addSublocationChangeListener:listener];
212 NSLog(@"Added sublocation change listener");
213 // [objc_LocationWindow_addSublocationChangeListener]
214
215 [_locationWindow setSublocationId:1];
216 [_locationWindow setSublocationId:2];
217
218 // [objc_LocationWindow_removeSublocationChangeListener]
219 [_locationWindow removeSublocationChangeListener:listener];
220 NSLog(@"Removed sublocation change listener");
221 // [objc_LocationWindow_removeSublocationChangeListener]
222}
223
227- (void)demonstrateUserLocationLayer {
228 NSLog(@"--- UserLocationLayer ---");
229
230 if (_userLocationLayer == nil) {
231 NSLog(@"UserLocationLayer not available yet");
232 return;
233 }
234
235 // [objc_UserLocationLayer_setVisible]
237 NSLog(@"User location layer set visible");
238 // [objc_UserLocationLayer_setVisible]
239
240 // [objc_UserLocationLayer_isVisible]
241 BOOL visible = [_userLocationLayer isVisible];
242 NSLog(@"User location layer is visible: %@", visible ? @"YES" : @"NO");
243 // [objc_UserLocationLayer_isVisible]
244
245 // [objc_UserLocationLayer_setAnchor]
246 NCScreenPoint *anchor = [[NCScreenPoint alloc] initWithX:100.0f y:200.0f];
248 NSLog(@"Set user location anchor to: (%.1f, %.1f)", anchor.x, anchor.y);
249 // [objc_UserLocationLayer_setAnchor]
250
251 // [objc_UserLocationLayer_anchorEnabled]
252 BOOL anchorEnabled = [_userLocationLayer anchorEnabled];
253 NSLog(@"Anchor enabled: %@", anchorEnabled ? @"YES" : @"NO");
254 // [objc_UserLocationLayer_anchorEnabled]
255
256 // [objc_UserLocationLayer_resetAnchor]
258 NSLog(@"Anchor reset to default");
259 // [objc_UserLocationLayer_resetAnchor]
260}
261
265- (void)demonstrateCoordinateConversion {
266 NSLog(@"--- Coordinate Conversion Methods ---");
267
268 if (_locationWindow == nil) {
269 NSLog(@"LocationWindow not available yet");
270 return;
271 }
272
273 // [objc_LocationWindow_screenPositionToGlobal]
274 NCScreenPoint *screenPoint = [[NCScreenPoint alloc] initWithX:100.0 y:200.0];
275 NCGlobalPoint *globalPoint = [_locationWindow screenPositionToGlobal:screenPoint];
276 NSLog(@"Screen position (%.1f, %.1f) converted to WGS84: (%.6f, %.6f)",
277 screenPoint.x, screenPoint.y, globalPoint.latitude, globalPoint.longitude);
278 // [objc_LocationWindow_screenPositionToGlobal]
279
280 // [objc_LocationWindow_globalToScreenPosition]
281 NCGlobalPoint *globalPoint2 = [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176];
282 NCScreenPoint *screenPoint2 = [_locationWindow globalToScreenPosition:globalPoint2 clipToViewport:YES];
283 NSLog(@"WGS84 (%.6f, %.6f) converted to screen with clipping: (%.1f, %.1f)",
284 globalPoint2.latitude, globalPoint2.longitude, screenPoint2.x, screenPoint2.y);
285 // [objc_LocationWindow_globalToScreenPosition]
286
287 NSArray<NCScreenPoint *> *testScreenPoints = @[
288 [[NCScreenPoint alloc] initWithX:0.0 y:0.0],
289 [[NCScreenPoint alloc] initWithX:250.0 y:250.0],
290 [[NCScreenPoint alloc] initWithX:1000.0 y:600.0]
291 ];
292
293 for (int i = 0; i < testScreenPoints.count; i++) {
294 NCScreenPoint *sp = testScreenPoints[i];
295 NCGlobalPoint *gp = [_locationWindow screenPositionToGlobal:sp];
296 NCScreenPoint *backToScreen = [_locationWindow globalToScreenPosition:gp clipToViewport:NO];
297 NSLog(@"Test %d: Screen (%.1f, %.1f) -> WGS84 (%.6f, %.6f) -> Screen (%.1f, %.1f)",
298 i, sp.x, sp.y, gp.latitude, gp.longitude, 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}