diff options
Diffstat (limited to 'platform/darwin/src/MGLAttributionInfo.mm')
-rw-r--r-- | platform/darwin/src/MGLAttributionInfo.mm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm index ce63a25422..73147270c1 100644 --- a/platform/darwin/src/MGLAttributionInfo.mm +++ b/platform/darwin/src/MGLAttributionInfo.mm @@ -127,6 +127,15 @@ return self; } +- (id)copyWithZone:(nullable NSZone *)zone +{ + MGLAttributionInfo *info = [[[self class] allocWithZone:zone] initWithTitle:_title + URL:_URL]; + info.feedbackLink = _feedbackLink; + + return info; +} + - (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel { return [self feedbackURLForStyleURL:nil atCenterCoordinate:centerCoordinate zoomLevel:zoomLevel direction:0 pitch:0]; } @@ -160,6 +169,25 @@ return components.URL; } +- (NSAttributedString *)titleWithStyle:(MGLAttributionInfoStyle)style +{ + NSString *openStreetMap = NSLocalizedStringWithDefaultValue(@"OSM_FULL_NAME", @"Foundation", nil, @"OpenStreetMap", @"OpenStreetMap full name attribution"); + NSString *OSM = NSLocalizedStringWithDefaultValue(@"OSM_SHORT_NAME", @"Foundation", nil, @"OSM", @"OpenStreetMap short name attribution"); + + NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithAttributedString:self.title]; + [title removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, [title.string length])]; + + BOOL isAbbreviated = (style == MGLAttributionInfoStyleShort); + + if ([title.string rangeOfString:@"OpenStreetMap"].location != NSNotFound) { + [title.mutableString replaceOccurrencesOfString:@"OpenStreetMap" withString:isAbbreviated ? OSM : openStreetMap + options:NSCaseInsensitiveSearch + range:NSMakeRange(0, [title.mutableString length])]; + } + + return title; +} + - (BOOL)isEqual:(id)object { return [object isKindOfClass:[self class]] && [[object title] isEqual:self.title] && [[object URL] isEqual:self.URL]; } |