[ios, osx] Ignore compound shape types as annotations
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.
This commit is contained in:
committed by
Minh Nguyễn
parent
bacf1f59ca
commit
974e669698
@@ -19,8 +19,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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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. */
|
||||
@@ -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.
|
||||
|
||||
@@ -2820,21 +2820,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
@@ -1621,16 +1621,10 @@ public:
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user