[ios, osx] Feature querying; complex geometry classes
Added methods to MGLMapView that return the rendered features at a visible point or within a visible rectangle on the map, optionally restricted to a set of layers, plus voluminous documentation. Added several new geometry classes corresponding to distinct geometry types supported by geometry.hpp. Added parallel “feature” classes to represent these geometries along with tags (IDs) and attributes (properties) from the source. Grouped classes in the Foundation and SDK groups by theme. In iosapp, dropped pins’ callout views now display the name of the topmost named feature at that point. In osxapp, a long press on the map highlights the features under the cursor. Dropping a pin via the menu or context menu item shows the usual dropped pin, but the pin’s title is now the name of a feature under the cursor, if available, rather than “Dropped Pin”. Fixes the iOS/OS X side of #352.
This commit is contained in:
committed by
Minh Nguyễn
parent
c9520713ca
commit
c6683ee1d3
@@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol MGLAnnotation;
|
||||
@protocol MGLOverlay;
|
||||
@protocol MGLCalloutView;
|
||||
@protocol MGLFeature;
|
||||
|
||||
/** The vertical alignment of an annotation within a map view. */
|
||||
typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
|
||||
@@ -1021,6 +1022,132 @@ IB_DESIGNABLE
|
||||
*/
|
||||
- (void)removeOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays;
|
||||
|
||||
#pragma mark Accessing the Underlying Map Data
|
||||
|
||||
/**
|
||||
Returns an array of rendered map features that intersect with a given point.
|
||||
|
||||
This method may return features from any of the map’s style layers. To restrict
|
||||
the search to a particular layer or layers, use the
|
||||
`-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:` method. For more
|
||||
information about searching for map features, see that method’s documentation.
|
||||
|
||||
@param point A point expressed in the map view’s coordinate system.
|
||||
@return An array of objects conforming to the `MGLFeature` protocol that
|
||||
represent features in the sources used by the current style.
|
||||
*/
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point NS_SWIFT_NAME(visibleFeatures(at:));
|
||||
|
||||
/**
|
||||
Returns an array of rendered map features that intersect with a given point,
|
||||
restricted to the given style layers.
|
||||
|
||||
Each object in the returned array represents a feature rendered by the
|
||||
current style and provides access to attributes specified by the relevant
|
||||
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>.
|
||||
The returned array includes features specified in vector and GeoJSON tile
|
||||
sources but does not include anything from raster, image, or video sources.
|
||||
|
||||
Only visible features are returned. For example, suppose the current style uses
|
||||
the
|
||||
<a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets source</a>,
|
||||
but none of the specified style layers includes features that have the `maki`
|
||||
property set to `bus`. If you pass a point corresponding to the location of a
|
||||
bus stop into this method, the bus stop feature does not appear in the
|
||||
resulting array. On the other hand, if the style does include bus stops, an
|
||||
`MGLFeature` object representing that bus stop is returned and its
|
||||
`featureAttributes` dictionary has the `maki` key set to `bus` (along with
|
||||
other attributes). The dictionary contains only the attributes provided by the
|
||||
tile source; it does not include computed attribute values or rules about how
|
||||
the feature is rendered by the current style.
|
||||
|
||||
The returned array is sorted by z-order, starting with the topmost rendered
|
||||
feature and ending with the bottommost rendered feature. A feature that is
|
||||
rendered multiple times due to wrapping across the antimeridian at low zoom
|
||||
levels is included only once, subject to the caveat that follows.
|
||||
|
||||
Features come from tiled vector data or GeoJSON data that is converted to tiles
|
||||
internally, so feature geometries are clipped at tile boundaries and features
|
||||
may appear duplicated across tiles. For example, suppose the specified point
|
||||
lies along a road that spans the screen. The resulting array includes those
|
||||
parts of the road that lie within the map tile that contain the specified
|
||||
point, even if the road extends into other tiles.
|
||||
|
||||
To find out the layer names in a particular style, view the style in
|
||||
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
|
||||
|
||||
@param point A point expressed in the map view’s coordinate system.
|
||||
@param styleLayerIdentifiers A set of strings that correspond to the names of
|
||||
layers defined in the current style. Only the features contained in these
|
||||
layers are included in the returned array.
|
||||
@return An array of objects conforming to the `MGLFeature` protocol that
|
||||
represent features in the sources used by the current style.
|
||||
*/
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(at:styleLayerIdentifiers:));
|
||||
|
||||
/**
|
||||
Returns an array of rendered map features that intersect with the given
|
||||
rectangle.
|
||||
|
||||
This method may return features from any of the map’s style layers. To restrict
|
||||
the search to a particular layer or layers, use the
|
||||
`-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:` method. For more
|
||||
information about searching for map features, see that method’s documentation.
|
||||
|
||||
@param rect A rectangle expressed in the map view’s coordinate system.
|
||||
@return An array of objects conforming to the `MGLFeature` protocol that
|
||||
represent features in the sources used by the current style.
|
||||
*/
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect NS_SWIFT_NAME(visibleFeatures(in:));
|
||||
|
||||
/**
|
||||
Returns an array of rendered map features that intersect with the given
|
||||
rectangle, restricted to the given style layers.
|
||||
|
||||
Each object in the returned array represents a feature rendered by the
|
||||
current style and provides access to attributes specified by the relevant
|
||||
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>.
|
||||
The returned array includes features specified in vector and GeoJSON tile
|
||||
sources but does not include anything from raster, image, or video sources.
|
||||
|
||||
Only visible features are returned. For example, suppose the current style uses
|
||||
the
|
||||
<a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets source</a>,
|
||||
but none of the specified style layers includes features that have the `maki`
|
||||
property set to `bus`. If you pass a rectangle containing the location of a bus
|
||||
stop into this method, the bus stop feature does not appear in the resulting
|
||||
array. On the other hand, if the style does include bus stops, an `MGLFeature`
|
||||
object representing that bus stop is returned and its `featureAttributes`
|
||||
dictionary has the `maki` key set to `bus` (along with other attributes). The
|
||||
dictionary contains only the attributes provided by the tile source; it does
|
||||
not include computed attribute values or rules about how the feature is
|
||||
rendered by the current style.
|
||||
|
||||
The returned array is sorted by z-order, starting with the topmost rendered
|
||||
feature and ending with the bottommost rendered feature. A feature that is
|
||||
rendered multiple times due to wrapping across the antimeridian at low zoom
|
||||
levels is included only once, subject to the caveat that follows.
|
||||
|
||||
Features come from tiled vector data or GeoJSON data that is converted to tiles
|
||||
internally, so feature geometries are clipped at tile boundaries and features
|
||||
may appear duplicated across tiles. For example, suppose the specified
|
||||
rectangle intersects with a road that spans the screen. The resulting array
|
||||
includes those parts of the road that lie within the map tiles covering the
|
||||
specified rectangle, even if the road extends into other tiles. The portion of
|
||||
the road within each map tile is included individually.
|
||||
|
||||
To find out the layer names in a particular style, view the style in
|
||||
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
|
||||
|
||||
@param rect A rectangle expressed in the map view’s coordinate system.
|
||||
@param styleLayerIdentifiers A set of strings that correspond to the names of
|
||||
layers defined in the current style. Only the features contained in these
|
||||
layers are included in the returned array.
|
||||
@return An array of objects conforming to the `MGLFeature` protocol that
|
||||
represent features in the sources used by the current style.
|
||||
*/
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(in:styleLayerIdentifiers:));
|
||||
|
||||
#pragma mark Debugging the Map
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user