diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-08-31 09:45:23 +0200 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-09-02 14:41:47 -0700 |
commit | ad095e458db7eee4085ec8be2528cdfa257371fd (patch) | |
tree | 021a7c93fc23ff71b8eac37486d864334b965620 /platform/darwin | |
parent | 7e208c46cebe5b49d4b7ead9826bbe4229ebabd3 (diff) | |
download | qtlocation-mapboxgl-ad095e458db7eee4085ec8be2528cdfa257371fd.tar.gz |
[ios, macos] fixes #5962 added geojson options to support clustering
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/src/MGLGeoJSONOptions.h | 13 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeoJSONOptions.m | 19 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeoJSONSource.h | 5 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeoJSONSource.mm | 27 |
4 files changed, 63 insertions, 1 deletions
diff --git a/platform/darwin/src/MGLGeoJSONOptions.h b/platform/darwin/src/MGLGeoJSONOptions.h new file mode 100644 index 0000000000..50b6d0ae6e --- /dev/null +++ b/platform/darwin/src/MGLGeoJSONOptions.h @@ -0,0 +1,13 @@ +#import <Foundation/Foundation.h> + +@interface MGLGeoJSONOptions : NSObject + +@property (nonatomic, assign) NSInteger maximumZoom; +@property (nonatomic, assign) NSInteger buffer; +@property (nonatomic, assign) double tolerance; + +@property (nonatomic, assign) BOOL cluster; +@property (nonatomic, assign) NSInteger clusterRadius; +@property (nonatomic, assign) NSInteger clusterMaximumZoom; + +@end diff --git a/platform/darwin/src/MGLGeoJSONOptions.m b/platform/darwin/src/MGLGeoJSONOptions.m new file mode 100644 index 0000000000..bab99ef88d --- /dev/null +++ b/platform/darwin/src/MGLGeoJSONOptions.m @@ -0,0 +1,19 @@ +#import "MGLGeoJSONOptions.h" + +@implementation MGLGeoJSONOptions + +- (instancetype)init +{ + if (self = [super init]) { + _maximumZoom = 18; + _buffer = 128; + _tolerance = 0.375; + + _cluster = NO; + _clusterRadius = 50; + _clusterMaximumZoom = 17; + } + return self; +} + +@end diff --git a/platform/darwin/src/MGLGeoJSONSource.h b/platform/darwin/src/MGLGeoJSONSource.h index ca6ccb5b19..a12c0b64e1 100644 --- a/platform/darwin/src/MGLGeoJSONSource.h +++ b/platform/darwin/src/MGLGeoJSONSource.h @@ -1,6 +1,7 @@ #import "MGLSource.h" #import "MGLTypes.h" +#import "MGLGeoJSONOptions.h" NS_ASSUME_NONNULL_BEGIN @@ -38,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, nullable) NSURL *URL; +@property (nonatomic, readonly, nullable) MGLGeoJSONOptions *geoJSONOptions; + /** Initializes a source with the given identifier and GeoJSON data. @@ -46,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data options:(MGLGeoJSONOptions *)options NS_DESIGNATED_INITIALIZER; + /** Initializes a source with the given identifier and URL. diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index b411e53429..46bea779a3 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -16,6 +16,15 @@ return self; } +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier geoJSONData:(NSData *)data options:(MGLGeoJSONOptions *)options +{ + if (self = [super initWithSourceIdentifier:sourceIdentifier]) { + _geoJSONData = data; + _geoJSONOptions = options; + } + return self; +} + - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url { if (self = [super initWithSourceIdentifier:sourceIdentifier]) { _URL = url; @@ -23,9 +32,24 @@ return self; } +- (mbgl::style::GeoJSONOptions)mbgl_geoJSONOptions +{ + auto options = mbgl::style::GeoJSONOptions(); + options.maxzoom = self.geoJSONOptions.maximumZoom; + options.buffer = self.geoJSONOptions.buffer; + options.tolerance = self.geoJSONOptions.tolerance; + options.cluster = self.geoJSONOptions.cluster; + options.clusterRadius = self.geoJSONOptions.clusterRadius; + options.clusterMaxZoom = self.geoJSONOptions.clusterMaximumZoom; + return options; +} + - (std::unique_ptr<mbgl::style::Source>)mbgl_source { - auto source = std::make_unique<mbgl::style::GeoJSONSource>(self.sourceIdentifier.UTF8String); + auto source = self.geoJSONOptions + ? std::make_unique<mbgl::style::GeoJSONSource>(self.sourceIdentifier.UTF8String, [self mbgl_geoJSONOptions]) + : std::make_unique<mbgl::style::GeoJSONSource>(self.sourceIdentifier.UTF8String); + if (self.URL) { NSURL *url = self.URL.mgl_URLByStandardizingScheme; source->setURL(url.absoluteString.UTF8String); @@ -35,6 +59,7 @@ source->setGeoJSON(geojson); _features = MGLFeaturesFromMBGLFeatures(geojson); } + return std::move(source); } |