summaryrefslogtreecommitdiff
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
parent9d0ab5549ceb9da57293cf5259a4a00eb4383260 (diff)
downloadqtlocation-mapboxgl-02a32b55e4ec392d213d435354bbcd2f33cef40c.tar.gz
2210: MGLAnnotationImage image can be update
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--include/mbgl/ios/MGLAnnotationImage.h4
-rw-r--r--platform/ios/MGLAnnotationImage.m15
-rw-r--r--platform/ios/MGLAnnotationImage_Private.h18
-rw-r--r--platform/ios/MGLMapView.mm16
5 files changed, 46 insertions, 8 deletions
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index 9ae44b2d45..d510d25c03 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -60,6 +60,7 @@
'../platform/ios/MGLUserLocationAnnotationView.h',
'../platform/ios/MGLUserLocationAnnotationView.m',
'../include/mbgl/ios/MGLAnnotationImage.h',
+ '../platform/ios/MGLAnnotationImage_Private.h',
'../platform/ios/MGLAnnotationImage.m',
'../platform/ios/MGLCategoryLoader.h',
'../platform/ios/MGLCategoryLoader.m',
diff --git a/include/mbgl/ios/MGLAnnotationImage.h b/include/mbgl/ios/MGLAnnotationImage.h
index 70bf8b7599..efc79ffb90 100644
--- a/include/mbgl/ios/MGLAnnotationImage.h
+++ b/include/mbgl/ios/MGLAnnotationImage.h
@@ -13,12 +13,12 @@ NS_ASSUME_NONNULL_BEGIN
* @param image The image to be displayed for the annotation.
* @param reuseIdentifier The string that identifies that this annotation image is reusable.
* @return The initialized annotation image object or `nil` if there was a problem initializing the object. */
-+ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier;
++ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(nullable NSString *)reuseIdentifier;
/** @name Getting and Setting Attributes */
/** The image to be displayed for the annotation. */
-@property (nonatomic, readonly) UIImage *image;
+@property (nonatomic, strong) UIImage *image;
/** The string that identifies that this annotation image is reusable. (read-only)
*
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