summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRomain Quidet <romain.quidet.ext@mappy.com>2015-11-30 14:16:00 +0100
committerMinh Nguyễn <mxn@1ec5.org>2015-12-15 16:36:17 -0800
commit02a32b55e4ec392d213d435354bbcd2f33cef40c (patch)
treea4533ea19d8cd277aad14804fc2f3e15bce1b872 /platform
parent9d0ab5549ceb9da57293cf5259a4a00eb4383260 (diff)
downloadqtlocation-mapboxgl-02a32b55e4ec392d213d435354bbcd2f33cef40c.tar.gz
2210: MGLAnnotationImage image can be update
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLAnnotationImage.m15
-rw-r--r--platform/ios/MGLAnnotationImage_Private.h18
-rw-r--r--platform/ios/MGLMapView.mm16
3 files changed, 43 insertions, 6 deletions
diff --git a/platform/ios/MGLAnnotationImage.m b/platform/ios/MGLAnnotationImage.m
index cd211c52e6..ad560552ce 100644
--- a/platform/ios/MGLAnnotationImage.m
+++ b/platform/ios/MGLAnnotationImage.m
@@ -1,20 +1,20 @@
-#import "MGLAnnotationImage.h"
+#import "MGLAnnotationImage_Private.h"
@interface MGLAnnotationImage ()
-@property (nonatomic) UIImage *image;
-@property (nonatomic) NSString *reuseIdentifier;
+@property (nonatomic, strong) NSString *reuseIdentifier;
+@property (nonatomic, weak) id<MGLAnnotationImageDelegate> delegate;
@end
@implementation MGLAnnotationImage
-+ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier
++ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(nullable NSString *)reuseIdentifier
{
return [[self alloc] initWithImage:image reuseIdentifier:reuseIdentifier];
}
-- (instancetype)initWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier
+- (instancetype)initWithImage:(UIImage *)image reuseIdentifier:(nullable NSString *)reuseIdentifier
{
self = [super init];
@@ -28,4 +28,9 @@
return self;
}
+- (void)setImage:(UIImage *)image {
+ _image = image;
+ [self.delegate annotationImageNeedsRedisplay:self];
+}
+
@end
diff --git a/platform/ios/MGLAnnotationImage_Private.h b/platform/ios/MGLAnnotationImage_Private.h
new file mode 100644
index 0000000000..f22a9ac4e2
--- /dev/null
+++ b/platform/ios/MGLAnnotationImage_Private.h
@@ -0,0 +1,18 @@
+#import "MGLAnnotationImage.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@protocol MGLAnnotationImageDelegate <NSObject>
+
+@required
+- (void)annotationImageNeedsRedisplay:(MGLAnnotationImage *)annotationImage;
+
+@end
+
+@interface MGLAnnotationImage (Private)
+
+@property (nonatomic, weak) id<MGLAnnotationImageDelegate> delegate;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 9050773a87..fc4a655e6f 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -36,6 +36,7 @@
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
#import "MGLAccountManager_Private.h"
+#import "MGLAnnotationImage_Private.h"
#import "MGLMapboxEvents.h"
#import "SMCalloutView.h"
@@ -120,7 +121,8 @@ public:
CLLocationManagerDelegate,
UIActionSheetDelegate,
SMCalloutViewDelegate,
- MGLMultiPointDelegate>
+ MGLMultiPointDelegate,
+ MGLAnnotationImageDelegate>
@property (nonatomic) EAGLContext *context;
@property (nonatomic) GLKView *glView;
@@ -2166,6 +2168,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
{
self.annotationImagesByIdentifier[annotationImage.reuseIdentifier] = annotationImage;
[self installAnnotationImage:annotationImage];
+ annotationImage.delegate = self;
}
NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
@@ -2709,6 +2712,17 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
animated:animated];
}
+#pragma mark Annotation Image Delegate
+
+- (void)annotationImageNeedsRedisplay:(MGLAnnotationImage *)annotationImage
+{
+ // remove sprite
+ NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ _mbglMap->removeSprite(symbolName.UTF8String);
+ [self installAnnotationImage:annotationImage];
+ _mbglMap->update(mbgl::Update::Annotations);
+}
+
#pragma mark - User Location -
- (void)setShowsUserLocation:(BOOL)showsUserLocation