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

Expose name and default position of current style #6127

Merged
merged 2 commits into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -558,6 +558,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 @@ -1214,12 +1222,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.);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like studio wraps bearings. Do we do this since we don't know where the style will actually come from? (just curious)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we can’t assume the style was authored in Studio. Alternatively, we could establish a convention that mbgl::Map wraps the return values of getDefeaultBearing() and getBearing(), but we can tackle that separately from this PR.

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