From 8441d1d7ded89f048463dc7d9de70f68bad97d40 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Fri, 19 Sep 2025 13:40:05 +0300 Subject: [PATCH] Add extra UI settings and location manager settings. (#3817) Co-authored-by: Tetiana Gubanova <3168855+TatyanaPolunina@users.noreply.github.com> --- platform/ios/app/MBXState.h | 3 +++ platform/ios/app/MBXState.m | 19 ++++++++++++-- platform/ios/app/MBXViewController.mm | 3 +++ platform/ios/src/MLNMapView.h | 29 +++++++++++++++++++++ platform/ios/src/MLNMapView.mm | 37 +++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) diff --git a/platform/ios/app/MBXState.h b/platform/ios/app/MBXState.h index 2929b911c..3af2d7ce7 100644 --- a/platform/ios/app/MBXState.h +++ b/platform/ios/app/MBXState.h @@ -25,6 +25,9 @@ FOUNDATION_EXTERN NSString *const MBXReuseQueueStatsEnabled; @property (nonatomic) BOOL framerateMeasurementEnabled; @property (nonatomic) MLNMapDebugMaskOptions debugMask; @property (nonatomic) BOOL reuseQueueStatsEnabled; +@property (nonatomic) BOOL showsCompassView; +@property (nonatomic) BOOL showsLogoView; +@property (nonatomic) BOOL showsAttributionButton; @property (nonatomic, readonly) NSString *debugDescription; diff --git a/platform/ios/app/MBXState.m b/platform/ios/app/MBXState.m index 503319968..32232f20a 100644 --- a/platform/ios/app/MBXState.m +++ b/platform/ios/app/MBXState.m @@ -10,6 +10,9 @@ NSString *const MBXShowsMapScale = @"MBXMapShowsScale"; NSString *const MBXMapShowsHeadingIndicator = @"MBXMapShowsHeadingIndicator"; NSString *const MBXMapFramerateMeasurementEnabled = @"MBXMapFramerateMeasurementEnabled"; NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; +NSString *const MBXShowsCompassView = @"MBXShowsCompassView"; +NSString *const MBXShowsLogoView = @"MBXShowsLogoView"; +NSString *const MBXShowsAttributionButton = @"MBXShowsAttributionButton"; @interface MBXState() @@ -29,6 +32,9 @@ NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; [coder encodeBool:_showsUserHeadingIndicator forKey:MBXMapShowsHeadingIndicator]; [coder encodeBool:_framerateMeasurementEnabled forKey:MBXMapFramerateMeasurementEnabled]; [coder encodeBool:_reuseQueueStatsEnabled forKey:MBXReuseQueueStatsEnabled]; + [coder encodeBool:_showsLogoView forKey:MBXShowsLogoView]; + [coder encodeBool:_showsCompassView forKey:MBXShowsCompassView]; + [coder encodeBool:_showsAttributionButton forKey:MBXShowsAttributionButton]; } - (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder { @@ -43,6 +49,9 @@ NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; BOOL decodedShowsUserHeadingIndicator = [decoder decodeBoolForKey:MBXMapShowsHeadingIndicator]; BOOL decodedFramerateMeasurementEnabled = [decoder decodeBoolForKey:MBXMapFramerateMeasurementEnabled]; BOOL decodedReuseQueueStatsEnabled = [decoder decodeBoolForKey:MBXReuseQueueStatsEnabled]; + BOOL decodedShowsLogoView = [decoder decodeBoolForKey:MBXShowsLogoView]; + BOOL decodedShowsCompassView = [decoder decodeBoolForKey:MBXShowsCompassView]; + BOOL decodedAttributionButton = [decoder decodeBoolForKey:MBXShowsAttributionButton]; _camera = decodedCamera; _userTrackingMode = decodedUserTrackingMode.intValue; @@ -54,6 +63,9 @@ NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; _showsUserHeadingIndicator = decodedShowsUserHeadingIndicator; _framerateMeasurementEnabled = decodedFramerateMeasurementEnabled; _reuseQueueStatsEnabled = decodedReuseQueueStatsEnabled; + _showsLogoView = decodedShowsLogoView; + _showsCompassView = decodedShowsCompassView; + _showsAttributionButton = decodedAttributionButton; } return self; @@ -64,7 +76,7 @@ NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; } - (NSString *)debugDescription { - return [NSString stringWithFormat:@"Camera: %@\nTracking mode: %lu\nShows user location: %@\nDebug mask value: %lu\nShows zoom level ornament: %@\nShows time frame graph: %@\nShows map scale: %@\nShows user heading indicator: %@\nFramerate measurement enabled: %@\nReuse queue stats enabled: %@", + return [NSString stringWithFormat:@"Camera: %@\nTracking mode: %lu\nShows user location: %@\nDebug mask value: %lu\nShows zoom level ornament: %@\nShows time frame graph: %@\nShows map scale: %@\nShows user heading indicator: %@\nFramerate measurement enabled: %@\nReuse queue stats enabled: %@\nShows logo view: %@\nShows compass view: %@\nShows attribution button: %@", self.camera, (unsigned long)self.userTrackingMode, self.showsUserLocation ? @"YES" : @"NO", @@ -74,7 +86,10 @@ NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled"; self.showsMapScale ? @"YES" : @"NO", self.showsUserHeadingIndicator ? @"YES" : @"NO", self.framerateMeasurementEnabled ? @"YES" : @"NO", - self.reuseQueueStatsEnabled ? @"YES" : @"NO"]; + self.reuseQueueStatsEnabled ? @"YES" : @"NO", + self.showsLogoView ? @"YES" : @"NO", + self.showsCompassView ? @"YES" : @"NO", + self.showsAttributionButton ? @"YES" : @"NO"]; } @end diff --git a/platform/ios/app/MBXViewController.mm b/platform/ios/app/MBXViewController.mm index 44aed06c4..b0e1031b7 100644 --- a/platform/ios/app/MBXViewController.mm +++ b/platform/ios/app/MBXViewController.mm @@ -300,6 +300,9 @@ CLLocationCoordinate2D randomWorldCoordinate(void) { self.mapView.showsUserHeadingIndicator = YES; self.mapView.showsScale = YES; + self.mapView.showsLogoView = YES; + self.mapView.showsCompassView = YES; + self.mapView.showsAttributionButton = YES; self.zoomLevelOrnamentEnabled = NO; self.frameTimeGraphEnabled = NO; } else { diff --git a/platform/ios/src/MLNMapView.h b/platform/ios/src/MLNMapView.h index 1e800fafe..6533c56d3 100644 --- a/platform/ios/src/MLNMapView.h +++ b/platform/ios/src/MLNMapView.h @@ -357,6 +357,14 @@ MLN_EXPORT */ @property (nonatomic, assign) CGPoint scaleBarMargins; +/** + A Boolean value indicating whether the map may display Compass View. + + The view controlled by this property is available at `compassView`. The default value + of this property is `YES`. + */ +@property (nonatomic, assign) BOOL showsCompassView; + /** A control indicating the map’s direction and allowing the user to manipulate the direction, positioned in the upper-right corner. @@ -374,6 +382,14 @@ MLN_EXPORT */ @property (nonatomic, assign) CGPoint compassViewMargins; +/** + A Boolean value indicating whether the map may display MapLibre logo. + + The view controlled by this property is available at `logoView`. The default value + of this property is `YES`. + */ +@property (nonatomic, assign) BOOL showsLogoView; + /** A logo, the MapLibre logo by default, positioned in the lower-left corner. You are not required to display this, but some vector-sources may require attribution. @@ -391,6 +407,14 @@ MLN_EXPORT */ @property (nonatomic, assign) CGPoint logoViewMargins; +/** + A Boolean value indicating whether the map may display Attribution Button. + + The view controlled by this property is available at `attributionButton`. The default value + of this property is `YES`. + */ +@property (nonatomic, assign) BOOL showsAttributionButton; + /** A view showing legally required copyright notices, positioned at the bottom-right of the map view. @@ -510,6 +534,11 @@ MLN_EXPORT // MARK: Displaying the User’s Location +/** + Disabled using a current location manager. + */ +- (void)disableLocationManager; + /** The object that this map view uses to start and stop the delivery of location-related updates. diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index 23313088f..8a6b9542e 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -782,6 +782,10 @@ public: NSStringFromClass(self.class)); }); + _showsLogoView = YES; + _showsCompassView = YES; + _showsAttributionButton = YES; + // setup logo // UIImage *logo = [UIImage mgl_resourceImageNamed:@"maplibre-logo-stroke-gray"]; @@ -790,6 +794,7 @@ public: _logoView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"LOGO_A11Y_LABEL", nil, nil, @"Mapbox", @"Accessibility label"); _logoView.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:_logoView]; + _logoView.hidden = !_showsLogoView; _logoViewConstraints = [NSMutableArray array]; _logoViewPosition = MLNOrnamentPositionBottomLeft; _logoViewMargins = MLNOrnamentDefaultPositionOffset; @@ -802,6 +807,7 @@ public: [_attributionButton addTarget:self action:@selector(showAttribution:) forControlEvents:UIControlEventTouchUpInside]; _attributionButton.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:_attributionButton]; + _attributionButton.hidden = !_showsAttributionButton; _attributionButtonConstraints = [NSMutableArray array]; UILongPressGestureRecognizer *attributionLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showAttribution:)]; @@ -813,6 +819,7 @@ public: // _compassView = [MLNCompassButton compassButtonWithMapView:self]; [self addSubview:_compassView]; + _compassView.hidden = !_showsCompassView; _compassViewConstraints = [NSMutableArray array]; _compassViewPosition = MLNOrnamentPositionTopRight; _compassViewMargins = MLNOrnamentDefaultPositionOffset; @@ -3227,6 +3234,27 @@ static void *windowScreenContext = &windowScreenContext; } } +- (void)setShowsLogoView:(BOOL)showsLogoView +{ + MLNLogDebug(@"Setting showsLogoView: %@", MLNStringFromBOOL(showsLogoView)); + _showsLogoView = showsLogoView; + self.logoView.hidden = !showsLogoView; +} + +- (void)setShowsCompassView:(BOOL)showsCompassView +{ + MLNLogDebug(@"Setting showsCompassView: %@", MLNStringFromBOOL(showsCompassView)); + _showsCompassView = showsCompassView; + self.compassView.hidden = !showsCompassView; +} + +- (void)setShowsAttributionButton:(BOOL)showsAttributionButton +{ + MLNLogDebug(@"Setting showsAttributionButton: %@", MLNStringFromBOOL(showsAttributionButton)); + _showsAttributionButton = showsAttributionButton; + self.attributionButton.hidden = !showsAttributionButton; +} + - (void)setScaleBarShouldShowDarkStyles:(BOOL)scaleBarShouldShowDarkStyles { _scaleBarShouldShowDarkStyles = scaleBarShouldShowDarkStyles; @@ -5983,9 +6011,18 @@ static void *windowScreenContext = &windowScreenContext; // MARK: - User Location - + +- (void)disableLocationManager +{ + [_locationManager stopUpdatingLocation]; + [_locationManager stopUpdatingHeading]; + _locationManager = nil; +} + - (void)setLocationManager:(nullable id)locationManager { MLNLogDebug(@"Setting locationManager: %@", locationManager); + if (!locationManager) { locationManager = [[MLNCLLocationManager alloc] init]; }