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

Add -mapView:didFinishLoadingStyle: delegate methods #6636

Merged
merged 2 commits into from
Oct 11, 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
12 changes: 12 additions & 0 deletions platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

@interface MGLStyle()
@property (nonatomic, weak) MGLMapView *mapView;
@property (readonly, copy, nullable) NSURL *URL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine for now, but it would be nice to make this public at some point, especially once we have #6386.

@end

@implementation MGLStyle
Expand Down Expand Up @@ -92,6 +93,10 @@ - (NSString *)name {
return @(self.mapView.mbglMap->getStyleName().c_str());
}

- (NSURL *)URL {
Copy link
Contributor

Choose a reason for hiding this comment

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

What I was thinking of in #6636 (review) is just a comment here, something like:

    // note that if `mbglMap->setStyleJSON()` is ever wired up, this can return unexpected results

Copy link
Contributor Author

@friedbunny friedbunny Oct 8, 2016

Choose a reason for hiding this comment

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

Unexpected in what sense? The private definition of this property says it’s nullable. Is there an expectation that URL will end up returning something in the future that isn’t a URL or null?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, misunderstood. Carry on! 👍

return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())];
}

- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier
{
auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String);
Expand Down Expand Up @@ -254,5 +259,12 @@ - (void)removeStyleClass:(NSString *)styleClass
}
}

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p; name = %@, URL = %@>",
NSStringFromClass([self class]), (void *)self,
self.name ? [NSString stringWithFormat:@"\"%@\"", self.name] : self.name,
self.URL ? [NSString stringWithFormat:@"\"%@\"", self.URL] : self.URL];
}

@end
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* 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))
* The `identifier` property of an MGLFeature may now be either a number or string. ([#5514](https://github.com/mapbox/mapbox-gl-native/pull/5514))
* If MGLMapView is unable to obtain or parse a style, it now calls its delegate’s `-mapViewDidFailLoadingMap:withError:` method. ([#6145](https://github.com/mapbox/mapbox-gl-native/pull/6145))
* Added the `-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]` delegate method, which offers the earliest opportunity to modify the layout or appearance of the current style before the map view is displayed to the user. ([#6636](https://github.com/mapbox/mapbox-gl-native/pull/6636))
* Fixed crashes that could occur when loading a malformed stylesheet. ([#5736](https://github.com/mapbox/mapbox-gl-native/pull/5736))
* Fixed an issue causing stepwise zoom functions to be misinterpreted. ([#6328](https://github.com/mapbox/mapbox-gl-native/pull/6328))
* A source’s tiles are no longer rendered when the map is outside the source’s supported zoom levels. ([#6345](https://github.com/mapbox/mapbox-gl-native/pull/6345))
Expand Down
8 changes: 8 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,14 @@ - (void)notifyMapChange:(mbgl::MapChange)change
}
break;
}
case mbgl::MapChangeDidFinishLoadingStyle:
{
if ([self.delegate respondsToSelector:@selector(mapView:didFinishLoadingStyle:)])
{
[self.delegate mapView:self didFinishLoadingStyle:self.style];
}
break;
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions platform/ios/src/MGLMapViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;

/**
Tells the delegate that the map has just finished loading a style.

This method is called during the initialization of the map view and after any
subsequent loading of a new style. This method is called between the
`-mapViewWillStartRenderingMap:` and `-mapViewDidFinishRenderingMap:` delegate
methods. Changes to sources or layers of the current style do not cause this
method to be called.

This method is the earliest opportunity to modify the layout or appearance of
the current style before the map view is displayed to the user.

@param mapView The map view that has just loaded a style.
@param style The style that was loaded.
*/
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style;

#pragma mark Tracking User Location

/**
Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Fixed an issue causing an MGLOfflinePack’s progress to continue to update after calling `-suspend`. ([#6186](https://github.com/mapbox/mapbox-gl-native/pull/6186))
* Fixed an issue preventing cached annotation images from displaying while the device is offline. ([#6358](https://github.com/mapbox/mapbox-gl-native/pull/6358))
* If MGLMapView is unable to obtain or parse a style, it now calls its delegate’s `-mapViewDidFailLoadingMap:withError:` method. ([#6145](https://github.com/mapbox/mapbox-gl-native/pull/6145))
* Added the `-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]` delegate method, which offers the earliest opportunity to modify the layout or appearance of the current style before the map view is displayed to the user. ([#6636](https://github.com/mapbox/mapbox-gl-native/pull/6636))
* Fixed an issue causing stepwise zoom functions to be misinterpreted. ([#6328](https://github.com/mapbox/mapbox-gl-native/pull/6328))
* A source’s tiles are no longer rendered when the map is outside the source’s supported zoom levels. ([#6345](https://github.com/mapbox/mapbox-gl-native/pull/6345))
* Fixed a crash that could occur when the device is disconnected while downloading an offline pack. ([#6293](https://github.com/mapbox/mapbox-gl-native/pull/6293))
Expand Down
8 changes: 8 additions & 0 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,14 @@ - (void)notifyMapChange:(mbgl::MapChange)change {
}
break;
}
case mbgl::MapChangeDidFinishLoadingStyle:
{
if ([self.delegate respondsToSelector:@selector(mapView:didFinishLoadingStyle:)])
{
[self.delegate mapView:self didFinishLoadingStyle:self.style];
}
break;
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions platform/macos/src/MGLMapViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered;

/**
Tells the delegate that the map has just finished loading a style.

This method is called during the initialization of the map view and after any
subsequent loading of a new style. This method is called between the
`-mapViewWillStartRenderingMap:` and `-mapViewDidFinishRenderingMap:` delegate
methods. Changes to sources or layers of the current style do not cause this
method to be called.

This method is the earliest opportunity to modify the layout or appearance of
the current style before the map view is displayed to the user.

@param mapView The map view that has just loaded a style.
@param style The style that was loaded.
*/
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style;

#pragma mark Managing the Appearance of Annotations

/**
Expand Down