summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-01-06 15:13:39 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-01-06 23:43:07 -0800
commit11d99bd890ef2cbadc16beb7289dd818fa86c9df (patch)
tree6b7650c5675fdd0c3b0719e4262ffc4213b83843 /platform
parentb70fd7ae6947e9d0c2f4b2a2d23069cedac5fa4a (diff)
downloadqtlocation-mapboxgl-11d99bd890ef2cbadc16beb7289dd818fa86c9df.tar.gz
[ios] Refined custom callout view support
Renamed MGLCalloutView to MGLCompactCalloutView and MGLCalloutViewProtocol to MGLCalloutView to avoid an awkward workaround for a Swift name collision. Replaced individual title and subtitle properties with a single representedObject property that lets you use custom annotation properties in the custom callout view. Overrode a problematic SMCalloutView method. Added lots more documentation.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLCalloutView.h6
-rw-r--r--platform/ios/src/MGLCalloutView.m5
-rw-r--r--platform/ios/src/MGLCompactCalloutView.h11
-rw-r--r--platform/ios/src/MGLCompactCalloutView.m31
-rw-r--r--platform/ios/src/MGLMapView.mm21
5 files changed, 51 insertions, 23 deletions
diff --git a/platform/ios/src/MGLCalloutView.h b/platform/ios/src/MGLCalloutView.h
deleted file mode 100644
index aa5cb95b57..0000000000
--- a/platform/ios/src/MGLCalloutView.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#import "SMCalloutView.h"
-#import "MGLCalloutViewProtocol.h"
-
-@interface MGLCalloutView : SMCalloutView <MGLCalloutViewProtocol>
-
-@end
diff --git a/platform/ios/src/MGLCalloutView.m b/platform/ios/src/MGLCalloutView.m
deleted file mode 100644
index 8fc7cdc08d..0000000000
--- a/platform/ios/src/MGLCalloutView.m
+++ /dev/null
@@ -1,5 +0,0 @@
-#import "MGLCalloutView.h"
-
-@implementation MGLCalloutView
-
-@end
diff --git a/platform/ios/src/MGLCompactCalloutView.h b/platform/ios/src/MGLCompactCalloutView.h
new file mode 100644
index 0000000000..5f8edd921f
--- /dev/null
+++ b/platform/ios/src/MGLCompactCalloutView.h
@@ -0,0 +1,11 @@
+#import "SMCalloutView.h"
+#import "MGLCalloutView.h"
+
+/**
+ A concrete implementation of `MGLCalloutView` based on [SMCalloutView](https://github.com/nfarina/calloutview). This callout view displays the represented annotation’s title, subtitle, and accessory views in a compact, two-line layout.
+ */
+@interface MGLCompactCalloutView : SMCalloutView <MGLCalloutView>
+
++ (instancetype)platformCalloutView;
+
+@end
diff --git a/platform/ios/src/MGLCompactCalloutView.m b/platform/ios/src/MGLCompactCalloutView.m
new file mode 100644
index 0000000000..49812c51a4
--- /dev/null
+++ b/platform/ios/src/MGLCompactCalloutView.m
@@ -0,0 +1,31 @@
+#import "MGLCompactCalloutView.h"
+
+#import "MGLAnnotation.h"
+
+@implementation MGLCompactCalloutView
+{
+ id <MGLAnnotation> _representedObject;
+}
+
+@synthesize representedObject = _representedObject;
+
++ (instancetype)platformCalloutView
+{
+ return [[self alloc] init];
+}
+
+- (void)setRepresentedObject:(id <MGLAnnotation>)representedObject
+{
+ _representedObject = representedObject;
+
+ if ([representedObject respondsToSelector:@selector(title)])
+ {
+ self.title = representedObject.title;
+ }
+ if ([representedObject respondsToSelector:@selector(subtitle)])
+ {
+ self.subtitle = representedObject.subtitle;
+ }
+}
+
+@end
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index ce42fefe3f..c0909f873d 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -39,7 +39,7 @@
#import "MGLAccountManager_Private.h"
#import "MGLAnnotationImage_Private.h"
#import "MGLMapboxEvents.h"
-#import "MGLCalloutView.h"
+#import "MGLCompactCalloutView.h"
#import <algorithm>
#import <cstdlib>
@@ -138,7 +138,7 @@ public:
/// Mapping from reusable identifiers to annotation images.
@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImagesByIdentifier;
/// Currently shown popover representing the selected annotation.
-@property (nonatomic) UIView<MGLCalloutViewProtocol> *calloutViewForSelectedAnnotation;
+@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation;
@property (nonatomic) MGLUserLocationAnnotationView *userLocationAnnotationView;
@property (nonatomic) CLLocationManager *locationManager;
@property (nonatomic) CGPoint centerPoint;
@@ -1341,12 +1341,12 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
}
}
-- (BOOL)calloutViewShouldHighlight:(__unused MGLCalloutView *)calloutView
+- (BOOL)calloutViewShouldHighlight:(__unused MGLCompactCalloutView *)calloutView
{
return [self.delegate respondsToSelector:@selector(mapView:tapOnCalloutForAnnotation:)];
}
-- (void)calloutViewClicked:(__unused MGLCalloutView *)calloutView
+- (void)calloutViewTapped:(__unused MGLCompactCalloutView *)calloutView
{
if ([self.delegate respondsToSelector:@selector(mapView:tapOnCalloutForAnnotation:)])
{
@@ -2514,9 +2514,9 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
[self.delegate mapView:self annotationCanShowCallout:annotation])
{
// build the callout
- if ([self.delegate respondsToSelector:@selector(mapView:customCalloutViewForAnnotation:)])
+ if ([self.delegate respondsToSelector:@selector(mapView:calloutViewForAnnotation:)])
{
- self.calloutViewForSelectedAnnotation = [self.delegate mapView:self customCalloutViewForAnnotation:annotation];
+ self.calloutViewForSelectedAnnotation = [self.delegate mapView:self calloutViewForAnnotation:annotation];
}
if (!self.calloutViewForSelectedAnnotation)
{
@@ -2576,13 +2576,10 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
}
}
-- (MGLCalloutView *)calloutViewForAnnotation:(id <MGLAnnotation>)annotation
+- (MGLCompactCalloutView *)calloutViewForAnnotation:(id <MGLAnnotation>)annotation
{
- MGLCalloutView *calloutView = (MGLCalloutView *)[MGLCalloutView platformCalloutView];
-
- if ([annotation respondsToSelector:@selector(title)]) calloutView.title = annotation.title;
- if ([annotation respondsToSelector:@selector(subtitle)]) calloutView.subtitle = annotation.subtitle;
-
+ MGLCompactCalloutView *calloutView = [MGLCompactCalloutView platformCalloutView];
+ calloutView.representedObject = annotation;
calloutView.tintColor = self.tintColor;
return calloutView;