From 403ac491745da1c772cf7e2301d815cf4dc48902 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 1 Nov 2016 13:33:39 -0600 Subject: [PATCH 01/61] Sketching out CustomVectorSource interface --- platform/darwin/src/MGLCustomVectorSource.h | 60 ++++++++++++++++++++ platform/darwin/src/MGLCustomVectorSource.mm | 22 +++++++ platform/ios/ios.xcodeproj/project.pbxproj | 39 ++++++++----- 3 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 platform/darwin/src/MGLCustomVectorSource.h create mode 100644 platform/darwin/src/MGLCustomVectorSource.mm diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h new file mode 100644 index 00000000000..f6efdf3fb3d --- /dev/null +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -0,0 +1,60 @@ +#import "MGLSource.h" +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol MGLCustomVectorSourceDataSource + +/** + Fetch data for a tile + @param zoom + @param y + @param x + @param callback A block to call with the data that has been fetched for the tile. The data can be in the form of a + GeoJSON Feature, FeatureCollection, or Geometry. + */ +- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)x callback:(void (^)(NSDictionary* __nullable))callback; + +@end + +@interface MGLCustomVectorSource : MGLSource + +/** + Returns a custom vector datasource initialized with an identifier, datasource, and zoom levels. + + @param identifier A string that uniquely identifies the source. + @param minimumZoomLevel The minimum zoom level at which the source will display tiles. + @param maximumZoomLevel The maximum zoom level at which the source will display tiles. + @param dataSource An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel dataSource:(NSObject*)dataSource NS_DESIGNATED_INITIALIZER; + +/** + An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. + */ +@property (nonatomic, readonly, copy) NSObject *dataSource; + +/** + An `NSNumber` object containing an integer; specifies the minimum zoom level at + which the source will display tiles. The value should be in the range of 0 to + 22. + */ +@property (nonatomic, nonnull) NSNumber *minimumZoomLevel; + +/** + An `NSNumber` object containing an integer; specifies the maximum zoom level at + which to display tiles. The value should be in the range of 0 to 22 and greater + than `minimumZoomLevel`. + */ +@property (nonatomic, nonnull) NSNumber *maximumZoomLevel; + +/** + An `NSString` object that contains an attribution to be displayed when the map + is shown to a user. The default value is `nil`. + */ +@property (nonatomic, copy, nullable) NSString *attribution; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm new file mode 100644 index 00000000000..a2e0c50bf4e --- /dev/null +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -0,0 +1,22 @@ +#import "MGLCustomVectorSource.h" + +#import "MGLSource_Private.h" + +@implementation MGLCustomVectorSource + +- (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel dataSource:(NSObject*)dataSource +{ + if (self = [super initWithIdentifier:identifier]) + { + _maximumZoomLevel = @(maximumZoomLevel); + _minimumZoomLevel = @(minimumZoomLevel); + _dataSource = dataSource; + } + return self; +} + +- (std::unique_ptr)mbglSource { + return nil; +} + +@end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 2dcfd71216f..99173126c49 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -171,6 +171,10 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; + 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; }; + 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; }; + 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; + 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; @@ -413,13 +417,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; - proxyType = 1; - remoteGlobalIDString = DA25D5B81CCD9EDE00607828; - remoteInfo = settings; - }; DA25D5C91CCDA0CC00607828 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; @@ -595,6 +592,8 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; + 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCustomVectorSource.h; sourceTree = ""; }; + 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLCustomVectorSource.mm; sourceTree = ""; tabWidth = 4; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -841,6 +840,8 @@ 404C26E01D89B877000AA13D /* MGLTileSet.h */, 404C26E61D89C515000AA13D /* MGLTileSet_Private.h */, 404C26E11D89B877000AA13D /* MGLTileSet.mm */, + 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */, + 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */, ); name = Sources; sourceTree = ""; @@ -1282,8 +1283,8 @@ DA8847E11CBAFA5100AB86E3 /* MGLGeometry.h */, DA8848011CBAFA6200AB86E3 /* MGLGeometry_Private.h */, DA8848021CBAFA6200AB86E3 /* MGLGeometry.mm */, - DA8848041CBAFA6200AB86E3 /* MGLMultiPoint_Private.h */, DA8847E31CBAFA5100AB86E3 /* MGLMultiPoint.h */, + DA8848041CBAFA6200AB86E3 /* MGLMultiPoint_Private.h */, DA8848051CBAFA6200AB86E3 /* MGLMultiPoint.mm */, DA8847E71CBAFA5100AB86E3 /* MGLOverlay.h */, DA8847E81CBAFA5100AB86E3 /* MGLPointAnnotation.h */, @@ -1421,6 +1422,7 @@ 35D13AB71D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */, DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */, 40F887701D7A1E58008ECB67 /* MGLGeoJSONSource_Private.h in Headers */, + 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, @@ -1544,6 +1546,7 @@ DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */, DABFB86C1CBE99E500D62B32 /* MGLTypes.h in Headers */, DABFB8691CBE99E500D62B32 /* MGLShape.h in Headers */, + 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, 3510FFEB1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */, 35E1A4D91D74336F007AA97F /* MGLValueEvaluator.h in Headers */, 7E016D7F1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */, @@ -1653,7 +1656,6 @@ buildRules = ( ); dependencies = ( - DA25D5C81CCDA0C100607828 /* PBXTargetDependency */, ); name = dynamic; productName = framework; @@ -1726,25 +1728,31 @@ TargetAttributes = { DA1DC9491CB6C1C2006E619F = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; DA25D5B81CCD9EDE00607828 = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; DA2E88501CC036F400F24E7B = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0800; + DevelopmentTeam = PEWGB469RG; }; DA8847D11CBAF91600AB86E3 = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; DA8933D41CCD306400E68420 = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; DAA4E4121CBB71D400178DFB = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; DABCABA71CB80692000A7C39 = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = PEWGB469RG; }; }; }; @@ -1931,6 +1939,7 @@ 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, DA8848541CBAFB9800AB86E3 /* MGLCompactCalloutView.m in Sources */, + 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */, DA8848251CBAFA6200AB86E3 /* MGLPointAnnotation.mm in Sources */, 35136D3C1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, @@ -2004,6 +2013,7 @@ 30E5781A1DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, DAA4E4291CBB730400178DFB /* NSBundle+MGLAdditions.m in Sources */, + 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */, DAA4E42E1CBB730400178DFB /* MGLAPIClient.m in Sources */, 35136D3D1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, @@ -2077,11 +2087,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - DA25D5C81CCDA0C100607828 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = DA25D5B81CCD9EDE00607828 /* settings */; - targetProxy = DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */; - }; DA25D5CA1CCDA0CC00607828 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DA8933D41CCD306400E68420 /* bundle */; @@ -2187,6 +2192,7 @@ CURRENT_SEMANTIC_VERSION = 1.0.0; CURRENT_SHORT_VERSION = 1.0; DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = PEWGB469RG; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -2238,6 +2244,7 @@ CURRENT_SEMANTIC_VERSION = 1.0.0; CURRENT_SHORT_VERSION = 1.0; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = PEWGB469RG; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -2261,6 +2268,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = PEWGB469RG; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2273,6 +2281,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = PEWGB469RG; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; From 5d74f08bccf2b2baec1193a34b5f9d5f4293cd02 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 2 Nov 2016 15:29:20 -0600 Subject: [PATCH 02/61] Sketch out interface --- .../style/sources/custom_vector_source.hpp | 31 +++++++++++++++++++ platform/darwin/src/MGLCustomVectorSource.mm | 21 ++++++++++++- .../style/sources/custom_vector_source.cpp | 12 +++++++ .../sources/custom_vector_source_impl.cpp | 24 ++++++++++++++ .../sources/custom_vector_source_impl.hpp | 29 +++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 include/mbgl/style/sources/custom_vector_source.hpp create mode 100644 src/mbgl/style/sources/custom_vector_source.cpp create mode 100644 src/mbgl/style/sources/custom_vector_source_impl.cpp create mode 100644 src/mbgl/style/sources/custom_vector_source_impl.hpp diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp new file mode 100644 index 00000000000..14b9a01bf7d --- /dev/null +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + + struct CustomVectorSourceOptions { + uint8_t minzoom = 0; + uint8_t maxzoom = 18; + }; + + +class CustomVectorSource : public Source { +public: + CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile); + + // Private implementation + + class Impl; +}; + +template <> +inline bool Source::is() const { + return type == SourceType::Vector; +} + +} // namespace style +} // namespace mbgl diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index a2e0c50bf4e..ad09ac596b8 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -1,6 +1,7 @@ #import "MGLCustomVectorSource.h" #import "MGLSource_Private.h" +#include @implementation MGLCustomVectorSource @@ -15,8 +16,26 @@ - (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUI return self; } +- (mbgl::style::CustomVectorSourceOptions)customSourceOptions { + auto options = mbgl::style::CustomVectorSourceOptions(); + options.minzoom = self.minimumZoomLevel.integerValue; + options.maxzoom = self.maximumZoomLevel.integerValue; + return options; +} + - (std::unique_ptr)mbglSource { - return nil; + auto source = std::make_unique(self.identifier.UTF8String, self.customSourceOptions, + ^void(uint8_t z, uint32_t x, uint32_t y){ + [self.dataSource getTileForZoom:z + x:x + y:y + callback:^(NSDictionary * _Nullable) { + + }]; + }); + return std::move(source); } + + @end diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp new file mode 100644 index 00000000000..2d4b4f15768 --- /dev/null +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -0,0 +1,12 @@ +#include +#include + +namespace mbgl { + namespace style { + + CustomVectorSource::CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile) + : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)) { + } + + } // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp new file mode 100644 index 00000000000..51909fd9ce1 --- /dev/null +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +namespace mbgl { + namespace style { + + CustomVectorSource::Impl::Impl(std::string id, Source& base_, CustomVectorSourceOptions options_, std::function fetchTile_) + : Source::Impl(SourceType::Vector, std::move(id), base_), options(options_), fetchTile(fetchTile_) { + } + + Range CustomVectorSource::Impl::getZoomRange() { + return { options.minzoom, options.maxzoom }; + } + + std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, + const UpdateParameters& parameters) { + auto tilePointer = std::make_unique(tileID, base.getID(), parameters); +// setTileData(*tilePointer.get(), tileID); + return std::move(tilePointer); + } + + } // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp new file mode 100644 index 00000000000..f38f5dd3ed0 --- /dev/null +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +namespace mbgl { + namespace style { + + class CustomVectorSource::Impl : public Source::Impl { + public: + Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); + + uint16_t getTileSize() const final { + return util::tileSize; + } + void loadDescription(FileSource&) final {} + + private: +// std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; + CustomVectorSourceOptions options; + std::function fetchTile; + + Range getZoomRange() final; + std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; + + }; + + } // namespace style +} // namespace mbgl From 579ef870230118e1bcff82d91cb209920a873183 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 05:04:46 -0600 Subject: [PATCH 03/61] Add to Mapbox.h header --- platform/darwin/src/MGLCustomVectorSource.h | 4 +--- platform/ios/ios.xcodeproj/project.pbxproj | 8 ++++---- platform/ios/src/Mapbox.h | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index f6efdf3fb3d..cbcbf32d0b2 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -1,6 +1,4 @@ #import "MGLSource.h" -#import -#import NS_ASSUME_NONNULL_BEGIN @@ -14,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @param callback A block to call with the data that has been fetched for the tile. The data can be in the form of a GeoJSON Feature, FeatureCollection, or Geometry. */ -- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)x callback:(void (^)(NSDictionary* __nullable))callback; +- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:(void (^)(NSDictionary* __nullable))callback; @end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 99173126c49..b9ba0be3041 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -171,8 +171,8 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; - 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; }; - 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; }; + 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; @@ -1408,6 +1408,7 @@ buildActionMask = 2147483647; files = ( 35D13AC31D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, + 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, DA88483A1CBAFB8500AB86E3 /* MGLAnnotationImage.h in Headers */, DA35A2BB1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */, 353933FE1D3FB7DD003F57D7 /* MGLSymbolStyleLayer.h in Headers */, @@ -1422,7 +1423,6 @@ 35D13AB71D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */, DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */, 40F887701D7A1E58008ECB67 /* MGLGeoJSONSource_Private.h in Headers */, - 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, @@ -1522,6 +1522,7 @@ DA35A2CA1CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */, 350098BC1D480108004B2AF0 /* MGLVectorSource.h in Headers */, 353933FC1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */, + 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, 3566C76D1D4A8DFA008152BC /* MGLRasterSource.h in Headers */, DAED38641D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */, DABFB85E1CBE99E500D62B32 /* MGLAnnotation.h in Headers */, @@ -1546,7 +1547,6 @@ DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */, DABFB86C1CBE99E500D62B32 /* MGLTypes.h in Headers */, DABFB8691CBE99E500D62B32 /* MGLShape.h in Headers */, - 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, 3510FFEB1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */, 35E1A4D91D74336F007AA97F /* MGLValueEvaluator.h in Headers */, 7E016D7F1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */, diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index 7664695315a..aa7ba533035 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -54,3 +54,4 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h" #import "MGLTileSet.h" +#import "MGLCustomVectorSource.h" From 095281e9b94bcaedcd4aba2f193c2a56dfd424cf Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 05:41:57 -0600 Subject: [PATCH 04/61] Move tilesize into options --- include/mbgl/style/sources/custom_vector_source.hpp | 1 + src/mbgl/style/sources/custom_vector_source_impl.cpp | 4 ++++ src/mbgl/style/sources/custom_vector_source_impl.hpp | 5 +---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 14b9a01bf7d..92bb6e980be 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -10,6 +10,7 @@ namespace style { struct CustomVectorSourceOptions { uint8_t minzoom = 0; uint8_t maxzoom = 18; + uint16_t tileSize = 512; }; diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 51909fd9ce1..4337cb04461 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -13,6 +13,10 @@ namespace mbgl { return { options.minzoom, options.maxzoom }; } + uint16_t CustomVectorSource::Impl::getTileSize() const { + return options.tileSize; + } + std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { auto tilePointer = std::make_unique(tileID, base.getID(), parameters); diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index f38f5dd3ed0..5482ffd5014 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -10,16 +10,13 @@ namespace mbgl { public: Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); - uint16_t getTileSize() const final { - return util::tileSize; - } void loadDescription(FileSource&) final {} private: -// std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; CustomVectorSourceOptions options; std::function fetchTile; + uint16_t getTileSize() const; Range getZoomRange() final; std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; From 165667292272f4f117c31384f7ed45a0fbac6ea9 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 08:48:23 -0600 Subject: [PATCH 05/61] obj-c class is getting called for tiles --- .../style/sources/custom_vector_source.hpp | 3 + platform/darwin/src/MGLCustomVectorSource.h | 8 ++- platform/darwin/src/MGLCustomVectorSource.mm | 55 +++++++++++++++---- platform/ios/ios.xcodeproj/project.pbxproj | 8 +-- .../style/sources/custom_vector_source.cpp | 6 +- .../sources/custom_vector_source_impl.cpp | 8 ++- .../sources/custom_vector_source_impl.hpp | 3 +- 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 92bb6e980be..77a5459d660 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -18,9 +18,12 @@ class CustomVectorSource : public Source { public: CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile); + void setSourceLoaded(); + // Private implementation class Impl; + Impl* const impl; }; template <> diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index cbcbf32d0b2..f7e53313a17 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -2,6 +2,9 @@ NS_ASSUME_NONNULL_BEGIN +@protocol MGLFeature; + + @protocol MGLCustomVectorSourceDataSource /** @@ -12,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @param callback A block to call with the data that has been fetched for the tile. The data can be in the form of a GeoJSON Feature, FeatureCollection, or Geometry. */ -- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:(void (^)(NSDictionary* __nullable))callback; +- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( void (^)(NSArray>*) )callback; @end @@ -53,6 +56,9 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, copy, nullable) NSString *attribution; + +- (void)setSourceLoaded; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index ad09ac596b8..d34efa4a2d6 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -1,8 +1,19 @@ #import "MGLCustomVectorSource.h" +#import "MGLMapView_Private.h" #import "MGLSource_Private.h" +#import "MGLFeature_Private.h" + #include +@interface MGLCustomVectorSource () { + std::unique_ptr _pendingSource; +} + +@property (nonnull) mbgl::style::CustomVectorSource *rawSource; + +@end + @implementation MGLCustomVectorSource - (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel dataSource:(NSObject*)dataSource @@ -12,30 +23,50 @@ - (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUI _maximumZoomLevel = @(maximumZoomLevel); _minimumZoomLevel = @(minimumZoomLevel); _dataSource = dataSource; + + auto source = std::make_unique(self.identifier.UTF8String, self.customSourceOptions, + ^void(uint8_t z, uint32_t x, uint32_t y) + { + [self.dataSource getTileForZoom:z + x:x + y:y + callback: + ^(NS_ARRAY_OF(id ) *features) + { + [self processData:features forTile:z x:x y:y]; +// NSLog(@"Got tile data into callback%@", tiledata); + }]; + }); + + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); + } return self; } -- (mbgl::style::CustomVectorSourceOptions)customSourceOptions { +- (mbgl::style::CustomVectorSourceOptions)customSourceOptions +{ auto options = mbgl::style::CustomVectorSourceOptions(); options.minzoom = self.minimumZoomLevel.integerValue; options.maxzoom = self.maximumZoomLevel.integerValue; return options; } -- (std::unique_ptr)mbglSource { - auto source = std::make_unique(self.identifier.UTF8String, self.customSourceOptions, - ^void(uint8_t z, uint32_t x, uint32_t y){ - [self.dataSource getTileForZoom:z - x:x - y:y - callback:^(NSDictionary * _Nullable) { - - }]; - }); - return std::move(source); +- (void)addToMapView:(MGLMapView *)mapView +{ + mapView.mbglMap->addSource(std::move(_pendingSource)); } +- (void)setSourceLoaded +{ + _rawSource->setSourceLoaded(); +} + +- (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y +{ + NSLog(@"processData %li/%li/%li", (long)z, (long)x, (long)y); +} @end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index b9ba0be3041..8a850b6d327 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -171,8 +171,8 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; - 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB291DCB7A9200B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2A1DCB7AFC00B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; @@ -1408,7 +1408,6 @@ buildActionMask = 2147483647; files = ( 35D13AC31D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, - 88F0C0831DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, DA88483A1CBAFB8500AB86E3 /* MGLAnnotationImage.h in Headers */, DA35A2BB1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */, 353933FE1D3FB7DD003F57D7 /* MGLSymbolStyleLayer.h in Headers */, @@ -1501,6 +1500,7 @@ DA8848871CBB033F00AB86E3 /* Fabric.h in Headers */, 35305D4A1D22AA6A0007D005 /* NSData+MGLAdditions.h in Headers */, 359F57461D2FDDA6005217F1 /* MGLUserLocationAnnotationView_Private.h in Headers */, + 88DDFB2A1DCB7AFC00B53BDD /* MGLCustomVectorSource.h in Headers */, 404C26E21D89B877000AA13D /* MGLTileSet.h in Headers */, DA8848841CBB033F00AB86E3 /* FABAttributes.h in Headers */, DA8847FD1CBAFA5100AB86E3 /* MGLTilePyramidOfflineRegion.h in Headers */, @@ -1522,7 +1522,7 @@ DA35A2CA1CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */, 350098BC1D480108004B2AF0 /* MGLVectorSource.h in Headers */, 353933FC1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */, - 88F0C0841DC8FD8C002DB7AE /* MGLCustomVectorSource.h in Headers */, + 88DDFB291DCB7A9200B53BDD /* MGLCustomVectorSource.h in Headers */, 3566C76D1D4A8DFA008152BC /* MGLRasterSource.h in Headers */, DAED38641D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */, DABFB85E1CBE99E500D62B32 /* MGLAnnotation.h in Headers */, diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 2d4b4f15768..7740eacd346 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -5,7 +5,11 @@ namespace mbgl { namespace style { CustomVectorSource::CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile) - : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)) { + : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), + impl(static_cast(baseImpl.get())) { } + + void CustomVectorSource::setSourceLoaded() { + impl->setSourceLoaded(); } } // namespace style diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 4337cb04461..09567610428 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -20,9 +21,14 @@ namespace mbgl { std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { auto tilePointer = std::make_unique(tileID, base.getID(), parameters); -// setTileData(*tilePointer.get(), tileID); + fetchTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y); return std::move(tilePointer); } + + void CustomVectorSource::Impl::setSourceLoaded() { + loaded = true; + observer->onSourceLoaded(base); + } } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index 5482ffd5014..c3a8b3fda09 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -11,7 +11,8 @@ namespace mbgl { Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); void loadDescription(FileSource&) final {} - + void setSourceLoaded(); + private: CustomVectorSourceOptions options; std::function fetchTile; From d2c62ef516cc37f2c73768bd6340f3e534cc1ad6 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 08:59:08 -0600 Subject: [PATCH 06/61] Get rid of setSourceLoaded non-sense --- include/mbgl/style/sources/custom_vector_source.hpp | 2 -- platform/darwin/src/MGLCustomVectorSource.mm | 4 ---- src/mbgl/style/sources/custom_vector_source.cpp | 4 ---- src/mbgl/style/sources/custom_vector_source_impl.cpp | 6 +----- src/mbgl/style/sources/custom_vector_source_impl.hpp | 1 - 5 files changed, 1 insertion(+), 16 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 77a5459d660..eb48b79dd23 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -17,8 +17,6 @@ namespace style { class CustomVectorSource : public Source { public: CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile); - - void setSourceLoaded(); // Private implementation diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index d34efa4a2d6..f4fef40ae10 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -58,10 +58,6 @@ - (void)addToMapView:(MGLMapView *)mapView mapView.mbglMap->addSource(std::move(_pendingSource)); } -- (void)setSourceLoaded -{ - _rawSource->setSourceLoaded(); -} - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 7740eacd346..f2fc96f5ddf 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -8,9 +8,5 @@ namespace mbgl { : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), impl(static_cast(baseImpl.get())) { } - void CustomVectorSource::setSourceLoaded() { - impl->setSourceLoaded(); - } - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 09567610428..279972736a8 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -8,6 +8,7 @@ namespace mbgl { CustomVectorSource::Impl::Impl(std::string id, Source& base_, CustomVectorSourceOptions options_, std::function fetchTile_) : Source::Impl(SourceType::Vector, std::move(id), base_), options(options_), fetchTile(fetchTile_) { + loaded = true; } Range CustomVectorSource::Impl::getZoomRange() { @@ -24,11 +25,6 @@ namespace mbgl { fetchTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y); return std::move(tilePointer); } - - void CustomVectorSource::Impl::setSourceLoaded() { - loaded = true; - observer->onSourceLoaded(base); - } } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index c3a8b3fda09..ea193fed206 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -11,7 +11,6 @@ namespace mbgl { Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); void loadDescription(FileSource&) final {} - void setSourceLoaded(); private: CustomVectorSourceOptions options; From 908a7e24197f1472ae1c4d74f3c5d54713389209 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 11:50:19 -0600 Subject: [PATCH 07/61] It works! --- .../style/sources/custom_vector_source.hpp | 4 ++-- platform/darwin/src/MGLCustomVectorSource.h | 2 -- platform/darwin/src/MGLCustomVectorSource.mm | 13 ++++++++++-- .../style/sources/custom_vector_source.cpp | 4 ++++ .../sources/custom_vector_source_impl.cpp | 20 +++++++++++++++++++ .../sources/custom_vector_source_impl.hpp | 3 ++- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index eb48b79dd23..e25d216bc71 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include namespace mbgl { namespace style { @@ -18,6 +17,7 @@ class CustomVectorSource : public Source { public: CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile); + void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); // Private implementation class Impl; diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index f7e53313a17..5b8e3ea0891 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -57,8 +57,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, nullable) NSString *attribution; -- (void)setSourceLoaded; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index f4fef40ae10..f1890b5ea25 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -3,8 +3,10 @@ #import "MGLMapView_Private.h" #import "MGLSource_Private.h" #import "MGLFeature_Private.h" +#import "MGLShape_Private.h" #include +#include @interface MGLCustomVectorSource () { std::unique_ptr _pendingSource; @@ -34,7 +36,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUI ^(NS_ARRAY_OF(id ) *features) { [self processData:features forTile:z x:x y:y]; -// NSLog(@"Got tile data into callback%@", tiledata); }]; }); @@ -58,10 +59,18 @@ - (void)addToMapView:(MGLMapView *)mapView mapView.mbglMap->addSource(std::move(_pendingSource)); } - - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { NSLog(@"processData %li/%li/%li", (long)z, (long)x, (long)y); + + mbgl::FeatureCollection featureCollection; + featureCollection.reserve(features.count); + for (id feature in features) + { + featureCollection.push_back([feature mbglFeature]); + } + const auto geojson = mbgl::GeoJSON{featureCollection}; + self.rawSource->setTileData(z, x, y, geojson); } diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index f2fc96f5ddf..ee526ca04c5 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -8,5 +8,9 @@ namespace mbgl { : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), impl(static_cast(baseImpl.get())) { } + void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { + impl->setTileData(z, x, y, geoJSON); + } + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 279972736a8..3ef20b5fada 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -26,5 +27,24 @@ namespace mbgl { return std::move(tilePointer); } + void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) + { + double scale = util::EXTENT / util::tileSize; + + mapbox::geojsonvt::Options vtOptions; + vtOptions.maxZoom = options.maxzoom; + vtOptions.extent = util::EXTENT; + vtOptions.buffer = std::round(scale * 0);//options.buffer + vtOptions.tolerance = scale * 1;//options.tolerance + mapbox::geojsonvt::GeoJSONVT geojSONVT = mapbox::geojsonvt::GeoJSONVT(geoJSON, vtOptions); + + for (auto const &item : tiles) { + GeoJSONTile* geoJSONTile = static_cast(item.second.get()); + if(geoJSONTile->id.canonical.z == z && geoJSONTile->id.canonical.x == x && geoJSONTile->id.canonical.y == y) { + geoJSONTile->updateData(geojSONVT.getTile(z, x, y).features); + } + } + } + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index ea193fed206..664ccc9bcd1 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -11,7 +11,8 @@ namespace mbgl { Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); void loadDescription(FileSource&) final {} - + void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); + private: CustomVectorSourceOptions options; std::function fetchTile; From 30c9cb94c8657f7c4e3b98065a08a0c2e3e11b8c Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 12:11:16 -0600 Subject: [PATCH 08/61] Inherit Options from GeoJSONOptions --- .../style/sources/custom_vector_source.hpp | 5 ++- .../sources/custom_vector_source_impl.cpp | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index e25d216bc71..5474e138184 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -2,13 +2,12 @@ #include #include - +#include namespace mbgl { namespace style { - struct CustomVectorSourceOptions { + struct CustomVectorSourceOptions : GeoJSONOptions { uint8_t minzoom = 0; - uint8_t maxzoom = 18; uint16_t tileSize = 512; }; diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 3ef20b5fada..2d793457681 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -31,17 +32,34 @@ namespace mbgl { { double scale = util::EXTENT / util::tileSize; - mapbox::geojsonvt::Options vtOptions; - vtOptions.maxZoom = options.maxzoom; - vtOptions.extent = util::EXTENT; - vtOptions.buffer = std::round(scale * 0);//options.buffer - vtOptions.tolerance = scale * 1;//options.tolerance - mapbox::geojsonvt::GeoJSONVT geojSONVT = mapbox::geojsonvt::GeoJSONVT(geoJSON, vtOptions); + variant geoJSONOrSupercluster; + if (!options.cluster) { + mapbox::geojsonvt::Options vtOptions; + vtOptions.maxZoom = options.maxzoom; + vtOptions.extent = util::EXTENT; + vtOptions.buffer = std::round(scale * options.buffer); + vtOptions.tolerance = scale * options.tolerance; + geoJSONOrSupercluster = std::make_unique(geoJSON, vtOptions); + } else { + mapbox::supercluster::Options clusterOptions; + clusterOptions.maxZoom = options.clusterMaxZoom; + clusterOptions.extent = util::EXTENT; + clusterOptions.radius = std::round(scale * options.clusterRadius); + + const auto& features = geoJSON.get>(); + geoJSONOrSupercluster = + std::make_unique(features, clusterOptions); + } for (auto const &item : tiles) { - GeoJSONTile* geoJSONTile = static_cast(item.second.get()); - if(geoJSONTile->id.canonical.z == z && geoJSONTile->id.canonical.x == x && geoJSONTile->id.canonical.y == y) { - geoJSONTile->updateData(geojSONVT.getTile(z, x, y).features); + GeoJSONTile* tile = static_cast(item.second.get()); + if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + if (geoJSONOrSupercluster.is()) { + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); + } else { + assert(geoJSONOrSupercluster.is()); + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); + } } } } From aa5b27eb3aa13e454fd97fc32f04d6ad596eb49f Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 13:37:59 -0600 Subject: [PATCH 09/61] Create a common base class between MGLGeoJSONSource and MGLCustomVectorSource --- .../style/sources/custom_vector_source.hpp | 8 +-- include/mbgl/style/sources/geojson_source.hpp | 3 + platform/darwin/src/MGLCustomVectorSource.h | 30 ++------- platform/darwin/src/MGLCustomVectorSource.mm | 18 ++--- platform/darwin/src/MGLGeoJSONSource.h | 52 +-------------- platform/darwin/src/MGLGeoJSONSource.mm | 50 +------------- platform/darwin/src/MGLGeoJSONSourceBase.h | 63 ++++++++++++++++++ platform/darwin/src/MGLGeoJSONSourceBase.mm | 65 +++++++++++++++++++ .../darwin/src/MGLGeoJSONSourceBase_Private.h | 10 +++ .../darwin/src/MGLGeoJSONSource_Private.h | 2 - platform/ios/ios.xcodeproj/project.pbxproj | 14 ++++ .../style/sources/custom_vector_source.cpp | 2 +- .../sources/custom_vector_source_impl.cpp | 2 +- .../sources/custom_vector_source_impl.hpp | 4 +- 14 files changed, 172 insertions(+), 151 deletions(-) create mode 100644 platform/darwin/src/MGLGeoJSONSourceBase.h create mode 100644 platform/darwin/src/MGLGeoJSONSourceBase.mm create mode 100644 platform/darwin/src/MGLGeoJSONSourceBase_Private.h diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 5474e138184..e2e4884227e 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -6,15 +6,9 @@ namespace mbgl { namespace style { - struct CustomVectorSourceOptions : GeoJSONOptions { - uint8_t minzoom = 0; - uint16_t tileSize = 512; - }; - - class CustomVectorSource : public Source { public: - CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile); + CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); // Private implementation diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index e633e6efba8..0fd2c28c5a2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -26,7 +26,10 @@ using SuperclusterPointer = std::unique_ptr; struct GeoJSONOptions { // GeoJSON-VT options + uint8_t minzoom = 0; + uint8_t maxzoom = 18; + uint16_t tileSize = 512; uint16_t buffer = 128; double tolerance = 0.375; diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 5b8e3ea0891..deb04421604 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -1,10 +1,11 @@ #import "MGLSource.h" +#import "MGLGeoJSONSource.h" +#import "MGLGeoJSONSourceBase.h" NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; - @protocol MGLCustomVectorSourceDataSource /** @@ -12,14 +13,13 @@ NS_ASSUME_NONNULL_BEGIN @param zoom @param y @param x - @param callback A block to call with the data that has been fetched for the tile. The data can be in the form of a - GeoJSON Feature, FeatureCollection, or Geometry. + @param callback A block to call with the data that has been fetched for the tile. */ - (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( void (^)(NSArray>*) )callback; @end -@interface MGLCustomVectorSource : MGLSource +@interface MGLCustomVectorSource : MGLGeoJSONSourceBase /** Returns a custom vector datasource initialized with an identifier, datasource, and zoom levels. @@ -29,33 +29,13 @@ NS_ASSUME_NONNULL_BEGIN @param maximumZoomLevel The maximum zoom level at which the source will display tiles. @param dataSource An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ -- (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel dataSource:(NSObject*)dataSource NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER; /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ @property (nonatomic, readonly, copy) NSObject *dataSource; -/** - An `NSNumber` object containing an integer; specifies the minimum zoom level at - which the source will display tiles. The value should be in the range of 0 to - 22. - */ -@property (nonatomic, nonnull) NSNumber *minimumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to display tiles. The value should be in the range of 0 to 22 and greater - than `minimumZoomLevel`. - */ -@property (nonatomic, nonnull) NSNumber *maximumZoomLevel; - -/** - An `NSString` object that contains an attribution to be displayed when the map - is shown to a user. The default value is `nil`. - */ -@property (nonatomic, copy, nullable) NSString *attribution; - @end diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index f1890b5ea25..51bf5c9397c 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -4,6 +4,7 @@ #import "MGLSource_Private.h" #import "MGLFeature_Private.h" #import "MGLShape_Private.h" +#import "MGLGeoJSONSourceBase_Private.h" #include #include @@ -12,21 +13,20 @@ @interface MGLCustomVectorSource () { std::unique_ptr _pendingSource; } +@property (nonatomic, readwrite) NSDictionary *options; @property (nonnull) mbgl::style::CustomVectorSource *rawSource; @end @implementation MGLCustomVectorSource -- (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel dataSource:(NSObject*)dataSource +- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options { if (self = [super initWithIdentifier:identifier]) { - _maximumZoomLevel = @(maximumZoomLevel); - _minimumZoomLevel = @(minimumZoomLevel); _dataSource = dataSource; - auto source = std::make_unique(self.identifier.UTF8String, self.customSourceOptions, + auto source = std::make_unique(self.identifier.UTF8String, self.geoJSONOptions, ^void(uint8_t z, uint32_t x, uint32_t y) { [self.dataSource getTileForZoom:z @@ -46,14 +46,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier minimumZoomLevel:(NSUI return self; } -- (mbgl::style::CustomVectorSourceOptions)customSourceOptions -{ - auto options = mbgl::style::CustomVectorSourceOptions(); - options.minzoom = self.minimumZoomLevel.integerValue; - options.maxzoom = self.maximumZoomLevel.integerValue; - return options; -} - - (void)addToMapView:(MGLMapView *)mapView { mapView.mbglMap->addSource(std::move(_pendingSource)); @@ -61,8 +53,6 @@ - (void)addToMapView:(MGLMapView *)mapView - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { - NSLog(@"processData %li/%li/%li", (long)z, (long)x, (long)y); - mbgl::FeatureCollection featureCollection; featureCollection.reserve(features.count); for (id feature in features) diff --git a/platform/darwin/src/MGLGeoJSONSource.h b/platform/darwin/src/MGLGeoJSONSource.h index 30232c62111..6b680e2219c 100644 --- a/platform/darwin/src/MGLGeoJSONSource.h +++ b/platform/darwin/src/MGLGeoJSONSource.h @@ -1,67 +1,19 @@ #import "MGLSource.h" #import "MGLTypes.h" +#import "MGLGeoJSONSourceBase.h" NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; -/** - Options for `MGLGeoJSONSource` objects. - */ -typedef NSString *MGLGeoJSONSourceOption NS_STRING_ENUM; - -/** - An `NSNumber` object containing a Boolean enabling or disabling clustering. - If the `features` property contains point features, setting this option to - `YES` clusters the points by radius into groups. The default value is `NO`. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered; - -/** - An `NSNumber` object containing an integer; specifies the radius of each - cluster if clustering is enabled. A value of 512 produces a radius equal to - the width of a tile. The default value is 50. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to cluster points if clustering is enabled. Defaults to one zoom level - less than the value of `MGLGeoJSONSourceOptionMaximumZoomLevel` so that, at the - maximum zoom level, the features are not clustered. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to create vector tiles. A greater value produces greater detail at high - zoom levels. The default value is 18. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the size of the tile - buffer on each side. A value of 0 produces no buffer. A value of 512 produces a - buffer as wide as the tile itself. Larger values produce fewer rendering - artifacts near tile edges and slower performance. The default value is 128. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer; - -/** - An `NSNumber` object containing a double; specifies the Douglas-Peucker - simplification tolerance. A greater value produces simpler geometries and - improves performance. The default value is 0.375. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance; - /** A GeoJSON source. @see The style specification. */ -@interface MGLGeoJSONSource : MGLSource +@interface MGLGeoJSONSource : MGLGeoJSONSourceBase #pragma mark Initializing a Source diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index 8b37ba47cdb..c300fa28863 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -1,4 +1,5 @@ #import "MGLGeoJSONSource_Private.h" +#import "MGLGeoJSONSourceBase_Private.h" #import "MGLMapView_Private.h" #import "MGLSource_Private.h" @@ -8,12 +9,6 @@ #include -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered = @"MGLGeoJSONSourceOptionClustered"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius = @"MGLGeoJSONSourceOptionClusterRadius"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering = @"MGLGeoJSONSourceOptionMaximumZoomLevelForClustering"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel = @"MGLGeoJSONSourceOptionMaximumZoomLevel"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer = @"MGLGeoJSONSourceOptionBuffer"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"MGLGeoJSONSourceOptionSimplificationTolerance"; @interface MGLGeoJSONSource () @@ -106,50 +101,7 @@ - (void)commonInit self.rawSource = _pendingSource.get(); } -- (mbgl::style::GeoJSONOptions)geoJSONOptions -{ - auto mbglOptions = mbgl::style::GeoJSONOptions(); - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { - [self validateValue:value]; - mbglOptions.maxzoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { - [self validateValue:value]; - mbglOptions.buffer = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { - [self validateValue:value]; - mbglOptions.tolerance = [value doubleValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { - [self validateValue:value]; - mbglOptions.clusterRadius = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { - [self validateValue:value]; - mbglOptions.clusterMaxZoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { - [self validateValue:value]; - mbglOptions.cluster = [value boolValue]; - } - - return mbglOptions; -} -- (void)validateValue:(id)value -{ - if (! [value isKindOfClass:[NSNumber class]]) - { - [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; - } -} - (void)setGeoJSONData:(NSData *)geoJSONData { diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.h b/platform/darwin/src/MGLGeoJSONSourceBase.h new file mode 100644 index 00000000000..e459ff6d20a --- /dev/null +++ b/platform/darwin/src/MGLGeoJSONSourceBase.h @@ -0,0 +1,63 @@ +#import "MGLSource.h" + + +/** + Options for `MGLGeoJSONSource` objects. + */ +typedef NSString *MGLGeoJSONSourceOption NS_STRING_ENUM; + +/** + An `NSNumber` object containing a Boolean enabling or disabling clustering. + If the `features` property contains point features, setting this option to + `YES` clusters the points by radius into groups. The default value is `NO`. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered; + +/** + An `NSNumber` object containing an integer; specifies the radius of each + cluster if clustering is enabled. A value of 512 produces a radius equal to + the width of a tile. The default value is 50. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius; + +/** + An `NSNumber` object containing an integer; specifies the maximum zoom level at + which to cluster points if clustering is enabled. Defaults to one zoom level + less than the value of `MGLGeoJSONSourceOptionMaximumZoomLevel` so that, at the + maximum zoom level, the features are not clustered. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering; + +/** + An `NSNumber` object containing an integer; specifies the minimum zoom level at + which to create vector tiles. The default value is 0. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel; + +/** + An `NSNumber` object containing an integer; specifies the maximum zoom level at + which to create vector tiles. A greater value produces greater detail at high + zoom levels. The default value is 18. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel; + +/** + An `NSNumber` object containing an integer; specifies the size of the tile + buffer on each side. A value of 0 produces no buffer. A value of 512 produces a + buffer as wide as the tile itself. Larger values produce fewer rendering + artifacts near tile edges and slower performance. The default value is 128. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer; + +/** + An `NSNumber` object containing a double; specifies the Douglas-Peucker + simplification tolerance. A greater value produces simpler geometries and + improves performance. The default value is 0.375. + */ +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance; + + +@interface MGLGeoJSONSourceBase : MGLSource + + +@end diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm new file mode 100644 index 00000000000..ca67335597f --- /dev/null +++ b/platform/darwin/src/MGLGeoJSONSourceBase.mm @@ -0,0 +1,65 @@ +#import "MGLGeoJSONSourceBase.h" +#import "MGLGeoJSONSourceBase_Private.h" + +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered = @"MGLGeoJSONSourceOptionClustered"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius = @"MGLGeoJSONSourceOptionClusterRadius"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering = @"MGLGeoJSONSourceOptionMaximumZoomLevelForClustering"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel = @"MGLGeoJSONSourceOptionMaximumZoomLevel"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel = @"MGLGeoJSONSourceOptionMinimumZoomLevel"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer = @"MGLGeoJSONSourceOptionBuffer"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"MGLGeoJSONSourceOptionSimplificationTolerance"; + +@implementation MGLGeoJSONSourceBase + +- (mbgl::style::GeoJSONOptions)geoJSONOptions +{ + auto mbglOptions = mbgl::style::GeoJSONOptions(); + + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { + [self validateValue:value]; + mbglOptions.maxzoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionMinimumZoomLevel]) { + [self validateValue:value]; + mbglOptions.minzoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { + [self validateValue:value]; + mbglOptions.buffer = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { + [self validateValue:value]; + mbglOptions.tolerance = [value doubleValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { + [self validateValue:value]; + mbglOptions.clusterRadius = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { + [self validateValue:value]; + mbglOptions.clusterMaxZoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { + [self validateValue:value]; + mbglOptions.cluster = [value boolValue]; + } + + return mbglOptions; +} + +- (void)validateValue:(id)value +{ + if (! [value isKindOfClass:[NSNumber class]]) + { + [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; + } +} + + +@end diff --git a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h new file mode 100644 index 00000000000..008f9763018 --- /dev/null +++ b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h @@ -0,0 +1,10 @@ +#import "MGLGeoJSONSource.h" + +#include + +@interface MGLGeoJSONSourceBase (Private) + +@property (nonatomic, readwrite) NSDictionary *options; +- (mbgl::style::GeoJSONOptions)geoJSONOptions; + +@end diff --git a/platform/darwin/src/MGLGeoJSONSource_Private.h b/platform/darwin/src/MGLGeoJSONSource_Private.h index de5bb10face..ed6821af6db 100644 --- a/platform/darwin/src/MGLGeoJSONSource_Private.h +++ b/platform/darwin/src/MGLGeoJSONSource_Private.h @@ -5,6 +5,4 @@ @interface MGLGeoJSONSource (Private) -- (mbgl::style::GeoJSONOptions)geoJSONOptions; - @end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 8a850b6d327..a45884bd82e 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -173,6 +173,10 @@ 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 88DDFB291DCB7A9200B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88DDFB2A1DCB7AFC00B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2D1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2E1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2F1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */; }; + 88DDFB301DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */; }; 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; @@ -592,6 +596,9 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; + 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSourceBase.h; sourceTree = ""; }; + 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLGeoJSONSourceBase.mm; sourceTree = ""; }; + 88DDFB311DCBC36E00B53BDD /* MGLGeoJSONSourceBase_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSourceBase_Private.h; sourceTree = ""; }; 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCustomVectorSource.h; sourceTree = ""; }; 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLCustomVectorSource.mm; sourceTree = ""; tabWidth = 4; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -842,6 +849,9 @@ 404C26E11D89B877000AA13D /* MGLTileSet.mm */, 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */, 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */, + 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */, + 88DDFB311DCBC36E00B53BDD /* MGLGeoJSONSourceBase_Private.h */, + 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */, ); name = Sources; sourceTree = ""; @@ -1434,6 +1444,7 @@ 353933F51D3FB785003F57D7 /* MGLBackgroundStyleLayer.h in Headers */, DA88485A1CBAFB9800AB86E3 /* MGLUserLocation_Private.h in Headers */, DA27C24F1CBB4C11000B0ECD /* MGLAccountManager_Private.h in Headers */, + 88DDFB2D1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */, DA8847FC1CBAFA5100AB86E3 /* MGLStyle.h in Headers */, 354B83961D2E873E005D9406 /* MGLUserLocationAnnotationView.h in Headers */, DA8847F01CBAFA5100AB86E3 /* MGLAnnotation.h in Headers */, @@ -1535,6 +1546,7 @@ 404C26E31D89B877000AA13D /* MGLTileSet.h in Headers */, DABFB8611CBE99E500D62B32 /* MGLMultiPoint.h in Headers */, 3510FFF11D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, + 88DDFB2E1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */, 35E0CFE71D3E501500188327 /* MGLStyle_Private.h in Headers */, DABFB86D1CBE9A0F00D62B32 /* MGLAnnotationImage.h in Headers */, DABFB8721CBE9A0F00D62B32 /* MGLUserLocation.h in Headers */, @@ -1969,6 +1981,7 @@ DA8848321CBAFA6200AB86E3 /* NSString+MGLAdditions.m in Sources */, 408AA8581DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, DA35A2A11CC9E95F00E826B2 /* MGLCoordinateFormatter.m in Sources */, + 88DDFB2F1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */, 35305D481D22AA680007D005 /* NSData+MGLAdditions.mm in Sources */, DA8848291CBAFA6200AB86E3 /* MGLStyle.mm in Sources */, DA88481C1CBAFA6200AB86E3 /* MGLGeometry.mm in Sources */, @@ -2043,6 +2056,7 @@ DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */, 408AA8591DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, DAA4E4281CBB730400178DFB /* MGLTypes.m in Sources */, + 88DDFB301DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */, DA35A2A21CC9E95F00E826B2 /* MGLCoordinateFormatter.m in Sources */, 35305D491D22AA680007D005 /* NSData+MGLAdditions.mm in Sources */, DAA4E42D1CBB730400178DFB /* MGLAnnotationImage.m in Sources */, diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index ee526ca04c5..175d3d0a58e 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { - CustomVectorSource::CustomVectorSource(std::string id, CustomVectorSourceOptions options, std::function fetchTile) + CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile) : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), impl(static_cast(baseImpl.get())) { } diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 2d793457681..08f4475114a 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -8,7 +8,7 @@ namespace mbgl { namespace style { - CustomVectorSource::Impl::Impl(std::string id, Source& base_, CustomVectorSourceOptions options_, std::function fetchTile_) + CustomVectorSource::Impl::Impl(std::string id, Source& base_, GeoJSONOptions options_, std::function fetchTile_) : Source::Impl(SourceType::Vector, std::move(id), base_), options(options_), fetchTile(fetchTile_) { loaded = true; } diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index 664ccc9bcd1..2ab276ecbe3 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -8,13 +8,13 @@ namespace mbgl { class CustomVectorSource::Impl : public Source::Impl { public: - Impl(std::string id, Source&, CustomVectorSourceOptions options, std::function fetchTile); + Impl(std::string id, Source&, GeoJSONOptions options, std::function fetchTile); void loadDescription(FileSource&) final {} void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); private: - CustomVectorSourceOptions options; + GeoJSONOptions options; std::function fetchTile; uint16_t getTileSize() const; From b6015b8035bb74fe438a7ff9d501dbe60260d0b7 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 13:47:35 -0600 Subject: [PATCH 10/61] Dont use hardcoded default tile size --- include/mbgl/style/sources/geojson_source.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 0fd2c28c5a2..ea96e6bac20 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -29,7 +30,7 @@ struct GeoJSONOptions { uint8_t minzoom = 0; uint8_t maxzoom = 18; - uint16_t tileSize = 512; + uint16_t tileSize = util::tileSize; uint16_t buffer = 128; double tolerance = 0.375; From 6986db524b6364e4ad2efea4b49f98728e4130df Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 13:48:45 -0600 Subject: [PATCH 11/61] Fix indentation --- .../style/sources/custom_vector_source.hpp | 2 +- .../sources/custom_vector_source_impl.hpp | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index e2e4884227e..add80bcda3f 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -8,7 +8,7 @@ namespace style { class CustomVectorSource : public Source { public: - CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); + CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); // Private implementation diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index 2ab276ecbe3..33316444917 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -4,24 +4,24 @@ #include namespace mbgl { - namespace style { +namespace style { - class CustomVectorSource::Impl : public Source::Impl { - public: - Impl(std::string id, Source&, GeoJSONOptions options, std::function fetchTile); +class CustomVectorSource::Impl : public Source::Impl { +public: + Impl(std::string id, Source&, GeoJSONOptions options, std::function fetchTile); - void loadDescription(FileSource&) final {} - void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); + void loadDescription(FileSource&) final {} + void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); - private: - GeoJSONOptions options; - std::function fetchTile; +private: + GeoJSONOptions options; + std::function fetchTile; - uint16_t getTileSize() const; - Range getZoomRange() final; - std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; + uint16_t getTileSize() const; + Range getZoomRange() final; + std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; - }; - - } // namespace style +}; + +} // namespace style } // namespace mbgl From 74823134ed9cdb37993a0af14ee532973e665b3b Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 13:51:13 -0600 Subject: [PATCH 12/61] Revert development team setting --- platform/ios/ios.xcodeproj/project.pbxproj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index a45884bd82e..c643a646c7c 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -1740,7 +1740,6 @@ TargetAttributes = { DA1DC9491CB6C1C2006E619F = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DA25D5B81CCD9EDE00607828 = { CreatedOnToolsVersion = 7.3; @@ -1752,7 +1751,6 @@ }; DA8847D11CBAF91600AB86E3 = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DA8933D41CCD306400E68420 = { CreatedOnToolsVersion = 7.3; @@ -1764,7 +1762,6 @@ }; DABCABA71CB80692000A7C39 = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; }; }; @@ -2282,7 +2279,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = PEWGB469RG; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2295,7 +2292,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = PEWGB469RG; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2376,6 +2373,7 @@ BITCODE_GENERATION_MODE = bitcode; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -2409,6 +2407,7 @@ BITCODE_GENERATION_MODE = bitcode; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -2511,6 +2510,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/benchmark/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2523,6 +2523,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/benchmark/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; From f556388dcd06df8cafe79e4f5da141fce751568f Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 13:55:19 -0600 Subject: [PATCH 13/61] Revert more project file changes --- platform/ios/ios.xcodeproj/project.pbxproj | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index c643a646c7c..ada3edc28fc 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -1743,22 +1743,18 @@ }; DA25D5B81CCD9EDE00607828 = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DA2E88501CC036F400F24E7B = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DA8847D11CBAF91600AB86E3 = { CreatedOnToolsVersion = 7.3; }; DA8933D41CCD306400E68420 = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DAA4E4121CBB71D400178DFB = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = PEWGB469RG; }; DABCABA71CB80692000A7C39 = { CreatedOnToolsVersion = 7.3; @@ -2203,7 +2199,6 @@ CURRENT_SEMANTIC_VERSION = 1.0.0; CURRENT_SHORT_VERSION = 1.0; DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = PEWGB469RG; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -2255,7 +2250,6 @@ CURRENT_SEMANTIC_VERSION = 1.0.0; CURRENT_SHORT_VERSION = 1.0; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = PEWGB469RG; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -2279,7 +2273,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2292,7 +2285,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2373,7 +2365,6 @@ BITCODE_GENERATION_MODE = bitcode; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -2407,7 +2398,6 @@ BITCODE_GENERATION_MODE = bitcode; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -2510,7 +2500,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/benchmark/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2523,7 +2512,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/benchmark/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; From 0f61a1fca2404af35f98b4fa3cbe9913f7e28830 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 3 Nov 2016 15:06:06 -0600 Subject: [PATCH 14/61] Update docs --- platform/darwin/src/MGLCustomVectorSource.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index deb04421604..b81652c5a3b 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -6,6 +6,9 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; +/** + Data source for `MGLCustomVectorSource`. + */ @protocol MGLCustomVectorSourceDataSource /** @@ -19,15 +22,21 @@ NS_ASSUME_NONNULL_BEGIN @end +/** + A source for vector data that is fetched 1 tile at a time. Usefull for sources that are + too large to fit in memory, or are already divided into tiles, but not in Mapbox Vector Tile format. + */ @interface MGLCustomVectorSource : MGLGeoJSONSourceBase /** - Returns a custom vector datasource initialized with an identifier, datasource, and zoom levels. + Returns a custom vector datasource initialized with an identifier, datasource, and a + dictionary of options for the source according to the + style + specification. @param identifier A string that uniquely identifies the source. - @param minimumZoomLevel The minimum zoom level at which the source will display tiles. - @param maximumZoomLevel The maximum zoom level at which the source will display tiles. @param dataSource An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. + @param options An `NSDictionary` of options for this source. */ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER; From 74345066856d44da857c668447bace2316688d9f Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 06:06:50 -0700 Subject: [PATCH 15/61] Run MGLCustomSource queries on an NSOperationQueue --- platform/darwin/src/MGLCustomVectorSource.h | 4 +++ platform/darwin/src/MGLCustomVectorSource.mm | 33 ++++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index b81652c5a3b..a5ee4525af6 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -45,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, copy) NSObject *dataSource; +/** + A queue that calls to the datasource will be made on. + */ +@property (nonatomic, readonly) NSOperationQueue *requestQueue; @end diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 51bf5c9397c..cfbbb3c5526 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -25,19 +25,24 @@ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject(self.identifier.UTF8String, self.geoJSONOptions, - ^void(uint8_t z, uint32_t x, uint32_t y) - { - [self.dataSource getTileForZoom:z - x:x - y:y - callback: - ^(NS_ARRAY_OF(id ) *features) - { - [self processData:features forTile:z x:x y:y]; - }]; - }); + ^void(uint8_t z, uint32_t x, uint32_t y) + { + [self.requestQueue addOperationWithBlock: + ^{ + [self.dataSource getTileForZoom:z + x:x + y:y + callback: + ^(NS_ARRAY_OF(id ) *features) + { + [self processData:features forTile:z x:x y:y]; + }]; + }]; + }); _pendingSource = std::move(source); self.rawSource = _pendingSource.get(); @@ -60,7 +65,9 @@ - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x featureCollection.push_back([feature mbglFeature]); } const auto geojson = mbgl::GeoJSON{featureCollection}; - self.rawSource->setTileData(z, x, y, geojson); + dispatch_async(dispatch_get_main_queue(), ^{ + self.rawSource->setTileData(z, x, y, geojson); + }); } From 474905b0d03f08cf20602260b9dbdd45c3d458bb Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 06:18:30 -0700 Subject: [PATCH 16/61] Add example usage of MGLCustomVectorSource to setting in iosapp target --- platform/ios/app/MBXViewController.m | 84 +++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 8a2ccee4135..5359d441efb 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -72,6 +72,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingRasterSource, MBXSettingsRuntimeStylingCountryLabels, MBXSettingsRuntimeStylingRouteLine, + MBXSettingsRuntimeStylingCustomLatLonGrid, }; typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @@ -102,7 +103,8 @@ @implementation MBXSpriteBackedAnnotation @interface MBXViewController () + MGLMapViewDelegate, + MGLCustomVectorSourceDataSource> @property (nonatomic) IBOutlet MGLMapView *mapView; @@ -334,6 +336,7 @@ - (void)dismissSettings:(__unused id)sender @"Style Raster Source", [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], @"Add Route Line", + @"Add Custom Lat/Lon Grid", ]]; break; case MBXSettingsMiscellaneous: @@ -495,6 +498,9 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath case MBXSettingsRuntimeStylingRouteLine: [self styleRouteLine]; break; + case MBXSettingsRuntimeStylingCustomLatLonGrid: + [self addLatLonGrid]; + break; default: NSAssert(NO, @"All runtime styling setting rows should be implemented"); break; @@ -1136,6 +1142,21 @@ - (void)styleRouteLine [self.mapView.style addLayer:routeLayer]; } +- (void)addLatLonGrid +{ + MGLCustomVectorSource *source = [[MGLCustomVectorSource alloc] initWithIdentifier:@"latlon" + dataSource:self + options:@{MGLGeoJSONSourceOptionMinimumZoomLevel:@14}]; + [self.mapView.style addSource:source]; + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"latlonlines" + source:source]; + [self.mapView.style addLayer:lineLayer]; + MGLSymbolStyleLayer *labelLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"latlonlabels" + source:source]; + labelLayer.textField = [MGLStyleValue valueWithRawValue:@"{value}"]; + [self.mapView.style addLayer:labelLayer]; +} + - (void)styleLabelLanguageForLayersNamed:(NSArray *)layers { _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; @@ -1600,4 +1621,65 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } } +#pragma mark - MGLCustomVectorSourceDataSource +- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( void (^)(NSArray>*) )callback { + int tilesAtThisZoom = 1 << zoom; + double lngWidth = 360.0 / tilesAtThisZoom; + CLLocationCoordinate2D southwest; + CLLocationCoordinate2D northeast; + southwest.longitude = -180 + (x * lngWidth); + northeast.longitude = southwest.longitude + lngWidth; + + double latHeightMerc = 1.0 / tilesAtThisZoom; + double topLatMerc = y * latHeightMerc; + double bottomLatMerc = topLatMerc + latHeightMerc; + + southwest.latitude = (180 / M_PI) * ((2 * atan(exp(M_PI * (1 - (2 * bottomLatMerc))))) - (M_PI / 2.0)); + northeast.latitude = (180 / M_PI) * ((2 * atan(exp(M_PI * (1 - (2 * topLatMerc))))) - (M_PI / 2.0)); + + double gridSpacing; + if(zoom >= 13) { + gridSpacing = 0.01; + } else if(zoom >= 11) { + gridSpacing = 0.05; + } else if(zoom == 10) { + gridSpacing = .1; + } else if(zoom == 9) { + gridSpacing = 0.25; + } else if(zoom == 8) { + gridSpacing = 0.5; + } else if (zoom >= 6) { + gridSpacing = 1; + } else if(zoom == 5) { + gridSpacing = 2; + } else if(zoom >= 4) { + gridSpacing = 5; + } else if(zoom == 2) { + gridSpacing = 10; + } else { + gridSpacing = 20; + } + + NSMutableArray > * features = [NSMutableArray array]; + CLLocationCoordinate2D coords[2]; + + for (double y = ceil(northeast.latitude / gridSpacing) * gridSpacing; y >= floor(southwest.latitude / gridSpacing) * gridSpacing; y -= gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(y, southwest.longitude); + coords[1] = CLLocationCoordinate2DMake(y, northeast.longitude); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(y)}; + [features addObject:feature]; + } + + for (double x = floor(southwest.longitude / gridSpacing) * gridSpacing; x <= ceil(northeast.longitude / gridSpacing) * gridSpacing; x += gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(southwest.latitude, x); + coords[1] = CLLocationCoordinate2DMake(northeast.latitude, x); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(x)}; + [features addObject:feature]; + } + + callback(features); +} + @end From b2cdaa32e499b5188a3b25abf500aa41a9d17b54 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 06:47:51 -0700 Subject: [PATCH 17/61] Add method to reload a tile --- include/mbgl/style/sources/custom_vector_source.hpp | 3 ++- platform/darwin/src/MGLCustomVectorSource.h | 5 +++++ platform/darwin/src/MGLCustomVectorSource.mm | 6 ++++++ src/mbgl/style/sources/custom_vector_source.cpp | 3 +++ src/mbgl/style/sources/custom_vector_source_impl.cpp | 9 +++++++++ src/mbgl/style/sources/custom_vector_source_impl.hpp | 1 + 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index add80bcda3f..24bad7a080c 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -11,8 +11,9 @@ class CustomVectorSource : public Source { CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); - // Private implementation + void updateTile(uint8_t, uint32_t, uint32_t); + // Private implementation class Impl; Impl* const impl; }; diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index a5ee4525af6..dd738f0279c 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -40,6 +40,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER; +/** + Request that the source reloads a tile. Tile will only be reloaded if it is currently on screen. + */ +- (void)updateTile:(NSInteger)z x:(NSInteger)x y:(NSInteger)y; + /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index cfbbb3c5526..e6f260400a0 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -70,5 +70,11 @@ - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x }); } +- (void)updateTile:(NSInteger)z x:(NSInteger)x y:(NSInteger)y +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); + }); +} @end diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 175d3d0a58e..8e45ab1a333 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -12,5 +12,8 @@ namespace mbgl { impl->setTileData(z, x, y, geoJSON); } + void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { + impl->updateTile(z, x, y); + } } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 08f4475114a..4b13911c9aa 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -64,5 +64,14 @@ namespace mbgl { } } + void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { + for (auto const &item : tiles) { + GeoJSONTile* tile = static_cast(item.second.get()); + if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + fetchTile(z, x, y); + } + } + } + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index 33316444917..b29f5749f10 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -12,6 +12,7 @@ class CustomVectorSource::Impl : public Source::Impl { void loadDescription(FileSource&) final {} void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); + void updateTile(uint8_t, uint32_t, uint32_t); private: GeoJSONOptions options; From 36f0dd2d95c26dacfae4978b86cd84abe4a40105 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 11:01:16 -0700 Subject: [PATCH 18/61] Change names in obj-c classes to be consistent with project naming conventions --- platform/darwin/src/MGLCustomVectorSource.h | 4 ++-- platform/darwin/src/MGLCustomVectorSource.mm | 12 ++++++------ platform/ios/app/MBXViewController.m | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index dd738f0279c..9592fb12912 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @param x @param callback A block to call with the data that has been fetched for the tile. */ -- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( void (^)(NSArray>*) )callback; +- (void)getTileForZoomLevel:(NSUInteger)zoomLevel x:(NSUInteger)x y:(NSUInteger)y completionHandler:( void (^)(NSArray>*) )completionHandler; @end @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN /** Request that the source reloads a tile. Tile will only be reloaded if it is currently on screen. */ -- (void)updateTile:(NSInteger)z x:(NSInteger)x y:(NSInteger)y; +- (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y; /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index e6f260400a0..14b0cc1d330 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -33,10 +33,10 @@ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject) *features) { [self processData:features forTile:z x:x y:y]; @@ -46,7 +46,7 @@ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject)*)features forTile:(uint8_t)z x }); } -- (void)updateTile:(NSInteger)z x:(NSInteger)x y:(NSInteger)y +- (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y { dispatch_async(dispatch_get_main_queue(), ^{ self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 5359d441efb..7f8af7e1e8d 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1622,7 +1622,7 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } #pragma mark - MGLCustomVectorSourceDataSource -- (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( void (^)(NSArray>*) )callback { +- (void)getTileForZoomLevel:(NSUInteger)zoom x:(NSUInteger)x y:(NSUInteger)y completionHandler:(void (^)(NSArray> * _Nonnull))completionHandler { int tilesAtThisZoom = 1 << zoom; double lngWidth = 360.0 / tilesAtThisZoom; CLLocationCoordinate2D southwest; @@ -1679,7 +1679,7 @@ - (void)getTileForZoom:(NSInteger)zoom x:(NSInteger)x y:(NSInteger)y callback:( [features addObject:feature]; } - callback(features); + completionHandler(features); } @end From a530538307469849ad7049c3c9b74db4422cb04f Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 11:01:45 -0700 Subject: [PATCH 19/61] Change indentation to match project standards --- .../style/sources/custom_vector_source.cpp | 26 ++++--- .../sources/custom_vector_source_impl.cpp | 77 +++++++++---------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 8e45ab1a333..96ba9ddda46 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -2,18 +2,20 @@ #include namespace mbgl { - namespace style { +namespace style { - CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile) - : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), - impl(static_cast(baseImpl.get())) { } +CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile) + : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), + impl(static_cast(baseImpl.get())) { +} + +void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { + impl->setTileData(z, x, y, geoJSON); +} + +void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { + impl->updateTile(z, x, y); +} - void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { - impl->setTileData(z, x, y, geoJSON); - } - - void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { - impl->updateTile(z, x, y); - } - } // namespace style +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 4b13911c9aa..1bbcdcc382a 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -6,41 +6,40 @@ #include namespace mbgl { - namespace style { +namespace style { - CustomVectorSource::Impl::Impl(std::string id, Source& base_, GeoJSONOptions options_, std::function fetchTile_) +CustomVectorSource::Impl::Impl(std::string id, Source& base_, GeoJSONOptions options_, std::function fetchTile_) : Source::Impl(SourceType::Vector, std::move(id), base_), options(options_), fetchTile(fetchTile_) { - loaded = true; - } + loaded = true; +} - Range CustomVectorSource::Impl::getZoomRange() { - return { options.minzoom, options.maxzoom }; - } +Range CustomVectorSource::Impl::getZoomRange() { + return { options.minzoom, options.maxzoom }; +} - uint16_t CustomVectorSource::Impl::getTileSize() const { - return options.tileSize; - } +uint16_t CustomVectorSource::Impl::getTileSize() const { + return options.tileSize; +} - std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, +std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { - auto tilePointer = std::make_unique(tileID, base.getID(), parameters); - fetchTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y); - return std::move(tilePointer); - } + auto tilePointer = std::make_unique(tileID, base.getID(), parameters); + fetchTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y); + return std::move(tilePointer); +} + +void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { + double scale = util::EXTENT / util::tileSize; - void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) - { - double scale = util::EXTENT / util::tileSize; - - variant geoJSONOrSupercluster; - if (!options.cluster) { + variant geoJSONOrSupercluster; + if (!options.cluster) { mapbox::geojsonvt::Options vtOptions; vtOptions.maxZoom = options.maxzoom; vtOptions.extent = util::EXTENT; vtOptions.buffer = std::round(scale * options.buffer); vtOptions.tolerance = scale * options.tolerance; geoJSONOrSupercluster = std::make_unique(geoJSON, vtOptions); - } else { + } else { mapbox::supercluster::Options clusterOptions; clusterOptions.maxZoom = options.clusterMaxZoom; clusterOptions.extent = util::EXTENT; @@ -49,29 +48,29 @@ namespace mbgl { const auto& features = geoJSON.get>(); geoJSONOrSupercluster = std::make_unique(features, clusterOptions); - } - - for (auto const &item : tiles) { + } + + for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { - if (geoJSONOrSupercluster.is()) { - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); - } else { - assert(geoJSONOrSupercluster.is()); - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); - } + if (geoJSONOrSupercluster.is()) { + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); + } else { + assert(geoJSONOrSupercluster.is()); + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); + } } - } } +} - void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { - for (auto const &item : tiles) { - GeoJSONTile* tile = static_cast(item.second.get()); - if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { - fetchTile(z, x, y); - } +void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { + for (auto const &item : tiles) { + GeoJSONTile* tile = static_cast(item.second.get()); + if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + fetchTile(z, x, y); } } +} - } // namespace style +} // namespace style } // namespace mbgl From 6c589ed314a3bf81d45641645fb50f12c701a71d Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 7 Nov 2016 15:33:48 -0700 Subject: [PATCH 20/61] Fix Options not getting used for geojson or custom source --- platform/darwin/src/MGLCustomVectorSource.mm | 2 +- platform/darwin/src/MGLGeoJSONSource.mm | 10 +++------- platform/darwin/src/MGLGeoJSONSourceBase.mm | 9 +++++++++ platform/darwin/src/MGLGeoJSONSourceBase_Private.h | 3 +++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 14b0cc1d330..f8de9878d9c 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -22,7 +22,7 @@ @implementation MGLCustomVectorSource - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options { - if (self = [super initWithIdentifier:identifier]) + if (self = [super initWithIdentifier:identifier options:options]) { _dataSource = dataSource; diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index c300fa28863..81e8b3b3d76 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -12,7 +12,6 @@ @interface MGLGeoJSONSource () -@property (nonatomic, readwrite) NSDictionary *options; @property (nonatomic) mbgl::style::GeoJSONSource *rawSource; @end @@ -24,10 +23,9 @@ @implementation MGLGeoJSONSource - (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options { - if (self = [super initWithIdentifier:identifier]) + if (self = [super initWithIdentifier:identifier options:options]) { _geoJSONData = data; - _options = options; [self commonInit]; } return self; @@ -35,19 +33,17 @@ - (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *) - (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options { - if (self = [super initWithIdentifier:identifier]) + if (self = [super initWithIdentifier:identifier options:options]) { _URL = url; - _options = options; [self commonInit]; } return self; } - (instancetype)initWithIdentifier:(NSString *)identifier features:(NSArray> *)features options:(NS_DICTIONARY_OF(NSString *,id) *)options { - if (self = [super initWithIdentifier:identifier]) { + if (self = [super initWithIdentifier:identifier options:options]) { _features = features; - _options = options; [self commonInit]; } diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm index ca67335597f..a99b8d74e40 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase.mm +++ b/platform/darwin/src/MGLGeoJSONSourceBase.mm @@ -11,6 +11,15 @@ @implementation MGLGeoJSONSourceBase + +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(NSString *, id) *)options +{ + if (self = [super initWithIdentifier:identifier]) { + self.options = options; + } + return self; +} + - (mbgl::style::GeoJSONOptions)geoJSONOptions { auto mbglOptions = mbgl::style::GeoJSONOptions(); diff --git a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h index 008f9763018..d978af8e961 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h +++ b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h @@ -5,6 +5,9 @@ @interface MGLGeoJSONSourceBase (Private) @property (nonatomic, readwrite) NSDictionary *options; + +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(NSString *, id) *)options; + - (mbgl::style::GeoJSONOptions)geoJSONOptions; @end From dcd7f8e607ac7408144e8e6f92c35f7f1446e66a Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 8 Nov 2016 05:36:03 -0700 Subject: [PATCH 21/61] add function to custom source to reload all tiles --- include/mbgl/style/sources/custom_vector_source.hpp | 3 ++- platform/darwin/src/MGLCustomVectorSource.h | 5 +++++ platform/darwin/src/MGLCustomVectorSource.mm | 7 +++++++ src/mbgl/style/sources/custom_vector_source.cpp | 6 +++++- src/mbgl/style/sources/custom_vector_source_impl.cpp | 7 +++++++ src/mbgl/style/sources/custom_vector_source_impl.hpp | 1 + 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 24bad7a080c..3bf7c968f03 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -12,7 +12,8 @@ class CustomVectorSource : public Source { void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); void updateTile(uint8_t, uint32_t, uint32_t); - + void reload(); + // Private implementation class Impl; Impl* const impl; diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 9592fb12912..2f7acf2e147 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -45,6 +45,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y; +/** + Reload all tiles. + */ +- (void)reload; + /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index f8de9878d9c..b9663f25d77 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -77,4 +77,11 @@ - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y }); } +- (void)reload +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.rawSource->reload(); + }); +} + @end diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 96ba9ddda46..7a7f1093a9f 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -16,6 +16,10 @@ void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const ma void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { impl->updateTile(z, x, y); } - + +void CustomVectorSource::reload() { + impl->reload(); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 1bbcdcc382a..cb3bd400086 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -71,6 +71,13 @@ void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { } } } + +void CustomVectorSource::Impl::reload() { + for (auto const &item : tiles) { + GeoJSONTile* tile = static_cast(item.second.get()); + fetchTile(tile->id.canonical.z, tile->id.canonical.x, tile->id.canonical.y); + } +} } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index b29f5749f10..e7bf18eef33 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -13,6 +13,7 @@ class CustomVectorSource::Impl : public Source::Impl { void loadDescription(FileSource&) final {} void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); void updateTile(uint8_t, uint32_t, uint32_t); + void reload(); private: GeoJSONOptions options; From e403ed9c08ff35418c320dc0d79bc5083d876783 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 8 Nov 2016 09:39:00 -0700 Subject: [PATCH 22/61] Fix crash when parsing an empty feature collection with clustering enabled --- .../sources/custom_vector_source_impl.cpp | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index cb3bd400086..2708cbe0525 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -31,33 +31,42 @@ std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileI void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { double scale = util::EXTENT / util::tileSize; - variant geoJSONOrSupercluster; - if (!options.cluster) { - mapbox::geojsonvt::Options vtOptions; - vtOptions.maxZoom = options.maxzoom; - vtOptions.extent = util::EXTENT; - vtOptions.buffer = std::round(scale * options.buffer); - vtOptions.tolerance = scale * options.tolerance; - geoJSONOrSupercluster = std::make_unique(geoJSON, vtOptions); + if(geoJSON.is() && geoJSON.get().size() == 0) { + for (auto const &item : tiles) { + GeoJSONTile* tile = static_cast(item.second.get()); + if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + tile->updateData(mapbox::geometry::feature_collection()); + } + } } else { - mapbox::supercluster::Options clusterOptions; - clusterOptions.maxZoom = options.clusterMaxZoom; - clusterOptions.extent = util::EXTENT; - clusterOptions.radius = std::round(scale * options.clusterRadius); + variant geoJSONOrSupercluster; + if (!options.cluster) { + mapbox::geojsonvt::Options vtOptions; + vtOptions.maxZoom = options.maxzoom; + vtOptions.extent = util::EXTENT; + vtOptions.buffer = std::round(scale * options.buffer); + vtOptions.tolerance = scale * options.tolerance; + geoJSONOrSupercluster = std::make_unique(geoJSON, vtOptions); + } else { + mapbox::supercluster::Options clusterOptions; + clusterOptions.maxZoom = options.clusterMaxZoom; + clusterOptions.extent = util::EXTENT; + clusterOptions.radius = std::round(scale * options.clusterRadius); + + const auto& features = geoJSON.get>(); + geoJSONOrSupercluster = + std::make_unique(features, clusterOptions); + } - const auto& features = geoJSON.get>(); - geoJSONOrSupercluster = - std::make_unique(features, clusterOptions); - } - - for (auto const &item : tiles) { - GeoJSONTile* tile = static_cast(item.second.get()); - if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { - if (geoJSONOrSupercluster.is()) { - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); - } else { - assert(geoJSONOrSupercluster.is()); - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); + for (auto const &item : tiles) { + GeoJSONTile* tile = static_cast(item.second.get()); + if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + if (geoJSONOrSupercluster.is()) { + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); + } else { + assert(geoJSONOrSupercluster.is()); + tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); + } } } } From 50e7fe9fb8dfb84b69a801e1c1f6f05cbdef1fee Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 05:02:20 -0700 Subject: [PATCH 23/61] Revert unintended changes to project file --- platform/ios/ios.xcodeproj/project.pbxproj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index ada3edc28fc..5cf40f43cc5 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -421,6 +421,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; + proxyType = 1; + remoteGlobalIDString = DA25D5B81CCD9EDE00607828; + remoteInfo = settings; + }; DA25D5C91CCDA0CC00607828 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; @@ -1668,6 +1675,7 @@ buildRules = ( ); dependencies = ( + DA25D5C81CCDA0C100607828 /* PBXTargetDependency */, ); name = dynamic; productName = framework; @@ -1746,6 +1754,7 @@ }; DA2E88501CC036F400F24E7B = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; DA8847D11CBAF91600AB86E3 = { CreatedOnToolsVersion = 7.3; @@ -2094,6 +2103,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + DA25D5C81CCDA0C100607828 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = DA25D5B81CCD9EDE00607828 /* settings */; + targetProxy = DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */; + }; DA25D5CA1CCDA0CC00607828 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DA8933D41CCD306400E68420 /* bundle */; From adfc031e0e55ad00c8478dad36984b5cc4ca75f9 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 05:04:54 -0700 Subject: [PATCH 24/61] Revert unintended whitespace --- platform/ios/ios.xcodeproj/project.pbxproj | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 5cf40f43cc5..92a3eaf83fc 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -421,13 +421,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; - proxyType = 1; - remoteGlobalIDString = DA25D5B81CCD9EDE00607828; - remoteInfo = settings; - }; + DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; + proxyType = 1; + remoteGlobalIDString = DA25D5B81CCD9EDE00607828; + remoteInfo = settings; + }; DA25D5C91CCDA0CC00607828 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = DA1DC9421CB6C1C2006E619F /* Project object */; @@ -2104,10 +2104,10 @@ /* Begin PBXTargetDependency section */ DA25D5C81CCDA0C100607828 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = DA25D5B81CCD9EDE00607828 /* settings */; - targetProxy = DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */; - }; + isa = PBXTargetDependency; + target = DA25D5B81CCD9EDE00607828 /* settings */; + targetProxy = DA25D5C71CCDA0C100607828 /* PBXContainerItemProxy */; + }; DA25D5CA1CCDA0CC00607828 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = DA8933D41CCD306400E68420 /* bundle */; From 570da2c3cdcc73430ba7af9e46dc8418818e5fc1 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 05:45:49 -0700 Subject: [PATCH 25/61] re-indent to 4 spaces --- platform/darwin/src/MGLGeoJSONSourceBase.mm | 92 ++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm index a99b8d74e40..ef4aeae5cec 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase.mm +++ b/platform/darwin/src/MGLGeoJSONSourceBase.mm @@ -14,60 +14,60 @@ @implementation MGLGeoJSONSourceBase - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(NSString *, id) *)options { - if (self = [super initWithIdentifier:identifier]) { - self.options = options; - } - return self; + if (self = [super initWithIdentifier:identifier]) { + self.options = options; + } + return self; } - (mbgl::style::GeoJSONOptions)geoJSONOptions { - auto mbglOptions = mbgl::style::GeoJSONOptions(); - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { - [self validateValue:value]; - mbglOptions.maxzoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionMinimumZoomLevel]) { - [self validateValue:value]; - mbglOptions.minzoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { - [self validateValue:value]; - mbglOptions.buffer = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { - [self validateValue:value]; - mbglOptions.tolerance = [value doubleValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { - [self validateValue:value]; - mbglOptions.clusterRadius = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { - [self validateValue:value]; - mbglOptions.clusterMaxZoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { - [self validateValue:value]; - mbglOptions.cluster = [value boolValue]; - } - - return mbglOptions; + auto mbglOptions = mbgl::style::GeoJSONOptions(); + + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { + [self validateValue:value]; + mbglOptions.maxzoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionMinimumZoomLevel]) { + [self validateValue:value]; + mbglOptions.minzoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { + [self validateValue:value]; + mbglOptions.buffer = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { + [self validateValue:value]; + mbglOptions.tolerance = [value doubleValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { + [self validateValue:value]; + mbglOptions.clusterRadius = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { + [self validateValue:value]; + mbglOptions.clusterMaxZoom = [value integerValue]; + } + + if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { + [self validateValue:value]; + mbglOptions.cluster = [value boolValue]; + } + + return mbglOptions; } - (void)validateValue:(id)value { - if (! [value isKindOfClass:[NSNumber class]]) - { - [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; - } + if (! [value isKindOfClass:[NSNumber class]]) + { + [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; + } } From cb76fe9a90acaefd392c80a446166da0974d47e6 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 06:20:50 -0700 Subject: [PATCH 26/61] naming/spelling changes --- platform/darwin/src/MGLCustomVectorSource.h | 6 +++--- platform/darwin/src/MGLCustomVectorSource.mm | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 2f7acf2e147..6fcc0b703f2 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -16,14 +16,14 @@ NS_ASSUME_NONNULL_BEGIN @param zoom @param y @param x - @param callback A block to call with the data that has been fetched for the tile. + @param completionHandler A block to call with the data that has been fetched for the tile. */ - (void)getTileForZoomLevel:(NSUInteger)zoomLevel x:(NSUInteger)x y:(NSUInteger)y completionHandler:( void (^)(NSArray>*) )completionHandler; @end /** - A source for vector data that is fetched 1 tile at a time. Usefull for sources that are + A source for vector data that is fetched 1 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. */ @interface MGLCustomVectorSource : MGLGeoJSONSourceBase @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN /** Reload all tiles. */ -- (void)reload; +- (void)reloadData; /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index b9663f25d77..71359203319 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -77,7 +77,7 @@ - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y }); } -- (void)reload +- (void)reloadData { dispatch_async(dispatch_get_main_queue(), ^{ self.rawSource->reload(); From f6a908f491e0435a43f961acd6a1a3120c23a1a8 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 06:32:19 -0700 Subject: [PATCH 27/61] Change MGLCustomVectorSourceDataSource to not use a callback --- platform/darwin/src/MGLCustomVectorSource.h | 5 ++--- platform/darwin/src/MGLCustomVectorSource.mm | 13 +++++-------- platform/ios/app/MBXViewController.m | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 6fcc0b703f2..9d9f229fc19 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -16,9 +16,8 @@ NS_ASSUME_NONNULL_BEGIN @param zoom @param y @param x - @param completionHandler A block to call with the data that has been fetched for the tile. */ -- (void)getTileForZoomLevel:(NSUInteger)zoomLevel x:(NSUInteger)x y:(NSUInteger)y completionHandler:( void (^)(NSArray>*) )completionHandler; +- (NSArray>*)getTileForZoomLevel:(NSUInteger)zoomLevel x:(NSUInteger)x y:(NSUInteger)y; @end @@ -53,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ -@property (nonatomic, readonly, copy) NSObject *dataSource; +@property (nonatomic, weak) id dataSource; /** A queue that calls to the datasource will be made on. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 71359203319..6319453b88b 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -33,14 +33,11 @@ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject) *features) - { - [self processData:features forTile:z x:x y:y]; - }]; + [self processData: + [self.dataSource getTileForZoomLevel:z + x:x + y:y] + forTile:z x:x y:y]; }]; }); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 7f8af7e1e8d..2aeb115615c 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1622,7 +1622,7 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } #pragma mark - MGLCustomVectorSourceDataSource -- (void)getTileForZoomLevel:(NSUInteger)zoom x:(NSUInteger)x y:(NSUInteger)y completionHandler:(void (^)(NSArray> * _Nonnull))completionHandler { +- (NSArray>*)getTileForZoomLevel:(NSUInteger)zoom x:(NSUInteger)x y:(NSUInteger)y { int tilesAtThisZoom = 1 << zoom; double lngWidth = 360.0 / tilesAtThisZoom; CLLocationCoordinate2D southwest; @@ -1679,7 +1679,7 @@ - (void)getTileForZoomLevel:(NSUInteger)zoom x:(NSUInteger)x y:(NSUInteger)y com [features addObject:feature]; } - completionHandler(features); + return features; } @end From d731490a66b6c06a175ab265cda204835393ab1b Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 06:32:33 -0700 Subject: [PATCH 28/61] Make custom source demo work --- platform/ios/app/MBXViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 2aeb115615c..5415107e836 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1146,7 +1146,7 @@ - (void)addLatLonGrid { MGLCustomVectorSource *source = [[MGLCustomVectorSource alloc] initWithIdentifier:@"latlon" dataSource:self - options:@{MGLGeoJSONSourceOptionMinimumZoomLevel:@14}]; + options:@{MGLGeoJSONSourceOptionMaximumZoomLevel:@14}]; [self.mapView.style addSource:source]; MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"latlonlines" source:source]; From 92ed92270444fa8644d573b31a81055261f16d83 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 06:58:11 -0700 Subject: [PATCH 29/61] Use MGLGeoJSONSourceOption type --- platform/darwin/src/MGLCustomVectorSource.h | 2 +- platform/darwin/src/MGLCustomVectorSource.mm | 2 +- platform/darwin/src/MGLGeoJSONSourceBase.mm | 2 +- platform/darwin/src/MGLGeoJSONSourceBase_Private.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 9d9f229fc19..6d6cf0ef313 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @param dataSource An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. @param options An `NSDictionary` of options for this source. */ -- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; /** Request that the source reloads a tile. Tile will only be reloaded if it is currently on screen. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 6319453b88b..5658743a927 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -20,7 +20,7 @@ @interface MGLCustomVectorSource () { @implementation MGLCustomVectorSource -- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(NSString *, id) *)options +- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options { if (self = [super initWithIdentifier:identifier options:options]) { diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm index ef4aeae5cec..4f7271d96e7 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase.mm +++ b/platform/darwin/src/MGLGeoJSONSourceBase.mm @@ -12,7 +12,7 @@ @implementation MGLGeoJSONSourceBase -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(NSString *, id) *)options +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options { if (self = [super initWithIdentifier:identifier]) { self.options = options; diff --git a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h index d978af8e961..45a6e531415 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h +++ b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h @@ -4,9 +4,9 @@ @interface MGLGeoJSONSourceBase (Private) -@property (nonatomic, readwrite) NSDictionary *options; +@property (nonatomic, readwrite) NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *options; -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(NSString *, id) *)options; +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options; - (mbgl::style::GeoJSONOptions)geoJSONOptions; From 18e7c603aadf1fd196796a1f512aa5544fc83b8b Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 09:13:21 -0700 Subject: [PATCH 30/61] add boost to header search paths so mbgl/util/tile_cover.hpp can be included in an obj-c++ file --- platform/ios/ios.xcodeproj/project.pbxproj | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 92a3eaf83fc..b624631eade 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -2382,7 +2382,10 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + HEADER_SEARCH_PATHS = ( + "$(mbgl_core_INCLUDE_DIRECTORIES)", + ../../mason_packages/headers/boost/1.60.0/include, + ); INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2415,7 +2418,10 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + HEADER_SEARCH_PATHS = ( + "$(mbgl_core_INCLUDE_DIRECTORIES)", + ../../mason_packages/headers/boost/1.60.0/include, + ); INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2465,7 +2471,10 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + HEADER_SEARCH_PATHS = ( + "$(mbgl_core_INCLUDE_DIRECTORIES)", + ../../mason_packages/headers/boost/1.60.0/include, + ); OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2490,7 +2499,10 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; + HEADER_SEARCH_PATHS = ( + "$(mbgl_core_INCLUDE_DIRECTORIES)", + ../../mason_packages/headers/boost/1.60.0/include, + ); OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", From d742e841cd2bd6a19dff22e4e9135479166c420a Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 09:32:29 -0700 Subject: [PATCH 31/61] Revert "add boost to header search paths so mbgl/util/tile_cover.hpp can be included in an obj-c++ file" This reverts commit 53d37890fcbe92fb67fcbbded6f448af696885ae. --- platform/ios/ios.xcodeproj/project.pbxproj | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index b624631eade..92a3eaf83fc 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -2382,10 +2382,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - ../../mason_packages/headers/boost/1.60.0/include, - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2418,10 +2415,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - ../../mason_packages/headers/boost/1.60.0/include, - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2471,10 +2465,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - ../../mason_packages/headers/boost/1.60.0/include, - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", @@ -2499,10 +2490,7 @@ baseConfigurationReference = 55D8C9941D0F133500F42F10 /* config.xcconfig */; buildSettings = { BITCODE_GENERATION_MODE = bitcode; - HEADER_SEARCH_PATHS = ( - "$(mbgl_core_INCLUDE_DIRECTORIES)", - ../../mason_packages/headers/boost/1.60.0/include, - ); + HEADER_SEARCH_PATHS = "$(mbgl_core_INCLUDE_DIRECTORIES)"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "$(sqlite_cflags)", From ccb17deb4f5185409d46cf979812aaa0b3649f06 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 09:40:28 -0700 Subject: [PATCH 32/61] Add -reloadTileInCoordinateBounds:zoomLevel: method to MGLCustomVectorSource --- .../mbgl/style/sources/custom_vector_source.hpp | 3 +++ platform/darwin/src/MGLCustomVectorSource.h | 5 +++-- platform/darwin/src/MGLCustomVectorSource.mm | 14 ++++++++------ src/mbgl/style/sources/custom_vector_source.cpp | 6 +++++- .../style/sources/custom_vector_source_impl.cpp | 7 +++++++ .../style/sources/custom_vector_source_impl.hpp | 1 + 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 3bf7c968f03..49b3e81e91e 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -2,7 +2,9 @@ #include #include +#include #include + namespace mbgl { namespace style { @@ -12,6 +14,7 @@ class CustomVectorSource : public Source { void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); void updateTile(uint8_t, uint32_t, uint32_t); + void reloadRegion(mbgl::LatLngBounds bounds, uint8_t z); void reload(); // Private implementation diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 6d6cf0ef313..24ec3e01cde 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -1,6 +1,7 @@ #import "MGLSource.h" #import "MGLGeoJSONSource.h" #import "MGLGeoJSONSourceBase.h" +#import "MGLGeometry.h" NS_ASSUME_NONNULL_BEGIN @@ -40,9 +41,9 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; /** - Request that the source reloads a tile. Tile will only be reloaded if it is currently on screen. + Request that the source reloads a region. */ -- (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y; +- (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel; /** Reload all tiles. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 5658743a927..92ca27d8082 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -5,6 +5,7 @@ #import "MGLFeature_Private.h" #import "MGLShape_Private.h" #import "MGLGeoJSONSourceBase_Private.h" +#import "MGLGeometry_Private.h" #include #include @@ -67,18 +68,19 @@ - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x }); } +- (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel +{ + self.rawSource->reloadRegion(MGLLatLngBoundsFromCoordinateBounds(bounds), (uint8_t)zoomLevel); +} + - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y { - dispatch_async(dispatch_get_main_queue(), ^{ - self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); - }); + self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); } - (void)reloadData { - dispatch_async(dispatch_get_main_queue(), ^{ - self.rawSource->reload(); - }); + self.rawSource->reload(); } @end diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 7a7f1093a9f..55e7974a83e 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -12,7 +12,11 @@ CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, s void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { impl->setTileData(z, x, y, geoJSON); } - + +void CustomVectorSource::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { + impl->reloadRegion(bounds, z); +} + void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { impl->updateTile(z, x, y); } diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 2708cbe0525..8b9f0d1c5e0 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,12 @@ void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { } } +void CustomVectorSource::Impl::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { + for (const auto& tile : mbgl::util::tileCover(bounds, z)) { + updateTile(tile.canonical.z, tile.canonical.x, tile.canonical.z); + } +} + void CustomVectorSource::Impl::reload() { for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index e7bf18eef33..132c933ec2a 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -13,6 +13,7 @@ class CustomVectorSource::Impl : public Source::Impl { void loadDescription(FileSource&) final {} void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); void updateTile(uint8_t, uint32_t, uint32_t); + void reloadRegion(mbgl::LatLngBounds bounds, uint8_t z); void reload(); private: From d8ffb919c7de171eabcf918380c9fae6c72e03e4 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 10 Nov 2016 09:52:45 -0700 Subject: [PATCH 33/61] Add import to Mapbox.h --- platform/ios/src/Mapbox.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index aa7ba533035..eb065c544b5 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -44,7 +44,9 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLBackgroundStyleLayer.h" #import "MGLSource.h" #import "MGLVectorSource.h" +#import "MGLGeoJSONSourceBase.h" #import "MGLGeoJSONSource.h" +#import "MGLCustomVectorSource.h" #import "MGLRasterSource.h" #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" @@ -54,4 +56,3 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h" #import "MGLTileSet.h" -#import "MGLCustomVectorSource.h" From d73737096961df5cd34576f0f5283e6c494490ed Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 14 Nov 2016 11:17:17 -0700 Subject: [PATCH 34/61] Add new MGLCustomVectorSourceDataSource method based on bounds instead of tile id --- platform/darwin/src/MGLCustomVectorSource.h | 27 ++++++---- platform/darwin/src/MGLCustomVectorSource.mm | 57 ++++++++++++++------ platform/ios/app/MBXViewController.m | 4 +- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLCustomVectorSource.h index 24ec3e01cde..2ed262345da 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLCustomVectorSource.h @@ -8,17 +8,27 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; /** - Data source for `MGLCustomVectorSource`. + Data source for `MGLCustomVectorSource`. This protocol defines two optionak methods for fetching + data, one based on tile coordinates, and one based on a bounding box. Clases that implement this + protocol must implement one, and only one of the methods. */ @protocol MGLCustomVectorSourceDataSource +@optional /** - Fetch data for a tile - @param zoom - @param y - @param x + Fetch features for a tile. This will not be called on the main queue, it will be called on the callers requestQueue. + @param x tile X coordinate + @param y tile Y coordinate + @param zoomLevel tile zoom level */ -- (NSArray>*)getTileForZoomLevel:(NSUInteger)zoomLevel x:(NSUInteger)x y:(NSUInteger)y; +- (NSArray>*)featuresInTileAtX:(NSUInteger)x y:(NSUInteger)y zoomLevel:(NSUInteger)zoomLevel; + +/** + Fetch features for a tile. This will not be called on the main queue, it will be called on the callers requestQueue. + @param bounds The bounds to fetch data for + @param zoomLevel tile zoom level + */ +- (NSArray>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel; @end @@ -35,10 +45,9 @@ NS_ASSUME_NONNULL_BEGIN specification. @param identifier A string that uniquely identifies the source. - @param dataSource An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. @param options An `NSDictionary` of options for this source. */ -- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; /** Request that the source reloads a region. @@ -53,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ -@property (nonatomic, weak) id dataSource; +@property (nonatomic, weak, nullable) id dataSource; /** A queue that calls to the datasource will be made on. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 92ca27d8082..97e849af778 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -9,6 +9,7 @@ #include #include +#include @interface MGLCustomVectorSource () { std::unique_ptr _pendingSource; @@ -16,31 +17,42 @@ @interface MGLCustomVectorSource () { @property (nonatomic, readwrite) NSDictionary *options; @property (nonnull) mbgl::style::CustomVectorSource *rawSource; +@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForTile; +@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForBounds; @end @implementation MGLCustomVectorSource -- (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject*)dataSource options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options +- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options { if (self = [super initWithIdentifier:identifier options:options]) { - _dataSource = dataSource; - _requestQueue = [[NSOperationQueue alloc] init]; self.requestQueue.name = [NSString stringWithFormat:@"mgl.CustomVectorSource.%@", identifier]; - auto source = std::make_unique(self.identifier.UTF8String, self.geoJSONOptions, - ^void(uint8_t z, uint32_t x, uint32_t y) - { - [self.requestQueue addOperationWithBlock: - ^{ - [self processData: - [self.dataSource getTileForZoomLevel:z - x:x - y:y] - forTile:z x:x y:y]; - }]; - }); + auto source = std::make_unique + (self.identifier.UTF8String, self.geoJSONOptions, + ^void(uint8_t z, uint32_t x, uint32_t y) + { + [self.requestQueue addOperationWithBlock: + ^{ + NSArray> *data; + if(!self.dataSource) { + data = nil; + } else if(self.dataSourceImplementsFeaturesForTile) { + data = [self.dataSource featuresInTileAtX:x + y:y + zoomLevel:z]; + } else { +// mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(z, x, y); +// mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); +// data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) +// zoomLevel:z]; + } + [self processData:data + forTile:z x:x y:y]; + }]; + }); _pendingSource = std::move(source); self.rawSource = _pendingSource.get(); @@ -49,6 +61,21 @@ - (instancetype)initWithIdentifier:(NSString *)identifier dataSource:(NSObject)dataSource +{ + //Check which method the datasource implements, to avoid having to check for each tile + self.dataSourceImplementsFeaturesForTile = [dataSource respondsToSelector:@selector(featuresInTileAtX:y:zoomLevel:)]; + self.dataSourceImplementsFeaturesForBounds = [dataSource respondsToSelector:@selector(featuresInCoordinateBounds:zoomLevel:)]; + + if(!self.dataSourceImplementsFeaturesForBounds && !self.dataSourceImplementsFeaturesForTile) { + [NSException raise:@"Invalid Datasource" format:@"Datasource does not implement any MGLCustomVectorSourceDataSource methods"]; + } else if(self.dataSourceImplementsFeaturesForBounds && self.dataSourceImplementsFeaturesForTile) { + [NSException raise:@"Invalid Datasource" format:@"Datasource implements multiple MGLCustomVectorSourceDataSource methods"]; + } + + _dataSource = dataSource; +} + - (void)addToMapView:(MGLMapView *)mapView { mapView.mbglMap->addSource(std::move(_pendingSource)); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 5415107e836..58ce0a7d645 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1145,8 +1145,8 @@ - (void)styleRouteLine - (void)addLatLonGrid { MGLCustomVectorSource *source = [[MGLCustomVectorSource alloc] initWithIdentifier:@"latlon" - dataSource:self options:@{MGLGeoJSONSourceOptionMaximumZoomLevel:@14}]; + source.dataSource = self; [self.mapView.style addSource:source]; MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"latlonlines" source:source]; @@ -1622,7 +1622,7 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } #pragma mark - MGLCustomVectorSourceDataSource -- (NSArray>*)getTileForZoomLevel:(NSUInteger)zoom x:(NSUInteger)x y:(NSUInteger)y { +- (NSArray>*)featuresInTileAtX:(NSUInteger)x y:(NSUInteger)y zoomLevel:(NSUInteger)zoom { int tilesAtThisZoom = 1 << zoom; double lngWidth = 360.0 / tilesAtThisZoom; CLLocationCoordinate2D southwest; From 2e9e56831ebf0d67ec9389d4f35b474e008ca2e2 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 17 Nov 2016 14:22:09 -0700 Subject: [PATCH 35/61] updated cmake file list --- cmake/core-files.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 6a87be8b5fb..5fe24a14e85 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -304,9 +304,13 @@ set(MBGL_CORE_FILES src/mbgl/style/layers/symbol_layer_properties.hpp # style/sources + include/mbgl/style/sources/custom_vector_source.hpp include/mbgl/style/sources/geojson_source.hpp include/mbgl/style/sources/raster_source.hpp include/mbgl/style/sources/vector_source.hpp + src/mbgl/style/sources/custom_vector_source.cpp + src/mbgl/style/sources/custom_vector_source_impl.cpp + src/mbgl/style/sources/custom_vector_source_impl.hpp src/mbgl/style/sources/geojson_source.cpp src/mbgl/style/sources/geojson_source_impl.cpp src/mbgl/style/sources/geojson_source_impl.hpp From 244d68977428dcb92079a7fa9865e5bc0b6125f4 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 29 Nov 2016 14:36:35 -0700 Subject: [PATCH 36/61] Move hash functions for tile_id into their own header, so tile_id.hpp can be included in obj-c++ without needing to include boost --- src/mbgl/algorithm/generate_clip_ids.hpp | 1 + src/mbgl/style/source_impl.hpp | 1 + src/mbgl/tile/tile_id.hpp | 34 ---------------------- src/mbgl/tile/tile_id_hash.hpp | 37 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 src/mbgl/tile/tile_id_hash.hpp diff --git a/src/mbgl/algorithm/generate_clip_ids.hpp b/src/mbgl/algorithm/generate_clip_ids.hpp index d917b398af5..fb12fdcd2bb 100644 --- a/src/mbgl/algorithm/generate_clip_ids.hpp +++ b/src/mbgl/algorithm/generate_clip_ids.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index e6340ae1cb0..4583b67d3cb 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/src/mbgl/tile/tile_id.hpp b/src/mbgl/tile/tile_id.hpp index c95810342ba..8245960cd22 100644 --- a/src/mbgl/tile/tile_id.hpp +++ b/src/mbgl/tile/tile_id.hpp @@ -8,7 +8,6 @@ #include #include #include -#include namespace mbgl { @@ -240,36 +239,3 @@ inline float UnwrappedTileID::pixelsToTileUnits(const float pixelValue, const fl } } // namespace mbgl - -namespace std { - -template <> struct hash { - size_t operator()(const mbgl::CanonicalTileID &id) const { - std::size_t seed = 0; - boost::hash_combine(seed, id.x); - boost::hash_combine(seed, id.y); - boost::hash_combine(seed, id.z); - return seed; - } -}; - -template <> struct hash { - size_t operator()(const mbgl::UnwrappedTileID &id) const { - std::size_t seed = 0; - boost::hash_combine(seed, std::hash{}(id.canonical)); - boost::hash_combine(seed, id.wrap); - return seed; - } -}; - -template <> struct hash { - size_t operator()(const mbgl::OverscaledTileID &id) const { - std::size_t seed = 0; - boost::hash_combine(seed, std::hash{}(id.canonical)); - boost::hash_combine(seed, id.overscaledZ); - return seed; - } -}; - -} // namespace std - diff --git a/src/mbgl/tile/tile_id_hash.hpp b/src/mbgl/tile/tile_id_hash.hpp new file mode 100644 index 00000000000..0f52d9816f5 --- /dev/null +++ b/src/mbgl/tile/tile_id_hash.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +namespace std { + +template <> struct hash { + size_t operator()(const mbgl::CanonicalTileID &id) const { + std::size_t seed = 0; + boost::hash_combine(seed, id.x); + boost::hash_combine(seed, id.y); + boost::hash_combine(seed, id.z); + return seed; + } +}; + +template <> struct hash { + size_t operator()(const mbgl::UnwrappedTileID &id) const { + std::size_t seed = 0; + boost::hash_combine(seed, std::hash{}(id.canonical)); + boost::hash_combine(seed, id.wrap); + return seed; + } +}; + +template <> struct hash { + size_t operator()(const mbgl::OverscaledTileID &id) const { + std::size_t seed = 0; + boost::hash_combine(seed, std::hash{}(id.canonical)); + boost::hash_combine(seed, id.overscaledZ); + return seed; + } +}; + +} // namespace std + From 2f68306f3b475140ea146e6a1a8c973355ec512d Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 29 Nov 2016 14:43:04 -0700 Subject: [PATCH 37/61] Enable featuresInCoordinateBounds:zoomLevel: in MGLCustomVectorSourceDataSource --- platform/darwin/src/MGLCustomVectorSource.mm | 9 ++++--- platform/ios/app/MBXViewController.m | 28 +++++--------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 97e849af778..2cbb812e804 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -10,6 +10,7 @@ #include #include #include +#include @interface MGLCustomVectorSource () { std::unique_ptr _pendingSource; @@ -44,10 +45,10 @@ - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY y:y zoomLevel:z]; } else { -// mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(z, x, y); -// mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); -// data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) -// zoomLevel:z]; + mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(z, x, y); + mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); + data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) + zoomLevel:z]; } [self processData:data forTile:z x:x y:y]; diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 58ce0a7d645..790516fec48 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1622,21 +1622,7 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } #pragma mark - MGLCustomVectorSourceDataSource -- (NSArray>*)featuresInTileAtX:(NSUInteger)x y:(NSUInteger)y zoomLevel:(NSUInteger)zoom { - int tilesAtThisZoom = 1 << zoom; - double lngWidth = 360.0 / tilesAtThisZoom; - CLLocationCoordinate2D southwest; - CLLocationCoordinate2D northeast; - southwest.longitude = -180 + (x * lngWidth); - northeast.longitude = southwest.longitude + lngWidth; - - double latHeightMerc = 1.0 / tilesAtThisZoom; - double topLatMerc = y * latHeightMerc; - double bottomLatMerc = topLatMerc + latHeightMerc; - - southwest.latitude = (180 / M_PI) * ((2 * atan(exp(M_PI * (1 - (2 * bottomLatMerc))))) - (M_PI / 2.0)); - northeast.latitude = (180 / M_PI) * ((2 * atan(exp(M_PI * (1 - (2 * topLatMerc))))) - (M_PI / 2.0)); - +- (NSArray>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoom { double gridSpacing; if(zoom >= 13) { gridSpacing = 0.01; @@ -1663,17 +1649,17 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView NSMutableArray > * features = [NSMutableArray array]; CLLocationCoordinate2D coords[2]; - for (double y = ceil(northeast.latitude / gridSpacing) * gridSpacing; y >= floor(southwest.latitude / gridSpacing) * gridSpacing; y -= gridSpacing) { - coords[0] = CLLocationCoordinate2DMake(y, southwest.longitude); - coords[1] = CLLocationCoordinate2DMake(y, northeast.longitude); + for (double y = ceil(bounds.ne.latitude / gridSpacing) * gridSpacing; y >= floor(bounds.sw.latitude / gridSpacing) * gridSpacing; y -= gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(y, bounds.sw.longitude); + coords[1] = CLLocationCoordinate2DMake(y, bounds.ne.longitude); MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; feature.attributes = @{@"value": @(y)}; [features addObject:feature]; } - for (double x = floor(southwest.longitude / gridSpacing) * gridSpacing; x <= ceil(northeast.longitude / gridSpacing) * gridSpacing; x += gridSpacing) { - coords[0] = CLLocationCoordinate2DMake(southwest.latitude, x); - coords[1] = CLLocationCoordinate2DMake(northeast.latitude, x); + for (double x = floor(bounds.sw.longitude / gridSpacing) * gridSpacing; x <= ceil(bounds.ne.longitude / gridSpacing) * gridSpacing; x += gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(bounds.sw.latitude, x); + coords[1] = CLLocationCoordinate2DMake(bounds.ne.latitude, x); MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; feature.attributes = @{@"value": @(x)}; [features addObject:feature]; From c9fba943cde7d2a23ed694a853e06b63806632c6 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 8 Dec 2016 10:39:55 -0700 Subject: [PATCH 38/61] Fix error after rebasing to master --- platform/darwin/src/MGLGeoJSONSourceBase.mm | 6 ++++++ platform/darwin/src/MGLGeoJSONSourceBase_Private.h | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm index 4f7271d96e7..8ab84de745a 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase.mm +++ b/platform/darwin/src/MGLGeoJSONSourceBase.mm @@ -9,6 +9,12 @@ const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer = @"MGLGeoJSONSourceOptionBuffer"; const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"MGLGeoJSONSourceOptionSimplificationTolerance"; +@interface MGLGeoJSONSourceBase () + +@property (nonatomic, readwrite) NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *options; + +@end + @implementation MGLGeoJSONSourceBase diff --git a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h index 45a6e531415..6bc4134c31a 100644 --- a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h +++ b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h @@ -4,7 +4,6 @@ @interface MGLGeoJSONSourceBase (Private) -@property (nonatomic, readwrite) NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *options; - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options; From 6bde7e855e7b0cc0cd4d2dd3ab709ff36dcbe41a Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 8 Dec 2016 13:30:03 -0700 Subject: [PATCH 39/61] add removeFromMapView function --- platform/darwin/src/MGLCustomVectorSource.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLCustomVectorSource.mm index 2cbb812e804..14870efafcb 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLCustomVectorSource.mm @@ -79,9 +79,23 @@ - (void)setDataSource:(id)dataSource - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingSource == nullptr) { + [NSException raise:@"MGLRedundantSourceException" + format:@"This instance %@ was already added to %@. Adding the same source instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + mapView.mbglMap->addSource(std::move(_pendingSource)); } +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); + + _pendingSource = std::move(reinterpret_cast &>(removedSource)); + self.rawSource = _pendingSource.get(); +} + - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { mbgl::FeatureCollection featureCollection; From b591f5b2764a1eb9358c6d205145cf3b46e00cb4 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 23 Jan 2017 07:23:33 -0700 Subject: [PATCH 40/61] Update based on changes in master --- cmake/core-files.cmake | 1 + platform/darwin/src/MGLAbstractShapeSource.h | 77 ++++++++++++++++++ platform/darwin/src/MGLAbstractShapeSource.mm | 71 ++++++++++++++++ .../src/MGLAbstractShapeSource_Private.h | 18 +++++ ...ectorSource.h => MGLComputedShapeSource.h} | 20 ++--- ...torSource.mm => MGLComputedShapeSource.mm} | 51 +++++------- platform/darwin/src/MGLGeoJSONSourceBase.h | 63 --------------- platform/darwin/src/MGLGeoJSONSourceBase.mm | 80 ------------------- .../darwin/src/MGLGeoJSONSourceBase_Private.h | 12 --- platform/darwin/src/MGLShapeSource.h | 73 +---------------- platform/darwin/src/MGLShapeSource.mm | 62 +------------- platform/darwin/src/MGLShapeSource_Private.h | 3 - platform/ios/app/MBXViewController.m | 8 +- platform/ios/ios.xcodeproj/project.pbxproj | 52 ++++++------ platform/ios/src/Mapbox.h | 4 +- 15 files changed, 236 insertions(+), 359 deletions(-) create mode 100644 platform/darwin/src/MGLAbstractShapeSource.h create mode 100644 platform/darwin/src/MGLAbstractShapeSource.mm create mode 100644 platform/darwin/src/MGLAbstractShapeSource_Private.h rename platform/darwin/src/{MGLCustomVectorSource.h => MGLComputedShapeSource.h} (72%) rename platform/darwin/src/{MGLCustomVectorSource.mm => MGLComputedShapeSource.mm} (79%) delete mode 100644 platform/darwin/src/MGLGeoJSONSourceBase.h delete mode 100644 platform/darwin/src/MGLGeoJSONSourceBase.mm delete mode 100644 platform/darwin/src/MGLGeoJSONSourceBase_Private.h diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 274a9c6743b..4f2375e462a 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -374,6 +374,7 @@ set(MBGL_CORE_FILES src/mbgl/tile/tile_cache.cpp src/mbgl/tile/tile_cache.hpp src/mbgl/tile/tile_id.hpp + src/mbgl/tile/tile_id_hash.hpp src/mbgl/tile/tile_id_io.cpp src/mbgl/tile/tile_loader.hpp src/mbgl/tile/tile_loader_impl.hpp diff --git a/platform/darwin/src/MGLAbstractShapeSource.h b/platform/darwin/src/MGLAbstractShapeSource.h new file mode 100644 index 00000000000..43883eb8b35 --- /dev/null +++ b/platform/darwin/src/MGLAbstractShapeSource.h @@ -0,0 +1,77 @@ +#import "MGLSource.h" + +/** + Options for `MGLShapeSource` objects. + */ +typedef NSString *MGLShapeSourceOption NS_STRING_ENUM; + +/** + An `NSNumber` object containing a Boolean enabling or disabling clustering. + If the `shape` property contains point shapes, setting this option to + `YES` clusters the points by radius into groups. The default value is `NO`. + + This attribute corresponds to the + cluster + source property in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClustered; + +/** + An `NSNumber` object containing an integer; specifies the radius of each + cluster if clustering is enabled. A value of 512 produces a radius equal to + the width of a tile. The default value is 50. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius; + +/** + An `NSNumber` object containing an integer; specifies the maximum zoom level at + which to cluster points if clustering is enabled. Defaults to one zoom level + less than the value of `MGLShapeSourceOptionMaximumZoomLevel` so that, at the + maximum zoom level, the shapes are not clustered. + + This attribute corresponds to the + clusterMaxZoom + source property in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering; + +/** + An `NSNumber` object containing an integer; specifies the maximum zoom level at + which to create vector tiles. A greater value produces greater detail at high + zoom levels. The default value is 18. + + This attribute corresponds to the + maxzoom + source property in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel; + +/** + An `NSNumber` object containing an integer; specifies the size of the tile + buffer on each side. A value of 0 produces no buffer. A value of 512 produces a + buffer as wide as the tile itself. Larger values produce fewer rendering + artifacts near tile edges and slower performance. The default value is 128. + + This attribute corresponds to the + buffer + source property in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionBuffer; + +/** + An `NSNumber` object containing a double; specifies the Douglas-Peucker + simplification tolerance. A greater value produces simpler geometries and + improves performance. The default value is 0.375. + + This attribute corresponds to the + tolerance + source property in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; + + + +@interface MGLAbstractShapeSource : MGLSource + + +@end diff --git a/platform/darwin/src/MGLAbstractShapeSource.mm b/platform/darwin/src/MGLAbstractShapeSource.mm new file mode 100644 index 00000000000..a0b2640df38 --- /dev/null +++ b/platform/darwin/src/MGLAbstractShapeSource.mm @@ -0,0 +1,71 @@ +#import "MGLAbstractShapeSource.h" +#import "MGLAbstractShapeSource_Private.h" + +const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; +const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius = @"MGLShapeSourceOptionClusterRadius"; +const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering = @"MGLShapeSourceOptionMaximumZoomLevelForClustering"; +const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; +const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; +const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLShapeSourceOptionSimplificationTolerance"; + +@interface MGLAbstractShapeSource () + +@end + +@implementation MGLAbstractShapeSource + +@end + +mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { + auto geoJSONOptions = mbgl::style::GeoJSONOptions(); + + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; + } + geoJSONOptions.maxzoom = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionBuffer]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionBuffer must be an NSNumber."]; + } + geoJSONOptions.buffer = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionSimplificationTolerance]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionSimplificationTolerance must be an NSNumber."]; + } + geoJSONOptions.tolerance = value.doubleValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionClusterRadius]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionClusterRadius must be an NSNumber."]; + } + geoJSONOptions.clusterRadius = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevelForClustering]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevelForClustering must be an NSNumber."]; + } + geoJSONOptions.clusterMaxZoom = value.integerValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionClustered]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionClustered must be an NSNumber."]; + } + geoJSONOptions.cluster = value.boolValue; + } + + return geoJSONOptions; +} diff --git a/platform/darwin/src/MGLAbstractShapeSource_Private.h b/platform/darwin/src/MGLAbstractShapeSource_Private.h new file mode 100644 index 00000000000..e10ed4e6462 --- /dev/null +++ b/platform/darwin/src/MGLAbstractShapeSource_Private.h @@ -0,0 +1,18 @@ +#import "MGLAbstractShapeSource.h" + +#import "MGLFoundation.h" +#import "MGLTypes.h" +#import "MGLShape.h" + +#include + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLAbstractShapeSource (Private) + +MGL_EXPORT + +mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options); + +@end +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLCustomVectorSource.h b/platform/darwin/src/MGLComputedShapeSource.h similarity index 72% rename from platform/darwin/src/MGLCustomVectorSource.h rename to platform/darwin/src/MGLComputedShapeSource.h index 2ed262345da..0cef8f1fa69 100644 --- a/platform/darwin/src/MGLCustomVectorSource.h +++ b/platform/darwin/src/MGLComputedShapeSource.h @@ -1,7 +1,9 @@ -#import "MGLSource.h" -#import "MGLGeoJSONSource.h" -#import "MGLGeoJSONSourceBase.h" +#import "MGLAbstractShapeSource.h" + +#import "MGLFoundation.h" #import "MGLGeometry.h" +#import "MGLTypes.h" +#import "MGLShape.h" NS_ASSUME_NONNULL_BEGIN @@ -12,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN data, one based on tile coordinates, and one based on a bounding box. Clases that implement this protocol must implement one, and only one of the methods. */ -@protocol MGLCustomVectorSourceDataSource +@protocol MGLComputedShapeSourceDataSource @optional /** @@ -21,14 +23,14 @@ NS_ASSUME_NONNULL_BEGIN @param y tile Y coordinate @param zoomLevel tile zoom level */ -- (NSArray>*)featuresInTileAtX:(NSUInteger)x y:(NSUInteger)y zoomLevel:(NSUInteger)zoomLevel; +- (NSArray *>*)featuresInTileAtX:(NSUInteger)x y:(NSUInteger)y zoomLevel:(NSUInteger)zoomLevel; /** Fetch features for a tile. This will not be called on the main queue, it will be called on the callers requestQueue. @param bounds The bounds to fetch data for @param zoomLevel tile zoom level */ -- (NSArray>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel; +- (NSArray *>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel; @end @@ -36,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN A source for vector data that is fetched 1 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. */ -@interface MGLCustomVectorSource : MGLGeoJSONSourceBase +@interface MGLComputedShapeSource : MGLAbstractShapeSource /** Returns a custom vector datasource initialized with an identifier, datasource, and a @@ -47,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN @param identifier A string that uniquely identifies the source. @param options An `NSDictionary` of options for this source. */ -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier options:(nullable NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; /** Request that the source reloads a region. @@ -62,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN /** An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. */ -@property (nonatomic, weak, nullable) id dataSource; +@property (nonatomic, weak, nullable) id dataSource; /** A queue that calls to the datasource will be made on. diff --git a/platform/darwin/src/MGLCustomVectorSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm similarity index 79% rename from platform/darwin/src/MGLCustomVectorSource.mm rename to platform/darwin/src/MGLComputedShapeSource.mm index 14870efafcb..b057f249a5a 100644 --- a/platform/darwin/src/MGLCustomVectorSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -1,18 +1,19 @@ -#import "MGLCustomVectorSource.h" +#import "MGLComputedShapeSource.h" #import "MGLMapView_Private.h" #import "MGLSource_Private.h" #import "MGLFeature_Private.h" #import "MGLShape_Private.h" -#import "MGLGeoJSONSourceBase_Private.h" +#import "MGLAbstractShapeSource_Private.h" #import "MGLGeometry_Private.h" +#include #include #include #include #include -@interface MGLCustomVectorSource () { +@interface MGLComputedShapeSource () { std::unique_ptr _pendingSource; } @@ -23,21 +24,20 @@ @interface MGLCustomVectorSource () { @end -@implementation MGLCustomVectorSource +@implementation MGLComputedShapeSource -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options -{ - if (self = [super initWithIdentifier:identifier options:options]) - { +- (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.CustomVectorSource.%@", identifier]; + self.requestQueue.name = [NSString stringWithFormat:@"mgl.MGLComputedShapeSource.%@", identifier]; + auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); auto source = std::make_unique - (self.identifier.UTF8String, self.geoJSONOptions, + (self.identifier.UTF8String, geoJSONOptions, ^void(uint8_t z, uint32_t x, uint32_t y) { [self.requestQueue addOperationWithBlock: ^{ - NSArray> *data; + NSArray *> *data; if(!self.dataSource) { data = nil; } else if(self.dataSourceImplementsFeaturesForTile) { @@ -62,8 +62,7 @@ - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY return self; } -- (void)setDataSource:(id)dataSource -{ +- (void)setDataSource:(id)dataSource { //Check which method the datasource implements, to avoid having to check for each tile self.dataSourceImplementsFeaturesForTile = [dataSource respondsToSelector:@selector(featuresInTileAtX:y:zoomLevel:)]; self.dataSourceImplementsFeaturesForBounds = [dataSource respondsToSelector:@selector(featuresInCoordinateBounds:zoomLevel:)]; @@ -77,32 +76,29 @@ - (void)setDataSource:(id)dataSource _dataSource = dataSource; } -- (void)addToMapView:(MGLMapView *)mapView -{ +- (void)addToMapView:(MGLMapView *)mapView { if (_pendingSource == nullptr) { [NSException raise:@"MGLRedundantSourceException" format:@"This instance %@ was already added to %@. Adding the same source instance " \ "to the style more than once is invalid.", self, mapView.style]; } - + mapView.mbglMap->addSource(std::move(_pendingSource)); } -- (void)removeFromMapView:(MGLMapView *)mapView -{ +- (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); _pendingSource = std::move(reinterpret_cast &>(removedSource)); self.rawSource = _pendingSource.get(); } -- (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y -{ +- (void)processData:(NS_ARRAY_OF(MGLShape *)*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { mbgl::FeatureCollection featureCollection; featureCollection.reserve(features.count); - for (id feature in features) - { - featureCollection.push_back([feature mbglFeature]); + for (MGLShape * feature in features) { + mbgl::Feature geoJsonObject = [feature geoJSONObject].get(); + featureCollection.push_back(geoJsonObject); } const auto geojson = mbgl::GeoJSON{featureCollection}; dispatch_async(dispatch_get_main_queue(), ^{ @@ -110,18 +106,15 @@ - (void)processData:(NS_ARRAY_OF(id )*)features forTile:(uint8_t)z x }); } -- (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel -{ +- (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel { self.rawSource->reloadRegion(MGLLatLngBoundsFromCoordinateBounds(bounds), (uint8_t)zoomLevel); } -- (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y -{ +- (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y { self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); } -- (void)reloadData -{ +- (void)reloadData { self.rawSource->reload(); } diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.h b/platform/darwin/src/MGLGeoJSONSourceBase.h deleted file mode 100644 index e459ff6d20a..00000000000 --- a/platform/darwin/src/MGLGeoJSONSourceBase.h +++ /dev/null @@ -1,63 +0,0 @@ -#import "MGLSource.h" - - -/** - Options for `MGLGeoJSONSource` objects. - */ -typedef NSString *MGLGeoJSONSourceOption NS_STRING_ENUM; - -/** - An `NSNumber` object containing a Boolean enabling or disabling clustering. - If the `features` property contains point features, setting this option to - `YES` clusters the points by radius into groups. The default value is `NO`. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered; - -/** - An `NSNumber` object containing an integer; specifies the radius of each - cluster if clustering is enabled. A value of 512 produces a radius equal to - the width of a tile. The default value is 50. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to cluster points if clustering is enabled. Defaults to one zoom level - less than the value of `MGLGeoJSONSourceOptionMaximumZoomLevel` so that, at the - maximum zoom level, the features are not clustered. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering; - -/** - An `NSNumber` object containing an integer; specifies the minimum zoom level at - which to create vector tiles. The default value is 0. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to create vector tiles. A greater value produces greater detail at high - zoom levels. The default value is 18. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the size of the tile - buffer on each side. A value of 0 produces no buffer. A value of 512 produces a - buffer as wide as the tile itself. Larger values produce fewer rendering - artifacts near tile edges and slower performance. The default value is 128. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer; - -/** - An `NSNumber` object containing a double; specifies the Douglas-Peucker - simplification tolerance. A greater value produces simpler geometries and - improves performance. The default value is 0.375. - */ -extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance; - - -@interface MGLGeoJSONSourceBase : MGLSource - - -@end diff --git a/platform/darwin/src/MGLGeoJSONSourceBase.mm b/platform/darwin/src/MGLGeoJSONSourceBase.mm deleted file mode 100644 index 8ab84de745a..00000000000 --- a/platform/darwin/src/MGLGeoJSONSourceBase.mm +++ /dev/null @@ -1,80 +0,0 @@ -#import "MGLGeoJSONSourceBase.h" -#import "MGLGeoJSONSourceBase_Private.h" - -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered = @"MGLGeoJSONSourceOptionClustered"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius = @"MGLGeoJSONSourceOptionClusterRadius"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering = @"MGLGeoJSONSourceOptionMaximumZoomLevelForClustering"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel = @"MGLGeoJSONSourceOptionMaximumZoomLevel"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel = @"MGLGeoJSONSourceOptionMinimumZoomLevel"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer = @"MGLGeoJSONSourceOptionBuffer"; -const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"MGLGeoJSONSourceOptionSimplificationTolerance"; - -@interface MGLGeoJSONSourceBase () - -@property (nonatomic, readwrite) NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *options; - -@end - -@implementation MGLGeoJSONSourceBase - - -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options -{ - if (self = [super initWithIdentifier:identifier]) { - self.options = options; - } - return self; -} - -- (mbgl::style::GeoJSONOptions)geoJSONOptions -{ - auto mbglOptions = mbgl::style::GeoJSONOptions(); - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { - [self validateValue:value]; - mbglOptions.maxzoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionMinimumZoomLevel]) { - [self validateValue:value]; - mbglOptions.minzoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { - [self validateValue:value]; - mbglOptions.buffer = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { - [self validateValue:value]; - mbglOptions.tolerance = [value doubleValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { - [self validateValue:value]; - mbglOptions.clusterRadius = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { - [self validateValue:value]; - mbglOptions.clusterMaxZoom = [value integerValue]; - } - - if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { - [self validateValue:value]; - mbglOptions.cluster = [value boolValue]; - } - - return mbglOptions; -} - -- (void)validateValue:(id)value -{ - if (! [value isKindOfClass:[NSNumber class]]) - { - [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; - } -} - - -@end diff --git a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h b/platform/darwin/src/MGLGeoJSONSourceBase_Private.h deleted file mode 100644 index 6bc4134c31a..00000000000 --- a/platform/darwin/src/MGLGeoJSONSourceBase_Private.h +++ /dev/null @@ -1,12 +0,0 @@ -#import "MGLGeoJSONSource.h" - -#include - -@interface MGLGeoJSONSourceBase (Private) - - -- (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options; - -- (mbgl::style::GeoJSONOptions)geoJSONOptions; - -@end diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index 34806c548d0..66056f7424d 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -1,4 +1,4 @@ -#import "MGLSource.h" +#import "MGLAbstractShapeSource.h" #import "MGLFoundation.h" #import "MGLTypes.h" @@ -8,75 +8,6 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; -/** - Options for `MGLShapeSource` objects. - */ -typedef NSString *MGLShapeSourceOption NS_STRING_ENUM; - -/** - An `NSNumber` object containing a Boolean enabling or disabling clustering. - If the `shape` property contains point shapes, setting this option to - `YES` clusters the points by radius into groups. The default value is `NO`. - - This attribute corresponds to the - cluster - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClustered; - -/** - An `NSNumber` object containing an integer; specifies the radius of each - cluster if clustering is enabled. A value of 512 produces a radius equal to - the width of a tile. The default value is 50. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to cluster points if clustering is enabled. Defaults to one zoom level - less than the value of `MGLShapeSourceOptionMaximumZoomLevel` so that, at the - maximum zoom level, the shapes are not clustered. - - This attribute corresponds to the - clusterMaxZoom - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to create vector tiles. A greater value produces greater detail at high - zoom levels. The default value is 18. - - This attribute corresponds to the - maxzoom - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the size of the tile - buffer on each side. A value of 0 produces no buffer. A value of 512 produces a - buffer as wide as the tile itself. Larger values produce fewer rendering - artifacts near tile edges and slower performance. The default value is 128. - - This attribute corresponds to the - buffer - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionBuffer; - -/** - An `NSNumber` object containing a double; specifies the Douglas-Peucker - simplification tolerance. A greater value produces simpler geometries and - improves performance. The default value is 0.375. - - This attribute corresponds to the - tolerance - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; - /** `MGLShapeSource` is a map content source that supplies vector shapes to be shown on the map. The shapes may be instances of `MGLShape` or `MGLFeature`, @@ -109,7 +40,7 @@ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionSimplificationT ``` */ MGL_EXPORT -@interface MGLShapeSource : MGLSource +@interface MGLShapeSource : MGLAbstractShapeSource #pragma mark Initializing a Source diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 245b7f2de2b..7a9e8b16466 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -1,4 +1,5 @@ #import "MGLShapeSource_Private.h" +#import "MGLAbstractShapeSource_Private.h" #import "MGLMapView_Private.h" #import "MGLSource_Private.h" @@ -10,12 +11,7 @@ #include #include -const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; -const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius = @"MGLShapeSourceOptionClusterRadius"; -const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering = @"MGLShapeSourceOptionMaximumZoomLevelForClustering"; -const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; -const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; -const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLShapeSourceOptionSimplificationTolerance"; + @interface MGLShapeSource () @@ -125,57 +121,3 @@ - (NSString *)description { } @end - -mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { - auto geoJSONOptions = mbgl::style::GeoJSONOptions(); - - if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; - } - geoJSONOptions.maxzoom = value.integerValue; - } - - if (NSNumber *value = options[MGLShapeSourceOptionBuffer]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionBuffer must be an NSNumber."]; - } - geoJSONOptions.buffer = value.integerValue; - } - - if (NSNumber *value = options[MGLShapeSourceOptionSimplificationTolerance]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionSimplificationTolerance must be an NSNumber."]; - } - geoJSONOptions.tolerance = value.doubleValue; - } - - if (NSNumber *value = options[MGLShapeSourceOptionClusterRadius]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionClusterRadius must be an NSNumber."]; - } - geoJSONOptions.clusterRadius = value.integerValue; - } - - if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevelForClustering]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionMaximumZoomLevelForClustering must be an NSNumber."]; - } - geoJSONOptions.clusterMaxZoom = value.integerValue; - } - - if (NSNumber *value = options[MGLShapeSourceOptionClustered]) { - if (![value isKindOfClass:[NSNumber class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionClustered must be an NSNumber."]; - } - geoJSONOptions.cluster = value.boolValue; - } - - return geoJSONOptions; -} diff --git a/platform/darwin/src/MGLShapeSource_Private.h b/platform/darwin/src/MGLShapeSource_Private.h index c14f4fbb592..8191705b30c 100644 --- a/platform/darwin/src/MGLShapeSource_Private.h +++ b/platform/darwin/src/MGLShapeSource_Private.h @@ -16,7 +16,4 @@ namespace mbgl { @end -MGL_EXPORT -mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options); - NS_ASSUME_NONNULL_END diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index d4422e66ab1..3f7682826ae 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -106,7 +106,7 @@ @implementation MBXSpriteBackedAnnotation @interface MBXViewController () + MGLComputedShapeSourceDataSource> @property (nonatomic) IBOutlet MGLMapView *mapView; @@ -1212,8 +1212,8 @@ - (void)styleRouteLine - (void)addLatLonGrid { - MGLCustomVectorSource *source = [[MGLCustomVectorSource alloc] initWithIdentifier:@"latlon" - options:@{MGLGeoJSONSourceOptionMaximumZoomLevel:@14}]; + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"latlon" + options:@{MGLShapeSourceOptionMaximumZoomLevel:@14}]; source.dataSource = self; [self.mapView.style addSource:source]; MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"latlonlines" @@ -1221,7 +1221,7 @@ - (void)addLatLonGrid [self.mapView.style addLayer:lineLayer]; MGLSymbolStyleLayer *labelLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"latlonlabels" source:source]; - labelLayer.textField = [MGLStyleValue valueWithRawValue:@"{value}"]; + labelLayer.text = [MGLStyleValue valueWithRawValue:@"{value}"]; [self.mapView.style addLayer:labelLayer]; } diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 5f7f7092df3..a31d43dbbca 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -176,18 +176,18 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; - 88DDFB291DCB7A9200B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88DDFB2A1DCB7AFC00B53BDD /* MGLCustomVectorSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88B079A61E363A7200834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88B079A71E363A7300834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB291DCB7A9200B53BDD /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2A1DCB7AFC00B53BDD /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88DDFB2F1DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */; }; + 88DDFB301DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */; }; + 88F0C0851DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */; }; + 88F0C0861DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */; }; DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88DDFB2D1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88DDFB2E1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88DDFB2F1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */; }; - 88DDFB301DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */; }; DA00FC901D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; }; DA00FC911D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; }; - 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; - 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; @@ -629,13 +629,13 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; - 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSourceBase.h; sourceTree = ""; }; - 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLGeoJSONSourceBase.mm; sourceTree = ""; }; + 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; + 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; tabWidth = 4; }; + 88DDFB311DCBC36E00B53BDD /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; + 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; + 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; tabWidth = 4; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; - 88DDFB311DCBC36E00B53BDD /* MGLGeoJSONSourceBase_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSourceBase_Private.h; sourceTree = ""; }; - 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCustomVectorSource.h; sourceTree = ""; }; - 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLCustomVectorSource.mm; sourceTree = ""; tabWidth = 4; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -892,11 +892,11 @@ 350098B91D480108004B2AF0 /* MGLVectorSource.h */, DAF0D8121DFE0EC500B28378 /* MGLVectorSource_Private.h */, 350098BA1D480108004B2AF0 /* MGLVectorSource.mm */, - 88F0C0811DC8FD8C002DB7AE /* MGLCustomVectorSource.h */, - 88F0C0821DC8FD8C002DB7AE /* MGLCustomVectorSource.mm */, - 88DDFB2B1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h */, - 88DDFB311DCBC36E00B53BDD /* MGLGeoJSONSourceBase_Private.h */, - 88DDFB2C1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm */, + 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */, + 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */, + 88DDFB311DCBC36E00B53BDD /* MGLAbstractShapeSource_Private.h */, + 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */, + 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */, ); name = Sources; sourceTree = ""; @@ -1502,7 +1502,6 @@ 353933F51D3FB785003F57D7 /* MGLBackgroundStyleLayer.h in Headers */, DA88485A1CBAFB9800AB86E3 /* MGLUserLocation_Private.h in Headers */, DA27C24F1CBB4C11000B0ECD /* MGLAccountManager_Private.h in Headers */, - 88DDFB2D1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */, DA8847FC1CBAFA5100AB86E3 /* MGLStyle.h in Headers */, DAF0D8131DFE0EC500B28378 /* MGLVectorSource_Private.h in Headers */, 354B83961D2E873E005D9406 /* MGLUserLocationAnnotationView.h in Headers */, @@ -1522,6 +1521,7 @@ DD0902AB1DB192A800C5BDCE /* MGLNetworkConfiguration.h in Headers */, DA8848571CBAFB9800AB86E3 /* MGLMapboxEvents.h in Headers */, DA8848311CBAFA6200AB86E3 /* NSString+MGLAdditions.h in Headers */, + 88B079A61E363A7200834FAB /* MGLAbstractShapeSource.h in Headers */, 353933F81D3FB79F003F57D7 /* MGLLineStyleLayer.h in Headers */, DAAF722D1DA903C700312FA4 /* MGLStyleValue_Private.h in Headers */, DA8847F41CBAFA5100AB86E3 /* MGLOfflinePack.h in Headers */, @@ -1570,7 +1570,7 @@ DA8848871CBB033F00AB86E3 /* Fabric.h in Headers */, 35305D4A1D22AA6A0007D005 /* NSData+MGLAdditions.h in Headers */, 359F57461D2FDDA6005217F1 /* MGLUserLocationAnnotationView_Private.h in Headers */, - 88DDFB2A1DCB7AFC00B53BDD /* MGLCustomVectorSource.h in Headers */, + 88DDFB2A1DCB7AFC00B53BDD /* MGLComputedShapeSource.h in Headers */, 404C26E21D89B877000AA13D /* MGLTileSource.h in Headers */, DA8848841CBB033F00AB86E3 /* FABAttributes.h in Headers */, DA8847FD1CBAFA5100AB86E3 /* MGLTilePyramidOfflineRegion.h in Headers */, @@ -1593,7 +1593,7 @@ DA35A2CA1CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */, 350098BC1D480108004B2AF0 /* MGLVectorSource.h in Headers */, 353933FC1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */, - 88DDFB291DCB7A9200B53BDD /* MGLCustomVectorSource.h in Headers */, + 88DDFB291DCB7A9200B53BDD /* MGLComputedShapeSource.h in Headers */, 3566C76D1D4A8DFA008152BC /* MGLRasterSource.h in Headers */, DAED38641D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */, DABFB85E1CBE99E500D62B32 /* MGLAnnotation.h in Headers */, @@ -1605,7 +1605,6 @@ 404C26E31D89B877000AA13D /* MGLTileSource.h in Headers */, DABFB8611CBE99E500D62B32 /* MGLMultiPoint.h in Headers */, 3510FFF11D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, - 88DDFB2E1DCBC21700B53BDD /* MGLGeoJSONSourceBase.h in Headers */, 35E0CFE71D3E501500188327 /* MGLStyle_Private.h in Headers */, DABFB86D1CBE9A0F00D62B32 /* MGLAnnotationImage.h in Headers */, DABFB8721CBE9A0F00D62B32 /* MGLUserLocation.h in Headers */, @@ -1641,6 +1640,7 @@ 40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */, DABFB8631CBE99E500D62B32 /* MGLOfflineRegion.h in Headers */, DA35A2B21CCA141D00E826B2 /* MGLCompassDirectionFormatter.h in Headers */, + 88B079A71E363A7300834FAB /* MGLAbstractShapeSource.h in Headers */, DAF0D8141DFE0EC500B28378 /* MGLVectorSource_Private.h in Headers */, DABFB8731CBE9A9900D62B32 /* Mapbox.h in Headers */, 357FE2DE1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */, @@ -2022,7 +2022,7 @@ 30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, DA8848541CBAFB9800AB86E3 /* MGLCompactCalloutView.m in Sources */, - 88F0C0851DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */, + 88F0C0851DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */, DA8848251CBAFA6200AB86E3 /* MGLPointAnnotation.mm in Sources */, 35136D3C1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, @@ -2053,7 +2053,7 @@ DA8848321CBAFA6200AB86E3 /* NSString+MGLAdditions.m in Sources */, 408AA8581DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, DA35A2A11CC9E95F00E826B2 /* MGLCoordinateFormatter.m in Sources */, - 88DDFB2F1DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */, + 88DDFB2F1DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */, 35305D481D22AA680007D005 /* NSData+MGLAdditions.mm in Sources */, DA8848291CBAFA6200AB86E3 /* MGLStyle.mm in Sources */, 357FE2DF1E02D2B20068B753 /* NSCoder+MGLAdditions.mm in Sources */, @@ -2099,7 +2099,7 @@ 30E5781A1DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */, 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */, DAA4E4291CBB730400178DFB /* NSBundle+MGLAdditions.m in Sources */, - 88F0C0861DC8FD8C002DB7AE /* MGLCustomVectorSource.mm in Sources */, + 88F0C0861DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */, DAA4E42E1CBB730400178DFB /* MGLAPIClient.m in Sources */, 35136D3D1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, @@ -2130,7 +2130,7 @@ DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */, 408AA8591DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, DAA4E4281CBB730400178DFB /* MGLTypes.m in Sources */, - 88DDFB301DCBC21700B53BDD /* MGLGeoJSONSourceBase.mm in Sources */, + 88DDFB301DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */, DA35A2A21CC9E95F00E826B2 /* MGLCoordinateFormatter.m in Sources */, 35305D491D22AA680007D005 /* NSData+MGLAdditions.mm in Sources */, 357FE2E01E02D2B20068B753 /* NSCoder+MGLAdditions.mm in Sources */, diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index 000fdb586d5..09ed1007209 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -48,8 +48,8 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[]; #import "MGLTileSource.h" #import "MGLVectorSource.h" #import "MGLShapeSource.h" -#import "MGLGeoJSONSourceBase.h" -#import "MGLCustomVectorSource.h" +#import "MGLAbstractShapeSource.h" +#import "MGLComputedShapeSource.h" #import "MGLRasterSource.h" #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" From fb3762482f73a3f497d67683b1943d70b6c3d5da Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 23 Jan 2017 09:00:39 -0700 Subject: [PATCH 41/61] re-add min zoom option that was removed in merge --- platform/darwin/src/MGLAbstractShapeSource.h | 10 ++++++++++ platform/darwin/src/MGLAbstractShapeSource.mm | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLAbstractShapeSource.h b/platform/darwin/src/MGLAbstractShapeSource.h index 43883eb8b35..0c920f2e0f8 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.h +++ b/platform/darwin/src/MGLAbstractShapeSource.h @@ -35,6 +35,16 @@ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius; */ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering; +/** + An `NSNumber` object containing an integer; specifies the minimum zoom level at + which to create vector tiles. The default value is 0. + + This attribute corresponds to the + minzoom + source property in the Mapbox Style Specification. + */ +extern const MGLShapeSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel; + /** An `NSNumber` object containing an integer; specifies the maximum zoom level at which to create vector tiles. A greater value produces greater detail at high diff --git a/platform/darwin/src/MGLAbstractShapeSource.mm b/platform/darwin/src/MGLAbstractShapeSource.mm index a0b2640df38..dfecb3472d2 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.mm +++ b/platform/darwin/src/MGLAbstractShapeSource.mm @@ -4,6 +4,7 @@ const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius = @"MGLShapeSourceOptionClusterRadius"; const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering = @"MGLShapeSourceOptionMaximumZoomLevelForClustering"; +const MGLShapeSourceOption MGLShapeSourceOptionMinimumZoomLevel = @"MGLShapeSourceOptionMinimumZoomLevel"; const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLShapeSourceOptionSimplificationTolerance"; @@ -18,7 +19,15 @@ @implementation MGLAbstractShapeSource mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { auto geoJSONOptions = mbgl::style::GeoJSONOptions(); - + + if (NSNumber *value = options[MGLShapeSourceOptionMinimumZoomLevel]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; + } + geoJSONOptions.minzoom = value.integerValue; + } + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { if (![value isKindOfClass:[NSNumber class]]) { [NSException raise:NSInvalidArgumentException From 517f447834ec8879c997d842b634fa3db3a22b1e Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 23 Jan 2017 17:49:42 -0700 Subject: [PATCH 42/61] Fix typoed option name --- platform/darwin/src/MGLAbstractShapeSource.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLAbstractShapeSource.h b/platform/darwin/src/MGLAbstractShapeSource.h index 0c920f2e0f8..87dc07f8742 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.h +++ b/platform/darwin/src/MGLAbstractShapeSource.h @@ -43,7 +43,7 @@ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLeve minzoom source property in the Mapbox Style Specification. */ -extern const MGLShapeSourceOption MGLGeoJSONSourceOptionMinimumZoomLevel; +extern const MGLShapeSourceOption MGLShapeSourceOptionMinimumZoomLevel; /** An `NSNumber` object containing an integer; specifies the maximum zoom level at From daa5209e1584c558753a8ec2cc5b75a1f2d8ff62 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 06:57:21 -0700 Subject: [PATCH 43/61] Fix build for macos --- platform/macos/macos.xcodeproj/project.pbxproj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index fc9e0c74e1b..4aa0e2600a7 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -63,6 +63,9 @@ 556660D61E1D07E400E2C41B /* MGLVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 556660D51E1D07E400E2C41B /* MGLVersionNumber.m */; }; 558F18221D0B13B100123F46 /* libmbgl-loop.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 558F18211D0B13B000123F46 /* libmbgl-loop.a */; }; 55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; + 88B079AC1E37941300834FAB /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */; }; + 88B079AD1E37942700834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88B079AE1E37943900834FAB /* MGLAbstractShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; @@ -316,6 +319,9 @@ 558F18211D0B13B000123F46 /* libmbgl-loop.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-loop.a"; path = "../../build/osx/Debug/libmbgl-loop.a"; sourceTree = ""; }; 55D9B4B01D005D3900C1CCE2 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = ""; }; + 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; + 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; + 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; }; DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -573,6 +579,9 @@ DA7DC9821DED647F0027472F /* MGLRasterSource_Private.h */, 352742841D4C244700A1ECE6 /* MGLRasterSource.mm */, 352742871D4C245800A1ECE6 /* MGLShapeSource.h */, + 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */, + 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */, + 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */, DA87A99B1DC9D8DD00810D09 /* MGLShapeSource_Private.h */, 352742881D4C245800A1ECE6 /* MGLShapeSource.mm */, 3527427F1D4C243B00A1ECE6 /* MGLSource.h */, @@ -993,6 +1002,7 @@ 35C5D8471D6DD66D00E95907 /* NSComparisonPredicate+MGLAdditions.h in Headers */, DAE6C3A31CC31E9400DB3429 /* MGLAnnotationImage.h in Headers */, DAE6C3A41CC31E9400DB3429 /* MGLMapView.h in Headers */, + 88B079AE1E37943900834FAB /* MGLAbstractShapeSource_Private.h in Headers */, 355BA4ED1D41633E00CCC6D5 /* NSColor+MGLAdditions.h in Headers */, DAE6C3611CC31E0400DB3429 /* MGLOfflineStorage.h in Headers */, 352742781D4C220900A1ECE6 /* MGLStyleValue.h in Headers */, @@ -1059,6 +1069,7 @@ DAE6C3891CC31E2A00DB3429 /* MGLMultiPoint_Private.h in Headers */, DAE6C3A51CC31E9400DB3429 /* MGLMapView+IBAdditions.h in Headers */, DA35A2AD1CCA091800E826B2 /* MGLCompassDirectionFormatter.h in Headers */, + 88B079AD1E37942700834FAB /* MGLAbstractShapeSource.h in Headers */, 352742851D4C244700A1ECE6 /* MGLRasterSource.h in Headers */, 408AA85B1DAEECFE00022900 /* MGLShape_Private.h in Headers */, DACC22181CF3D4F700D220D9 /* MGLFeature_Private.h in Headers */, @@ -1306,6 +1317,7 @@ DAE6C3B51CC31EF300DB3429 /* MGLCompassCell.m in Sources */, DA8F25901D51CA600010E6B5 /* MGLRasterStyleLayer.mm in Sources */, DAD165751CF4CD7A001FF4B9 /* MGLShapeCollection.mm in Sources */, + 88B079AC1E37941300834FAB /* MGLAbstractShapeSource.mm in Sources */, 35C5D8481D6DD66D00E95907 /* NSComparisonPredicate+MGLAdditions.mm in Sources */, DA35A2AE1CCA091800E826B2 /* MGLCompassDirectionFormatter.m in Sources */, DA8F258C1D51CA540010E6B5 /* MGLLineStyleLayer.mm in Sources */, From fc0b94ba89c65ef5b3b8905f89f99c166e8d10f6 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 07:11:14 -0700 Subject: [PATCH 44/61] Add ComputedShapeSource to macos target --- platform/darwin/src/MGLComputedShapeSource.mm | 1 - platform/macos/macos.xcodeproj/project.pbxproj | 8 ++++++++ platform/macos/src/Mapbox.h | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index b057f249a5a..aa202f2a05e 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -2,7 +2,6 @@ #import "MGLMapView_Private.h" #import "MGLSource_Private.h" -#import "MGLFeature_Private.h" #import "MGLShape_Private.h" #import "MGLAbstractShapeSource_Private.h" #import "MGLGeometry_Private.h" diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 4aa0e2600a7..6b8a038a68c 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -63,9 +63,11 @@ 556660D61E1D07E400E2C41B /* MGLVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 556660D51E1D07E400E2C41B /* MGLVersionNumber.m */; }; 558F18221D0B13B100123F46 /* libmbgl-loop.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 558F18211D0B13B000123F46 /* libmbgl-loop.a */; }; 55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; + 8877024C1E37977D0097E255 /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */; }; 88B079AC1E37941300834FAB /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */; }; 88B079AD1E37942700834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88B079AE1E37943900834FAB /* MGLAbstractShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */; }; + 88B079B21E37957000834FAB /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; @@ -322,6 +324,8 @@ 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; }; + 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; + 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; }; DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -575,6 +579,8 @@ 3527427E1D4C242B00A1ECE6 /* Sources */ = { isa = PBXGroup; children = ( + 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */, + 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */, 352742831D4C244700A1ECE6 /* MGLRasterSource.h */, DA7DC9821DED647F0027472F /* MGLRasterSource_Private.h */, 352742841D4C244700A1ECE6 /* MGLRasterSource.mm */, @@ -1051,6 +1057,7 @@ DA35A2CF1CCAAED300E826B2 /* NSValue+MGLAdditions.h in Headers */, DAE6C3A61CC31E9400DB3429 /* MGLMapViewDelegate.h in Headers */, DAE6C38B1CC31E2A00DB3429 /* MGLOfflinePack_Private.h in Headers */, + 88B079B21E37957000834FAB /* MGLComputedShapeSource.h in Headers */, DACC22141CF3D3E200D220D9 /* MGLFeature.h in Headers */, 3538AA231D542685008EC33D /* MGLStyleLayer.h in Headers */, DAE6C35C1CC31E0400DB3429 /* MGLGeometry.h in Headers */, @@ -1321,6 +1328,7 @@ 35C5D8481D6DD66D00E95907 /* NSComparisonPredicate+MGLAdditions.mm in Sources */, DA35A2AE1CCA091800E826B2 /* MGLCompassDirectionFormatter.m in Sources */, DA8F258C1D51CA540010E6B5 /* MGLLineStyleLayer.mm in Sources */, + 8877024C1E37977D0097E255 /* MGLComputedShapeSource.mm in Sources */, 408AA8691DAEEE5500022900 /* MGLPolyline+MGLAdditions.m in Sources */, DA8F25941D51CA750010E6B5 /* MGLSymbolStyleLayer.mm in Sources */, 3529039C1D6C63B80002C7DF /* NSPredicate+MGLAdditions.mm in Sources */, diff --git a/platform/macos/src/Mapbox.h b/platform/macos/src/Mapbox.h index 1f30497184a..80fa1cfe31d 100644 --- a/platform/macos/src/Mapbox.h +++ b/platform/macos/src/Mapbox.h @@ -46,6 +46,8 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[]; #import "MGLTileSource.h" #import "MGLVectorSource.h" #import "MGLShapeSource.h" +#import "MGLAbstractShapeSource.h" +#import "MGLComputedShapeSource.h" #import "MGLRasterSource.h" #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" From fcaa6e807a9c2ed6b8951a213ca0919cae23f435 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 08:55:51 -0700 Subject: [PATCH 45/61] Export classes, and add docs for MGLAbstractShapeSource --- platform/darwin/src/MGLAbstractShapeSource.h | 12 +++++++++++- platform/darwin/src/MGLComputedShapeSource.h | 1 + platform/ios/app/MBXViewController.m | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MGLAbstractShapeSource.h b/platform/darwin/src/MGLAbstractShapeSource.h index 87dc07f8742..10214f8025b 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.h +++ b/platform/darwin/src/MGLAbstractShapeSource.h @@ -79,8 +79,18 @@ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionBuffer; */ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; +/** + `MGLAbstractShapeSource` is an abstract base class for map content sources that + supply vector shapes to be shown on the map. A shape source is added to an + `MGLStyle` object along with an `MGLVectorStyleLayer` object. The vector style + layer defines the appearance of any content supplied by the shape source. - + + Do not create instances of this class directly, and do not create your own + subclasses of this class. Instead, create instances of `MGLShapeSource` or + `MGLComputedShapeSource`. + */ +MGL_EXPORT @interface MGLAbstractShapeSource : MGLSource diff --git a/platform/darwin/src/MGLComputedShapeSource.h b/platform/darwin/src/MGLComputedShapeSource.h index 0cef8f1fa69..a4458441541 100644 --- a/platform/darwin/src/MGLComputedShapeSource.h +++ b/platform/darwin/src/MGLComputedShapeSource.h @@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN A source for vector data that is fetched 1 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. */ +MGL_EXPORT @interface MGLComputedShapeSource : MGLAbstractShapeSource /** diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 3f7682826ae..9b0d72f177d 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1698,7 +1698,7 @@ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView } } -#pragma mark - MGLCustomVectorSourceDataSource +#pragma mark - MGLComputedShapeSourceDataSource - (NSArray>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoom { double gridSpacing; if(zoom >= 13) { From 1597509a0fdc17e734d5f5335daa1d05c703c40a Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 08:56:45 -0700 Subject: [PATCH 46/61] Add Graticule layer to mac app to test MGLComputedShapeSource --- platform/macos/app/Base.lproj/MainMenu.xib | 6 ++ platform/macos/app/MapDocument.m | 93 +++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 9faf1ba04b7..bc2ef06ef61 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -543,6 +543,12 @@ + + + + + + diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 40fd9e4600e..dd1e4c21626 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -50,7 +50,7 @@ return flattenedShapes; } -@interface MapDocument () +@interface MapDocument () @property (weak) IBOutlet NSArrayController *styleLayersArrayController; @property (weak) IBOutlet NSTableView *styleLayersTableView; @@ -639,6 +639,47 @@ - (IBAction)removeCustomStyleLayer:(id)sender { [self.mapView.style removeLayer:layer]; } +- (IBAction)insertGraticuleLayer:(id)sender { + [self.undoManager registerUndoWithTarget:self handler:^(id _Nonnull target) { + [self removeGraticuleLayer:sender]; + }]; + + if (!self.undoManager.isUndoing) { + [self.undoManager setActionName:@"Add Graticule Layer"]; + } + + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"graticule" + options:@{MGLShapeSourceOptionMaximumZoomLevel:@14}]; + source.dataSource = self; + [self.mapView.style addSource:source]; + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"graticule.lines" + source:source]; + [self.mapView.style addLayer:lineLayer]; + MGLSymbolStyleLayer *labelLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"graticule.labels" + source:source]; + labelLayer.text = [MGLStyleValue valueWithRawValue:@"{value}"]; + [self.mapView.style addLayer:labelLayer]; +} + +- (IBAction)removeGraticuleLayer:(id)sender { + [self.undoManager registerUndoWithTarget:self handler:^(id _Nonnull target) { + [self insertGraticuleLayer:sender]; + }]; + + if (!self.undoManager.isUndoing) { + [self.undoManager setActionName:@"Delete Graticule Layer"]; + } + + MGLStyleLayer *layer = [self.mapView.style layerWithIdentifier:@"graticule.lines"]; + [self.mapView.style removeLayer:layer]; + + layer = [self.mapView.style layerWithIdentifier:@"graticule.labels"]; + [self.mapView.style removeLayer:layer]; + + MGLSource *source = [self.mapView.style sourceWithIdentifier:@"graticule"]; + [self.mapView.style removeSource:source]; +} + #pragma mark Offline packs - (IBAction)addOfflinePack:(id)sender { @@ -926,6 +967,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { if (menuItem.action == @selector(insertCustomStyleLayer:)) { return ![self.mapView.style layerWithIdentifier:@"mbx-custom"]; } + if (menuItem.action == @selector(insertGraticuleLayer:)) { + return ![self.mapView.style sourceWithIdentifier:@"graticule"]; + } if (menuItem.action == @selector(showAllAnnotations:) || menuItem.action == @selector(removeAllAnnotations:)) { return self.mapView.annotations.count > 0; } @@ -1095,6 +1139,53 @@ - (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)ann return 0.8; } +#pragma mark - MGLComputedShapeSourceDataSource +- (NSArray>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoom { + double gridSpacing; + if(zoom >= 13) { + gridSpacing = 0.01; + } else if(zoom >= 11) { + gridSpacing = 0.05; + } else if(zoom == 10) { + gridSpacing = .1; + } else if(zoom == 9) { + gridSpacing = 0.25; + } else if(zoom == 8) { + gridSpacing = 0.5; + } else if (zoom >= 6) { + gridSpacing = 1; + } else if(zoom == 5) { + gridSpacing = 2; + } else if(zoom >= 4) { + gridSpacing = 5; + } else if(zoom == 2) { + gridSpacing = 10; + } else { + gridSpacing = 20; + } + + NSMutableArray > * features = [NSMutableArray array]; + CLLocationCoordinate2D coords[2]; + + for (double y = ceil(bounds.ne.latitude / gridSpacing) * gridSpacing; y >= floor(bounds.sw.latitude / gridSpacing) * gridSpacing; y -= gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(y, bounds.sw.longitude); + coords[1] = CLLocationCoordinate2DMake(y, bounds.ne.longitude); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(y)}; + [features addObject:feature]; + } + + for (double x = floor(bounds.sw.longitude / gridSpacing) * gridSpacing; x <= ceil(bounds.ne.longitude / gridSpacing) * gridSpacing; x += gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(bounds.sw.latitude, x); + coords[1] = CLLocationCoordinate2DMake(bounds.ne.latitude, x); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(x)}; + [features addObject:feature]; + } + + return features; +} + @end @interface ValidatedToolbarItem : NSToolbarItem From 206783bf8e200a2245932626ba777a54d43639d9 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 09:21:09 -0700 Subject: [PATCH 47/61] Documentation fixes --- platform/darwin/docs/theme/assets/css/jazzy.css.scss | 1 + platform/darwin/src/MGLComputedShapeSource.h | 4 ++-- platform/darwin/src/MGLComputedShapeSource.mm | 4 ++-- platform/ios/jazzy.yml | 2 ++ platform/macos/jazzy.yml | 2 ++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/platform/darwin/docs/theme/assets/css/jazzy.css.scss b/platform/darwin/docs/theme/assets/css/jazzy.css.scss index 6b4dffc8791..f081b7f8b14 100644 --- a/platform/darwin/docs/theme/assets/css/jazzy.css.scss +++ b/platform/darwin/docs/theme/assets/css/jazzy.css.scss @@ -385,6 +385,7 @@ pre code { .nav-group-task[data-name="MGLSource"], .nav-group-task[data-name="MGLStyleLayer"], .nav-group-task[data-name="MGLTileSource"], +.nav-group-task[data-name="MGLAbstractShapeSource"], .nav-group-task[data-name="MGLVectorStyleLayer"] { .nav-group-task-link::after { @extend %nav-group-task-gloss; diff --git a/platform/darwin/src/MGLComputedShapeSource.h b/platform/darwin/src/MGLComputedShapeSource.h index a4458441541..6b3d7a9cc9b 100644 --- a/platform/darwin/src/MGLComputedShapeSource.h +++ b/platform/darwin/src/MGLComputedShapeSource.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; /** - Data source for `MGLCustomVectorSource`. This protocol defines two optionak methods for fetching + Data source for `MGLComputedShapeSource`. This protocol defines two optionak methods for fetching data, one based on tile coordinates, and one based on a bounding box. Clases that implement this protocol must implement one, and only one of the methods. */ @@ -63,7 +63,7 @@ MGL_EXPORT - (void)reloadData; /** - An object that implements the `MGLCustomVectorSourceDataSource` protocol that will be queried for tile data. + An object that implements the `MGLComputedShapeSource` protocol that will be queried for tile data. */ @property (nonatomic, weak, nullable) id dataSource; diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index aa202f2a05e..50658501fc0 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -67,9 +67,9 @@ - (void)setDataSource:(id)dataSource { self.dataSourceImplementsFeaturesForBounds = [dataSource respondsToSelector:@selector(featuresInCoordinateBounds:zoomLevel:)]; if(!self.dataSourceImplementsFeaturesForBounds && !self.dataSourceImplementsFeaturesForTile) { - [NSException raise:@"Invalid Datasource" format:@"Datasource does not implement any MGLCustomVectorSourceDataSource methods"]; + [NSException raise:@"Invalid Datasource" format:@"Datasource does not implement any MGLComputedShapeSourceDataSource methods"]; } else if(self.dataSourceImplementsFeaturesForBounds && self.dataSourceImplementsFeaturesForTile) { - [NSException raise:@"Invalid Datasource" format:@"Datasource implements multiple MGLCustomVectorSourceDataSource methods"]; + [NSException raise:@"Invalid Datasource" format:@"Datasource implements multiple MGLComputedShapeSourceDataSource methods"]; } _dataSource = dataSource; diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml index 71f6be37f24..a038008dd3a 100644 --- a/platform/ios/jazzy.yml +++ b/platform/ios/jazzy.yml @@ -71,7 +71,9 @@ custom_categories: children: - MGLSource - MGLTileSource + - MGLAbstractShapeSource - MGLShapeSource + - MGLComputedShapeSource - MGLRasterSource - MGLVectorSource - name: Style Layers diff --git a/platform/macos/jazzy.yml b/platform/macos/jazzy.yml index 56f72556367..8aa93a41f7f 100644 --- a/platform/macos/jazzy.yml +++ b/platform/macos/jazzy.yml @@ -59,7 +59,9 @@ custom_categories: children: - MGLSource - MGLTileSource + - MGLAbstractShapeSource - MGLShapeSource + - MGLComputedShapeSource - MGLRasterSource - MGLVectorSource - name: Style Layers From bee3b2887197838ade39696b6d7c66e52742a863 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 24 Jan 2017 09:22:28 -0700 Subject: [PATCH 48/61] Add entries to iOS and macOS change logs --- platform/ios/CHANGELOG.md | 1 + platform/macos/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b8a17b169a9..9c3b0653c06 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -21,6 +21,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed incorrect interpolation of style functions in Boolean-typed style attributes. ([#7526](https://github.com/mapbox/mapbox-gl-native/pull/7526)) * Removed support for the `ref` property in layers in style JSON files. ([#7586](https://github.com/mapbox/mapbox-gl-native/pull/7586)) * Fixed an issue that collapsed consecutive newlines within text labels. ([#7446](https://github.com/mapbox/mapbox-gl-native/pull/7446)) +* Added `MGLComputedShapeSource` source class that allows applications to supply vector data on a per-tile basis. ### Other changes diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 24dde427a28..90387cfdea5 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -19,6 +19,7 @@ * Fixed incorrect interpolation of style functions in Boolean-typed style attributes. ([#7526](https://github.com/mapbox/mapbox-gl-native/pull/7526)) * Removed support for the `ref` property in layers in style JSON files. ([#7586](https://github.com/mapbox/mapbox-gl-native/pull/7586)) * Fixed an issue that collapsed consecutive newlines within text labels. ([#7446](https://github.com/mapbox/mapbox-gl-native/pull/7446)) +* Added `MGLComputedShapeSource` source class that allows applications to supply vector data on a per-tile basis. ### Other changes From 16fb0672e64a72b7400c321d55858b73cd5d8c3f Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 26 Jan 2017 11:06:34 -0700 Subject: [PATCH 49/61] Clear cache when reloading source --- src/mbgl/style/sources/custom_vector_source_impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 8b9f0d1c5e0..8abff02964f 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -74,6 +74,9 @@ void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, co } void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { + if(cache.has(OverscaledTileID(z, x, y))) { + cache.clear(); + } for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { @@ -81,7 +84,7 @@ void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { } } } - + void CustomVectorSource::Impl::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { for (const auto& tile : mbgl::util::tileCover(bounds, z)) { updateTile(tile.canonical.z, tile.canonical.x, tile.canonical.z); @@ -89,6 +92,7 @@ void CustomVectorSource::Impl::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z } void CustomVectorSource::Impl::reload() { + cache.clear(); for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); fetchTile(tile->id.canonical.z, tile->id.canonical.x, tile->id.canonical.y); From cbe281523e575cbc5e5eccc9e4c21fc708ae9c88 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 11:52:02 -0700 Subject: [PATCH 50/61] Fix duplicated options after merging --- platform/darwin/src/MGLAbstractShapeSource.h | 2 + platform/darwin/src/MGLAbstractShapeSource.mm | 13 ++-- platform/darwin/src/MGLShapeSource.h | 66 ------------------- platform/darwin/src/MGLShapeSource.mm | 7 +- 4 files changed, 10 insertions(+), 78 deletions(-) diff --git a/platform/darwin/src/MGLAbstractShapeSource.h b/platform/darwin/src/MGLAbstractShapeSource.h index 10214f8025b..83eb051c44d 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.h +++ b/platform/darwin/src/MGLAbstractShapeSource.h @@ -13,6 +13,8 @@ typedef NSString *MGLShapeSourceOption NS_STRING_ENUM; This attribute corresponds to the cluster source property in the Mapbox Style Specification. + + This option only affects point features within a shape source. */ extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClustered; diff --git a/platform/darwin/src/MGLAbstractShapeSource.mm b/platform/darwin/src/MGLAbstractShapeSource.mm index dfecb3472d2..ca839cb3ced 100644 --- a/platform/darwin/src/MGLAbstractShapeSource.mm +++ b/platform/darwin/src/MGLAbstractShapeSource.mm @@ -1,12 +1,12 @@ #import "MGLAbstractShapeSource.h" #import "MGLAbstractShapeSource_Private.h" -const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; +const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius = @"MGLShapeSourceOptionClusterRadius"; +const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; +const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering = @"MGLShapeSourceOptionMaximumZoomLevelForClustering"; const MGLShapeSourceOption MGLShapeSourceOptionMinimumZoomLevel = @"MGLShapeSourceOptionMinimumZoomLevel"; -const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; -const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLShapeSourceOptionSimplificationTolerance"; @interface MGLAbstractShapeSource () @@ -19,15 +19,15 @@ @implementation MGLAbstractShapeSource mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { auto geoJSONOptions = mbgl::style::GeoJSONOptions(); - + if (NSNumber *value = options[MGLShapeSourceOptionMinimumZoomLevel]) { if (![value isKindOfClass:[NSNumber class]]) { [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; + format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; } geoJSONOptions.minzoom = value.integerValue; } - + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { if (![value isKindOfClass:[NSNumber class]]) { [NSException raise:NSInvalidArgumentException @@ -78,3 +78,4 @@ @implementation MGLAbstractShapeSource return geoJSONOptions; } + diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index ed11dc0ce13..750dcf2a7d2 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -13,72 +13,6 @@ NS_ASSUME_NONNULL_BEGIN */ typedef NSString *MGLShapeSourceOption NS_STRING_ENUM; -/** - An `NSNumber` object containing a Boolean enabling or disabling clustering. - If the `shape` property contains point shapes, setting this option to - `YES` clusters the points by radius into groups. The default value is `NO`. - - This attribute corresponds to the - cluster - source property in the Mapbox Style Specification. - - This option only affects point features within a shape source. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClustered; - -/** - An `NSNumber` object containing an integer; specifies the radius of each - cluster if clustering is enabled. A value of 512 produces a radius equal to - the width of a tile. The default value is 50. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to cluster points if clustering is enabled. Defaults to one zoom level - less than the value of `MGLShapeSourceOptionMaximumZoomLevel` so that, at the - maximum zoom level, the shapes are not clustered. - - This attribute corresponds to the - clusterMaxZoom - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to create vector tiles. A greater value produces greater detail at high - zoom levels. The default value is 18. - - This attribute corresponds to the - maxzoom - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the size of the tile - buffer on each side. A value of 0 produces no buffer. A value of 512 produces a - buffer as wide as the tile itself. Larger values produce fewer rendering - artifacts near tile edges and slower performance. The default value is 128. - - This attribute corresponds to the - buffer - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionBuffer; - -/** - An `NSNumber` object containing a double; specifies the Douglas-Peucker - simplification tolerance. A greater value produces simpler geometries and - improves performance. The default value is 0.375. - - This attribute corresponds to the - tolerance - source property in the Mapbox Style Specification. - */ -extern MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; - /** `MGLShapeSource` is a map content source that supplies vector shapes to be shown on the map. The shapes may be instances of `MGLShape` or `MGLFeature`, diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 67b6dc5a471..34d6a58ecd9 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -11,12 +11,7 @@ #include #include -const MGLShapeSourceOption MGLShapeSourceOptionClustered = @"MGLShapeSourceOptionClustered"; -const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius = @"MGLShapeSourceOptionClusterRadius"; -const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevelForClustering = @"MGLShapeSourceOptionMaximumZoomLevelForClustering"; -const MGLShapeSourceOption MGLShapeSourceOptionMaximumZoomLevel = @"MGLShapeSourceOptionMaximumZoomLevel"; -const MGLShapeSourceOption MGLShapeSourceOptionBuffer = @"MGLShapeSourceOptionBuffer"; -const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLShapeSourceOptionSimplificationTolerance"; + @interface MGLShapeSource () From b31841de93613631751ebdbdb21af2cf99c25697 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 11:53:18 -0700 Subject: [PATCH 51/61] Fix merge error --- platform/ios/app/MBXViewController.m | 34 +--------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 6a07115af10..876af697164 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -583,6 +583,7 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath break; case MBXSettingsRuntimeStylingDDSPolygon: [self stylePolygonWithDDS]; + break; case MBXSettingsRuntimeStylingCustomLatLonGrid: [self addLatLonGrid]; break; @@ -1383,39 +1384,6 @@ - (void)styleLabelLanguageForLayersNamed:(NSArray *)layers } } -- (void)styleLabelLanguageForLayersNamed:(NSArray *)layers -{ - _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; - NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; - NSString *language = _usingLocaleBasedCountryLabels ? bestLanguageForUser : @"{name}"; - - for (NSString *layerName in layers) { - MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:layerName]; - - if ([layer isKindOfClass:[MGLSymbolStyleLayer class]]) { - if ([layer.text isKindOfClass:[MGLStyleConstantValue class]]) { - MGLStyleConstantValue *label = (MGLStyleConstantValue *)layer.text; - if ([label.rawValue hasPrefix:@"{name"]) { - layer.text = [MGLStyleValue valueWithRawValue:language]; - } - } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLStyleConstantValue *stop, BOOL *done) { - if ([stop.rawValue hasPrefix:@"{name"]) { - stops[zoomLevel] = [MGLStyleValue valueWithRawValue:language]; - } - }]; - function.stops = stops; - layer.text = function; - } - } else { - NSLog(@"%@ is not a symbol style layer", layerName); - } - } -} - - (NSString *)bestLanguageForUser { NSArray *supportedLanguages = @[ @"en", @"es", @"fr", @"de", @"ru", @"zh" ]; From 13ef94e3e590b7ae0354ae4570e14bee9b5089b5 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 13:39:09 -0700 Subject: [PATCH 52/61] fix `make test` failing --- src/mbgl/algorithm/update_renderables.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mbgl/algorithm/update_renderables.hpp b/src/mbgl/algorithm/update_renderables.hpp index fe2dc2c5708..d6d177f3299 100644 --- a/src/mbgl/algorithm/update_renderables.hpp +++ b/src/mbgl/algorithm/update_renderables.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include From ab55326eae415027ce84a3146f2ee6e4b18fa466 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 13:45:26 -0700 Subject: [PATCH 53/61] Fix failing test --- platform/darwin/test/MGLShapeSourceTests.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/darwin/test/MGLShapeSourceTests.mm b/platform/darwin/test/MGLShapeSourceTests.mm index ba85d760204..588ad3dd991 100644 --- a/platform/darwin/test/MGLShapeSourceTests.mm +++ b/platform/darwin/test/MGLShapeSourceTests.mm @@ -2,6 +2,7 @@ #import #import "MGLFeature_Private.h" +#import "MGLAbstractShapeSource_Private.h" #import "MGLShapeSource_Private.h" #import "MGLSource_Private.h" From 3fcb46f48c933012cf0ad5495a538f26f03863a3 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 14:45:08 -0700 Subject: [PATCH 54/61] Test for MGLComputedShapeSource, but all it tests is the initializer --- .../darwin/test/MGLComputedShapeSourceTests.m | 25 +++++++++++++++++++ platform/ios/ios.xcodeproj/project.pbxproj | 18 +++++++------ .../macos/macos.xcodeproj/project.pbxproj | 16 +++++++----- 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 platform/darwin/test/MGLComputedShapeSourceTests.m diff --git a/platform/darwin/test/MGLComputedShapeSourceTests.m b/platform/darwin/test/MGLComputedShapeSourceTests.m new file mode 100644 index 00000000000..3d1a37a4dc5 --- /dev/null +++ b/platform/darwin/test/MGLComputedShapeSourceTests.m @@ -0,0 +1,25 @@ +#import + +#import + + +@interface MGLComputedShapeSourceTests : XCTestCase +@end + +@implementation MGLComputedShapeSourceTests + +- (void)testInitializer { + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" + options:@{}]; + XCTAssertNotNil(source); + XCTAssertNotNil(source.requestQueue); + XCTAssertNil(source.dataSource); +} + +- (void)testNilOptions { + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" options:nil]; + XCTAssertNotNil(source); +} + + +@end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 56bcda32f2d..71aaadc1763 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -186,16 +186,17 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; - 968F36B51E4D128D003A5522 /* MGLDistanceFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3557F7AE1E1D27D300CCA5E6 /* MGLDistanceFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 96E027231E57C76E004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027251E57C76E004B8E66 /* Localizable.strings */; }; 88B079A61E363A7200834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88B079A71E363A7300834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88DDFB291DCB7A9200B53BDD /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88DDFB2A1DCB7AFC00B53BDD /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88DDFB2F1DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */; }; 88DDFB301DCBC21700B53BDD /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */; }; + 88EF0E6C1E677358008A6617 /* MGLComputedShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EF0E6A1E677345008A6617 /* MGLComputedShapeSourceTests.m */; }; 88F0C0851DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */; }; 88F0C0861DC8FD8C002DB7AE /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */; }; + 968F36B51E4D128D003A5522 /* MGLDistanceFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3557F7AE1E1D27D300CCA5E6 /* MGLDistanceFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 96E027231E57C76E004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027251E57C76E004B8E66 /* Localizable.strings */; }; DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC901D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; }; @@ -648,6 +649,12 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; + 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; + 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; tabWidth = 4; }; + 88DDFB311DCBC36E00B53BDD /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; + 88EF0E6A1E677345008A6617 /* MGLComputedShapeSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLComputedShapeSourceTests.m; path = ../../darwin/test/MGLComputedShapeSourceTests.m; sourceTree = ""; }; + 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; + 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; tabWidth = 4; }; 9660916B1E5BBFD700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 9660916C1E5BBFD900A9A03B /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = ""; }; 9660916D1E5BBFDB00A9A03B /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = ""; }; @@ -655,17 +662,12 @@ 9660916F1E5BBFDE00A9A03B /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/Localizable.strings; sourceTree = ""; }; 968F36B41E4D0FC6003A5522 /* ja */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = ""; }; 96E027241E57C76E004B8E66 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; - 88B079A51E36371A00834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; - 88DDFB2C1DCBC21700B53BDD /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; tabWidth = 4; }; 96E027271E57C77A004B8E66 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = ""; }; 96E027281E57C7DB004B8E66 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 96E027291E57C7DE004B8E66 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; 96E0272A1E57C7DF004B8E66 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = ""; }; - 88DDFB311DCBC36E00B53BDD /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; - 88F0C0811DC8FD8C002DB7AE /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; 96E0272B1E57C7E3004B8E66 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = ""; }; 96E0272C1E57C7E5004B8E66 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; - 88F0C0821DC8FD8C002DB7AE /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; tabWidth = 4; }; 96E0272D1E57C7E6004B8E66 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = ""; }; 96E0272E1E57C7E7004B8E66 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; @@ -1075,6 +1077,7 @@ isa = PBXGroup; children = ( 40CFA6501D787579008103BD /* MGLShapeSourceTests.mm */, + 88EF0E6A1E677345008A6617 /* MGLComputedShapeSourceTests.m */, 4085AF081D933DEA00F11B22 /* MGLTileSetTests.mm */, ); name = Sources; @@ -2082,6 +2085,7 @@ 3598544D1E1D38AA00B29F84 /* MGLDistanceFormatterTests.m in Sources */, DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */, DA35A2C61CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m in Sources */, + 88EF0E6C1E677358008A6617 /* MGLComputedShapeSourceTests.m in Sources */, DAE7DEC21E245455007505A6 /* MGLNSStringAdditionsTests.m in Sources */, 4085AF091D933DEA00F11B22 /* MGLTileSetTests.mm in Sources */, DAEDC4341D603417000224FF /* MGLAttributionInfoTests.m in Sources */, diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 43156987415..92ae407b523 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -70,12 +70,13 @@ 558F18221D0B13B100123F46 /* libmbgl-loop.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 558F18211D0B13B000123F46 /* libmbgl-loop.a */; }; 55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; 55E2AD111E5B0A6900E8C587 /* MGLOfflineStorageTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */; }; - 96E027311E57C9A7004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027331E57C9A7004B8E66 /* Localizable.strings */; }; 8877024C1E37977D0097E255 /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */; }; 88B079AC1E37941300834FAB /* MGLAbstractShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */; }; 88B079AD1E37942700834FAB /* MGLAbstractShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88B079AE1E37943900834FAB /* MGLAbstractShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */; }; 88B079B21E37957000834FAB /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 88EF0E6F1E6777ED008A6617 /* MGLComputedShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EF0E6D1E6777E8008A6617 /* MGLComputedShapeSourceTests.m */; }; + 96E027311E57C9A7004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027331E57C9A7004B8E66 /* Localizable.strings */; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; @@ -335,23 +336,24 @@ 55D9B4B01D005D3900C1CCE2 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLOfflineStorageTests.mm; path = ../../darwin/test/MGLOfflineStorageTests.mm; sourceTree = ""; }; 55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = ""; }; + 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; + 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; + 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; }; + 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; + 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; }; + 88EF0E6D1E6777E8008A6617 /* MGLComputedShapeSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLComputedShapeSourceTests.m; sourceTree = ""; }; 966091701E5BBFF700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 966091711E5BBFF900A9A03B /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = ""; }; 966091721E5BBFFA00A9A03B /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/Localizable.strings; sourceTree = ""; }; 966091731E5BBFFA00A9A03B /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/Localizable.strings; sourceTree = ""; }; - 88B079A81E3793E000834FAB /* MGLAbstractShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource_Private.h; sourceTree = ""; }; 96E027321E57C9A7004B8E66 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; 96E027341E57C9A9004B8E66 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; - 88B079A91E3793E000834FAB /* MGLAbstractShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAbstractShapeSource.h; sourceTree = ""; }; 96E027351E57C9AB004B8E66 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = ""; }; 96E027361E57C9AC004B8E66 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = ""; }; - 88B079AA1E3793E000834FAB /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = ""; }; 96E027371E57C9B5004B8E66 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; 96E027381E57C9B7004B8E66 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = ""; }; - 88B079AF1E3794F300834FAB /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = ""; }; 96E027391E57C9B9004B8E66 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = ""; }; 96E0273A1E57C9BB004B8E66 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = ""; }; - 88B079B01E3794F300834FAB /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = ""; }; 96E0273B1E57C9BC004B8E66 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; @@ -737,6 +739,7 @@ isa = PBXGroup; children = ( DA87A9961DC9D88400810D09 /* MGLShapeSourceTests.mm */, + 88EF0E6D1E6777E8008A6617 /* MGLComputedShapeSourceTests.m */, DA87A9971DC9D88400810D09 /* MGLTileSetTests.mm */, ); name = Sources; @@ -1424,6 +1427,7 @@ DA87A9A41DCACC5000810D09 /* MGLSymbolStyleLayerTests.mm in Sources */, 40E1601D1DF217D6005EA6D9 /* MGLStyleLayerTests.m in Sources */, DA87A9A61DCACC5000810D09 /* MGLCircleStyleLayerTests.mm in Sources */, + 88EF0E6F1E6777ED008A6617 /* MGLComputedShapeSourceTests.m in Sources */, DA87A99E1DC9DC2100810D09 /* MGLPredicateTests.mm in Sources */, DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */, DA87A9A71DCACC5000810D09 /* MGLBackgroundStyleLayerTests.mm in Sources */, From f01e1f2bf53c09cf2f295c10677b93d15b00e56c Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 16:26:49 -0700 Subject: [PATCH 55/61] First test for CustomVectorSource --- cmake/test-files.cmake | 1 + test/style/custom_vector_source.test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/style/custom_vector_source.test.cpp diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 59929bbb701..c991c61dba5 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -80,6 +80,7 @@ set(MBGL_TEST_FILES test/style/conversion/stringify.test.cpp # style + test/style/custom_vector_source.test.cpp test/style/filter.test.cpp # style/function diff --git a/test/style/custom_vector_source.test.cpp b/test/style/custom_vector_source.test.cpp new file mode 100644 index 00000000000..2b69737c1f7 --- /dev/null +++ b/test/style/custom_vector_source.test.cpp @@ -0,0 +1,22 @@ +#include +#include + + +#include + +using namespace mbgl; + + +TEST(CustomVectorSource, EmptyData) { + mbgl::style::GeoJSONOptions options; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" + const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) {}; +#pragma clang diagnostic pop + + auto testSource = std::make_unique("source", options, callback); + + mbgl::FeatureCollection featureCollection; + testSource->setTileData(0, 0, 0, mbgl::GeoJSON{featureCollection}); +} From f75b34d43f1b6aa97b3d5db201ea8ae23afe06c6 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Wed, 1 Mar 2017 16:49:49 -0700 Subject: [PATCH 56/61] A couple more tests --- test/style/custom_vector_source.test.cpp | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/style/custom_vector_source.test.cpp b/test/style/custom_vector_source.test.cpp index 2b69737c1f7..2456a46fb3d 100644 --- a/test/style/custom_vector_source.test.cpp +++ b/test/style/custom_vector_source.test.cpp @@ -1,6 +1,7 @@ #include #include +#include #include @@ -20,3 +21,33 @@ TEST(CustomVectorSource, EmptyData) { mbgl::FeatureCollection featureCollection; testSource->setTileData(0, 0, 0, mbgl::GeoJSON{featureCollection}); } + +TEST(CustomVectorSource, Geometry) { + mbgl::style::GeoJSONOptions options; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" + const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) {}; +#pragma clang diagnostic pop + + auto testSource = std::make_unique("source", options, callback); + + Polygon polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }}; + testSource->setTileData(0, 0, 0, mbgl::GeoJSON{polygon}); +} + +TEST(CustomVectorSource, ReloadWithNoTiles) { + mbgl::style::GeoJSONOptions options; + + __block bool called = false; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" + const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) { + called = true; + }; +#pragma clang diagnostic pop + + auto testSource = std::make_unique("source", options, callback); + testSource->reloadRegion(mbgl::LatLngBounds::world(), 0); + EXPECT_EQ(called, false); +} From c73f6de2bda43c8a5d7c4a3af877bab8015d2328 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 2 Mar 2017 17:47:29 -0700 Subject: [PATCH 57/61] Fix memory corruption when removing a ComputedShapeSource --- platform/darwin/src/MGLComputedShapeSource.mm | 102 ++++++++++++------ .../style/sources/custom_vector_source.cpp | 16 ++- 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index 50658501fc0..f65e8982713 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -23,6 +23,67 @@ @interface MGLComputedShapeSource () { @end + +@interface MGLComputedShapeSourceFetchOperation : NSOperation + +@property (nonatomic, readonly) uint8_t z; +@property (nonatomic, readonly) uint32_t x; +@property (nonatomic, readonly) uint32_t y; +@property (nonatomic, readonly, weak) MGLComputedShapeSource *source; + +- (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y; + +@end + +@implementation MGLComputedShapeSourceFetchOperation + + +- (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { + self = [super init]; + _x = x; + _y = y; + _z = z; + _source = source; + return self; +} + +- (void)main { + if ([self isCancelled]) { + return; + } + + NSArray *> *data; + if(!self.source.dataSource) { + data = nil; + } else if(self.source.dataSourceImplementsFeaturesForTile) { + data = [self.source.dataSource featuresInTileAtX:self.x + y:self.y + zoomLevel:self.z]; + } else { + mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(self.z, self.x, self.y); + mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); + data = [self.source.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) + zoomLevel:self.z]; + } + + if(![self isCancelled]) { + mbgl::FeatureCollection featureCollection; + featureCollection.reserve(data.count); + for (MGLShape * feature in data) { + mbgl::Feature geoJsonObject = [feature geoJSONObject].get(); + featureCollection.push_back(geoJsonObject); + } + const auto geojson = mbgl::GeoJSON{featureCollection}; + dispatch_async(dispatch_get_main_queue(), ^{ + if(![self isCancelled] && self.source.rawSource) { + self.source.rawSource->setTileData(self.z, self.x, self.y, geojson); + } + }); + } +} + +@end + @implementation MGLComputedShapeSource - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options { @@ -34,34 +95,22 @@ - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY (self.identifier.UTF8String, geoJSONOptions, ^void(uint8_t z, uint32_t x, uint32_t y) { - [self.requestQueue addOperationWithBlock: - ^{ - NSArray *> *data; - if(!self.dataSource) { - data = nil; - } else if(self.dataSourceImplementsFeaturesForTile) { - data = [self.dataSource featuresInTileAtX:x - y:y - zoomLevel:z]; - } else { - mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(z, x, y); - mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); - data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) - zoomLevel:z]; - } - [self processData:data - forTile:z x:x y:y]; - }]; + NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self z:z x:x y:y]; + [self.requestQueue addOperation:operation]; }); _pendingSource = std::move(source); self.rawSource = _pendingSource.get(); - } return self; } +- (void)dealloc { + [self.requestQueue cancelAllOperations]; +} + - (void)setDataSource:(id)dataSource { + [self.requestQueue cancelAllOperations]; //Check which method the datasource implements, to avoid having to check for each tile self.dataSourceImplementsFeaturesForTile = [dataSource respondsToSelector:@selector(featuresInTileAtX:y:zoomLevel:)]; self.dataSourceImplementsFeaturesForBounds = [dataSource respondsToSelector:@selector(featuresInCoordinateBounds:zoomLevel:)]; @@ -86,25 +135,13 @@ - (void)addToMapView:(MGLMapView *)mapView { } - (void)removeFromMapView:(MGLMapView *)mapView { + [self.requestQueue cancelAllOperations]; auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); _pendingSource = std::move(reinterpret_cast &>(removedSource)); self.rawSource = _pendingSource.get(); } -- (void)processData:(NS_ARRAY_OF(MGLShape *)*)features forTile:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { - mbgl::FeatureCollection featureCollection; - featureCollection.reserve(features.count); - for (MGLShape * feature in features) { - mbgl::Feature geoJsonObject = [feature geoJSONObject].get(); - featureCollection.push_back(geoJsonObject); - } - const auto geojson = mbgl::GeoJSON{featureCollection}; - dispatch_async(dispatch_get_main_queue(), ^{ - self.rawSource->setTileData(z, x, y, geojson); - }); -} - - (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoomLevel { self.rawSource->reloadRegion(MGLLatLngBoundsFromCoordinateBounds(bounds), (uint8_t)zoomLevel); } @@ -114,6 +151,7 @@ - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y } - (void)reloadData { + [self.requestQueue cancelAllOperations]; self.rawSource->reload(); } diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 55e7974a83e..3a12c08f5e9 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -10,19 +10,27 @@ CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, s } void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { - impl->setTileData(z, x, y, geoJSON); + if(impl != nullptr) { + impl->setTileData(z, x, y, geoJSON); + } } void CustomVectorSource::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { - impl->reloadRegion(bounds, z); + if(impl != nullptr) { + impl->reloadRegion(bounds, z); + } } void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { - impl->updateTile(z, x, y); + if(impl != nullptr) { + impl->updateTile(z, x, y); + } } void CustomVectorSource::reload() { - impl->reload(); + if(impl != nullptr) { + impl->reload(); + } } } // namespace style From 0be7292227ca5008fe611dee89c799871776c37e Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Fri, 3 Mar 2017 08:02:49 -0700 Subject: [PATCH 58/61] Change indent in MGLComputedShapeSourceTests to 4 spaces --- platform/darwin/test/MGLComputedShapeSourceTests.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/darwin/test/MGLComputedShapeSourceTests.m b/platform/darwin/test/MGLComputedShapeSourceTests.m index 3d1a37a4dc5..35499cbc9e9 100644 --- a/platform/darwin/test/MGLComputedShapeSourceTests.m +++ b/platform/darwin/test/MGLComputedShapeSourceTests.m @@ -9,16 +9,16 @@ @interface MGLComputedShapeSourceTests : XCTestCase @implementation MGLComputedShapeSourceTests - (void)testInitializer { - MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" - options:@{}]; - XCTAssertNotNil(source); - XCTAssertNotNil(source.requestQueue); - XCTAssertNil(source.dataSource); + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" + options:@{}]; + XCTAssertNotNil(source); + XCTAssertNotNil(source.requestQueue); + XCTAssertNil(source.dataSource); } - (void)testNilOptions { - MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" options:nil]; - XCTAssertNotNil(source); + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"id" options:nil]; + XCTAssertNotNil(source); } From 86ab2880ca35091ca9f25e9279792fb5569ffaf8 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 6 Mar 2017 05:53:54 -0700 Subject: [PATCH 59/61] Update layer removal to be consistent with #7962 --- platform/darwin/src/MGLComputedShapeSource.mm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index f65e8982713..b4e4a6c54a4 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -136,9 +136,20 @@ - (void)addToMapView:(MGLMapView *)mapView { - (void)removeFromMapView:(MGLMapView *)mapView { [self.requestQueue cancelAllOperations]; + if (self.rawSource != mapView.mbglMap->getSource(self.identifier.UTF8String)) { + return; + } + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); - _pendingSource = std::move(reinterpret_cast &>(removedSource)); + mbgl::style::CustomVectorSource *source = dynamic_cast(removedSource.get()); + if (!source) { + return; + } + + removedSource.release(); + + _pendingSource = std::unique_ptr(source); self.rawSource = _pendingSource.get(); } From 4bb3a9c58ca3beb8ab695ae66456cf9c4d9847d4 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Mon, 6 Mar 2017 09:59:00 -0700 Subject: [PATCH 60/61] Fix crash when source is dealloced --- platform/darwin/src/MGLComputedShapeSource.mm | 30 +++++++++++++------ .../style/sources/custom_vector_source.cpp | 16 +++------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index b4e4a6c54a4..7eeea58f6c5 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -29,7 +29,10 @@ @interface MGLComputedShapeSourceFetchOperation : NSOperation @property (nonatomic, readonly) uint8_t z; @property (nonatomic, readonly) uint32_t x; @property (nonatomic, readonly) uint32_t y; -@property (nonatomic, readonly, weak) MGLComputedShapeSource *source; +@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForTile; +@property (nonatomic, assign) BOOL dataSourceImplementsFeaturesForBounds; +@property (nonatomic, weak, nullable) id dataSource; +@property (nonatomic, nullable) mbgl::style::CustomVectorSource *rawSource; - (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y; @@ -43,7 +46,11 @@ - (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(ui _x = x; _y = y; _z = z; - _source = source; + _dataSourceImplementsFeaturesForTile = source.dataSourceImplementsFeaturesForTile; + _dataSourceImplementsFeaturesForBounds = source.dataSourceImplementsFeaturesForBounds; + _dataSource = source.dataSource; + mbgl::style::CustomVectorSource *rawSource = (mbgl::style::CustomVectorSource *)source.rawSource; + _rawSource = rawSource; return self; } @@ -53,16 +60,16 @@ - (void)main { } NSArray *> *data; - if(!self.source.dataSource) { + if(!self.dataSource) { data = nil; - } else if(self.source.dataSourceImplementsFeaturesForTile) { - data = [self.source.dataSource featuresInTileAtX:self.x + } else if(self.dataSourceImplementsFeaturesForTile) { + data = [self.dataSource featuresInTileAtX:self.x y:self.y zoomLevel:self.z]; } else { mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID(self.z, self.x, self.y); mbgl::LatLngBounds tileBounds = mbgl::LatLngBounds(tileID); - data = [self.source.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) + data = [self.dataSource featuresInCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(tileBounds) zoomLevel:self.z]; } @@ -74,14 +81,19 @@ - (void)main { featureCollection.push_back(geoJsonObject); } const auto geojson = mbgl::GeoJSON{featureCollection}; - dispatch_async(dispatch_get_main_queue(), ^{ - if(![self isCancelled] && self.source.rawSource) { - self.source.rawSource->setTileData(self.z, self.x, self.y, geojson); + dispatch_sync(dispatch_get_main_queue(), ^{ + if(![self isCancelled] && self.rawSource) { + self.rawSource->setTileData(self.z, self.x, self.y, geojson); } }); } } +- (void)cancel { + [super cancel]; + self.rawSource = NULL; +} + @end @implementation MGLComputedShapeSource diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 3a12c08f5e9..55e7974a83e 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -10,27 +10,19 @@ CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, s } void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { - if(impl != nullptr) { - impl->setTileData(z, x, y, geoJSON); - } + impl->setTileData(z, x, y, geoJSON); } void CustomVectorSource::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { - if(impl != nullptr) { - impl->reloadRegion(bounds, z); - } + impl->reloadRegion(bounds, z); } void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { - if(impl != nullptr) { - impl->updateTile(z, x, y); - } + impl->updateTile(z, x, y); } void CustomVectorSource::reload() { - if(impl != nullptr) { - impl->reload(); - } + impl->reload(); } } // namespace style From 883f72e01e45561938a0dfeb8cdf1f831df58aa0 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Tue, 7 Mar 2017 09:02:57 -0700 Subject: [PATCH 61/61] Address review comments --- .../style/sources/custom_vector_source.hpp | 6 ++-- include/mbgl/style/sources/geojson_source.hpp | 1 - platform/darwin/src/MGLComputedShapeSource.mm | 19 ++++++------ .../style/sources/custom_vector_source.cpp | 10 +++---- .../sources/custom_vector_source_impl.cpp | 30 +++++++++---------- .../sources/custom_vector_source_impl.hpp | 8 ++--- test/style/custom_vector_source.test.cpp | 23 +++++--------- 7 files changed, 45 insertions(+), 52 deletions(-) diff --git a/include/mbgl/style/sources/custom_vector_source.hpp b/include/mbgl/style/sources/custom_vector_source.hpp index 49b3e81e91e..c9efbd617ea 100644 --- a/include/mbgl/style/sources/custom_vector_source.hpp +++ b/include/mbgl/style/sources/custom_vector_source.hpp @@ -10,10 +10,10 @@ namespace style { class CustomVectorSource : public Source { public: - CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); + CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile); - void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); - void updateTile(uint8_t, uint32_t, uint32_t); + void setTileData(const CanonicalTileID&, const mapbox::geojson::geojson&); + void reloadTile(const CanonicalTileID&); void reloadRegion(mbgl::LatLngBounds bounds, uint8_t z); void reload(); diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 95a7beb2fbf..d5d15f5db19 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -28,7 +28,6 @@ using SuperclusterPointer = std::unique_ptr; struct GeoJSONOptions { // GeoJSON-VT options uint8_t minzoom = 0; - uint8_t maxzoom = 18; uint16_t tileSize = util::tileSize; uint16_t buffer = 128; diff --git a/platform/darwin/src/MGLComputedShapeSource.mm b/platform/darwin/src/MGLComputedShapeSource.mm index 7eeea58f6c5..dd6eedbb4f7 100644 --- a/platform/darwin/src/MGLComputedShapeSource.mm +++ b/platform/darwin/src/MGLComputedShapeSource.mm @@ -34,18 +34,18 @@ @interface MGLComputedShapeSourceFetchOperation : NSOperation @property (nonatomic, weak, nullable) id dataSource; @property (nonatomic, nullable) mbgl::style::CustomVectorSource *rawSource; -- (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y; +- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileId; @end @implementation MGLComputedShapeSourceFetchOperation -- (instancetype)initForSource:(MGLComputedShapeSource*)source z:(uint8_t)z x:(uint32_t)x y:(uint32_t)y { +- (instancetype)initForSource:(MGLComputedShapeSource*)source tile:(const mbgl::CanonicalTileID&)tileID { self = [super init]; - _x = x; - _y = y; - _z = z; + _z = tileID.z; + _x = tileID.x; + _y = tileID.y; _dataSourceImplementsFeaturesForTile = source.dataSourceImplementsFeaturesForTile; _dataSourceImplementsFeaturesForBounds = source.dataSourceImplementsFeaturesForBounds; _dataSource = source.dataSource; @@ -83,7 +83,7 @@ - (void)main { const auto geojson = mbgl::GeoJSON{featureCollection}; dispatch_sync(dispatch_get_main_queue(), ^{ if(![self isCancelled] && self.rawSource) { - self.rawSource->setTileData(self.z, self.x, self.y, geojson); + self.rawSource->setTileData(mbgl::CanonicalTileID(self.z, self.x, self.y), geojson); } }); } @@ -105,9 +105,9 @@ - (instancetype)initWithIdentifier:(NSString *)identifier options:(NS_DICTIONARY auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); auto source = std::make_unique (self.identifier.UTF8String, geoJSONOptions, - ^void(uint8_t z, uint32_t x, uint32_t y) + ^void(const mbgl::CanonicalTileID& tileID) { - NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self z:z x:x y:y]; + NSOperation *operation = [[MGLComputedShapeSourceFetchOperation alloc] initForSource:self tile:tileID]; [self.requestQueue addOperation:operation]; }); @@ -170,7 +170,8 @@ - (void)reloadTileInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUI } - (void)setNeedsUpdateAtZoomLevel:(NSUInteger)z x:(NSUInteger)x y:(NSUInteger)y { - self.rawSource->updateTile((uint8_t)z, (uint32_t)x, (uint32_t)y); + mbgl::CanonicalTileID tileID = mbgl::CanonicalTileID((uint8_t)z, (uint32_t)x, (uint32_t)y); + self.rawSource->reloadTile(tileID); } - (void)reloadData { diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp index 55e7974a83e..e29ab19c6e0 100644 --- a/src/mbgl/style/sources/custom_vector_source.cpp +++ b/src/mbgl/style/sources/custom_vector_source.cpp @@ -4,21 +4,21 @@ namespace mbgl { namespace style { -CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile) +CustomVectorSource::CustomVectorSource(std::string id, GeoJSONOptions options, std::function fetchTile) : Source(SourceType::Vector, std::make_unique(std::move(id), *this, options, fetchTile)), impl(static_cast(baseImpl.get())) { } -void CustomVectorSource::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { - impl->setTileData(z, x, y, geoJSON); +void CustomVectorSource::setTileData(const CanonicalTileID& tileId, const mapbox::geojson::geojson& geoJSON) { + impl->setTileData(tileId, geoJSON); } void CustomVectorSource::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { impl->reloadRegion(bounds, z); } -void CustomVectorSource::updateTile(uint8_t z, uint32_t x, uint32_t y) { - impl->updateTile(z, x, y); +void CustomVectorSource::reloadTile(const CanonicalTileID& tileId) { + impl->reloadTile(tileId); } void CustomVectorSource::reload() { diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp index 8abff02964f..3175e0bb108 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.cpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp @@ -9,7 +9,7 @@ namespace mbgl { namespace style { -CustomVectorSource::Impl::Impl(std::string id, Source& base_, GeoJSONOptions options_, std::function fetchTile_) +CustomVectorSource::Impl::Impl(std::string id, Source& base_, GeoJSONOptions options_, std::function fetchTile_) : Source::Impl(SourceType::Vector, std::move(id), base_), options(options_), fetchTile(fetchTile_) { loaded = true; } @@ -25,17 +25,17 @@ uint16_t CustomVectorSource::Impl::getTileSize() const { std::unique_ptr CustomVectorSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { auto tilePointer = std::make_unique(tileID, base.getID(), parameters); - fetchTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y); + fetchTile(tileID.canonical); return std::move(tilePointer); } -void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, const mapbox::geojson::geojson& geoJSON) { - double scale = util::EXTENT / util::tileSize; +void CustomVectorSource::Impl::setTileData(const CanonicalTileID& tileID, const mapbox::geojson::geojson& geoJSON) { + constexpr double scale = util::EXTENT / util::tileSize; - if(geoJSON.is() && geoJSON.get().size() == 0) { + if(geoJSON.is() && geoJSON.get().empty()) { for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); - if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + if(tile->id.canonical == tileID) { tile->updateData(mapbox::geometry::feature_collection()); } } @@ -61,33 +61,33 @@ void CustomVectorSource::Impl::setTileData(uint8_t z, uint32_t x, uint32_t y, co for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); - if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { + if(tile->id.canonical == tileID) { if (geoJSONOrSupercluster.is()) { - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y).features); + tile->updateData(geoJSONOrSupercluster.get()->getTile(tileID.z, tileID.x, tileID.y).features); } else { assert(geoJSONOrSupercluster.is()); - tile->updateData(geoJSONOrSupercluster.get()->getTile(z, x, y)); + tile->updateData(geoJSONOrSupercluster.get()->getTile(tileID.z, tileID.x, tileID.y)); } } } } } -void CustomVectorSource::Impl::updateTile(uint8_t z, uint32_t x, uint32_t y) { - if(cache.has(OverscaledTileID(z, x, y))) { +void CustomVectorSource::Impl::reloadTile(const CanonicalTileID& tileId) { + if(cache.has(OverscaledTileID(tileId.z, tileId.x, tileId.y))) { cache.clear(); } for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); - if(tile->id.canonical.z == z && tile->id.canonical.x == x && tile->id.canonical.y == y) { - fetchTile(z, x, y); + if(tile->id.canonical == tileId) { + fetchTile(tileId); } } } void CustomVectorSource::Impl::reloadRegion(mbgl::LatLngBounds bounds, uint8_t z) { for (const auto& tile : mbgl::util::tileCover(bounds, z)) { - updateTile(tile.canonical.z, tile.canonical.x, tile.canonical.z); + reloadTile(tile.canonical); } } @@ -95,7 +95,7 @@ void CustomVectorSource::Impl::reload() { cache.clear(); for (auto const &item : tiles) { GeoJSONTile* tile = static_cast(item.second.get()); - fetchTile(tile->id.canonical.z, tile->id.canonical.x, tile->id.canonical.y); + fetchTile(tile->id.canonical); } } diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp index 132c933ec2a..4ca9e22d0e1 100644 --- a/src/mbgl/style/sources/custom_vector_source_impl.hpp +++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp @@ -8,17 +8,17 @@ namespace style { class CustomVectorSource::Impl : public Source::Impl { public: - Impl(std::string id, Source&, GeoJSONOptions options, std::function fetchTile); + Impl(std::string id, Source&, GeoJSONOptions options, std::function fetchTile); void loadDescription(FileSource&) final {} - void setTileData(uint8_t, uint32_t, uint32_t, const mapbox::geojson::geojson&); - void updateTile(uint8_t, uint32_t, uint32_t); + void setTileData(const CanonicalTileID& tileID, const mapbox::geojson::geojson&); + void reloadTile(const CanonicalTileID& tileID); void reloadRegion(mbgl::LatLngBounds bounds, uint8_t z); void reload(); private: GeoJSONOptions options; - std::function fetchTile; + std::function fetchTile; uint16_t getTileSize() const; Range getZoomRange() final; diff --git a/test/style/custom_vector_source.test.cpp b/test/style/custom_vector_source.test.cpp index 2456a46fb3d..1ae3d683622 100644 --- a/test/style/custom_vector_source.test.cpp +++ b/test/style/custom_vector_source.test.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -11,41 +12,33 @@ using namespace mbgl; TEST(CustomVectorSource, EmptyData) { mbgl::style::GeoJSONOptions options; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-parameter" - const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) {}; -#pragma clang diagnostic pop + const auto callback = [](CanonicalTileID) {}; auto testSource = std::make_unique("source", options, callback); mbgl::FeatureCollection featureCollection; - testSource->setTileData(0, 0, 0, mbgl::GeoJSON{featureCollection}); + testSource->setTileData(CanonicalTileID(0, 0, 0), mbgl::GeoJSON{featureCollection}); } TEST(CustomVectorSource, Geometry) { mbgl::style::GeoJSONOptions options; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-parameter" - const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) {}; -#pragma clang diagnostic pop + + const auto callback = [](CanonicalTileID) {}; auto testSource = std::make_unique("source", options, callback); Polygon polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }}; - testSource->setTileData(0, 0, 0, mbgl::GeoJSON{polygon}); + testSource->setTileData(CanonicalTileID(0, 0, 0), mbgl::GeoJSON{polygon}); } TEST(CustomVectorSource, ReloadWithNoTiles) { mbgl::style::GeoJSONOptions options; - __block bool called = false; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-parameter" - const auto callback = ^void(uint8_t z, uint32_t x, uint32_t y) { + bool called = false; + const auto callback = [&called](CanonicalTileID) { called = true; }; -#pragma clang diagnostic pop auto testSource = std::make_unique("source", options, callback); testSource->reloadRegion(mbgl::LatLngBounds::world(), 0);