summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-06-24 11:27:23 -0700
committerGitHub <noreply@github.com>2016-06-24 11:27:23 -0700
commitd9a1033b2a8b5d1068cca7a46d6b4a973ccab72b (patch)
tree9dd4ce44dcc87a116ba0accddd7449e2a39e5e39 /platform
parentd29bef957fe117158077a5af223d3cee14032ee2 (diff)
downloadqtlocation-mapboxgl-d9a1033b2a8b5d1068cca7a46d6b4a973ccab72b.tar.gz
[ios] Use transparent image for annotations backed by views (#5461)
The current implementation of view backed annotations mostly relies on the existing annotation model manager and the associated underlying boost query implementations for annotation management. However, since the representation of the model is a view, an image was not installed for view backed annotations. Because the underlying annotation management implementation is not entire comfortable working without an image, it would report `[INFO] {Worker}[Sprite]: Can't find sprite named 'default_marker'` when annotation models without an image were encountered. This updates the annotation adding logic in to create (or reuse) and install a small, invisible image for each view backed annotation.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapView.mm36
1 files changed, 32 insertions, 4 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 79a5f961b2..c0dacb50fe 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -88,6 +88,10 @@ const CLLocationDirection MGLToleranceForSnappingToNorth = 7;
/// Reuse identifier and file name of the default point annotation image.
static NSString * const MGLDefaultStyleMarkerSymbolName = @"default_marker";
+/// Reuse identifier and file name of the invisible point annotation image used
+/// by annotations that are visually backed by MGLAnnotationView objects
+static NSString * const MGLInvisibleStyleMarkerSymbolName = @"invisible_marker";
+
/// Prefix that denotes a sprite installed by MGLMapView, to avoid collisions
/// with style-defined sprites.
NSString *const MGLAnnotationSpritePrefix = @"com.mapbox.sprites.";
@@ -2861,6 +2865,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
annotationView.annotation = annotation;
annotationView.center = [self convertCoordinate:annotation.coordinate toPointToView:self];
[newAnnotationViews addObject:annotationView];
+
+ MGLAnnotationImage *annotationImage = self.invisibleAnnotationImage;
+ symbolName = annotationImage.styleIconIdentifier;
+ annotationImagesForAnnotation[annotationValue] = annotationImage;
+ if ( ! self.annotationImagesByIdentifier[annotationImage.reuseIdentifier])
+ {
+ [self installAnnotationImage:annotationImage];
+ }
}
}
@@ -2897,22 +2909,21 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
MGLAnnotationTag annotationTag = _mbglMap->addAnnotation(mbgl::SymbolAnnotation {
MGLPointFromLocationCoordinate2D(annotation.coordinate),
- symbolName.UTF8String ?: ""
+ symbolName.UTF8String
});
MGLAnnotationContext context;
context.annotation = annotation;
MGLAnnotationImage *annotationImage = annotationImagesForAnnotation[annotationValue];
+ context.imageReuseIdentifier = annotationImage.reuseIdentifier;
- if (annotationImage) {
- context.imageReuseIdentifier = annotationImage.reuseIdentifier;
- }
if (annotationView) {
context.annotationView = annotationView;
context.viewReuseIdentifier = annotationView.reuseIdentifier;
}
_annotationContextsByAnnotationTag[annotationTag] = context;
+
if ([annotation isKindOfClass:[NSObject class]]) {
NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint.");
[(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag];
@@ -2962,6 +2973,23 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
return annotationImage;
}
+- (MGLAnnotationImage *)invisibleAnnotationImage
+{
+ MGLAnnotationImage *annotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLInvisibleStyleMarkerSymbolName];
+
+ if (!annotationImage)
+ {
+ UIGraphicsBeginImageContext(CGSizeMake(1, 1));
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ annotationImage = [MGLAnnotationImage annotationImageWithImage:image
+ reuseIdentifier:MGLInvisibleStyleMarkerSymbolName];
+ annotationImage.styleIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
+ }
+
+ return annotationImage;
+}
+
- (MGLAnnotationView *)annotationViewForAnnotation:(id<MGLAnnotation>)annotation
{
MGLAnnotationView *annotationView = [self.delegate mapView:self viewForAnnotation:annotation];