From 7f75eb5d6ae014391f3baf066a9873c5fb1c1ded Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 9 Dec 2016 16:09:10 -0800 Subject: [ios, macos] Rename MGLGeoJSONSource to MGLShapeSource (#7334) --- platform/darwin/src/MGLFeature.h | 6 +- platform/darwin/src/MGLGeoJSONSource.h | 145 ------------- platform/darwin/src/MGLGeoJSONSource.mm | 204 ------------------ platform/darwin/src/MGLGeoJSONSource_Private.h | 11 - platform/darwin/src/MGLPointCollection.h | 2 +- platform/darwin/src/MGLRuntimeStylingTests.m.ejs | 2 +- platform/darwin/src/MGLShapeSource.h | 145 +++++++++++++ platform/darwin/src/MGLShapeSource.mm | 204 ++++++++++++++++++ platform/darwin/src/MGLShapeSource_Private.h | 12 ++ platform/darwin/src/MGLStyle.mm | 4 +- platform/darwin/src/MGLVectorStyleLayer.h | 2 +- platform/darwin/test/MGLCircleStyleLayerTests.m | 2 +- platform/darwin/test/MGLFillStyleLayerTests.m | 2 +- platform/darwin/test/MGLFilterTests.mm | 4 +- platform/darwin/test/MGLGeoJSONSourceTests.mm | 254 ----------------------- platform/darwin/test/MGLLineStyleLayerTests.m | 2 +- platform/darwin/test/MGLRasterStyleLayerTests.m | 2 +- platform/darwin/test/MGLShapeSourceTests.mm | 254 +++++++++++++++++++++++ platform/darwin/test/MGLStyleTests.mm | 10 +- platform/darwin/test/MGLStyleValueTests.swift | 6 +- platform/darwin/test/MGLSymbolStyleLayerTests.m | 2 +- platform/ios/app/MBXViewController.m | 123 ++++++----- platform/ios/ios.xcodeproj/project.pbxproj | 44 ++-- platform/ios/jazzy.yml | 2 +- platform/ios/src/Mapbox.h | 2 +- platform/macos/app/MapDocument.m | 2 +- platform/macos/jazzy.yml | 2 +- platform/macos/macos.xcodeproj/project.pbxproj | 32 +-- platform/macos/src/Mapbox.h | 2 +- 29 files changed, 742 insertions(+), 742 deletions(-) delete mode 100644 platform/darwin/src/MGLGeoJSONSource.h delete mode 100644 platform/darwin/src/MGLGeoJSONSource.mm delete mode 100644 platform/darwin/src/MGLGeoJSONSource_Private.h create mode 100644 platform/darwin/src/MGLShapeSource.h create mode 100644 platform/darwin/src/MGLShapeSource.mm create mode 100644 platform/darwin/src/MGLShapeSource_Private.h delete mode 100644 platform/darwin/test/MGLGeoJSONSourceTests.mm create mode 100644 platform/darwin/test/MGLShapeSourceTests.mm (limited to 'platform') diff --git a/platform/darwin/src/MGLFeature.h b/platform/darwin/src/MGLFeature.h index 384c5a073e..ed4ff627b9 100644 --- a/platform/darwin/src/MGLFeature.h +++ b/platform/darwin/src/MGLFeature.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN using `-[MGLMapView visibleFeaturesAtPoint:]` and related methods. Each feature object associates a shape with an identifier and attributes as specified by the source. Like ordinary `MGLAnnotation` objects, some kinds of `MGLFeature` - objects can also be added to a map view using an `MGLGeoJSONSource` or + objects can also be added to a map view using an `MGLShapeSource` or `-[MGLMapView addAnnotations:]` and related methods. */ @protocol MGLFeature @@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN layer reference. Note that while it is possible to change this value on feature instances obtained from `-[MGLMapView visibleFeaturesAtPoint:]` and related methods, there will be no effect on the map. Setting this value can be useful - when the feature instance is used to initialize an `MGLGeoJSONSource` and that + when the feature instance is used to initialize an `MGLShapeSource` and that source is added to the map and styled. */ @property (nonatomic, copy, nullable) id identifier; @@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN layer references. Note that while it is possible to change this value on feature instances obtained from `-[MGLMapView visibleFeaturesAtPoint:]` and related methods, there will be no effect on the map. Setting this value can be useful - when the feature instance is used to initialize an `MGLGeoJSONSource` and that + when the feature instance is used to initialize an `MGLShapeSource` and that source is added to the map and styled. */ @property (nonatomic, copy) NS_DICTIONARY_OF(NSString *, id) *attributes; diff --git a/platform/darwin/src/MGLGeoJSONSource.h b/platform/darwin/src/MGLGeoJSONSource.h deleted file mode 100644 index 2e86cf5b4f..0000000000 --- a/platform/darwin/src/MGLGeoJSONSource.h +++ /dev/null @@ -1,145 +0,0 @@ -#import "MGLSource.h" - -#import "MGLTypes.h" -#import "MGLShape.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 - -#pragma mark Initializing a Source - -/** - Returns a GeoJSON source initialized with an identifier, GeoJSON data, and a - dictionary of options for the source according to the - style - specification. - - @param identifier A string that uniquely identifies the source. - @param geoJSONData An `NSData` object representing GeoJSON source code. - @param options An `NSDictionary` of options for this source. - @return An initialized GeoJSON source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(nullable NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; - -/** - Returns a GeoJSON source with an identifier, URL, and dictionary of options for - the source according to the - style - specification. - - @param identifier A string that uniquely identifies the source. - @param URL An HTTP(S) URL, absolute file URL, or local file URL relative to the - current application’s resource bundle. - @param options An `NSDictionary` of options for this source. - @return An initialized GeoJSON source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(nullable NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; - -/** - Returns a GeoJSON source with an identifier, features dictionary, and dictionary - of options for the source according to the - style - specification. - - @param identifier A string that uniquely identifies the source. - @param shape A concrete subclass of `MGLShape` - @param options An `NSDictionary` of options for this source. - @return An initialized GeoJSON source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(nullable NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; - -#pragma mark Accessing a Source’s Content - -/** - The contents of the source. A shape can represent a GeoJSON geometry, a feature, - or a collection of features. - - If the receiver was initialized using `-initWithIdentifier:URL:options:`, this property - is set to `nil`. This property is unavailable until the receiver is passed into - `-[MGLStyle addSource]`. - */ -@property (nonatomic, nullable) MGLShape *shape; - -/** - A GeoJSON representation of the contents of the source. - - Use the `features` property instead to get an object representation of the - contents. Alternatively, use `NSJSONSerialization` with the value of this - property to transform it into Foundation types. - - If the receiver was initialized using `-initWithIdentifier:URL:options` or - `-initWithIdentifier:features:options`, this property is set to `nil`. - This property is unavailable until the receiver is passed - into `-[MGLStyle addSource]`. - */ -@property (nonatomic, nullable, copy) NSData *geoJSONData; - -/** - The URL to the GeoJSON document that specifies the contents of the source. - - If the receiver was initialized using `-initWithIdentifier:geoJSONData:options`, this - property is set to `nil`. - */ -@property (nonatomic, nullable) NSURL *URL; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm deleted file mode 100644 index 570b884149..0000000000 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ /dev/null @@ -1,204 +0,0 @@ -#import "MGLGeoJSONSource_Private.h" - -#import "MGLMapView_Private.h" -#import "MGLSource_Private.h" -#import "MGLFeature_Private.h" -#import "MGLShape_Private.h" - -#import "NSURL+MGLAdditions.h" - -#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 () - -- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource NS_DESIGNATED_INITIALIZER; - -@property (nonatomic, readwrite) NSDictionary *options; -@property (nonatomic) mbgl::style::GeoJSONSource *rawSource; - -@end - -@implementation MGLGeoJSONSource -{ - std::unique_ptr _pendingSource; -} - -- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options -{ - if (self = [super initWithIdentifier:identifier]) - { - _geoJSONData = data; - _options = options; - [self commonInit]; - } - return self; -} - -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options -{ - if (self = [super initWithIdentifier:identifier]) - { - _URL = url; - _options = options; - [self commonInit]; - } - return self; -} - -- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(NSDictionary *)options -{ - if (self = [super initWithIdentifier:identifier]) { - _shape = shape; - _options = options; - [self commonInit]; - } - return self; -} - -- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource { - return [super initWithRawSource:rawSource]; -} - -- (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)commonInit -{ - auto source = std::make_unique(self.identifier.UTF8String, self.geoJSONOptions); - - if (self.URL) { - NSURL *url = self.URL.mgl_URLByStandardizingScheme; - source->setURL(url.absoluteString.UTF8String); - _shape = nil; - } else if (self.geoJSONData) { - NSString *string = [[NSString alloc] initWithData:self.geoJSONData encoding:NSUTF8StringEncoding]; - const auto geojson = mapbox::geojson::parse(string.UTF8String); - source->setGeoJSON(geojson); - _shape = MGLShapeFromGeoJSON(geojson); - } else { - const auto geojson = mbgl::GeoJSON{self.shape.geometryObject}; - source->setGeoJSON(geojson); - } - - _pendingSource = std::move(source); - 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 -{ - _geoJSONData = geoJSONData; - - if (self.rawSource == NULL) - { - [self commonInit]; - } - - NSString *string = [[NSString alloc] initWithData:_geoJSONData encoding:NSUTF8StringEncoding]; - const auto geojson = mapbox::geojson::parse(string.UTF8String); - self.rawSource->setGeoJSON(geojson); - - _shape = MGLShapeFromGeoJSON(geojson); -} - -- (void)setURL:(NSURL *)URL -{ - _URL = URL; - - if (self.rawSource == NULL) - { - [self commonInit]; - } - - NSURL *url = self.URL.mgl_URLByStandardizingScheme; - self.rawSource->setURL(url.absoluteString.UTF8String); -} - - -- (void)setShape:(MGLShape *)shape -{ - if (self.rawSource == NULL) - { - [self commonInit]; - } - - const auto geojson = mbgl::GeoJSON{shape.geometryObject}; - self.rawSource->setGeoJSON(geojson); - - _shape = shape; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; geoJSONData = %@; shape = %@>", - NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.geoJSONData, self.shape]; -} - -@end diff --git a/platform/darwin/src/MGLGeoJSONSource_Private.h b/platform/darwin/src/MGLGeoJSONSource_Private.h deleted file mode 100644 index 9d67deee34..0000000000 --- a/platform/darwin/src/MGLGeoJSONSource_Private.h +++ /dev/null @@ -1,11 +0,0 @@ -#import "MGLGeoJSONSource.h" - -#include - -@interface MGLGeoJSONSource (Private) - -- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource; - -- (mbgl::style::GeoJSONOptions)geoJSONOptions; - -@end diff --git a/platform/darwin/src/MGLPointCollection.h b/platform/darwin/src/MGLPointCollection.h index ce3e95a16d..95af9dae5e 100644 --- a/platform/darwin/src/MGLPointCollection.h +++ b/platform/darwin/src/MGLPointCollection.h @@ -11,7 +11,7 @@ @note `MGLPointCollection` objects cannot be added to a map view using `-[MGLMapView addAnnotations:]` and related methods. However, when used in a - `MGLPointCollectionFeature` to initialize a `MGLGeoJSONSource` that is added + `MGLPointCollectionFeature` to initialize a `MGLShapeSource` that is added to the map view's style, the point collection represents as a group of distinct annotations. */ diff --git a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs index 720ee4547e..91c626d1a2 100644 --- a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs +++ b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs @@ -19,7 +19,7 @@ <% } else { -%> NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID" source:source]; <% } -%> diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h new file mode 100644 index 0000000000..5067466e6d --- /dev/null +++ b/platform/darwin/src/MGLShapeSource.h @@ -0,0 +1,145 @@ +#import "MGLSource.h" + +#import "MGLTypes.h" +#import "MGLShape.h" + +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`. + */ +extern 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 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. + */ +extern 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. + */ +extern 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. + */ +extern 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. + */ +extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; + +/** + A shape source. + + @see The + style specification. + */ +@interface MGLShapeSource : MGLSource + +#pragma mark Initializing a Source + +/** + Returns a shape source initialized with an identifier, GeoJSON data, and a + dictionary of options for the source according to the + style + specification. + + @param identifier A string that uniquely identifies the source. + @param geoJSONData An `NSData` object representing GeoJSON source code. + @param options An `NSDictionary` of options for this source. + @return An initialized shape source. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(nullable NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; + +/** + Returns a shape source with an identifier, URL, and dictionary of options for + the source according to the + style + specification. + + @param identifier A string that uniquely identifies the source. + @param URL An HTTP(S) URL, absolute file URL, or local file URL relative to the + current application’s resource bundle. + @param options An `NSDictionary` of options for this source. + @return An initialized shape source. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(nullable NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; + +/** + Returns a shape source with an identifier, a shape, and dictionary + of options for the source according to the + style + specification. + + @param identifier A string that uniquely identifies the source. + @param shape A concrete subclass of `MGLShape` + @param options An `NSDictionary` of options for this source. + @return An initialized shape source. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(nullable NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; + +#pragma mark Accessing a Source’s Content + +/** + The contents of the source. A shape can represent a GeoJSON geometry, a feature, + or a collection of features. + + If the receiver was initialized using `-initWithIdentifier:URL:options:`, this property + is set to `nil`. This property is unavailable until the receiver is passed into + `-[MGLStyle addSource]`. + */ +@property (nonatomic, nullable) MGLShape *shape; + +/** + A GeoJSON representation of the contents of the source. + + Use the `shape` property instead to get an object representation of the + contents. Alternatively, use `NSJSONSerialization` with the value of this + property to transform it into Foundation types. + + If the receiver was initialized using `-initWithIdentifier:URL:options` or + `-initWithIdentifier:shape:options`, this property is set to `nil`. + This property is unavailable until the receiver is passed into + `-[MGLStyle addSource]`. + */ +@property (nonatomic, nullable, copy) NSData *geoJSONData; + +/** + The URL to the GeoJSON document that specifies the contents of the source. + + If the receiver was initialized using `-initWithIdentifier:geoJSONData:options`, + this property is set to `nil`. + */ +@property (nonatomic, nullable) NSURL *URL; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm new file mode 100644 index 0000000000..434e6fcb1b --- /dev/null +++ b/platform/darwin/src/MGLShapeSource.mm @@ -0,0 +1,204 @@ +#import "MGLShapeSource_Private.h" + +#import "MGLMapView_Private.h" +#import "MGLSource_Private.h" +#import "MGLFeature_Private.h" +#import "MGLShape_Private.h" + +#import "NSURL+MGLAdditions.h" + +#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 () + +- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource NS_DESIGNATED_INITIALIZER; + +@property (nonatomic, readwrite) NSDictionary *options; +@property (nonatomic) mbgl::style::GeoJSONSource *rawSource; + +@end + +@implementation MGLShapeSource +{ + std::unique_ptr _pendingSource; +} + +- (instancetype)initWithIdentifier:(NSString *)identifier geoJSONData:(NSData *)data options:(NS_DICTIONARY_OF(NSString *, id) *)options +{ + if (self = [super initWithIdentifier:identifier]) + { + _geoJSONData = data; + _options = options; + [self commonInit]; + } + return self; +} + +- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options +{ + if (self = [super initWithIdentifier:identifier]) + { + _URL = url; + _options = options; + [self commonInit]; + } + return self; +} + +- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(NSDictionary *)options +{ + if (self = [super initWithIdentifier:identifier]) { + _shape = shape; + _options = options; + [self commonInit]; + } + return self; +} + +- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource { + return [super initWithRawSource:rawSource]; +} + +- (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)commonInit +{ + auto source = std::make_unique(self.identifier.UTF8String, self.geoJSONOptions); + + if (self.URL) { + NSURL *url = self.URL.mgl_URLByStandardizingScheme; + source->setURL(url.absoluteString.UTF8String); + _shape = nil; + } else if (self.geoJSONData) { + NSString *string = [[NSString alloc] initWithData:self.geoJSONData encoding:NSUTF8StringEncoding]; + const auto geojson = mapbox::geojson::parse(string.UTF8String); + source->setGeoJSON(geojson); + _shape = MGLShapeFromGeoJSON(geojson); + } else { + const auto geojson = mbgl::GeoJSON{self.shape.geometryObject}; + source->setGeoJSON(geojson); + } + + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); +} + +- (mbgl::style::GeoJSONOptions)geoJSONOptions +{ + auto mbglOptions = mbgl::style::GeoJSONOptions(); + + if (id value = self.options[MGLShapeSourceOptionMaximumZoomLevel]) { + [self validateValue:value]; + mbglOptions.maxzoom = [value integerValue]; + } + + if (id value = self.options[MGLShapeSourceOptionBuffer]) { + [self validateValue:value]; + mbglOptions.buffer = [value integerValue]; + } + + if (id value = self.options[MGLShapeSourceOptionSimplificationTolerance]) { + [self validateValue:value]; + mbglOptions.tolerance = [value doubleValue]; + } + + if (id value = self.options[MGLShapeSourceOptionClusterRadius]) { + [self validateValue:value]; + mbglOptions.clusterRadius = [value integerValue]; + } + + if (id value = self.options[MGLShapeSourceOptionMaximumZoomLevelForClustering]) { + [self validateValue:value]; + mbglOptions.clusterMaxZoom = [value integerValue]; + } + + if (id value = self.options[MGLShapeSourceOptionClustered]) { + [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 +{ + _geoJSONData = geoJSONData; + + if (self.rawSource == NULL) + { + [self commonInit]; + } + + NSString *string = [[NSString alloc] initWithData:_geoJSONData encoding:NSUTF8StringEncoding]; + const auto geojson = mapbox::geojson::parse(string.UTF8String); + self.rawSource->setGeoJSON(geojson); + + _shape = MGLShapeFromGeoJSON(geojson); +} + +- (void)setURL:(NSURL *)URL +{ + _URL = URL; + + if (self.rawSource == NULL) + { + [self commonInit]; + } + + NSURL *url = self.URL.mgl_URLByStandardizingScheme; + self.rawSource->setURL(url.absoluteString.UTF8String); +} + + +- (void)setShape:(MGLShape *)shape +{ + if (self.rawSource == NULL) + { + [self commonInit]; + } + + const auto geojson = mbgl::GeoJSON{shape.geometryObject}; + self.rawSource->setGeoJSON(geojson); + + _shape = shape; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; geoJSONData = %@; shape = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.geoJSONData, self.shape]; +} + +@end diff --git a/platform/darwin/src/MGLShapeSource_Private.h b/platform/darwin/src/MGLShapeSource_Private.h new file mode 100644 index 0000000000..af5dc33f96 --- /dev/null +++ b/platform/darwin/src/MGLShapeSource_Private.h @@ -0,0 +1,12 @@ +#import "MGLShapeSource.h" +#import "MGLShapeSource_Private.h" + +#include + +@interface MGLShapeSource (Private) + +- (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource; + +- (mbgl::style::GeoJSONOptions)geoJSONOptions; + +@end diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index ee0bb286ba..c84782dba9 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -19,7 +19,7 @@ #import "MGLSource.h" #import "MGLVectorSource_Private.h" #import "MGLRasterSource.h" -#import "MGLGeoJSONSource.h" +#import "MGLShapeSource.h" #import "MGLAttributionInfo.h" #import "MGLTileSet_Private.h" @@ -167,7 +167,7 @@ static NSURL *MGLStyleURL_emerald; if (auto vectorSource = source->as()) { return [[MGLVectorSource alloc] initWithRawSource:vectorSource]; } else if (auto geoJSONSource = source->as()) { - return [[MGLGeoJSONSource alloc] initWithRawSource:geoJSONSource]; + return [[MGLShapeSource alloc] initWithRawSource:geoJSONSource]; } else if (auto rasterSource = source->as()) { return [[MGLRasterSource alloc] initWithRawSource:rasterSource]; } else { diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h index e0980af44d..1197d76807 100644 --- a/platform/darwin/src/MGLVectorStyleLayer.h +++ b/platform/darwin/src/MGLVectorStyleLayer.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN /** `MGLVectorStyleLayer` is an abstract superclass for style layers whose content - is defined by an `MGLGeoJSONSource` or `MGLVectorSource` object. + is defined by an `MGLShapeSource` or `MGLVectorSource` object. Do not create instances of this class directly, and do not create your own subclasses of this class. Instead, create instances of the following concrete diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m index 432d3ffa79..f98e731354 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ b/platform/darwin/test/MGLCircleStyleLayerTests.m @@ -11,7 +11,7 @@ - (void)testCircleLayer { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m index 87846302ea..dd16214a71 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ b/platform/darwin/test/MGLFillStyleLayerTests.m @@ -11,7 +11,7 @@ - (void)testFillLayer { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index b18400f83a..4b393fd1dc 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -5,7 +5,7 @@ @interface MGLFilterTests : MGLStyleLayerTests { - MGLGeoJSONSource *source; + MGLShapeSource *source; MGLLineStyleLayer *layer; } @end @@ -18,7 +18,7 @@ NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; NSData *geoJSONData = [NSData dataWithContentsOfURL:url]; - source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"test-source" geoJSONData:geoJSONData options:nil]; + source = [[MGLShapeSource alloc] initWithIdentifier:@"test-source" geoJSONData:geoJSONData options:nil]; [self.mapView.style addSource:source]; layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"test-layer" source:source]; } diff --git a/platform/darwin/test/MGLGeoJSONSourceTests.mm b/platform/darwin/test/MGLGeoJSONSourceTests.mm deleted file mode 100644 index 47f12828eb..0000000000 --- a/platform/darwin/test/MGLGeoJSONSourceTests.mm +++ /dev/null @@ -1,254 +0,0 @@ -#import - -#import -#import "MGLFeature_Private.h" -#import "MGLGeoJSONSource_Private.h" -#import "MGLSource_Private.h" - -#include - -@interface MGLGeoJSONSourceTests : XCTestCase -@end - -@implementation MGLGeoJSONSourceTests - -- (void)testMGLGeoJSONSourceWithOptions { - NSURL *url = [NSURL URLWithString:@"http://www.mapbox.com/source"]; - - NSDictionary *options = @{MGLGeoJSONSourceOptionClustered: @YES, - MGLGeoJSONSourceOptionClusterRadius: @42, - MGLGeoJSONSourceOptionMaximumZoomLevelForClustering: @98, - MGLGeoJSONSourceOptionMaximumZoomLevel: @99, - MGLGeoJSONSourceOptionBuffer: @1976, - MGLGeoJSONSourceOptionSimplificationTolerance: @0.42}; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options]; - - auto mbglOptions = [source geoJSONOptions]; - XCTAssertTrue(mbglOptions.cluster); - XCTAssertEqual(mbglOptions.clusterRadius, 42); - XCTAssertEqual(mbglOptions.clusterMaxZoom, 98); - XCTAssertEqual(mbglOptions.maxzoom, 99); - XCTAssertEqual(mbglOptions.buffer, 1976); - XCTAssertEqual(mbglOptions.tolerance, 0.42); - - options = @{MGLGeoJSONSourceOptionClustered: @"number 1"}; - XCTAssertThrows([[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options]); -} - -- (void)testNilShape { - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"id" shape:nil options:nil]; - XCTAssertNil(source.shape); -} - -- (void)testMGLGeoJSONSourceWithDataMultipleFeatures { - - NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}"; - - NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" geoJSONData:data options:nil]; - - MGLShapeCollection *collection = (MGLShapeCollection *)source.shape; - XCTAssertNotNil(collection); - XCTAssertEqual(collection.shapes.count, 1); - XCTAssertTrue([collection.shapes.firstObject isMemberOfClass:[MGLPolylineFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithSingleFeature { - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geojson" - geoJSONData:[@"{\"type\": \"Point\", \"coordinates\": [0, 0]}" dataUsingEncoding:NSUTF8StringEncoding] - options:nil]; - XCTAssertNotNil(source.shape); - XCTAssert([source.shape isKindOfClass:[MGLPointFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithPolylineFeatures { - CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; - MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:2]; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polylineFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLPolylineFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithPolygonFeatures { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(100.0, 0.0), - CLLocationCoordinate2DMake(101.0, 0.0), - CLLocationCoordinate2DMake(101.0, 1.0), - CLLocationCoordinate2DMake(100.0, 1.0), - CLLocationCoordinate2DMake(100.0, 0.0)}; - - MGLPolygonFeature *polygonFeature = (MGLPolygonFeature *)[MGLPolygonFeature polygonWithCoordinates:coordinates count:5]; - polygonFeature.identifier = @"feature-id"; - NSString *stringAttribute = @"string"; - NSNumber *boolAttribute = [NSNumber numberWithBool:YES]; - NSNumber *doubleAttribute = [NSNumber numberWithDouble:1.23]; - NSDictionary *nestedDictionaryValue = @{@"nested-key-1": @"nested-string-value"}; - NSArray *arrayValue = @[@"string-value", @2]; - NSDictionary *dictionaryValue = @{@"key-1": @"string-value", - @"key-2": @1, - @"key-3": nestedDictionaryValue, - @"key-4": arrayValue}; - NSArray *arrayOfArrays = @[@[@1, @"string-value", @[@"jagged"]]]; - NSArray *arrayOfDictionaries = @[@{@"key": @"value"}]; - - polygonFeature.attributes = @{@"name": stringAttribute, - @"bool": boolAttribute, - @"double": doubleAttribute, - @"dictionary-attribute": dictionaryValue, - @"array-attribute": arrayValue, - @"array-of-array-attribute": arrayOfArrays, - @"array-of-dictionary-attribute": arrayOfDictionaries}; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; - - XCTAssertNotNil(source.shape); - MGLPolygonFeature *expectedPolygonFeature = (MGLPolygonFeature *)source.shape; - XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); - XCTAssertTrue([expectedPolygonFeature isMemberOfClass:[MGLPolygonFeature class]]); - XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"name"], stringAttribute); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"bool"], boolAttribute); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"double"], doubleAttribute); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"dictionary-attribute"], dictionaryValue); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-attribute"], arrayValue); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-array-attribute"], arrayOfArrays); - XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-dictionary-attribute"], arrayOfDictionaries); -} - -- (void)testMGLGeoJSONSourceWithPolygonFeaturesInculdingInteriorPolygons { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(100.0, 0.0), - CLLocationCoordinate2DMake(101.0, 0.0), - CLLocationCoordinate2DMake(101.0, 1.0), - CLLocationCoordinate2DMake(100.0, 1.0), - CLLocationCoordinate2DMake(100.0, 0.0)}; - - CLLocationCoordinate2D interiorCoordinates[] = { - CLLocationCoordinate2DMake(100.2, 0.2), - CLLocationCoordinate2DMake(100.8, 0.2), - CLLocationCoordinate2DMake(100.8, 0.8), - CLLocationCoordinate2DMake(100.2, 0.8), - CLLocationCoordinate2DMake(100.2, 0.2)}; - - MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; - - MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLPolygonFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithMultiPolylineFeatures { - CLLocationCoordinate2D firstCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; - MGLPolylineFeature *firstPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:firstCoordinates count:2]; - CLLocationCoordinate2D secondCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; - MGLPolylineFeature *secondPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:secondCoordinates count:2]; - MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[firstPolylineFeature, secondPolylineFeature]]; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:multiPolylineFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolylineFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithMultiPolygonFeatures { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(100.0, 0.0), - CLLocationCoordinate2DMake(101.0, 0.0), - CLLocationCoordinate2DMake(101.0, 1.0), - CLLocationCoordinate2DMake(100.0, 1.0), - CLLocationCoordinate2DMake(100.0, 0.0)}; - - CLLocationCoordinate2D interiorCoordinates[] = { - CLLocationCoordinate2DMake(100.2, 0.2), - CLLocationCoordinate2DMake(100.8, 0.2), - CLLocationCoordinate2DMake(100.8, 0.8), - CLLocationCoordinate2DMake(100.2, 0.8), - CLLocationCoordinate2DMake(100.2, 0.2)}; - - MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; - - MGLPolygonFeature *firstPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; - MGLPolygonFeature *secondPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; - - MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[firstPolygon, secondPolygon]]; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:multiPolygonFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolygonFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithPointFeature { - MGLPointFeature *pointFeature = [MGLPointFeature new]; - pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2); - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" shape:pointFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLPointFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithPointCollectionFeature { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(100.0, 0.0), - CLLocationCoordinate2DMake(101.0, 0.0), - CLLocationCoordinate2DMake(101.0, 1.0), - CLLocationCoordinate2DMake(100.0, 1.0), - CLLocationCoordinate2DMake(100.0, 0.0)}; - MGLPointCollectionFeature *pointCollectionFeature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:5]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" shape:pointCollectionFeature options:nil]; - - XCTAssertNotNil(source.shape); - XCTAssertTrue([source.shape isMemberOfClass:[MGLPointCollectionFeature class]]); -} - -- (void)testMGLGeoJSONSourceWithShapeCollectionFeatures { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(100.0, 0.0), - CLLocationCoordinate2DMake(101.0, 0.0), - CLLocationCoordinate2DMake(101.0, 1.0), - CLLocationCoordinate2DMake(100.0, 1.0), - CLLocationCoordinate2DMake(100.0, 0.0)}; - - CLLocationCoordinate2D interiorCoordinates[] = { - CLLocationCoordinate2DMake(100.2, 0.2), - CLLocationCoordinate2DMake(100.8, 0.2), - CLLocationCoordinate2DMake(100.8, 0.8), - CLLocationCoordinate2DMake(100.2, 0.8), - CLLocationCoordinate2DMake(100.2, 0.2)}; - - MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; - - MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; - - CLLocationCoordinate2D coordinates_2[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; - MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates_2 count:2]; - - MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[polygonFeature, polygonFeature]]; - - MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[polylineFeature, polylineFeature]]; - - MGLPointCollectionFeature *pointCollectionFeature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:5]; - - MGLPointFeature *pointFeature = [MGLPointFeature new]; - pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2); - - MGLShapeCollectionFeature *shapeCollectionFeature = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[polygonFeature, polylineFeature, multiPolygonFeature, multiPolylineFeature, pointCollectionFeature, pointFeature]]; - - MGLShapeCollectionFeature *shapeCollectionFeature_1 = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[polygonFeature, polylineFeature, multiPolygonFeature, multiPolylineFeature, pointCollectionFeature, pointFeature, shapeCollectionFeature]]; - - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:shapeCollectionFeature_1 options:nil]; - - MGLShapeCollectionFeature *shape = (MGLShapeCollectionFeature *)source.shape; - - XCTAssertNotNil(shape); - XCTAssert(shape.shapes.count == 7, @"Shape collection should contain 7 shapes"); -} - -@end diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m index e313b55bc7..49dd1f2198 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ b/platform/darwin/test/MGLLineStyleLayerTests.m @@ -11,7 +11,7 @@ - (void)testLineLayer { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m index 197f1d4723..485664c986 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ b/platform/darwin/test/MGLRasterStyleLayerTests.m @@ -11,7 +11,7 @@ - (void)testRasterLayer { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/darwin/test/MGLShapeSourceTests.mm b/platform/darwin/test/MGLShapeSourceTests.mm new file mode 100644 index 0000000000..c4273e6e3f --- /dev/null +++ b/platform/darwin/test/MGLShapeSourceTests.mm @@ -0,0 +1,254 @@ +#import + +#import +#import "MGLFeature_Private.h" +#import "MGLShapeSource_Private.h" +#import "MGLSource_Private.h" + +#include + +@interface MGLShapeSourceTests : XCTestCase +@end + +@implementation MGLShapeSourceTests + +- (void)testMGLShapeSourceWithOptions { + NSURL *url = [NSURL URLWithString:@"http://www.mapbox.com/source"]; + + NSDictionary *options = @{MGLShapeSourceOptionClustered: @YES, + MGLShapeSourceOptionClusterRadius: @42, + MGLShapeSourceOptionMaximumZoomLevelForClustering: @98, + MGLShapeSourceOptionMaximumZoomLevel: @99, + MGLShapeSourceOptionBuffer: @1976, + MGLShapeSourceOptionSimplificationTolerance: @0.42}; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" URL:url options:options]; + + auto mbglOptions = [source geoJSONOptions]; + XCTAssertTrue(mbglOptions.cluster); + XCTAssertEqual(mbglOptions.clusterRadius, 42); + XCTAssertEqual(mbglOptions.clusterMaxZoom, 98); + XCTAssertEqual(mbglOptions.maxzoom, 99); + XCTAssertEqual(mbglOptions.buffer, 1976); + XCTAssertEqual(mbglOptions.tolerance, 0.42); + + options = @{MGLShapeSourceOptionClustered: @"number 1"}; + XCTAssertThrows([[MGLShapeSource alloc] initWithIdentifier:@"source-id" URL:url options:options]); +} + +- (void)testNilShape { + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"id" shape:nil options:nil]; + XCTAssertNil(source.shape); +} + +- (void)testMGLShapeSourceWithDataMultipleFeatures { + + NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}"; + + NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" geoJSONData:data options:nil]; + + MGLShapeCollection *collection = (MGLShapeCollection *)source.shape; + XCTAssertNotNil(collection); + XCTAssertEqual(collection.shapes.count, 1); + XCTAssertTrue([collection.shapes.firstObject isMemberOfClass:[MGLPolylineFeature class]]); +} + +- (void)testMGLShapeSourceWithSingleFeature { + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geojson" + geoJSONData:[@"{\"type\": \"Point\", \"coordinates\": [0, 0]}" dataUsingEncoding:NSUTF8StringEncoding] + options:nil]; + XCTAssertNotNil(source.shape); + XCTAssert([source.shape isKindOfClass:[MGLPointFeature class]]); +} + +- (void)testMGLShapeSourceWithPolylineFeatures { + CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; + MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:2]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:polylineFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPolylineFeature class]]); +} + +- (void)testMGLShapeSourceWithPolygonFeatures { + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(100.0, 0.0), + CLLocationCoordinate2DMake(101.0, 0.0), + CLLocationCoordinate2DMake(101.0, 1.0), + CLLocationCoordinate2DMake(100.0, 1.0), + CLLocationCoordinate2DMake(100.0, 0.0)}; + + MGLPolygonFeature *polygonFeature = (MGLPolygonFeature *)[MGLPolygonFeature polygonWithCoordinates:coordinates count:5]; + polygonFeature.identifier = @"feature-id"; + NSString *stringAttribute = @"string"; + NSNumber *boolAttribute = [NSNumber numberWithBool:YES]; + NSNumber *doubleAttribute = [NSNumber numberWithDouble:1.23]; + NSDictionary *nestedDictionaryValue = @{@"nested-key-1": @"nested-string-value"}; + NSArray *arrayValue = @[@"string-value", @2]; + NSDictionary *dictionaryValue = @{@"key-1": @"string-value", + @"key-2": @1, + @"key-3": nestedDictionaryValue, + @"key-4": arrayValue}; + NSArray *arrayOfArrays = @[@[@1, @"string-value", @[@"jagged"]]]; + NSArray *arrayOfDictionaries = @[@{@"key": @"value"}]; + + polygonFeature.attributes = @{@"name": stringAttribute, + @"bool": boolAttribute, + @"double": doubleAttribute, + @"dictionary-attribute": dictionaryValue, + @"array-attribute": arrayValue, + @"array-of-array-attribute": arrayOfArrays, + @"array-of-dictionary-attribute": arrayOfDictionaries}; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; + + XCTAssertNotNil(source.shape); + MGLPolygonFeature *expectedPolygonFeature = (MGLPolygonFeature *)source.shape; + XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); + XCTAssertTrue([expectedPolygonFeature isMemberOfClass:[MGLPolygonFeature class]]); + XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"name"], stringAttribute); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"bool"], boolAttribute); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"double"], doubleAttribute); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"dictionary-attribute"], dictionaryValue); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-attribute"], arrayValue); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-array-attribute"], arrayOfArrays); + XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-dictionary-attribute"], arrayOfDictionaries); +} + +- (void)testMGLShapeSourceWithPolygonFeaturesInculdingInteriorPolygons { + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(100.0, 0.0), + CLLocationCoordinate2DMake(101.0, 0.0), + CLLocationCoordinate2DMake(101.0, 1.0), + CLLocationCoordinate2DMake(100.0, 1.0), + CLLocationCoordinate2DMake(100.0, 0.0)}; + + CLLocationCoordinate2D interiorCoordinates[] = { + CLLocationCoordinate2DMake(100.2, 0.2), + CLLocationCoordinate2DMake(100.8, 0.2), + CLLocationCoordinate2DMake(100.8, 0.8), + CLLocationCoordinate2DMake(100.2, 0.8), + CLLocationCoordinate2DMake(100.2, 0.2)}; + + MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; + + MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPolygonFeature class]]); +} + +- (void)testMGLShapeSourceWithMultiPolylineFeatures { + CLLocationCoordinate2D firstCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; + MGLPolylineFeature *firstPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:firstCoordinates count:2]; + CLLocationCoordinate2D secondCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; + MGLPolylineFeature *secondPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:secondCoordinates count:2]; + MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[firstPolylineFeature, secondPolylineFeature]]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:multiPolylineFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolylineFeature class]]); +} + +- (void)testMGLShapeSourceWithMultiPolygonFeatures { + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(100.0, 0.0), + CLLocationCoordinate2DMake(101.0, 0.0), + CLLocationCoordinate2DMake(101.0, 1.0), + CLLocationCoordinate2DMake(100.0, 1.0), + CLLocationCoordinate2DMake(100.0, 0.0)}; + + CLLocationCoordinate2D interiorCoordinates[] = { + CLLocationCoordinate2DMake(100.2, 0.2), + CLLocationCoordinate2DMake(100.8, 0.2), + CLLocationCoordinate2DMake(100.8, 0.8), + CLLocationCoordinate2DMake(100.2, 0.8), + CLLocationCoordinate2DMake(100.2, 0.2)}; + + MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; + + MGLPolygonFeature *firstPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; + MGLPolygonFeature *secondPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; + + MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[firstPolygon, secondPolygon]]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:multiPolygonFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolygonFeature class]]); +} + +- (void)testMGLShapeSourceWithPointFeature { + MGLPointFeature *pointFeature = [MGLPointFeature new]; + pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2); + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"souce-id" shape:pointFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPointFeature class]]); +} + +- (void)testMGLShapeSourceWithPointCollectionFeature { + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(100.0, 0.0), + CLLocationCoordinate2DMake(101.0, 0.0), + CLLocationCoordinate2DMake(101.0, 1.0), + CLLocationCoordinate2DMake(100.0, 1.0), + CLLocationCoordinate2DMake(100.0, 0.0)}; + MGLPointCollectionFeature *pointCollectionFeature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:5]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"souce-id" shape:pointCollectionFeature options:nil]; + + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPointCollectionFeature class]]); +} + +- (void)testMGLShapeSourceWithShapeCollectionFeatures { + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(100.0, 0.0), + CLLocationCoordinate2DMake(101.0, 0.0), + CLLocationCoordinate2DMake(101.0, 1.0), + CLLocationCoordinate2DMake(100.0, 1.0), + CLLocationCoordinate2DMake(100.0, 0.0)}; + + CLLocationCoordinate2D interiorCoordinates[] = { + CLLocationCoordinate2DMake(100.2, 0.2), + CLLocationCoordinate2DMake(100.8, 0.2), + CLLocationCoordinate2DMake(100.8, 0.8), + CLLocationCoordinate2DMake(100.2, 0.8), + CLLocationCoordinate2DMake(100.2, 0.2)}; + + MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5]; + + MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; + + CLLocationCoordinate2D coordinates_2[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; + MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates_2 count:2]; + + MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[polygonFeature, polygonFeature]]; + + MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[polylineFeature, polylineFeature]]; + + MGLPointCollectionFeature *pointCollectionFeature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:5]; + + MGLPointFeature *pointFeature = [MGLPointFeature new]; + pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2); + + MGLShapeCollectionFeature *shapeCollectionFeature = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[polygonFeature, polylineFeature, multiPolygonFeature, multiPolylineFeature, pointCollectionFeature, pointFeature]]; + + MGLShapeCollectionFeature *shapeCollectionFeature_1 = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[polygonFeature, polylineFeature, multiPolygonFeature, multiPolylineFeature, pointCollectionFeature, pointFeature, shapeCollectionFeature]]; + + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:shapeCollectionFeature_1 options:nil]; + + MGLShapeCollectionFeature *shape = (MGLShapeCollectionFeature *)source.shape; + + XCTAssertNotNil(shape); + XCTAssert(shape.shapes.count == 7, @"Shape collection should contain 7 shapes"); +} + +@end diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index ae55951fd9..f2151988b9 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -1,7 +1,7 @@ #import "MGLMapView.h" #import "MGLStyle_Private.h" -#import "MGLGeoJSONSource.h" +#import "MGLShapeSource.h" #import "MGLRasterSource.h" #import "MGLVectorSource.h" @@ -121,9 +121,9 @@ } - (void)testAddingSourcesTwice { - MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; - [self.style addSource:geoJSONSource]; - XCTAssertThrowsSpecificNamed([self.style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException"); + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; + [self.style addSource:shapeSource]; + XCTAssertThrowsSpecificNamed([self.style addSource:shapeSource], NSException, @"MGLRedundantSourceException"); MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42]; [self.style addSource:rasterSource]; @@ -143,7 +143,7 @@ } - (void)testAddingLayersTwice { - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"]; [self.style addLayer:backgroundLayer]; diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index 7a266a495f..2d2792fdc0 100644 --- a/platform/darwin/test/MGLStyleValueTests.swift +++ b/platform/darwin/test/MGLStyleValueTests.swift @@ -5,8 +5,8 @@ import Mapbox extension MGLStyleValueTests { func testConstantValues() { - let geoJSONSource = MGLGeoJSONSource(identifier: "test", shape: nil, options: nil) - let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) + let shapeSource = MGLShapeSource(identifier: "test", shape: nil, options: nil) + let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: shapeSource) // Boolean symbolStyleLayer.iconAllowOverlap = MGLStyleConstantValue(rawValue: true) @@ -22,7 +22,7 @@ extension MGLStyleValueTests { } func testFunctions() { - let geoJSONSource = MGLGeoJSONSource(identifier: "test", shape: nil, options: nil) + let geoJSONSource = MGLShapeSource(identifier: "test", shape: nil, options: nil) let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) // Boolean diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index 13019ffdfc..fc8d848a0a 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -11,7 +11,7 @@ - (void)testSymbolLayer { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.mapView.style addSource:source]; MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index de1a337e42..2858753e83 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -54,7 +54,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingWater = 0, MBXSettingsRuntimeStylingRoads, MBXSettingsRuntimeStylingRaster, - MBXSettingsRuntimeStylingGeoJSON, + MBXSettingsRuntimeStylingShape, MBXSettingsRuntimeStylingSymbols, MBXSettingsRuntimeStylingBuildings, MBXSettingsRuntimeStylingFerry, @@ -65,9 +65,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingStyleQuery, MBXSettingsRuntimeStylingFeatureSource, MBXSettingsRuntimeStylingPointCollection, - MBXSettingsRuntimeStylingUpdateGeoJSONSourceData, - MBXSettingsRuntimeStylingUpdateGeoJSONSourceURL, - MBXSettingsRuntimeStylingUpdateGeoJSONSourceFeatures, + MBXSettingsRuntimeStylingUpdateShapeSourceData, + MBXSettingsRuntimeStylingUpdateShapeSourceURL, + MBXSettingsRuntimeStylingUpdateShapeSourceFeatures, MBXSettingsRuntimeStylingVectorSource, MBXSettingsRuntimeStylingRasterSource, MBXSettingsRuntimeStylingCountryLabels, @@ -316,7 +316,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Style Water With Function", @"Style Roads With Function", @"Add Raster & Apply Function", - @"Add GeoJSON & Apply Fill", + @"Add Shapes & Apply Fill", @"Style Symbol Color", @"Style Building Fill Color", @"Style Ferry Line Color", @@ -324,12 +324,12 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Style Fill With Filter", @"Style Lines With Filter", @"Style Fill With Numeric Filter", - @"Style Query For GeoJSON", + @"Query and Style Features", @"Style Feature", @"Style Dynamic Point Collection", - @"Update GeoJSON Source: Data", - @"Update GeoJSON Source: URL", - @"Update GeoJSON Source: Features", + @"Update Shape Source: Data", + @"Update Shape Source: URL", + @"Update Shape Source: Features", @"Style Vector Source", @"Style Raster Source", [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], @@ -441,8 +441,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsRuntimeStylingRaster: [self styleRasterLayer]; break; - case MBXSettingsRuntimeStylingGeoJSON: - [self styleGeoJSONSource]; + case MBXSettingsRuntimeStylingShape: + [self styleShapeSource]; break; case MBXSettingsRuntimeStylingSymbols: [self styleSymbolLayer]; @@ -474,14 +474,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsRuntimeStylingPointCollection: [self styleDynamicPointCollection]; break; - case MBXSettingsRuntimeStylingUpdateGeoJSONSourceURL: - [self updateGeoJSONSourceURL]; + case MBXSettingsRuntimeStylingUpdateShapeSourceURL: + [self updateShapeSourceURL]; break; - case MBXSettingsRuntimeStylingUpdateGeoJSONSourceData: - [self updateGeoJSONSourceData]; + case MBXSettingsRuntimeStylingUpdateShapeSourceData: + [self updateShapeSourceData]; break; - case MBXSettingsRuntimeStylingUpdateGeoJSONSourceFeatures: - [self updateGeoJSONSourceFeatures]; + case MBXSettingsRuntimeStylingUpdateShapeSourceFeatures: + [self updateShapeSourceFeatures]; break; case MBXSettingsRuntimeStylingVectorSource: [self styleVectorSource]; @@ -764,11 +764,11 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addLayer:rasterLayer]; } -- (void)styleGeoJSONSource +- (void)styleShapeSource { NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"ams" URL:geoJSONURL options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"ams" URL:geoJSONURL options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source]; @@ -897,7 +897,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { dispatch_async(dispatch_get_main_queue(), ^{ MGLShapeCollectionFeature *features = [MGLShapeCollectionFeature shapeCollectionWithShapes:visibleFeatures]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:querySourceID shape:features options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:querySourceID shape:features options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:queryLayerID source:source]; @@ -913,44 +913,44 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { self.mapView.centerCoordinate = CLLocationCoordinate2DMake(51.068585180672635, -114.06074523925781); CLLocationCoordinate2D leafCoords[] = { - CLLocationCoordinate2DMake(50.9683733218221,-114.07035827636719), - CLLocationCoordinate2DMake(51.02325750523972,-114.06967163085938), - CLLocationCoordinate2DMake(51.009434536947786,-114.14245605468749), - CLLocationCoordinate2DMake(51.030599281184124,-114.12597656249999), - CLLocationCoordinate2DMake(51.060386316691016,-114.21043395996094), - CLLocationCoordinate2DMake(51.063838646941576,-114.17816162109375), - CLLocationCoordinate2DMake(51.08152779888779,-114.19876098632812), - CLLocationCoordinate2DMake(51.08066507029602,-114.16854858398438), - CLLocationCoordinate2DMake(51.09662294502995,-114.17472839355469), - CLLocationCoordinate2DMake(51.07764539352731,-114.114990234375), - CLLocationCoordinate2DMake(51.13670896949613,-114.12391662597656), - CLLocationCoordinate2DMake(51.13369295212583,-114.09576416015624), - CLLocationCoordinate2DMake(51.17546878815025,-114.07585144042969), - CLLocationCoordinate2DMake(51.140155605265896,-114.04632568359375), - CLLocationCoordinate2DMake(51.15049396880196,-114.01542663574219), - CLLocationCoordinate2DMake(51.088860342359965,-114.00924682617186), - CLLocationCoordinate2DMake(51.12205789681453,-113.94813537597656), - CLLocationCoordinate2DMake(51.106539930027225,-113.94882202148438), - CLLocationCoordinate2DMake(51.117747873223344,-113.92616271972656), - CLLocationCoordinate2DMake(51.10093493903458,-113.92616271972656), - CLLocationCoordinate2DMake(51.10697105503078,-113.90625), - CLLocationCoordinate2DMake(51.09144802136697,-113.9117431640625), - CLLocationCoordinate2DMake(51.04916446529361,-113.97010803222655), - CLLocationCoordinate2DMake(51.045279344649146,-113.9398956298828), - CLLocationCoordinate2DMake(51.022825599852496,-114.06211853027344), - CLLocationCoordinate2DMake(51.045279344649146,-113.9398956298828), - CLLocationCoordinate2DMake(51.022825599852496,-114.06211853027344), - CLLocationCoordinate2DMake(51.022825599852496,-114.06280517578125), - CLLocationCoordinate2DMake(50.968805734317804,-114.06280517578125), - CLLocationCoordinate2DMake(50.9683733218221,-114.07035827636719), + {50.9683733218221,-114.07035827636719}, + {51.02325750523972,-114.06967163085938}, + {51.009434536947786,-114.14245605468749}, + {51.030599281184124,-114.12597656249999}, + {51.060386316691016,-114.21043395996094}, + {51.063838646941576,-114.17816162109375}, + {51.08152779888779,-114.19876098632812}, + {51.08066507029602,-114.16854858398438}, + {51.09662294502995,-114.17472839355469}, + {51.07764539352731,-114.114990234375}, + {51.13670896949613,-114.12391662597656}, + {51.13369295212583,-114.09576416015624}, + {51.17546878815025,-114.07585144042969}, + {51.140155605265896,-114.04632568359375}, + {51.15049396880196,-114.01542663574219}, + {51.088860342359965,-114.00924682617186}, + {51.12205789681453,-113.94813537597656}, + {51.106539930027225,-113.94882202148438}, + {51.117747873223344,-113.92616271972656}, + {51.10093493903458,-113.92616271972656}, + {51.10697105503078,-113.90625}, + {51.09144802136697,-113.9117431640625}, + {51.04916446529361,-113.97010803222655}, + {51.045279344649146,-113.9398956298828}, + {51.022825599852496,-114.06211853027344}, + {51.045279344649146,-113.9398956298828}, + {51.022825599852496,-114.06211853027344}, + {51.022825599852496,-114.06280517578125}, + {50.968805734317804,-114.06280517578125}, + {50.9683733218221,-114.07035827636719}, }; NSUInteger coordsCount = sizeof(leafCoords) / sizeof(leafCoords[0]); MGLPolygonFeature *feature = [MGLPolygonFeature polygonWithCoordinates:leafCoords count:coordsCount]; feature.identifier = @"leaf-feature"; feature.attributes = @{@"color": @"red"}; - - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"leaf-source" shape:feature options:nil]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"leaf-source" shape:feature options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-fill-layer" source:source]; @@ -960,14 +960,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addLayer:layer]; } -- (void)updateGeoJSONSourceData +- (void)updateShapeSourceData { [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(40.329795743702064, -107.75390625) zoomLevel:11 animated:NO]; NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}"; NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"mutable-data-source-id" geoJSONData:data options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-id" geoJSONData:data options:nil]; [self.mapView.style addSource:source]; MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-id" source:source]; @@ -981,13 +981,13 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { }); } -- (void)updateGeoJSONSourceURL +- (void)updateShapeSourceURL { [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(48.668731, -122.857151) zoomLevel:11 animated:NO]; NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"polyline" ofType:@"geojson"]; NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"mutable-data-source-url-id" URL:geoJSONURL options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-url-id" URL:geoJSONURL options:nil]; [self.mapView.style addSource:source]; MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-url-id" source:source]; @@ -1003,7 +1003,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { }); } -- (void)updateGeoJSONSourceFeatures +- (void)updateShapeSourceFeatures { [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(-41.1520, 288.6592) zoomLevel:10 animated:NO]; @@ -1026,9 +1026,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLPolygonFeature *smallBoxFeature = [MGLPolygonFeature polygonWithCoordinates:smallBox count:sizeof(smallBox)/sizeof(smallBox[0])]; MGLPolygonFeature *largeBoxFeature = [MGLPolygonFeature polygonWithCoordinates:largeBox count:sizeof(largeBox)/sizeof(largeBox[0])]; - MGLShapeCollectionFeature *collection = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[smallBoxFeature]]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"mutable-data-source-features-id" - shape:collection + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-features-id" + shape:smallBoxFeature options:nil]; [self.mapView.style addSource:source]; @@ -1052,7 +1051,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { {36.99508088541243, -109.04007911682129}, }; MGLPointCollectionFeature *feature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:4]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"wiggle-source" shape:feature options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"wiggle-source" shape:feature options:nil]; [self.mapView.style addSource:source]; MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"wiggle-layer" source:source]; @@ -1119,7 +1118,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLPolylineFeature *routeLine = [MGLPolylineFeature polylineWithCoordinates:coords count:count]; - MGLGeoJSONSource *routeSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"style-route-source" shape:routeLine options:nil]; + MGLShapeSource *routeSource = [[MGLShapeSource alloc] initWithIdentifier:@"style-route-source" shape:routeLine options:nil]; [self.mapView.style addSource:routeSource]; MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 30ed5556b2..8c69d7105e 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -76,10 +76,10 @@ 354B839C1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 354B839B1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m */; }; 35599DED1D46F14E0048254D /* MGLStyleValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */; }; 35599DEE1D46F14E0048254D /* MGLStyleValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */; }; - 3566C7661D4A77BA008152BC /* MGLGeoJSONSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C7641D4A77BA008152BC /* MGLGeoJSONSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3566C7671D4A77BA008152BC /* MGLGeoJSONSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C7641D4A77BA008152BC /* MGLGeoJSONSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3566C7681D4A77BA008152BC /* MGLGeoJSONSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3566C7651D4A77BA008152BC /* MGLGeoJSONSource.mm */; }; - 3566C7691D4A77BA008152BC /* MGLGeoJSONSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3566C7651D4A77BA008152BC /* MGLGeoJSONSource.mm */; }; + 3566C7661D4A77BA008152BC /* MGLShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C7641D4A77BA008152BC /* MGLShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3566C7671D4A77BA008152BC /* MGLShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C7641D4A77BA008152BC /* MGLShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3566C7681D4A77BA008152BC /* MGLShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3566C7651D4A77BA008152BC /* MGLShapeSource.mm */; }; + 3566C7691D4A77BA008152BC /* MGLShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3566C7651D4A77BA008152BC /* MGLShapeSource.mm */; }; 3566C76C1D4A8DFA008152BC /* MGLRasterSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3566C76D1D4A8DFA008152BC /* MGLRasterSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3566C76E1D4A8DFA008152BC /* MGLRasterSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3566C76B1D4A8DFA008152BC /* MGLRasterSource.mm */; }; @@ -155,12 +155,12 @@ 408AA8581DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */; }; 408AA8591DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */; }; 40CF6DBB1DAC3C6600A4D18B /* MGLShape_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40CF6DBA1DAC3C1800A4D18B /* MGLShape_Private.h */; }; - 40CFA6511D7875BB008103BD /* MGLGeoJSONSourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 40CFA6501D787579008103BD /* MGLGeoJSONSourceTests.mm */; }; + 40CFA6511D7875BB008103BD /* MGLShapeSourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 40CFA6501D787579008103BD /* MGLShapeSourceTests.mm */; }; 40EDA1C01CFE0E0200D9EA68 /* MGLAnnotationContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */; }; 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; }; 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; }; - 40F887701D7A1E58008ECB67 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */; }; - 40F887711D7A1E59008ECB67 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */; }; + 40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; }; + 40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; }; 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; }; 554180421D2E97DE00012372 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554180411D2E97DE00012372 /* OpenGLES.framework */; }; 55D8C9961D0F18CE00F42F10 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */; }; @@ -538,8 +538,8 @@ 354B839A1D2E9B48005D9406 /* MBXUserLocationAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXUserLocationAnnotationView.h; sourceTree = ""; }; 354B839B1D2E9B48005D9406 /* MBXUserLocationAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXUserLocationAnnotationView.m; sourceTree = ""; }; 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLStyleValue.mm; sourceTree = ""; }; - 3566C7641D4A77BA008152BC /* MGLGeoJSONSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSource.h; sourceTree = ""; }; - 3566C7651D4A77BA008152BC /* MGLGeoJSONSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLGeoJSONSource.mm; sourceTree = ""; }; + 3566C7641D4A77BA008152BC /* MGLShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeSource.h; sourceTree = ""; }; + 3566C7651D4A77BA008152BC /* MGLShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLShapeSource.mm; sourceTree = ""; }; 3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLRasterSource.h; sourceTree = ""; }; 3566C76B1D4A8DFA008152BC /* MGLRasterSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLRasterSource.mm; sourceTree = ""; }; 3566C7701D4A9198008152BC /* MGLSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLSource_Private.h; sourceTree = ""; }; @@ -593,10 +593,10 @@ 408AA8551DAEDA0800022900 /* NSDictionary+MGLAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+MGLAdditions.h"; sourceTree = ""; }; 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSDictionary+MGLAdditions.mm"; sourceTree = ""; }; 40CF6DBA1DAC3C1800A4D18B /* MGLShape_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLShape_Private.h; sourceTree = ""; }; - 40CFA6501D787579008103BD /* MGLGeoJSONSourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLGeoJSONSourceTests.mm; path = ../../darwin/test/MGLGeoJSONSourceTests.mm; sourceTree = ""; }; + 40CFA6501D787579008103BD /* MGLShapeSourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLShapeSourceTests.mm; path = ../../darwin/test/MGLShapeSourceTests.mm; sourceTree = ""; }; 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView.h; sourceTree = ""; }; 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAnnotationContainerView.m; sourceTree = ""; }; - 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSource_Private.h; sourceTree = ""; }; + 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLShapeSource_Private.h; sourceTree = ""; }; 40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = ""; }; 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAnnotationView.m; sourceTree = ""; }; 554180411D2E97DE00012372 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; @@ -848,9 +848,9 @@ 35136D4B1D4277FC00C20EFD /* MGLSource.mm */, 350098B91D480108004B2AF0 /* MGLVectorSource.h */, 350098BA1D480108004B2AF0 /* MGLVectorSource.mm */, - 3566C7641D4A77BA008152BC /* MGLGeoJSONSource.h */, - 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */, - 3566C7651D4A77BA008152BC /* MGLGeoJSONSource.mm */, + 3566C7641D4A77BA008152BC /* MGLShapeSource.h */, + 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */, + 3566C7651D4A77BA008152BC /* MGLShapeSource.mm */, 3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */, 3566C76B1D4A8DFA008152BC /* MGLRasterSource.mm */, 404C26E01D89B877000AA13D /* MGLTileSet.h */, @@ -962,7 +962,7 @@ 40CFA64E1D78754A008103BD /* Sources */ = { isa = PBXGroup; children = ( - 40CFA6501D787579008103BD /* MGLGeoJSONSourceTests.mm */, + 40CFA6501D787579008103BD /* MGLShapeSourceTests.mm */, 4085AF081D933DEA00F11B22 /* MGLTileSetTests.mm */, ); name = Sources; @@ -1442,7 +1442,7 @@ 7E016D7E1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */, 35D13AB71D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */, DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */, - 40F887701D7A1E58008ECB67 /* MGLGeoJSONSource_Private.h in Headers */, + 40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */, 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, @@ -1485,7 +1485,7 @@ DAD165781CF4CDFF001FF4B9 /* MGLShapeCollection.h in Headers */, DAED38631D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */, DA88481E1CBAFA6200AB86E3 /* MGLMultiPoint_Private.h in Headers */, - 3566C7661D4A77BA008152BC /* MGLGeoJSONSource.h in Headers */, + 3566C7661D4A77BA008152BC /* MGLShapeSource.h in Headers */, 35CE61821D4165D9004F2359 /* UIColor+MGLAdditions.h in Headers */, 35B82BF81D6C5F8400B1B721 /* NSPredicate+MGLAdditions.h in Headers */, DA35A29E1CC9E94C00E826B2 /* MGLCoordinateFormatter.h in Headers */, @@ -1548,7 +1548,7 @@ DABFB8641CBE99E500D62B32 /* MGLOfflineStorage.h in Headers */, DAD165791CF4CDFF001FF4B9 /* MGLShapeCollection.h in Headers */, 4049C29E1DB6CD6C00B3F799 /* MGLPointCollection.h in Headers */, - 3566C7671D4A77BA008152BC /* MGLGeoJSONSource.h in Headers */, + 3566C7671D4A77BA008152BC /* MGLShapeSource.h in Headers */, DA35A29F1CC9E94C00E826B2 /* MGLCoordinateFormatter.h in Headers */, 404C26E31D89B877000AA13D /* MGLTileSet.h in Headers */, DABFB8611CBE99E500D62B32 /* MGLMultiPoint.h in Headers */, @@ -1585,7 +1585,7 @@ 353933F31D3FB753003F57D7 /* MGLCircleStyleLayer.h in Headers */, 3538AA1E1D542239008EC33D /* MGLForegroundStyleLayer.h in Headers */, 30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */, - 40F887711D7A1E59008ECB67 /* MGLGeoJSONSource_Private.h in Headers */, + 40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */, DABFB8631CBE99E500D62B32 /* MGLOfflineRegion.h in Headers */, DA35A2B21CCA141D00E826B2 /* MGLCompassDirectionFormatter.h in Headers */, DABFB8731CBE9A9900D62B32 /* Mapbox.h in Headers */, @@ -1929,7 +1929,7 @@ 357579871D502AFE000B822E /* MGLLineStyleLayerTests.m in Sources */, 357579891D502B06000B822E /* MGLCircleStyleLayerTests.m in Sources */, DA2207BF1DC0805F0002F84D /* MGLStyleValueTests.swift in Sources */, - 40CFA6511D7875BB008103BD /* MGLGeoJSONSourceTests.mm in Sources */, + 40CFA6511D7875BB008103BD /* MGLShapeSourceTests.mm in Sources */, DA35A2C51CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m in Sources */, 35B8E08C1D6C8B5100E768D2 /* MGLFilterTests.mm in Sources */, DD58A4C61D822BD000E1F038 /* MGLExpressionTests.mm in Sources */, @@ -1961,7 +1961,7 @@ 35136D3C1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DD1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, - 3566C7681D4A77BA008152BC /* MGLGeoJSONSource.mm in Sources */, + 3566C7681D4A77BA008152BC /* MGLShapeSource.mm in Sources */, 400533021DB0862B0069F638 /* NSArray+MGLAdditions.mm in Sources */, 35136D421D42274500C20EFD /* MGLRasterStyleLayer.mm in Sources */, 3538AA1F1D542239008EC33D /* MGLForegroundStyleLayer.m in Sources */, @@ -2036,7 +2036,7 @@ 35136D3D1D42272500C20EFD /* MGLCircleStyleLayer.mm in Sources */, 350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */, DA6408DE1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */, - 3566C7691D4A77BA008152BC /* MGLGeoJSONSource.mm in Sources */, + 3566C7691D4A77BA008152BC /* MGLShapeSource.mm in Sources */, 400533031DB086490069F638 /* NSArray+MGLAdditions.mm in Sources */, 35136D431D42274500C20EFD /* MGLRasterStyleLayer.mm in Sources */, 3538AA201D542239008EC33D /* MGLForegroundStyleLayer.m in Sources */, diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml index c19d9e3883..4b60961c61 100644 --- a/platform/ios/jazzy.yml +++ b/platform/ios/jazzy.yml @@ -66,7 +66,7 @@ custom_categories: - name: Data Sources children: - MGLSource - - MGLGeoJSONSource + - MGLShapeSource - MGLRasterSource - MGLTileSet - MGLVectorSource diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index 64fc2be0d4..d401ca020c 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -44,7 +44,7 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLOpenGLStyleLayer.h" #import "MGLSource.h" #import "MGLVectorSource.h" -#import "MGLGeoJSONSource.h" +#import "MGLShapeSource.h" #import "MGLRasterSource.h" #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index c742440e84..2c31610779 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -691,7 +691,7 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id