-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
23b471e
to
d93b9b5
Compare
src/mbgl/style/style_impl.cpp
Outdated
, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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&)
.
@@ -101,7 +120,7 @@ typedef void (^MGLMapSnapshotCompletionHandler)(NSImage* _Nullable snapshot, NSE | |||
options.zoomLevel = 10 | |||
|
|||
var snapshotter = MGLMapSnapshotter(options: options) | |||
snapshotter.start { (image, error) in | |||
snapshotter.start { (snapshot, error) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was missed when the sample was added apparently. Added it now and updated the code.
/** | ||
URL of the map style to snapshot. | ||
*/ | ||
@property (nonatomic) NSURL* styleURL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space before asterisk. (Sorry. 😬)
@@ -139,6 +158,37 @@ MGL_EXPORT | |||
- (void)cancel; | |||
|
|||
/** | |||
The zoom level. | |||
|
|||
The default zoom level is 0. This overwrites the camera zoom level if set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
The zoom level. | |
The default zoom level is 0. If this property is non-zero and the camera property | |
is non-nil, the camera’s altitude is ignored in favor of this property’s value. |
mbgl::ScreenCoordinate sc = _pointForFn(MGLLatLngFromLocationCoordinate2D(coordinate)); | ||
return NSMakePoint(sc.x * self.scale, sc.y * self.scale); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | ||
|
||
This overwrites the coordinate bounds if set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
A camera representing the viewport visible in the snapshot. | |
If this property is non-nil and the `coordinateBounds` property is set to a non-empty | |
coordinate bounds, the camera’s center coordinate and altitude are ignored in favor | |
of the `coordinateBounds` property. |
mapbox-gl-native/platform/darwin/src/MGLMapSnapshotter.h
Lines 49 to 52 in d913f4b
The cooordinate rectangle that encompasses the bounds to capture. | |
If this property is non-empty and the camera property is non-nil, the camera’s | |
center coordinate and altitude are ignored in favor of this property’s value. |
etc.
@@ -186,4 +214,81 @@ - (void)cancel; | |||
_mbglMapSnapshotter.reset(); | |||
} | |||
|
|||
- (NSURL*)styleURL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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