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

Commit

Permalink
[ios, osx] Ignore compound shape types as annotations
Browse files Browse the repository at this point in the history
Ignore any multipolyline, multipolygon, or shape collection object passed into -addAnnotation: or -addAnnotations:. Previously, these methods broke apart the compound shape into its constituent shapes in order to recursively add them to the map. But that broke assumptions about a one-to-one correspondence between annotations and their contexts during selection and deletion.
  • Loading branch information
1ec5 committed May 27, 2016
1 parent d0ea7c3 commit 354396a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
5 changes: 3 additions & 2 deletions platform/darwin/src/MGLFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ NS_ASSUME_NONNULL_BEGIN
Typically, you do not create feature objects yourself but rather obtain them
using `-[MGLMapView visibleFeaturesAtPoint:]` and related methods. Each feature
object associates a shape with an identifier and attributes as specified by the
source. Like any `MGLAnnotation` object, an `MGLFeature` object can be added to
a map view using `-[MGLMapView addAnnotations:]` and related methods.
source. Like ordinary `MGLAnnotation` objects, some kinds of `MGLFeature`
objects can also be added to a map view using `-[MGLMapView addAnnotations:]`
and related methods.
*/
@protocol MGLFeature <MGLAnnotation>

Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ NS_ASSUME_NONNULL_BEGIN
object to represent an atoll together with an island in the atoll’s lagoon:
the atoll itself would be one `MGLPolygon` object, while the inner island would
be another.
@note `MGLMultiPolygon` objects cannot be added to a map view using
`-[MGLMapView addAnnotations:]` and related methods.
*/
@interface MGLMultiPolygon : MGLShape <MGLOverlay>

Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
both sides of a divided highway (dual carriageway), excluding the median
(central reservation): each carriageway would be a distinct `MGLPolyline`
object.
@note `MGLMultiPolyline` objects cannot be added to a map view using
`-[MGLMapView addAnnotations:]` and related methods.
*/
@interface MGLMultiPolyline : MGLShape <MGLOverlay>

Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLShapeCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ NS_ASSUME_NONNULL_BEGIN
The `MGLShapeCollection` class represents a shape consisting of one or more
distinct but related shapes that are instances of `MGLShape`. The constituent
shapes can be a mixture of different kinds of shapes.
@note `MGLShapeCollection` objects cannot be added to a map view using
`-[MGLMapView addAnnotations:]` and related methods.
*/
@interface MGLShapeCollection : MGLShape

Expand Down
10 changes: 10 additions & 0 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,11 @@ 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.
@param annotation The annotation object to add to the receiver. This object
must conform to the `MGLAnnotation` protocol. The map view retains the
annotation object. */
Expand All @@ -889,6 +894,11 @@ 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.
@param annotations An array of annotation objects. Each object in the array
must conform to the `MGLAnnotation` protocol. The map view retains each
individual annotation object.
Expand Down
18 changes: 4 additions & 14 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2819,21 +2819,11 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
shapes.emplace_back(multiPoint.annotationSegments, [multiPoint shapeAnnotationPropertiesObjectWithDelegate:self]);
[userShapes addObject:annotation];
}
else if ([annotation isKindOfClass:[MGLMultiPolyline class]])
else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
|| [annotation isKindOfClass:[MGLShapeCollection class]])
{
// TODO: Add real support for these types down in mbgl instead of breaking the annotation apart.
NS_ARRAY_OF(MGLPolyline *) *polylines = [(MGLMultiPolyline *)annotation polylines];
[self addAnnotations:polylines];
}
else if ([annotation isKindOfClass:[MGLMultiPolygon class]])
{
NS_ARRAY_OF(MGLPolygon *) *polygons = [(MGLMultiPolygon *)annotation polygons];
[self addAnnotations:polygons];
}
else if ([annotation isKindOfClass:[MGLShapeCollection class]])
{
NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *shapes = [(MGLShapeCollection *)annotation shapes];
[self addAnnotations:shapes];
continue;
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions platform/osx/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ 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.
@param annotation The annotation object to add to the receiver. This object
must conform to the `MGLAnnotation` protocol. The map view retains the
annotation object.
Expand All @@ -543,6 +548,11 @@ 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.
@param annotations An array of annotation objects. Each object in the array
must conform to the `MGLAnnotation` protocol. The map view retains each
individual annotation object.
Expand Down
14 changes: 4 additions & 10 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1621,16 +1621,10 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
}
shapes.emplace_back(multiPoint.annotationSegments, [multiPoint shapeAnnotationPropertiesObjectWithDelegate:self]);
[userShapes addObject:annotation];
} else if ([annotation isKindOfClass:[MGLMultiPolyline class]]) {
// TODO: Add real support for these types down in mbgl instead of breaking the annotation apart.
NS_ARRAY_OF(MGLPolyline *) *polylines = [(MGLMultiPolyline *)annotation polylines];
[self addAnnotations:polylines];
} else if ([annotation isKindOfClass:[MGLMultiPolygon class]]) {
NS_ARRAY_OF(MGLPolygon *) *polygons = [(MGLMultiPolygon *)annotation polygons];
[self addAnnotations:polygons];
} else if ([annotation isKindOfClass:[MGLShapeCollection class]]) {
NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *shapes = [(MGLShapeCollection *)annotation shapes];
[self addAnnotations:shapes];
} else if ([annotation isKindOfClass:[MGLMultiPolyline class]]
|| [annotation isKindOfClass:[MGLMultiPolygon class]]
|| [annotation isKindOfClass:[MGLShapeCollection class]]) {
continue;
} else {
MGLAnnotationImage *annotationImage = nil;
if (delegateHasImagesForAnnotations) {
Expand Down

0 comments on commit 354396a

Please sign in to comment.