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
14
15@interface DemoSublocationChangeListener : NSObject <NCSublocationChangeListener>
16@end
17
18@implementation DemoSublocationChangeListener
19// [objc_SublocationChangeListener_onActiveSublocationChanged]
20- (void)onActiveSublocationChanged:(int32_t)sublocationId {
21 NSLog(@"Active sublocation changed to: %d", sublocationId);
22}
23// [objc_SublocationChangeListener_onActiveSublocationChanged]
24@end
25
26@implementation LocationWindowCommonExample {
27 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 demonstrateUserLocationView];
50 [self demonstrateUserLocationLayer];
51 [self demonstrateCoordinateConversion];
52 [self demonstrateMapFeatureSelection];
53 [self demonstrateZoomProperties];
54}
55
59- (void)demonstrateSetSublocationId {
60 NSLog(@"--- setSublocationId Method ---");
61
62 if (_locationWindow == nil) {
63 NSLog(@"LocationWindow not available yet");
64 return;
65 }
66
67 // [objc_LocationWindow_setSublocationId]
68 // Set sublocation ID to switch between floors
69 [_locationWindow setSublocationId:1];
70 NSLog(@"Set sublocation ID to 1 (first floor)");
71 // [objc_LocationWindow_setSublocationId]
72
73 // [objc_LocationWindow_setSublocationId_2]
74 // Set sublocation ID to another floor
75 [_locationWindow setSublocationId:2];
76 NSLog(@"Set sublocation ID to 2 (second floor)");
77 // [objc_LocationWindow_setSublocationId_2]
78
79 // [objc_LocationWindow_setSublocationId_3]
80 // Set sublocation ID to ground floor
81 [_locationWindow setSublocationId:0];
82 NSLog(@"Set sublocation ID to 0 (ground floor)");
83 // [objc_LocationWindow_setSublocationId_3]
84
85 // Test with different sublocation IDs
86 NSArray<NSNumber *> *sublocationIds = @[@1, @2, @3, @0, @5];
87 for (NSNumber *idNumber in sublocationIds) {
88 [_locationWindow setSublocationId:idNumber.intValue];
89 NSLog(@"Switched to sublocation ID: %d", idNumber.intValue);
90 }
91}
92
96- (void)demonstrateSublocationQueries {
97 NSLog(@"--- getSublocationId & getEnclosingCamera ---");
98
99 if (_locationWindow == nil) {
100 NSLog(@"LocationWindow not available yet");
101 return;
102 }
103
104 // [objc_LocationWindow_getSublocationId]
105 NSNumber *currentId = [_locationWindow getSublocationId];
106 if (currentId != nil) {
107 NSLog(@"Current sublocation id: %@", currentId);
108 } else {
109 NSLog(@"Current sublocation id is not set");
110 }
111 // [objc_LocationWindow_getSublocationId]
112
113 // [objc_LocationWindow_getEnclosingCamera]
114 NCBoundingBox *boundingBox = [[NCBoundingBox alloc] initWithBottomLeft:[[NCPoint alloc] initWithX:0.0 y:0.0]
115 topRight:[[NCPoint alloc] initWithX:20.0 y:30.0]];
116 NCCamera *camera = [_locationWindow getEnclosingCamera:boundingBox];
117 NSLog(@"Camera that fits bounding box: %@", camera);
118 // [objc_LocationWindow_getEnclosingCamera]
119}
120
124- (void)demonstrateSublocationChangeListener {
125 NSLog(@"--- Sublocation Change Listener ---");
126
127 if (_locationWindow == nil) {
128 NSLog(@"LocationWindow not available yet");
129 return;
130 }
131
132 DemoSublocationChangeListener *listener = [[DemoSublocationChangeListener alloc] init];
133
134 // [objc_LocationWindow_addSublocationChangeListener]
135 [_locationWindow addSublocationChangeListener:listener];
136 NSLog(@"Added sublocation change listener");
137 // [objc_LocationWindow_addSublocationChangeListener]
138
139 [_locationWindow setSublocationId:1];
140 [_locationWindow setSublocationId:2];
141
142 // [objc_LocationWindow_removeSublocationChangeListener]
143 [_locationWindow removeSublocationChangeListener:listener];
144 NSLog(@"Removed sublocation change listener");
145 // [objc_LocationWindow_removeSublocationChangeListener]
146}
147
151- (void)demonstrateUserLocationView {
152 NSLog(@"--- UserLocationView ---");
153
154 if (_userLocationView == nil) {
155 NSLog(@"UserLocationView not available yet");
156 return;
157 }
158
159 // [objc_UserLocationView_getArrow]
161 NSLog(@"Arrow icon object: %@", arrow);
162 // [objc_UserLocationView_getArrow]
163
164 // [objc_UserLocationView_getAccuracyCircle]
166 NSLog(@"Accuracy circle object: %@", accuracyCircle);
167 // [objc_UserLocationView_getAccuracyCircle]
168}
169
173- (void)demonstrateUserLocationLayer {
174 NSLog(@"--- UserLocationLayer ---");
175
176 if (_userLocationLayer == nil) {
177 NSLog(@"UserLocationLayer not available yet");
178 return;
179 }
180
181 // [objc_UserLocationLayer_setVisible]
183 NSLog(@"User location layer set visible");
184 // [objc_UserLocationLayer_setVisible]
185
186 // [objc_UserLocationLayer_isVisible]
187 BOOL visible = [_userLocationLayer isVisible];
188 NSLog(@"User location layer is visible: %@", visible ? @"YES" : @"NO");
189 // [objc_UserLocationLayer_isVisible]
190
191 // [objc_UserLocationLayer_setAnchor]
192 NCScreenPoint *anchor = [[NCScreenPoint alloc] initWithX:100.0f y:200.0f];
194 NSLog(@"Set user location anchor to: (%.1f, %.1f)", anchor.x, anchor.y);
195 // [objc_UserLocationLayer_setAnchor]
196
197 // [objc_UserLocationLayer_anchorEnabled]
198 BOOL anchorEnabled = [_userLocationLayer anchorEnabled];
199 NSLog(@"Anchor enabled: %@", anchorEnabled ? @"YES" : @"NO");
200 // [objc_UserLocationLayer_anchorEnabled]
201
202 // [objc_UserLocationLayer_resetAnchor]
204 NSLog(@"Anchor reset to default");
205 // [objc_UserLocationLayer_resetAnchor]
206}
207
211- (void)demonstrateCoordinateConversion {
212 NSLog(@"--- Coordinate Conversion Methods ---");
213
214 if (_locationWindow == nil) {
215 NSLog(@"LocationWindow not available yet");
216 return;
217 }
218
219 // [objc_LocationWindow_screenPositionToMeters]
220 // Convert screen position to meters
221 NCPoint *screenPoint = [[NCPoint alloc] initWithX:100.0 y:200.0];
222 NCPoint *metersPoint = [_locationWindow screenPositionToMeters:screenPoint];
223 NSLog(@"Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)",
224 screenPoint.x, screenPoint.y, metersPoint.x, metersPoint.y);
225 // [objc_LocationWindow_screenPositionToMeters]
226
227 // [objc_LocationWindow_screenPositionToMeters_2]
228 // Convert another screen position to meters
229 NCPoint *screenPoint2 = [[NCPoint alloc] initWithX:500.0 y:300.0];
230 NCPoint *metersPoint2 = [_locationWindow screenPositionToMeters:screenPoint2];
231 NSLog(@"Screen position (%.1f, %.1f) converted to meters: (%.1f, %.1f)",
232 screenPoint2.x, screenPoint2.y, metersPoint2.x, metersPoint2.y);
233 // [objc_LocationWindow_screenPositionToMeters_2]
234
235 // [objc_LocationWindow_metersToScreenPosition]
236 // Convert meters to screen position with clipping
237 NCPoint *metersPoint3 = [[NCPoint alloc] initWithX:50.0 y:75.0];
238 NCPoint *screenPoint3 = [_locationWindow metersToScreenPosition:metersPoint3 clipToViewport:YES];
239 NSLog(@"Meters position (%.1f, %.1f) converted to screen with clipping: (%.1f, %.1f)",
240 metersPoint3.x, metersPoint3.y, screenPoint3.x, screenPoint3.y);
241 // [objc_LocationWindow_metersToScreenPosition]
242
243 // [objc_LocationWindow_metersToScreenPosition_2]
244 // Convert meters to screen position without clipping
245 NCPoint *metersPoint4 = [[NCPoint alloc] initWithX:150.0 y:200.0];
246 NCPoint *screenPoint4 = [_locationWindow metersToScreenPosition:metersPoint4 clipToViewport:NO];
247 NSLog(@"Meters position (%.1f, %.1f) converted to screen without clipping: (%.1f, %.1f)",
248 metersPoint4.x, metersPoint4.y, screenPoint4.x, screenPoint4.y);
249 // [objc_LocationWindow_metersToScreenPosition_2]
250
251 // Test coordinate conversion with different values
252 NSArray<NCPoint *> *testScreenPoints = @[
253 [[NCPoint alloc] initWithX:0.0 y:0.0],
254 [[NCPoint alloc] initWithX:250.0 y:250.0],
255 [[NCPoint alloc] initWithX:1000.0 y:600.0]
256 ];
257
258 for (int i = 0; i < testScreenPoints.count; i++) {
259 NCPoint *screenPoint = testScreenPoints[i];
260 NCPoint *metersPoint = [_locationWindow screenPositionToMeters:screenPoint];
261 NCPoint *backToScreen = [_locationWindow metersToScreenPosition:metersPoint clipToViewport:NO];
262 NSLog(@"Test %d: Screen (%.1f, %.1f) -> Meters (%.1f, %.1f) -> Screen (%.1f, %.1f)",
263 i, screenPoint.x, screenPoint.y,
264 metersPoint.x, metersPoint.y,
265 backToScreen.x, backToScreen.y);
266 }
267}
268
272- (void)demonstrateMapFeatureSelection {
273 NSLog(@"--- Map Feature Selection Methods ---");
274
275 if (_locationWindow == nil) {
276 NSLog(@"LocationWindow not available yet");
277 return;
278 }
279
280 // [objc_LocationWindow_selectMapFeature]
281 // Select map feature by ID
282 NSString *featureId = "room_101";
283 BOOL selected = [_locationWindow selectMapFeature:featureId];
284 NSLog(@"Selected map feature %@: %@", featureId, selected ? @"YES" : @"NO");
285 // [objc_LocationWindow_selectMapFeature]
286
287 // [objc_LocationWindow_selectMapFeature_2]
288 // Select another map feature
289 NSString *featureId2 = "office_205";
290 BOOL selected2 = [_locationWindow selectMapFeature:featureId2];
291 NSLog(@"Selected map feature %@: %@", featureId2, selected2 ? @"YES" : @"NO");
292 // [objc_LocationWindow_selectMapFeature_2]
293
294 // [objc_LocationWindow_getSelectedMapFeatures]
295 // Get list of selected map features
296 NSArray<NSString *> *selectedFeatures = [_locationWindow selectedMapFeatures];
297 NSLog(@"Currently selected map features: %lu features", (unsigned long)selectedFeatures.count);
298 for (NSString *feature in selectedFeatures) {
299 NSLog(@" - %@", feature);
300 }
301 // [objc_LocationWindow_getSelectedMapFeatures]
302
303 // [objc_LocationWindow_deselectMapFeature]
304 // Deselect specific map feature
305 BOOL deselected = [_locationWindow deselectMapFeature:featureId];
306 NSLog(@"Deselected map feature %@: %@", featureId, deselected ? @"YES" : @"NO");
307 // [objc_LocationWindow_deselectMapFeature]
308
309 // [objc_LocationWindow_deselectMapFeature_2]
310 // Deselect another map feature
311 BOOL deselected2 = [_locationWindow deselectMapFeature:featureId2];
312 NSLog(@"Deselected map feature %@: %@", featureId2, deselected2 ? @"YES" : @"NO");
313 // [objc_LocationWindow_deselectMapFeature_2]
314
315 // [objc_LocationWindow_deselectAllMapFeatures]
316 // Deselect all map features
317 [_locationWindow deselectAllMapFeatures];
318 NSLog(@"Deselected all map features");
319 // [objc_LocationWindow_deselectAllMapFeatures]
320
321 // [objc_LocationWindow_getSelectedMapFeatures_2]
322 // Verify all features are deselected
323 NSArray<NSString *> *remainingFeatures = [_locationWindow selectedMapFeatures];
324 NSLog(@"Remaining selected features after deselect all: %lu features", (unsigned long)remainingFeatures.count);
325 // [objc_LocationWindow_getSelectedMapFeatures_2]
326
327 // Test multiple feature selection and deselection
328 NSArray<NSString *> *testFeatureIds = @[@"room_101", @"office_205", @"meeting_room_301", @"cafe_401"];
329
330 // Select multiple features
331 for (NSString *featureId in testFeatureIds) {
332 BOOL success = [_locationWindow selectMapFeature:featureId];
333 NSLog(@"Selected feature %@: %@", featureId, success ? @"YES" : @"NO");
334 }
335
336 // Check selected features
337 NSArray<NSString *> *allSelected = [_locationWindow selectedMapFeatures];
338 NSLog(@"All selected features: %lu features", (unsigned long)allSelected.count);
339
340 // Deselect all at once
341 [_locationWindow deselectAllMapFeatures];
342 NSLog(@"Deselected all features at once");
343}
344
348- (void)demonstrateZoomProperties {
349 NSLog(@"--- Zoom Properties ---");
350
351 if (_locationWindow == nil) {
352 NSLog(@"LocationWindow not available yet");
353 return;
354 }
355
356 // [objc_LocationWindow_getZoomFactor]
357 // Get current zoom factor
358 double currentZoom = [_locationWindow zoomFactor];
359 NSLog(@"Current zoom factor: %.1f", currentZoom);
360 // [objc_LocationWindow_getZoomFactor]
361
362 // [objc_LocationWindow_setZoomFactor]
363 // Set zoom factor
364 [_locationWindow setZoomFactor:150.0];
365 NSLog(@"Set zoom factor to 150.0");
366 // [objc_LocationWindow_setZoomFactor]
367
368 // [objc_LocationWindow_getMinZoomFactor]
369 // Get minimum zoom factor
370 double minZoomFactor = [_locationWindow minZoomFactor];
371 NSLog(@"Minimum zoom factor: %.1f", minZoomFactor);
372 // [objc_LocationWindow_getMinZoomFactor]
373
374 // [objc_LocationWindow_setMinZoomFactor]
375 // Set minimum zoom factor
376 [_locationWindow setMinZoomFactor:50.0];
377 NSLog(@"Set minimum zoom factor to 50.0");
378 // [objc_LocationWindow_setMinZoomFactor]
379
380 // [objc_LocationWindow_getMaxZoomFactor]
381 // Get maximum zoom factor
382 double maxZoomFactor = [_locationWindow maxZoomFactor];
383 NSLog(@"Maximum zoom factor: %.1f", maxZoomFactor);
384 // [objc_LocationWindow_getMaxZoomFactor]
385
386 // [objc_LocationWindow_setMaxZoomFactor]
387 // Set maximum zoom factor
388 [_locationWindow setMaxZoomFactor:300.0];
389 NSLog(@"Set maximum zoom factor to 300.0");
390 // [objc_LocationWindow_setMaxZoomFactor]
391
392 // Test zoom factor changes
393 NSArray<NSNumber *> *testZoomFactors = @[@100.0, @125.0, @150.0, @200.0, @250.0];
394 for (NSNumber *zoom in testZoomFactors) {
395 [_locationWindow setZoomFactor:zoom.doubleValue];
396 NSLog(@"Changed zoom factor to: %.1f", [_locationWindow zoomFactor]);
397 }
398
399 // Test zoom limits
400 NSLog(@"Testing zoom limits...");
401 [_locationWindow setZoomFactor:[_locationWindow minZoomFactor]];
402 NSLog(@"Set to minimum zoom: %.1f", [_locationWindow zoomFactor]);
403
404 [_locationWindow setZoomFactor:[_locationWindow maxZoomFactor]];
405 NSLog(@"Set to maximum zoom: %.1f", [_locationWindow zoomFactor]);
406
407 // Reset to default
408 [_locationWindow setZoomFactor:100.0];
409 NSLog(@"Reset zoom factor to default: %.1f", [_locationWindow zoomFactor]);
410}
411
415- (void)runExample {
416 NSLog(@"=== LocationWindowCommon Example ===");
417
418 // Simulate LocationWindow initialization
419 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
420 // TODO: User will implement LocationWindow initialization here
421 // self->_locationWindow = [self getLocationWindow];
422
423 // Run demonstrations
424 [self demonstrateLocationWindowCommonMethods];
425
426 NSLog(@"=== Example completed ===");
427 });
428}
429
430@end
431
435int main(int argc, const char * argv[]) {
436 @autoreleasepool {
438 [example runExample];
439
440 // Keep the program running for a bit to see the output
441 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
442 }
443 return 0;
444}