Repository navigation
Map snapshotter additions - #10163
Conversation
23b471e to
d93b9b5
Compare
| , fileSource(other.fileSource) | ||
| , spriteLoader(std::make_unique<SpriteLoader>(pixelRatio)) | ||
| , light(std::make_unique<Light>(*other.light)) | ||
| , observer(&nullObserver) { |
There was a problem hiding this comment.
What about all the other members? images, sources, layers, etc.?
Copying the collections is going to be tricky. The wrapper classes should be copied, because they have an observer reference, while the immutable instances (and the immutable vector) should be shared.
Ideally, Style::Impl is itself held in an Immutable, and we move the wrappers, observers, Scheduler, FileSource, AsyncRequest, and SpriteLoader to Style. Then MapSnapshotter can accept an Immutable<Style::Impl> and doesn't have to handle making copies of anything, while the dirty work of copying all the wrappers and setting new observers can be centralized in Style(const Style&).
|
|
||
| var snapshotter = MGLMapSnapshotter(options: options) | ||
| snapshotter.start { (image, error) in | ||
| snapshotter.start { (snapshot, error) in |
There was a problem hiding this comment.
Add this example to MGLDocumentationExampleTests.swift, per these instructions for adding a code example. Otherwise, the next time someone generates runtime styling code, this block may get overwritten.
There was a problem hiding this comment.
Was missed when the sample was added apparently. Added it now and updated the code.
|
|
||
| /** | ||
| URL of the map style to snapshot. | ||
| */ |
There was a problem hiding this comment.
Nit: space before asterisk. (Sorry. 😬)
|
|
||
| /** | ||
| The zoom level. | ||
|
|
There was a problem hiding this comment.
For consistency, let’s match the language used in MGLMapSnapshotOptions documentation:
mapbox-gl-native/platform/darwin/src/MGLMapSnapshotter.h
Lines 32 to 35 in d913f4b
| mbgl::ScreenCoordinate sc = _pointForFn(MGLLatLngFromLocationCoordinate2D(coordinate)); | ||
| return NSMakePoint(sc.x * self.scale, sc.y * self.scale); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
FYI, on macOS, NSPoint is a typedef for CGPoint and NSMakePoint() calls CGPointMake(), so conditional compilation isn’t strictly necessary in the implementation.
| - (NSURL*)styleURL; | ||
| { | ||
| NSString *styleURLString = @(_mbglMapSnapshotter->getStyleURL().c_str()); | ||
| return styleURLString && styleURLString.length > 0 ? [NSURL URLWithString:styleURLString] : nil; |
There was a problem hiding this comment.
FYI, styleURLString.length ? … : nil is acceptable shorthand.
| - (NSURL*)styleURL; | ||
| { | ||
| NSString *styleURLString = @(_mbglMapSnapshotter->getStyleURL().c_str()); | ||
| return styleURLString && styleURLString.length > 0 ? [NSURL URLWithString:styleURLString] : nil; |
There was a problem hiding this comment.
Can styleURL be nil? If so, then the property should be declared nullable in the interface. Otherwise, we can assert here that the style is non-nil.
|
As discussed, Runtime Style support is going to need more effort to separate Style from Map on iOS (and Android in the next major release) #9914. Dropping from this PR. |
180c242 to
4a89384
Compare
|
@fabian-guerra @tobrun I finished up the wrappers and added the attributions to the callback so they are ready to use in the SDKs. Should be good to go. |
|
Played around with the Android code and is looking 👍 |
1ec5
left a comment
There was a problem hiding this comment.
These are good changes – thank you. On the iOS/macOS front, just one documentation request, a historical note, and a proposed improvement to the provided example code.
|
|
||
| /** | ||
| A camera representing the viewport visible in the snapshot. | ||
|
|
There was a problem hiding this comment.
Similarly to #10163 (comment), we should try to be consistent with the corresponding properties of MGLMapSnapshotOptions:
mapbox-gl-native/platform/darwin/src/MGLMapSnapshotter.h
Lines 40 to 44 in d913f4b
mapbox-gl-native/platform/darwin/src/MGLMapSnapshotter.h
Lines 49 to 52 in d913f4b
etc.
| _mbglMapSnapshotter.reset(); | ||
| } | ||
|
|
||
| - (NSURL*)styleURL; |
There was a problem hiding this comment.
The trailing semicolon here is technically incorrect, but GCC and Clang are lenient about it by default because it used to be very common a decade or so ago. (If I remember correctly, older versions of Interface Builder would generate boilerplate code for you that included the semicolon.) Just an FYI; I thought you might find it interesting. The most substantive issue is the space before the asterisk. 😛
| //#-example-code | ||
| let camera = MGLMapCamera() | ||
| camera.centerCoordinate = CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365) | ||
| camera.pitch = 20 |
There was a problem hiding this comment.
The preferred way to create a camera is via one of the other initializers, either MGLMapCamera(lookingAtCenter:fromEyeCoordinate:eyeAltitude:) or MGLMapCamera(lookingAtCenter:fromDistance:pitch:heading:). Following MapKit’s lead, these initializers encourage developers to make it clear as to whether the camera is based on a focused point on the map or an actor somewhere in space.
(You can specify whatever distance you want, since zoomLevel will override it below. #5583 would allow us to eliminate this awkward situation.)
There was a problem hiding this comment.
Just moved over the existing documentation, but I will adapt.
|
@ivovandongen noticing the following when implementing attribution on android: I'm getting back the following String: Would it be possible to exclude the Additionally the attribution was setup as String[], but these seem to be placed in a single string: Also there is an empty string that shouldn't be there. |
| }}; | ||
|
|
||
| // Collect all source attributions | ||
| std::vector<std::string> attributions; |
There was a problem hiding this comment.
By the way, we decided in #6465, we decided that mbgl wouldn’t be responsible for collecting each source’s attribution strings. I take it this is merely a stopgap until we have full runtime styling support for snapshots?
There was a problem hiding this comment.
The situation is slightly different here as the Map/Style/Sources live on another thread. This means we can't call them directly from the main thread and copying them over just to give access to the attribution strings seems like a waste. That's why I opted to pass them along with the snapshot result.
Most likely, there are two sources, and one has multiple links in its attribution HTML, while another has an empty string as its attribution HTML. It should be the job of platform-specific code to parse links out of the HTML and detect map feedback links, as it does in the usual case for interactive map views. |
|
Thank you for adding the context, will adapt the binding code accordingly |
…m latlng for snapshot - Wraps the TransformState for the snapshot so that the snapshotter itself is free to be re-used or destroyed
…o the pointFor functionality
4a89384 to
1c4b6a7
Compare

Some additions to the map snapshotter api