4#import <NCScreenPoint.h>
18#import <UIKit/UIKit.h>
30@implementation DemoSublocationChangeListener
32- (void)onActiveSublocationChanged:(int32_t)sublocationId {
33 NSLog(
@"Active sublocation changed to: %d", sublocationId);
38@interface DemoRouteLayerListener : NSObject <NCRouteLayerListener>
41@implementation DemoRouteLayerListener
43 NSLog(
@"Route status: %ld", (
long)status);
46- (void)onRouteAdvanced:(NCRouteProgress *)progress {
50- (void)onRouteTargetReached {
51 NSLog(
@"Route target reached");
55@interface DemoRouteViewListener : NSObject <NCRouteViewListener>
56@property (nonatomic, weak) NCRouteLayer *routeLayer;
59@implementation DemoRouteViewListener
60- (void)onRouteViewsChanged {
61 NSLog(
@"Route views changed");
64- (void)onSelectedRouteChanged:(
id<NCRouteView>)route {
65 NSLog(
@"Selected route changed");
68- (void)onRouteViewTap:(
id<NCRouteView>)route {
69 [
self.routeLayer selectRoute:route];
73@implementation LocationWindowCommonExample {
74 NCLocationWindow *_locationWindow;
93 NSLog(
@"=== LocationWindowCommon Methods ===");
95 [
self demonstrateSetSublocationId];
96 [
self demonstrateOperatingMode];
97 [
self demonstrateSublocationQueries];
98 [
self demonstrateSublocationChangeListener];
99 [
self demonstrateUserLocationLayer];
100 [
self demonstrateRouteLayer];
101 [
self demonstrateCoordinateConversion];
102 [
self demonstrateMapFeatureSelection];
103 [
self demonstrateApplyLayerFilter];
104 [
self demonstrateDebugFlags];
105 [
self demonstrateZoomProperties];
111- (void)demonstrateDebugFlags {
112 NSLog(
@"--- Debug flags ---");
115 NSArray<NSNumber *> *allFlags = @[
119 @(NCDebugFlagLabels),
120 @(NCDebugFlagDrawAllLabels),
121 @(NCDebugFlagSelectionBuffer)
123 NSLog(
@"Debug flag enum values: %lu", (
unsigned long)allFlags.count);
129 NSLog(
@"Updated debug flags on LocationWindow");
134 NSLog(
@"Debug flag INFOS enabled: %@", infosOn ?
@"YES" :
@"NO");
142- (void)demonstrateOperatingMode {
143 NSLog(
@"--- Operating Mode ---");
145 if (_locationWindow == nil) {
146 NSLog(
@"LocationWindow not available yet");
151 NSArray<NSNumber *> *modes = @[@(NCOperatingModeIndoorOnly), @(NCOperatingModeOutdoor), @(NCOperatingModeOutdoorIndoor)];
152 NSLog(
@"Operating modes: %lu", (
unsigned long)modes.count);
156 [_locationWindow setOperatingMode:NCOperatingModeOutdoorIndoor];
157 NSLog(
@"Set operating mode to OUTDOOR_INDOOR");
162 NSLog(
@"Current operating mode: %ld", (
long)currentMode);
166 NSArray<NSNumber *> *themes = @[@(NCMapThemeLight), @(NCMapThemeDark)];
167 NSLog(
@"Map themes: %lu", (
unsigned long)themes.count);
171 [_locationWindow setMapTheme:NCMapThemeDark];
172 NSLog(
@"Set map theme to DARK");
176 NCMapTheme currentTheme = [_locationWindow getMapTheme];
177 NSLog(
@"Current map theme: %ld", (
long)currentTheme);
181 NSArray<NSNumber *> *kinds = @[@(NCTileKindVector), @(NCTileKindRaster)];
182 NSLog(
@"Tile kinds: %lu", (
unsigned long)kinds.count);
186 NSArray<NSNumber *> *schemas = @[@(NCTileSchemaShortbread), @(NCTileSchemaOpenMapTiles), @(NCTileSchemaMapboxStreets)];
187 NSLog(
@"Tile schemas: %lu", (
unsigned long)schemas.count);
192 initWithUrlTemplate:@"https://api.maptiler.com/tiles/v3-openmaptiles/{z}/{x}/{y}.pbf"
194 queryParameters:@{@"key": @"YOUR_MAPTILER_KEY"}];
199 initWithPath:@"/path/to/map.mbtiles"];
204 initWithSchema:NCTileSchemaOpenMapTiles
210 kind:NCTileKindVector];
212 initWithSchema:NCTileSchemaShortbread
218 kind:NCTileKindVector];
222 [_locationWindow setTileProvider:osmHttp];
223 [_locationWindow setTileProvider:nil];
225 initWithUrlTemplate:@"https://tile.openstreetmap.org/{z}/{x}/{y}.png"
227 queryParameters:nil];
229 initWithSchema:NCTileSchemaShortbread
234 attribution:@"© OpenStreetMap contributors"
235 kind:NCTileKindRaster];
236 [_locationWindow setTileProvider:imagery];
241 initWithHorizontalAlignment:NCAttributionHorizontalAlignmentRight
242 verticalAlignment:NCAttributionVerticalAlignmentBottom];
246 [_locationWindow setAttributionAlignment:alignment];
250 NSString *attribution = [_locationWindow getAttribution];
251 NSLog(
@"Attribution: %@", attribution);
258- (void)demonstrateSetSublocationId {
259 NSLog(
@"--- setSublocationId Method ---");
261 if (_locationWindow == nil) {
262 NSLog(
@"LocationWindow not available yet");
268 [_locationWindow setSublocationId:1];
269 NSLog(
@"Set sublocation ID to 1 (first floor)");
274 [_locationWindow setSublocationId:2];
275 NSLog(
@"Set sublocation ID to 2 (second floor)");
280 [_locationWindow setSublocationId:0];
281 NSLog(
@"Set sublocation ID to 0 (ground floor)");
285 NSArray<NSNumber *> *sublocationIds = @[@1, @2, @3, @0, @5];
286 for (NSNumber *idNumber in sublocationIds) {
287 [_locationWindow setSublocationId:idNumber.intValue];
288 NSLog(
@"Switched to sublocation ID: %d", idNumber.intValue);
295- (void)demonstrateSublocationQueries {
296 NSLog(
@"--- getSublocationId & getEnclosingCamera ---");
298 if (_locationWindow == nil) {
299 NSLog(
@"LocationWindow not available yet");
304 NSNumber *currentId = [_locationWindow getSublocationId];
305 if (currentId != nil) {
306 NSLog(
@"Current sublocation id: %@", currentId);
308 NSLog(
@"Current sublocation id is not set");
314 topRight:[[
NCGlobalPoint alloc] initWithLatitude:55.76 longitude:37.63]];
315 NCCamera *camera = [_locationWindow getEnclosingCamera:boundingBox];
316 NSLog(
@"Camera that fits bounding box: %@", camera);
321 bottomRight:[[NCScreenPoint alloc] initWithX:1000 y:1600]];
322 [_locationWindow setFocusRect:focus];
326 NCCamera *padded = [_locationWindow getEnclosingCameraWithFocus:boundingBox
330 NSLog(
@"Camera that fits bounding box in focus rect: %@", padded);
337- (void)demonstrateSublocationChangeListener {
338 NSLog(
@"--- Sublocation Change Listener ---");
340 if (_locationWindow == nil) {
341 NSLog(
@"LocationWindow not available yet");
348 [_locationWindow addSublocationChangeListener:listener];
349 NSLog(
@"Added sublocation change listener");
352 [_locationWindow setSublocationId:1];
353 [_locationWindow setSublocationId:2];
356 [_locationWindow removeSublocationChangeListener:listener];
357 NSLog(
@"Removed sublocation change listener");
364- (void)demonstrateUserLocationLayer {
365 NSLog(
@"--- UserLocationLayer ---");
368 NSLog(
@"UserLocationLayer not available yet");
374 NSLog(
@"User location layer set visible");
379 NSLog(
@"User location layer is visible: %@", visible ?
@"YES" :
@"NO");
383 NCScreenPoint *anchor = [[NCScreenPoint alloc] initWithX:100.0f y:200.0f];
385 NSLog(
@"Set user location anchor to: (%.1f, %.1f)", anchor.x, anchor.y);
390 NSLog(
@"Anchor enabled: %@", anchorEnabled ?
@"YES" :
@"NO");
395 NSLog(
@"Heading-up mode enabled");
400 NSLog(
@"Heading-up mode active: %@", headingModeActive ?
@"YES" :
@"NO");
405 NSLog(
@"Follow mode set to heading");
410 NSLog(
@"Follow mode: %ld", (
long)followMode);
414 UIImage *arrow = [UIImage imageWithContentsOfFile:@"/path/to/arrow.png"];
419 NSLog(
@"Custom arrow bitmap cleared");
424 NSLog(
@"Accuracy circle color updated");
429 NSLog(
@"Anchor reset to default");
436- (void)demonstrateRouteLayer {
437 NSLog(
@"--- RouteLayer ---");
440 NSLog(
@"RouteLayer not available yet");
446 NSLog(
@"Route layer set visible");
451 NSLog(
@"Route layer is visible: %d", visible);
456 NSLog(
@"Traveled color updated");
461 NSLog(
@"Remaining color updated");
466 NSLog(
@"Route width updated");
471 NSLog(
@"Remaining style set to DOTTED");
476 NSLog(
@"Remaining style: %ld", (
long)remainingStyle);
481 NSLog(
@"Remaining point size updated");
486 NSLog(
@"Remaining placement updated");
491 NSLog(
@"Remaining placement spacing updated");
496 NSLog(
@"Remaining placement min ratio updated");
501 NSLog(
@"Remaining collision disabled");
506 NSLog(
@"Remaining dash length updated");
511 NSLog(
@"Remaining gap length updated");
515 initWithPoint:[[
NCGlobalPoint alloc] initWithLatitude:55.751244 longitude:37.618423]
518 initWithPoint:[[
NCGlobalPoint alloc] initWithLatitude:55.751700 longitude:37.619000]
523 NSLog(
@"Static route applied");
528 NSLog(
@"Guidance target applied");
533 NSLog(
@"Visible routes: %lu", (
unsigned long)routes.count);
538 if (selectedRoute != nil) {
539 NSLog(
@"Selected route length: %f", [selectedRoute length]);
544 if (routes.count > 0) {
562 NSLog(
@"Route layer cleared");
569- (void)demonstrateCoordinateConversion {
570 NSLog(
@"--- Coordinate Conversion Methods ---");
572 if (_locationWindow == nil) {
573 NSLog(
@"LocationWindow not available yet");
578 NCScreenPoint *screenPoint = [[NCScreenPoint alloc] initWithX:100.0 y:200.0];
579 NCGlobalPoint *globalPoint = [_locationWindow screenPositionToGlobal:screenPoint];
580 NSLog(
@"Screen position (%.1f, %.1f) converted to WGS84: (%.6f, %.6f)",
586 NSLog(
@"Viewport top-left: %@", visibleRegion.
topLeft);
591 NSLog(
@"Focus-rect top-left: %@", focusRegion.
topLeft);
596 NCScreenPoint *screenPoint2 = [_locationWindow globalToScreenPosition:globalPoint2 clipToViewport:YES];
597 NSLog(
@"WGS84 (%.6f, %.6f) converted to screen with clipping: (%.1f, %.1f)",
601 NSArray<NCScreenPoint *> *testScreenPoints = @[
602 [[NCScreenPoint alloc] initWithX:0.0 y:0.0],
603 [[NCScreenPoint alloc] initWithX:250.0 y:250.0],
604 [[NCScreenPoint alloc] initWithX:1000.0 y:600.0]
607 for (
int i = 0; i < testScreenPoints.count; i++) {
608 NCScreenPoint *sp = testScreenPoints[i];
609 NCGlobalPoint *gp = [_locationWindow screenPositionToGlobal:sp];
610 NCScreenPoint *backToScreen = [_locationWindow globalToScreenPosition:gp clipToViewport:NO];
611 NSLog(
@"Test %d: Screen (%.1f, %.1f) -> WGS84 (%.6f, %.6f) -> Screen (%.1f, %.1f)",
619- (void)demonstrateMapFeatureSelection {
620 NSLog(
@"--- Map Feature Selection Methods ---");
622 if (_locationWindow == nil) {
623 NSLog(
@"LocationWindow not available yet");
629 NSString *featureId =
"room_101";
630 BOOL selected = [_locationWindow selectMapFeature:featureId];
631 NSLog(
@"Selected map feature %@: %@", featureId, selected ?
@"YES" :
@"NO");
636 NSString *featureId2 =
"office_205";
637 BOOL selected2 = [_locationWindow selectMapFeature:featureId2];
638 NSLog(
@"Selected map feature %@: %@", featureId2, selected2 ?
@"YES" :
@"NO");
643 NSArray<NSString *> *selectedFeatures = [_locationWindow selectedMapFeatures];
644 NSLog(
@"Currently selected map features: %lu features", (
unsigned long)selectedFeatures.count);
645 for (NSString *feature in selectedFeatures) {
646 NSLog(
@" - %@", feature);
652 BOOL deselected = [_locationWindow deselectMapFeature:featureId];
653 NSLog(
@"Deselected map feature %@: %@", featureId, deselected ?
@"YES" :
@"NO");
658 BOOL deselected2 = [_locationWindow deselectMapFeature:featureId2];
659 NSLog(
@"Deselected map feature %@: %@", featureId2, deselected2 ?
@"YES" :
@"NO");
664 [_locationWindow deselectAllMapFeatures];
665 NSLog(
@"Deselected all map features");
670 NSArray<NSString *> *remainingFeatures = [_locationWindow selectedMapFeatures];
671 NSLog(
@"Remaining selected features after deselect all: %lu features", (
unsigned long)remainingFeatures.count);
675 NSArray<NSString *> *testFeatureIds = @[@"room_101", @"office_205", @"meeting_room_301", @"cafe_401"];
678 for (NSString *featureId in testFeatureIds) {
679 BOOL success = [_locationWindow selectMapFeature:featureId];
680 NSLog(
@"Selected feature %@: %@", featureId, success ?
@"YES" :
@"NO");
684 NSArray<NSString *> *allSelected = [_locationWindow selectedMapFeatures];
685 NSLog(
@"All selected features: %lu features", (
unsigned long)allSelected.count);
688 [_locationWindow deselectAllMapFeatures];
689 NSLog(
@"Deselected all features at once");
695- (void)demonstrateApplyLayerFilter {
696 NSLog(
@"--- applyLayerFilter Method ---");
698 if (_locationWindow == nil) {
699 NSLog(
@"LocationWindow not available yet");
710 NSArray<NCMapFilterCondition *> *conditions = @[[[
NCMapFilterCondition alloc] initWithProperty:@"category" values:@[@"Toilet", @"Cafe"]]];
711 [_locationWindow applyLayerFilterWithLayer:@"venues" conditions:conditions];
712 NSLog(
@"Applied layer filter: show venues with category Toilet or Cafe");
716 [_locationWindow applyLayerFilterWithLayer:@"venues" conditions:@[]];
717 NSLog(
@"Reset layer filter: show all venues");
723- (void)demonstrateZoomProperties {
724 NSLog(
@"--- Zoom Properties ---");
726 if (_locationWindow == nil) {
727 NSLog(
@"LocationWindow not available yet");
733 double currentZoom = [_locationWindow zoomFactor];
734 NSLog(
@"Current zoom factor: %.1f", currentZoom);
739 [_locationWindow setZoomFactor:150.0];
740 NSLog(
@"Set zoom factor to 150.0");
745 double minZoomFactor = [_locationWindow minZoomFactor];
746 NSLog(
@"Minimum zoom factor: %.1f", minZoomFactor);
751 [_locationWindow setMinZoomFactor:50.0];
752 NSLog(
@"Set minimum zoom factor to 50.0");
757 double maxZoomFactor = [_locationWindow maxZoomFactor];
758 NSLog(
@"Maximum zoom factor: %.1f", maxZoomFactor);
763 [_locationWindow setMaxZoomFactor:300.0];
764 NSLog(
@"Set maximum zoom factor to 300.0");
768 NSArray<NSNumber *> *testZoomFactors = @[@100.0, @125.0, @150.0, @200.0, @250.0];
769 for (NSNumber *zoom in testZoomFactors) {
770 [_locationWindow setZoomFactor:zoom.doubleValue];
771 NSLog(
@"Changed zoom factor to: %.1f", [_locationWindow zoomFactor]);
775 NSLog(
@"Testing zoom limits...");
776 [_locationWindow setZoomFactor:[_locationWindow minZoomFactor]];
777 NSLog(
@"Set to minimum zoom: %.1f", [_locationWindow zoomFactor]);
779 [_locationWindow setZoomFactor:[_locationWindow maxZoomFactor]];
780 NSLog(
@"Set to maximum zoom: %.1f", [_locationWindow zoomFactor]);
783 [_locationWindow setZoomFactor:100.0];
784 NSLog(
@"Reset zoom factor to default: %.1f", [_locationWindow zoomFactor]);
791 NSLog(
@"=== LocationWindowCommon Example ===");
794 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
799 [
self demonstrateLocationWindowCommonMethods];
801 NSLog(
@"=== Example completed ===");
810int main(
int argc,
const char * argv[]) {
813 [example runExample];
816 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];