diff options
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLShapeSource.mm | 5 | ||||
-rw-r--r-- | platform/darwin/src/MGLSource.mm | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLSource_Private.h | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource.mm | 7 |
4 files changed, 22 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 15437ebedb..023a81bba8 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -95,7 +95,10 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh optionalFilter = predicate.mgl_filter; } - std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ {}, optionalFilter }); + std::vector<mbgl::Feature> features; + if (self.mapView) { + features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { {}, optionalFilter }); + } return MGLFeaturesFromMBGLFeatures(features); } diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index 59c2ae13e6..eb859ba2c0 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -10,6 +10,8 @@ // special internal source types like mbgl::AnnotationSource. @property (nonatomic, readonly) mbgl::style::Source *rawSource; +@property (nonatomic, readonly, weak) MGLMapView *mapView; + @end @implementation MGLSource { @@ -48,12 +50,14 @@ "to the style more than once is invalid.", self, mapView.style]; } + _mapView = mapView; mapView.mbglMap->addSource(std::move(_pendingSource)); } - (void)removeFromMapView:(MGLMapView *)mapView { if (self.rawSource == mapView.mbglMap->getSource(self.identifier.UTF8String)) { _pendingSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); + _mapView = nil; } } diff --git a/platform/darwin/src/MGLSource_Private.h b/platform/darwin/src/MGLSource_Private.h index 6f86e4800b..91bfac6390 100644 --- a/platform/darwin/src/MGLSource_Private.h +++ b/platform/darwin/src/MGLSource_Private.h @@ -44,6 +44,14 @@ struct SourceWrapper { @property (nonatomic, readonly) mbgl::style::Source *rawSource; /** + The map view whose style currently contains the source. + + If the source is not currently part of any map view’s style, this property is + set to `nil`. + */ +@property (nonatomic, readonly, weak) MGLMapView *mapView; + +/** Adds the mbgl source that this object represents to the mbgl map. Once a mbgl source is added, ownership of the object is transferred to the diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index afce3bad46..5e9f4f4a6e 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -3,9 +3,11 @@ #import "MGLFeature_Private.h" #import "MGLSource_Private.h" #import "MGLTileSource_Private.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "NSURL+MGLAdditions.h" +#include <mbgl/map/map.hpp> #include <mbgl/style/sources/vector_source.hpp> @interface MGLVectorSource () @@ -59,7 +61,10 @@ optionalFilter = predicate.mgl_filter; } - std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ optionalSourceLayerIDs, optionalFilter }); + std::vector<mbgl::Feature> features; + if (self.mapView) { + features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { optionalSourceLayerIDs, optionalFilter }); + } return MGLFeaturesFromMBGLFeatures(features); } |