diff options
Diffstat (limited to 'platform/darwin/src/MGLComputedShapeSource.mm')
-rw-r--r-- | platform/darwin/src/MGLComputedShapeSource.mm | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index 9049f5862a..a980872a3f 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -17,7 +17,6 @@ } @property (nonatomic, readwrite) NSDictionary *options; -@property (nonnull) mbgl::style::CustomVectorSource *rawSource; @property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForTile; @property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForBounds; @@ -32,15 +31,14 @@ @property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForBounds; @property (nonatomic, weak, nullable) id<MGLComputedShapeSourceDataSource> dataSource; @property (nonatomic, nullable) mbgl::style::CustomVectorSource *rawSource; -@property (nonatomic) mbgl::style::FetchTileCallback callback; -- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileId callback:(mbgl::style::FetchTileCallback) callback; +- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileId; @end @implementation MGLComputedShapeSourceFetchOperation -- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileID callback:(mbgl::style::FetchTileCallback) callback { +- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileID { self = [super init]; _z = tileID.z; _x = tileID.x; @@ -50,7 +48,6 @@ _dataSource = source.dataSource; mbgl::style::CustomVectorSource *rawSource = (mbgl::style::CustomVectorSource *)source.rawSource; _rawSource = rawSource; - _callback = callback; return self; } @@ -83,7 +80,7 @@ const auto geojson = mbgl::GeoJSON{featureCollection}; dispatch_sync(dispatch_get_main_queue(), ^{ if(![self isCancelled] && self.rawSource) { - self.callback(mbgl::CanonicalTileID(self.z, self.x, self.y), geojson); + self.rawSource->setTileData(mbgl::CanonicalTileID(self.z, self.x, self.y), geojson); } }); } @@ -99,22 +96,27 @@ @implementation MGLComputedShapeSource - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options { - if (self = [super initWithIdentifier:identifier]) { - _requestQueue = [[NSOperationQueue alloc] init]; - self.requestQueue.name = [NSString stringWithFormat:@"mgl.MGLComputedShapeSource.%@", identifier]; - auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); - auto source = std::make_unique<mbgl::style::CustomVectorSource> - (self.identifier.UTF8String, geoJSONOptions, - ^void(const mbgl::CanonicalTileID& tileID, mbgl::style::FetchTileCallback callback) - { - NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self tile:tileID callback: callback]; - [self.requestQueue addOperation:operation]; - }); - - _pendingSource = std::move(source); - self.rawSource = _pendingSource.get(); - } - return self; + _requestQueue = [[NSOperationQueue alloc] init]; + self.requestQueue.name = [NSString stringWithFormat:@"mgl.MGLComputedShapeSource.%@", identifier]; + self.requestQueue.qualityOfService = NSQualityOfServiceUtility; + self.requestQueue.maxConcurrentOperationCount = 4; + auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); + auto source = std::make_unique<mbgl::style::CustomVectorSource> + (identifier.UTF8String, geoJSONOptions, + ^void(const mbgl::CanonicalTileID& tileID) + { + NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self tile:tileID]; + [self.requestQueue addOperation:operation]; + }, + ^void(const mbgl::CanonicalTileID& tileID) + { + for(MGLComputedShapeSourceFetchOperation *operation in [self.requestQueue operations]) { + if(operation.x == tileID.x && operation.y == tileID.y && operation.z == tileID.z) { + [operation cancel]; + } + } + }); + return self = [super initWithPendingSource:std::move(source)]; } - (void)dealloc { |