[ios, macos] fixes #5962 added geojson options to support clustering

This commit is contained in:
Fredrik Karlsson
2016-08-31 09:45:23 +02:00
committed by Jesse Bounds
parent 7e208c46ce
commit ad095e458d
6 changed files with 76 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -150,6 +150,10 @@
35E1A4D81D74336F007AA97F /* MGLValueEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E1A4D71D74336F007AA97F /* MGLValueEvaluator.h */; };
35E1A4D91D74336F007AA97F /* MGLValueEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E1A4D71D74336F007AA97F /* MGLValueEvaluator.h */; };
35E208A71D24210F00EC9A46 /* MGLNSDataAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */; };
35E751DC1D76BE9800DFF553 /* MGLGeoJSONOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E751DA1D76BE9800DFF553 /* MGLGeoJSONOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
35E751DD1D76BE9800DFF553 /* MGLGeoJSONOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E751DA1D76BE9800DFF553 /* MGLGeoJSONOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
35E751DE1D76BE9800DFF553 /* MGLGeoJSONOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 35E751DB1D76BE9800DFF553 /* MGLGeoJSONOptions.m */; };
35E751DF1D76BE9800DFF553 /* MGLGeoJSONOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 35E751DB1D76BE9800DFF553 /* MGLGeoJSONOptions.m */; };
35E79F201D41266300957B9E /* MGLStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */; };
35E79F211D41266300957B9E /* MGLStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */; };
36F1153D1D46080700878E1A /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 36F1153B1D46080700878E1A /* libmbgl-core.a */; };
@@ -558,6 +562,8 @@
35E0CFE51D3E501500188327 /* MGLStyle_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyle_Private.h; sourceTree = "<group>"; };
35E1A4D71D74336F007AA97F /* MGLValueEvaluator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLValueEvaluator.h; sourceTree = "<group>"; };
35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLNSDataAdditionsTests.m; sourceTree = "<group>"; };
35E751DA1D76BE9800DFF553 /* MGLGeoJSONOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONOptions.h; sourceTree = "<group>"; };
35E751DB1D76BE9800DFF553 /* MGLGeoJSONOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLGeoJSONOptions.m; sourceTree = "<group>"; };
35E79F1F1D41266300957B9E /* MGLStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayer_Private.h; sourceTree = "<group>"; };
36F1153B1D46080700878E1A /* libmbgl-core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-core.a"; path = "build/Debug-iphoneos/libmbgl-core.a"; sourceTree = "<group>"; };
36F1153C1D46080700878E1A /* libmbgl-platform-ios.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-platform-ios.a"; path = "build/Debug-iphoneos/libmbgl-platform-ios.a"; sourceTree = "<group>"; };
@@ -807,6 +813,8 @@
3566C7651D4A77BA008152BC /* MGLGeoJSONSource.mm */,
3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */,
3566C76B1D4A8DFA008152BC /* MGLRasterSource.mm */,
35E751DA1D76BE9800DFF553 /* MGLGeoJSONOptions.h */,
35E751DB1D76BE9800DFF553 /* MGLGeoJSONOptions.m */,
);
name = Sources;
sourceTree = "<group>";
@@ -1369,6 +1377,7 @@
354D42DC1D4919F900F400A1 /* NSValue+MGLStyleAttributeAdditions_Private.h in Headers */,
DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */,
350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */,
35E751DC1D76BE9800DFF553 /* MGLGeoJSONOptions.h in Headers */,
DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */,
404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */,
DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */,
@@ -1484,6 +1493,7 @@
3566C7721D4A9198008152BC /* MGLSource_Private.h in Headers */,
353933FF1D3FB7DD003F57D7 /* MGLSymbolStyleLayer.h in Headers */,
DABFB8661CBE99E500D62B32 /* MGLPointAnnotation.h in Headers */,
35E751DD1D76BE9800DFF553 /* MGLGeoJSONOptions.h in Headers */,
35599DF11D46F3A60048254D /* MGLStyleAttributeValue.h in Headers */,
DABFB8621CBE99E500D62B32 /* MGLOfflinePack.h in Headers */,
DAD1656D1CF41981001FF4B9 /* MGLFeature.h in Headers */,
@@ -1907,6 +1917,7 @@
DA88481F1CBAFA6200AB86E3 /* MGLMultiPoint.mm in Sources */,
DA88482B1CBAFA6200AB86E3 /* MGLTypes.m in Sources */,
4018B1C71CDC287F00F666AF /* MGLAnnotationView.mm in Sources */,
35E751DE1D76BE9800DFF553 /* MGLGeoJSONOptions.m in Sources */,
DA88481D1CBAFA6200AB86E3 /* MGLMapCamera.mm in Sources */,
DA8848261CBAFA6200AB86E3 /* MGLPolygon.mm in Sources */,
35B82BFA1D6C5F8400B1B721 /* NSPredicate+MGLAdditions.mm in Sources */,
@@ -1975,6 +1986,7 @@
DAA4E4301CBB730400178DFB /* MGLLocationManager.m in Sources */,
DAA4E4321CBB730400178DFB /* MGLMapView.mm in Sources */,
DAA4E41E1CBB730400178DFB /* MGLMapCamera.mm in Sources */,
35E751DF1D76BE9800DFF553 /* MGLGeoJSONOptions.m in Sources */,
4018B1C81CDC287F00F666AF /* MGLAnnotationView.mm in Sources */,
DAA4E4341CBB730400178DFB /* MGLFaux3DUserLocationAnnotationView.m in Sources */,
35B82BFB1D6C5F8400B1B721 /* NSPredicate+MGLAdditions.mm in Sources */,

View File

@@ -43,6 +43,7 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[];
#import "MGLSource.h"
#import "MGLVectorSource.h"
#import "MGLGeoJSONSource.h"
#import "MGLGeoJSONOptions.h"
#import "MGLRasterSource.h"
#import "MGLTilePyramidOfflineRegion.h"
#import "MGLTypes.h"