Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Ignore multipoints when added as annotations #5262

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ - (void)dealloc
- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation
{
// Use GL backed pins for dropped pin annotations
if ([annotation isMemberOfClass:[MBXDroppedPinAnnotation class]])
if ([annotation isKindOfClass:[MBXDroppedPinAnnotation class]])
{
return nil;
}
Expand Down
14 changes: 8 additions & 6 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,10 @@ IB_DESIGNABLE
Adds an annotation to the map view.

@note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
cannot be added to the map view at this time. Any multipolyline,
multipolygon, or shape collection object that is passed into this method is
silently ignored.
cannot be added to the map view at this time. Nor can `MGLMultiPoint`
objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
multipoint, multipolyline, multipolygon, or shape collection object that is
specified is silently ignored.

@param annotation The annotation object to add to the receiver. This object
must conform to the `MGLAnnotation` protocol. The map view retains the
Expand All @@ -895,9 +896,10 @@ IB_DESIGNABLE
Adds an array of annotations to the map view.

@note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
cannot be added to the map view at this time. Any multipolyline,
multipolygon, or shape collection objects that are passed in are silently
ignored.
cannot be added to the map view at this time. Nor can `MGLMultiPoint`
objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
multipoint, multipolyline, multipolygon, or shape collection objects that
are specified are silently ignored.

@param annotations An array of annotation objects. Each object in the array
must conform to the `MGLAnnotation` protocol. The map view retains each
Expand Down
19 changes: 11 additions & 8 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,14 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations

if ([annotation isKindOfClass:[MGLMultiPoint class]])
{
// The multipoint knows how to style itself (with the map view’s help).
// Actual multipoints aren’t supported as annotations.
if ([annotation isMemberOfClass:[MGLMultiPoint class]]
|| [annotation isMemberOfClass:[MGLMultiPointFeature class]])
{
continue;
}

// The polyline or polygon knows how to style itself (with the map view’s help).
MGLMultiPoint *multiPoint = (MGLMultiPoint *)annotation;
if (!multiPoint.pointCount) {
continue;
Expand All @@ -2846,13 +2853,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
context.annotation = annotation;
_annotationContextsByAnnotationTag[annotationTag] = context;
}
else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
|| [annotation isKindOfClass:[MGLShapeCollection class]])
{
continue;
}
else
else if ( ! [annotation isKindOfClass:[MGLMultiPolyline class]]
|| ![annotation isKindOfClass:[MGLMultiPolygon class]]
|| ![annotation isKindOfClass:[MGLShapeCollection class]])
{
MGLAnnotationView *annotationView;
NSString *symbolName;
Expand Down
13 changes: 12 additions & 1 deletion platform/osx/app/MapDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
NSMutableArray *flattenedShapes = [NSMutableArray arrayWithCapacity:shapes.count];
for (id <MGLAnnotation> shape in shapes) {
NSArray *subshapes;
if ([shape isKindOfClass:[MGLMultiPolyline class]]) {
// Flatten multipoints but not polylines or polygons.
if ([shape isMemberOfClass:[MGLMultiPoint class]]) {
NSUInteger pointCount = [(MGLMultiPoint *)shape pointCount];
CLLocationCoordinate2D *coordinates = [(MGLMultiPoint *)shape coordinates];
NSMutableArray *pointAnnotations = [NSMutableArray arrayWithCapacity:pointCount];
for (NSUInteger i = 0; i < pointCount; i++) {
MGLPointAnnotation *pointAnnotation = [[MGLPointAnnotation alloc] init];
pointAnnotation.coordinate = coordinates[i];
[pointAnnotations addObject:pointAnnotation];
}
subshapes = pointAnnotations;
} else if ([shape isKindOfClass:[MGLMultiPolyline class]]) {
subshapes = [(MGLMultiPolyline *)shape polylines];
} else if ([shape isKindOfClass:[MGLMultiPolygon class]]) {
subshapes = [(MGLMultiPolygon *)shape polygons];
Expand Down
14 changes: 8 additions & 6 deletions platform/osx/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,10 @@ IB_DESIGNABLE
Adds an annotation to the map view.

@note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
cannot be added to the map view at this time. Any multipolyline,
multipolygon, or shape collection object that is passed into this method is
silently ignored.
cannot be added to the map view at this time. Nor can `MGLMultiPoint`
objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
multipoint, multipolyline, multipolygon, or shape collection object that is
specified is silently ignored.

@param annotation The annotation object to add to the receiver. This object
must conform to the `MGLAnnotation` protocol. The map view retains the
Expand All @@ -549,9 +550,10 @@ IB_DESIGNABLE
Adds an array of annotations to the map view.

@note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
cannot be added to the map view at this time. Any multipolyline,
multipolygon, or shape collection objects that are passed in are silently
ignored.
cannot be added to the map view at this time. Nor can `MGLMultiPoint`
objects that are not instances of `MGLPolyline` or `MGLPolygon`. Any
multipoint, multipolyline, multipolygon, or shape collection objects that
are specified are silently ignored.

@param annotations An array of annotation objects. Each object in the array
must conform to the `MGLAnnotation` protocol. The map view retains each
Expand Down
14 changes: 9 additions & 5 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,12 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"Annotation does not conform to MGLAnnotation");

if ([annotation isKindOfClass:[MGLMultiPoint class]]) {
// Actual multipoints aren’t supported as annotations.
if ([annotation isMemberOfClass:[MGLMultiPoint class]]
|| [annotation isMemberOfClass:[MGLMultiPointFeature class]]) {
continue;
}

// The multipoint knows how to style itself (with the map view’s help).
MGLMultiPoint *multiPoint = (MGLMultiPoint *)annotation;
if (!multiPoint.pointCount) {
Expand All @@ -1618,11 +1624,9 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
MGLAnnotationContext context;
context.annotation = annotation;
_annotationContextsByAnnotationTag[annotationTag] = context;
} else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
|| [annotation isKindOfClass:[MGLShapeCollection class]]) {
continue;
} else {
} else if (![annotation isKindOfClass:[MGLMultiPolyline class]]
|| ![annotation isKindOfClass:[MGLMultiPolygon class]]
|| ![annotation isKindOfClass:[MGLShapeCollection class]]) {
MGLAnnotationImage *annotationImage = nil;
if (delegateHasImagesForAnnotations) {
annotationImage = [self.delegate mapView:self imageForAnnotation:annotation];
Expand Down