summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-08 17:43:17 -0800
committerGitHub <noreply@github.com>2016-12-08 17:43:17 -0800
commitfe53af7de031e296cdb9b0a7e88688fd3f54e0d8 (patch)
treed51f217f5e90db30fb4447c17cf899c678688ed9 /platform/ios/src
parent89d4c40d927388f44e00e004e8a22db2d1b2eeab (diff)
downloadqtlocation-mapboxgl-fe53af7de031e296cdb9b0a7e88688fd3f54e0d8.tar.gz
[ios, macos] Source-driven attribution (#5999)
* [ios, macos] Source-driven attribution Refactored MGLSource initialization. Implemented a new private class, MGLAttributionInfo, that parses an HTML attribution string from TileJSON and stores the resulting structured data. Added methods to MGLTileSet and MGLStyle to aggregate MGLAttributionInfos. On macOS, update the attribution view as soon as the source attribution changes. On iOS, fetch the current attribution information when displaying the action sheet. Removed hard-coded attribution strings. * [macos] Respect inline formatting in attribution HTML Apply a default font and color to attribution HTML as it is imported into an attributed string. Pass the attributed string into MGLAttributionButton as is, without stripping formatting. Avoid overriding the font and color after importing the HTML, in case these attributes are explicitly specified rather than intrinsic to a hyperlink. Constrain the top of the attribution view to all the attribution buttons, in case one of them needs additional headspace. * [ios, macos] Display unlinked attribution strings Unlinked attribution strings are represented on macOS as buttons that have the default cursor and do nothing when clicked. On iOS, they are action sheet buttons that do nothing but dismiss the action sheet. * [macos] Fixed random Auto Layout exception Auto Layout randomly finds itself unable to satisfy constraints when updating attribution, due to some spurious constraints between attribution buttons. Regenerate the entire attribution view every time the source attribution changes. * [ios, macos] Thoroughly dedupe attribution infos Also added a test to verify parity with the GL JS implementation. This implementation avoids sorting. * [ios, macos] Trim whitespace from attribution strings Also added parsing tests. * [ios, macos] Added attribution parsing tests for styles Included an emoji test to ensure that attribution strings are interpreted as UTF-8, to avoid mojibake. Included a test of removing the underline from a leading copyright symbol. * [ios, macos] Derive feedback link from source MGLAttributionInfo now detects feedback links in the attribution HTML code, and it is responsible for tailoring the feedback URL to the current viewport. Removed the hard-coded feedback action from the attribution sheet on iOS in favor of a source-derived feedback title and URL. Moved the feedback action from macosapp to MGLMapView; applications are now expected to hook an Improve This Map menu item to an MGLMapView action.
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLMapView.mm65
1 files changed, 34 insertions, 31 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 3ee03182a8..c67105b9e7 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -55,6 +55,7 @@
#import "MGLCompactCalloutView.h"
#import "MGLAnnotationContainerView.h"
#import "MGLAnnotationContainerView_Private.h"
+#import "MGLAttributionInfo.h"
#include <algorithm>
#include <cstdlib>
@@ -310,6 +311,8 @@ public:
BOOL _delegateHasLineWidthsForShapeAnnotations;
MGLCompassDirectionFormatter *_accessibilityCompassFormatter;
+
+ NS_ARRAY_OF(MGLAttributionInfo *) *_attributionInfos;
}
#pragma mark - Setup & Teardown -
@@ -1714,44 +1717,27 @@ public:
- (void)showAttribution
{
- if ( ! self.attributionSheet)
+ self.attributionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedStringWithDefaultValue(@"SDK_NAME", nil, nil, @"Mapbox iOS SDK", @"Action sheet title")
+ delegate:self
+ cancelButtonTitle:NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"")
+ destructiveButtonTitle:nil
+ otherButtonTitles:nil];
+
+ _attributionInfos = [self.style attributionInfosWithFontSize:[UIFont buttonFontSize] linkColor:nil];
+ for (MGLAttributionInfo *info in _attributionInfos)
{
- self.attributionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedStringWithDefaultValue(@"SDK_NAME", nil, nil, @"Mapbox iOS SDK", @"Action sheet title")
- delegate:self
- cancelButtonTitle:NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"")
- destructiveButtonTitle:nil
- otherButtonTitles:
- NSLocalizedStringWithDefaultValue(@"COPY_MAPBOX", nil, nil, @"© Mapbox", @"Copyright notice in attribution sheet"),
- NSLocalizedStringWithDefaultValue(@"COPY_OSM", nil, nil, @"© OpenStreetMap", @"Copyright notice in attribution sheet"),
- NSLocalizedStringWithDefaultValue(@"MAP_FEEDBACK", nil, nil, @"Improve This Map", @"Action in attribution sheet"),
- NSLocalizedStringWithDefaultValue(@"TELEMETRY_NAME", nil, nil, @"Mapbox Telemetry", @"Action in attribution sheet"),
- nil];
-
+ NSString *title = [info.title.string capitalizedStringWithLocale:[NSLocale currentLocale]];
+ [self.attributionSheet addButtonWithTitle:title];
}
-
+
+ [self.attributionSheet addButtonWithTitle:NSLocalizedStringWithDefaultValue(@"TELEMETRY_NAME", nil, nil, @"Mapbox Telemetry", @"Action in attribution sheet")];
+
[self.attributionSheet showFromRect:self.attributionButton.frame inView:self animated:YES];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
- if (buttonIndex == actionSheet.firstOtherButtonIndex)
- {
- [[UIApplication sharedApplication] openURL:
- [NSURL URLWithString:@"https://www.mapbox.com/about/maps/"]];
- }
- else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1)
- {
- [[UIApplication sharedApplication] openURL:
- [NSURL URLWithString:@"http://www.openstreetmap.org/about/"]];
- }
- else if (buttonIndex == actionSheet.firstOtherButtonIndex + 2)
- {
- NSString *feedbackURL = [NSString stringWithFormat:@"https://www.mapbox.com/map-feedback/#/%.5f/%.5f/%i",
- self.longitude, self.latitude, (int)round(self.zoomLevel + 1)];
- [[UIApplication sharedApplication] openURL:
- [NSURL URLWithString:feedbackURL]];
- }
- else if (buttonIndex == actionSheet.firstOtherButtonIndex + 3)
+ if (buttonIndex == actionSheet.numberOfButtons - 1)
{
NSString *message;
NSString *participate;
@@ -1777,6 +1763,19 @@ public:
otherButtonTitles:NSLocalizedStringWithDefaultValue(@"TELEMETRY_MORE", nil, nil, @"Tell Me More", @"Telemetry prompt button"), optOut, nil];
[alert show];
}
+ else if (buttonIndex > 0)
+ {
+ MGLAttributionInfo *info = _attributionInfos[buttonIndex + actionSheet.firstOtherButtonIndex];
+ NSURL *url = info.URL;
+ if (url)
+ {
+ if (info.feedbackLink)
+ {
+ url = [info feedbackURLAtCenterCoordinate:self.centerCoordinate zoomLevel:self.zoomLevel];
+ }
+ [[UIApplication sharedApplication] openURL:url];
+ }
+ }
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
@@ -4694,6 +4693,10 @@ public:
}
break;
}
+ case mbgl::MapChangeSourceDidChange:
+ {
+ break;
+ }
}
}