summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-03-02 18:36:44 -0800
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-04 15:42:07 -0800
commit161ae804c23ff76f6c25596e811ec5861833d960 (patch)
treeb4e4f1fafd26c3710d783f279660fc7db533c591 /platform
parent60d10dd27df38ac4e97214d1cd514198c381695c (diff)
downloadqtlocation-mapboxgl-161ae804c23ff76f6c25596e811ec5861833d960.tar.gz
[ios, macos] Add support for queryRenderedFeatures filter
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/ios/src/MGLMapView.h59
-rw-r--r--platform/ios/src/MGLMapView.mm25
-rw-r--r--platform/macos/CHANGELOG.md1
-rw-r--r--platform/macos/src/MGLMapView.h94
-rw-r--r--platform/macos/src/MGLMapView.mm23
6 files changed, 163 insertions, 40 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index 33da2715f2..79c9b59f7e 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -52,6 +52,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed an issue that sometimes caused crashes when the SDK interacted with the file system in the background. ([#8125](https://github.com/mapbox/mapbox-gl-native/pull/8125))
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
* Fixed an issue that was causing the system location indicator to stay on in background after telemetry was disabled. ([#7833](https://github.com/mapbox/mapbox-gl-native/pull/7833))
+* Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246)
## 3.4.2 - February 21, 2017
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index 4a7ac308de..8fb58005de 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -1136,6 +1136,25 @@ IB_DESIGNABLE
/**
Returns an array of rendered map features that intersect with a given point,
restricted to the given style layers.
+
+ This method may return all features from the specified layers. To filter
+ the returned features, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate:` 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.
+ @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 a given point,
+ restricted to the given style layers and filtered by the given
+ predicate.
Each object in the returned array represents a feature rendered by the
current style and provides access to attributes specified by the relevant
@@ -1183,10 +1202,11 @@ IB_DESIGNABLE
@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.
+ @param predicate A predicate to filter the returned features.
@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:));
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(nullable NSPredicate *)predicate NS_SWIFT_NAME(visibleFeatures(at:styleLayerIdentifiers:predicate:));
/**
Returns an array of rendered map features that intersect with the given
@@ -1206,7 +1226,27 @@ IB_DESIGNABLE
/**
Returns an array of rendered map features that intersect with the given
rectangle, restricted to the given style layers.
+
+ This method may return all features from the specified layers. To filter
+ the returned features, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate:` 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.
+ @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:));
+/**
+ Returns an array of rendered map features that intersect with the given
+ rectangle, restricted to the given style layers and filtered by the given
+ predicate.
+
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>.
@@ -1243,21 +1283,22 @@ IB_DESIGNABLE
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
@note Layer identifiers are not guaranteed to exist across styles or different
- versions of the same style. Applications that use this API must first set the
- style URL to an explicitly versioned style using a convenience method like
- `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
- inspectable in Interface Builder, or a manually constructed `NSURL`. This
- approach also avoids layer identifer name changes that will occur in the default
- style’s layers over time.
-
+ versions of the same style. Applications that use this API must first set the
+ style URL to an explicitly versioned style using a convenience method like
+ `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
+ inspectable in Interface Builder, or a manually constructed `NSURL`. This
+ approach also avoids layer identifer name changes that will occur in the default
+ style’s layers over time.
+
@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.
+ @param predicate A predicate to filter the returned features.
@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:));
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(nullable NSPredicate *)predicate NS_SWIFT_NAME(visibleFeatures(in:styleLayerIdentifiers:predicate:));
#pragma mark Debugging the Map
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 2990a4e163..5b4f27da18 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -45,6 +45,7 @@
#import "NSException+MGLAdditions.h"
#import "NSURL+MGLAdditions.h"
#import "UIImage+MGLAdditions.h"
+#import "NSPredicate+MGLAdditions.h"
#import "MGLFaux3DUserLocationAnnotationView.h"
#import "MGLUserLocationAnnotationView.h"
@@ -4605,7 +4606,11 @@ public:
return [self visibleFeaturesAtPoint:point inStyleLayersWithIdentifiers:nil];
}
-- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
+ return [self visibleFeaturesAtPoint:point inStyleLayersWithIdentifiers:styleLayerIdentifiers predicate:nil];
+}
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(NSPredicate *)predicate
{
mbgl::ScreenCoordinate screenCoordinate = { point.x, point.y };
@@ -4620,8 +4625,13 @@ public:
}];
optionalLayerIDs = layerIDs;
}
+
+ mbgl::optional<mbgl::style::Filter> optionalFilter;
+ if (predicate) {
+ optionalFilter = predicate.mgl_filter;
+ }
- std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, { optionalLayerIDs, {} });
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, { optionalLayerIDs, optionalFilter });
return MGLFeaturesFromMBGLFeatures(features);
}
@@ -4630,6 +4640,10 @@ public:
}
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
+ return [self visibleFeaturesInRect:rect inStyleLayersWithIdentifiers:styleLayerIdentifiers predicate:nil];
+}
+
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(NSPredicate *)predicate {
mbgl::ScreenBox screenBox = {
{ CGRectGetMinX(rect), CGRectGetMinY(rect) },
{ CGRectGetMaxX(rect), CGRectGetMaxY(rect) },
@@ -4644,8 +4658,13 @@ public:
}];
optionalLayerIDs = layerIDs;
}
+
+ mbgl::optional<mbgl::style::Filter> optionalFilter;
+ if (predicate) {
+ optionalFilter = predicate.mgl_filter;
+ }
- std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, { optionalLayerIDs, {} });
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, { optionalLayerIDs, optionalFilter });
return MGLFeaturesFromMBGLFeatures(features);
}
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index 38711b5202..5a10432ce4 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -47,6 +47,7 @@
* Fixed an issue where translucent point annotations along tile boundaries would be drawn darker than expected. ([#6832](https://github.com/mapbox/mapbox-gl-native/pull/6832))
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574))
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
+* Added support for predicates in rendered feature querying [8256](https://github.com/mapbox/mapbox-gl-native/pull/8246)
## 0.3.1 - February 21, 2017
diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h
index 4d1a2fc2c4..fa07821e19 100644
--- a/platform/macos/src/MGLMapView.h
+++ b/platform/macos/src/MGLMapView.h
@@ -789,6 +789,33 @@ MGL_EXPORT IB_DESIGNABLE
Returns an array of rendered map features that intersect with a given point,
restricted to the given style layers.
+ This method may return all features from the specified layers. To filter
+ the returned features, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate:` method. For more
+ information about searching for map features, see that method’s documentation.
+
+ @note Layer identifiers are not guaranteed to exist across styles or different
+ versions of the same style. Applications that use this API must first set the
+ style URL to an explicitly versioned style using a convenience method like
+ `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
+ inspectable in Interface Builder, or a manually constructed `NSURL`. This
+ approach also avoids layer identifer name changes that will occur in the default
+ style’s layers over time.
+
+ @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:(NSPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(at:styleLayerIdentifiers:));
+
+/**
+ Returns an array of rendered map features that intersect with a given point,
+ restricted to the given style layers and filtered by the given
+ predicate.
+
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>.
@@ -824,21 +851,22 @@ MGL_EXPORT IB_DESIGNABLE
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
@note Layer identifiers are not guaranteed to exist across styles or different
- versions of the same style. Applications that use this API must first set the
- style URL to an explicitly versioned style using a convenience method like
- `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
- inspectable in Interface Builder, or a manually constructed `NSURL`. This
- approach also avoids layer identifer name changes that will occur in the default
- style’s layers over time.
-
+ versions of the same style. Applications that use this API must first set the
+ style URL to an explicitly versioned style using a convenience method like
+ `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
+ inspectable in Interface Builder, or a manually constructed `NSURL`. This
+ approach also avoids layer identifer name changes that will occur in the default
+ style’s layers over time.
+
@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.
+ layers defined in the current style. Only the features contained in these
+ layers are included in the returned array.
+ @param predicate A predicate to filter the returned features.
@return An array of objects conforming to the `MGLFeature` protocol that
- represent features in the sources used by the current style.
+ represent features in the sources used by the current style.
*/
-- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(NSPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(_:styleLayerIdentifiers:));
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(NSPoint)point inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(nullable NSPredicate *)predicate NS_SWIFT_NAME(visibleFeatures(at:styleLayerIdentifiers:predicate:));
/**
Returns an array of rendered map features that intersect with the given
@@ -858,7 +886,28 @@ MGL_EXPORT IB_DESIGNABLE
/**
Returns an array of rendered map features that intersect with the given
rectangle, restricted to the given style layers.
+
+ This method may return all features from the specified layers. To filter
+ the returned features, use the
+ `-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate:` 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.
+ @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:(NSRect)rect 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, restricted to the given style layers and filtered by the given
+ predicate.
+
+
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>.
@@ -895,21 +944,22 @@ MGL_EXPORT IB_DESIGNABLE
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a>.
@note Layer identifiers are not guaranteed to exist across styles or different
- versions of the same style. Applications that use this API must first set the
- style URL to an explicitly versioned style using a convenience method like
- `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
- inspectable in Interface Builder, or a manually constructed `NSURL`. This
- approach also avoids layer identifer name changes that will occur in the default
- style’s layers over time.
-
+ versions of the same style. Applications that use this API must first set the
+ style URL to an explicitly versioned style using a convenience method like
+ `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
+ inspectable in Interface Builder, or a manually constructed `NSURL`. This
+ approach also avoids layer identifer name changes that will occur in the default
+ style’s layers over time.
+
@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.
+ layers defined in the current style. Only the features contained in these
+ layers are included in the returned array.
+ @param predicate A predicate to filter the returned features.
@return An array of objects conforming to the `MGLFeature` protocol that
- represent features in the sources used by the current style.
+ represent features in the sources used by the current style.
*/
-- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(NSRect)rect inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers NS_SWIFT_NAME(visibleFeatures(_:styleLayerIdentifiers:));
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(NSRect)rect inStyleLayersWithIdentifiers:(nullable NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(nullable NSPredicate *)predicate NS_SWIFT_NAME(visibleFeatures(in:styleLayerIdentifiers:predicate:));
#pragma mark Converting Geographic Coordinates
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index ff98095e15..e09daa1c18 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -50,6 +50,7 @@
#import "NSURL+MGLAdditions.h"
#import "NSColor+MGLAdditions.h"
#import "NSImage+MGLAdditions.h"
+#import "NSPredicate+MGLAdditions.h"
#import <QuartzCore/QuartzCore.h>
@@ -2519,7 +2520,7 @@ public:
return [self visibleFeaturesAtPoint:point inStyleLayersWithIdentifiers:nil];
}
-- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(NSPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(NSPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(NSPredicate *)predicate {
// Cocoa origin is at the lower-left corner.
mbgl::ScreenCoordinate screenCoordinate = { point.x, NSHeight(self.bounds) - point.y };
@@ -2532,8 +2533,13 @@ public:
}];
optionalLayerIDs = layerIDs;
}
-
- std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, { optionalLayerIDs });
+
+ mbgl::optional<mbgl::style::Filter> optionalFilter;
+ if (predicate) {
+ optionalFilter = predicate.mgl_filter;
+ }
+
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, { optionalLayerIDs, optionalFilter });
return MGLFeaturesFromMBGLFeatures(features);
}
@@ -2541,7 +2547,7 @@ public:
return [self visibleFeaturesInRect:rect inStyleLayersWithIdentifiers:nil];
}
-- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(NSRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
+- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(NSRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers predicate:(NSPredicate *)predicate {
// Cocoa origin is at the lower-left corner.
mbgl::ScreenBox screenBox = {
{ NSMinX(rect), NSHeight(self.bounds) - NSMaxY(rect) },
@@ -2557,8 +2563,13 @@ public:
}];
optionalLayerIDs = layerIDs;
}
-
- std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, { optionalLayerIDs });
+
+ mbgl::optional<mbgl::style::Filter> optionalFilter;
+ if (predicate) {
+ optionalFilter = predicate.mgl_filter;
+ }
+
+ std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, { optionalLayerIDs, optionalFilter });
return MGLFeaturesFromMBGLFeatures(features);
}