summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-17 15:36:10 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-19 14:24:59 -0700
commit7a5406bc5022d7fcdc92590012af7636155a49c7 (patch)
tree3a5d48be31aae12d676d4a223d2775e06acea572 /platform
parentbc9b52e0abe5d2616fe3f84c923e0083001e8732 (diff)
downloadqtlocation-mapboxgl-7a5406bc5022d7fcdc92590012af7636155a49c7.tar.gz
[ios] Update annotations instead of replacing them
When refreshing an annotation’s image, update the annotation instead of replacing it outright.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapView.mm47
1 files changed, 18 insertions, 29 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 526031f201..2120f2b7b6 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2370,11 +2370,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
{
- [self addAnnotations:annotations withAnnotationImage:nil];
-}
-
-- (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations withAnnotationImage:(MGLAnnotationImage *)explicitAnnotationImage
-{
if ( ! annotations) return;
[self willChangeValueForKey:@"annotations"];
@@ -2394,8 +2389,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
else
{
- MGLAnnotationImage *annotationImage = explicitAnnotationImage;
- if ( ! annotationImage && delegateImplementsImageForPoint)
+ MGLAnnotationImage *annotationImage;
+ if (delegateImplementsImageForPoint)
{
annotationImage = [self.delegate mapView:self imageForAnnotation:annotation];
}
@@ -2421,7 +2416,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
[annotationImages addObject:annotationImage];
- points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName ? [symbolName UTF8String] : "");
+ points.emplace_back(MGLLatLngFromLocationCoordinate2D(annotation.coordinate), symbolName.UTF8String ?: "");
}
}
@@ -3067,48 +3062,42 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (annotationImage.image)
{
// Add the new icon to the style.
- annotationImage.styleIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ NSString *updatedIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ annotationImage.styleIconIdentifier = updatedIconIdentifier;
[self installAnnotationImage:annotationImage];
if ([iconIdentifier isEqualToString:fallbackIconIdentifier])
{
- // Remove any annotations associated with the annotation image.
- NSMutableArray *annotationsToRecreate = [NSMutableArray array];
+ // Update any annotations associated with the annotation image.
for (auto &pair : _annotationContextsByAnnotationTag)
{
if ([pair.second.imageReuseIdentifier isEqualToString:reuseIdentifier])
{
- [annotationsToRecreate addObject:pair.second.annotation];
+ const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(pair.second.annotation.coordinate);
+ _mbglMap->updatePointAnnotation(pair.first, { latLng, updatedIconIdentifier.UTF8String ?: "" });
}
}
- [self removeAnnotations:annotationsToRecreate];
-
- // Recreate the annotations with the new icon.
- [self addAnnotations:annotationsToRecreate withAnnotationImage:annotationImage];
}
}
else
{
- // Remove any annotations associated with the annotation image.
- NSMutableArray *annotationsToRecreate = [NSMutableArray array];
+ // Add the default icon to the style if necessary.
+ annotationImage.styleIconIdentifier = fallbackIconIdentifier;
+ if ( ! [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName])
+ {
+ [self installAnnotationImage:self.defaultAnnotationImage];
+ }
+
+ // Update any annotations associated with the annotation image.
for (auto &pair : _annotationContextsByAnnotationTag)
{
if ([pair.second.imageReuseIdentifier isEqualToString:reuseIdentifier])
{
- [annotationsToRecreate addObject:pair.second.annotation];
+ const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(pair.second.annotation.coordinate);
+ _mbglMap->updatePointAnnotation(pair.first, { latLng, fallbackIconIdentifier.UTF8String ?: "" });
}
}
- [self removeAnnotations:annotationsToRecreate];
-
- // Recreate the annotations, falling back to the default icon.
- annotationImage.styleIconIdentifier = fallbackIconIdentifier;
- if ( ! [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName])
- {
- [self installAnnotationImage:self.defaultAnnotationImage];
- }
- [self addAnnotations:annotationsToRecreate withAnnotationImage:annotationImage];
}
- _mbglMap->update(mbgl::Update::Annotations);
}
#pragma mark - User Location -