Repository navigation
[ios, macos] Add attribution to snapshots. - #10352
Conversation
f7ac41f to
312e915
Compare
|
@1ec5 what would be the best approach to draw the background? I've tried to draw a NSView/UIView directly to the graphic context but it doesn't get rendered. |
|
This PR will fix #10114. |
There was a problem hiding this comment.
If a shorter info follows a taller info, attributionBackgroundHeight will wind up with the shorter info’s height. MAX() would address that scenario.
There was a problem hiding this comment.
As general code hygiene, use CGFloat for individual x and y values, or preferably combine them into a CGPoint.
There was a problem hiding this comment.
Combine these CGFloats into a CGSize.
By default, NSView and UIView can only draw on the main thread. Could that be the issue? In any case, it isn’t necessary to match the macOS SDK’s MGLMapView attribution design pixel-for-pixel: if it’s more convenient to draw the same CIFilter effects without the use of a view, that would be perfectly reasonable. |
There was a problem hiding this comment.
The macOS SDK positions the attribution view toward the bottom-left corner of MGLMapView, to the right of the logo view, because the zooming and rotation controls are located in the bottom-right corner by default. But there aren’t any zooming or rotation controls in snapshots, so it would be more consistent with other platforms to place the attribution at the bottom-right corner.
888ed3a to
86ee34d
Compare
86ee34d to
1676461
Compare
| UIGraphicsEndImageContext(); | ||
| #else | ||
| NSImage *logoImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mgl_frameworkBundle] pathForResource:@"mapbox" ofType:@"pdf"]]; | ||
| NSImage *attributionBackgroundImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mgl_frameworkBundle] pathForResource:@"attribution_background" ofType:@"pdf"]]; |
There was a problem hiding this comment.
attribution_background.pdf looks very simple – couldn’t we implement the same effect using image compositing APIs such as the ones provided by Core Image? Additionally, the screenshot in #10352 (comment) shows that a simple translucent background doesn’t adequately ensure readability atop labels. Let’s try to find a way to reuse this code without necessarily using a view:
mapbox-gl-native/platform/macos/src/MGLMapView.mm
Lines 387 to 404 in c247211
| [logoImage drawInRect:logoImageRect]; | ||
|
|
||
| CGPoint attributionTextPosition = CGPointMake(targetFrame.size.width - 10 - attributionBackgroundSize.width, | ||
| logoImageRect.origin.y + (logoImageRect.size.height / 2) - (attributionBackgroundSize.height / 2)); |
There was a problem hiding this comment.
As tail work, we’ll have to figure out how to shrink attribution in narrower images, especially when there are multiple attribution strings, as in Mapbox Satellite Streets. Possibilities include replacing the logo image with one that omits the wordmark and also abbreviating some commonly attributed names.
dba6cdc to
34d6f3d
Compare
34d6f3d to
1745810
Compare
1ec5
left a comment
There was a problem hiding this comment.
This PR looks good. Added some feedback that could be useful as tail work or in this PR if you get to it.
|
|
||
| [logoImage drawInRect:logoImageRect]; | ||
|
|
||
| NSRect cropRect = NSMakeRect(attributionTextPosition.x, MGLLogoImagePosition.y + 1, attributionBackgroundSize.width, attributionBackgroundSize.height); |
There was a problem hiding this comment.
What should we do if the logo and attribution text overlap? This can also be tail work, but I wonder if there’s a quick fix in that case, like bumping the logo up above the attribution text and left-aligning the attribution text. (Or would that be too unpredictable?)
|
|
||
| NSImage *blurredAttributionBackground = [self blurredAttributionBackground:attributionBackgroundImage]; | ||
|
|
||
| [blurredAttributionBackground drawInRect:CGRectMake(attributionTextPosition.x, MGLLogoImagePosition.y + 1, attributionBackgroundSize.width, attributionBackgroundSize.height)]; |
There was a problem hiding this comment.
There’s quite a bit of duplicated logic between iOS and macOS. Could we factor out any common code, taking advantage of the fact that NSRect, NSPoint, and NSSize are typedefs of CGRect, CGPoint, and CGSize, respectively?



Fixes #10114