From 2523f33ac440be1a817e50d2d8bdc4d9c5b0a9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 24 Aug 2016 11:43:54 -0700 Subject: [PATCH] [ios, macos] Expose name and default position of current style (#6127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ios] Reset to style’s default position * [ios, macos] Added name property to MGLStyle --- platform/darwin/src/MGLStyle.h | 7 +++++++ platform/darwin/src/MGLStyle.mm | 4 ++++ platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.h | 14 ++++++++------ platform/ios/src/MGLMapView.mm | 10 +++++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 3354d27a43a..bc4c32da914 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -164,6 +164,13 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ + (NSURL *)satelliteStreetsStyleURLWithVersion:(NSInteger)version; +/** + The name of the style. + + You can customize the style’s name in Mapbox Studio. + */ +@property (readonly, copy, nullable) NSString *name; + #pragma mark Runtime Styling /** diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 7b6a36d834b..e392cead3fc 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -88,6 +88,10 @@ + (NSURL *)emeraldStyleURL { return MGLStyleURL_emerald; } +- (NSString *)name { + return @(self.mapView.mbglMap->getStyleName().c_str()); +} + - (mbgl::style::Layer *)mbglLayerWithIdentifier:(NSString *)identifier { return self.mapView.mbglMap->getLayer(identifier.UTF8String); diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b81acf63a62..24c1c8d70ad 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -17,6 +17,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Added [quadkey](https://msdn.microsoft.com/en-us/library/bb259689.aspx) support and limited WMS support in raster tile URL templates. ([#5628](https://github.com/mapbox/mapbox-gl-native/pull/5628)) * TileJSON manifests can now specify `"scheme": "tms"` to indicate the use of [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) coordinates. ([#2270](https://github.com/mapbox/mapbox-gl-native/pull/2270)) * Fixed rendering artifacts and missing glyphs that occurred after viewing a large number of CJK characters on the map. ([#5908](https://github.com/mapbox/mapbox-gl-native/pull/5908)) +* `-[MGLMapView resetPosition]` now resets to the current style’s default center coordinates, zoom level, direction, and pitch, if specified. ([#6127](https://github.com/mapbox/mapbox-gl-native/pull/6127)) * The `text-pitch-alignment` property is now supported in stylesheets for improved street label legibility on a tilted map. ([#5288](https://github.com/mapbox/mapbox-gl-native/pull/5288)) * The `icon-text-fit` and `icon-text-fit-padding` properties are now supported in stylesheets, allowing the background of a shield to automatically resize to fit the shield’s text. ([#5334](https://github.com/mapbox/mapbox-gl-native/pull/5334)) * The `circle-pitch-scale` property is now supported in stylesheets, allowing circle features in a tilted base map to scale or remain the same size as the viewing distance changes. ([#5576](https://github.com/mapbox/mapbox-gl-native/pull/5576)) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 40a9ad51f77..57b74daa045 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -539,6 +539,14 @@ IB_DESIGNABLE */ - (IBAction)resetNorth; +/** + Resets the map to the current style’s default viewport. + + If the style doesn’t specify a default viewport, the map resets to a minimum + zoom level, a center coordinate of (0, 0), and a northern heading. + */ +- (IBAction)resetPosition; + /** The coordinate bounds visible in the receiver’s viewport. @@ -1195,12 +1203,6 @@ IB_DESIGNABLE - (void)emptyMemoryCache __attribute__((deprecated)); -/** - Resets the map to the minimum zoom level, a center coordinate of (0, 0), and - a northern heading. - */ -- (void)resetPosition; - @end NS_ASSUME_NONNULL_END diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index d588f797ccd..c3091a588b3 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1899,9 +1899,13 @@ - (void)resetNorthAnimated:(BOOL)animated - (void)resetPosition { - MGLMapCamera *camera = [MGLMapCamera camera]; - camera.altitude = MGLAltitudeForZoomLevel(0, 0, 0, self.frame.size); - self.camera = camera; + CGFloat pitch = _mbglMap->getDefaultPitch(); + CLLocationDirection heading = mbgl::util::wrap(_mbglMap->getDefaultBearing(), 0., 360.); + CLLocationDistance distance = MGLAltitudeForZoomLevel(_mbglMap->getDefaultZoom(), pitch, 0, self.frame.size); + self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(_mbglMap->getDefaultLatLng()) + fromDistance:distance + pitch:pitch + heading:heading]; } - (void)emptyMemoryCache