19@implementation DemoSublocationChangeListener
21- (void)onActiveSublocationChanged:(int32_t)sublocationId {
22 NSLog(
@"Active sublocation changed to: %d", sublocationId);
27@implementation LocationWindowCommonExample {
28 NCLocationWindow *_locationWindow;
44 NSLog(
@"=== LocationWindowCommon Methods ===");
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];
60- (void)demonstrateDebugFlags {
61 NSLog(
@"--- Debug flags ---");
64 NSArray<NSNumber *> *allFlags = @[
69 @(NCDebugFlagDrawAllLabels),
70 @(NCDebugFlagSelectionBuffer)
72 NSLog(
@"Debug flag enum values: %lu", (
unsigned long)allFlags.count);
78 NSLog(
@"Updated debug flags on LocationWindow");
83 NSLog(
@"Debug flag INFOS enabled: %@", infosOn ?
@"YES" :
@"NO");
90- (void)demonstrateSetSublocationId {
91 NSLog(
@"--- setSublocationId Method ---");
93 if (_locationWindow == nil) {
94 NSLog(
@"LocationWindow not available yet");
100 [_locationWindow setSublocationId:1];
101 NSLog(
@"Set sublocation ID to 1 (first floor)");
106 [_locationWindow setSublocationId:2];
107 NSLog(
@"Set sublocation ID to 2 (second floor)");
112 [_locationWindow setSublocationId:0];
113 NSLog(
@"Set sublocation ID to 0 (ground floor)");
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);
127- (void)demonstrateSublocationQueries {
128 NSLog(
@"--- getSublocationId & getEnclosingCamera ---");
130 if (_locationWindow == nil) {
131 NSLog(
@"LocationWindow not available yet");
136 NSNumber *currentId = [_locationWindow getSublocationId];
137 if (currentId != nil) {
138 NSLog(
@"Current sublocation id: %@", currentId);
140 NSLog(
@"Current sublocation id is not set");
146 topRight:[[
NCPoint alloc] initWithX:20.0 y:30.0]];
147 NCCamera *camera = [_locationWindow getEnclosingCamera:boundingBox];
148 NSLog(
@"Camera that fits bounding box: %@", camera);
155- (void)demonstrateSublocationChangeListener {
156 NSLog(
@"--- Sublocation Change Listener ---");
158 if (_locationWindow == nil) {
159 NSLog(
@"LocationWindow not available yet");
166 [_locationWindow addSublocationChangeListener:listener];
167 NSLog(
@"Added sublocation change listener");
170 [_locationWindow setSublocationId:1];
171 [_locationWindow setSublocationId:2];
174 [_locationWindow removeSublocationChangeListener:listener];
175 NSLog(
@"Removed sublocation change listener");
182- (void)demonstrateUserLocationLayer {
183 NSLog(
@"--- UserLocationLayer ---");
186 NSLog(
@"UserLocationLayer not available yet");
192 NSLog(
@"User location layer set visible");
197 NSLog(
@"User location layer is visible: %@", visible ?
@"YES" :
@"NO");
201 NCScreenPoint *anchor = [[NCScreenPoint alloc] initWithX:100.0f y:200.0f];
203 NSLog(
@"Set user location anchor to: (%.1f, %.1f)", anchor.x, anchor.y);
208 NSLog(
@"Anchor enabled: %@", anchorEnabled ?
@"YES" :
@"NO");
213 NSLog(
@"Anchor reset to default");
220- (void)demonstrateCoordinateConversion {
221 NSLog(
@"--- Coordinate Conversion Methods ---");
223 if (_locationWindow == nil) {
224 NSLog(
@"LocationWindow not available yet");
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);
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);
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);
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);
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]
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);
281- (void)demonstrateMapFeatureSelection {
282 NSLog(
@"--- Map Feature Selection Methods ---");
284 if (_locationWindow == nil) {
285 NSLog(
@"LocationWindow not available yet");
291 NSString *featureId =
"room_101";
292 BOOL selected = [_locationWindow selectMapFeature:featureId];
293 NSLog(
@"Selected map feature %@: %@", featureId, selected ?
@"YES" :
@"NO");
298 NSString *featureId2 =
"office_205";
299 BOOL selected2 = [_locationWindow selectMapFeature:featureId2];
300 NSLog(
@"Selected map feature %@: %@", featureId2, selected2 ?
@"YES" :
@"NO");
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);
314 BOOL deselected = [_locationWindow deselectMapFeature:featureId];
315 NSLog(
@"Deselected map feature %@: %@", featureId, deselected ?
@"YES" :
@"NO");
320 BOOL deselected2 = [_locationWindow deselectMapFeature:featureId2];
321 NSLog(
@"Deselected map feature %@: %@", featureId2, deselected2 ?
@"YES" :
@"NO");
326 [_locationWindow deselectAllMapFeatures];
327 NSLog(
@"Deselected all map features");
332 NSArray<NSString *> *remainingFeatures = [_locationWindow selectedMapFeatures];
333 NSLog(
@"Remaining selected features after deselect all: %lu features", (
unsigned long)remainingFeatures.count);
337 NSArray<NSString *> *testFeatureIds = @[@"room_101", @"office_205", @"meeting_room_301", @"cafe_401"];
340 for (NSString *featureId in testFeatureIds) {
341 BOOL success = [_locationWindow selectMapFeature:featureId];
342 NSLog(
@"Selected feature %@: %@", featureId, success ?
@"YES" :
@"NO");
346 NSArray<NSString *> *allSelected = [_locationWindow selectedMapFeatures];
347 NSLog(
@"All selected features: %lu features", (
unsigned long)allSelected.count);
350 [_locationWindow deselectAllMapFeatures];
351 NSLog(
@"Deselected all features at once");
357- (void)demonstrateApplyLayerFilter {
358 NSLog(
@"--- applyLayerFilter Method ---");
360 if (_locationWindow == nil) {
361 NSLog(
@"LocationWindow not available yet");
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");
378 [_locationWindow applyLayerFilterWithLayer:@"venues" conditions:@[]];
379 NSLog(
@"Reset layer filter: show all venues");
385- (void)demonstrateZoomProperties {
386 NSLog(
@"--- Zoom Properties ---");
388 if (_locationWindow == nil) {
389 NSLog(
@"LocationWindow not available yet");
395 double currentZoom = [_locationWindow zoomFactor];
396 NSLog(
@"Current zoom factor: %.1f", currentZoom);
401 [_locationWindow setZoomFactor:150.0];
402 NSLog(
@"Set zoom factor to 150.0");
407 double minZoomFactor = [_locationWindow minZoomFactor];
408 NSLog(
@"Minimum zoom factor: %.1f", minZoomFactor);
413 [_locationWindow setMinZoomFactor:50.0];
414 NSLog(
@"Set minimum zoom factor to 50.0");
419 double maxZoomFactor = [_locationWindow maxZoomFactor];
420 NSLog(
@"Maximum zoom factor: %.1f", maxZoomFactor);
425 [_locationWindow setMaxZoomFactor:300.0];
426 NSLog(
@"Set maximum zoom factor to 300.0");
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]);
437 NSLog(
@"Testing zoom limits...");
438 [_locationWindow setZoomFactor:[_locationWindow minZoomFactor]];
439 NSLog(
@"Set to minimum zoom: %.1f", [_locationWindow zoomFactor]);
441 [_locationWindow setZoomFactor:[_locationWindow maxZoomFactor]];
442 NSLog(
@"Set to maximum zoom: %.1f", [_locationWindow zoomFactor]);
445 [_locationWindow setZoomFactor:100.0];
446 NSLog(
@"Reset zoom factor to default: %.1f", [_locationWindow zoomFactor]);
453 NSLog(
@"=== LocationWindowCommon Example ===");
456 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
461 [
self demonstrateLocationWindowCommonMethods];
463 NSLog(
@"=== Example completed ===");
472int main(
int argc,
const char * argv[]) {
475 [example runExample];
478 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];