diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-10 16:34:28 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-10 16:53:14 -0700 |
commit | f381388b1c6bd10deffbc8b83bb9b37c21dda90c (patch) | |
tree | 70d5fff0975e79aee14658be8329fc982b5b0d0c | |
parent | 648e74109dd995d5594795b9ddc1e249929b9630 (diff) | |
download | qtlocation-mapboxgl-f381388b1c6bd10deffbc8b83bb9b37c21dda90c.tar.gz |
[macos] Update bindings for Options
-rw-r--r-- | platform/darwin/src/MGLAbstractShapeSource.mm | 36 | ||||
-rw-r--r-- | platform/darwin/src/MGLAbstractShapeSource_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLComputedShapeSource.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLComputedShapeSource.mm | 27 |
4 files changed, 57 insertions, 14 deletions
diff --git a/platform/darwin/src/MGLAbstractShapeSource.mm b/platform/darwin/src/MGLAbstractShapeSource.mm index ff3c68b200..6573b47897 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.mm +++ b/platform/darwin/src/MGLAbstractShapeSource.mm @@ -79,3 +79,39 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGL return geoJSONOptions; } +mbgl::style::CustomVectorSource::Options MBGLCustomVectorSourceOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { + mbgl::style::CustomVectorSource::Options sourceOptions; + + if (NSNumber *value = options[MGLShapeSourceOptionMinimumZoomLevel]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevelForClustering must be an NSNumber."]; + } + sourceOptions.zoomRange.min = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; + } + sourceOptions.zoomRange.max = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionBuffer]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionBuffer must be an NSNumber."]; + } + sourceOptions.tileOptions.buffer = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionSimplificationTolerance]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionSimplificationTolerance must be an NSNumber."]; + } + sourceOptions.tileOptions.tolerance = value.doubleValue; + } + return sourceOptions; +} diff --git a/platform/darwin/src/MGLAbstractShapeSource_Private.h b/platform/darwin/src/MGLAbstractShapeSource_Private.h index e10ed4e646..dade47d22a 100644 --- a/platform/darwin/src/MGLAbstractShapeSource_Private.h +++ b/platform/darwin/src/MGLAbstractShapeSource_Private.h @@ -5,6 +5,7 @@ #import "MGLShape.h" #include <mbgl/style/sources/geojson_source.hpp> +#include <mbgl/style/sources/custom_vector_source.hpp> NS_ASSUME_NONNULL_BEGIN @@ -14,5 +15,8 @@ MGL_EXPORT mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options); +MGL_EXPORT +mbgl::style::CustomVectorSource::Options MBGLCustomVectorSourceOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options); + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLComputedShapeSource.h b/platform/darwin/src/MGLComputedShapeSource.h index d5326ccdf2..fc99c00946 100644 --- a/platform/darwin/src/MGLComputedShapeSource.h +++ b/platform/darwin/src/MGLComputedShapeSource.h @@ -37,6 +37,10 @@ NS_ASSUME_NONNULL_BEGIN /** A source for vector data that is fetched one tile at a time. Useful for sources that are too large to fit in memory, or are already divided into tiles, but not in Mapbox Vector Tile format. + + Supported options are `MGLShapeSourceOptionMinimumZoomLevel`, `MGLShapeSourceOptionMaximumZoomLevel`, + `MGLShapeSourceOptionBuffer`, and `MGLShapeSourceOptionSimplificationTolerance.` This source does + not support clustering. */ MGL_EXPORT @interface MGLComputedShapeSource : MGLAbstractShapeSource diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index a980872a3f..a1c3a8b893 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -9,7 +9,6 @@ #include <mbgl/map/map.hpp> #include <mbgl/style/sources/custom_vector_source.hpp> #include <mbgl/tile/tile_id.hpp> -#include <mbgl/util/geo.hpp> #include <mbgl/util/geojson.hpp> @interface MGLComputedShapeSource () { @@ -100,22 +99,22 @@ 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]) { + + auto sourceOptions = MBGLCustomVectorSourceOptionsFromDictionary(options); + sourceOptions.fetchTileFunction = ^void(const mbgl::CanonicalTileID& tileID) { + NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self tile:tileID]; + [self.requestQueue addOperation:operation]; + }; + + sourceOptions.cancelTileFunction = ^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]; } - } - }); + } + }; + + auto source = std::make_unique<mbgl::style::CustomVectorSource>(identifier.UTF8String, sourceOptions); return self = [super initWithPendingSource:std::move(source)]; } |