summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLAttributionInfo.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLAttributionInfo.mm')
-rw-r--r--platform/darwin/src/MGLAttributionInfo.mm21
1 files changed, 19 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm
index 2719aef7ca..cf7b3cb22f 100644
--- a/platform/darwin/src/MGLAttributionInfo.mm
+++ b/platform/darwin/src/MGLAttributionInfo.mm
@@ -1,4 +1,4 @@
-#import "MGLAttributionInfo.h"
+#import "MGLAttributionInfo_Private.h"
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
@@ -7,13 +7,18 @@
#endif
#import "MGLMapCamera.h"
+#import "NSArray+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
#include <string>
@implementation MGLAttributionInfo
-+ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor {
++ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(nullable NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor {
+ if (!htmlString) {
+ return @[];
+ }
+
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding),
@@ -84,6 +89,18 @@
return infos;
}
++ (NSAttributedString *)attributedStringForAttributionInfos:(NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfos {
+ NSMutableArray *titles = [NSMutableArray arrayWithCapacity:attributionInfos.count];
+ for (MGLAttributionInfo *info in attributionInfos) {
+ NSMutableAttributedString *title = info.title.mutableCopy;
+ if (info.URL) {
+ [title addAttribute:NSLinkAttributeName value:info.URL range:title.mgl_wholeRange];
+ }
+ [titles addObject:title];
+ }
+ return [titles mgl_attributedComponentsJoinedByString:@" "];
+}
+
- (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL {
if (self = [super init]) {
_title = title;