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