Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Expose name and default position of current style (#6127)
Browse files Browse the repository at this point in the history
* [ios] Reset to style’s default position

* [ios, macos] Added name property to MGLStyle
  • Loading branch information
1ec5 authored Aug 24, 2016
1 parent 7fb7bc0 commit 2523f33
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
7 changes: 7 additions & 0 deletions platform/darwin/src/MGLStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
4 changes: 4 additions & 0 deletions platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 8 additions & 6 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2523f33

Please sign in to comment.