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

[ios, macos] Add attribution to snapshots. - #10352

Merged
fabian-guerra merged 1 commit into
release-aguafrom
fabian-snapshot-attribution-10114
Nov 7, 2017
Merged

fabian-guerra merged 1 commit into
release-aguafrom
fabian-snapshot-attribution-10114

Conversation

@fabian-guerra

@fabian-guerra fabian-guerra commented Nov 1, 2017 •

Copy link
Copy Markdown
Contributor

Fixes #10114

@fabian-guerra
fabian-guerra force-pushed the fabian-snapshot-attribution-10114 branch from f7ac41f to 312e915 Compare November 2, 2017 22:53
@fabian-guerra
fabian-guerra requested a review from 1ec5 November 2, 2017 22:53
@fabian-guerra

Copy link
Copy Markdown
Contributor Author

@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 is how it looks for now.
attribution

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release labels Nov 3, 2017
@1ec5

1ec5 commented Nov 3, 2017

Copy link
Copy Markdown
Contributor

This PR will fix #10114.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: background.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If a shorter info follows a taller info, attributionBackgroundHeight will wind up with the shorter info’s height. MAX() would address that scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As general code hygiene, use CGFloat for individual x and y values, or preferably combine them into a CGPoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Combine these CGFloats into a CGSize.

@1ec5

1ec5 commented Nov 3, 2017

Copy link
Copy Markdown
Contributor

I've tried to draw a NSView/UIView directly to the graphic context but it doesn't get rendered.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@fabian-guerra
fabian-guerra force-pushed the fabian-snapshot-attribution-10114 branch 4 times, most recently from 888ed3a to 86ee34d Compare November 3, 2017 18:34
@fabian-guerra

Copy link
Copy Markdown
Contributor Author

This is how it looks on iOS
screen shot 2017-11-03 at 2 29 08 pm

macOS
screen shot 2017-11-03 at 2 35 47 pm

@fabian-guerra fabian-guerra self-assigned this Nov 3, 2017
@fabian-guerra
fabian-guerra force-pushed the fabian-snapshot-attribution-10114 branch from 86ee34d to 1676461 Compare November 3, 2017 19:19
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"]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

// Make the background and foreground translucent to be unobtrusive.
_attributionView.layer.opacity = 0.6;
// Blur the background to prevent text underneath the view from running into
// the text in the view, rendering it illegible.
CIFilter *attributionBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[attributionBlurFilter setDefaults];
// Brighten the background. This is similar to applying a translucent white
// background on the view, but the effect is a bit more subtle and works
// well with the blur above.
CIFilter *attributionColorFilter = [CIFilter filterWithName:@"CIColorControls"];
[attributionColorFilter setDefaults];
[attributionColorFilter setValue:@(0.1) forKey:kCIInputBrightnessKey];
// Apply the background effects and a standard button corner radius.
_attributionView.backgroundFilters = @[attributionColorFilter, attributionBlurFilter];
_attributionView.layer.cornerRadius = 4;

[logoImage drawInRect:logoImageRect];

CGPoint attributionTextPosition = CGPointMake(targetFrame.size.width - 10 - attributionBackgroundSize.width,
logoImageRect.origin.y + (logoImageRect.size.height / 2) - (attributionBackgroundSize.height / 2));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@fabian-guerra
fabian-guerra force-pushed the fabian-snapshot-attribution-10114 branch 3 times, most recently from dba6cdc to 34d6f3d Compare November 7, 2017 21:51
@fabian-guerra
fabian-guerra force-pushed the fabian-snapshot-attribution-10114 branch from 34d6f3d to 1745810 Compare November 7, 2017 21:55

@1ec5 1ec5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@fabian-guerra
fabian-guerra merged commit 93e363b into release-agua Nov 7, 2017
@fabian-guerra
fabian-guerra deleted the fabian-snapshot-attribution-10114 branch November 7, 2017 22:56
@lilykaiser lilykaiser added this to the ios-v3.7.0 milestone Nov 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants