2210: MGLAnnotationImage image can be update
This commit is contained in:
committed by
Minh Nguyễn
parent
9d0ab5549c
commit
02a32b55e4
@@ -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',
|
||||
|
||||
@@ -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)
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
18
platform/ios/MGLAnnotationImage_Private.h
Normal file
18
platform/ios/MGLAnnotationImage_Private.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user