diff options
Diffstat (limited to 'platform/darwin/src')
41 files changed, 1197 insertions, 929 deletions
diff --git a/platform/darwin/src/MGLAttributionInfo.h b/platform/darwin/src/MGLAttributionInfo.h index 84552722c9..7395e3f346 100644 --- a/platform/darwin/src/MGLAttributionInfo.h +++ b/platform/darwin/src/MGLAttributionInfo.h @@ -13,45 +13,49 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLAttributionInfo : NSObject /** - Parses and returns the attribution infos contained in the given HTML source - code string. + Returns an initialized attribution info object with the given title and URL. - @param htmlString The HTML source code to parse. - @param fontSize The default text size in points. - @param linkColor The default link color. + @param title The attribution statement’s title. + @param URL A URL to more information about the entity named in the attribution. + @return An initialized attribution info object. */ -+ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor; - - (instancetype)initWithTitle:(NSAttributedString *)title URL:(nullable NSURL *)URL; +/** + The attribution statement’s attributed title text. + */ @property (nonatomic) NSAttributedString *title; -@property (nonatomic, nullable) NSURL *URL; -@property (nonatomic, getter=isFeedbackLink) BOOL feedbackLink; - -- (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel; -@end - -@interface NSMutableArray (MGLAttributionInfoAdditions) +/** + The URL to more information about the entity named in the attribution. + + If this property is set, the attribution statement should be displayed as a + hyperlink or action button. Otherwise, if it is `nil`, the attribution + statement should be displayed as plain text. + */ +@property (nonatomic, nullable) NSURL *URL; /** - Adds the given attribution info object to the receiver as long as it isn’t - redundant to any object already in the receiver. Any existing object that is - redundant to the given object is replaced by the given object. + A Boolean value indicating whether the attribution statement is a shortcut to a + feedback tool. - @param info The info object to add to the receiver. - @return True if the given info object was added to the receiver. + If this property is set, the statement should be treated as a way for the user + to provide feedback rather than an attribution statement. */ -- (void)growArrayByAddingAttributionInfo:(MGLAttributionInfo *)info; +@property (nonatomic, getter=isFeedbackLink) BOOL feedbackLink; /** - Adds each of the given attribution info objects to the receiver as long as it - isn’t redundant to any object already in the receiver. Any existing object that - is redundant to the given object is replaced by the given object. + Returns a copy of the `URL` property modified to account for the given center + coordinate and zoom level. - @param infos An array of info objects to add to the receiver. + @param centerCoordinate The map’s center coordinate. + @param zoomLevel The map’s zoom level. See `MGLMapView`’s `zoomLevel` property + for more information. + @return A modified URL containing a fragment that points to the specified + viewport. If the `feedbackLink` property is set to `NO`, this method returns + `nil`. */ -- (void)growArrayByAddingAttributionInfosFromArray:(NS_ARRAY_OF(MGLAttributionInfo *) *)infos; +- (nullable NSURL *)feedbackURLAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel; @end diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm index 2719aef7ca..cf7b3cb22f 100644 --- a/platform/darwin/src/MGLAttributionInfo.mm +++ b/platform/darwin/src/MGLAttributionInfo.mm @@ -1,4 +1,4 @@ -#import "MGLAttributionInfo.h" +#import "MGLAttributionInfo_Private.h" #if TARGET_OS_IPHONE #import <UIKit/UIKit.h> @@ -7,13 +7,18 @@ #endif #import "MGLMapCamera.h" +#import "NSArray+MGLAdditions.h" #import "NSString+MGLAdditions.h" #include <string> @implementation MGLAttributionInfo -+ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor { ++ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(nullable NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor { + if (!htmlString) { + return @[]; + } + NSDictionary *options = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding), @@ -84,6 +89,18 @@ return infos; } ++ (NSAttributedString *)attributedStringForAttributionInfos:(NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfos { + NSMutableArray *titles = [NSMutableArray arrayWithCapacity:attributionInfos.count]; + for (MGLAttributionInfo *info in attributionInfos) { + NSMutableAttributedString *title = info.title.mutableCopy; + if (info.URL) { + [title addAttribute:NSLinkAttributeName value:info.URL range:title.mgl_wholeRange]; + } + [titles addObject:title]; + } + return [titles mgl_attributedComponentsJoinedByString:@" "]; +} + - (instancetype)initWithTitle:(NSAttributedString *)title URL:(NSURL *)URL { if (self = [super init]) { _title = title; diff --git a/platform/darwin/src/MGLAttributionInfo_Private.h b/platform/darwin/src/MGLAttributionInfo_Private.h new file mode 100644 index 0000000000..c9a428b571 --- /dev/null +++ b/platform/darwin/src/MGLAttributionInfo_Private.h @@ -0,0 +1,48 @@ +#import <Foundation/Foundation.h> +#import <CoreGraphics/CoreGraphics.h> +#import <CoreLocation/CoreLocation.h> + +#import "MGLAttributionInfo.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLAttributionInfo (Private) + +/** + Parses and returns the attribution infos contained in the given HTML source + code string. + + @param htmlString The HTML source code to parse. + @param fontSize The default text size in points. + @param linkColor The default link color. + */ ++ (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosFromHTMLString:(nullable NSString *)htmlString fontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor; + ++ (NSAttributedString *)attributedStringForAttributionInfos:(NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfos; + +@end + +@interface NSMutableArray (MGLAttributionInfoAdditions) + +/** + Adds the given attribution info object to the receiver as long as it isn’t + redundant to any object already in the receiver. Any existing object that is + redundant to the given object is replaced by the given object. + + @param info The info object to add to the receiver. + @return True if the given info object was added to the receiver. + */ +- (void)growArrayByAddingAttributionInfo:(MGLAttributionInfo *)info; + +/** + Adds each of the given attribution info objects to the receiver as long as it + isn’t redundant to any object already in the receiver. Any existing object that + is redundant to the given object is replaced by the given object. + + @param infos An array of info objects to add to the receiver. + */ +- (void)growArrayByAddingAttributionInfosFromArray:(NS_ARRAY_OF(MGLAttributionInfo *) *)infos; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 0ac25c39fe..6a76f6072e 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -26,11 +26,21 @@ if (self = [super initWithIdentifier:identifier]) { auto layer = std::make_unique<mbgl::style::BackgroundLayer>(identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } +- (mbgl::style::BackgroundLayer *)rawLayer +{ + return (mbgl::style::BackgroundLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::BackgroundLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -52,7 +62,7 @@ - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -67,7 +77,7 @@ removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::BackgroundLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes @@ -76,13 +86,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(backgroundColor); - _rawLayer->setBackgroundColor(mbglValue); + self.rawLayer->setBackgroundColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)backgroundColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getBackgroundColor() ?: _rawLayer->getDefaultBackgroundColor(); + auto propertyValue = self.rawLayer->getBackgroundColor() ?: self.rawLayer->getDefaultBackgroundColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -90,13 +100,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(backgroundOpacity); - _rawLayer->setBackgroundOpacity(mbglValue); + self.rawLayer->setBackgroundOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)backgroundOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getBackgroundOpacity() ?: _rawLayer->getDefaultBackgroundOpacity(); + auto propertyValue = self.rawLayer->getBackgroundOpacity() ?: self.rawLayer->getDefaultBackgroundOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -104,13 +114,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(backgroundPattern); - _rawLayer->setBackgroundPattern(mbglValue); + self.rawLayer->setBackgroundPattern(mbglValue); } - (MGLStyleValue<NSString *> *)backgroundPattern { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern(); + auto propertyValue = self.rawLayer->getBackgroundPattern() ?: self.rawLayer->getDefaultBackgroundPattern(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 90026490a6..0cd84453a2 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -39,15 +39,26 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::CircleLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + +- (mbgl::style::CircleLayer *)rawLayer +{ + return (mbgl::style::CircleLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::CircleLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); - auto layerID = _rawLayer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } @@ -55,22 +66,23 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - _rawLayer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -92,7 +104,7 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -107,7 +119,7 @@ namespace mbgl { removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::CircleLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes @@ -116,13 +128,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleBlur); - _rawLayer->setCircleBlur(mbglValue); + self.rawLayer->setCircleBlur(mbglValue); } - (MGLStyleValue<NSNumber *> *)circleBlur { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur(); + auto propertyValue = self.rawLayer->getCircleBlur() ?: self.rawLayer->getDefaultCircleBlur(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -130,13 +142,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(circleColor); - _rawLayer->setCircleColor(mbglValue); + self.rawLayer->setCircleColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)circleColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleColor() ?: _rawLayer->getDefaultCircleColor(); + auto propertyValue = self.rawLayer->getCircleColor() ?: self.rawLayer->getDefaultCircleColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -144,13 +156,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleOpacity); - _rawLayer->setCircleOpacity(mbglValue); + self.rawLayer->setCircleOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)circleOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleOpacity() ?: _rawLayer->getDefaultCircleOpacity(); + auto propertyValue = self.rawLayer->getCircleOpacity() ?: self.rawLayer->getDefaultCircleOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -158,13 +170,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumPropertyValue(circlePitchScale); - _rawLayer->setCirclePitchScale(mbglValue); + self.rawLayer->setCirclePitchScale(mbglValue); } - (MGLStyleValue<NSValue *> *)circlePitchScale { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); + auto propertyValue = self.rawLayer->getCirclePitchScale() ?: self.rawLayer->getDefaultCirclePitchScale(); return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumStyleValue(propertyValue); } @@ -172,13 +184,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleRadius); - _rawLayer->setCircleRadius(mbglValue); + self.rawLayer->setCircleRadius(mbglValue); } - (MGLStyleValue<NSNumber *> *)circleRadius { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius(); + auto propertyValue = self.rawLayer->getCircleRadius() ?: self.rawLayer->getDefaultCircleRadius(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -186,13 +198,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(circleTranslate); - _rawLayer->setCircleTranslate(mbglValue); + self.rawLayer->setCircleTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)circleTranslate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleTranslate() ?: _rawLayer->getDefaultCircleTranslate(); + auto propertyValue = self.rawLayer->getCircleTranslate() ?: self.rawLayer->getDefaultCircleTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -200,13 +212,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslateAnchor>().toEnumPropertyValue(circleTranslateAnchor); - _rawLayer->setCircleTranslateAnchor(mbglValue); + self.rawLayer->setCircleTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)circleTranslateAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getCircleTranslateAnchor() ?: _rawLayer->getDefaultCircleTranslateAnchor(); + auto propertyValue = self.rawLayer->getCircleTranslateAnchor() ?: self.rawLayer->getDefaultCircleTranslateAnchor(); return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslateAnchor>().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm index ba2ea6e605..c1e0c312a0 100644 --- a/platform/darwin/src/MGLFeature.mm +++ b/platform/darwin/src/MGLFeature.mm @@ -1,5 +1,4 @@ #import "MGLFeature_Private.h" -#import "MGLShapeCollectionFeature_Private.h" #import "MGLPointAnnotation.h" #import "MGLPolyline.h" @@ -18,7 +17,7 @@ #import <mbgl/style/conversion/geojson.hpp> #import <mapbox/geometry/feature.hpp> -@interface MGLPointFeature () <MGLFeaturePrivate> +@interface MGLPointFeature () @end @implementation MGLPointFeature @@ -34,13 +33,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLPolylineFeature () <MGLFeaturePrivate> +@interface MGLPolylineFeature () @end @implementation MGLPolylineFeature @@ -56,13 +55,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLPolygonFeature () <MGLFeaturePrivate> +@interface MGLPolygonFeature () @end @implementation MGLPolygonFeature @@ -78,13 +77,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLPointCollectionFeature () <MGLFeaturePrivate> +@interface MGLPointCollectionFeature () @end @implementation MGLPointCollectionFeature @@ -100,13 +99,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLMultiPolylineFeature () <MGLFeaturePrivate> +@interface MGLMultiPolylineFeature () @end @implementation MGLMultiPolylineFeature @@ -122,13 +121,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLMultiPolygonFeature () <MGLFeaturePrivate> +@interface MGLMultiPolygonFeature () @end @implementation MGLMultiPolygonFeature @@ -144,13 +143,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { +- (mbgl::GeoJSON)geoJSONObject { return mbglFeature({[self geometryObject]}, identifier, self.attributes); } @end -@interface MGLShapeCollectionFeature () <MGLFeaturePrivate> +@interface MGLShapeCollectionFeature () @end @implementation MGLShapeCollectionFeature @@ -172,17 +171,13 @@ return NSDictionaryFeatureForGeometry([super geoJSONDictionary], self.attributes, self.identifier); } -- (mbgl::Feature)mbglFeature { - [NSException raise:@"Method unavailable" format:@"%s is not available on %@.", __PRETTY_FUNCTION__, [self class]]; - mbgl::Polygon<double> geometry; - return mbgl::Feature{geometry}; -} - -- (mbgl::FeatureCollection)mbglFeatureCollection { +- (mbgl::GeoJSON)geoJSONObject { mbgl::FeatureCollection featureCollection; featureCollection.reserve(self.shapes.count); - for (id <MGLFeaturePrivate> feature in self.shapes) { - featureCollection.push_back([feature mbglFeature]); + for (MGLShape <MGLFeature> *feature in self.shapes) { + auto geoJSONObject = feature.geoJSONObject; + NSAssert(geoJSONObject.is<mbgl::Feature>(), @"Feature collection must only contain features."); + featureCollection.push_back(geoJSONObject.get<mbgl::Feature>()); } return featureCollection; } @@ -196,27 +191,27 @@ template <typename T> class GeometryEvaluator { public: - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Point<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::Point<T> &geometry) const { MGLPointFeature *feature = [[MGLPointFeature alloc] init]; feature.coordinate = toLocationCoordinate2D(geometry); return feature; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::LineString<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::LineString<T> &geometry) const { std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(geometry); return [MGLPolylineFeature polylineWithCoordinates:&coordinates[0] count:coordinates.size()]; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Polygon<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::Polygon<T> &geometry) const { return toShape<MGLPolygonFeature>(geometry); } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiPoint<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::MultiPoint<T> &geometry) const { std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(geometry); return [[MGLPointCollectionFeature alloc] initWithCoordinates:&coordinates[0] count:coordinates.size()]; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiLineString<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::MultiLineString<T> &geometry) const { NSMutableArray *polylines = [NSMutableArray arrayWithCapacity:geometry.size()]; for (auto &lineString : geometry) { std::vector<CLLocationCoordinate2D> coordinates = toLocationCoordinates2D(lineString); @@ -227,7 +222,7 @@ public: return [MGLMultiPolylineFeature multiPolylineWithPolylines:polylines]; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::MultiPolygon<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::MultiPolygon<T> &geometry) const { NSMutableArray *polygons = [NSMutableArray arrayWithCapacity:geometry.size()]; for (auto &polygon : geometry) { [polygons addObject:toShape(polygon)]; @@ -236,11 +231,11 @@ public: return [MGLMultiPolygonFeature multiPolygonWithPolygons:polygons]; } - MGLShape <MGLFeaturePrivate> * operator()(const mapbox::geometry::geometry_collection<T> &collection) const { + MGLShape <MGLFeature> * operator()(const mapbox::geometry::geometry_collection<T> &collection) const { NSMutableArray *shapes = [NSMutableArray arrayWithCapacity:collection.size()]; for (auto &geometry : collection) { // This is very much like the transformation that happens in MGLFeaturesFromMBGLFeatures(), but these are raw geometries with no associated feature IDs or attributes. - MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<T>::visit(geometry, *this); + MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<T>::visit(geometry, *this); [shapes addObject:shape]; } return [MGLShapeCollectionFeature shapeCollectionWithShapes:shapes]; @@ -280,23 +275,23 @@ private: template <typename T> class GeoJSONEvaluator { public: - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Geometry<T> &geometry) const { + MGLShape <MGLFeature> * operator()(const mbgl::Geometry<T> &geometry) const { GeometryEvaluator<T> evaluator; - MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<T>::visit(geometry, evaluator); + MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<T>::visit(geometry, evaluator); return shape; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::Feature &feature) const { - MGLShape <MGLFeaturePrivate> *shape = (MGLShape <MGLFeaturePrivate> *)MGLFeatureFromMBGLFeature(feature); + MGLShape <MGLFeature> * operator()(const mbgl::Feature &feature) const { + MGLShape <MGLFeature> *shape = (MGLShape <MGLFeature> *)MGLFeatureFromMBGLFeature(feature); return shape; } - MGLShape <MGLFeaturePrivate> * operator()(const mbgl::FeatureCollection &collection) const { + MGLShape <MGLFeature> * operator()(const mbgl::FeatureCollection &collection) const { NSMutableArray *shapes = [NSMutableArray arrayWithCapacity:collection.size()]; for (const auto &feature : collection) { [shapes addObject:MGLFeatureFromMBGLFeature(feature)]; } - return [MGLShapeCollection<MGLFeaturePrivate> shapeCollectionWithShapes:shapes]; + return [MGLShapeCollectionFeature shapeCollectionWithShapes:shapes]; } }; @@ -316,7 +311,7 @@ id <MGLFeature> MGLFeatureFromMBGLFeature(const mbgl::Feature &feature) { attributes[@(pair.first.c_str())] = mbgl::Value::visit(value, evaluator); } GeometryEvaluator<double> evaluator; - MGLShape <MGLFeaturePrivate> *shape = mapbox::geometry::geometry<double>::visit(feature.geometry, evaluator); + MGLShape <MGLFeature> *shape = mapbox::geometry::geometry<double>::visit(feature.geometry, evaluator); if (feature.id) { shape.identifier = mbgl::FeatureIdentifier::visit(*feature.id, ValueEvaluator()); } diff --git a/platform/darwin/src/MGLFeature_Private.h b/platform/darwin/src/MGLFeature_Private.h index a3c7432f4a..97af509893 100644 --- a/platform/darwin/src/MGLFeature_Private.h +++ b/platform/darwin/src/MGLFeature_Private.h @@ -36,10 +36,4 @@ mbgl::Feature mbglFeature(mbgl::Feature feature, id identifier, NSDictionary *at */ NS_DICTIONARY_OF(NSString *, id) *NSDictionaryFeatureForGeometry(NSDictionary *geometry, NSDictionary *attributes, id identifier); -@protocol MGLFeaturePrivate <MGLFeature> - -- (mbgl::Feature)mbglFeature; - -@end - NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index e2808ddc19..47bd84fde7 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -34,15 +34,26 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::FillLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + +- (mbgl::style::FillLayer *)rawLayer +{ + return (mbgl::style::FillLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::FillLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); - auto layerID = _rawLayer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } @@ -50,22 +61,23 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - _rawLayer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -87,7 +99,7 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -102,7 +114,7 @@ namespace mbgl { removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::FillLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes @@ -111,13 +123,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(fillAntialias); - _rawLayer->setFillAntialias(mbglValue); + self.rawLayer->setFillAntialias(mbglValue); } - (MGLStyleValue<NSNumber *> *)fillAntialias { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillAntialias() ?: _rawLayer->getDefaultFillAntialias(); + auto propertyValue = self.rawLayer->getFillAntialias() ?: self.rawLayer->getDefaultFillAntialias(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -125,13 +137,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(fillColor); - _rawLayer->setFillColor(mbglValue); + self.rawLayer->setFillColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)fillColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillColor() ?: _rawLayer->getDefaultFillColor(); + auto propertyValue = self.rawLayer->getFillColor() ?: self.rawLayer->getDefaultFillColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -139,13 +151,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(fillOpacity); - _rawLayer->setFillOpacity(mbglValue); + self.rawLayer->setFillOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)fillOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); + auto propertyValue = self.rawLayer->getFillOpacity() ?: self.rawLayer->getDefaultFillOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -153,13 +165,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(fillOutlineColor); - _rawLayer->setFillOutlineColor(mbglValue); + self.rawLayer->setFillOutlineColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)fillOutlineColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillOutlineColor() ?: _rawLayer->getDefaultFillOutlineColor(); + auto propertyValue = self.rawLayer->getFillOutlineColor() ?: self.rawLayer->getDefaultFillOutlineColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -167,13 +179,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(fillPattern); - _rawLayer->setFillPattern(mbglValue); + self.rawLayer->setFillPattern(mbglValue); } - (MGLStyleValue<NSString *> *)fillPattern { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); + auto propertyValue = self.rawLayer->getFillPattern() ?: self.rawLayer->getDefaultFillPattern(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } @@ -181,13 +193,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(fillTranslate); - _rawLayer->setFillTranslate(mbglValue); + self.rawLayer->setFillTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)fillTranslate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillTranslate() ?: _rawLayer->getDefaultFillTranslate(); + auto propertyValue = self.rawLayer->getFillTranslate() ?: self.rawLayer->getDefaultFillTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -195,13 +207,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslateAnchor>().toEnumPropertyValue(fillTranslateAnchor); - _rawLayer->setFillTranslateAnchor(mbglValue); + self.rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)fillTranslateAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor(); + auto propertyValue = self.rawLayer->getFillTranslateAnchor() ?: self.rawLayer->getDefaultFillTranslateAnchor(); return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslateAnchor>().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 2fc9d9e695..a23441c664 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -46,15 +46,26 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::LineLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + +- (mbgl::style::LineLayer *)rawLayer +{ + return (mbgl::style::LineLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::LineLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); - auto layerID = _rawLayer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } @@ -62,22 +73,23 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - _rawLayer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -99,7 +111,7 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -114,7 +126,7 @@ namespace mbgl { removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::LineLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes @@ -123,13 +135,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumPropertyValue(lineCap); - _rawLayer->setLineCap(mbglValue); + self.rawLayer->setLineCap(mbglValue); } - (MGLStyleValue<NSValue *> *)lineCap { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineCap() ?: _rawLayer->getDefaultLineCap(); + auto propertyValue = self.rawLayer->getLineCap() ?: self.rawLayer->getDefaultLineCap(); return MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumStyleValue(propertyValue); } @@ -137,13 +149,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumPropertyValue(lineJoin); - _rawLayer->setLineJoin(mbglValue); + self.rawLayer->setLineJoin(mbglValue); } - (MGLStyleValue<NSValue *> *)lineJoin { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineJoin() ?: _rawLayer->getDefaultLineJoin(); + auto propertyValue = self.rawLayer->getLineJoin() ?: self.rawLayer->getDefaultLineJoin(); return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumStyleValue(propertyValue); } @@ -151,13 +163,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineMiterLimit); - _rawLayer->setLineMiterLimit(mbglValue); + self.rawLayer->setLineMiterLimit(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineMiterLimit { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineMiterLimit() ?: _rawLayer->getDefaultLineMiterLimit(); + auto propertyValue = self.rawLayer->getLineMiterLimit() ?: self.rawLayer->getDefaultLineMiterLimit(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -165,13 +177,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineRoundLimit); - _rawLayer->setLineRoundLimit(mbglValue); + self.rawLayer->setLineRoundLimit(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineRoundLimit { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineRoundLimit() ?: _rawLayer->getDefaultLineRoundLimit(); + auto propertyValue = self.rawLayer->getLineRoundLimit() ?: self.rawLayer->getDefaultLineRoundLimit(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -181,13 +193,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineBlur); - _rawLayer->setLineBlur(mbglValue); + self.rawLayer->setLineBlur(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineBlur { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineBlur() ?: _rawLayer->getDefaultLineBlur(); + auto propertyValue = self.rawLayer->getLineBlur() ?: self.rawLayer->getDefaultLineBlur(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -195,13 +207,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(lineColor); - _rawLayer->setLineColor(mbglValue); + self.rawLayer->setLineColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)lineColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineColor() ?: _rawLayer->getDefaultLineColor(); + auto propertyValue = self.rawLayer->getLineColor() ?: self.rawLayer->getDefaultLineColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -209,13 +221,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toPropertyValue(lineDashPattern); - _rawLayer->setLineDasharray(mbglValue); + self.rawLayer->setLineDasharray(mbglValue); } - (MGLStyleValue<NSArray<NSNumber *> *> *)lineDashPattern { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineDasharray() ?: _rawLayer->getDefaultLineDasharray(); + auto propertyValue = self.rawLayer->getLineDasharray() ?: self.rawLayer->getDefaultLineDasharray(); return MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toStyleValue(propertyValue); } @@ -223,13 +235,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineGapWidth); - _rawLayer->setLineGapWidth(mbglValue); + self.rawLayer->setLineGapWidth(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineGapWidth { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineGapWidth() ?: _rawLayer->getDefaultLineGapWidth(); + auto propertyValue = self.rawLayer->getLineGapWidth() ?: self.rawLayer->getDefaultLineGapWidth(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -237,13 +249,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineOffset); - _rawLayer->setLineOffset(mbglValue); + self.rawLayer->setLineOffset(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineOffset { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineOffset() ?: _rawLayer->getDefaultLineOffset(); + auto propertyValue = self.rawLayer->getLineOffset() ?: self.rawLayer->getDefaultLineOffset(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -251,13 +263,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineOpacity); - _rawLayer->setLineOpacity(mbglValue); + self.rawLayer->setLineOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineOpacity() ?: _rawLayer->getDefaultLineOpacity(); + auto propertyValue = self.rawLayer->getLineOpacity() ?: self.rawLayer->getDefaultLineOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -265,13 +277,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(linePattern); - _rawLayer->setLinePattern(mbglValue); + self.rawLayer->setLinePattern(mbglValue); } - (MGLStyleValue<NSString *> *)linePattern { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLinePattern() ?: _rawLayer->getDefaultLinePattern(); + auto propertyValue = self.rawLayer->getLinePattern() ?: self.rawLayer->getDefaultLinePattern(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } @@ -279,13 +291,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(lineTranslate); - _rawLayer->setLineTranslate(mbglValue); + self.rawLayer->setLineTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)lineTranslate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineTranslate() ?: _rawLayer->getDefaultLineTranslate(); + auto propertyValue = self.rawLayer->getLineTranslate() ?: self.rawLayer->getDefaultLineTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -293,13 +305,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslateAnchor>().toEnumPropertyValue(lineTranslateAnchor); - _rawLayer->setLineTranslateAnchor(mbglValue); + self.rawLayer->setLineTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)lineTranslateAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineTranslateAnchor() ?: _rawLayer->getDefaultLineTranslateAnchor(); + auto propertyValue = self.rawLayer->getLineTranslateAnchor() ?: self.rawLayer->getDefaultLineTranslateAnchor(); return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslateAnchor>().toEnumStyleValue(propertyValue); } @@ -307,13 +319,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(lineWidth); - _rawLayer->setLineWidth(mbglValue); + self.rawLayer->setLineWidth(mbglValue); } - (MGLStyleValue<NSNumber *> *)lineWidth { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getLineWidth() ?: _rawLayer->getDefaultLineWidth(); + auto propertyValue = self.rawLayer->getLineWidth() ?: self.rawLayer->getDefaultLineWidth(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index c72b844447..f109ea85b0 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -2,6 +2,7 @@ #import "MGLMapView_Private.h" #import "MGLStyle_Private.h" +#import "MGLStyleLayer_Private.h" #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/math/wrap.hpp> @@ -96,11 +97,19 @@ void MGLFinishCustomStyleLayer(void *context) { MGLFinishCustomStyleLayer, (__bridge void *)self); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } +- (mbgl::style::CustomLayer *)rawLayer { + return (mbgl::style::CustomLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::CustomLayer *)rawLayer { + super.rawLayer = rawLayer; +} + #pragma mark - Adding to and removing from a map view - (void)setMapView:(MGLMapView *)mapView { @@ -130,7 +139,7 @@ void MGLFinishCustomStyleLayer(void *context) { return; } _pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::CustomLayer> &>(removedLayer)); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } /** diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index 46b00b9a4d..387a575b2d 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -1,8 +1,8 @@ #import "MGLPointCollection_Private.h" #import "MGLGeometry_Private.h" +#import <mbgl/util/geojson.hpp> #import <mbgl/util/geometry.hpp> -#import <mbgl/util/feature.hpp> NS_ASSUME_NONNULL_BEGIN diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm index e5bb977863..393bd31d0d 100644 --- a/platform/darwin/src/MGLPolygon.mm +++ b/platform/darwin/src/MGLPolygon.mm @@ -5,6 +5,8 @@ #import "MGLPolygon+MGLAdditions.h" +#import <mbgl/util/geojson.hpp> + @implementation MGLPolygon @dynamic overlayBounds; diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm index ae6abc5280..0baeb68e1a 100644 --- a/platform/darwin/src/MGLPolyline.mm +++ b/platform/darwin/src/MGLPolyline.mm @@ -5,6 +5,8 @@ #import "MGLPolyline+MGLAdditions.h" +#import <mbgl/util/geojson.hpp> + @implementation MGLPolyline @dynamic overlayBounds; diff --git a/platform/darwin/src/MGLRasterSource.h b/platform/darwin/src/MGLRasterSource.h index 2940f05371..262e8f2ce1 100644 --- a/platform/darwin/src/MGLRasterSource.h +++ b/platform/darwin/src/MGLRasterSource.h @@ -1,93 +1,94 @@ -#import "MGLSource.h" -#import "MGLTypes.h" +#import "MGLTileSource.h" #import <CoreGraphics/CoreGraphics.h> -@class MGLTileSet; - NS_ASSUME_NONNULL_BEGIN /** + An `NSNumber` object containing a floating-point number that specifies the + width and height (measured in points) at which the map displays each raster + image tile when the map’s zoom level is an integer. The raster source scales + its images up or down when the map’s zoom level falls between two integers. + + The default value for this option is 512. Version 4 of the + <a href="https://www.mapbox.com/api-documentation/#maps">Mapbox Maps API</a> + requires a value of 256, as do many third-party tile servers, so consult your + provider’s documentation for the correct value. + + This option is only applicable to `MGLRasterSource` objects; it is ignored when + initializing `MGLVectorSource` objects. + */ +extern const MGLTileSourceOption MGLTileSourceOptionTileSize; + +/** `MGLRasterSource` is a map content source that supplies raster image tiles to - be shown on the map. The location of and metadata about the raster tiles are - defined by either an `MGLTileSet` object or an external TileJSON resource. A - raster source is added to an `MGLStyle` object along with an - `MGLRasterStyleLayer` object. Use a raster style layer to control the + be shown on the map. The location of and metadata about the tiles are defined + either by an option dictionary or by an external file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + A raster source is added to an `MGLStyle` object along with one or more + `MGLRasterStyleLayer` objects. Use a raster style layer to control the appearance of content supplied by the raster source. + + Each + <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-raster"><code>raster</code></a> + source defined by the style JSON file is represented at runtime by an + `MGLRasterSource` object that you can use to initialize new style layers. You + can also add and remove sources dynamically using methods such as + `-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`. */ -@interface MGLRasterSource : MGLSource +@interface MGLRasterSource : MGLTileSource #pragma mark Initializing a Source /** - Returns a raster source initialized with an identifier, TileJSON configuration - URL, and tile size. + Returns a raster source initialized with an identifier and configuration URL. After initializing and configuring the source, add it to a map view’s style using the `-[MGLStyle addSource:]` method. The URL may be a full HTTP or HTTPS URL or, for tile sets hosted by Mapbox, a - Mapbox URL indicating a map identifier (`mapbox://<mapid>`). + Mapbox URL indicating a map identifier (`mapbox://<mapid>`). The URL should + point to a JSON file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + + If a Mapbox URL is specified, this source uses a tile size of 256. For all + other tile sets, the default value is 512. (See the + `MGLTileSourceOptionTileSize` documentation for more information about tile + sizes.) If you need to use a tile size other than the default, use the + `-initWithIdentifier:configurationURL:tileSize:` method. @param identifier A string that uniquely identifies the source in the style to which it is added. - @param url A URL to a TileJSON configuration file describing the source’s - contents and other metadata. - @param tileSize The height and width (measured in points) at which to display - each tile in this source when the map’s zoom level is an integer. + @param configurationURL A URL to a TileJSON configuration file describing the + source’s contents and other metadata. @return An initialized raster source. */ -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url tileSize:(CGFloat)tileSize NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL; /** - Returns a raster source initialized with the given identifier, tile size, and - tile set. + Returns a raster source initialized with an identifier, configuration URL, and + tile size. After initializing and configuring the source, add it to a map view’s style using the `-[MGLStyle addSource:]` method. - - @param identifier A string that uniquely identifies the source in the style to - which it is added. - @param tileSet A tile set describing the source’s contents and other metadata. - @param tileSize The height and width (measured in points) at which to display - each tile in this source when the map’s zoom level is an integer. - @return An initialized raster source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize NS_DESIGNATED_INITIALIZER; - -#pragma mark Accessing a Source’s Content - -/** - A URL to a TileJSON configuration file describing the source’s contents and - other metadata. The URL may be a full HTTP or HTTPS URL or, for tile sets hosted by Mapbox, a - Mapbox URL indicating a map identifier (`mapbox://<mapid>`). - - @see <a href="https://www.mapbox.com/help/an-open-platform/#tilejson">The - TileJSON specification.</a> - */ -@property (nonatomic, readonly, copy) NSURL *URL; - -/** - The height and width (measured in points) at which to display each tile in this - source when the map’s zoom level is an integer. - - A tile may be scaled up or down when the zoom level is between two integers. + Mapbox URL indicating a map identifier (`mapbox://<mapid>`). The URL should + point to a JSON file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. - The default value of this property is 512 points. + @param identifier A string that uniquely identifies the source in the style to + which it is added. + @param configurationURL A URL to a TileJSON configuration file describing the + source’s contents and other metadata. + @param tileSize The width and height (measured in points) of each tiled image + in the raster source. See the `MGLTileSourceOptionTileSize` documentation + for details. + @return An initialized raster source. */ -@property (nonatomic, readonly, assign) NSUInteger tileSize; +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize NS_DESIGNATED_INITIALIZER; -/** - The tile set used to locate and download tiles. - - A tile set holds the raster tile URL template strings and associated - configuration for those strings. It can be passed in place of the URL - to TileJSON in order to create a source configured to download tiles - from ordinary web URLs. - */ -@property (nonatomic, readonly, nullable) MGLTileSet *tileSet; +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; @end diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index 1671e1decd..edca8bced1 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -2,11 +2,16 @@ #import "MGLMapView_Private.h" #import "MGLSource_Private.h" -#import "MGLTileSet_Private.h" +#import "MGLTileSource_Private.h" #import "NSURL+MGLAdditions.h" #include <mbgl/style/sources/raster_source.hpp> +const MGLTileSourceOption MGLTileSourceOptionTileSize = @"MGLTileSourceOptionTileSize"; + +static const CGFloat MGLRasterSourceClassicTileSize = 256; +static const CGFloat MGLRasterSourceRetinaTileSize = 512; + @interface MGLRasterSource () - (instancetype)initWithRawSource:(mbgl::style::RasterSource *)rawSource NS_DESIGNATED_INITIALIZER; @@ -15,88 +20,84 @@ @end -@implementation MGLRasterSource -{ +@implementation MGLRasterSource { std::unique_ptr<mbgl::style::RasterSource> _pendingSource; } -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url tileSize:(CGFloat)tileSize -{ - if (self = [super initWithIdentifier:identifier]) { - _URL = url; - _tileSize = tileSize; - [self commonInit]; - } - return self; +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL { + // The style specification default is 512, but 256 is the expected value for + // any tile set that would be accessed through a mapbox: URL and therefore + // any tile URL that this option currently affects. + BOOL isMapboxURL = ([configurationURL.scheme isEqualToString:@"mapbox"] + && [configurationURL.host containsString:@"."] + && (!configurationURL.path.length || [configurationURL.path isEqualToString:@"/"])); + CGFloat tileSize = isMapboxURL ? MGLRasterSourceClassicTileSize : MGLRasterSourceRetinaTileSize; + return [self initWithIdentifier:identifier configurationURL:configurationURL tileSize:tileSize]; } -- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet tileSize:(CGFloat)tileSize; -{ - if (self = [super initWithIdentifier:identifier]) - { - _tileSet = tileSet; - _tileSize = tileSize; - [self commonInit]; +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize { + if (self = [super initWithIdentifier:identifier configurationURL:configurationURL]) { + auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, + configurationURL.mgl_URLByStandardizingScheme.absoluteString.UTF8String, + uint16_t(round(tileSize))); + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); } return self; } -- (instancetype)initWithRawSource:(mbgl::style::RasterSource *)rawSource { - if (self = [super initWithRawSource:rawSource]) { - if (auto attribution = rawSource->getAttribution()) { - _tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[]]; - _tileSet.attribution = @(attribution->c_str()); +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options { + if (self = [super initWithIdentifier:identifier tileURLTemplates:tileURLTemplates options:options]) { + mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, options); + + uint16_t tileSize; + if (NSNumber *tileSizeNumber = options[MGLTileSourceOptionTileSize]) { + if (![tileSizeNumber isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionTileSize must be set to an NSNumber."]; + } + tileSize = static_cast<uint16_t>(round(tileSizeNumber.doubleValue)); } + + auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, tileSet, tileSize); + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); } return self; } -- (void)commonInit -{ - std::unique_ptr<mbgl::style::RasterSource> source; - - if (self.URL) - { - source = std::make_unique<mbgl::style::RasterSource>(self.identifier.UTF8String, - self.URL.mgl_URLByStandardizingScheme.absoluteString.UTF8String, - uint16_t(self.tileSize)); - } - else - { - source = std::make_unique<mbgl::style::RasterSource>(self.identifier.UTF8String, - self.tileSet.mbglTileset, - uint16_t(self.tileSize)); - } - - _pendingSource = std::move(source); - self.rawSource = _pendingSource.get(); +- (instancetype)initWithRawSource:(mbgl::style::RasterSource *)rawSource { + return [super initWithRawSource:rawSource]; } -- (void)addToMapView:(MGLMapView *)mapView -{ +- (void)addToMapView:(MGLMapView *)mapView { if (_pendingSource == nullptr) { [NSException raise:@"MGLRedundantSourceException" format:@"This instance %@ was already added to %@. Adding the same source instance " \ - "to the style more than once is invalid.", self, mapView.style]; + @"to the style more than once is invalid.", self, mapView.style]; } mapView.mbglMap->addSource(std::move(_pendingSource)); } -- (void)removeFromMapView:(MGLMapView *)mapView -{ +- (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterSource> &>(removedSource)); self.rawSource = _pendingSource.get(); } -- (NSString *)description -{ - return [NSString stringWithFormat: - @"<%@: %p; identifier = %@; URL = %@; tileSet = %@; tileSize = %lu>", - NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, - self.tileSet, (unsigned long)self.tileSize]; +- (mbgl::style::RasterSource *)rawSource { + return (mbgl::style::RasterSource *)super.rawSource; +} + +- (void)setRawSource:(mbgl::style::RasterSource *)rawSource { + super.rawSource = rawSource; +} + +- (NSString *)attributionHTMLString { + auto attribution = self.rawSource->getAttribution(); + return attribution ? @(attribution->c_str()) : nil; } @end diff --git a/platform/darwin/src/MGLRasterSource_Private.h b/platform/darwin/src/MGLRasterSource_Private.h index 4a367cf8f8..47b1c13517 100644 --- a/platform/darwin/src/MGLRasterSource_Private.h +++ b/platform/darwin/src/MGLRasterSource_Private.h @@ -1,5 +1,7 @@ #import "MGLRasterSource.h" +NS_ASSUME_NONNULL_BEGIN + namespace mbgl { namespace style { class RasterSource; @@ -11,3 +13,5 @@ namespace mbgl { - (instancetype)initWithRawSource:(mbgl::style::RasterSource *)rawSource; @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 1bb5c33c28..9c2a64d0da 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -26,10 +26,21 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::RasterLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + +- (mbgl::style::RasterLayer *)rawLayer +{ + return (mbgl::style::RasterLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::RasterLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -51,7 +62,7 @@ - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -66,7 +77,7 @@ removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::RasterLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes @@ -75,13 +86,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(maximumRasterBrightness); - _rawLayer->setRasterBrightnessMax(mbglValue); + self.rawLayer->setRasterBrightnessMax(mbglValue); } - (MGLStyleValue<NSNumber *> *)maximumRasterBrightness { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterBrightnessMax() ?: _rawLayer->getDefaultRasterBrightnessMax(); + auto propertyValue = self.rawLayer->getRasterBrightnessMax() ?: self.rawLayer->getDefaultRasterBrightnessMax(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -89,13 +100,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(minimumRasterBrightness); - _rawLayer->setRasterBrightnessMin(mbglValue); + self.rawLayer->setRasterBrightnessMin(mbglValue); } - (MGLStyleValue<NSNumber *> *)minimumRasterBrightness { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterBrightnessMin() ?: _rawLayer->getDefaultRasterBrightnessMin(); + auto propertyValue = self.rawLayer->getRasterBrightnessMin() ?: self.rawLayer->getDefaultRasterBrightnessMin(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -103,13 +114,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterContrast); - _rawLayer->setRasterContrast(mbglValue); + self.rawLayer->setRasterContrast(mbglValue); } - (MGLStyleValue<NSNumber *> *)rasterContrast { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterContrast() ?: _rawLayer->getDefaultRasterContrast(); + auto propertyValue = self.rawLayer->getRasterContrast() ?: self.rawLayer->getDefaultRasterContrast(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -117,13 +128,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterFadeDuration); - _rawLayer->setRasterFadeDuration(mbglValue); + self.rawLayer->setRasterFadeDuration(mbglValue); } - (MGLStyleValue<NSNumber *> *)rasterFadeDuration { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterFadeDuration() ?: _rawLayer->getDefaultRasterFadeDuration(); + auto propertyValue = self.rawLayer->getRasterFadeDuration() ?: self.rawLayer->getDefaultRasterFadeDuration(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -131,13 +142,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterHueRotation); - _rawLayer->setRasterHueRotate(mbglValue); + self.rawLayer->setRasterHueRotate(mbglValue); } - (MGLStyleValue<NSNumber *> *)rasterHueRotation { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterHueRotate() ?: _rawLayer->getDefaultRasterHueRotate(); + auto propertyValue = self.rawLayer->getRasterHueRotate() ?: self.rawLayer->getDefaultRasterHueRotate(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -145,13 +156,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterOpacity); - _rawLayer->setRasterOpacity(mbglValue); + self.rawLayer->setRasterOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)rasterOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterOpacity() ?: _rawLayer->getDefaultRasterOpacity(); + auto propertyValue = self.rawLayer->getRasterOpacity() ?: self.rawLayer->getDefaultRasterOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -159,13 +170,13 @@ MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterSaturation); - _rawLayer->setRasterSaturation(mbglValue); + self.rawLayer->setRasterSaturation(mbglValue); } - (MGLStyleValue<NSNumber *> *)rasterSaturation { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getRasterSaturation() ?: _rawLayer->getDefaultRasterSaturation(); + auto propertyValue = self.rawLayer->getRasterSaturation() ?: self.rawLayer->getDefaultRasterSaturation(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLShape.h b/platform/darwin/src/MGLShape.h index ce9375c910..e7dbe90242 100644 --- a/platform/darwin/src/MGLShape.h +++ b/platform/darwin/src/MGLShape.h @@ -13,6 +13,30 @@ NS_ASSUME_NONNULL_BEGIN */ @interface MGLShape : NSObject <MGLAnnotation> +#pragma mark Creating a Shape + +/** + Returns an `MGLShape` object initialized with the given data interpreted as a + string containing a GeoJSON object. + + If the GeoJSON object is a geometry, the returned value is a kind of + `MGLShape`. If it is a feature object, the returned value is a kind of + `MGLShape` that conforms to the `MGLFeature` protocol. If it is a feature + collection object, the returned value is an instance of + `MGLShapeCollectionFeature`. + + @param data String data containing GeoJSON source code. + @param encoding The encoding used by `data`. + @param outError Upon return, if an error has occurred, a pointer to an + `NSError` object describing the error. Pass in `NULL` to ignore any error. + @return An `MGLShape` object representation of `data`, or `nil` if `data` could + not be parsed as valid GeoJSON source code. If `nil`, `outError` contains an + `NSError` object describing the problem. + */ ++ (nullable instancetype)shapeWithData:(NSData *)data encoding:(NSStringEncoding)encoding error:(NSError * _Nullable *)outError; + +#pragma mark Accessing the Shape Attributes + /** The title of the shape annotation. The default value of this property is `nil`. */ @@ -34,6 +58,17 @@ NS_ASSUME_NONNULL_BEGIN #endif +#pragma mark Creating GeoJSON Data + +/** + Returns the GeoJSON string representation of the shape encapsulated in a data + object. + + @param encoding The string encoding to use. + @return A data object containing the shape’s GeoJSON string representation. + */ +- (NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLShape.mm b/platform/darwin/src/MGLShape.mm index e3d92c38c8..ee14027cd8 100644 --- a/platform/darwin/src/MGLShape.mm +++ b/platform/darwin/src/MGLShape.mm @@ -1,14 +1,52 @@ -#import "MGLShape.h" +#import "MGLShape_Private.h" + +#import "MGLFeature_Private.h" @implementation MGLShape -- (CLLocationCoordinate2D)coordinate -{ - [[NSException exceptionWithName:@"MGLAbstractClassException" - reason:@"MGLShape is an abstract class" - userInfo:nil] raise]; ++ (nullable instancetype)shapeWithData:(NSData *)data encoding:(NSStringEncoding)encoding error:(NSError * _Nullable *)outError { + NSString *string = [[NSString alloc] initWithData:data encoding:encoding]; + if (!string) { + if (outError) { + *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:nil]; + } + return nil; + } + + try { + const auto geojson = mapbox::geojson::parse(string.UTF8String); + return MGLShapeFromGeoJSON(geojson); + } catch (std::runtime_error &err) { + if (outError) { + *outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{ + NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"%s", err.what()], + }]; + } + return nil; + } +} + +- (mbgl::GeoJSON)geoJSONObject { + return self.geometryObject; +} + +- (mbgl::Geometry<double>)geometryObject { + [NSException raise:@"MGLAbstractClassException" + format:@"MGLShape is an abstract class"]; + return mbgl::Point<double>(); +} + +- (NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding { + auto geometry = self.geoJSONObject; + NSString *string = @(mapbox::geojson::stringify(geometry).c_str()); + return [string dataUsingEncoding:NSUTF8StringEncoding]; +} + +- (CLLocationCoordinate2D)coordinate { + [NSException raise:@"MGLAbstractClassException" + format:@"MGLShape is an abstract class"]; - return CLLocationCoordinate2DMake(MAXFLOAT, MAXFLOAT); + return kCLLocationCoordinate2DInvalid; } @end diff --git a/platform/darwin/src/MGLShapeCollectionFeature_Private.h b/platform/darwin/src/MGLShapeCollectionFeature_Private.h deleted file mode 100644 index 4f07a93b35..0000000000 --- a/platform/darwin/src/MGLShapeCollectionFeature_Private.h +++ /dev/null @@ -1,13 +0,0 @@ -#import "MGLFeature.h" - -#import <mbgl/util/feature.hpp> - -NS_ASSUME_NONNULL_BEGIN - -@interface MGLShapeCollectionFeature () - -- (mbgl::FeatureCollection)mbglFeatureCollection; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index 407d9c45a1..68cb40a83f 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -64,6 +64,14 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; `MGLStyle` object along with an `MGLVectorStyleLayer` object. The vector style layer defines the appearance of any content supplied by the shape source. + Each + <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson"><code>geojson</code></a> + source defined by the style JSON file is represented at runtime by an + `MGLShapeSource` object that you can use to refine the map’s content and + initialize new style layers. You can also add and remove sources dynamically + using methods such as `-[MGLStyle addSource:]` and + `-[MGLStyle sourceWithIdentifier:]`. + Any vector style layer initialized with a shape source should have a `nil` value in its `sourceLayerIdentifier` property. */ @@ -72,23 +80,8 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; #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 - <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">style - specification</a>. - - @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 - <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">style - specification</a>. + the source. @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 @@ -99,10 +92,16 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; - (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 - <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">style - specification</a>. + Returns a shape source with an identifier, a shape, and dictionary of options + for the source. + + To specify attributes about the shape, use an instance of an `MGLShape` + subclass that conforms to the `MGLFeature` protocol, such as `MGLPointFeature`. + To include multiple shapes in the source, use an `MGLShapeCollection` or + `MGLShapeCollectionFeature` object. + + To create a shape from GeoJSON source code, use the + `+[MGLShape shapeWithData:encoding:error:]` method. @param identifier A string that uniquely identifies the source. @param shape A concrete subclass of `MGLShape` @@ -119,31 +118,17 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance; 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]`. + passed into `-[MGLStyle addSource:]`. */ -@property (nonatomic, nullable, copy) NSData *geoJSONData; +@property (nonatomic, copy, nullable) MGLShape *shape; /** 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`. + If the receiver was initialized using `-initWithIdentifier:shape:options:`, + this property is set to `nil`. */ -@property (nonatomic, nullable) NSURL *URL; +@property (nonatomic, copy, nullable) NSURL *URL; @end diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 987306a228..d062e656c2 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -3,7 +3,6 @@ #import "MGLMapView_Private.h" #import "MGLSource_Private.h" #import "MGLFeature_Private.h" -#import "MGLShapeCollectionFeature_Private.h" #import "MGLShape_Private.h" #import "NSURL+MGLAdditions.h" @@ -26,39 +25,32 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh @end -@implementation MGLShapeSource -{ +@implementation MGLShapeSource { std::unique_ptr<mbgl::style::GeoJSONSource> _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]; +- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url options:(NS_DICTIONARY_OF(NSString *, id) *)options { + if (self = [super initWithIdentifier:identifier]) { + auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); + auto source = std::make_unique<mbgl::style::GeoJSONSource>(identifier.UTF8String, geoJSONOptions); + + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); + + self.URL = url; } return self; } -- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(NSDictionary<MGLShapeSourceOption,id> *)options -{ +- (instancetype)initWithIdentifier:(NSString *)identifier shape:(nullable MGLShape *)shape options:(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *)options { if (self = [super initWithIdentifier:identifier]) { - _shape = shape; - _options = options; - [self commonInit]; + auto geoJSONOptions = MGLGeoJSONOptionsFromDictionary(options); + auto source = std::make_unique<mbgl::style::GeoJSONSource>(identifier.UTF8String, geoJSONOptions); + + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); + + self.shape = shape; } return self; } @@ -67,8 +59,7 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh return [super initWithRawSource:rawSource]; } -- (void)addToMapView:(MGLMapView *)mapView -{ +- (void)addToMapView:(MGLMapView *)mapView { if (_pendingSource == nullptr) { [NSException raise:@"MGLRedundantSourceException" format:@"This instance %@ was already added to %@. Adding the same source instance " \ @@ -78,135 +69,97 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh mapView.mbglMap->addSource(std::move(_pendingSource)); } -- (void)removeFromMapView:(MGLMapView *)mapView -{ +- (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::GeoJSONSource> &>(removedSource)); self.rawSource = _pendingSource.get(); } -- (void)commonInit -{ - auto source = std::make_unique<mbgl::style::GeoJSONSource>(self.identifier.UTF8String, self.geoJSONOptions); - - if (self.URL) { - NSURL *url = self.URL.mgl_URLByStandardizingScheme; - source->setURL(url.absoluteString.UTF8String); +- (mbgl::style::GeoJSONSource *)rawSource { + return (mbgl::style::GeoJSONSource *)super.rawSource; +} + +- (void)setRawSource:(mbgl::style::GeoJSONSource *)rawSource { + super.rawSource = rawSource; +} + +- (NSURL *)URL { + auto url = self.rawSource->getURL(); + return url ? [NSURL URLWithString:@(url->c_str())] : nil; +} + +- (void)setURL:(NSURL *)url { + if (url) { + self.rawSource->setURL(url.mgl_URLByStandardizingScheme.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 { - if ([self.shape isKindOfClass:[MGLShapeCollectionFeature class]]) { - MGLShapeCollectionFeature *feature = (MGLShapeCollectionFeature *)self.shape; - source->setGeoJSON(mbgl::GeoJSON{[feature mbglFeatureCollection]}); - } else if ([self.shape conformsToProtocol:@protocol(MGLFeature)]) { - id<MGLFeaturePrivate> feature = (id<MGLFeaturePrivate>)self.shape; - source->setGeoJSON(mbgl::GeoJSON{[feature mbglFeature]}); - } else { - source->setGeoJSON(mbgl::GeoJSON{self.shape.geometryObject}); - } + self.shape = nil; } - - _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)setShape:(MGLShape *)shape { + self.rawSource->setGeoJSON({ shape.geoJSONObject }); + _shape = shape; } -- (void)validateValue:(id)value -{ - if (! [value isKindOfClass:[NSNumber class]]) - { - [NSException raise:@"Value not handled" format:@"%@ is not an NSNumber", value]; - } +- (NSString *)description { + return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; shape = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.shape]; } -- (void)setGeoJSONData:(NSData *)geoJSONData -{ - _geoJSONData = geoJSONData; +@end + +mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options) { + auto geoJSONOptions = mbgl::style::GeoJSONOptions(); - if (self.rawSource == NULL) - { - [self commonInit]; + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevel]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevel must be an NSNumber."]; + } + geoJSONOptions.maxzoom = value.integerValue; } - NSString *string = [[NSString alloc] initWithData:_geoJSONData encoding:NSUTF8StringEncoding]; - const auto geojson = mapbox::geojson::parse(string.UTF8String); - self.rawSource->setGeoJSON(geojson); + if (NSNumber *value = options[MGLShapeSourceOptionBuffer]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionBuffer must be an NSNumber."]; + } + geoJSONOptions.buffer = value.integerValue; + } - _shape = MGLShapeFromGeoJSON(geojson); -} - -- (void)setURL:(NSURL *)URL -{ - _URL = URL; + if (NSNumber *value = options[MGLShapeSourceOptionSimplificationTolerance]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionSimplificationTolerance must be an NSNumber."]; + } + geoJSONOptions.tolerance = value.doubleValue; + } + + if (NSNumber *value = options[MGLShapeSourceOptionClusterRadius]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionClusterRadius must be an NSNumber."]; + } + geoJSONOptions.clusterRadius = value.integerValue; + } - if (self.rawSource == NULL) - { - [self commonInit]; + if (NSNumber *value = options[MGLShapeSourceOptionMaximumZoomLevelForClustering]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionMaximumZoomLevelForClustering must be an NSNumber."]; + } + geoJSONOptions.clusterMaxZoom = value.integerValue; } - NSURL *url = self.URL.mgl_URLByStandardizingScheme; - self.rawSource->setURL(url.absoluteString.UTF8String); -} - - -- (void)setShape:(MGLShape *)shape -{ - if (self.rawSource == NULL) - { - [self commonInit]; + if (NSNumber *value = options[MGLShapeSourceOptionClustered]) { + if (![value isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionClustered must be an NSNumber."]; + } + geoJSONOptions.cluster = value.boolValue; } - - 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]; + return geoJSONOptions; } - -@end diff --git a/platform/darwin/src/MGLShapeSource_Private.h b/platform/darwin/src/MGLShapeSource_Private.h index af5dc33f96..584a5a4b30 100644 --- a/platform/darwin/src/MGLShapeSource_Private.h +++ b/platform/darwin/src/MGLShapeSource_Private.h @@ -1,12 +1,21 @@ #import "MGLShapeSource.h" #import "MGLShapeSource_Private.h" -#include <mbgl/style/sources/geojson_source.hpp> +NS_ASSUME_NONNULL_BEGIN + +namespace mbgl { + namespace style { + class GeoJSONOptions; + struct GeoJSONSource; + } +} @interface MGLShapeSource (Private) - (instancetype)initWithRawSource:(mbgl::style::GeoJSONSource *)rawSource; -- (mbgl::style::GeoJSONOptions)geoJSONOptions; - @end + +mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NS_DICTIONARY_OF(MGLShapeSourceOption, id) *options); + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLShape_Private.h b/platform/darwin/src/MGLShape_Private.h index 2c7c4700a3..15d1c1eb97 100644 --- a/platform/darwin/src/MGLShape_Private.h +++ b/platform/darwin/src/MGLShape_Private.h @@ -1,10 +1,16 @@ #import "MGLShape.h" +#import <mbgl/util/geojson.hpp> #import <mbgl/util/geometry.hpp> @interface MGLShape (Private) /** + Returns an `mbgl::GeoJSON` representation of the `MGLShape`. + */ +- (mbgl::GeoJSON)geoJSONObject; + +/** Returns an `mbgl::Geometry<double>` representation of the `MGLShape`. */ - (mbgl::Geometry<double>)geometryObject; diff --git a/platform/darwin/src/MGLSource.h b/platform/darwin/src/MGLSource.h index f0a8aacecb..6b381fca19 100644 --- a/platform/darwin/src/MGLSource.h +++ b/platform/darwin/src/MGLSource.h @@ -1,5 +1,7 @@ #import <Foundation/Foundation.h> +NS_ASSUME_NONNULL_BEGIN + /** `MGLSource` is an abstract base class for map content sources. A map content source supplies content to be shown on the map. A source is added to an @@ -13,13 +15,15 @@ `-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`. Do not create instances of this class directly, and do not create your own - subclasses of this class. Instead, create instances of `MGLRasterSource`, - `MGLShapeSource`, and `MGLVectorSource`. + subclasses of this class. Instead, create instances of `MGLShapeSource` and the + concrete subclasses of `MGLTileSource`. */ @interface MGLSource : NSObject #pragma mark Initializing a Source +- (instancetype)init __attribute__((unavailable("Use -initWithIdentifier: instead."))); + /** Returns a source initialized with an identifier. @@ -40,3 +44,5 @@ @property (nonatomic, copy) NSString *identifier; @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLSource_Private.h b/platform/darwin/src/MGLSource_Private.h index 3100e0ae6e..6e1d2e379c 100644 --- a/platform/darwin/src/MGLSource_Private.h +++ b/platform/darwin/src/MGLSource_Private.h @@ -1,5 +1,7 @@ #import "MGLSource.h" +NS_ASSUME_NONNULL_BEGIN + namespace mbgl { namespace style { class Source; @@ -46,3 +48,5 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView; @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 1e60b956c7..c2ae75ed9c 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -17,12 +17,12 @@ #import "NSDate+MGLAdditions.h" #import "MGLSource.h" -#import "MGLVectorSource_Private.h" +#import "MGLTileSource_Private.h" +#import "MGLVectorSource.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" -#import "MGLAttributionInfo.h" -#import "MGLTileSet_Private.h" +#import "MGLAttributionInfo_Private.h" #include <mbgl/util/default_styles.hpp> #include <mbgl/sprite/sprite_image.hpp> @@ -209,13 +209,12 @@ static NSURL *MGLStyleURL_emerald; auto rawSources = self.mapView.mbglMap->getSources(); NSMutableArray *infos = [NSMutableArray arrayWithCapacity:rawSources.size()]; for (auto rawSource = rawSources.begin(); rawSource != rawSources.end(); ++rawSource) { - MGLSource *source = [self sourceFromMBGLSource:*rawSource]; - if (![source isKindOfClass:[MGLVectorSource class]] - && ![source isKindOfClass:[MGLRasterSource class]]) { + MGLTileSource *source = (MGLTileSource *)[self sourceFromMBGLSource:*rawSource]; + if (![source isKindOfClass:[MGLTileSource class]]) { continue; } - NSArray *tileSetInfos = [[(id)source tileSet] attributionInfosWithFontSize:fontSize linkColor:linkColor]; + NSArray *tileSetInfos = [source attributionInfosWithFontSize:fontSize linkColor:linkColor]; [infos growArrayByAddingAttributionInfosFromArray:tileSetInfos]; } return infos; diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 032fbfcc9b..3b446dd02e 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -62,7 +62,7 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier]) { auto layer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } @@ -73,17 +73,28 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + <% } -%> +- (mbgl::style::<%- camelize(type) %>Layer *)rawLayer +{ + return (mbgl::style::<%- camelize(type) %>Layer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::<%- camelize(type) %>Layer *)rawLayer +{ + super.rawLayer = rawLayer; +} + <% if (type !== 'background' && type !== 'raster') { -%> - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); - auto layerID = _rawLayer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } @@ -91,24 +102,25 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - _rawLayer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + <% } -%> -#pragma mark - Adding to and removing from a map view +#pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer { @@ -129,7 +141,7 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -144,7 +156,7 @@ namespace mbgl { removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } <% if (layoutProperties.length) { -%> @@ -156,17 +168,17 @@ namespace mbgl { <% if (property.type == "enum") { -%> auto mbglValue = MGLStyleValueTransformer<mbgl::style::<%- mbglType(property) %>, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); + self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); + self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); + auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> return MGLStyleValueTransformer<mbgl::style::<%- mbglType(property) %>, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); <% } else { -%> @@ -185,17 +197,17 @@ namespace mbgl { <% if (property.type == "enum") { -%> auto mbglValue = MGLStyleValueTransformer<mbgl::style::<%- mbglType(property) %>, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); + self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); + self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); + auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> return MGLStyleValueTransformer<mbgl::style::<%- mbglType(property) %>, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); <% } else { -%> diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index 077af9a995..8f1cdfb4a1 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @"-[MGLStyle removeLayer:] has been called " \ @"with this instance but another style layer instance was added with the same identifer. It is an " \ @"error to send any message to this layer since it cannot be recovered after removal due to the " \ - @"identifer collision. Use unique identifiers for all layer instances including layers of " \ + @"identifier collision. Use unique identifiers for all layer instances including layers of " \ @"different types."]; \ } \ } while (NO); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 2561152efc..af92c6ba67 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -93,15 +93,26 @@ namespace mbgl { if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::SymbolLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } return self; } + +- (mbgl::style::SymbolLayer *)rawLayer +{ + return (mbgl::style::SymbolLayer *)super.rawLayer; +} + +- (void)setRawLayer:(mbgl::style::SymbolLayer *)rawLayer +{ + super.rawLayer = rawLayer; +} + - (NSString *)sourceLayerIdentifier { MGLAssertStyleLayerIsValid(); - auto layerID = _rawLayer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } @@ -109,22 +120,23 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - _rawLayer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { MGLAssertStyleLayerIsValid(); - return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer @@ -146,7 +158,7 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { _pendingLayer = nullptr; - _rawLayer = nullptr; + self.rawLayer = nullptr; auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { @@ -161,7 +173,7 @@ namespace mbgl { removedLayer.release(); _pendingLayer = std::unique_ptr<mbgl::style::SymbolLayer>(layer); - _rawLayer = _pendingLayer.get(); + self.rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes @@ -170,13 +182,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconAllowOverlap); - _rawLayer->setIconAllowOverlap(mbglValue); + self.rawLayer->setIconAllowOverlap(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconAllowOverlap { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconAllowOverlap() ?: _rawLayer->getDefaultIconAllowOverlap(); + auto propertyValue = self.rawLayer->getIconAllowOverlap() ?: self.rawLayer->getDefaultIconAllowOverlap(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -184,13 +196,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconIgnorePlacement); - _rawLayer->setIconIgnorePlacement(mbglValue); + self.rawLayer->setIconIgnorePlacement(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconIgnorePlacement { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconIgnorePlacement() ?: _rawLayer->getDefaultIconIgnorePlacement(); + auto propertyValue = self.rawLayer->getIconIgnorePlacement() ?: self.rawLayer->getDefaultIconIgnorePlacement(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -198,13 +210,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(iconImageName); - _rawLayer->setIconImage(mbglValue); + self.rawLayer->setIconImage(mbglValue); } - (MGLStyleValue<NSString *> *)iconImageName { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconImage() ?: _rawLayer->getDefaultIconImage(); + auto propertyValue = self.rawLayer->getIconImage() ?: self.rawLayer->getDefaultIconImage(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } @@ -212,13 +224,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconKeepUpright); - _rawLayer->setIconKeepUpright(mbglValue); + self.rawLayer->setIconKeepUpright(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconKeepUpright { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconKeepUpright() ?: _rawLayer->getDefaultIconKeepUpright(); + auto propertyValue = self.rawLayer->getIconKeepUpright() ?: self.rawLayer->getDefaultIconKeepUpright(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -226,13 +238,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(iconOffset); - _rawLayer->setIconOffset(mbglValue); + self.rawLayer->setIconOffset(mbglValue); } - (MGLStyleValue<NSValue *> *)iconOffset { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconOffset() ?: _rawLayer->getDefaultIconOffset(); + auto propertyValue = self.rawLayer->getIconOffset() ?: self.rawLayer->getDefaultIconOffset(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -240,13 +252,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconOptional); - _rawLayer->setIconOptional(mbglValue); + self.rawLayer->setIconOptional(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconOptional { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconOptional() ?: _rawLayer->getDefaultIconOptional(); + auto propertyValue = self.rawLayer->getIconOptional() ?: self.rawLayer->getDefaultIconOptional(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -254,13 +266,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconPadding); - _rawLayer->setIconPadding(mbglValue); + self.rawLayer->setIconPadding(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconPadding { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconPadding() ?: _rawLayer->getDefaultIconPadding(); + auto propertyValue = self.rawLayer->getIconPadding() ?: self.rawLayer->getDefaultIconPadding(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -268,13 +280,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconRotate); - _rawLayer->setIconRotate(mbglValue); + self.rawLayer->setIconRotate(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconRotate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconRotate() ?: _rawLayer->getDefaultIconRotate(); + auto propertyValue = self.rawLayer->getIconRotate() ?: self.rawLayer->getDefaultIconRotate(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -282,13 +294,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toEnumPropertyValue(iconRotationAlignment); - _rawLayer->setIconRotationAlignment(mbglValue); + self.rawLayer->setIconRotationAlignment(mbglValue); } - (MGLStyleValue<NSValue *> *)iconRotationAlignment { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconRotationAlignment() ?: _rawLayer->getDefaultIconRotationAlignment(); + auto propertyValue = self.rawLayer->getIconRotationAlignment() ?: self.rawLayer->getDefaultIconRotationAlignment(); return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toEnumStyleValue(propertyValue); } @@ -296,13 +308,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconScale); - _rawLayer->setIconSize(mbglValue); + self.rawLayer->setIconSize(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconScale { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconSize() ?: _rawLayer->getDefaultIconSize(); + auto propertyValue = self.rawLayer->getIconSize() ?: self.rawLayer->getDefaultIconSize(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -310,13 +322,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toEnumPropertyValue(iconTextFit); - _rawLayer->setIconTextFit(mbglValue); + self.rawLayer->setIconTextFit(mbglValue); } - (MGLStyleValue<NSValue *> *)iconTextFit { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconTextFit() ?: _rawLayer->getDefaultIconTextFit(); + auto propertyValue = self.rawLayer->getIconTextFit() ?: self.rawLayer->getDefaultIconTextFit(); return MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toEnumStyleValue(propertyValue); } @@ -324,13 +336,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toPropertyValue(iconTextFitPadding); - _rawLayer->setIconTextFitPadding(mbglValue); + self.rawLayer->setIconTextFitPadding(mbglValue); } - (MGLStyleValue<NSValue *> *)iconTextFitPadding { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconTextFitPadding() ?: _rawLayer->getDefaultIconTextFitPadding(); + auto propertyValue = self.rawLayer->getIconTextFitPadding() ?: self.rawLayer->getDefaultIconTextFitPadding(); return MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toStyleValue(propertyValue); } @@ -338,13 +350,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(symbolAvoidEdges); - _rawLayer->setSymbolAvoidEdges(mbglValue); + self.rawLayer->setSymbolAvoidEdges(mbglValue); } - (MGLStyleValue<NSNumber *> *)symbolAvoidEdges { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getSymbolAvoidEdges() ?: _rawLayer->getDefaultSymbolAvoidEdges(); + auto propertyValue = self.rawLayer->getSymbolAvoidEdges() ?: self.rawLayer->getDefaultSymbolAvoidEdges(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -352,13 +364,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toEnumPropertyValue(symbolPlacement); - _rawLayer->setSymbolPlacement(mbglValue); + self.rawLayer->setSymbolPlacement(mbglValue); } - (MGLStyleValue<NSValue *> *)symbolPlacement { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); + auto propertyValue = self.rawLayer->getSymbolPlacement() ?: self.rawLayer->getDefaultSymbolPlacement(); return MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toEnumStyleValue(propertyValue); } @@ -366,13 +378,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(symbolSpacing); - _rawLayer->setSymbolSpacing(mbglValue); + self.rawLayer->setSymbolSpacing(mbglValue); } - (MGLStyleValue<NSNumber *> *)symbolSpacing { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getSymbolSpacing() ?: _rawLayer->getDefaultSymbolSpacing(); + auto propertyValue = self.rawLayer->getSymbolSpacing() ?: self.rawLayer->getDefaultSymbolSpacing(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -380,13 +392,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textAllowOverlap); - _rawLayer->setTextAllowOverlap(mbglValue); + self.rawLayer->setTextAllowOverlap(mbglValue); } - (MGLStyleValue<NSNumber *> *)textAllowOverlap { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextAllowOverlap() ?: _rawLayer->getDefaultTextAllowOverlap(); + auto propertyValue = self.rawLayer->getTextAllowOverlap() ?: self.rawLayer->getDefaultTextAllowOverlap(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -394,13 +406,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toEnumPropertyValue(textAnchor); - _rawLayer->setTextAnchor(mbglValue); + self.rawLayer->setTextAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)textAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); + auto propertyValue = self.rawLayer->getTextAnchor() ?: self.rawLayer->getDefaultTextAnchor(); return MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toEnumStyleValue(propertyValue); } @@ -408,13 +420,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(textField); - _rawLayer->setTextField(mbglValue); + self.rawLayer->setTextField(mbglValue); } - (MGLStyleValue<NSString *> *)textField { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextField() ?: _rawLayer->getDefaultTextField(); + auto propertyValue = self.rawLayer->getTextField() ?: self.rawLayer->getDefaultTextField(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } @@ -422,13 +434,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toPropertyValue(textFont); - _rawLayer->setTextFont(mbglValue); + self.rawLayer->setTextFont(mbglValue); } - (MGLStyleValue<NSArray<NSString *> *> *)textFont { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextFont() ?: _rawLayer->getDefaultTextFont(); + auto propertyValue = self.rawLayer->getTextFont() ?: self.rawLayer->getDefaultTextFont(); return MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toStyleValue(propertyValue); } @@ -436,13 +448,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textIgnorePlacement); - _rawLayer->setTextIgnorePlacement(mbglValue); + self.rawLayer->setTextIgnorePlacement(mbglValue); } - (MGLStyleValue<NSNumber *> *)textIgnorePlacement { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextIgnorePlacement() ?: _rawLayer->getDefaultTextIgnorePlacement(); + auto propertyValue = self.rawLayer->getTextIgnorePlacement() ?: self.rawLayer->getDefaultTextIgnorePlacement(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -450,13 +462,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustify>().toEnumPropertyValue(textJustify); - _rawLayer->setTextJustify(mbglValue); + self.rawLayer->setTextJustify(mbglValue); } - (MGLStyleValue<NSValue *> *)textJustify { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); + auto propertyValue = self.rawLayer->getTextJustify() ?: self.rawLayer->getDefaultTextJustify(); return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustify>().toEnumStyleValue(propertyValue); } @@ -464,13 +476,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textKeepUpright); - _rawLayer->setTextKeepUpright(mbglValue); + self.rawLayer->setTextKeepUpright(mbglValue); } - (MGLStyleValue<NSNumber *> *)textKeepUpright { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextKeepUpright() ?: _rawLayer->getDefaultTextKeepUpright(); + auto propertyValue = self.rawLayer->getTextKeepUpright() ?: self.rawLayer->getDefaultTextKeepUpright(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -478,13 +490,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textLetterSpacing); - _rawLayer->setTextLetterSpacing(mbglValue); + self.rawLayer->setTextLetterSpacing(mbglValue); } - (MGLStyleValue<NSNumber *> *)textLetterSpacing { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextLetterSpacing() ?: _rawLayer->getDefaultTextLetterSpacing(); + auto propertyValue = self.rawLayer->getTextLetterSpacing() ?: self.rawLayer->getDefaultTextLetterSpacing(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -492,13 +504,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textLineHeight); - _rawLayer->setTextLineHeight(mbglValue); + self.rawLayer->setTextLineHeight(mbglValue); } - (MGLStyleValue<NSNumber *> *)textLineHeight { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextLineHeight() ?: _rawLayer->getDefaultTextLineHeight(); + auto propertyValue = self.rawLayer->getTextLineHeight() ?: self.rawLayer->getDefaultTextLineHeight(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -506,13 +518,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textMaxAngle); - _rawLayer->setTextMaxAngle(mbglValue); + self.rawLayer->setTextMaxAngle(mbglValue); } - (MGLStyleValue<NSNumber *> *)textMaxAngle { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextMaxAngle() ?: _rawLayer->getDefaultTextMaxAngle(); + auto propertyValue = self.rawLayer->getTextMaxAngle() ?: self.rawLayer->getDefaultTextMaxAngle(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -520,13 +532,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textMaxWidth); - _rawLayer->setTextMaxWidth(mbglValue); + self.rawLayer->setTextMaxWidth(mbglValue); } - (MGLStyleValue<NSNumber *> *)textMaxWidth { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextMaxWidth() ?: _rawLayer->getDefaultTextMaxWidth(); + auto propertyValue = self.rawLayer->getTextMaxWidth() ?: self.rawLayer->getDefaultTextMaxWidth(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -534,13 +546,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(textOffset); - _rawLayer->setTextOffset(mbglValue); + self.rawLayer->setTextOffset(mbglValue); } - (MGLStyleValue<NSValue *> *)textOffset { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextOffset() ?: _rawLayer->getDefaultTextOffset(); + auto propertyValue = self.rawLayer->getTextOffset() ?: self.rawLayer->getDefaultTextOffset(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -548,13 +560,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textOptional); - _rawLayer->setTextOptional(mbglValue); + self.rawLayer->setTextOptional(mbglValue); } - (MGLStyleValue<NSNumber *> *)textOptional { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextOptional() ?: _rawLayer->getDefaultTextOptional(); + auto propertyValue = self.rawLayer->getTextOptional() ?: self.rawLayer->getDefaultTextOptional(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } @@ -562,13 +574,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textPadding); - _rawLayer->setTextPadding(mbglValue); + self.rawLayer->setTextPadding(mbglValue); } - (MGLStyleValue<NSNumber *> *)textPadding { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextPadding() ?: _rawLayer->getDefaultTextPadding(); + auto propertyValue = self.rawLayer->getTextPadding() ?: self.rawLayer->getDefaultTextPadding(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -576,13 +588,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toEnumPropertyValue(textPitchAlignment); - _rawLayer->setTextPitchAlignment(mbglValue); + self.rawLayer->setTextPitchAlignment(mbglValue); } - (MGLStyleValue<NSValue *> *)textPitchAlignment { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); + auto propertyValue = self.rawLayer->getTextPitchAlignment() ?: self.rawLayer->getDefaultTextPitchAlignment(); return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toEnumStyleValue(propertyValue); } @@ -590,13 +602,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textRotate); - _rawLayer->setTextRotate(mbglValue); + self.rawLayer->setTextRotate(mbglValue); } - (MGLStyleValue<NSNumber *> *)textRotate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextRotate() ?: _rawLayer->getDefaultTextRotate(); + auto propertyValue = self.rawLayer->getTextRotate() ?: self.rawLayer->getDefaultTextRotate(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -604,13 +616,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toEnumPropertyValue(textRotationAlignment); - _rawLayer->setTextRotationAlignment(mbglValue); + self.rawLayer->setTextRotationAlignment(mbglValue); } - (MGLStyleValue<NSValue *> *)textRotationAlignment { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); + auto propertyValue = self.rawLayer->getTextRotationAlignment() ?: self.rawLayer->getDefaultTextRotationAlignment(); return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toEnumStyleValue(propertyValue); } @@ -618,13 +630,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textSize); - _rawLayer->setTextSize(mbglValue); + self.rawLayer->setTextSize(mbglValue); } - (MGLStyleValue<NSNumber *> *)textSize { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextSize() ?: _rawLayer->getDefaultTextSize(); + auto propertyValue = self.rawLayer->getTextSize() ?: self.rawLayer->getDefaultTextSize(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -632,13 +644,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toEnumPropertyValue(textTransform); - _rawLayer->setTextTransform(mbglValue); + self.rawLayer->setTextTransform(mbglValue); } - (MGLStyleValue<NSValue *> *)textTransform { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); + auto propertyValue = self.rawLayer->getTextTransform() ?: self.rawLayer->getDefaultTextTransform(); return MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toEnumStyleValue(propertyValue); } @@ -648,13 +660,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(iconColor); - _rawLayer->setIconColor(mbglValue); + self.rawLayer->setIconColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)iconColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconColor() ?: _rawLayer->getDefaultIconColor(); + auto propertyValue = self.rawLayer->getIconColor() ?: self.rawLayer->getDefaultIconColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -662,13 +674,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconHaloBlur); - _rawLayer->setIconHaloBlur(mbglValue); + self.rawLayer->setIconHaloBlur(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconHaloBlur { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconHaloBlur() ?: _rawLayer->getDefaultIconHaloBlur(); + auto propertyValue = self.rawLayer->getIconHaloBlur() ?: self.rawLayer->getDefaultIconHaloBlur(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -676,13 +688,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(iconHaloColor); - _rawLayer->setIconHaloColor(mbglValue); + self.rawLayer->setIconHaloColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)iconHaloColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconHaloColor() ?: _rawLayer->getDefaultIconHaloColor(); + auto propertyValue = self.rawLayer->getIconHaloColor() ?: self.rawLayer->getDefaultIconHaloColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -690,13 +702,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconHaloWidth); - _rawLayer->setIconHaloWidth(mbglValue); + self.rawLayer->setIconHaloWidth(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconHaloWidth { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconHaloWidth() ?: _rawLayer->getDefaultIconHaloWidth(); + auto propertyValue = self.rawLayer->getIconHaloWidth() ?: self.rawLayer->getDefaultIconHaloWidth(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -704,13 +716,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconOpacity); - _rawLayer->setIconOpacity(mbglValue); + self.rawLayer->setIconOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)iconOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconOpacity() ?: _rawLayer->getDefaultIconOpacity(); + auto propertyValue = self.rawLayer->getIconOpacity() ?: self.rawLayer->getDefaultIconOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -718,13 +730,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(iconTranslate); - _rawLayer->setIconTranslate(mbglValue); + self.rawLayer->setIconTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)iconTranslate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconTranslate() ?: _rawLayer->getDefaultIconTranslate(); + auto propertyValue = self.rawLayer->getIconTranslate() ?: self.rawLayer->getDefaultIconTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -732,13 +744,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslateAnchor>().toEnumPropertyValue(iconTranslateAnchor); - _rawLayer->setIconTranslateAnchor(mbglValue); + self.rawLayer->setIconTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)iconTranslateAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getIconTranslateAnchor() ?: _rawLayer->getDefaultIconTranslateAnchor(); + auto propertyValue = self.rawLayer->getIconTranslateAnchor() ?: self.rawLayer->getDefaultIconTranslateAnchor(); return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslateAnchor>().toEnumStyleValue(propertyValue); } @@ -746,13 +758,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(textColor); - _rawLayer->setTextColor(mbglValue); + self.rawLayer->setTextColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)textColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextColor() ?: _rawLayer->getDefaultTextColor(); + auto propertyValue = self.rawLayer->getTextColor() ?: self.rawLayer->getDefaultTextColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -760,13 +772,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textHaloBlur); - _rawLayer->setTextHaloBlur(mbglValue); + self.rawLayer->setTextHaloBlur(mbglValue); } - (MGLStyleValue<NSNumber *> *)textHaloBlur { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextHaloBlur() ?: _rawLayer->getDefaultTextHaloBlur(); + auto propertyValue = self.rawLayer->getTextHaloBlur() ?: self.rawLayer->getDefaultTextHaloBlur(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -774,13 +786,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(textHaloColor); - _rawLayer->setTextHaloColor(mbglValue); + self.rawLayer->setTextHaloColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)textHaloColor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextHaloColor() ?: _rawLayer->getDefaultTextHaloColor(); + auto propertyValue = self.rawLayer->getTextHaloColor() ?: self.rawLayer->getDefaultTextHaloColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } @@ -788,13 +800,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textHaloWidth); - _rawLayer->setTextHaloWidth(mbglValue); + self.rawLayer->setTextHaloWidth(mbglValue); } - (MGLStyleValue<NSNumber *> *)textHaloWidth { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextHaloWidth() ?: _rawLayer->getDefaultTextHaloWidth(); + auto propertyValue = self.rawLayer->getTextHaloWidth() ?: self.rawLayer->getDefaultTextHaloWidth(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -802,13 +814,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(textOpacity); - _rawLayer->setTextOpacity(mbglValue); + self.rawLayer->setTextOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)textOpacity { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextOpacity() ?: _rawLayer->getDefaultTextOpacity(); + auto propertyValue = self.rawLayer->getTextOpacity() ?: self.rawLayer->getDefaultTextOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } @@ -816,13 +828,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(textTranslate); - _rawLayer->setTextTranslate(mbglValue); + self.rawLayer->setTextTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)textTranslate { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextTranslate() ?: _rawLayer->getDefaultTextTranslate(); + auto propertyValue = self.rawLayer->getTextTranslate() ?: self.rawLayer->getDefaultTextTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } @@ -830,13 +842,13 @@ namespace mbgl { MGLAssertStyleLayerIsValid(); auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslateAnchor>().toEnumPropertyValue(textTranslateAnchor); - _rawLayer->setTextTranslateAnchor(mbglValue); + self.rawLayer->setTextTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)textTranslateAnchor { MGLAssertStyleLayerIsValid(); - auto propertyValue = _rawLayer->getTextTranslateAnchor() ?: _rawLayer->getDefaultTextTranslateAnchor(); + auto propertyValue = self.rawLayer->getTextTranslateAnchor() ?: self.rawLayer->getDefaultTextTranslateAnchor(); return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslateAnchor>().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLTileSet.h b/platform/darwin/src/MGLTileSet.h deleted file mode 100644 index 88bc7e4ae0..0000000000 --- a/platform/darwin/src/MGLTileSet.h +++ /dev/null @@ -1,82 +0,0 @@ -#import <Foundation/Foundation.h> -#import "MGLTypes.h" - -NS_ASSUME_NONNULL_BEGIN - -/** These constants represent the scheme that the tile URL templates will use. */ -typedef NS_ENUM(NSUInteger, MGLTileSetScheme) { - MGLTileSetSchemeXYZ = 0, - MGLTileSetSchemeTMS -}; - -/** - The `MGLTileSet` class holds the tile URL template strings and associated - configuration for those strings. It can be passed to an `MGLVectorSource` or - `MGLRasterSource` instead of an `NSURL` representing a TileJSON URL to create a - source. - */ -@interface MGLTileSet : NSObject - -#pragma mark Creating a Tile Set - -/** - Initializes and returns a new tile set object. - - @param tileURLTemplates An `NSArray` of `NSString` objects that represent the - tile templates. - @return The initialized tile set object. - */ -- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates; - -/** - Initializes and returns a new tile set object. - - @param tileURLTemplates An `NSArray` of `NSString` objects that represent the - tile templates. - @param minimumZoomLevel An `NSUInteger`; specifies the minimum zoom level at - which to display tiles. - @param maximumZoomLevel An `NSUInteger`; specifies the maximum zoom level at - which to display tiles. - @return The initialized tile set object. - */ -- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel; - -#pragma mark Accessing Tile Set Metadata - -/** - An `NSArray` of `NSString` objects that represent the tile templates. - */ -@property (nonatomic, copy) NS_ARRAY_OF(NSString *) *tileURLTemplates; - -/** - An `NSNumber` object containing an integer; specifies the minimum zoom level at - which the source will display tiles. The value should be in the range of 0 to - 22. The default value is 0 and the source will use the default value - if `minimumZoomLevel` is nil. - */ -@property (nonatomic, nullable) NSNumber *minimumZoomLevel; - -/** - An `NSNumber` object containing an integer; specifies the maximum zoom level at - which to display tiles. The value should be in the range of 0 to 22 and greater - than `minimumZoomLevel`. The default value is 22 and the source will use the - default value if `maximumZoomLevel` is nil. - */ -@property (nonatomic, nullable) NSNumber *maximumZoomLevel; - -/** - An `NSString` object that contains an attribution to be displayed when the map - is shown to a user. The default value is `nil`. - */ -@property (nonatomic, copy, nullable) NSString *attribution; - -/** - An `MGLTileSetScheme` value that contains an enumeration (either - `MGLTileSetSchemeXYZ` or `MGLTileSetSchemeTMS`) that influences the y direction - of the tile coordinates. The default is `MGLTileSetSchemeXYZ`. - */ -@property (nonatomic) MGLTileSetScheme scheme; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLTileSet.mm b/platform/darwin/src/MGLTileSet.mm deleted file mode 100644 index 6afc6c19af..0000000000 --- a/platform/darwin/src/MGLTileSet.mm +++ /dev/null @@ -1,101 +0,0 @@ -#import "MGLTileSet.h" - -#import "MGLAttributionInfo.h" - -#include <mbgl/util/tileset.hpp> - -@implementation MGLTileSet - -- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates -{ - if (self = [super init]) - { - _tileURLTemplates = tileURLTemplates; - } - return self; -} - -- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel -{ - if (minimumZoomLevel > maximumZoomLevel) - { - [[NSException exceptionWithName:@"Invalid minimumZoomLevel" - reason:@"minimumZoomLevel must be less than maximumZoomLevel" - userInfo:nil] raise]; - return nil; - } - - if (self = [super init]) - { - _tileURLTemplates = tileURLTemplates; - _minimumZoomLevel = @(minimumZoomLevel); - _maximumZoomLevel = @(maximumZoomLevel); - } - return self; -} - -- (void)setMinimumZoomLevel:(NSNumber *)minimumZoomLevel -{ - if (self.maximumZoomLevel && [minimumZoomLevel integerValue] > [self.maximumZoomLevel integerValue]) - { - [[NSException exceptionWithName:@"Invalid minimumZoomLevel" - reason:@"minimumZoomLevel must be less than maximumZoomLevel" - userInfo:nil] raise]; - return; - } - - _minimumZoomLevel = minimumZoomLevel; -} - -- (void)setMaximumZoomLevel:(NSNumber *)maximumZoomLevel -{ - if (self.maximumZoomLevel && [maximumZoomLevel integerValue] < [self.maximumZoomLevel integerValue]) - { - [[NSException exceptionWithName:@"Invalid minimumZoomLevel" - reason:@"minimumZoomLevel must be less than maximumZoomLevel" - userInfo:nil] raise]; - } - - _maximumZoomLevel = maximumZoomLevel; -} - -- (nullable NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosWithFontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor { - return [MGLAttributionInfo attributionInfosFromHTMLString:self.attribution - fontSize:fontSize - linkColor:linkColor]; -} - -- (mbgl::Tileset)mbglTileset -{ - mbgl::Tileset tileset; - - for (NSString *tileURLTemplate in self.tileURLTemplates) - { - tileset.tiles.push_back(tileURLTemplate.UTF8String); - } - - // set the minimum / maximum zoom range to the values specified by this class if they - // were set. otherwise, use the core objects default values - uint8_t minimumZoomLevel = self.minimumZoomLevel ? [self.minimumZoomLevel unsignedIntegerValue] : tileset.zoomRange.min; - uint8_t maximumZoomLevel = self.minimumZoomLevel ? [self.maximumZoomLevel unsignedIntegerValue] : tileset.zoomRange.max; - tileset.zoomRange = mbgl::Range<uint8_t>(minimumZoomLevel, maximumZoomLevel); - - if (self.attribution) - { - tileset.attribution = self.attribution.UTF8String; - } - - if (self.scheme == MGLTileSetSchemeTMS) { - tileset.scheme = mbgl::Tileset::Scheme::TMS; - } - - return tileset; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"<%@: %p; tileURLTemplates = %@>", - NSStringFromClass([self class]), (void *)self, self.tileURLTemplates]; -} - -@end diff --git a/platform/darwin/src/MGLTileSet_Private.h b/platform/darwin/src/MGLTileSet_Private.h deleted file mode 100644 index 038fe57fa2..0000000000 --- a/platform/darwin/src/MGLTileSet_Private.h +++ /dev/null @@ -1,24 +0,0 @@ -#import "MGLTileSet.h" - -#include <mbgl/util/tileset.hpp> - -NS_ASSUME_NONNULL_BEGIN - -@class MGLAttributionInfo; - -@interface MGLTileSet (Private) - -/** - A structured representation of the `attribution` property. The default value is - `nil`. - - @param fontSize The default text size in points. - @param linkColor The default link color. - */ -- (nullable NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosWithFontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor; - -- (mbgl::Tileset)mbglTileset; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLTileSource.h b/platform/darwin/src/MGLTileSource.h new file mode 100644 index 0000000000..caf915637e --- /dev/null +++ b/platform/darwin/src/MGLTileSource.h @@ -0,0 +1,179 @@ +#import <Foundation/Foundation.h> + +#import "MGLSource.h" +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@class MGLAttributionInfo; + +/** + Options for `MGLTileSource` objects. + */ +typedef NSString *MGLTileSourceOption NS_STRING_ENUM; + +/** + An `NSNumber` object containing an unsigned integer that specifies the minimum + zoom level at which to display tiles from the source. + + The value should be between 0 and 22, inclusive, and less than + `MGLTileSourceOptionMaximumZoomLevel`, if specified. The default value for this + option is 0. + */ +extern const MGLTileSourceOption MGLTileSourceOptionMinimumZoomLevel; + +/** + An `NSNumber` object containing an unsigned integer that specifies the maximum + zoom level at which to display tiles from the source. + + The value should be between 0 and 22, inclusive, and less than + `MGLTileSourceOptionMinimumZoomLevel`, if specified. The default value for this + option is 22. + */ +extern const MGLTileSourceOption MGLTileSourceOptionMaximumZoomLevel; + +#if TARGET_OS_IPHONE +/** + An HTML string defining the buttons to be displayed in an action sheet when the + source is part of a map view’s style and the map view’s attribution button is + pressed. + + By default, no attribution statements are displayed. If the + `MGLTileSourceOptionAttributionInfos` option is specified, this option is + ignored. + */ +extern const MGLTileSourceOption MGLTileSourceOptionAttributionHTMLString; + +/** + An array of `MGLAttributionInfo` objects defining the buttons to be displayed + in an action sheet when the source is part of a map view’s style and the map + view’s attribution button is pressed. + + By default, no attribution statements are displayed. + */ +extern const MGLTileSourceOption MGLTileSourceOptionAttributionInfos; +#else +/** + An HTML string defining the buttons to be displayed in the map view’s + attribution view when the source is part of the map view’s style. + + By default, no attribution statements are displayed. If the + `MGLTileSourceOptionAttributionInfos` option is specified, this option is + ignored. + */ +extern const MGLTileSourceOption MGLTileSourceOptionAttributionHTMLString; + +/** + An array of `MGLAttributionInfo` objects defining the buttons to be displayed + in the map view’s attribution view when the source is part of the map view’s + style. + + By default, no attribution statements are displayed. + */ +extern const MGLTileSourceOption MGLTileSourceOptionAttributionInfos; +#endif + +/** + An `NSNumber` object containing an unsigned integer that specifies the tile + coordinate system for the source’s tile URLs. The integer corresponds to one of + the constants described in `MGLTileCoordinateSystem`. + + The default value for this option is `MGLTileCoordinateSystemXYZ`. + */ +extern const MGLTileSourceOption MGLTileSourceOptionTileCoordinateSystem; + +/** + Tile coordinate systems that determine how tile coordinates in tile URLs are + interpreted. + */ +typedef NS_ENUM(NSUInteger, MGLTileCoordinateSystem) { + /** + The origin is at the top-left (northwest), and `y` values increase + southwards. + + This tile coordinate system is used by Mapbox and OpenStreetMap tile + servers. + */ + MGLTileCoordinateSystemXYZ = 0, + + /** + The origin is at the bottom-left (southwest), and `y` values increase + northwards. + + This tile coordinate system is used by tile servers that conform to the + <a href="http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification">Tile Map Service Specification</a>. + */ + MGLTileCoordinateSystemTMS +}; + +/** + `MGLTileSource` is a map content source that supplies map tiles to be shown on + the map. The location of and metadata about the tiles are defined either by an + option dictionary or by an external file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + A tile source is added to an `MGLStyle` object along with one or more + `MGLRasterStyleLayer` or `MGLVectorStyleLayer` objects. Use a style layer to + control the appearance of content supplied by the tile source. + + Do not create instances of this class directly, and do not create your own + subclasses of this class. Instead, create instances of `MGLRasterSource` and + `MGLVectorSource`. + */ +@interface MGLTileSource : MGLSource + +#pragma mark Initializing a Source + +- (instancetype)init __attribute__((unavailable("Use -initWithIdentifier:configurationURL: or -initWithIdentifier:tileURLTemplates:options: instead."))); +- (instancetype)initWithIdentifier:(NSString *)identifier __attribute__((unavailable("Use -initWithIdentifier:configurationURL: or -initWithIdentifier:tileURLTemplates:options: instead."))); + +/** + Returns a tile source initialized with an identifier and configuration URL. + + After initializing and configuring the source, add it to a map view’s style + using the `-[MGLStyle addSource:]` method. + + The URL may be a full HTTP or HTTPS URL or, for tile sets hosted by Mapbox, a + Mapbox URL indicating a map identifier (`mapbox://<mapid>`). The URL should + point to a JSON file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + + @param identifier A string that uniquely identifies the source in the style to + which it is added. + @param configurationURL A URL to a TileJSON configuration file describing the + source’s contents and other metadata. + @return An initialized tile source. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL; + +/** + Returns a tile source initialized an identifier, tile URL templates, and + options. + + After initializing and configuring the source, add it to a map view’s style + using the `-[MGLStyle addSource:]` method. + + @param identifier A string that uniquely identifies the source in the style to + which it is added. + @param tileURLTemplates An array of tile URL template strings. + @param options A dictionary containing configuration options. See + `MGLTileSourceOption` for available keys and values. Pass in `nil` to use + the default values. + @return An initialized tile source. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options; + +#pragma mark Accessing Attribution Strings + +/** + An array of `MGLAttributionInfo` objects that define the attribution + statements to be displayed when the map is shown to the user. + + By default, this array is empty. If the source is initialized with a + configuration URL, this array is also empty until the configuration JSON file + is loaded. + */ +@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLAttributionInfo *) *attributionInfos; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLTileSource.mm b/platform/darwin/src/MGLTileSource.mm new file mode 100644 index 0000000000..522675bc88 --- /dev/null +++ b/platform/darwin/src/MGLTileSource.mm @@ -0,0 +1,123 @@ +#import "MGLTileSource_Private.h" + +#import "MGLAttributionInfo_Private.h" +#import "NSString+MGLAdditions.h" + +#if TARGET_OS_IPHONE + #import <UIKit/UIKit.h> +#else + #import <Cocoa/Cocoa.h> +#endif + +#include <mbgl/util/tileset.hpp> + +const MGLTileSourceOption MGLTileSourceOptionMinimumZoomLevel = @"MGLTileSourceOptionMinimumZoomLevel"; +const MGLTileSourceOption MGLTileSourceOptionMaximumZoomLevel = @"MGLTileSourceOptionMaximumZoomLevel"; +const MGLTileSourceOption MGLTileSourceOptionAttributionHTMLString = @"MGLTileSourceOptionAttributionHTMLString"; +const MGLTileSourceOption MGLTileSourceOptionAttributionInfos = @"MGLTileSourceOptionAttributionInfos"; +const MGLTileSourceOption MGLTileSourceOptionTileCoordinateSystem = @"MGLTileSourceOptionTileCoordinateSystem"; + +@implementation MGLTileSource + +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL { + return [super initWithIdentifier:identifier]; +} + +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options { + return [super initWithIdentifier:identifier]; +} + +- (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfos { + return [self attributionInfosWithFontSize:0 linkColor:nil]; +} + +- (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosWithFontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor { + return [MGLAttributionInfo attributionInfosFromHTMLString:self.attributionHTMLString + fontSize:fontSize + linkColor:linkColor]; +} + +- (NSString *)attributionHTMLString { + [NSException raise:@"MGLAbstractClassException" + format:@"MGLTileSource is an abstract class"]; + return nil; +} + +@end + +mbgl::Tileset MGLTileSetFromTileURLTemplates(NS_ARRAY_OF(NSString *) *tileURLTemplates, NS_DICTIONARY_OF(MGLTileSourceOption, id) * _Nullable options) { + mbgl::Tileset tileSet; + + for (NSString *tileURLTemplate in tileURLTemplates) { + tileSet.tiles.push_back(tileURLTemplate.UTF8String); + } + + // set the minimum / maximum zoom range to the values specified by this class if they + // were set. otherwise, use the core objects default values + if (NSNumber *minimumZoomLevel = options[MGLTileSourceOptionMinimumZoomLevel]) { + if (![minimumZoomLevel isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionMinimumZoomLevel must be set to an NSNumber."]; + } + tileSet.zoomRange.min = minimumZoomLevel.integerValue; + } + if (NSNumber *maximumZoomLevel = options[MGLTileSourceOptionMaximumZoomLevel]) { + if (![maximumZoomLevel isKindOfClass:[NSNumber class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionMinimumZoomLevel must be set to an NSNumber."]; + } + tileSet.zoomRange.max = maximumZoomLevel.integerValue; + } + if (tileSet.zoomRange.min > tileSet.zoomRange.max) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionMinimumZoomLevel must be less than MGLTileSourceOptionMaximumZoomLevel."]; + } + + if (NSString *attribution = options[MGLTileSourceOptionAttributionHTMLString]) { + if (![attribution isKindOfClass:[NSString class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionAttributionHTMLString must be set to a string."]; + } + tileSet.attribution = attribution.UTF8String; + } + + if (NSArray *attributionInfos = options[MGLTileSourceOptionAttributionInfos]) { + if (![attributionInfos isKindOfClass:[NSArray class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionAttributionInfos must be set to a string."]; + } + + NSAttributedString *attributedString = [MGLAttributionInfo attributedStringForAttributionInfos:attributionInfos]; +#if TARGET_OS_IPHONE + static NSString * const NSExcludedElementsDocumentAttribute = @"ExcludedElements"; +#endif + NSDictionary *documentAttributes = @{ + NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, + NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding), + // The attribution string is meant to be a simple, inline fragment, not a full-fledged, validating document. + NSExcludedElementsDocumentAttribute: @[@"XML", @"DOCTYPE", @"html", @"head", @"meta", @"title", @"style", @"body", @"p"], + }; + NSData *data = [attributedString dataFromRange:attributedString.mgl_wholeRange documentAttributes:documentAttributes error:NULL]; + NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + tileSet.attribution = html.UTF8String; + } + + if (NSNumber *tileCoordinateSystemNumber = options[MGLTileSourceOptionTileCoordinateSystem]) { + if (![tileCoordinateSystemNumber isKindOfClass:[NSValue class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLTileSourceOptionTileCoordinateSystem must be set to an NSValue or NSNumber."]; + } + MGLTileCoordinateSystem tileCoordinateSystem; + [tileCoordinateSystemNumber getValue:&tileCoordinateSystem]; + switch (tileCoordinateSystem) { + case MGLTileCoordinateSystemXYZ: + tileSet.scheme = mbgl::Tileset::Scheme::XYZ; + break; + case MGLTileCoordinateSystemTMS: + tileSet.scheme = mbgl::Tileset::Scheme::TMS; + break; + } + } + + return tileSet; +} diff --git a/platform/darwin/src/MGLTileSource_Private.h b/platform/darwin/src/MGLTileSource_Private.h new file mode 100644 index 0000000000..ca80e3d960 --- /dev/null +++ b/platform/darwin/src/MGLTileSource_Private.h @@ -0,0 +1,36 @@ +#import "MGLTileSource.h" + +#import <CoreGraphics/CoreGraphics.h> + +NS_ASSUME_NONNULL_BEGIN + +namespace mbgl { + class Tileset; +} + +@class MGLAttributionInfo; + +@interface MGLTileSource (Private) + +/** + An HTML string to be displayed as attribution when the map is shown to a user. + + The default value is `nil`. If the source is initialized with a configuration + URL, this property is also `nil` until the configuration JSON file is loaded. + */ +@property (nonatomic, copy, nullable, readonly) NSString *attributionHTMLString; + +/** + A structured representation of the `attribution` property. The default value is + `nil`. + + @param fontSize The default text size in points, or 0 to use the default. + @param linkColor The default link color, or `nil` to use the default. + */ +- (NS_ARRAY_OF(MGLAttributionInfo *) *)attributionInfosWithFontSize:(CGFloat)fontSize linkColor:(nullable MGLColor *)linkColor; + +@end + +mbgl::Tileset MGLTileSetFromTileURLTemplates(NS_ARRAY_OF(NSString *) *tileURLTemplates, NS_DICTIONARY_OF(MGLTileSourceOption, id) * _Nullable options); + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLVectorSource.h b/platform/darwin/src/MGLVectorSource.h index 758b4c993f..f91a0cbb23 100644 --- a/platform/darwin/src/MGLVectorSource.h +++ b/platform/darwin/src/MGLVectorSource.h @@ -1,80 +1,35 @@ -#import "MGLSource.h" -#import "MGLTypes.h" - -@class MGLTileSet; +#import "MGLTileSource.h" NS_ASSUME_NONNULL_BEGIN /** `MGLVectorSource` is a map content source that supplies tiled vector data in <a href="https://www.mapbox.com/vector-tiles/">Mapbox Vector Tile</a> format to - be shown on the map. The location of and metadata about the vector tiles are - defined by either an `MGLTileSet` object or an external TileJSON resource. A - vector source is added to an `MGLStyle` object along with an - `MGLVectorStyleLayer` object. The vector style layer defines the appearance of + be shown on the map. The location of and metadata about the tiles are defined + either by an option dictionary or by an external file that conforms to the + <a href="https://github.com/mapbox/tilejson-spec/">TileJSON specification</a>. + A vector source is added to an `MGLStyle` object along with one or more + `MGLVectorStyleLayer` objects. A vector style layer defines the appearance of any content supplied by the vector source. + Each + <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-vector"><code>vector</code></a> + source defined by the style JSON file is represented at runtime by an + `MGLVectorSource` object that you can use to initialize new style layers. You + can also add and remove sources dynamically using methods such as + `-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`. + Within each vector tile, each geometric coordinate must lie between −1 × <var>extent</var> and (<var>extent</var> × 2) − 1, inclusive. Any vector style layer initialized with a vector source must have a non-`nil` value in its `sourceLayerIdentifier` property. */ -@interface MGLVectorSource : MGLSource - -#pragma mark Initializing a Source - -/** - Returns a vector source initialized with an identifier and TileJSON URL. - - After initializing and configuring the source, add it to a map view’s style - using the `-[MGLStyle addSource:]` method. - - The URL may be a full HTTP or HTTPS URL or, for tile sets hosted by Mapbox, a - Mapbox URL indicating a map identifier (`mapbox://<mapid>`). - - @param identifier A string that uniquely identifies the source in the style to - which it is added. - @param url A URL to a TileJSON configuration file describing the source’s - contents and other metadata. - @return An initialized vector source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url NS_DESIGNATED_INITIALIZER; - -/** - Returns a vector source initialized an identifier and tile set. - - After initializing and configuring the source, add it to a map view’s style - using the `-[MGLStyle addSource:]` method. - - @param identifier A string that uniquely identifies the source in the style to - which it is added. - @param tileSet A tile set describing the source’s contents and other metadata. - @return An initialized vector source. - */ -- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet NS_DESIGNATED_INITIALIZER; +@interface MGLVectorSource : MGLTileSource -#pragma mark Accessing a Source’s Content +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL NS_DESIGNATED_INITIALIZER; -/** - A URL to a TileJSON configuration file describing the source’s contents and - other metadata. - - The URL may be a full HTTP or HTTPS URL or, for tile sets hosted by Mapbox, a - Mapbox URL indicating a map identifier (`mapbox://<mapid>`). - - If the receiver was initialized using `-initWithIdentifier:tileSet:`, this - property is set to `nil`. - */ -@property (nonatomic, readonly, copy) NSURL *URL; - -/** - A tile set describing the source’s contents and other metadata. - - If the receiver was initialized using `-initWithIdentifier:URL:`, this property - is set to `nil`. - */ -@property (nonatomic, readonly, nullable) MGLTileSet *tileSet; +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; @end diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index b5ec0b33be..0eea8dd18c 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -2,7 +2,7 @@ #import "MGLMapView_Private.h" #import "MGLSource_Private.h" -#import "MGLTileSet_Private.h" +#import "MGLTileSource_Private.h" #import "NSURL+MGLAdditions.h" #include <mbgl/style/sources/vector_source.hpp> @@ -15,62 +15,36 @@ @end -@implementation MGLVectorSource -{ +@implementation MGLVectorSource { std::unique_ptr<mbgl::style::VectorSource> _pendingSource; } -- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url -{ - if (self = [super initWithIdentifier:identifier]) - { - _URL = url; - [self commonInit]; +- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL { + if (self = [super initWithIdentifier:identifier configurationURL:configurationURL]) { + auto source = std::make_unique<mbgl::style::VectorSource>(identifier.UTF8String, + configurationURL.mgl_URLByStandardizingScheme.absoluteString.UTF8String); + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); } return self; } -- (instancetype)initWithIdentifier:(NSString *)identifier tileSet:(MGLTileSet *)tileSet -{ - if (self = [super initWithIdentifier:identifier]) - { - _tileSet = tileSet; - [self commonInit]; +- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates options:(nullable NS_DICTIONARY_OF(MGLTileSourceOption, id) *)options { + if (self = [super initWithIdentifier:identifier tileURLTemplates:tileURLTemplates options:options]) { + mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, options); + + auto source = std::make_unique<mbgl::style::VectorSource>(identifier.UTF8String, tileSet); + _pendingSource = std::move(source); + self.rawSource = _pendingSource.get(); } return self; } - (instancetype)initWithRawSource:(mbgl::style::VectorSource *)rawSource { - if (self = [super initWithRawSource:rawSource]) { - if (auto attribution = rawSource->getAttribution()) { - _tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[]]; - _tileSet.attribution = @(attribution->c_str()); - } - } - return self; + return [super initWithRawSource:rawSource]; } -- (void)commonInit -{ - std::unique_ptr<mbgl::style::VectorSource> source; - - if (self.URL) - { - source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String, - self.URL.mgl_URLByStandardizingScheme.absoluteString.UTF8String); - } - else - { - source = std::make_unique<mbgl::style::VectorSource>(self.identifier.UTF8String, - self.tileSet.mbglTileset); - } - - _pendingSource = std::move(source); - self.rawSource = _pendingSource.get(); -} - -- (void)addToMapView:(MGLMapView *)mapView -{ +- (void)addToMapView:(MGLMapView *)mapView { if (_pendingSource == nullptr) { [NSException raise:@"MGLRedundantSourceException" format:@"This instance %@ was already added to %@. Adding the same source instance " \ @@ -80,18 +54,24 @@ mapView.mbglMap->addSource(std::move(_pendingSource)); } -- (void)removeFromMapView:(MGLMapView *)mapView -{ +- (void)removeFromMapView:(MGLMapView *)mapView { auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); _pendingSource = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::VectorSource> &>(removedSource)); self.rawSource = _pendingSource.get(); } -- (NSString *)description -{ - return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; tileSet = %@>", - NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.tileSet]; +- (mbgl::style::VectorSource *)rawSource { + return (mbgl::style::VectorSource *)super.rawSource; +} + +- (void)setRawSource:(mbgl::style::VectorSource *)rawSource { + super.rawSource = rawSource; +} + +- (NSString *)attributionHTMLString { + auto attribution = self.rawSource->getAttribution(); + return attribution ? @(attribution->c_str()) : nil; } @end diff --git a/platform/darwin/src/MGLVectorSource_Private.h b/platform/darwin/src/MGLVectorSource_Private.h index ce6bccdbae..12fcd82012 100644 --- a/platform/darwin/src/MGLVectorSource_Private.h +++ b/platform/darwin/src/MGLVectorSource_Private.h @@ -1,5 +1,7 @@ #import "MGLVectorSource.h" +NS_ASSUME_NONNULL_BEGIN + namespace mbgl { namespace style { class VectorSource; @@ -11,3 +13,5 @@ namespace mbgl { - (instancetype)initWithRawSource:(mbgl::style::VectorSource *)rawSource; @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSArray+MGLAdditions.h b/platform/darwin/src/NSArray+MGLAdditions.h index 6871f15486..eb1cfb7c47 100644 --- a/platform/darwin/src/NSArray+MGLAdditions.h +++ b/platform/darwin/src/NSArray+MGLAdditions.h @@ -6,4 +6,7 @@ - (std::vector<mbgl::Value>)mgl_vector; +/** Returns a string resulting from inserting a separator between each attributed string in the array */ +- (NSAttributedString *)mgl_attributedComponentsJoinedByString:(NSString *)separator; + @end diff --git a/platform/darwin/src/NSArray+MGLAdditions.mm b/platform/darwin/src/NSArray+MGLAdditions.mm index 976eda704f..b2799c46e1 100644 --- a/platform/darwin/src/NSArray+MGLAdditions.mm +++ b/platform/darwin/src/NSArray+MGLAdditions.mm @@ -23,4 +23,19 @@ return vector; } +- (NSAttributedString *)mgl_attributedComponentsJoinedByString:(NSString *)separator { + NSAttributedString *attributedSeparator = [[NSAttributedString alloc] initWithString:separator]; + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; + BOOL isSubsequentItem = NO; + for (NSAttributedString *component in self) { + NSAssert([component isKindOfClass:[NSAttributedString class]], @"Items in array must be attributed strings."); + if (isSubsequentItem) { + [attributedString appendAttributedString:attributedSeparator]; + } + isSubsequentItem = YES; + [attributedString appendAttributedString:component]; + } + return attributedString; +} + @end |