diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-05-26 22:23:06 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-05-27 21:42:39 -0700 |
commit | 974e6696986d49e2eb130e24bde9e75402b0f386 (patch) | |
tree | 884e9429aaab158eee8c7ff1c13950a64ca91bb8 | |
parent | bacf1f59ca8e06b5b5423a35b4e4c30d92624758 (diff) | |
download | qtlocation-mapboxgl-974e6696986d49e2eb130e24bde9e75402b0f386.tar.gz |
[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.
-rw-r--r-- | platform/darwin/src/MGLFeature.h | 5 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolygon.h | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolyline.h | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeCollection.h | 3 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.h | 10 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 18 | ||||
-rw-r--r-- | platform/osx/src/MGLMapView.h | 10 | ||||
-rw-r--r-- | platform/osx/src/MGLMapView.mm | 14 |
8 files changed, 40 insertions, 26 deletions
diff --git a/platform/darwin/src/MGLFeature.h b/platform/darwin/src/MGLFeature.h index b593ff70e4..69cff6b054 100644 --- a/platform/darwin/src/MGLFeature.h +++ b/platform/darwin/src/MGLFeature.h @@ -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> diff --git a/platform/darwin/src/MGLPolygon.h b/platform/darwin/src/MGLPolygon.h index e1dc553f30..3d5b36abb6 100644 --- a/platform/darwin/src/MGLPolygon.h +++ b/platform/darwin/src/MGLPolygon.h @@ -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> diff --git a/platform/darwin/src/MGLPolyline.h b/platform/darwin/src/MGLPolyline.h index a453a43a41..78d9649751 100644 --- a/platform/darwin/src/MGLPolyline.h +++ b/platform/darwin/src/MGLPolyline.h @@ -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> diff --git a/platform/darwin/src/MGLShapeCollection.h b/platform/darwin/src/MGLShapeCollection.h index f4dc226228..6a21d6fb90 100644 --- a/platform/darwin/src/MGLShapeCollection.h +++ b/platform/darwin/src/MGLShapeCollection.h @@ -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 diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 725677a65b..ca0584c821 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -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. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index d81c588cd6..59830b094f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -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 { diff --git a/platform/osx/src/MGLMapView.h b/platform/osx/src/MGLMapView.h index c08a257bea..5c7e75135b 100644 --- a/platform/osx/src/MGLMapView.h +++ b/platform/osx/src/MGLMapView.h @@ -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. diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 660c5d9ee0..c398a9424b 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -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) { |