From 8afc68bbe4cdb81bbb758ea9d6f3e7880738fbbd Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 3 Nov 2016 18:19:55 -0700 Subject: [PATCH 01/67] [ios] Store annotation tags for MGLMultiPoint annotations in the map (#6888) * [ios] Store annotation tags for MGLMultiPoint annotations in the map This fixes an issue where, if a multipoint annotation was added, native annotation view update logic would crash. Adding the annotation tag for multipoints, too, avoids the out of range exception. This also adds a check for MGLMultiPoint for offscreen annotations for consistency with the onscreen case. --- platform/ios/src/MGLMapView.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9206036a6..25a9b8518 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2915,6 +2915,7 @@ public: MGLAnnotationContext context; context.annotation = annotation; _annotationContextsByAnnotationTag[annotationTag] = context; + _annotationTagsByAnnotation[annotation] = annotationTag; [(NSObject *)annotation addObserver:self forKeyPath:@"coordinates" options:0 context:(void *)(NSUInteger)annotationTag]; } @@ -4704,13 +4705,19 @@ public: // Enqueue (and move if required) offscreen annotation views for (id annotation in offscreenAnnotations) { - CLLocationCoordinate2D coordinate = annotation.coordinate; + // Defer to the shape/polygon styling delegate methods + if ([annotation isKindOfClass:[MGLMultiPoint class]]) + { + continue; + } + MGLAnnotationTag annotationTag = _annotationTagsByAnnotation.at(annotation); MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); UIView *annotationView = annotationContext.annotationView; if (annotationView) { + CLLocationCoordinate2D coordinate = annotation.coordinate; // Every so often (1 out of 1000 frames?) the mbgl query mechanism fails. This logic spot checks the // offscreenAnnotations values -- if they are actually still on screen then the view center is // moved and the enqueue operation is avoided. This allows us to keep the performance benefit of From 751aff2ddd1770d9842c273f65e8aad768112151 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 4 Nov 2016 13:50:53 -0700 Subject: [PATCH 02/67] [ios, macos] Work around annotation race condition (#6924) When annotations are removed concurrently with being updated because of a map redraw, it is possible that mbgl will still consider an annotation to exist depending on what part of the map lifecycle the call update annotations happens. However, the annotation context by tag map in MGLMapView (on the main thread) will always be up to date. This adds a guard that uses that map to avoid considering annotations that have actually been removed as visible. Another issue was that adding the same annotation object twice has always been allowed and has worked, visually. However, a recent refactor to make the reuse queue work correctly is not tolerant of the a single view representing two annotation instances that are the same. The effect is that a new UIView will be generated for each (clone) annotation that is added and only the last view will move with the map. The other views become detached and float around in the view as the map is panned. This commit adds a guard to make adding an annotation instance a no-op if it has already been added before. --- platform/ios/src/MGLMapView.mm | 12 +++++++++++- platform/macos/src/MGLMapView.mm | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 25a9b8518..00d2425a4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2836,7 +2836,11 @@ public: for (auto const& annotationTag: annotationTags) { - MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag]; + if (!_annotationContextsByAnnotationTag.count(annotationTag)) + { + continue; + } + MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); [annotations addObject:annotationContext.annotation]; } @@ -2903,6 +2907,12 @@ public: { NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"annotation should conform to MGLAnnotation"); + // adding the same annotation object twice is a no-op + if ([self.annotations containsObject:annotation]) + { + continue; + } + if ([annotation isKindOfClass:[MGLMultiPoint class]]) { // The polyline or polygon knows how to style itself (with the map view’s help). diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 4df365378..6679aaaa6 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1635,7 +1635,11 @@ public: for (auto const& annotationTag: annotationTags) { - MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag]; + if (!_annotationContextsByAnnotationTag.count(annotationTag)) + { + continue; + } + MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); [annotations addObject:annotationContext.annotation]; } @@ -1687,6 +1691,12 @@ public: for (id annotation in annotations) { NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"Annotation does not conform to MGLAnnotation"); + // adding the same annotation object twice is a no-op + if ([self.annotations containsObject:annotation]) + { + continue; + } + if ([annotation isKindOfClass:[MGLMultiPoint class]]) { // The multipoint knows how to style itself (with the map view’s help). MGLMultiPoint *multiPoint = (MGLMultiPoint *)annotation; From 4e8121aaf1037f2e927ba80d4da85ebe3eef5060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 4 Nov 2016 09:49:46 -0700 Subject: [PATCH 03/67] [ios, macos] Fixed Xcode 7.x compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define NSErrorDomain before its first use. Define NSNotificationName as a typedef instead of a #define. Guard these shims on the existence of NS_STRING_ENUM rather than another macro that’s new to Xcode 8. Fixes #6906. --- platform/darwin/src/MGLTypes.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/darwin/src/MGLTypes.h b/platform/darwin/src/MGLTypes.h index e9e05bc68..a6b7254b5 100644 --- a/platform/darwin/src/MGLTypes.h +++ b/platform/darwin/src/MGLTypes.h @@ -20,6 +20,13 @@ NS_ASSUME_NONNULL_BEGIN +#ifndef NS_STRING_ENUM + #define NS_STRING_ENUM + #define NS_EXTENSIBLE_STRING_ENUM + typedef NSString *NSErrorDomain; + typedef NSString *NSNotificationName; +#endif + /** Indicates an error occurred in the Mapbox SDK. */ extern NSErrorDomain const MGLErrorDomain; @@ -97,9 +104,3 @@ NS_ASSUME_NONNULL_END #define NS_MUTABLE_DICTIONARY_OF(ObjectClass...) NSMutableDictionary #endif #endif - -#if !defined(FOUNDATION_SWIFT_SDK_EPOCH_LESS_THAN) || FOUNDATION_SWIFT_SDK_EPOCH_LESS_THAN(8) - #define NS_STRING_ENUM - #define NS_EXTENSIBLE_STRING_ENUM - #define NSNotificationName NSString * -#endif From 373904e822bfb13acc8015987497d43507eb5b2a Mon Sep 17 00:00:00 2001 From: fabian-guerra Date: Fri, 4 Nov 2016 15:20:01 -0700 Subject: [PATCH 04/67] [ios, macos] Layer ownership refactor (#6904) `MGLStyleLayer` was updated to support a raw pointer to the mbgl object, which is always initialized, either to the value returned by `mbgl::Map getLayer`, or for independently created objects, to the pointer value held in `pendingLayer`. In the latter case, this raw pointer value stays even after ownership of the object is transferred via `mbgl::Map addLayer`. --- .../darwin/src/MGLBackgroundStyleLayer.mm | 41 +++- platform/darwin/src/MGLCircleStyleLayer.mm | 65 +++-- platform/darwin/src/MGLFillStyleLayer.mm | 65 +++-- platform/darwin/src/MGLLineStyleLayer.mm | 93 ++++--- platform/darwin/src/MGLRasterStyleLayer.mm | 57 +++-- platform/darwin/src/MGLStyle.mm | 14 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 50 +++- platform/darwin/src/MGLStyleLayer_Private.h | 32 ++- platform/darwin/src/MGLSymbolStyleLayer.mm | 229 ++++++++++-------- platform/ios/app/MBXViewController.m | 1 + 10 files changed, 427 insertions(+), 220 deletions(-) diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 33a105e5d..38c97e8d4 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,50 +12,74 @@ @interface MGLBackgroundStyleLayer () -@property (nonatomic) mbgl::style::BackgroundLayer *layer; +@property (nonatomic) mbgl::style::BackgroundLayer *rawLayer; @end @implementation MGLBackgroundStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier { if (self = [super initWithIdentifier:identifier]) { - _layer = new mbgl::style::BackgroundLayer(identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + #pragma mark - Accessing the Paint Attributes - (void)setBackgroundColor:(MGLStyleValue *)backgroundColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundColor); - self.layer->setBackgroundColor(mbglValue); + self.rawLayer->setBackgroundColor(mbglValue); } - (MGLStyleValue *)backgroundColor { - auto propertyValue = self.layer->getBackgroundColor() ?: self.layer->getDefaultBackgroundColor(); + auto propertyValue = self.rawLayer->getBackgroundColor() ?: self.rawLayer->getDefaultBackgroundColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundPattern:(MGLStyleValue *)backgroundPattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundPattern); - self.layer->setBackgroundPattern(mbglValue); + self.rawLayer->setBackgroundPattern(mbglValue); } - (MGLStyleValue *)backgroundPattern { - auto propertyValue = self.layer->getBackgroundPattern() ?: self.layer->getDefaultBackgroundPattern(); + auto propertyValue = self.rawLayer->getBackgroundPattern() ?: self.rawLayer->getDefaultBackgroundPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundOpacity:(MGLStyleValue *)backgroundOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundOpacity); - self.layer->setBackgroundOpacity(mbglValue); + self.rawLayer->setBackgroundOpacity(mbglValue); } - (MGLStyleValue *)backgroundOpacity { - auto propertyValue = self.layer->getBackgroundOpacity() ?: self.layer->getDefaultBackgroundOpacity(); + auto propertyValue = self.rawLayer->getBackgroundOpacity() ?: self.rawLayer->getDefaultBackgroundOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 8fe97a053..13eedf3f9 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,111 +12,135 @@ @interface MGLCircleStyleLayer () -@property (nonatomic) mbgl::style::CircleLayer *layer; +@property (nonatomic) mbgl::style::CircleLayer *rawLayer; @end @implementation MGLCircleStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::CircleLayer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + - (NSString *)sourceLayerIdentifier { - auto layerID = self.layer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.layer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } #pragma mark - Accessing the Paint Attributes - (void)setCircleRadius:(MGLStyleValue *)circleRadius { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleRadius); - self.layer->setCircleRadius(mbglValue); + self.rawLayer->setCircleRadius(mbglValue); } - (MGLStyleValue *)circleRadius { - auto propertyValue = self.layer->getCircleRadius() ?: self.layer->getDefaultCircleRadius(); + auto propertyValue = self.rawLayer->getCircleRadius() ?: self.rawLayer->getDefaultCircleRadius(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleColor:(MGLStyleValue *)circleColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleColor); - self.layer->setCircleColor(mbglValue); + self.rawLayer->setCircleColor(mbglValue); } - (MGLStyleValue *)circleColor { - auto propertyValue = self.layer->getCircleColor() ?: self.layer->getDefaultCircleColor(); + auto propertyValue = self.rawLayer->getCircleColor() ?: self.rawLayer->getDefaultCircleColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleBlur:(MGLStyleValue *)circleBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleBlur); - self.layer->setCircleBlur(mbglValue); + self.rawLayer->setCircleBlur(mbglValue); } - (MGLStyleValue *)circleBlur { - auto propertyValue = self.layer->getCircleBlur() ?: self.layer->getDefaultCircleBlur(); + auto propertyValue = self.rawLayer->getCircleBlur() ?: self.rawLayer->getDefaultCircleBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleOpacity:(MGLStyleValue *)circleOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleOpacity); - self.layer->setCircleOpacity(mbglValue); + self.rawLayer->setCircleOpacity(mbglValue); } - (MGLStyleValue *)circleOpacity { - auto propertyValue = self.layer->getCircleOpacity() ?: self.layer->getDefaultCircleOpacity(); + auto propertyValue = self.rawLayer->getCircleOpacity() ?: self.rawLayer->getDefaultCircleOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleTranslate:(MGLStyleValue *)circleTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(circleTranslate); - self.layer->setCircleTranslate(mbglValue); + self.rawLayer->setCircleTranslate(mbglValue); } - (MGLStyleValue *)circleTranslate { - auto propertyValue = self.layer->getCircleTranslate() ?: self.layer->getDefaultCircleTranslate(); + auto propertyValue = self.rawLayer->getCircleTranslate() ?: self.rawLayer->getDefaultCircleTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setCircleTranslateAnchor:(MGLStyleValue *)circleTranslateAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleTranslateAnchor); - self.layer->setCircleTranslateAnchor(mbglValue); + self.rawLayer->setCircleTranslateAnchor(mbglValue); } - (MGLStyleValue *)circleTranslateAnchor { - auto propertyValue = self.layer->getCircleTranslateAnchor() ?: self.layer->getDefaultCircleTranslateAnchor(); + auto propertyValue = self.rawLayer->getCircleTranslateAnchor() ?: self.rawLayer->getDefaultCircleTranslateAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circlePitchScale); - self.layer->setCirclePitchScale(mbglValue); + self.rawLayer->setCirclePitchScale(mbglValue); } - (MGLStyleValue *)circlePitchScale { - auto propertyValue = self.layer->getCirclePitchScale() ?: self.layer->getDefaultCirclePitchScale(); + auto propertyValue = self.rawLayer->getCirclePitchScale() ?: self.rawLayer->getDefaultCirclePitchScale(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index e16e3b265..1f8b7402d 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,111 +12,135 @@ @interface MGLFillStyleLayer () -@property (nonatomic) mbgl::style::FillLayer *layer; +@property (nonatomic) mbgl::style::FillLayer *rawLayer; @end @implementation MGLFillStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::FillLayer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + - (NSString *)sourceLayerIdentifier { - auto layerID = self.layer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.layer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } #pragma mark - Accessing the Paint Attributes - (void)setFillAntialias:(MGLStyleValue *)fillAntialias { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillAntialias); - self.layer->setFillAntialias(mbglValue); + self.rawLayer->setFillAntialias(mbglValue); } - (MGLStyleValue *)fillAntialias { - auto propertyValue = self.layer->getFillAntialias() ?: self.layer->getDefaultFillAntialias(); + auto propertyValue = self.rawLayer->getFillAntialias() ?: self.rawLayer->getDefaultFillAntialias(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOpacity:(MGLStyleValue *)fillOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOpacity); - self.layer->setFillOpacity(mbglValue); + self.rawLayer->setFillOpacity(mbglValue); } - (MGLStyleValue *)fillOpacity { - auto propertyValue = self.layer->getFillOpacity() ?: self.layer->getDefaultFillOpacity(); + auto propertyValue = self.rawLayer->getFillOpacity() ?: self.rawLayer->getDefaultFillOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillColor:(MGLStyleValue *)fillColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillColor); - self.layer->setFillColor(mbglValue); + self.rawLayer->setFillColor(mbglValue); } - (MGLStyleValue *)fillColor { - auto propertyValue = self.layer->getFillColor() ?: self.layer->getDefaultFillColor(); + auto propertyValue = self.rawLayer->getFillColor() ?: self.rawLayer->getDefaultFillColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOutlineColor:(MGLStyleValue *)fillOutlineColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOutlineColor); - self.layer->setFillOutlineColor(mbglValue); + self.rawLayer->setFillOutlineColor(mbglValue); } - (MGLStyleValue *)fillOutlineColor { - auto propertyValue = self.layer->getFillOutlineColor() ?: self.layer->getDefaultFillOutlineColor(); + auto propertyValue = self.rawLayer->getFillOutlineColor() ?: self.rawLayer->getDefaultFillOutlineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillTranslate:(MGLStyleValue *)fillTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(fillTranslate); - self.layer->setFillTranslate(mbglValue); + self.rawLayer->setFillTranslate(mbglValue); } - (MGLStyleValue *)fillTranslate { - auto propertyValue = self.layer->getFillTranslate() ?: self.layer->getDefaultFillTranslate(); + auto propertyValue = self.rawLayer->getFillTranslate() ?: self.rawLayer->getDefaultFillTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setFillTranslateAnchor:(MGLStyleValue *)fillTranslateAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillTranslateAnchor); - self.layer->setFillTranslateAnchor(mbglValue); + self.rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue *)fillTranslateAnchor { - auto propertyValue = self.layer->getFillTranslateAnchor() ?: self.layer->getDefaultFillTranslateAnchor(); + auto propertyValue = self.rawLayer->getFillTranslateAnchor() ?: self.rawLayer->getDefaultFillTranslateAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillPattern:(MGLStyleValue *)fillPattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillPattern); - self.layer->setFillPattern(mbglValue); + self.rawLayer->setFillPattern(mbglValue); } - (MGLStyleValue *)fillPattern { - auto propertyValue = self.layer->getFillPattern() ?: self.layer->getDefaultFillPattern(); + auto propertyValue = self.rawLayer->getFillPattern() ?: self.rawLayer->getDefaultFillPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 57724a060..aa699ea37 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,80 +12,86 @@ @interface MGLLineStyleLayer () -@property (nonatomic) mbgl::style::LineLayer *layer; +@property (nonatomic) mbgl::style::LineLayer *rawLayer; @end @implementation MGLLineStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::LineLayer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + - (NSString *)sourceLayerIdentifier { - auto layerID = self.layer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.layer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineCap); - self.layer->setLineCap(mbglValue); + self.rawLayer->setLineCap(mbglValue); } - (MGLStyleValue *)lineCap { - auto propertyValue = self.layer->getLineCap() ?: self.layer->getDefaultLineCap(); + auto propertyValue = self.rawLayer->getLineCap() ?: self.rawLayer->getDefaultLineCap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineJoin:(MGLStyleValue *)lineJoin { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineJoin); - self.layer->setLineJoin(mbglValue); + self.rawLayer->setLineJoin(mbglValue); } - (MGLStyleValue *)lineJoin { - auto propertyValue = self.layer->getLineJoin() ?: self.layer->getDefaultLineJoin(); + auto propertyValue = self.rawLayer->getLineJoin() ?: self.rawLayer->getDefaultLineJoin(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineMiterLimit:(MGLStyleValue *)lineMiterLimit { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineMiterLimit); - self.layer->setLineMiterLimit(mbglValue); + self.rawLayer->setLineMiterLimit(mbglValue); } - (MGLStyleValue *)lineMiterLimit { - auto propertyValue = self.layer->getLineMiterLimit() ?: self.layer->getDefaultLineMiterLimit(); + auto propertyValue = self.rawLayer->getLineMiterLimit() ?: self.rawLayer->getDefaultLineMiterLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineRoundLimit:(MGLStyleValue *)lineRoundLimit { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineRoundLimit); - self.layer->setLineRoundLimit(mbglValue); + self.rawLayer->setLineRoundLimit(mbglValue); } - (MGLStyleValue *)lineRoundLimit { - auto propertyValue = self.layer->getLineRoundLimit() ?: self.layer->getDefaultLineRoundLimit(); + auto propertyValue = self.rawLayer->getLineRoundLimit() ?: self.rawLayer->getDefaultLineRoundLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -92,102 +99,120 @@ - (void)setLineOpacity:(MGLStyleValue *)lineOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOpacity); - self.layer->setLineOpacity(mbglValue); + self.rawLayer->setLineOpacity(mbglValue); } - (MGLStyleValue *)lineOpacity { - auto propertyValue = self.layer->getLineOpacity() ?: self.layer->getDefaultLineOpacity(); + auto propertyValue = self.rawLayer->getLineOpacity() ?: self.rawLayer->getDefaultLineOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineColor:(MGLStyleValue *)lineColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineColor); - self.layer->setLineColor(mbglValue); + self.rawLayer->setLineColor(mbglValue); } - (MGLStyleValue *)lineColor { - auto propertyValue = self.layer->getLineColor() ?: self.layer->getDefaultLineColor(); + auto propertyValue = self.rawLayer->getLineColor() ?: self.rawLayer->getDefaultLineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineTranslate:(MGLStyleValue *)lineTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(lineTranslate); - self.layer->setLineTranslate(mbglValue); + self.rawLayer->setLineTranslate(mbglValue); } - (MGLStyleValue *)lineTranslate { - auto propertyValue = self.layer->getLineTranslate() ?: self.layer->getDefaultLineTranslate(); + auto propertyValue = self.rawLayer->getLineTranslate() ?: self.rawLayer->getDefaultLineTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setLineTranslateAnchor:(MGLStyleValue *)lineTranslateAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineTranslateAnchor); - self.layer->setLineTranslateAnchor(mbglValue); + self.rawLayer->setLineTranslateAnchor(mbglValue); } - (MGLStyleValue *)lineTranslateAnchor { - auto propertyValue = self.layer->getLineTranslateAnchor() ?: self.layer->getDefaultLineTranslateAnchor(); + auto propertyValue = self.rawLayer->getLineTranslateAnchor() ?: self.rawLayer->getDefaultLineTranslateAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineWidth:(MGLStyleValue *)lineWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineWidth); - self.layer->setLineWidth(mbglValue); + self.rawLayer->setLineWidth(mbglValue); } - (MGLStyleValue *)lineWidth { - auto propertyValue = self.layer->getLineWidth() ?: self.layer->getDefaultLineWidth(); + auto propertyValue = self.rawLayer->getLineWidth() ?: self.rawLayer->getDefaultLineWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineGapWidth:(MGLStyleValue *)lineGapWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineGapWidth); - self.layer->setLineGapWidth(mbglValue); + self.rawLayer->setLineGapWidth(mbglValue); } - (MGLStyleValue *)lineGapWidth { - auto propertyValue = self.layer->getLineGapWidth() ?: self.layer->getDefaultLineGapWidth(); + auto propertyValue = self.rawLayer->getLineGapWidth() ?: self.rawLayer->getDefaultLineGapWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineOffset:(MGLStyleValue *)lineOffset { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOffset); - self.layer->setLineOffset(mbglValue); + self.rawLayer->setLineOffset(mbglValue); } - (MGLStyleValue *)lineOffset { - auto propertyValue = self.layer->getLineOffset() ?: self.layer->getDefaultLineOffset(); + auto propertyValue = self.rawLayer->getLineOffset() ?: self.rawLayer->getDefaultLineOffset(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineBlur:(MGLStyleValue *)lineBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineBlur); - self.layer->setLineBlur(mbglValue); + self.rawLayer->setLineBlur(mbglValue); } - (MGLStyleValue *)lineBlur { - auto propertyValue = self.layer->getLineBlur() ?: self.layer->getDefaultLineBlur(); + auto propertyValue = self.rawLayer->getLineBlur() ?: self.rawLayer->getDefaultLineBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineDasharray:(MGLStyleValue *> *)lineDasharray { auto mbglValue = MGLStyleValueTransformer, NSArray *, float>().toPropertyValue(lineDasharray); - self.layer->setLineDasharray(mbglValue); + self.rawLayer->setLineDasharray(mbglValue); } - (MGLStyleValue *> *)lineDasharray { - auto propertyValue = self.layer->getLineDasharray() ?: self.layer->getDefaultLineDasharray(); + auto propertyValue = self.rawLayer->getLineDasharray() ?: self.rawLayer->getDefaultLineDasharray(); return MGLStyleValueTransformer, NSArray *, float>().toStyleValue(propertyValue); } - (void)setLinePattern:(MGLStyleValue *)linePattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(linePattern); - self.layer->setLinePattern(mbglValue); + self.rawLayer->setLinePattern(mbglValue); } - (MGLStyleValue *)linePattern { - auto propertyValue = self.layer->getLinePattern() ?: self.layer->getDefaultLinePattern(); + auto propertyValue = self.rawLayer->getLinePattern() ?: self.rawLayer->getDefaultLinePattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index f616e8951..ba1df40f9 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,90 +12,114 @@ @interface MGLRasterStyleLayer () -@property (nonatomic) mbgl::style::RasterLayer *layer; +@property (nonatomic) mbgl::style::RasterLayer *rawLayer; @end @implementation MGLRasterStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::RasterLayer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + #pragma mark - Accessing the Paint Attributes - (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterOpacity); - self.layer->setRasterOpacity(mbglValue); + self.rawLayer->setRasterOpacity(mbglValue); } - (MGLStyleValue *)rasterOpacity { - auto propertyValue = self.layer->getRasterOpacity() ?: self.layer->getDefaultRasterOpacity(); + auto propertyValue = self.rawLayer->getRasterOpacity() ?: self.rawLayer->getDefaultRasterOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterHueRotate:(MGLStyleValue *)rasterHueRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterHueRotate); - self.layer->setRasterHueRotate(mbglValue); + self.rawLayer->setRasterHueRotate(mbglValue); } - (MGLStyleValue *)rasterHueRotate { - auto propertyValue = self.layer->getRasterHueRotate() ?: self.layer->getDefaultRasterHueRotate(); + auto propertyValue = self.rawLayer->getRasterHueRotate() ?: self.rawLayer->getDefaultRasterHueRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterBrightnessMin:(MGLStyleValue *)rasterBrightnessMin { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMin); - self.layer->setRasterBrightnessMin(mbglValue); + self.rawLayer->setRasterBrightnessMin(mbglValue); } - (MGLStyleValue *)rasterBrightnessMin { - auto propertyValue = self.layer->getRasterBrightnessMin() ?: self.layer->getDefaultRasterBrightnessMin(); + auto propertyValue = self.rawLayer->getRasterBrightnessMin() ?: self.rawLayer->getDefaultRasterBrightnessMin(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterBrightnessMax:(MGLStyleValue *)rasterBrightnessMax { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMax); - self.layer->setRasterBrightnessMax(mbglValue); + self.rawLayer->setRasterBrightnessMax(mbglValue); } - (MGLStyleValue *)rasterBrightnessMax { - auto propertyValue = self.layer->getRasterBrightnessMax() ?: self.layer->getDefaultRasterBrightnessMax(); + auto propertyValue = self.rawLayer->getRasterBrightnessMax() ?: self.rawLayer->getDefaultRasterBrightnessMax(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterSaturation:(MGLStyleValue *)rasterSaturation { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterSaturation); - self.layer->setRasterSaturation(mbglValue); + self.rawLayer->setRasterSaturation(mbglValue); } - (MGLStyleValue *)rasterSaturation { - auto propertyValue = self.layer->getRasterSaturation() ?: self.layer->getDefaultRasterSaturation(); + auto propertyValue = self.rawLayer->getRasterSaturation() ?: self.rawLayer->getDefaultRasterSaturation(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterContrast:(MGLStyleValue *)rasterContrast { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterContrast); - self.layer->setRasterContrast(mbglValue); + self.rawLayer->setRasterContrast(mbglValue); } - (MGLStyleValue *)rasterContrast { - auto propertyValue = self.layer->getRasterContrast() ?: self.layer->getDefaultRasterContrast(); + auto propertyValue = self.rawLayer->getRasterContrast() ?: self.rawLayer->getDefaultRasterContrast(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterFadeDuration:(MGLStyleValue *)rasterFadeDuration { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterFadeDuration); - self.layer->setRasterFadeDuration(mbglValue); + self.rawLayer->setRasterFadeDuration(mbglValue); } - (MGLStyleValue *)rasterFadeDuration { - auto propertyValue = self.layer->getRasterFadeDuration() ?: self.layer->getDefaultRasterFadeDuration(); + auto propertyValue = self.rawLayer->getRasterFadeDuration() ?: self.rawLayer->getDefaultRasterFadeDuration(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index a17b7d6b7..d59194725 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -134,7 +134,7 @@ static NSURL *MGLStyleURL_emerald; return nil; } - styleLayer.layer = mbglLayer; + styleLayer.rawLayer = mbglLayer; return styleLayer; } @@ -173,26 +173,25 @@ static NSURL *MGLStyleURL_emerald; - (void)addLayer:(MGLStyleLayer *)layer { - if (!layer.layer) { + if (!layer.rawLayer) { [NSException raise:NSInvalidArgumentException format: @"The style layer %@ cannot be added to the style. " @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } - - self.mapView.mbglMap->addLayer(std::unique_ptr(layer.layer)); + [layer addToMapView:self.mapView]; } - (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer { - if (!layer.layer) { + if (!layer.rawLayer) { [NSException raise:NSInvalidArgumentException format: @"The style layer %@ cannot be added to the style. " @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } - if (!otherLayer.layer) { + if (!otherLayer.rawLayer) { [NSException raise:NSInvalidArgumentException format: @"A style layer cannot be placed before %@ in the style. " @@ -200,8 +199,7 @@ static NSURL *MGLStyleURL_emerald; otherLayer]; } - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - self.mapView.mbglMap->addLayer(std::unique_ptr(layer.layer), belowLayerId); + [layer addToMapView:self.mapView belowLayer:otherLayer]; } - (void)addSource:(MGLSource *)source diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 3678e9ec5..48d013d48 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -7,6 +7,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -16,50 +17,59 @@ @interface MGL<%- camelize(type) %>StyleLayer () -@property (nonatomic) mbgl::style::<%- camelize(type) %>Layer *layer; +@property (nonatomic) mbgl::style::<%- camelize(type) %>Layer *rawLayer; @end @implementation MGL<%- camelize(type) %>StyleLayer +{ + std::unique_ptrLayer> _pendingLayer; +} <% if (type == 'background') { -%> - (instancetype)initWithIdentifier:(NSString *)identifier { if (self = [super initWithIdentifier:identifier]) { - _layer = new mbgl::style::<%- camelize(type) %>Layer(identifier.UTF8String); + auto layer = std::make_uniqueLayer>(identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + <% } else { -%> - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::<%- camelize(type) %>Layer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_uniqueLayer>(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + <% } -%> <% if (type !== 'background' && type !== 'raster') { -%> - (NSString *)sourceLayerIdentifier { - auto layerID = self.layer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.layer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } <% } -%> @@ -69,11 +79,11 @@ <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - self.layer->set<%- camelize(property.name) %>(mbglValue); + self.rawLayer->set<%- camelize(property.name) %>(mbglValue); } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = self.layer->get<%- camelize(property.name) %>() ?: self.layer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = self.rawLayer->get<%- camelize(property.name) %>() ?: self.rawLayer->getDefault<%- camelize(property.name) %>(); return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); } @@ -85,14 +95,32 @@ <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - self.layer->set<%- camelize(property.name) %>(mbglValue); + self.rawLayer->set<%- camelize(property.name) %>(mbglValue); } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = self.layer->get<%- camelize(property.name) %>() ?: self.layer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = self.rawLayer->get<%- camelize(property.name) %>() ?: self.rawLayer->getDefault<%- camelize(property.name) %>(); return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); } <% } -%> <% } -%> + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index 5fa01856e..f61630b8c 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -5,9 +5,39 @@ #include +@class MGLMapView; + @interface MGLStyleLayer (Private) @property (nonatomic, readwrite, copy) NSString *identifier; -@property (nonatomic) mbgl::style::Layer *layer; + +/** + A raw pointer to the mbgl object, which is always initialized, either to the + value returned by `mbgl::Map getLayer`, or for independently created objects, + to the pointer value held in `pendingLayer`. In the latter case, this raw + pointer value stays even after ownership of the object is transferred via + `mbgl::Map addLayer`. + */ +@property (nonatomic) mbgl::style::Layer *rawLayer; + +/** + Adds the mbgl style layer that this object represents to the mbgl map. + + Once a mbgl style layer is added, ownership of the object is transferred to the + `mbgl::Map` and this object no longer has an active unique_ptr reference to the + `mbgl::style::Layer`. + */ +- (void)addToMapView:(MGLMapView *)mapView; + + + +/** + Adds the mbgl style layer that this object represents to the mbgl map below the specified `otherLayer`. + + Once a mbgl style layer is added, ownership of the object is transferred to the + `mbgl::Map` and this object no longer has an active unique_ptr reference to the + `mbgl::style::Layer`. + */ +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer; @end diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index a4c56fe29..539e0f2cc 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -2,6 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. #import "MGLSource.h" +#import "MGLMapView_Private.h" #import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" @@ -11,380 +12,386 @@ @interface MGLSymbolStyleLayer () -@property (nonatomic) mbgl::style::SymbolLayer *layer; +@property (nonatomic) mbgl::style::SymbolLayer *rawLayer; @end @implementation MGLSymbolStyleLayer +{ + std::unique_ptr _pendingLayer; +} - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source { if (self = [super initWithIdentifier:identifier source:source]) { - _layer = new mbgl::style::SymbolLayer(identifier.UTF8String, source.identifier.UTF8String); + auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); + _pendingLayer = std::move(layer); + self.rawLayer = _pendingLayer.get(); } return self; } + - (NSString *)sourceLayerIdentifier { - auto layerID = self.layer->getSourceLayer(); + auto layerID = self.rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.layer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.layer->setFilter(predicate.mgl_filter); + self.rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.layer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } #pragma mark - Accessing the Layout Attributes - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolPlacement); - self.layer->setSymbolPlacement(mbglValue); + self.rawLayer->setSymbolPlacement(mbglValue); } - (MGLStyleValue *)symbolPlacement { - auto propertyValue = self.layer->getSymbolPlacement() ?: self.layer->getDefaultSymbolPlacement(); + auto propertyValue = self.rawLayer->getSymbolPlacement() ?: self.rawLayer->getDefaultSymbolPlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolSpacing); - self.layer->setSymbolSpacing(mbglValue); + self.rawLayer->setSymbolSpacing(mbglValue); } - (MGLStyleValue *)symbolSpacing { - auto propertyValue = self.layer->getSymbolSpacing() ?: self.layer->getDefaultSymbolSpacing(); + auto propertyValue = self.rawLayer->getSymbolSpacing() ?: self.rawLayer->getDefaultSymbolSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setSymbolAvoidEdges:(MGLStyleValue *)symbolAvoidEdges { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolAvoidEdges); - self.layer->setSymbolAvoidEdges(mbglValue); + self.rawLayer->setSymbolAvoidEdges(mbglValue); } - (MGLStyleValue *)symbolAvoidEdges { - auto propertyValue = self.layer->getSymbolAvoidEdges() ?: self.layer->getDefaultSymbolAvoidEdges(); + auto propertyValue = self.rawLayer->getSymbolAvoidEdges() ?: self.rawLayer->getDefaultSymbolAvoidEdges(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconAllowOverlap:(MGLStyleValue *)iconAllowOverlap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconAllowOverlap); - self.layer->setIconAllowOverlap(mbglValue); + self.rawLayer->setIconAllowOverlap(mbglValue); } - (MGLStyleValue *)iconAllowOverlap { - auto propertyValue = self.layer->getIconAllowOverlap() ?: self.layer->getDefaultIconAllowOverlap(); + auto propertyValue = self.rawLayer->getIconAllowOverlap() ?: self.rawLayer->getDefaultIconAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconIgnorePlacement:(MGLStyleValue *)iconIgnorePlacement { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconIgnorePlacement); - self.layer->setIconIgnorePlacement(mbglValue); + self.rawLayer->setIconIgnorePlacement(mbglValue); } - (MGLStyleValue *)iconIgnorePlacement { - auto propertyValue = self.layer->getIconIgnorePlacement() ?: self.layer->getDefaultIconIgnorePlacement(); + auto propertyValue = self.rawLayer->getIconIgnorePlacement() ?: self.rawLayer->getDefaultIconIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOptional:(MGLStyleValue *)iconOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOptional); - self.layer->setIconOptional(mbglValue); + self.rawLayer->setIconOptional(mbglValue); } - (MGLStyleValue *)iconOptional { - auto propertyValue = self.layer->getIconOptional() ?: self.layer->getDefaultIconOptional(); + auto propertyValue = self.rawLayer->getIconOptional() ?: self.rawLayer->getDefaultIconOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotationAlignment); - self.layer->setIconRotationAlignment(mbglValue); + self.rawLayer->setIconRotationAlignment(mbglValue); } - (MGLStyleValue *)iconRotationAlignment { - auto propertyValue = self.layer->getIconRotationAlignment() ?: self.layer->getDefaultIconRotationAlignment(); + auto propertyValue = self.rawLayer->getIconRotationAlignment() ?: self.rawLayer->getDefaultIconRotationAlignment(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconSize:(MGLStyleValue *)iconSize { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconSize); - self.layer->setIconSize(mbglValue); + self.rawLayer->setIconSize(mbglValue); } - (MGLStyleValue *)iconSize { - auto propertyValue = self.layer->getIconSize() ?: self.layer->getDefaultIconSize(); + auto propertyValue = self.rawLayer->getIconSize() ?: self.rawLayer->getDefaultIconSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTextFit:(MGLStyleValue *)iconTextFit { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconTextFit); - self.layer->setIconTextFit(mbglValue); + self.rawLayer->setIconTextFit(mbglValue); } - (MGLStyleValue *)iconTextFit { - auto propertyValue = self.layer->getIconTextFit() ?: self.layer->getDefaultIconTextFit(); + auto propertyValue = self.rawLayer->getIconTextFit() ?: self.rawLayer->getDefaultIconTextFit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTextFitPadding:(MGLStyleValue *)iconTextFitPadding { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTextFitPadding); - self.layer->setIconTextFitPadding(mbglValue); + self.rawLayer->setIconTextFitPadding(mbglValue); } - (MGLStyleValue *)iconTextFitPadding { - auto propertyValue = self.layer->getIconTextFitPadding() ?: self.layer->getDefaultIconTextFitPadding(); + auto propertyValue = self.rawLayer->getIconTextFitPadding() ?: self.rawLayer->getDefaultIconTextFitPadding(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconImage:(MGLStyleValue *)iconImage { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconImage); - self.layer->setIconImage(mbglValue); + self.rawLayer->setIconImage(mbglValue); } - (MGLStyleValue *)iconImage { - auto propertyValue = self.layer->getIconImage() ?: self.layer->getDefaultIconImage(); + auto propertyValue = self.rawLayer->getIconImage() ?: self.rawLayer->getDefaultIconImage(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotate:(MGLStyleValue *)iconRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotate); - self.layer->setIconRotate(mbglValue); + self.rawLayer->setIconRotate(mbglValue); } - (MGLStyleValue *)iconRotate { - auto propertyValue = self.layer->getIconRotate() ?: self.layer->getDefaultIconRotate(); + auto propertyValue = self.rawLayer->getIconRotate() ?: self.rawLayer->getDefaultIconRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconPadding:(MGLStyleValue *)iconPadding { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconPadding); - self.layer->setIconPadding(mbglValue); + self.rawLayer->setIconPadding(mbglValue); } - (MGLStyleValue *)iconPadding { - auto propertyValue = self.layer->getIconPadding() ?: self.layer->getDefaultIconPadding(); + auto propertyValue = self.rawLayer->getIconPadding() ?: self.rawLayer->getDefaultIconPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconKeepUpright:(MGLStyleValue *)iconKeepUpright { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconKeepUpright); - self.layer->setIconKeepUpright(mbglValue); + self.rawLayer->setIconKeepUpright(mbglValue); } - (MGLStyleValue *)iconKeepUpright { - auto propertyValue = self.layer->getIconKeepUpright() ?: self.layer->getDefaultIconKeepUpright(); + auto propertyValue = self.rawLayer->getIconKeepUpright() ?: self.rawLayer->getDefaultIconKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOffset:(MGLStyleValue *)iconOffset { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconOffset); - self.layer->setIconOffset(mbglValue); + self.rawLayer->setIconOffset(mbglValue); } - (MGLStyleValue *)iconOffset { - auto propertyValue = self.layer->getIconOffset() ?: self.layer->getDefaultIconOffset(); + auto propertyValue = self.rawLayer->getIconOffset() ?: self.rawLayer->getDefaultIconOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPitchAlignment); - self.layer->setTextPitchAlignment(mbglValue); + self.rawLayer->setTextPitchAlignment(mbglValue); } - (MGLStyleValue *)textPitchAlignment { - auto propertyValue = self.layer->getTextPitchAlignment() ?: self.layer->getDefaultTextPitchAlignment(); + auto propertyValue = self.rawLayer->getTextPitchAlignment() ?: self.rawLayer->getDefaultTextPitchAlignment(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotationAlignment); - self.layer->setTextRotationAlignment(mbglValue); + self.rawLayer->setTextRotationAlignment(mbglValue); } - (MGLStyleValue *)textRotationAlignment { - auto propertyValue = self.layer->getTextRotationAlignment() ?: self.layer->getDefaultTextRotationAlignment(); + auto propertyValue = self.rawLayer->getTextRotationAlignment() ?: self.rawLayer->getDefaultTextRotationAlignment(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextField:(MGLStyleValue *)textField { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textField); - self.layer->setTextField(mbglValue); + self.rawLayer->setTextField(mbglValue); } - (MGLStyleValue *)textField { - auto propertyValue = self.layer->getTextField() ?: self.layer->getDefaultTextField(); + auto propertyValue = self.rawLayer->getTextField() ?: self.rawLayer->getDefaultTextField(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextFont:(MGLStyleValue *> *)textFont { auto mbglValue = MGLStyleValueTransformer, NSArray *, std::string>().toPropertyValue(textFont); - self.layer->setTextFont(mbglValue); + self.rawLayer->setTextFont(mbglValue); } - (MGLStyleValue *> *)textFont { - auto propertyValue = self.layer->getTextFont() ?: self.layer->getDefaultTextFont(); + auto propertyValue = self.rawLayer->getTextFont() ?: self.rawLayer->getDefaultTextFont(); return MGLStyleValueTransformer, NSArray *, std::string>().toStyleValue(propertyValue); } - (void)setTextSize:(MGLStyleValue *)textSize { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textSize); - self.layer->setTextSize(mbglValue); + self.rawLayer->setTextSize(mbglValue); } - (MGLStyleValue *)textSize { - auto propertyValue = self.layer->getTextSize() ?: self.layer->getDefaultTextSize(); + auto propertyValue = self.rawLayer->getTextSize() ?: self.rawLayer->getDefaultTextSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextMaxWidth:(MGLStyleValue *)textMaxWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxWidth); - self.layer->setTextMaxWidth(mbglValue); + self.rawLayer->setTextMaxWidth(mbglValue); } - (MGLStyleValue *)textMaxWidth { - auto propertyValue = self.layer->getTextMaxWidth() ?: self.layer->getDefaultTextMaxWidth(); + auto propertyValue = self.rawLayer->getTextMaxWidth() ?: self.rawLayer->getDefaultTextMaxWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLineHeight:(MGLStyleValue *)textLineHeight { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLineHeight); - self.layer->setTextLineHeight(mbglValue); + self.rawLayer->setTextLineHeight(mbglValue); } - (MGLStyleValue *)textLineHeight { - auto propertyValue = self.layer->getTextLineHeight() ?: self.layer->getDefaultTextLineHeight(); + auto propertyValue = self.rawLayer->getTextLineHeight() ?: self.rawLayer->getDefaultTextLineHeight(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLetterSpacing); - self.layer->setTextLetterSpacing(mbglValue); + self.rawLayer->setTextLetterSpacing(mbglValue); } - (MGLStyleValue *)textLetterSpacing { - auto propertyValue = self.layer->getTextLetterSpacing() ?: self.layer->getDefaultTextLetterSpacing(); + auto propertyValue = self.rawLayer->getTextLetterSpacing() ?: self.rawLayer->getDefaultTextLetterSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextJustify:(MGLStyleValue *)textJustify { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textJustify); - self.layer->setTextJustify(mbglValue); + self.rawLayer->setTextJustify(mbglValue); } - (MGLStyleValue *)textJustify { - auto propertyValue = self.layer->getTextJustify() ?: self.layer->getDefaultTextJustify(); + auto propertyValue = self.rawLayer->getTextJustify() ?: self.rawLayer->getDefaultTextJustify(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextAnchor:(MGLStyleValue *)textAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAnchor); - self.layer->setTextAnchor(mbglValue); + self.rawLayer->setTextAnchor(mbglValue); } - (MGLStyleValue *)textAnchor { - auto propertyValue = self.layer->getTextAnchor() ?: self.layer->getDefaultTextAnchor(); + auto propertyValue = self.rawLayer->getTextAnchor() ?: self.rawLayer->getDefaultTextAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextMaxAngle:(MGLStyleValue *)textMaxAngle { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxAngle); - self.layer->setTextMaxAngle(mbglValue); + self.rawLayer->setTextMaxAngle(mbglValue); } - (MGLStyleValue *)textMaxAngle { - auto propertyValue = self.layer->getTextMaxAngle() ?: self.layer->getDefaultTextMaxAngle(); + auto propertyValue = self.rawLayer->getTextMaxAngle() ?: self.rawLayer->getDefaultTextMaxAngle(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextRotate:(MGLStyleValue *)textRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotate); - self.layer->setTextRotate(mbglValue); + self.rawLayer->setTextRotate(mbglValue); } - (MGLStyleValue *)textRotate { - auto propertyValue = self.layer->getTextRotate() ?: self.layer->getDefaultTextRotate(); + auto propertyValue = self.rawLayer->getTextRotate() ?: self.rawLayer->getDefaultTextRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextPadding:(MGLStyleValue *)textPadding { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPadding); - self.layer->setTextPadding(mbglValue); + self.rawLayer->setTextPadding(mbglValue); } - (MGLStyleValue *)textPadding { - auto propertyValue = self.layer->getTextPadding() ?: self.layer->getDefaultTextPadding(); + auto propertyValue = self.rawLayer->getTextPadding() ?: self.rawLayer->getDefaultTextPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textKeepUpright); - self.layer->setTextKeepUpright(mbglValue); + self.rawLayer->setTextKeepUpright(mbglValue); } - (MGLStyleValue *)textKeepUpright { - auto propertyValue = self.layer->getTextKeepUpright() ?: self.layer->getDefaultTextKeepUpright(); + auto propertyValue = self.rawLayer->getTextKeepUpright() ?: self.rawLayer->getDefaultTextKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTransform:(MGLStyleValue *)textTransform { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textTransform); - self.layer->setTextTransform(mbglValue); + self.rawLayer->setTextTransform(mbglValue); } - (MGLStyleValue *)textTransform { - auto propertyValue = self.layer->getTextTransform() ?: self.layer->getDefaultTextTransform(); + auto propertyValue = self.rawLayer->getTextTransform() ?: self.rawLayer->getDefaultTextTransform(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOffset:(MGLStyleValue *)textOffset { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textOffset); - self.layer->setTextOffset(mbglValue); + self.rawLayer->setTextOffset(mbglValue); } - (MGLStyleValue *)textOffset { - auto propertyValue = self.layer->getTextOffset() ?: self.layer->getDefaultTextOffset(); + auto propertyValue = self.rawLayer->getTextOffset() ?: self.rawLayer->getDefaultTextOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAllowOverlap); - self.layer->setTextAllowOverlap(mbglValue); + self.rawLayer->setTextAllowOverlap(mbglValue); } - (MGLStyleValue *)textAllowOverlap { - auto propertyValue = self.layer->getTextAllowOverlap() ?: self.layer->getDefaultTextAllowOverlap(); + auto propertyValue = self.rawLayer->getTextAllowOverlap() ?: self.rawLayer->getDefaultTextAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textIgnorePlacement); - self.layer->setTextIgnorePlacement(mbglValue); + self.rawLayer->setTextIgnorePlacement(mbglValue); } - (MGLStyleValue *)textIgnorePlacement { - auto propertyValue = self.layer->getTextIgnorePlacement() ?: self.layer->getDefaultTextIgnorePlacement(); + auto propertyValue = self.rawLayer->getTextIgnorePlacement() ?: self.rawLayer->getDefaultTextIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOptional:(MGLStyleValue *)textOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOptional); - self.layer->setTextOptional(mbglValue); + self.rawLayer->setTextOptional(mbglValue); } - (MGLStyleValue *)textOptional { - auto propertyValue = self.layer->getTextOptional() ?: self.layer->getDefaultTextOptional(); + auto propertyValue = self.rawLayer->getTextOptional() ?: self.rawLayer->getDefaultTextOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -392,142 +399,160 @@ - (void)setIconOpacity:(MGLStyleValue *)iconOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOpacity); - self.layer->setIconOpacity(mbglValue); + self.rawLayer->setIconOpacity(mbglValue); } - (MGLStyleValue *)iconOpacity { - auto propertyValue = self.layer->getIconOpacity() ?: self.layer->getDefaultIconOpacity(); + auto propertyValue = self.rawLayer->getIconOpacity() ?: self.rawLayer->getDefaultIconOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconColor:(MGLStyleValue *)iconColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconColor); - self.layer->setIconColor(mbglValue); + self.rawLayer->setIconColor(mbglValue); } - (MGLStyleValue *)iconColor { - auto propertyValue = self.layer->getIconColor() ?: self.layer->getDefaultIconColor(); + auto propertyValue = self.rawLayer->getIconColor() ?: self.rawLayer->getDefaultIconColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloColor:(MGLStyleValue *)iconHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloColor); - self.layer->setIconHaloColor(mbglValue); + self.rawLayer->setIconHaloColor(mbglValue); } - (MGLStyleValue *)iconHaloColor { - auto propertyValue = self.layer->getIconHaloColor() ?: self.layer->getDefaultIconHaloColor(); + auto propertyValue = self.rawLayer->getIconHaloColor() ?: self.rawLayer->getDefaultIconHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloWidth:(MGLStyleValue *)iconHaloWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloWidth); - self.layer->setIconHaloWidth(mbglValue); + self.rawLayer->setIconHaloWidth(mbglValue); } - (MGLStyleValue *)iconHaloWidth { - auto propertyValue = self.layer->getIconHaloWidth() ?: self.layer->getDefaultIconHaloWidth(); + auto propertyValue = self.rawLayer->getIconHaloWidth() ?: self.rawLayer->getDefaultIconHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloBlur:(MGLStyleValue *)iconHaloBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloBlur); - self.layer->setIconHaloBlur(mbglValue); + self.rawLayer->setIconHaloBlur(mbglValue); } - (MGLStyleValue *)iconHaloBlur { - auto propertyValue = self.layer->getIconHaloBlur() ?: self.layer->getDefaultIconHaloBlur(); + auto propertyValue = self.rawLayer->getIconHaloBlur() ?: self.rawLayer->getDefaultIconHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTranslate:(MGLStyleValue *)iconTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTranslate); - self.layer->setIconTranslate(mbglValue); + self.rawLayer->setIconTranslate(mbglValue); } - (MGLStyleValue *)iconTranslate { - auto propertyValue = self.layer->getIconTranslate() ?: self.layer->getDefaultIconTranslate(); + auto propertyValue = self.rawLayer->getIconTranslate() ?: self.rawLayer->getDefaultIconTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconTranslateAnchor:(MGLStyleValue *)iconTranslateAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconTranslateAnchor); - self.layer->setIconTranslateAnchor(mbglValue); + self.rawLayer->setIconTranslateAnchor(mbglValue); } - (MGLStyleValue *)iconTranslateAnchor { - auto propertyValue = self.layer->getIconTranslateAnchor() ?: self.layer->getDefaultIconTranslateAnchor(); + auto propertyValue = self.rawLayer->getIconTranslateAnchor() ?: self.rawLayer->getDefaultIconTranslateAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOpacity:(MGLStyleValue *)textOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOpacity); - self.layer->setTextOpacity(mbglValue); + self.rawLayer->setTextOpacity(mbglValue); } - (MGLStyleValue *)textOpacity { - auto propertyValue = self.layer->getTextOpacity() ?: self.layer->getDefaultTextOpacity(); + auto propertyValue = self.rawLayer->getTextOpacity() ?: self.rawLayer->getDefaultTextOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextColor:(MGLStyleValue *)textColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textColor); - self.layer->setTextColor(mbglValue); + self.rawLayer->setTextColor(mbglValue); } - (MGLStyleValue *)textColor { - auto propertyValue = self.layer->getTextColor() ?: self.layer->getDefaultTextColor(); + auto propertyValue = self.rawLayer->getTextColor() ?: self.rawLayer->getDefaultTextColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloColor:(MGLStyleValue *)textHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloColor); - self.layer->setTextHaloColor(mbglValue); + self.rawLayer->setTextHaloColor(mbglValue); } - (MGLStyleValue *)textHaloColor { - auto propertyValue = self.layer->getTextHaloColor() ?: self.layer->getDefaultTextHaloColor(); + auto propertyValue = self.rawLayer->getTextHaloColor() ?: self.rawLayer->getDefaultTextHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloWidth:(MGLStyleValue *)textHaloWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloWidth); - self.layer->setTextHaloWidth(mbglValue); + self.rawLayer->setTextHaloWidth(mbglValue); } - (MGLStyleValue *)textHaloWidth { - auto propertyValue = self.layer->getTextHaloWidth() ?: self.layer->getDefaultTextHaloWidth(); + auto propertyValue = self.rawLayer->getTextHaloWidth() ?: self.rawLayer->getDefaultTextHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloBlur:(MGLStyleValue *)textHaloBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloBlur); - self.layer->setTextHaloBlur(mbglValue); + self.rawLayer->setTextHaloBlur(mbglValue); } - (MGLStyleValue *)textHaloBlur { - auto propertyValue = self.layer->getTextHaloBlur() ?: self.layer->getDefaultTextHaloBlur(); + auto propertyValue = self.rawLayer->getTextHaloBlur() ?: self.rawLayer->getDefaultTextHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTranslate:(MGLStyleValue *)textTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textTranslate); - self.layer->setTextTranslate(mbglValue); + self.rawLayer->setTextTranslate(mbglValue); } - (MGLStyleValue *)textTranslate { - auto propertyValue = self.layer->getTextTranslate() ?: self.layer->getDefaultTextTranslate(); + auto propertyValue = self.rawLayer->getTextTranslate() ?: self.rawLayer->getDefaultTextTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextTranslateAnchor:(MGLStyleValue *)textTranslateAnchor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textTranslateAnchor); - self.layer->setTextTranslateAnchor(mbglValue); + self.rawLayer->setTextTranslateAnchor(mbglValue); } - (MGLStyleValue *)textTranslateAnchor { - auto propertyValue = self.layer->getTextTranslateAnchor() ?: self.layer->getDefaultTextTranslateAnchor(); + auto propertyValue = self.rawLayer->getTextTranslateAnchor() ?: self.rawLayer->getDefaultTextTranslateAnchor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } + +#pragma mark - Add style layer to map + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + @end diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index a7ea42930..11247ea3f 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -769,6 +769,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source]; fillLayer.fillColor = [MGLStyleValue valueWithRawValue:[UIColor purpleColor]]; [self.mapView.style addLayer:fillLayer]; + } - (void)styleSymbolLayer From 5e65d8109a3716ef028a33a755be5ed2bf0e6959 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 8 Nov 2016 13:32:58 -0800 Subject: [PATCH 05/67] [ios, macos] Use the rawLayer pointer to access the mbgl layer (#6966) A previous refactor neglected to remove the unused `layer` property. This removes that property and uses the rawLayer property that actually points to the mbgl layer. --- platform/darwin/src/MGLStyleLayer.mm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm index 293aa54f3..7f29041f8 100644 --- a/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/darwin/src/MGLStyleLayer.mm @@ -5,8 +5,6 @@ @interface MGLStyleLayer () -@property (nonatomic) mbgl::style::Layer *layer; - @end @implementation MGLStyleLayer @@ -24,33 +22,33 @@ mbgl::style::VisibilityType v = visible ? mbgl::style::VisibilityType::Visible : mbgl::style::VisibilityType::None; - self.layer->setVisibility(v); + self.rawLayer->setVisibility(v); } - (BOOL)isVisible { - mbgl::style::VisibilityType v = self.layer->getVisibility(); + mbgl::style::VisibilityType v = self.rawLayer->getVisibility(); return (v == mbgl::style::VisibilityType::Visible); } - (void)setMaximumZoomLevel:(float)maximumZoomLevel { - self.layer->setMaxZoom(maximumZoomLevel); + self.rawLayer->setMaxZoom(maximumZoomLevel); } - (float)maximumZoomLevel { - return self.layer->getMaxZoom(); + return self.rawLayer->getMaxZoom(); } - (void)setMinimumZoomLevel:(float)minimumZoomLevel { - self.layer->setMinZoom(minimumZoomLevel); + self.rawLayer->setMinZoom(minimumZoomLevel); } - (float)minimumZoomLevel { - return self.layer->getMinZoom(); + return self.rawLayer->getMinZoom(); } @end From b91bbbef10525ba183f3ba23ffe9e57ed829db21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 7 Nov 2016 23:00:55 -0800 Subject: [PATCH 06/67] [macos] Map annotations to annotation tags Optimized lookup of annotation tags by annotation from O(n) to a simple map lookup, for better performance and consistency with the iOS implementation of MGLMapView. --- platform/macos/src/MGLMapView.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 6679aaaa6..bacba265f 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -35,6 +35,7 @@ #import #import +#import #import #import @@ -110,6 +111,9 @@ enum { MGLAnnotationTagNotFound = UINT32_MAX }; /// the annotation itself. typedef std::unordered_map MGLAnnotationTagContextMap; +/// Mapping from an annotation object to an annotation tag. +typedef std::map, MGLAnnotationTag> MGLAnnotationObjectTagMap; + /// Returns an NSImage for the default marker image. NSImage *MGLDefaultMarkerImage() { NSString *path = [[NSBundle mgl_frameworkBundle] pathForResource:MGLDefaultStyleMarkerSymbolName @@ -172,6 +176,7 @@ public: BOOL _didHideCursorDuringGesture; MGLAnnotationTagContextMap _annotationContextsByAnnotationTag; + MGLAnnotationObjectTagMap _annotationTagsByAnnotation; MGLAnnotationTag _selectedAnnotationTag; MGLAnnotationTag _lastSelectedAnnotationTag; /// Size of the rectangle formed by unioning the maximum slop area around every annotation image. @@ -293,6 +298,7 @@ public: // Set up annotation management and selection state. _annotationImagesByIdentifier = [NSMutableDictionary dictionary]; _annotationContextsByAnnotationTag = {}; + _annotationTagsByAnnotation = {}; _selectedAnnotationTag = MGLAnnotationTagNotFound; _lastSelectedAnnotationTag = MGLAnnotationTagNotFound; _annotationsNearbyLastClick = {}; @@ -1708,6 +1714,7 @@ public: MGLAnnotationContext context; context.annotation = annotation; _annotationContextsByAnnotationTag[annotationTag] = context; + _annotationTagsByAnnotation[annotation] = annotationTag; [(NSObject *)annotation addObserver:self forKeyPath:@"coordinates" options:0 context:(void *)(NSUInteger)annotationTag]; } else if (![annotation isKindOfClass:[MGLMultiPolyline class]] @@ -1745,6 +1752,7 @@ public: context.annotation = annotation; context.imageReuseIdentifier = annotationImage.reuseIdentifier; _annotationContextsByAnnotationTag[annotationTag] = context; + _annotationTagsByAnnotation[annotation] = annotationTag; if ([annotation isKindOfClass:[NSObject class]]) { NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint."); @@ -1831,6 +1839,7 @@ public: } _annotationContextsByAnnotationTag.erase(annotationTag); + _annotationTagsByAnnotation.erase(annotation); if ([annotation isKindOfClass:[NSObject class]] && ![annotation isKindOfClass:[MGLMultiPoint class]]) { From f2ba2b2deea7f832e575db652851dc7f5787309d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 7 Nov 2016 23:04:52 -0800 Subject: [PATCH 07/67] [ios, macos] Fixed crash getting annotation view Streamlined -[MGLMapView annotationTagForAnnotation:] to use the mapping added in #5987. Reverted an unsafe access into that mapping that was added in #5987; returning nil is preferable when no such annotation can be found. Return the user location annotation view when given the user location annotation. --- platform/ios/src/MGLMapView.mm | 32 +++++++++++++++++--------------- platform/macos/src/MGLMapView.mm | 9 ++------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 00d2425a4..39f243f57 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2865,19 +2865,13 @@ public: /// Returns the annotation tag assigned to the given annotation. Relatively expensive. - (MGLAnnotationTag)annotationTagForAnnotation:(id )annotation { - if ( ! annotation || annotation == self.userLocation) + if ( ! annotation || annotation == self.userLocation + || _annotationTagsByAnnotation.count(annotation) == 0) { return MGLAnnotationTagNotFound; } - - for (auto &pair : _annotationContextsByAnnotationTag) - { - if (pair.second.annotation == annotation) - { - return pair.first; - } - } - return MGLAnnotationTagNotFound; + + return _annotationTagsByAnnotation.at(annotation); } - (void)addAnnotation:(id )annotation @@ -3101,7 +3095,14 @@ public: - (nullable MGLAnnotationView *)viewForAnnotation:(id)annotation { - MGLAnnotationTag annotationTag = _annotationTagsByAnnotation.at(annotation); + if (annotation == self.userLocation) + { + return self.userLocationAnnotationView; + } + MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation]; + if (annotationTag == MGLAnnotationTagNotFound) { + return nil; + } MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); return annotationContext.annotationView; } @@ -4675,9 +4676,9 @@ public: continue; } - // Get the annotation tag then use it to get the context. This avoids the expensive lookup - // by tag in `annotationTagForAnnotation:` - MGLAnnotationTag annotationTag = _annotationTagsByAnnotation.at(annotation); + // Get the annotation tag then use it to get the context. + MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation]; + NSAssert(annotationTag != MGLAnnotationTagNotFound, @"-visibleAnnotationsInRect: returned unrecognized annotation"); MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); MGLAnnotationView *annotationView = annotationContext.annotationView; @@ -4721,7 +4722,8 @@ public: continue; } - MGLAnnotationTag annotationTag = _annotationTagsByAnnotation.at(annotation); + MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation]; + NSAssert(annotationTag != MGLAnnotationTagNotFound, @"-visibleAnnotationsInRect: returned unrecognized annotation"); MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); UIView *annotationView = annotationContext.annotationView; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index bacba265f..c50d3d564 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1667,16 +1667,11 @@ public: /// Returns the annotation tag assigned to the given annotation. Relatively expensive. - (MGLAnnotationTag)annotationTagForAnnotation:(id )annotation { - if (!annotation) { + if (!annotation || _annotationTagsByAnnotation.count(annotation) == 0) { return MGLAnnotationTagNotFound; } - for (auto &pair : _annotationContextsByAnnotationTag) { - if (pair.second.annotation == annotation) { - return pair.first; - } - } - return MGLAnnotationTagNotFound; + return _annotationTagsByAnnotation.at(annotation); } - (void)addAnnotation:(id )annotation { From 9edda03157ca240fc4eead996981db194bd0023f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 8 Nov 2016 16:39:30 -0800 Subject: [PATCH 08/67] [core] Ensure correct GL context in Map::onLowMemory() --- src/mbgl/map/map.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 7b5802638..903f90c54 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -1015,7 +1015,9 @@ void Map::setSourceTileCacheSize(size_t size) { void Map::onLowMemory() { if (impl->painter) { + impl->backend.activate(); impl->painter->cleanup(); + impl->backend.deactivate(); } if (impl->style) { impl->style->onLowMemory(); From 9de8279438ed92e7259702c7392087a8e3cd46e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Fri, 11 Nov 2016 22:12:25 -0800 Subject: [PATCH 09/67] [ios, macos] 3.4.0/0.3.0 sections in changelogs --- platform/ios/CHANGELOG.md | 2 +- platform/macos/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b552deccb..f5b10ed30 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,7 +2,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. -## master +## 3.4.0 ### Packaging diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 9f08e5de9..82d4b3b28 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for Mapbox macOS SDK -## master +## 0.3.0 ### Packaging From 870d432f34cee2fff2c0b06ddf6d9ac330253cd9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 4 Nov 2016 13:00:41 -0700 Subject: [PATCH 10/67] [core] Separate pathway for notifying workers of new images/glyphs --- package.json | 2 +- src/mbgl/style/source_impl.cpp | 6 +++ src/mbgl/style/source_impl.hpp | 12 ++++-- src/mbgl/style/style.cpp | 11 +++++- src/mbgl/style/style.hpp | 1 + src/mbgl/tile/geometry_tile.cpp | 4 ++ src/mbgl/tile/geometry_tile.hpp | 1 + src/mbgl/tile/geometry_tile_worker.cpp | 51 ++++++++++++++++++++++---- src/mbgl/tile/geometry_tile_worker.hpp | 2 + src/mbgl/tile/tile.hpp | 1 + 10 files changed, 78 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index de2f6ff39..29a7e7cf1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lodash": "^4.16.4", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#98a56d538b11fb331aa67a6d632d6ecd6821b007", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#844ecd23c3314eec509dbcdaf0f956d5504e6fef", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#10a135f01b56989aa03686de94cc67c3efa6139d", "mkdirp": "^0.5.1", "node-cmake": "^1.2.1", "request": "^2.72.0", diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 1fb6d59f0..73fc30d2d 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -172,6 +172,12 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { } } +void Source::Impl::updateSymbolDependentTiles() { + for (auto& pair : tiles) { + pair.second->symbolDependenciesChanged(); + } +} + void Source::Impl::reloadTiles() { cache.clear(); diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index 14ed9cd01..a4dd48444 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -43,11 +43,17 @@ public: virtual void loadDescription(FileSource&) = 0; bool isLoaded() const; - // Called when the camera has changed or icons or glyphs are loaded. May load new - // tiles, unload obsolete tiles, and trigger further parsing of incomplete tiles or - // re-placement of existing complete tiles. + // Called when the camera has changed. May load new tiles, unload obsolete tiles, or + // trigger re-placement of existing complete tiles. void updateTiles(const UpdateParameters&); + // Called when icons or glyphs are loaded. Triggers further processing of tiles which + // were waiting on such dependencies. + void updateSymbolDependentTiles(); + + // Removes all tiles (by putting them into the cache). + void removeTiles(); + // Request that all loaded tiles re-run the layout operation on the existing source // data with fresh style information. void reloadTiles(); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index e1cbe56bc..fbe28e179 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -218,6 +218,12 @@ void Style::updateTiles(const UpdateParameters& parameters) { } } +void Style::updateSymbolDependentTiles() { + for (const auto& source : sources) { + source->baseImpl->updateSymbolDependentTiles(); + } +} + void Style::relayout() { for (const auto& sourceID : updateBatch.sourceIDs) { Source* source = getSource(sourceID); @@ -463,7 +469,7 @@ void Style::setObserver(style::Observer* observer_) { void Style::onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) { observer->onGlyphsLoaded(fontStack, glyphRange); - observer->onUpdate(Update::Repaint); + updateSymbolDependentTiles(); } void Style::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { @@ -513,7 +519,8 @@ void Style::onTileError(Source& source, const OverscaledTileID& tileID, std::exc void Style::onSpriteLoaded() { observer->onSpriteLoaded(); - observer->onUpdate(Update::Repaint); + observer->onUpdate(Update::Repaint); // For *-pattern properties. + updateSymbolDependentTiles(); } void Style::onSpriteError(std::exception_ptr error) { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 21b25857d..14aef5de4 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -121,6 +121,7 @@ private: std::vector>::const_iterator findLayer(const std::string& layerID) const; void reloadLayerSource(Layer&); + void updateSymbolDependentTiles(); // GlyphStoreObserver implementation. void onGlyphsLoaded(const FontStack&, const GlyphRange&) override; diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 46e2b414f..c77467ebc 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -65,6 +65,10 @@ void GeometryTile::setPlacementConfig(const PlacementConfig& desiredConfig) { worker.invoke(&GeometryTileWorker::setPlacementConfig, desiredConfig, correlationID); } +void GeometryTile::symbolDependenciesChanged() { + worker.invoke(&GeometryTileWorker::symbolDependenciesChanged); +} + void GeometryTile::redoLayout() { // Mark the tile as pending again if it was complete before to prevent signaling a complete // state despite pending parse operations. diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index bcc71480a..cb3ca5463 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -35,6 +35,7 @@ public: void setData(std::unique_ptr); void setPlacementConfig(const PlacementConfig&) override; + void symbolDependenciesChanged() override; void redoLayout() override; Bucket* getBucket(const style::Layer&) override; diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index b6f166be5..6ff3c6779 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -42,13 +42,13 @@ GeometryTileWorker::~GeometryTileWorker() { States are indicated by [state], lines are transitions triggered by messages, (parentheses) are actions taken on transition. - [idle] <------------------. - | | - set{Data,Layers,Placement} | - | | - (do layout/placement; self-send "coalesced") | - v | - [coalescing] --- coalesced --. + [idle] <----------------------------. + | | + set{Data,Layers,Placement}, symbolDependenciesChanged | + | | + (do layout/placement; self-send "coalesced") | + v | + [coalescing] --- coalesced ------------. | | .-----------------. .---------------. | | @@ -140,6 +140,31 @@ void GeometryTileWorker::setPlacementConfig(PlacementConfig placementConfig_, ui } } +void GeometryTileWorker::symbolDependenciesChanged() { + try { + switch (state) { + case Idle: + if (hasPendingSymbolDependencies()) { + attemptPlacement(); + coalesce(); + } + break; + + case Coalescing: + if (hasPendingSymbolDependencies()) { + state = NeedPlacement; + } + break; + + case NeedPlacement: + case NeedLayout: + break; + } + } catch (...) { + parent.invoke(&GeometryTile::onError, std::current_exception()); + } +} + void GeometryTileWorker::coalesced() { try { switch (state) { @@ -238,6 +263,18 @@ void GeometryTileWorker::redoLayout() { attemptPlacement(); } +bool GeometryTileWorker::hasPendingSymbolDependencies() const { + bool result = false; + + for (const auto& symbolLayout : symbolLayouts) { + if (symbolLayout->state == SymbolLayout::Pending) { + result = true; + } + } + + return result; +} + void GeometryTileWorker::attemptPlacement() { if (!data || !layers || !placementConfig) { return; diff --git a/src/mbgl/tile/geometry_tile_worker.hpp b/src/mbgl/tile/geometry_tile_worker.hpp index d55b29702..58b5e23cf 100644 --- a/src/mbgl/tile/geometry_tile_worker.hpp +++ b/src/mbgl/tile/geometry_tile_worker.hpp @@ -34,12 +34,14 @@ public: void setLayers(std::vector>, uint64_t correlationID); void setData(std::unique_ptr, uint64_t correlationID); void setPlacementConfig(PlacementConfig, uint64_t correlationID); + void symbolDependenciesChanged(); private: void coalesce(); void coalesced(); void redoLayout(); void attemptPlacement(); + bool hasPendingSymbolDependencies() const; ActorRef self; ActorRef parent; diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 949bc0e33..eea89bd63 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -48,6 +48,7 @@ public: virtual Bucket* getBucket(const style::Layer&) = 0; virtual void setPlacementConfig(const PlacementConfig&) {} + virtual void symbolDependenciesChanged() {}; virtual void redoLayout() {} virtual void queryRenderedFeatures( From 5dcf7ca18ef1cfdf3f91afd08da73e317eeda67a Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Nov 2016 01:59:24 +0200 Subject: [PATCH 11/67] [linux] Added OSMesa headless backend --- CMakeLists.txt | 5 ++ Makefile | 3 +- include/mbgl/gl/implementation.hpp | 2 + .../platform/default/headless_backend.hpp | 7 +++ platform/default/headless_backend_osmesa.cpp | 47 +++++++++++++++++++ platform/linux/config.cmake | 31 ++++++++++-- 6 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 platform/default/headless_backend_osmesa.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9169dea81..5e99f8031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,16 @@ include(.mason/mason.cmake) option(WITH_CXX11ABI "Use cxx11abi mason packages" OFF) option(WITH_COVERAGE "Enable coverage reports" OFF) +option(WITH_OSMESA "Use OSMesa headless backend" OFF) if(WITH_CXX11ABI) set(MASON_CXXABI_SUFFIX -cxx11abi) endif() +if(WITH_OSMESA) + add_compile_options(-D__OSMESA__) +endif() + mason_use(geometry VERSION 0.8.0 HEADER_ONLY) mason_use(variant VERSION 1.1.0 HEADER_ONLY) mason_use(unique_resource VERSION dev HEADER_ONLY) diff --git a/Makefile b/Makefile index 1415d4f07..29acc367f 100644 --- a/Makefile +++ b/Makefile @@ -291,7 +291,8 @@ $(LINUX_BUILD): $(BUILD_DEPS) -DCMAKE_BUILD_TYPE=$(BUILDTYPE) \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DWITH_CXX11ABI=$(shell scripts/check-cxx11abi.sh) \ - -DWITH_COVERAGE=${WITH_COVERAGE}) + -DWITH_COVERAGE=${WITH_COVERAGE} \ + -DWITH_OSMESA=${WITH_OSMESA}) .PHONY: linux linux: glfw-app render offline diff --git a/include/mbgl/gl/implementation.hpp b/include/mbgl/gl/implementation.hpp index 4e3a3e51c..a0101085f 100644 --- a/include/mbgl/gl/implementation.hpp +++ b/include/mbgl/gl/implementation.hpp @@ -9,6 +9,8 @@ #else #define MBGL_USE_CGL 1 #endif +#elif defined(__OSMESA__) + #define MBGL_USE_OSMESA 1 #else #define MBGL_USE_GLX 1 #endif diff --git a/include/mbgl/platform/default/headless_backend.hpp b/include/mbgl/platform/default/headless_backend.hpp index 2f4886a36..b6c654943 100644 --- a/include/mbgl/platform/default/headless_backend.hpp +++ b/include/mbgl/platform/default/headless_backend.hpp @@ -12,6 +12,8 @@ typedef struct __GLXcontextRec* GLXContext; typedef struct __GLXFBConfigRec* GLXFBConfig; typedef long unsigned int XID; typedef XID GLXPbuffer; +#elif MBGL_USE_OSMESA +#include #endif #include @@ -71,6 +73,11 @@ private: GLXPbuffer glxPbuffer = 0; #endif +#if MBGL_USE_OSMESA + OSMesaContext glContext = nullptr; + GLubyte fakeBuffer = 0; +#endif + std::function mapChangeCallback; }; diff --git a/platform/default/headless_backend_osmesa.cpp b/platform/default/headless_backend_osmesa.cpp new file mode 100644 index 000000000..e0e385fcc --- /dev/null +++ b/platform/default/headless_backend_osmesa.cpp @@ -0,0 +1,47 @@ +#include +#include + +namespace mbgl { + +gl::glProc HeadlessBackend::initializeExtension(const char* name) { + return OSMesaGetProcAddress(name); +} + +void HeadlessBackend::createContext() { + if (glContext == nullptr) { +#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 + glContext = OSMesaCreateContextExt(OSMESA_RGBA, 16, 0, 0, nullptr); +#else + glContext = OSMesaCreateContext(OSMESA_RGBA, nullptr); +#endif + if (glContext == nullptr) { + Log::Error(Event::OpenGL, "failed to create OSMesa context"); + } + } + + if (glContext == nullptr) { + throw std::runtime_error("Error creating GL context object."); + } +} + +void HeadlessBackend::destroyContext() { + if (glContext) { + if (glContext != OSMesaGetCurrentContext()) { + activateContext(); + } + OSMesaDestroyContext(glContext); + glContext = nullptr; + } +} + +void HeadlessBackend::activateContext() { + if (!OSMesaMakeCurrent(glContext, &fakeBuffer, GL_UNSIGNED_BYTE, 1, 1)) { + throw std::runtime_error("Switching OpenGL context failed.\n"); + } +} + +void HeadlessBackend::deactivateContext() { + // no-op. +} + +} // namespace mbgl diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 6bde3136f..e8de73783 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -1,4 +1,5 @@ mason_use(glfw VERSION 3.2.1) +mason_use(mesa VERSION 13.0.0) mason_use(boost_libprogram_options VERSION 1.60.0) mason_use(sqlite VERSION 3.14.2) mason_use(libuv VERSION 1.9.1) @@ -11,7 +12,34 @@ mason_use(benchmark VERSION 1.0.0) include(cmake/loop-uv.cmake) +macro(use_glx_backend _TARGET) + target_sources(${_TARGET} + PRIVATE platform/default/headless_backend_glx.cpp + ) + + target_link_libraries(${_TARGET} + PUBLIC -lGL + PUBLIC -lX11 + ) +endmacro() + +macro(use_osmesa_backend _TARGET) + target_sources(${_TARGET} + PRIVATE platform/default/headless_backend_osmesa.cpp + ) + + target_add_mason_package(${_TARGET} + PUBLIC mesa + ) +endmacro() + macro(mbgl_platform_core) + if (WITH_OSMESA) + use_osmesa_backend(mbgl-core) + else() + use_glx_backend(mbgl-core) + endif() + target_sources(mbgl-core # File source PRIVATE platform/default/asset_file_source.cpp @@ -41,7 +69,6 @@ macro(mbgl_platform_core) PRIVATE platform/default/webp_reader.cpp # Headless view - PRIVATE platform/default/headless_backend_glx.cpp PRIVATE platform/default/headless_backend.cpp PRIVATE platform/default/headless_display.cpp PRIVATE platform/default/offscreen_view.cpp @@ -63,8 +90,6 @@ macro(mbgl_platform_core) target_link_libraries(mbgl-core PUBLIC -lz PUBLIC -lcurl - PUBLIC -lGL - PUBLIC -lX11 ) endmacro() From 1b2379509742d4bc5e77ee78df0d66e1ff7077cd Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Nov 2016 16:46:58 +0200 Subject: [PATCH 12/67] [linux] Update target headless backends Enable OSMesa backend via WITH_OSMESA=1 envvar. OSMesa backend uses Gallium OSMesa implementation, which uses LLVMpipe as default driver. --- .mason | 2 +- .travis.yml | 5 ++--- scripts/travis_setup.sh | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.mason b/.mason index 48ea4761b..4279f5878 160000 --- a/.mason +++ b/.mason @@ -1 +1 @@ -Subproject commit 48ea4761bd386f9113397a4366d63e83e3586644 +Subproject commit 4279f58787acba8286789f861cf7c3c4ce47d522 diff --git a/.travis.yml b/.travis.yml index 6c749acfd..25744e128 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons_shortcuts: addons_clang35: &clang35 apt: sources: [ 'ubuntu-toolchain-r-test', 'george-edison55-precise-backports' ] - packages: [ 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'cmake', 'cmake-data', + packages: [ 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.8v4', 'cmake', 'cmake-data', 'mesa-utils', 'libxi-dev', 'libglu1-mesa-dev', 'x11proto-randr-dev', 'x11proto-xext-dev', 'libxrandr-dev', 'x11proto-xf86vidmode-dev', 'libxxf86vm-dev', 'libxcursor-dev', 'libxinerama-dev' ] addons_gcc5: &gcc5 @@ -46,7 +46,6 @@ before_script: script: - make linux - make benchmark - - make test - make run-test after_script: - ccache --show-stats @@ -60,7 +59,7 @@ matrix: dist: trusty language: node compiler: "node4-clang35-debug" - env: _CXX=clang++-3.5 _CC=clang-3.5 + env: _CXX=clang++-3.5 _CC=clang-3.5 WITH_OSMESA=1 addons: *clang35 before_script: - export PACKAGE_JSON_VERSION=$(node -e "console.log(require('./package.json').version)") diff --git a/scripts/travis_setup.sh b/scripts/travis_setup.sh index ae8dda46b..6fa1cc858 100755 --- a/scripts/travis_setup.sh +++ b/scripts/travis_setup.sh @@ -30,16 +30,6 @@ ${CXX} --version # Ensure mason is on the PATH export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason" -# Start the mock X server -if [ -f /etc/init.d/xvfb ] ; then - mapbox_time "start_xvfb" \ - sh -e /etc/init.d/xvfb start - sleep 2 # sometimes, xvfb takes some time to start up -fi - -# Make sure we're connecting to xvfb -export DISPLAY=:99.0 - mapbox_time "checkout_mason" \ git submodule update --init .mason @@ -47,10 +37,20 @@ git submodule update --init .mason mapbox_time "touch_package_json" \ touch package.json -# Install and set up to load a more recent version of mesa -mapbox_time "install_mesa" \ -mason install mesa 11.2.2 -export LD_LIBRARY_PATH="`mason prefix mesa 11.2.2`/lib:${LD_LIBRARY_PATH:-}" +# Start the mock X server +if [ -f /etc/init.d/xvfb ] && [ -z "${WITH_OSMESA}" ]; then + mapbox_time "start_xvfb" \ + sh -e /etc/init.d/xvfb start + sleep 2 # sometimes, xvfb takes some time to start up + + # Make sure we're connecting to xvfb + export DISPLAY=:99.0 + + # Install and set up to load a more recent version of mesa + mapbox_time "install_mesa" \ + mason install mesa 11.2.2 + export LD_LIBRARY_PATH="`mason prefix mesa 11.2.2`/lib:${LD_LIBRARY_PATH:-}" +fi # Install and set up to load awscli pip install --user awscli From 610f43cfd2ab02a57dc771074374cc10789933e8 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 4 Nov 2016 02:27:28 +0200 Subject: [PATCH 13/67] [linux] Use OSMesa when running Node tests --- .travis.yml | 36 ++++++++++++++-------------- platform/linux/config.cmake | 2 +- scripts/travis_setup.sh | 2 +- test/util/offscreen_texture.test.cpp | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25744e128..57f6e10ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,14 +7,12 @@ addons_shortcuts: apt: sources: [ 'ubuntu-toolchain-r-test', 'george-edison55-precise-backports' ] packages: [ 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.8v4', 'cmake', 'cmake-data', - 'mesa-utils', 'libxi-dev', 'libglu1-mesa-dev', 'x11proto-randr-dev', 'x11proto-xext-dev', 'libxrandr-dev', - 'x11proto-xf86vidmode-dev', 'libxxf86vm-dev', 'libxcursor-dev', 'libxinerama-dev' ] + 'libxrandr-dev', 'libxcursor-dev', 'libxinerama-dev' ] addons_gcc5: &gcc5 apt: sources: [ 'ubuntu-toolchain-r-test', 'george-edison55-precise-backports' ] - packages: [ 'gdb', 'g++-5', 'gcc-5', 'cmake', 'cmake-data', - 'mesa-utils', 'libxi-dev', 'libglu1-mesa-dev', 'x11proto-randr-dev', 'x11proto-xext-dev', 'libxrandr-dev', - 'x11proto-xf86vidmode-dev', 'libxxf86vm-dev', 'libxcursor-dev', 'libxinerama-dev' ] + packages: [ 'g++-5', 'gcc-5', 'libllvm3.8v4', 'cmake', 'cmake-data', + 'libxrandr-dev', 'libxcursor-dev', 'libxinerama-dev' ] addons_qt4: &qt4 apt: sources: [ 'ubuntu-toolchain-r-test', 'george-edison55-precise-backports' ] @@ -46,6 +44,7 @@ before_script: script: - make linux - make benchmark + - make test - make run-test after_script: - ccache --show-stats @@ -75,11 +74,13 @@ matrix: - ./platform/node/scripts/after_script.sh ${TRAVIS_JOB_NUMBER} # GCC 5 - Debug - Coverage + # FIXME: https://github.com/mapbox/mapbox-gl-native/issues/6918 - os: linux - sudo: false + sudo: required + dist: trusty language: cpp compiler: "glfw-gcc5-debug" - env: BUILDTYPE=Debug _CXX=g++-5 _CC=gcc-5 WITH_COVERAGE=1 + env: BUILDTYPE=Debug _CXX=g++-5 _CC=gcc-5 WITH_COVERAGE=1 WITH_OSMESA=1 addons: *gcc5 after_script: - ccache --show-stats @@ -87,10 +88,11 @@ matrix: # GCC 5 - Release - os: linux - sudo: false + sudo: required + dist: trusty language: cpp compiler: "glfw-gcc5-release" - env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 + env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 WITH_OSMESA=1 addons: *gcc5 # Clang 3.5 - Debug @@ -99,7 +101,7 @@ matrix: dist: trusty language: cpp compiler: "glfw-clang35-debug" - env: BUILDTYPE=Debug _CXX=clang++-3.5 _CC=clang-3.5 + env: BUILDTYPE=Debug _CXX=clang++-3.5 _CC=clang-3.5 WITH_OSMESA=1 addons: *clang35 # Clang 3.5 - Release @@ -108,7 +110,7 @@ matrix: dist: trusty language: cpp compiler: "glfw-clang35-release" - env: BUILDTYPE=Release _CXX=clang++-3.5 _CC=clang-3.5 + env: BUILDTYPE=Release _CXX=clang++-3.5 _CC=clang-3.5 WITH_OSMESA=1 addons: *clang35 # Clang 3.5 - tidy @@ -116,11 +118,11 @@ matrix: sudo: required dist: trusty language: cpp - compiler: "tidy-clang35-release" - env: BUILDTYPE=Release _CXX=clang++-3.5 _CC=clang-3.5 + compiler: "check-clang35-release" + env: BUILDTYPE=Release _CXX=clang++-3.5 _CC=clang-3.5 WITH_OSMESA=1 addons: *clang35 script: - - make tidy + - git fetch origin master:refs/remotes/origin/master # Qt 4 - Release - os: linux @@ -128,7 +130,7 @@ matrix: dist: trusty language: cpp compiler: "qt4-gcc5-release" - env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 WITH_QT_4=1 + env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 RUN_XVFB=1 WITH_QT_4=1 addons: *qt4 script: - make qt-app @@ -140,9 +142,7 @@ matrix: dist: trusty language: cpp compiler: "qt5-gcc5-release" - # Qt 5 gets confused with fglrx that is installed by default on Travis - # trusty bots. This way we force both Qt and Xvfb to load on mesa drivers. - env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/mesa + env: BUILDTYPE=Release _CXX=g++-5 _CC=gcc-5 RUN_XVFB=1 addons: *qt5 script: - make qt-app diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index e8de73783..8acb6e7e1 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -1,5 +1,5 @@ mason_use(glfw VERSION 3.2.1) -mason_use(mesa VERSION 13.0.0) +mason_use(mesa VERSION 13.0.0${MASON_CXXABI_SUFFIX}) mason_use(boost_libprogram_options VERSION 1.60.0) mason_use(sqlite VERSION 3.14.2) mason_use(libuv VERSION 1.9.1) diff --git a/scripts/travis_setup.sh b/scripts/travis_setup.sh index 6fa1cc858..47df36788 100755 --- a/scripts/travis_setup.sh +++ b/scripts/travis_setup.sh @@ -38,7 +38,7 @@ mapbox_time "touch_package_json" \ touch package.json # Start the mock X server -if [ -f /etc/init.d/xvfb ] && [ -z "${WITH_OSMESA}" ]; then +if [ -f /etc/init.d/xvfb ] && [ ! -z "${RUN_XVFB}" ]; then mapbox_time "start_xvfb" \ sh -e /etc/init.d/xvfb start sleep 2 # sometimes, xvfb takes some time to start up diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index bd4eab69a..4aded07b2 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -1,9 +1,9 @@ #include +#include #include #include #include -#include #include From b7818f2019c24608a17bdfb0f3efb21e6fb26217 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Oct 2016 18:13:15 +0300 Subject: [PATCH 14/67] [core] Fix render tile ordering when querying sources --- package.json | 2 +- src/mbgl/style/source_impl.cpp | 15 +++++++++++++-- src/mbgl/tile/tile_id.hpp | 23 ++++------------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 29a7e7cf1..5d7938715 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lodash": "^4.16.4", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#98a56d538b11fb331aa67a6d632d6ecd6821b007", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#10a135f01b56989aa03686de94cc67c3efa6139d", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8d2d9cb86a7b4a15bc5a59bab531cd102257918d", "mkdirp": "^0.5.1", "node-cmake": "^1.2.1", "request": "^2.72.0", diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 73fc30d2d..b38439040 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -201,8 +201,19 @@ std::unordered_map> Source::Impl::queryRendere mapbox::geometry::box box = mapbox::geometry::envelope(queryGeometry); - for (const auto& tilePtr : renderTiles) { - const RenderTile& renderTile = tilePtr.second; + + auto sortRenderTiles = [](const RenderTile& a, const RenderTile& b) { + return a.id.canonical.z != b.id.canonical.z ? a.id.canonical.z < b.id.canonical.z : + a.id.canonical.y != b.id.canonical.y ? a.id.canonical.y < b.id.canonical.y : + a.id.wrap != b.id.wrap ? a.id.wrap < b.id.wrap : a.id.canonical.x < b.id.canonical.x; + }; + std::vector> sortedTiles; + std::transform(renderTiles.cbegin(), renderTiles.cend(), std::back_inserter(sortedTiles), + [](const auto& pair) { return std::ref(pair.second); }); + std::sort(sortedTiles.begin(), sortedTiles.end(), sortRenderTiles); + + for (const auto& renderTileRef : sortedTiles) { + const RenderTile& renderTile = renderTileRef.get(); GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(renderTile.id, box.min); if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT) { continue; diff --git a/src/mbgl/tile/tile_id.hpp b/src/mbgl/tile/tile_id.hpp index 88b01269e..c95810342 100644 --- a/src/mbgl/tile/tile_id.hpp +++ b/src/mbgl/tile/tile_id.hpp @@ -108,12 +108,7 @@ inline bool CanonicalTileID::operator!=(const CanonicalTileID& rhs) const { } inline bool CanonicalTileID::operator<(const CanonicalTileID& rhs) const { - if (z != rhs.z) { - return z < rhs.z; - } else if (x != rhs.x) { - return x < rhs.x; - } - return y < rhs.y; + return z != rhs.z ? z < rhs.z : x != rhs.x ? x < rhs.x : y < rhs.y; } inline bool CanonicalTileID::isChildOf(const CanonicalTileID& parent) const { @@ -175,10 +170,7 @@ inline bool OverscaledTileID::operator!=(const OverscaledTileID& rhs) const { } inline bool OverscaledTileID::operator<(const OverscaledTileID& rhs) const { - if (overscaledZ != rhs.overscaledZ) { - return overscaledZ < rhs.overscaledZ; - } - return canonical < rhs.canonical; + return overscaledZ != rhs.overscaledZ ? overscaledZ < rhs.overscaledZ : canonical < rhs.canonical; } inline uint32_t OverscaledTileID::overscaleFactor() const { @@ -191,11 +183,7 @@ inline bool OverscaledTileID::isChildOf(const OverscaledTileID& rhs) const { } inline OverscaledTileID OverscaledTileID::scaledTo(uint8_t z) const { - if (z >= canonical.z) { - return { z, canonical }; - } else { - return { z, canonical.scaledTo(z) }; - } + return { z, z >= canonical.z ? canonical : canonical.scaledTo(z) }; } inline UnwrappedTileID OverscaledTileID::unwrapTo(int16_t wrap) const { @@ -223,10 +211,7 @@ inline bool UnwrappedTileID::operator!=(const UnwrappedTileID& rhs) const { } inline bool UnwrappedTileID::operator<(const UnwrappedTileID& rhs) const { - if (wrap != rhs.wrap) { - return wrap < rhs.wrap; - } - return canonical < rhs.canonical; + return wrap != rhs.wrap ? wrap < rhs.wrap : canonical < rhs.canonical; } inline bool UnwrappedTileID::isChildOf(const UnwrappedTileID& parent) const { From 13a118e3bd6060a915ae72b621bc575b79d5bf3e Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 10 Nov 2016 15:02:13 +0100 Subject: [PATCH 15/67] [core] symbol layer - recalculate style on icon/text size changes --- package.json | 2 +- src/mbgl/style/layer_observer.hpp | 2 +- src/mbgl/style/layers/layer.cpp.ejs | 2 +- src/mbgl/style/layers/line_layer.cpp | 8 +-- src/mbgl/style/layers/symbol_layer.cpp | 68 +++++++++++----------- src/mbgl/style/style.cpp | 12 +++- src/mbgl/style/style.hpp | 2 +- test/src/mbgl/test/stub_layer_observer.hpp | 6 +- test/style/style_layer.test.cpp | 2 +- 9 files changed, 56 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 5d7938715..7abe377a4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lodash": "^4.16.4", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#98a56d538b11fb331aa67a6d632d6ecd6821b007", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8d2d9cb86a7b4a15bc5a59bab531cd102257918d", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#af9ee275f19e81f839a2733e6906c3fac272620e", "mkdirp": "^0.5.1", "node-cmake": "^1.2.1", "request": "^2.72.0", diff --git a/src/mbgl/style/layer_observer.hpp b/src/mbgl/style/layer_observer.hpp index 4182a1b81..a3f9ca752 100644 --- a/src/mbgl/style/layer_observer.hpp +++ b/src/mbgl/style/layer_observer.hpp @@ -12,7 +12,7 @@ public: virtual void onLayerFilterChanged(Layer&) {} virtual void onLayerVisibilityChanged(Layer&) {} virtual void onLayerPaintPropertyChanged(Layer&) {} - virtual void onLayerLayoutPropertyChanged(Layer&) {} + virtual void onLayerLayoutPropertyChanged(Layer&, const char *) {} }; } // namespace style diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 237a68aad..c2cbc56a0 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -89,7 +89,7 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue if (value == get<%- camelize(property.name) %>()) return; impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>"); } <% } -%> diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 100ee7247..49ecf63c1 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -71,7 +71,7 @@ void LineLayer::setLineCap(PropertyValue value) { if (value == getLineCap()) return; impl->layout.lineCap.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "line-cap"); } PropertyValue LineLayer::getDefaultLineJoin() { return { LineJoinType::Miter }; @@ -85,7 +85,7 @@ void LineLayer::setLineJoin(PropertyValue value) { if (value == getLineJoin()) return; impl->layout.lineJoin.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "line-join"); } PropertyValue LineLayer::getDefaultLineMiterLimit() { return { 2 }; @@ -99,7 +99,7 @@ void LineLayer::setLineMiterLimit(PropertyValue value) { if (value == getLineMiterLimit()) return; impl->layout.lineMiterLimit.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit"); } PropertyValue LineLayer::getDefaultLineRoundLimit() { return { 1 }; @@ -113,7 +113,7 @@ void LineLayer::setLineRoundLimit(PropertyValue value) { if (value == getLineRoundLimit()) return; impl->layout.lineRoundLimit.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "line-round-limit"); } // Paint properties diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 6b4d7400d..d49e8d7fe 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -71,7 +71,7 @@ void SymbolLayer::setSymbolPlacement(PropertyValue value) { if (value == getSymbolPlacement()) return; impl->layout.symbolPlacement.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-placement"); } PropertyValue SymbolLayer::getDefaultSymbolSpacing() { return { 250 }; @@ -85,7 +85,7 @@ void SymbolLayer::setSymbolSpacing(PropertyValue value) { if (value == getSymbolSpacing()) return; impl->layout.symbolSpacing.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-spacing"); } PropertyValue SymbolLayer::getDefaultSymbolAvoidEdges() { return { false }; @@ -99,7 +99,7 @@ void SymbolLayer::setSymbolAvoidEdges(PropertyValue value) { if (value == getSymbolAvoidEdges()) return; impl->layout.symbolAvoidEdges.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-avoid-edges"); } PropertyValue SymbolLayer::getDefaultIconAllowOverlap() { return { false }; @@ -113,7 +113,7 @@ void SymbolLayer::setIconAllowOverlap(PropertyValue value) { if (value == getIconAllowOverlap()) return; impl->layout.iconAllowOverlap.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-allow-overlap"); } PropertyValue SymbolLayer::getDefaultIconIgnorePlacement() { return { false }; @@ -127,7 +127,7 @@ void SymbolLayer::setIconIgnorePlacement(PropertyValue value) { if (value == getIconIgnorePlacement()) return; impl->layout.iconIgnorePlacement.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-ignore-placement"); } PropertyValue SymbolLayer::getDefaultIconOptional() { return { false }; @@ -141,7 +141,7 @@ void SymbolLayer::setIconOptional(PropertyValue value) { if (value == getIconOptional()) return; impl->layout.iconOptional.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-optional"); } PropertyValue SymbolLayer::getDefaultIconRotationAlignment() { return { AlignmentType::Auto }; @@ -155,7 +155,7 @@ void SymbolLayer::setIconRotationAlignment(PropertyValue value) { if (value == getIconRotationAlignment()) return; impl->layout.iconRotationAlignment.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotation-alignment"); } PropertyValue SymbolLayer::getDefaultIconSize() { return { 1 }; @@ -169,7 +169,7 @@ void SymbolLayer::setIconSize(PropertyValue value) { if (value == getIconSize()) return; impl->layout.iconSize.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-size"); } PropertyValue SymbolLayer::getDefaultIconTextFit() { return { IconTextFitType::None }; @@ -183,7 +183,7 @@ void SymbolLayer::setIconTextFit(PropertyValue value) { if (value == getIconTextFit()) return; impl->layout.iconTextFit.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit"); } PropertyValue> SymbolLayer::getDefaultIconTextFitPadding() { return { {{ 0, 0, 0, 0 }} }; @@ -197,7 +197,7 @@ void SymbolLayer::setIconTextFitPadding(PropertyValue> valu if (value == getIconTextFitPadding()) return; impl->layout.iconTextFitPadding.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding"); } PropertyValue SymbolLayer::getDefaultIconImage() { return { "" }; @@ -211,7 +211,7 @@ void SymbolLayer::setIconImage(PropertyValue value) { if (value == getIconImage()) return; impl->layout.iconImage.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-image"); } PropertyValue SymbolLayer::getDefaultIconRotate() { return { 0 }; @@ -225,7 +225,7 @@ void SymbolLayer::setIconRotate(PropertyValue value) { if (value == getIconRotate()) return; impl->layout.iconRotate.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotate"); } PropertyValue SymbolLayer::getDefaultIconPadding() { return { 2 }; @@ -239,7 +239,7 @@ void SymbolLayer::setIconPadding(PropertyValue value) { if (value == getIconPadding()) return; impl->layout.iconPadding.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-padding"); } PropertyValue SymbolLayer::getDefaultIconKeepUpright() { return { false }; @@ -253,7 +253,7 @@ void SymbolLayer::setIconKeepUpright(PropertyValue value) { if (value == getIconKeepUpright()) return; impl->layout.iconKeepUpright.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright"); } PropertyValue> SymbolLayer::getDefaultIconOffset() { return { {{ 0, 0 }} }; @@ -267,7 +267,7 @@ void SymbolLayer::setIconOffset(PropertyValue> value) { if (value == getIconOffset()) return; impl->layout.iconOffset.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "icon-offset"); } PropertyValue SymbolLayer::getDefaultTextPitchAlignment() { return { AlignmentType::Auto }; @@ -281,7 +281,7 @@ void SymbolLayer::setTextPitchAlignment(PropertyValue value) { if (value == getTextPitchAlignment()) return; impl->layout.textPitchAlignment.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-pitch-alignment"); } PropertyValue SymbolLayer::getDefaultTextRotationAlignment() { return { AlignmentType::Auto }; @@ -295,7 +295,7 @@ void SymbolLayer::setTextRotationAlignment(PropertyValue value) { if (value == getTextRotationAlignment()) return; impl->layout.textRotationAlignment.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment"); } PropertyValue SymbolLayer::getDefaultTextField() { return { "" }; @@ -309,7 +309,7 @@ void SymbolLayer::setTextField(PropertyValue value) { if (value == getTextField()) return; impl->layout.textField.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-field"); } PropertyValue> SymbolLayer::getDefaultTextFont() { return { { "Open Sans Regular", "Arial Unicode MS Regular" } }; @@ -323,7 +323,7 @@ void SymbolLayer::setTextFont(PropertyValue> value) { if (value == getTextFont()) return; impl->layout.textFont.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-font"); } PropertyValue SymbolLayer::getDefaultTextSize() { return { 16 }; @@ -337,7 +337,7 @@ void SymbolLayer::setTextSize(PropertyValue value) { if (value == getTextSize()) return; impl->layout.textSize.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-size"); } PropertyValue SymbolLayer::getDefaultTextMaxWidth() { return { 10 }; @@ -351,7 +351,7 @@ void SymbolLayer::setTextMaxWidth(PropertyValue value) { if (value == getTextMaxWidth()) return; impl->layout.textMaxWidth.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-width"); } PropertyValue SymbolLayer::getDefaultTextLineHeight() { return { 1.2 }; @@ -365,7 +365,7 @@ void SymbolLayer::setTextLineHeight(PropertyValue value) { if (value == getTextLineHeight()) return; impl->layout.textLineHeight.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-line-height"); } PropertyValue SymbolLayer::getDefaultTextLetterSpacing() { return { 0 }; @@ -379,7 +379,7 @@ void SymbolLayer::setTextLetterSpacing(PropertyValue value) { if (value == getTextLetterSpacing()) return; impl->layout.textLetterSpacing.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-letter-spacing"); } PropertyValue SymbolLayer::getDefaultTextJustify() { return { TextJustifyType::Center }; @@ -393,7 +393,7 @@ void SymbolLayer::setTextJustify(PropertyValue value) { if (value == getTextJustify()) return; impl->layout.textJustify.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-justify"); } PropertyValue SymbolLayer::getDefaultTextAnchor() { return { TextAnchorType::Center }; @@ -407,7 +407,7 @@ void SymbolLayer::setTextAnchor(PropertyValue value) { if (value == getTextAnchor()) return; impl->layout.textAnchor.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-anchor"); } PropertyValue SymbolLayer::getDefaultTextMaxAngle() { return { 45 }; @@ -421,7 +421,7 @@ void SymbolLayer::setTextMaxAngle(PropertyValue value) { if (value == getTextMaxAngle()) return; impl->layout.textMaxAngle.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-angle"); } PropertyValue SymbolLayer::getDefaultTextRotate() { return { 0 }; @@ -435,7 +435,7 @@ void SymbolLayer::setTextRotate(PropertyValue value) { if (value == getTextRotate()) return; impl->layout.textRotate.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotate"); } PropertyValue SymbolLayer::getDefaultTextPadding() { return { 2 }; @@ -449,7 +449,7 @@ void SymbolLayer::setTextPadding(PropertyValue value) { if (value == getTextPadding()) return; impl->layout.textPadding.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-padding"); } PropertyValue SymbolLayer::getDefaultTextKeepUpright() { return { true }; @@ -463,7 +463,7 @@ void SymbolLayer::setTextKeepUpright(PropertyValue value) { if (value == getTextKeepUpright()) return; impl->layout.textKeepUpright.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright"); } PropertyValue SymbolLayer::getDefaultTextTransform() { return { TextTransformType::None }; @@ -477,7 +477,7 @@ void SymbolLayer::setTextTransform(PropertyValue value) { if (value == getTextTransform()) return; impl->layout.textTransform.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-transform"); } PropertyValue> SymbolLayer::getDefaultTextOffset() { return { {{ 0, 0 }} }; @@ -491,7 +491,7 @@ void SymbolLayer::setTextOffset(PropertyValue> value) { if (value == getTextOffset()) return; impl->layout.textOffset.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-offset"); } PropertyValue SymbolLayer::getDefaultTextAllowOverlap() { return { false }; @@ -505,7 +505,7 @@ void SymbolLayer::setTextAllowOverlap(PropertyValue value) { if (value == getTextAllowOverlap()) return; impl->layout.textAllowOverlap.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-allow-overlap"); } PropertyValue SymbolLayer::getDefaultTextIgnorePlacement() { return { false }; @@ -519,7 +519,7 @@ void SymbolLayer::setTextIgnorePlacement(PropertyValue value) { if (value == getTextIgnorePlacement()) return; impl->layout.textIgnorePlacement.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-ignore-placement"); } PropertyValue SymbolLayer::getDefaultTextOptional() { return { false }; @@ -533,7 +533,7 @@ void SymbolLayer::setTextOptional(PropertyValue value) { if (value == getTextOptional()) return; impl->layout.textOptional.set(value); - impl->observer->onLayerLayoutPropertyChanged(*this); + impl->observer->onLayerLayoutPropertyChanged(*this, "text-optional"); } // Paint properties diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index fbe28e179..91483e156 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -559,9 +559,17 @@ void Style::onLayerPaintPropertyChanged(Layer&) { observer->onUpdate(Update::RecalculateStyle | Update::Classes); } -void Style::onLayerLayoutPropertyChanged(Layer& layer) { +void Style::onLayerLayoutPropertyChanged(Layer& layer, const char * property) { layer.accept(QueueSourceReloadVisitor { updateBatch }); - observer->onUpdate(Update::Layout); + + auto update = Update::Layout; + + //Recalculate the style for certain properties + bool needsRecalculation = strcmp(property, "icon-size") == 0 || strcmp(property, "text-size") == 0; + if (needsRecalculation) { + update |= Update::RecalculateStyle; + } + observer->onUpdate(update); } void Style::dumpDebugLogs() const { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 14aef5de4..00e30d397 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -143,7 +143,7 @@ private: void onLayerFilterChanged(Layer&) override; void onLayerVisibilityChanged(Layer&) override; void onLayerPaintPropertyChanged(Layer&) override; - void onLayerLayoutPropertyChanged(Layer&) override; + void onLayerLayoutPropertyChanged(Layer&, const char *) override; Observer nullObserver; Observer* observer = &nullObserver; diff --git a/test/src/mbgl/test/stub_layer_observer.hpp b/test/src/mbgl/test/stub_layer_observer.hpp index f346080b1..07797ce92 100644 --- a/test/src/mbgl/test/stub_layer_observer.hpp +++ b/test/src/mbgl/test/stub_layer_observer.hpp @@ -22,12 +22,12 @@ public: if (layerPaintPropertyChanged) layerPaintPropertyChanged(layer); } - void onLayerLayoutPropertyChanged(Layer& layer) override { - if (layerLayoutPropertyChanged) layerLayoutPropertyChanged(layer); + void onLayerLayoutPropertyChanged(Layer& layer, const char * property) override { + if (layerLayoutPropertyChanged) layerLayoutPropertyChanged(layer, property); } std::function layerFilterChanged; std::function layerVisibilityChanged; std::function layerPaintPropertyChanged; - std::function layerLayoutPropertyChanged; + std::function layerLayoutPropertyChanged; }; diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 08952e379..f6dcc684c 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -246,7 +246,7 @@ TEST(Layer, Observer) { // Notifies observer on layout property change. bool layoutPropertyChanged = false; - observer.layerLayoutPropertyChanged = [&] (Layer& layer_) { + observer.layerLayoutPropertyChanged = [&] (Layer& layer_, const char *) { EXPECT_EQ(layer.get(), &layer_); layoutPropertyChanged = true; }; From 82fcd58121f272fea8d115ae0419791a78884324 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 7 Nov 2016 18:56:15 +0100 Subject: [PATCH 16/67] [ios] specify plist-file for settings bundle --- platform/ios/ios.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index a78cf583c..9561c741a 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -2268,6 +2268,7 @@ DA25D5BC1CCD9EDE00607828 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + INFOPLIST_FILE = framework/Settings.bundle/Root.plist; PRODUCT_NAME = Settings; SKIP_INSTALL = YES; WRAPPER_EXTENSION = bundle; @@ -2277,6 +2278,7 @@ DA25D5BD1CCD9EDE00607828 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + INFOPLIST_FILE = framework/Settings.bundle/Root.plist; PRODUCT_NAME = Settings; SKIP_INSTALL = YES; WRAPPER_EXTENSION = bundle; From 96a7a4402ef5eac2fa17ec7b52ef24e3b10bbf29 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 11 Nov 2016 14:40:04 -0800 Subject: [PATCH 17/67] [core] Return source and layer ownership (#7014) When a source or layer is removed transfer ownership back to the caller so it can (optionally) take it. Preserve the behavior that removing a CustomLayer triggers deinitialization. Deinitialize all custom layers when a style is destroyed in case those layers are not explicitly removed. --- include/mbgl/map/map.hpp | 4 ++-- src/mbgl/map/map.cpp | 13 +++++++---- src/mbgl/style/layers/custom_layer_impl.cpp | 12 ++++++---- src/mbgl/style/layers/custom_layer_impl.hpp | 1 + src/mbgl/style/style.cpp | 26 ++++++++++++++++++--- src/mbgl/style/style.hpp | 4 ++-- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index b1c840e68..0c14600c7 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -159,12 +159,12 @@ public: // Sources style::Source* getSource(const std::string& sourceID); void addSource(std::unique_ptr); - void removeSource(const std::string& sourceID); + std::unique_ptr removeSource(const std::string& sourceID); // Layers style::Layer* getLayer(const std::string& layerID); void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); - void removeLayer(const std::string& layerID); + std::unique_ptr removeLayer(const std::string& layerID); // Add image, bound to the style void addImage(const std::string&, std::unique_ptr); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 903f90c54..bd1de6f18 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -818,11 +818,12 @@ void Map::addSource(std::unique_ptr source) { } } -void Map::removeSource(const std::string& sourceID) { +std::unique_ptr Map::removeSource(const std::string& sourceID) { if (impl->style) { impl->styleMutated = true; - impl->style->removeSource(sourceID); + return impl->style->removeSource(sourceID); } + return nullptr; } style::Layer* Map::getLayer(const std::string& layerID) { @@ -847,18 +848,20 @@ void Map::addLayer(std::unique_ptr layer, const optional& be impl->backend.deactivate(); } -void Map::removeLayer(const std::string& id) { +std::unique_ptr Map::removeLayer(const std::string& id) { if (!impl->style) { - return; + return nullptr; } impl->styleMutated = true; impl->backend.activate(); - impl->style->removeLayer(id); + auto removedLayer = impl->style->removeLayer(id); impl->onUpdate(Update::Classes); impl->backend.deactivate(); + + return removedLayer; } void Map::addImage(const std::string& name, std::unique_ptr image) { diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index a0686e353..8896d04ca 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -23,11 +23,7 @@ CustomLayer::Impl::Impl(const CustomLayer::Impl& other) // Don't copy anything else. } -CustomLayer::Impl::~Impl() { - if (deinitializeFn) { - deinitializeFn(context); - } -} +CustomLayer::Impl::~Impl() = default; std::unique_ptr CustomLayer::Impl::clone() const { return std::make_unique(*this); @@ -43,6 +39,12 @@ void CustomLayer::Impl::initialize() { initializeFn(context); } +void CustomLayer::Impl::deinitialize() { + if (deinitializeFn) { + deinitializeFn(context); + } +} + void CustomLayer::Impl::render(const TransformState& state) const { assert(renderFn); diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index ffa892ddf..b5b626ca5 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -21,6 +21,7 @@ public: ~Impl() final; void initialize(); + void deinitialize(); void render(const TransformState&) const; private: diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 91483e156..05dbc0843 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -51,6 +51,12 @@ Style::~Style() { source->baseImpl->setObserver(nullptr); } + for (const auto& layer : layers) { + if (CustomLayer* customLayer = layer->as()) { + customLayer->impl->deinitialize(); + } + } + glyphAtlas->setObserver(nullptr); spriteAtlas->setObserver(nullptr); } @@ -134,7 +140,7 @@ void Style::addSource(std::unique_ptr source) { sources.emplace_back(std::move(source)); } -void Style::removeSource(const std::string& id) { +std::unique_ptr Style::removeSource(const std::string& id) { auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) { return source->getID() == id; }); @@ -143,8 +149,11 @@ void Style::removeSource(const std::string& id) { throw std::runtime_error("no such source"); } + auto source = std::move(*it); sources.erase(it); updateBatch.sourceIDs.erase(id); + + return source; } std::vector Style::getLayers() const { @@ -185,11 +194,22 @@ Layer* Style::addLayer(std::unique_ptr layer, optional befor return layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get(); } -void Style::removeLayer(const std::string& id) { - auto it = findLayer(id); +std::unique_ptr Style::removeLayer(const std::string& id) { + auto it = std::find_if(layers.begin(), layers.end(), [&](const auto& layer) { + return layer->baseImpl->id == id; + }); + if (it == layers.end()) throw std::runtime_error("no such layer"); + + auto layer = std::move(*it); + + if (CustomLayer* customLayer = layer->as()) { + customLayer->impl->deinitialize(); + } + layers.erase(it); + return layer; } std::string Style::getName() const { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 00e30d397..2875311c6 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -66,13 +66,13 @@ public: Source* getSource(const std::string& id) const; void addSource(std::unique_ptr); - void removeSource(const std::string& sourceID); + std::unique_ptr removeSource(const std::string& sourceID); std::vector getLayers() const; Layer* getLayer(const std::string& id) const; Layer* addLayer(std::unique_ptr, optional beforeLayerID = {}); - void removeLayer(const std::string& layerID); + std::unique_ptr removeLayer(const std::string& layerID); std::string getName() const; LatLng getDefaultLatLng() const; From 44e398865e7fa2b0186b9b93c9efcfa53e985566 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 14 Nov 2016 09:34:22 -0800 Subject: [PATCH 18/67] [ios, macos] Use std::vector for MGLMultiPoint coordinate storage (#6890) Refactor the previous C array based implementation to use C++ std::vector. This is done to avoid potential safety and security issues with the previous approach. --- platform/darwin/src/MGLMultiPoint.h | 23 +++-- platform/darwin/src/MGLMultiPoint.mm | 102 +++++++++------------- platform/darwin/src/MGLPointCollection.mm | 41 ++++----- 3 files changed, 73 insertions(+), 93 deletions(-) diff --git a/platform/darwin/src/MGLMultiPoint.h b/platform/darwin/src/MGLMultiPoint.h index 69c729584..5a37e25cc 100644 --- a/platform/darwin/src/MGLMultiPoint.h +++ b/platform/darwin/src/MGLMultiPoint.h @@ -48,17 +48,26 @@ NS_ASSUME_NONNULL_BEGIN cause the shape to be redrawn if it is currently visible on the map. @param range The range of points to update. The `location` field indicates the - first point you are replacing, with `0` being the first point, `1` being - the second point, and so on. The `length` field indicates the number of - points to update. You can append to an existing array of coordinates - by specifying a range with a `location` at the end of the existing array - and/or a `length` which extends past the end of the existing array. The array - in _`coords`_ must be equal in number to the length of the range. + first point you are replacing, with `0` being the first point, `1` being + the second point, and so on. The `length` field indicates the number of + points to update. The array in _`coords`_ must be equal in number to the + length of the range. If you want to append to the existing coordinates + array use `-[MGLMultiPoint appendCoordinates:count:]`. @param coords The array of coordinates defining the shape. The data in this - array is copied to the object. + array is copied to the object. */ - (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(CLLocationCoordinate2D *)coords; +/** + Appends one or more coordinates for the shape, which will instantaneously + cause the shape to be redrawn if it is currently visible on the map. + + @param coords The array of coordinates to add to the shape. The data in this + array is copied to the new object. + @param count The number of items in the `coords` array. + */ +- (void)appendCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index 17a61ed08..66ce27614 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -14,8 +14,8 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) @implementation MGLMultiPoint { - size_t _count; MGLCoordinateBounds _bounds; + std::vector _coordinates; } - (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count @@ -24,45 +24,23 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) if (self) { - [self setupWithCoordinates:coords count:count]; + NSAssert(count > 0, @"A multipoint must have coordinates"); + _coordinates = { coords, coords + count }; + [self computeBounds]; } return self; } -- (void)setupWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count -{ - if (_coordinates) free(_coordinates); - - _count = count; - _coordinates = (CLLocationCoordinate2D *)malloc(_count * sizeof(CLLocationCoordinate2D)); - - mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); - - for (NSUInteger i = 0; i < _count; i++) - { - _coordinates[i] = coords[i]; - bounds.extend(mbgl::LatLng(coords[i].latitude, coords[i].longitude)); - } - - _bounds = MGLCoordinateBoundsFromLatLngBounds(bounds); -} - -- (void)dealloc -{ - free(_coordinates); -} - - (CLLocationCoordinate2D)coordinate { - assert(_count > 0); - - return CLLocationCoordinate2DMake(_coordinates[0].latitude, _coordinates[0].longitude); + NSAssert([self pointCount] > 0, @"A multipoint must have coordinates"); + return _coordinates.at(0); } - (NSUInteger)pointCount { - return _count; + return _coordinates.size(); } + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingPointCount @@ -70,61 +48,61 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) return [NSSet setWithObjects:@"coordinates", nil]; } +- (CLLocationCoordinate2D *)coordinates +{ + return _coordinates.data(); +} + - (void)getCoordinates:(CLLocationCoordinate2D *)coords range:(NSRange)range { - if (range.location + range.length > _count) + if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException format:@"Invalid coordinate range %@ extends beyond current coordinate count of %zu", - NSStringFromRange(range), _count]; + NSStringFromRange(range), [self pointCount]]; } - NSUInteger index = 0; + std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); +} - for (NSUInteger i = range.location; i < range.location + range.length; i++) - { - coords[index] = _coordinates[i]; - index++; - } +- (void)appendCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count +{ + [self willChangeValueForKey:@"coordinates"]; + _coordinates.insert(_coordinates.end(), count, *coords); + [self computeBounds]; + [self didChangeValueForKey:@"coordinates"]; } - (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(CLLocationCoordinate2D *)coords { - if ((coords >= _coordinates && coords < _coordinates + _count) || - (coords + range.length >= _coordinates && coords + range.length < _coordinates + _count)) + if (range.length == 0) { - [NSException raise:NSRangeException format:@"Reuse of existing coordinates array %p not supported", coords]; + return; } - else if (range.length == 0) - { - [NSException raise:NSRangeException format:@"Empty coordinate range %@", NSStringFromRange(range)]; - } - else if (range.location > _count) + + if (NSMaxRange(range) > _coordinates.size()) { [NSException raise:NSRangeException format:@"Invalid range %@ for existing coordinate count %zu", - NSStringFromRange(range), _count]; + NSStringFromRange(range), [self pointCount]]; } [self willChangeValueForKey:@"coordinates"]; - if (NSMaxRange(range) <= _count) - { - // replacing existing coordinate(s) - memcpy(_coordinates + range.location, coords, range.length * sizeof(CLLocationCoordinate2D)); - } - else - { - // appending new coordinate(s) - NSUInteger newCount = NSMaxRange(range); - CLLocationCoordinate2D *newCoordinates = (CLLocationCoordinate2D *)malloc(newCount * sizeof(CLLocationCoordinate2D)); - memcpy(newCoordinates, _coordinates, fmin(_count, range.location) * sizeof(CLLocationCoordinate2D)); - memcpy(newCoordinates + range.location, coords, range.length * sizeof(CLLocationCoordinate2D)); - [self setupWithCoordinates:newCoordinates count:newCount]; - free(newCoordinates); - } + std::copy(coords, coords + range.length, _coordinates.begin() + range.location); + [self computeBounds]; [self didChangeValueForKey:@"coordinates"]; } +- (void)computeBounds +{ + mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); + for (auto coordinate : _coordinates) + { + bounds.extend(mbgl::LatLng(coordinate.latitude, coordinate.longitude)); + } + _bounds = MGLCoordinateBoundsFromLatLngBounds(bounds); +} + - (MGLCoordinateBounds)overlayBounds { return _bounds; @@ -144,7 +122,7 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p; count = %lu; bounds = %@>", - NSStringFromClass([self class]), (void *)self, (unsigned long)_count, MGLStringFromCoordinateBounds(_bounds)]; + NSStringFromClass([self class]), (void *)self, (unsigned long)[self pointCount], MGLStringFromCoordinateBounds(_bounds)]; } @end diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index 5871915b5..adf3cc3d4 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -8,8 +8,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation MGLPointCollection { - size_t _count; MGLCoordinateBounds _bounds; + std::vector _coordinates; } + (instancetype)pointCollectionWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count @@ -22,17 +22,12 @@ NS_ASSUME_NONNULL_BEGIN self = [super init]; if (self) { - _count = count; - _coordinates = (CLLocationCoordinate2D *)malloc(_count * sizeof(CLLocationCoordinate2D)); - + _coordinates = { coords, coords + count }; mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); - - for (NSUInteger i = 0; i < count; i++) + for (auto coordinate : _coordinates) { - _coordinates[i] = coords[i]; - bounds.extend(mbgl::LatLng(coords[i].latitude, coords[i].longitude)); + bounds.extend(mbgl::LatLng(coordinate.latitude, coordinate.longitude)); } - _bounds = MGLCoordinateBoundsFromLatLngBounds(bounds); } return self; @@ -40,32 +35,30 @@ NS_ASSUME_NONNULL_BEGIN - (NSUInteger)pointCount { - return _count; + return _coordinates.size(); +} + +- (CLLocationCoordinate2D *)coordinates +{ + return _coordinates.data(); } - (CLLocationCoordinate2D)coordinate { - assert(_count > 0); - - return CLLocationCoordinate2DMake(_coordinates[0].latitude, _coordinates[0].longitude); + NSAssert([self pointCount] > 0, @"A multipoint must have coordinates"); + return _coordinates.at(0); } - (void)getCoordinates:(CLLocationCoordinate2D *)coords range:(NSRange)range { - if (range.location + range.length > _count) + if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException format:@"Invalid coordinate range %@ extends beyond current coordinate count of %zu", - NSStringFromRange(range), _count]; - } - - NSUInteger index = 0; - - for (NSUInteger i = range.location; i < range.location + range.length; i++) - { - coords[index] = _coordinates[i]; - index++; + NSStringFromRange(range), [self pointCount]]; } + + std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); } - (MGLCoordinateBounds)overlayBounds @@ -104,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p; count = %lu>", - NSStringFromClass([self class]), (void *)self, (unsigned long)_count]; + NSStringFromClass([self class]), (void *)self, (unsigned long)[self pointCount]]; } @end From f968ede11b162eff03d892b7e9aa72b04628bb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 11 Nov 2016 17:24:40 +0100 Subject: [PATCH 19/67] [core] don't run symbol placement more often than necessary --- src/mbgl/tile/geometry_tile.cpp | 4 ++-- src/mbgl/tile/geometry_tile.hpp | 3 +-- src/mbgl/tile/geometry_tile_worker.cpp | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index c77467ebc..84455e478 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -57,11 +57,12 @@ void GeometryTile::setData(std::unique_ptr data_) { } void GeometryTile::setPlacementConfig(const PlacementConfig& desiredConfig) { - if (placedConfig == desiredConfig) { + if (requestedConfig == desiredConfig) { return; } ++correlationID; + requestedConfig = desiredConfig; worker.invoke(&GeometryTileWorker::setPlacementConfig, desiredConfig, correlationID); } @@ -112,7 +113,6 @@ void GeometryTile::onPlacement(PlacementResult result) { buckets[bucket.first] = std::move(bucket.second); } featureIndex->setCollisionTile(std::move(result.collisionTile)); - placedConfig = result.placedConfig; observer->onTileChanged(*this); } diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index cb3ca5463..86243e8a0 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -61,7 +61,6 @@ public: public: std::unordered_map> buckets; std::unique_ptr collisionTile; - PlacementConfig placedConfig; uint64_t correlationID; }; void onPlacement(PlacementResult); @@ -79,7 +78,7 @@ private: Actor worker; uint64_t correlationID = 0; - optional placedConfig; + optional requestedConfig; std::unordered_map> buckets; std::unique_ptr featureIndex; diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index 6ff3c6779..abb3894d3 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -321,7 +321,6 @@ void GeometryTileWorker::attemptPlacement() { parent.invoke(&GeometryTile::onPlacement, GeometryTile::PlacementResult { std::move(buckets), std::move(collisionTile), - *placementConfig, correlationID }); } From 1f4c317febf6dd66a4c5d02c732beeb9efd5e502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 7 Nov 2016 22:27:54 -0800 Subject: [PATCH 20/67] [ios] Pull in OHHTTPStubs project reference Removed individual OHHTTPStubs file references from the ios-tests project. Added a reference to the OHHTTPStubs project to the workspace. Link ios-tests to its iOS framework build product. --- .../ios.xcworkspace/contents.xcworkspacedata | 3 + .../ios-tests.xcodeproj/project.pbxproj | 56 ++++--------------- 2 files changed, 15 insertions(+), 44 deletions(-) diff --git a/platform/ios/ios.xcworkspace/contents.xcworkspacedata b/platform/ios/ios.xcworkspace/contents.xcworkspacedata index 08503d2be..65d928a67 100644 --- a/platform/ios/ios.xcworkspace/contents.xcworkspacedata +++ b/platform/ios/ios.xcworkspace/contents.xcworkspacedata @@ -10,6 +10,9 @@ + + diff --git a/platform/ios/uitest/ios-tests.xcodeproj/project.pbxproj b/platform/ios/uitest/ios-tests.xcodeproj/project.pbxproj index 0d6f89234..c9744d41b 100644 --- a/platform/ios/uitest/ios-tests.xcodeproj/project.pbxproj +++ b/platform/ios/uitest/ios-tests.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 96567A231B0E84CD00D78776 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 96567A221B0E84CD00D78776 /* LaunchScreen.xib */; }; 96567A311B0E8BB900D78776 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96567A301B0E8BB900D78776 /* Images.xcassets */; }; + DA180EF21DD1A4DF000A211D /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA180EF11DD1A4DF000A211D /* OHHTTPStubs.framework */; }; DA482C801C12582600772FE3 /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA482C7F1C12582600772FE3 /* Mapbox.framework */; }; DA482C811C12582600772FE3 /* Mapbox.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DA482C7F1C12582600772FE3 /* Mapbox.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; DA9C551D1CD9DFCD000A15C6 /* libKIF.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA9C551B1CD9DFA7000A15C6 /* libKIF.a */; }; @@ -17,12 +18,6 @@ DD043366196DBBE000E6F39D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD043365196DBBE000E6F39D /* main.m */; }; DD0580E81ACB628200B112C9 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD0580E71ACB628200B112C9 /* IOKit.framework */; }; DD0E6F841B0190E200DC035A /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DD0E6F701B0190E200DC035A /* libOCMock.a */; }; - DD0E6F981B01B68E00DC035A /* OHHTTPStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F8E1B01B68E00DC035A /* OHHTTPStubs.m */; }; - DD0E6F991B01B68E00DC035A /* OHHTTPStubs+NSURLSessionConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F8F1B01B68E00DC035A /* OHHTTPStubs+NSURLSessionConfiguration.m */; }; - DD0E6F9A1B01B68E00DC035A /* OHHTTPStubsResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F911B01B68E00DC035A /* OHHTTPStubsResponse.m */; }; - DD0E6F9B1B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F931B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.m */; }; - DD0E6F9C1B01B68E00DC035A /* OHHTTPStubsResponse+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F951B01B68E00DC035A /* OHHTTPStubsResponse+JSON.m */; }; - DD0E6F9D1B01B68E00DC035A /* OHPathHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = DD0E6F971B01B68E00DC035A /* OHPathHelpers.m */; }; DDBD016C196DC4740033959E /* MapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBD0168196DC4740033959E /* MapViewTests.m */; }; DDBD016D196DC4740033959E /* KIFTestActor+MapboxGL.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBD016A196DC4740033959E /* KIFTestActor+MapboxGL.m */; }; /* End PBXBuildFile section */ @@ -54,9 +49,9 @@ /* Begin PBXFileReference section */ 96567A221B0E84CD00D78776 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = SOURCE_ROOT; }; 96567A301B0E8BB900D78776 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = SOURCE_ROOT; }; + DA180EF11DD1A4DF000A211D /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = "OHHTTPStubs/OHHTTPStubs/build/Debug-iphoneos/OHHTTPStubs.framework"; sourceTree = ""; }; DA482C7F1C12582600772FE3 /* Mapbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Mapbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DA9C551B1CD9DFA7000A15C6 /* libKIF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libKIF.a; path = "../../../build/ios/Build/Products/Debug-iphonesimulator/libKIF.a"; sourceTree = ""; }; - DADD9EB51BD16D8B00DA9161 /* Compatibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Compatibility.h; path = OHHTTPStubs/OHHTTPStubs/Sources/Compatibility.h; sourceTree = SOURCE_ROOT; }; DD043323196DB9BC00E6F39D /* Mapbox GL Tests.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL Tests.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD04335F196DBBD500E6F39D /* MGLTAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLTAppDelegate.m; sourceTree = SOURCE_ROOT; }; DD043360196DBBD500E6F39D /* MGLTViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLTViewController.m; sourceTree = SOURCE_ROOT; }; @@ -75,17 +70,6 @@ DD0E6F781B0190E200DC035A /* OCMockObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMockObject.h; sourceTree = ""; }; DD0E6F791B0190E200DC035A /* OCMRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMRecorder.h; sourceTree = ""; }; DD0E6F7A1B0190E200DC035A /* OCMStubRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCMStubRecorder.h; sourceTree = ""; }; - DD0E6F8D1B01B68E00DC035A /* OHHTTPStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OHHTTPStubs.h; path = OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubs.h; sourceTree = SOURCE_ROOT; }; - DD0E6F8E1B01B68E00DC035A /* OHHTTPStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OHHTTPStubs.m; path = OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubs.m; sourceTree = SOURCE_ROOT; }; - DD0E6F8F1B01B68E00DC035A /* OHHTTPStubs+NSURLSessionConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OHHTTPStubs+NSURLSessionConfiguration.m"; path = "OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubs+NSURLSessionConfiguration.m"; sourceTree = SOURCE_ROOT; }; - DD0E6F901B01B68E00DC035A /* OHHTTPStubsResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OHHTTPStubsResponse.h; path = OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse.h; sourceTree = SOURCE_ROOT; }; - DD0E6F911B01B68E00DC035A /* OHHTTPStubsResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OHHTTPStubsResponse.m; path = OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse.m; sourceTree = SOURCE_ROOT; }; - DD0E6F921B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OHHTTPStubsResponse+HTTPMessage.h"; path = "OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+HTTPMessage.h"; sourceTree = SOURCE_ROOT; }; - DD0E6F931B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OHHTTPStubsResponse+HTTPMessage.m"; path = "OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+HTTPMessage.m"; sourceTree = SOURCE_ROOT; }; - DD0E6F941B01B68E00DC035A /* OHHTTPStubsResponse+JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OHHTTPStubsResponse+JSON.h"; path = "OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.h"; sourceTree = SOURCE_ROOT; }; - DD0E6F951B01B68E00DC035A /* OHHTTPStubsResponse+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OHHTTPStubsResponse+JSON.m"; path = "OHHTTPStubs/OHHTTPStubs/Sources/OHHTTPStubsResponse+JSON.m"; sourceTree = SOURCE_ROOT; }; - DD0E6F961B01B68E00DC035A /* OHPathHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OHPathHelpers.h; path = OHHTTPStubs/OHHTTPStubs/Sources/OHPathHelpers.h; sourceTree = SOURCE_ROOT; }; - DD0E6F971B01B68E00DC035A /* OHPathHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OHPathHelpers.m; path = OHHTTPStubs/OHHTTPStubs/Sources/OHPathHelpers.m; sourceTree = SOURCE_ROOT; }; DDBD0152196DC3D70033959E /* Test Bundle.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Test Bundle.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; DDBD0165196DC4560033959E /* Bundle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Bundle-Info.plist"; sourceTree = SOURCE_ROOT; }; DDBD0168196DC4740033959E /* MapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewTests.m; sourceTree = SOURCE_ROOT; }; @@ -106,6 +90,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + DA180EF21DD1A4DF000A211D /* OHHTTPStubs.framework in Frameworks */, DD0580E81ACB628200B112C9 /* IOKit.framework in Frameworks */, DA9C551D1CD9DFCD000A15C6 /* libKIF.a in Frameworks */, DD0E6F841B0190E200DC035A /* libOCMock.a in Frameworks */, @@ -137,6 +122,7 @@ DD043325196DB9BC00E6F39D /* Frameworks */ = { isa = PBXGroup; children = ( + DA180EF11DD1A4DF000A211D /* OHHTTPStubs.framework */, DA9C551B1CD9DFA7000A15C6 /* libKIF.a */, DA482C7F1C12582600772FE3 /* Mapbox.framework */, DD0580E71ACB628200B112C9 /* IOKit.framework */, @@ -194,25 +180,6 @@ path = OCMock/OCMock; sourceTree = SOURCE_ROOT; }; - DD0E6F861B01B67100DC035A /* OHHTTPStubs */ = { - isa = PBXGroup; - children = ( - DADD9EB51BD16D8B00DA9161 /* Compatibility.h */, - DD0E6F8D1B01B68E00DC035A /* OHHTTPStubs.h */, - DD0E6F8E1B01B68E00DC035A /* OHHTTPStubs.m */, - DD0E6F8F1B01B68E00DC035A /* OHHTTPStubs+NSURLSessionConfiguration.m */, - DD0E6F901B01B68E00DC035A /* OHHTTPStubsResponse.h */, - DD0E6F911B01B68E00DC035A /* OHHTTPStubsResponse.m */, - DD0E6F921B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.h */, - DD0E6F931B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.m */, - DD0E6F941B01B68E00DC035A /* OHHTTPStubsResponse+JSON.h */, - DD0E6F951B01B68E00DC035A /* OHHTTPStubsResponse+JSON.m */, - DD0E6F961B01B68E00DC035A /* OHPathHelpers.h */, - DD0E6F971B01B68E00DC035A /* OHPathHelpers.m */, - ); - name = OHHTTPStubs; - sourceTree = ""; - }; DDBD0139196DC38D0033959E /* Tests */ = { isa = PBXGroup; children = ( @@ -221,7 +188,6 @@ DDBD0168196DC4740033959E /* MapViewTests.m */, DDBD0167196DC46B0033959E /* Supporting Files */, DD0E6F6B1B01906600DC035A /* OCMock */, - DD0E6F861B01B67100DC035A /* OHHTTPStubs */, ); name = Tests; path = "Mapbox GL Tests"; @@ -342,14 +308,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DD0E6F981B01B68E00DC035A /* OHHTTPStubs.m in Sources */, - DD0E6F9C1B01B68E00DC035A /* OHHTTPStubsResponse+JSON.m in Sources */, - DD0E6F9B1B01B68E00DC035A /* OHHTTPStubsResponse+HTTPMessage.m in Sources */, DDBD016D196DC4740033959E /* KIFTestActor+MapboxGL.m in Sources */, - DD0E6F991B01B68E00DC035A /* OHHTTPStubs+NSURLSessionConfiguration.m in Sources */, - DD0E6F9A1B01B68E00DC035A /* OHHTTPStubsResponse.m in Sources */, DDBD016C196DC4740033959E /* MapViewTests.m in Sources */, - DD0E6F9D1B01B68E00DC035A /* OHPathHelpers.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -480,6 +440,10 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Mapbox GL Tests.app/Mapbox GL Tests"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/OHHTTPStubs/OHHTTPStubs/build/Debug-iphoneos", + ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -513,6 +477,10 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Mapbox GL Tests.app/Mapbox GL Tests"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/OHHTTPStubs/OHHTTPStubs/build/Debug-iphoneos", + ); GCC_PREPROCESSOR_DEFINITIONS = "KIF_XCTEST=1"; HEADER_SEARCH_PATHS = ( "$(inherited)", From 56c2272b7dc261f988c70e0f8cb90ff853932011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Mon, 7 Nov 2016 22:28:42 -0800 Subject: [PATCH 21/67] [ios] Upgraded to KIF 3.5.1, OHHTTPStubs 5.2.2 --- platform/ios/uitest/KIF | 2 +- platform/ios/uitest/OHHTTPStubs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/uitest/KIF b/platform/ios/uitest/KIF index 973a4cb65..bcb58d041 160000 --- a/platform/ios/uitest/KIF +++ b/platform/ios/uitest/KIF @@ -1 +1 @@ -Subproject commit 973a4cb653b54c3e8b2c0681f4097568ff0ac345 +Subproject commit bcb58d0419cfaefe286f3df1c8618bac43b45921 diff --git a/platform/ios/uitest/OHHTTPStubs b/platform/ios/uitest/OHHTTPStubs index deed01a15..e3cd0173c 160000 --- a/platform/ios/uitest/OHHTTPStubs +++ b/platform/ios/uitest/OHHTTPStubs @@ -1 +1 @@ -Subproject commit deed01a1592210a4c37f3f5c5f2b32fe0e41c605 +Subproject commit e3cd0173c459b8cd43f202fe8816f16759167170 From 1c9d314236736bf47e33fb95d2b457a5650fc519 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 14 Nov 2016 15:50:33 -0800 Subject: [PATCH 22/67] [ios, macos] Take back source and layer ownership on removal (#7048) If a source or layer is removed from the style, recapture the unique pointer ownership. This makes it safe to add back sources and layers after they have been removed. --- .../darwin/src/MGLBackgroundStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLCircleStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLFillStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLGeoJSONSource.mm | 8 ++++ platform/darwin/src/MGLLineStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLRasterSource.mm | 8 ++++ platform/darwin/src/MGLRasterStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLSource_Private.h | 9 ++++ platform/darwin/src/MGLStyle.mm | 9 +--- platform/darwin/src/MGLStyleLayer.mm.ejs | 42 +++++++++++-------- platform/darwin/src/MGLStyleLayer_Private.h | 11 ++++- platform/darwin/src/MGLSymbolStyleLayer.mm | 42 +++++++++++-------- platform/darwin/src/MGLVectorSource.mm | 8 ++++ 13 files changed, 219 insertions(+), 128 deletions(-) diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 38c97e8d4..a4914d324 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -32,6 +32,31 @@ } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Paint Attributes - (void)setBackgroundColor:(MGLStyleValue *)backgroundColor { @@ -65,21 +90,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 13eedf3f9..13262a8c9 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -53,6 +53,31 @@ return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Paint Attributes - (void)setCircleRadius:(MGLStyleValue *)circleRadius { @@ -126,21 +151,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 1f8b7402d..5aed779c8 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -53,6 +53,31 @@ return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Paint Attributes - (void)setFillAntialias:(MGLStyleValue *)fillAntialias { @@ -126,21 +151,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index 0dbe1030c..0213b6a27 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -64,6 +64,14 @@ const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"M mapView.mbglMap->addSource(std::move(_pendingSource)); } +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); + + _pendingSource = std::move(reinterpret_cast &>(removedSource)); + self.rawSource = _pendingSource.get(); +} + - (void)commonInit { auto source = std::make_unique(self.identifier.UTF8String, self.geoJSONOptions); diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index aa699ea37..c7509e287 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -53,6 +53,31 @@ return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { @@ -198,21 +223,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index fc47c2385..92494febf 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -65,4 +65,12 @@ mapView.mbglMap->addSource(std::move(_pendingSource)); } +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); + + _pendingSource = std::move(reinterpret_cast &>(removedSource)); + self.rawSource = _pendingSource.get(); +} + @end diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index ba1df40f9..063f5e338 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -32,6 +32,31 @@ } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Paint Attributes - (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { @@ -105,21 +130,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLSource_Private.h b/platform/darwin/src/MGLSource_Private.h index dff230ede..d360e71f3 100644 --- a/platform/darwin/src/MGLSource_Private.h +++ b/platform/darwin/src/MGLSource_Private.h @@ -28,4 +28,13 @@ */ - (void)addToMapView:(MGLMapView *)mapView; +/** + Removes the mbgl source that this object represents from the mbgl map. + + When a mbgl source is removed, ownership of the object is transferred back + to the `MGLSource` instance and the unique_ptr reference is valid again. It is + safe to add the source back to the style after it is removed. + */ +- (void)removeFromMapView:(MGLMapView *)mapView; + @end diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index d59194725..7e67273a3 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -168,7 +168,7 @@ static NSURL *MGLStyleURL_emerald; - (void)removeLayer:(MGLStyleLayer *)layer { - self.mapView.mbglMap->removeLayer(layer.identifier.UTF8String); + [layer removeFromMapView:self.mapView]; } - (void)addLayer:(MGLStyleLayer *)layer @@ -209,12 +209,7 @@ static NSURL *MGLStyleURL_emerald; - (void)removeSource:(MGLSource *)source { - self.mapView.mbglMap->removeSource(source.identifier.UTF8String); - - // Once a mbgl source is removed from the map, ownership does not return - // to the MGL source. Therefore, the rawSource pointer is set to NULL - // so that the implementation of MGL source can avoid using it again. - source.rawSource = NULL; + [source removeFromMapView:self.mapView]; } - (NS_ARRAY_OF(NSString *) *)styleClasses diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 48d013d48..d366a1955 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -73,6 +73,31 @@ } <% } -%> + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_castLayer> &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + <% if (layoutProperties.length) { -%> #pragma mark - Accessing the Layout Attributes @@ -106,21 +131,4 @@ <% } -%> <% } -%> -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index f61630b8c..bfce452a4 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -29,11 +29,18 @@ */ - (void)addToMapView:(MGLMapView *)mapView; - +/** + Removes the mbgl style layer that this object represents from the mbgl map. + + When a mbgl style layer is removed, ownership of the object is transferred back + to the `MGLStyleLayer` instance and the unique_ptr reference is valid again. It + is safe to add the layer back to the style after it is removed. + */ +- (void)removeFromMapView:(MGLMapView *)mapView; /** Adds the mbgl style layer that this object represents to the mbgl map below the specified `otherLayer`. - + Once a mbgl style layer is added, ownership of the object is transferred to the `mbgl::Map` and this object no longer has an active unique_ptr reference to the `mbgl::style::Layer`. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 539e0f2cc..082743be5 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -53,6 +53,31 @@ return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; } + +#pragma mark - Adding to and removing from a map view + +- (void)addToMapView:(MGLMapView *)mapView +{ + [self addToMapView:mapView belowLayer:nil]; +} + +- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer +{ + if (otherLayer) { + const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); + } else { + mapView.mbglMap->addLayer(std::move(_pendingLayer)); + } +} + +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + self.rawLayer = _pendingLayer.get(); +} + #pragma mark - Accessing the Layout Attributes - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { @@ -538,21 +563,4 @@ } -#pragma mark - Add style layer to map - -- (void)addToMapView:(MGLMapView *)mapView -{ - [self addToMapView:mapView belowLayer:nil]; -} - -- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer -{ - if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; - mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId); - } else { - mapView.mbglMap->addLayer(std::move(_pendingLayer)); - } -} - @end diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index 995565419..2c7b529d7 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -64,4 +64,12 @@ static NSString *MGLVectorSourceType = @"vector"; mapView.mbglMap->addSource(std::move(_pendingSource)); } +- (void)removeFromMapView:(MGLMapView *)mapView +{ + auto removedSource = mapView.mbglMap->removeSource(self.identifier.UTF8String); + + _pendingSource = std::move(reinterpret_cast &>(removedSource)); + self.rawSource = _pendingSource.get(); +} + @end From 13c6648713a14afaad7551e023b0d61318ada765 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 20 Oct 2016 16:53:00 -0400 Subject: [PATCH 23/67] [ios] Make map view UI elements' constraints unambiguous NSLayoutRelationGreaterThanOrEqual meant that it either greater-than or equal could satisify the constraint, when really all we need is equal. --- platform/ios/src/MGLMapView.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 39f243f57..8cd9fea64 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -776,7 +776,7 @@ public: [self.compassViewConstraints addObject: [NSLayoutConstraint constraintWithItem:compassContainer attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationGreaterThanOrEqual + relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 @@ -819,7 +819,7 @@ public: [self.logoViewConstraints addObject: [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationGreaterThanOrEqual + relatedBy:NSLayoutRelationEqual toItem:self.logoView attribute:NSLayoutAttributeBaseline multiplier:1 @@ -843,7 +843,7 @@ public: [self.attributionButtonConstraints addObject: [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationGreaterThanOrEqual + relatedBy:NSLayoutRelationEqual toItem:self.attributionButton attribute:NSLayoutAttributeBaseline multiplier:1 From 40a7e6b414d03db830c83830c8b0c0c5ba35093d Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 20 Oct 2016 18:50:00 -0400 Subject: [PATCH 24/67] [ios] Constrain compass directly to the top layout guide In iOS 10, the top layout guide is not always returning the expected value unless there is a constraint applied directly against it. --- platform/ios/src/MGLMapView.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 8cd9fea64..c5f1ae0d5 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -773,14 +773,18 @@ public: [constraintParentView removeConstraints:self.compassViewConstraints]; [self.compassViewConstraints removeAllObjects]; + // Work around an apparent iOS 10 bug where the top layout guide isn't always updated + // unless there's an active constraint against it. This means we cannot constrain + // directly to the top of self — instead, we must constrain to the top layout guide's + // bottom offset, then subtract that value from contentInset. [self.compassViewConstraints addObject: [NSLayoutConstraint constraintWithItem:compassContainer attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual - toItem:self - attribute:NSLayoutAttributeTop + toItem:viewController.topLayoutGuide + attribute:NSLayoutAttributeBottom multiplier:1 - constant:5 + self.contentInset.top]]; + constant:5 + self.contentInset.top - viewController.topLayoutGuide.length]]; [self.compassViewConstraints addObject: [NSLayoutConstraint constraintWithItem:self From 07b311d4906623928ff225677dcd7a4d1ee34143 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Tue, 15 Nov 2016 12:51:49 +0100 Subject: [PATCH 25/67] [ios] update layout after device has been rotated --- platform/ios/src/MGLMapView.mm | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index c5f1ae0d5..ee7f98976 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -533,6 +533,8 @@ public: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationWillEnterForegroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; // set initial position // @@ -639,6 +641,7 @@ public: - (void)dealloc { + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [_attributionButton removeObserver:self forKeyPath:@"hidden"]; @@ -760,31 +763,29 @@ public: - (void)updateConstraints { - // If we have a view controller reference, use its layout guides for our various top & bottom - // views so they don't underlap navigation or tool bars. If we don't have a reference, apply - // constraints against ourself to maintain (albeit less ideal) placement of the subviews. + // If we have a view controller reference and its automaticallyAdjustsScrollViewInsets + // is set to YES, use its view as the parent for constraints. -[MGLMapView adjustContentInset] + // already take top and bottom layout guides into account. If we don't have a reference, apply + // constraints against ourself to maintain placement of the subviews. // UIViewController *viewController = self.viewControllerForLayoutGuides; - UIView *constraintParentView = (viewController.view ? viewController.view : self); - + BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; + UIView *view = useLayoutGuides ? viewController.view : self; + // compass // UIView *compassContainer = self.compassView.superview; - [constraintParentView removeConstraints:self.compassViewConstraints]; + [view removeConstraints:self.compassViewConstraints]; [self.compassViewConstraints removeAllObjects]; - // Work around an apparent iOS 10 bug where the top layout guide isn't always updated - // unless there's an active constraint against it. This means we cannot constrain - // directly to the top of self — instead, we must constrain to the top layout guide's - // bottom offset, then subtract that value from contentInset. [self.compassViewConstraints addObject: [NSLayoutConstraint constraintWithItem:compassContainer attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual - toItem:viewController.topLayoutGuide - attribute:NSLayoutAttributeBottom + toItem:view + attribute:NSLayoutAttributeTop multiplier:1 - constant:5 + self.contentInset.top - viewController.topLayoutGuide.length]]; + constant:5 + self.contentInset.top]]; [self.compassViewConstraints addObject: [NSLayoutConstraint constraintWithItem:self @@ -813,11 +814,11 @@ public: attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:compassImage.size.height]]; - [constraintParentView addConstraints:self.compassViewConstraints]; + [view addConstraints:self.compassViewConstraints]; // logo bug // - [constraintParentView removeConstraints:self.logoViewConstraints]; + [view removeConstraints:self.logoViewConstraints]; [self.logoViewConstraints removeAllObjects]; [self.logoViewConstraints addObject: @@ -837,11 +838,11 @@ public: attribute:NSLayoutAttributeLeading multiplier:1 constant:8 + self.contentInset.left]]; - [constraintParentView addConstraints:self.logoViewConstraints]; + [view addConstraints:self.logoViewConstraints]; // attribution button // - [constraintParentView removeConstraints:self.attributionButtonConstraints]; + [view removeConstraints:self.attributionButtonConstraints]; [self.attributionButtonConstraints removeAllObjects]; [self.attributionButtonConstraints addObject: @@ -861,7 +862,7 @@ public: attribute:NSLayoutAttributeTrailing multiplier:1 constant:8 + self.contentInset.right]]; - [constraintParentView addConstraints:self.attributionButtonConstraints]; + [view addConstraints:self.attributionButtonConstraints]; [super updateConstraints]; } @@ -1068,6 +1069,11 @@ public: [super didMoveToSuperview]; } +- (void)deviceOrientationDidChange:(__unused NSNotification *)notification +{ + [self setNeedsLayout]; +} + - (void)sleepGL:(__unused NSNotification *)notification { MGLAssertIsMainThread(); From eefda0d3813237d3f333c83780d481bc8a104309 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Mon, 14 Nov 2016 16:02:16 -0800 Subject: [PATCH 26/67] [ios, macos] fixes #7059: raise exception for abstract sources on add (#7060) --- platform/darwin/src/MGLStyle.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 7e67273a3..2da18bf95 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -204,6 +204,13 @@ static NSURL *MGLStyleURL_emerald; - (void)addSource:(MGLSource *)source { + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be added to the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } + [source addToMapView:self.mapView]; } From 9d5edb41ad5a2ed15a5f0344e5772488aac883eb Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 15 Nov 2016 10:05:35 -0800 Subject: [PATCH 27/67] [ios, macos] refs #7060: properly check removed layers & sources (#7062) --- platform/darwin/src/MGLStyle.mm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 2da18bf95..980abe3e3 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -168,6 +168,12 @@ static NSURL *MGLStyleURL_emerald; - (void)removeLayer:(MGLStyleLayer *)layer { + if (!layer.rawLayer) { + [NSException raise:NSInvalidArgumentException format: + @"The style layer %@ cannot be removed from the style. " + @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", + layer]; + } [layer removeFromMapView:self.mapView]; } @@ -198,7 +204,6 @@ static NSURL *MGLStyleURL_emerald; @"Make sure otherLayer was obtained using -[MGLStyle layerWithIdentifier:].", otherLayer]; } - [layer addToMapView:self.mapView belowLayer:otherLayer]; } @@ -210,12 +215,17 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the source was created as a member of a concrete subclass of MGLSource.", source]; } - [source addToMapView:self.mapView]; } - (void)removeSource:(MGLSource *)source { + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be removed from the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } [source removeFromMapView:self.mapView]; } From 5a982f9ccc15f166c7dfc81c98f30c2113f8896e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 15 Nov 2016 13:21:24 -0800 Subject: [PATCH 28/67] [ios, macos] Updated changelog --- platform/ios/CHANGELOG.md | 3 ++- platform/macos/CHANGELOG.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index f5b10ed30..9adfe13b9 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -41,13 +41,14 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * The user dot now animates between user locations when user tracking is disabled. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215)) * To customize the appearance of the user location annotation, subclass the newly added MGLUserLocationAnnotationView class and implement `-[MGLMapViewDelegate mapView:viewForAnnotation:]`. ([#5882](https://github.com/mapbox/mapbox-gl-native/pull/5882)) +* `-[MGLMapView viewForAnnotation:]` now returns the user location annotation view when given the user location annotation. ([#6957](https://github.com/mapbox/mapbox-gl-native/pull/6957)) * Fixed an issue causing the user dot’s accuracy ring to wobble while zooming in and out. ([#6019](https://github.com/mapbox/mapbox-gl-native/pull/6019)) * Heading accuracy indicator sizing has been changed to appear more precise. ([#6120](https://github.com/mapbox/mapbox-gl-native/pull/6120)) * Fixed an issue that caused the map to not update to reflect the centerOffset when the user location was tracked. ([#6216](https://github.com/mapbox/mapbox-gl-native/pull/6216)) ### Annotations -* MGLPolyline annotations and the exterior coordinates of MGLPolygon annotations are now able to be mutated, part or all, and changes are displayed immediately. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) +* Added new methods to MGLMultiPoint for changing or appending vertices along polyline annotations and the exteriors of polygon annotations. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) * Added new APIs to MGLMapView to query for visible annotations. Combined with `-[MGLMapView viewForAnnotation:]`, these APIs can be used to access all visible annotation views. ([6061](https://github.com/mapbox/mapbox-gl-native/pull/6061)) * Fixed an issue causing offscreen annotation views to be updated even when they were in the reuse queue. ([#5987](https://github.com/mapbox/mapbox-gl-native/pull/5987)) * Fixed an issue preventing MGLAnnotationView from animating when its coordinate changes. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215)) diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 82d4b3b28..1aa3b64f9 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -32,7 +32,7 @@ ### Annotations * Added `showAnnotations:animated:` and `showAnnotations:edgePadding:animated:`, which moves the map viewport to show the specified annotations. ([#5749](https://github.com/mapbox/mapbox-gl-native/pull/5749)) -* MGLPolyline annotations and the exterior coordinates of MGLPolygon annotations are now able to be mutated, part or all, and changes are displayed immediately. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) +* Added new methods to MGLMultiPoint for changing or appending vertices along polyline annotations and the exteriors of polygon annotations. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) * Added new APIs to MGLMapView to query for visible annotations. ([6061](https://github.com/mapbox/mapbox-gl-native/pull/6061)) * Deprecated `-[MGLMapViewDelegate mapView:alphaForShapeAnnotation:]` in favor of specifying an alpha component via `-[MGLMapViewDelegate mapView:strokeColorForShapeAnnotation:]` or `-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]`. ([#6706](https://github.com/mapbox/mapbox-gl-native/pull/6706)) * To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088)) From 068a89c2f8f1fe8962113c75e782cd7e204ca37a Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 15 Nov 2016 13:39:09 -0800 Subject: [PATCH 29/67] [ios, macos] Use NSNumber in exception strings (#7083) --- platform/darwin/src/MGLMultiPoint.mm | 8 ++++---- platform/darwin/src/MGLPointCollection.mm | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index 66ce27614..f086bcbc3 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -58,8 +58,8 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException - format:@"Invalid coordinate range %@ extends beyond current coordinate count of %zu", - NSStringFromRange(range), [self pointCount]]; + format:@"Invalid coordinate range %@ extends beyond current coordinate count of %@", + NSStringFromRange(range), @([self pointCount])]; } std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); @@ -83,8 +83,8 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) if (NSMaxRange(range) > _coordinates.size()) { [NSException raise:NSRangeException - format:@"Invalid range %@ for existing coordinate count %zu", - NSStringFromRange(range), [self pointCount]]; + format:@"Invalid range %@ for existing coordinate count %@", + NSStringFromRange(range), @([self pointCount])]; } [self willChangeValueForKey:@"coordinates"]; diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index adf3cc3d4..21982ca7b 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -54,8 +54,8 @@ NS_ASSUME_NONNULL_BEGIN if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException - format:@"Invalid coordinate range %@ extends beyond current coordinate count of %zu", - NSStringFromRange(range), [self pointCount]]; + format:@"Invalid coordinate range %@ extends beyond current coordinate count of %@", + NSStringFromRange(range), @([self pointCount])]; } std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); From 7e6d8db1364165b397562f43cd162814f36c4ec4 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 15 Nov 2016 13:47:13 -0800 Subject: [PATCH 30/67] Release ios-v3.4.0-beta.3 (#7082) --- platform/ios/CHANGELOG.md | 13 ++++++++++++- platform/ios/Mapbox-iOS-SDK-symbols.podspec | 2 +- platform/ios/Mapbox-iOS-SDK.podspec | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 9adfe13b9..4cb921f38 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -75,12 +75,23 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Database errors are now logged to the console. ([#6291](https://github.com/mapbox/mapbox-gl-native/pull/6291)) ### Other changes - +* Improved the performance of symbol style layers. ([#7025](https://github.com/mapbox/mapbox-gl-native/pull/7025)) * As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143)) * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) * MGLMapDebugOverdrawVisualizationMask no longer has any effect in Release builds of the SDK. This debug mask has been disabled for performance reasons. ([#5555](https://github.com/mapbox/mapbox-gl-native/pull/5555)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) +## 3.3.6 - November 9, 2016 + +* Fixed a crash that occurred during low-memory situations when multiple instances of MGLMapView were in the view hierarchy. The speculative fix in v3.3.5 has been reverted. ([#6972](https://github.com/mapbox/mapbox-gl-native/pull/6972)) + +## 3.3.5 - November 2, 2016 + +* Speculatively fixed an OpenGL rendering crash. ([#6844](https://github.com/mapbox/mapbox-gl-native/pull/6844)) +* Fixed an issue with symbols not being properly stripped from the dynamic framework. The dSYM file included with the standard dynamic framework in previous releases (e.g., `mapbox-ios-sdk-3.3.4-dynamic.zip` or the `Mapbox-iOS-SDK` pod) could not be used to symbolicate crashes. ([#6531](https://github.com/mapbox/mapbox-gl-native/pull/6531)) +* Include simulator architecture slices in the dSYM file that is generated for release builds. ([#5740](https://github.com/mapbox/mapbox-gl-native/pull/5740)) +* Fixed a rare networking-related crash. ([#5932](https://github.com/mapbox/mapbox-gl-native/pull/5932)) + ## 3.3.4 - August 8, 2016 * Fixed an issue that caused the user dot to be selected when tapping an annotation that lies within the user dot’s accuracy circle. First attempt was [#5816](https://github.com/mapbox/mapbox-gl-native/pull/5816) in v3.3.2, which excluded the pulsing halo but not the accuracy circle. ([#5894](https://github.com/mapbox/mapbox-gl-native/pull/5894)) diff --git a/platform/ios/Mapbox-iOS-SDK-symbols.podspec b/platform/ios/Mapbox-iOS-SDK-symbols.podspec index e26de7915..dbb6030ce 100644 --- a/platform/ios/Mapbox-iOS-SDK-symbols.podspec +++ b/platform/ios/Mapbox-iOS-SDK-symbols.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'Mapbox-iOS-SDK' - m.version = '3.4.0-beta.2-symbols' + m.version = '3.4.0-beta.3-symbols' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source, OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa Touch APIs.' diff --git a/platform/ios/Mapbox-iOS-SDK.podspec b/platform/ios/Mapbox-iOS-SDK.podspec index 6fd6d4b46..110c6d4e7 100644 --- a/platform/ios/Mapbox-iOS-SDK.podspec +++ b/platform/ios/Mapbox-iOS-SDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'Mapbox-iOS-SDK' - m.version = '3.4.0-beta.2' + m.version = '3.4.0-beta.3' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source, OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa Touch APIs.' From b4aba87892d8b6fa5c9d5608032bf54db98b6143 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 22 Aug 2016 13:59:09 +0200 Subject: [PATCH 31/67] [ios, macos] override style spec documentation --- .../darwin/scripts/generate-style-code.js | 3 +- .../scripts/style-spec-overrides-v8.json | 55 +++++++++++++++++++ platform/darwin/src/MGLBackgroundStyleLayer.h | 2 +- platform/darwin/src/MGLCircleStyleLayer.h | 2 +- platform/darwin/src/MGLFillStyleLayer.h | 6 +- platform/darwin/src/MGLLineStyleLayer.h | 4 +- platform/darwin/src/MGLSymbolStyleLayer.h | 14 ++--- 7 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 platform/darwin/scripts/style-spec-overrides-v8.json diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 62ab3b6b9..80d7504de 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -2,8 +2,9 @@ const fs = require('fs'); const ejs = require('ejs'); -const spec = require('mapbox-gl-style-spec').latest; +const _ = require('lodash'); const colorParser = require('csscolorparser'); +const spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json')); const prefix = 'MGL'; const suffix = 'StyleLayer'; diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json new file mode 100644 index 000000000..ed4293513 --- /dev/null +++ b/platform/darwin/scripts/style-spec-overrides-v8.json @@ -0,0 +1,55 @@ +{ + "layout_symbol": { + "icon-text-fit-padding": { + "doc": "Size of the additional area added to dimensions determined by `icon-text-fit`." + }, + "icon-offset": { + "doc": "Offset distance of icon from its anchor." + }, + "text-offset": { + "doc": "Offset distance of text from its anchor." + }, + "text-transform": { + "doc": "Specifies how to capitalize text." + } + }, + "paint_background": { + "background-pattern": { + "doc": "Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512)." + } + }, + "paint_fill": { + "fill-pattern": { + "doc": "Name of image in style images to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512)." + } + }, + "paint_line": { + "line-pattern": { + "doc": "Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512)." + }, + "line-translate": { + "doc": "The geometry's offset." + } + }, + "paint_circle": { + "circle-translate": { + "doc": "The geometry's offset." + } + }, + "paint_fill": { + "fill-translate": { + "doc": "The geometry's offset." + }, + "fill-color": { + "doc": "The color of the filled part of this layer." + } + }, + "paint_symbol": { + "icon-translate": { + "doc": "Distance that the icon's anchor is moved from its original placement." + }, + "text-translate": { + "doc": "Distance that the text's anchor is moved from its original placement." + } + } +} \ No newline at end of file diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h index 1c167fc91..a70383cc9 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer.h @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN #endif /** - Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). */ @property (nonatomic, null_resettable) MGLStyleValue *backgroundPattern; diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index 6006250cd..da7076e7d 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -88,7 +88,7 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { @property (nonatomic, null_resettable) MGLStyleValue *circleOpacity; /** - The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + The geometry's offset. This property is measured in points. diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h index 712bfea99..799fa380c 100644 --- a/platform/darwin/src/MGLFillStyleLayer.h +++ b/platform/darwin/src/MGLFillStyleLayer.h @@ -48,7 +48,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { #if TARGET_OS_IPHONE /** - The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1pt stroke, if it is used. + The color of the filled part of this layer. The default value of this property is an `MGLStyleValue` object containing `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. @@ -57,7 +57,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *fillColor; #else /** - The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1pt stroke, if it is used. + The color of the filled part of this layer. The default value of this property is an `MGLStyleValue` object containing `NSColor.blackColor`. Set this property to `nil` to reset it to the default value. @@ -74,7 +74,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *fillOutlineColor; /** - The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + The geometry's offset. This property is measured in points. diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 663e92771..68b0a73a2 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -134,7 +134,7 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) { #endif /** - The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + The geometry's offset. This property is measured in points. @@ -197,7 +197,7 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *> *lineDasharray; /** - Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). + Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). */ @property (nonatomic, null_resettable) MGLStyleValue *linePattern; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index 9bd943a34..dc0cd236c 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -171,7 +171,7 @@ typedef NS_ENUM(NSUInteger, MGLTextAnchor) { }; /** - Specifies how to capitalize text, similar to the CSS `text-transform` property. + Specifies how to capitalize text. Values of this type are used in the `textTransform` property of `MGLSymbolStyleLayer`. */ @@ -312,7 +312,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconTextFit; /** - Size of the additional area added to dimensions determined by `iconTextFit`, in clockwise order: top, right, bottom, left. + Size of the additional area added to dimensions determined by `iconTextFit`. This property is measured in points. @@ -359,7 +359,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconKeepUpright; /** - Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. + Offset distance of icon from its anchor. The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing a `CGVector` struct set to 0 from the left and 0 from the top. Set this property to `nil` to reset it to the default value. @@ -506,7 +506,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textKeepUpright; /** - Specifies how to capitalize text, similar to the CSS `text-transform` property. + Specifies how to capitalize text. The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextTransformNone`. Set this property to `nil` to reset it to the default value. @@ -515,7 +515,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textTransform; /** - Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. + Offset distance of text from its anchor. This property is measured in ems. @@ -626,7 +626,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconHaloBlur; /** - Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. + Distance that the icon's anchor is moved from its original placement. This property is measured in points. @@ -717,7 +717,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textHaloBlur; /** - Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. + Distance that the text's anchor is moved from its original placement. This property is measured in points. From e858dba86def62967865856f4dbbe1b24663cb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 18 Nov 2016 10:29:17 -0800 Subject: [PATCH 32/67] [ios, macos] Documented localization workflow --- platform/ios/DEVELOPING.md | 9 +++++++++ platform/macos/DEVELOPING.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/platform/ios/DEVELOPING.md b/platform/ios/DEVELOPING.md index a94845620..94ff49ee1 100644 --- a/platform/ios/DEVELOPING.md +++ b/platform/ios/DEVELOPING.md @@ -109,6 +109,15 @@ To add or update text that the user may see in the iOS SDK: 1. _(Optional.)_ When dealing with a number followed by a pluralized word, do not split the string. Instead, use a format string and make `val` ambiguous, like `%d file(s)`. Then pluralize for English in the appropriate [.stringsdict file](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html). See [platform/darwin/resources/en.lproj/Foundation.stringsdict](../darwin/resources/en.lproj/Foundation.stringsdict) for an example. Localizers should do likewise for their languages. 1. Run `make genstrings` and commit any changes it makes to .strings files. The make rule also updates the macOS SDK’s strings tables. +### Adding a localization + +To add a localization to the iOS SDK: + +1. In ios.xcworkspace, open the project editor for ios.xcodeproj. Using the project editor’s sidebar or tab bar dropdown, go to the “iosâ€� project; under the Localizations section of the Info tab, click the + button to add your language to the project. +1. In the sheet that appears, select all the .strings and .stringsdict files but not the .storyboard file. (LaunchScreen.storyboard is part of the iosapp example application, which is not localized.) +1. In the Project navigator, expand each .strings and .stringsdict file in the project. An additional version for your localization should be listed; translate it. Translate everything on the right side of the equals sign. Leave the left side and any comments unmodified. See Apple’s documentation on the [.strings](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html) and [.stringsdict](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html) formats. +1. You’re already most of the way towards localizing the macOS SDK too – consider [completing that localization](../macos/DEVELOPING.md#adding-a-localization). + ## Testing `make ios-test` builds and runs unit tests of cross-platform code as well as the SDK. diff --git a/platform/macos/DEVELOPING.md b/platform/macos/DEVELOPING.md index cf52a650a..71eb7995c 100644 --- a/platform/macos/DEVELOPING.md +++ b/platform/macos/DEVELOPING.md @@ -86,6 +86,15 @@ To add or update text that the user may see in the macOS SDK: 1. _(Optional.)_ When dealing with a number followed by a pluralized word, do not split the string. Instead, use a format string and make `val` ambiguous, like `%d file(s)`. Then pluralize for English in the appropriate [.stringsdict file](https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html). See [platform/darwin/resources/en.lproj/Foundation.stringsdict](../darwin/resources/en.lproj/Foundation.stringsdict) for an example. Localizers should do likewise for their languages. 1. Run `make genstrings` and commit any changes it makes to .strings files. The make rule also updates the iOS SDK’s strings tables. +### Adding a localization + +To add a localization to the macOS SDK: + +1. In macos.xcworkspace, open the project editor for macos.xcodeproj. Using the project editor’s sidebar or tab bar dropdown, go to the “macosâ€� project; under the Localizations section of the Info tab, click the + button to add your language to the project. +1. In the sheet that appears, select all the .strings and .stringsdict files but no .xib file. (Most of the XIBs are part of the macosapp example application, which is not localized, while MGLAnnotationCallout.xib contains no localizable strings.) +1. In the Project navigator, expand each .strings and .stringsdict file in the project. An additional version for your localization should be listed; translate it. Translate everything on the right side of the equals sign. Leave the left side and any comments unmodified. See Apple’s documentation on the [.strings](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html) and [.stringsdict](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html) formats. +1. You’re already most of the way towards localizing the iOS SDK too – consider [completing that localization](../ios/DEVELOPING.md#adding-a-localization). + ## Access tokens The demo applications use Mapbox vector tiles, which require a Mapbox account and API access token. Obtain an access token on the [Mapbox account page](https://www.mapbox.com/studio/account/tokens/). You will be prompted for this access token the first time you launch the demo application. From 307f8e4f41a440fdfcd9c7bb1833110ab9278ccf Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Sun, 20 Nov 2016 13:16:20 +0100 Subject: [PATCH 33/67] [ios] simplified constraints and fixed regression 6954 (#7084) * [ios] simplified constraints and fixed regression 6954 * [ios] removed excessive constraints * [ios] removed compass container view --- platform/ios/src/MGLMapView.mm | 52 +++++++--------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index ee7f98976..e857a9fa4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -468,10 +468,8 @@ public: _compassView.accessibilityTraits = UIAccessibilityTraitButton; _compassView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label"); _compassView.accessibilityHint = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_HINT", nil, nil, @"Rotates the map to face due north", @"Accessibility hint"); - UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; - [container addSubview:_compassView]; - container.translatesAutoresizingMaskIntoConstraints = NO; - [self addSubview:container]; + _compassView.translatesAutoresizingMaskIntoConstraints = NO; + [self addSubview:_compassView]; _compassViewConstraints = [NSMutableArray array]; // setup interaction @@ -763,26 +761,16 @@ public: - (void)updateConstraints { - // If we have a view controller reference and its automaticallyAdjustsScrollViewInsets - // is set to YES, use its view as the parent for constraints. -[MGLMapView adjustContentInset] - // already take top and bottom layout guides into account. If we don't have a reference, apply - // constraints against ourself to maintain placement of the subviews. - // - UIViewController *viewController = self.viewControllerForLayoutGuides; - BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; - UIView *view = useLayoutGuides ? viewController.view : self; - // compass // - UIView *compassContainer = self.compassView.superview; - [view removeConstraints:self.compassViewConstraints]; + [self removeConstraints:self.compassViewConstraints]; [self.compassViewConstraints removeAllObjects]; [self.compassViewConstraints addObject: - [NSLayoutConstraint constraintWithItem:compassContainer + [NSLayoutConstraint constraintWithItem:self.compassView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual - toItem:view + toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:5 + self.contentInset.top]]; @@ -791,34 +779,16 @@ public: [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual - toItem:compassContainer + toItem:self.compassView attribute:NSLayoutAttributeTrailing multiplier:1 constant:5 + self.contentInset.right]]; - UIImage *compassImage = self.compassView.image; - [self.compassViewConstraints addObject: - [NSLayoutConstraint constraintWithItem:compassContainer - attribute:NSLayoutAttributeWidth - relatedBy:NSLayoutRelationEqual - toItem:nil - attribute:NSLayoutAttributeNotAnAttribute - multiplier:1 - constant:compassImage.size.width]]; - - [self.compassViewConstraints addObject: - [NSLayoutConstraint constraintWithItem:compassContainer - attribute:NSLayoutAttributeHeight - relatedBy:NSLayoutRelationEqual - toItem:nil - attribute:NSLayoutAttributeNotAnAttribute - multiplier:1 - constant:compassImage.size.height]]; - [view addConstraints:self.compassViewConstraints]; + [self addConstraints:self.compassViewConstraints]; // logo bug // - [view removeConstraints:self.logoViewConstraints]; + [self removeConstraints:self.logoViewConstraints]; [self.logoViewConstraints removeAllObjects]; [self.logoViewConstraints addObject: @@ -838,11 +808,11 @@ public: attribute:NSLayoutAttributeLeading multiplier:1 constant:8 + self.contentInset.left]]; - [view addConstraints:self.logoViewConstraints]; + [self addConstraints:self.logoViewConstraints]; // attribution button // - [view removeConstraints:self.attributionButtonConstraints]; + [self removeConstraints:self.attributionButtonConstraints]; [self.attributionButtonConstraints removeAllObjects]; [self.attributionButtonConstraints addObject: @@ -862,7 +832,7 @@ public: attribute:NSLayoutAttributeTrailing multiplier:1 constant:8 + self.contentInset.right]]; - [view addConstraints:self.attributionButtonConstraints]; + [self addConstraints:self.attributionButtonConstraints]; [super updateConstraints]; } From 8fa078c08660fd387dad9e8e323984fe059bbbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 16 Nov 2016 15:03:05 +0100 Subject: [PATCH 34/67] [core] cache raster tiles --- src/mbgl/style/source_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index b38439040..7949f26d4 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -137,7 +137,7 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn, idealTiles, zoomRange, tileZoom); - if (type != SourceType::Raster && type != SourceType::Annotations && cache.getSize() == 0) { + if (type != SourceType::Annotations && cache.getSize() == 0) { size_t conservativeCacheSize = ((float)parameters.transformState.getWidth() / util::tileSize) * ((float)parameters.transformState.getHeight() / util::tileSize) * From 4e4e05ef50808a27d7a9a46c830d05165bd85e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Thu, 17 Nov 2016 02:26:02 -0800 Subject: [PATCH 35/67] [ios, macos] Updated changelog for #7091 --- platform/ios/CHANGELOG.md | 2 ++ platform/macos/CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 4cb921f38..8124fb3ac 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -75,6 +75,8 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Database errors are now logged to the console. ([#6291](https://github.com/mapbox/mapbox-gl-native/pull/6291)) ### Other changes + +* Raster tiles such as those from Mapbox Satellite are now cached, eliminating flashing while panning back and forth. ([#7091](https://github.com/mapbox/mapbox-gl-native/pull/7091)) * Improved the performance of symbol style layers. ([#7025](https://github.com/mapbox/mapbox-gl-native/pull/7025)) * As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143)) * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 1aa3b64f9..047ff9518 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -52,6 +52,7 @@ ### Other changes +* Raster tiles such as those from Mapbox Satellite are now cached, eliminating flashing while panning back and forth. ([#7091](https://github.com/mapbox/mapbox-gl-native/pull/7091)) * Fixed an issue where the map view’s center would always be calculated as if the view occupied the entire window. ([#6102](https://github.com/mapbox/mapbox-gl-native/pull/6102)) * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) From 13e0f9e527366dce43f59055fde17818f443e356 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 14 Nov 2016 16:59:30 -0800 Subject: [PATCH 36/67] [ios, macos] Refactor runtime styling enumeration properties Correctly map SDK runtime styling enumerations to mbgl equivalents. Also, add category methods to NSValue so enums can be wrapped up with less of the details of how they are layed out in memory in Objective-C. --- .../darwin/scripts/generate-style-code.js | 22 ++ .../darwin/src/MGLBackgroundStyleLayer.mm | 19 +- platform/darwin/src/MGLCircleStyleLayer.mm | 72 ++-- platform/darwin/src/MGLFillStyleLayer.mm | 60 +-- platform/darwin/src/MGLLineStyleLayer.mm | 114 +++--- platform/darwin/src/MGLRasterStyleLayer.mm | 36 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 81 +++- platform/darwin/src/MGLStyleValue_Private.h | 100 ++++- platform/darwin/src/MGLSymbolStyleLayer.mm | 346 +++++++++++------- .../NSValue+MGLStyleEnumAttributeAdditions.h | 232 ++++++++++++ ...Value+MGLStyleEnumAttributeAdditions.h.ejs | 66 ++++ .../NSValue+MGLStyleEnumAttributeAdditions.mm | 169 +++++++++ ...alue+MGLStyleEnumAttributeAdditions.mm.ejs | 46 +++ platform/ios/app/MBXViewController.m | 55 +++ platform/ios/ios.xcodeproj/project.pbxproj | 16 + platform/ios/src/Mapbox.h | 1 + .../macos/macos.xcodeproj/project.pbxproj | 12 + platform/macos/src/Mapbox.h | 1 + 18 files changed, 1160 insertions(+), 288 deletions(-) create mode 100644 platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h create mode 100644 platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs create mode 100644 platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm create mode 100644 platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 80d7504de..9090bb40e 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -301,6 +301,8 @@ global.mbglType = function(property) { const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/src/MGLRuntimeStylingTests.m.ejs', 'utf8'), { strict: true}); +const categoryH = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs', 'utf8'), { strict: true}); +const categoryM = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs', 'utf8'), { strict: true}); const layers = Object.keys(spec.layer.type.values).map((type) => { const layoutProperties = Object.keys(spec[`layout_${type}`]).reduce((memo, name) => { @@ -345,8 +347,28 @@ ${macosComment}${decl} }); } +var allLayoutProperties = []; +var allPaintProperties = []; +var allTypes = []; + for (var layer of layers) { + allLayoutProperties.push(layer.layoutProperties); + allPaintProperties.push(layer.paintProperties); + allTypes.push(layer.type); + const containsEnumerationProperties = _.filter(layer.layoutProperties, function(property){ return property["type"] === "enum"; }).length || _.filter(layer.paintProperties, function(property){ return property["type"] === "enum"; }).length; + layer.containsEnumerationProperties = containsEnumerationProperties; + fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer))); fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer)); fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer)); } + +fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h`, categoryH({ + layoutProperties: _.flatten(allLayoutProperties), + paintProperties: _.flatten(allPaintProperties), + types: allTypes +})); +fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm`, categoryM({ + layoutProperties: _.flatten(allLayoutProperties), + paintProperties: _.flatten(allPaintProperties) +})); diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index a4914d324..386c6322e 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -10,6 +10,7 @@ #include + @interface MGLBackgroundStyleLayer () @property (nonatomic) mbgl::style::BackgroundLayer *rawLayer; @@ -26,13 +27,11 @@ if (self = [super initWithIdentifier:identifier]) { auto layer = std::make_unique(identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -54,38 +53,38 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setBackgroundColor:(MGLStyleValue *)backgroundColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundColor); - self.rawLayer->setBackgroundColor(mbglValue); + _rawLayer->setBackgroundColor(mbglValue); } - (MGLStyleValue *)backgroundColor { - auto propertyValue = self.rawLayer->getBackgroundColor() ?: self.rawLayer->getDefaultBackgroundColor(); + auto propertyValue = _rawLayer->getBackgroundColor() ?: _rawLayer->getDefaultBackgroundColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundPattern:(MGLStyleValue *)backgroundPattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundPattern); - self.rawLayer->setBackgroundPattern(mbglValue); + _rawLayer->setBackgroundPattern(mbglValue); } - (MGLStyleValue *)backgroundPattern { - auto propertyValue = self.rawLayer->getBackgroundPattern() ?: self.rawLayer->getDefaultBackgroundPattern(); + auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundOpacity:(MGLStyleValue *)backgroundOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundOpacity); - self.rawLayer->setBackgroundOpacity(mbglValue); + _rawLayer->setBackgroundOpacity(mbglValue); } - (MGLStyleValue *)backgroundOpacity { - auto propertyValue = self.rawLayer->getBackgroundOpacity() ?: self.rawLayer->getDefaultBackgroundOpacity(); + auto propertyValue = _rawLayer->getBackgroundOpacity() ?: _rawLayer->getDefaultBackgroundOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 13262a8c9..4e5f2c7fd 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -10,6 +10,20 @@ #include +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, { + { MGLCircleTranslateAnchorMap, "map" }, + { MGLCircleTranslateAnchorViewport, "viewport" }, + }); + + MBGL_DEFINE_ENUM(MGLCirclePitchScale, { + { MGLCirclePitchScaleMap, "map" }, + { MGLCirclePitchScaleViewport, "viewport" }, + }); + +} + @interface MGLCircleStyleLayer () @property (nonatomic) mbgl::style::CircleLayer *rawLayer; @@ -26,34 +40,30 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -75,79 +85,85 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setCircleRadius:(MGLStyleValue *)circleRadius { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleRadius); - self.rawLayer->setCircleRadius(mbglValue); + _rawLayer->setCircleRadius(mbglValue); } - (MGLStyleValue *)circleRadius { - auto propertyValue = self.rawLayer->getCircleRadius() ?: self.rawLayer->getDefaultCircleRadius(); + auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleColor:(MGLStyleValue *)circleColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleColor); - self.rawLayer->setCircleColor(mbglValue); + _rawLayer->setCircleColor(mbglValue); } - (MGLStyleValue *)circleColor { - auto propertyValue = self.rawLayer->getCircleColor() ?: self.rawLayer->getDefaultCircleColor(); + auto propertyValue = _rawLayer->getCircleColor() ?: _rawLayer->getDefaultCircleColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleBlur:(MGLStyleValue *)circleBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleBlur); - self.rawLayer->setCircleBlur(mbglValue); + _rawLayer->setCircleBlur(mbglValue); } - (MGLStyleValue *)circleBlur { - auto propertyValue = self.rawLayer->getCircleBlur() ?: self.rawLayer->getDefaultCircleBlur(); + auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleOpacity:(MGLStyleValue *)circleOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleOpacity); - self.rawLayer->setCircleOpacity(mbglValue); + _rawLayer->setCircleOpacity(mbglValue); } - (MGLStyleValue *)circleOpacity { - auto propertyValue = self.rawLayer->getCircleOpacity() ?: self.rawLayer->getDefaultCircleOpacity(); + auto propertyValue = _rawLayer->getCircleOpacity() ?: _rawLayer->getDefaultCircleOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleTranslate:(MGLStyleValue *)circleTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(circleTranslate); - self.rawLayer->setCircleTranslate(mbglValue); + _rawLayer->setCircleTranslate(mbglValue); } - (MGLStyleValue *)circleTranslate { - auto propertyValue = self.rawLayer->getCircleTranslate() ?: self.rawLayer->getDefaultCircleTranslate(); + auto propertyValue = _rawLayer->getCircleTranslate() ?: _rawLayer->getDefaultCircleTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setCircleTranslateAnchor:(MGLStyleValue *)circleTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleTranslateAnchor); - self.rawLayer->setCircleTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circleTranslateAnchor); + _rawLayer->setCircleTranslateAnchor(mbglValue); } - (MGLStyleValue *)circleTranslateAnchor { - auto propertyValue = self.rawLayer->getCircleTranslateAnchor() ?: self.rawLayer->getDefaultCircleTranslateAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getCircleTranslateAnchor() ?: _rawLayer->getDefaultCircleTranslateAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circlePitchScale); - self.rawLayer->setCirclePitchScale(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); + _rawLayer->setCirclePitchScale(mbglValue); } - (MGLStyleValue *)circlePitchScale { - auto propertyValue = self.rawLayer->getCirclePitchScale() ?: self.rawLayer->getDefaultCirclePitchScale(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 5aed779c8..24c8a90f7 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -10,6 +10,15 @@ #include +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLFillTranslateAnchor, { + { MGLFillTranslateAnchorMap, "map" }, + { MGLFillTranslateAnchorViewport, "viewport" }, + }); + +} + @interface MGLFillStyleLayer () @property (nonatomic) mbgl::style::FillLayer *rawLayer; @@ -26,34 +35,30 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -75,78 +80,81 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setFillAntialias:(MGLStyleValue *)fillAntialias { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillAntialias); - self.rawLayer->setFillAntialias(mbglValue); + _rawLayer->setFillAntialias(mbglValue); } - (MGLStyleValue *)fillAntialias { - auto propertyValue = self.rawLayer->getFillAntialias() ?: self.rawLayer->getDefaultFillAntialias(); + auto propertyValue = _rawLayer->getFillAntialias() ?: _rawLayer->getDefaultFillAntialias(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOpacity:(MGLStyleValue *)fillOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOpacity); - self.rawLayer->setFillOpacity(mbglValue); + _rawLayer->setFillOpacity(mbglValue); } - (MGLStyleValue *)fillOpacity { - auto propertyValue = self.rawLayer->getFillOpacity() ?: self.rawLayer->getDefaultFillOpacity(); + auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillColor:(MGLStyleValue *)fillColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillColor); - self.rawLayer->setFillColor(mbglValue); + _rawLayer->setFillColor(mbglValue); } - (MGLStyleValue *)fillColor { - auto propertyValue = self.rawLayer->getFillColor() ?: self.rawLayer->getDefaultFillColor(); + auto propertyValue = _rawLayer->getFillColor() ?: _rawLayer->getDefaultFillColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOutlineColor:(MGLStyleValue *)fillOutlineColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOutlineColor); - self.rawLayer->setFillOutlineColor(mbglValue); + _rawLayer->setFillOutlineColor(mbglValue); } - (MGLStyleValue *)fillOutlineColor { - auto propertyValue = self.rawLayer->getFillOutlineColor() ?: self.rawLayer->getDefaultFillOutlineColor(); + auto propertyValue = _rawLayer->getFillOutlineColor() ?: _rawLayer->getDefaultFillOutlineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillTranslate:(MGLStyleValue *)fillTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(fillTranslate); - self.rawLayer->setFillTranslate(mbglValue); + _rawLayer->setFillTranslate(mbglValue); } - (MGLStyleValue *)fillTranslate { - auto propertyValue = self.rawLayer->getFillTranslate() ?: self.rawLayer->getDefaultFillTranslate(); + auto propertyValue = _rawLayer->getFillTranslate() ?: _rawLayer->getDefaultFillTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setFillTranslateAnchor:(MGLStyleValue *)fillTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillTranslateAnchor); - self.rawLayer->setFillTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(fillTranslateAnchor); + _rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue *)fillTranslateAnchor { - auto propertyValue = self.rawLayer->getFillTranslateAnchor() ?: self.rawLayer->getDefaultFillTranslateAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setFillPattern:(MGLStyleValue *)fillPattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillPattern); - self.rawLayer->setFillPattern(mbglValue); + _rawLayer->setFillPattern(mbglValue); } - (MGLStyleValue *)fillPattern { - auto propertyValue = self.rawLayer->getFillPattern() ?: self.rawLayer->getDefaultFillPattern(); + auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index c7509e287..93e310603 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -10,6 +10,27 @@ #include +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLLineCap, { + { MGLLineCapButt, "butt" }, + { MGLLineCapRound, "round" }, + { MGLLineCapSquare, "square" }, + }); + + MBGL_DEFINE_ENUM(MGLLineJoin, { + { MGLLineJoinBevel, "bevel" }, + { MGLLineJoinRound, "round" }, + { MGLLineJoinMiter, "miter" }, + }); + + MBGL_DEFINE_ENUM(MGLLineTranslateAnchor, { + { MGLLineTranslateAnchorMap, "map" }, + { MGLLineTranslateAnchorViewport, "viewport" }, + }); + +} + @interface MGLLineStyleLayer () @property (nonatomic) mbgl::style::LineLayer *rawLayer; @@ -26,34 +47,30 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -75,48 +92,54 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineCap); - self.rawLayer->setLineCap(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineCap); + _rawLayer->setLineCap(mbglValue); } - (MGLStyleValue *)lineCap { - auto propertyValue = self.rawLayer->getLineCap() ?: self.rawLayer->getDefaultLineCap(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getLineCap() ?: _rawLayer->getDefaultLineCap(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineJoin:(MGLStyleValue *)lineJoin { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineJoin); - self.rawLayer->setLineJoin(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); + _rawLayer->setLineJoin(mbglValue); } - (MGLStyleValue *)lineJoin { - auto propertyValue = self.rawLayer->getLineJoin() ?: self.rawLayer->getDefaultLineJoin(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getLineJoin() ?: _rawLayer->getDefaultLineJoin(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineMiterLimit:(MGLStyleValue *)lineMiterLimit { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineMiterLimit); - self.rawLayer->setLineMiterLimit(mbglValue); + _rawLayer->setLineMiterLimit(mbglValue); } - (MGLStyleValue *)lineMiterLimit { - auto propertyValue = self.rawLayer->getLineMiterLimit() ?: self.rawLayer->getDefaultLineMiterLimit(); + auto propertyValue = _rawLayer->getLineMiterLimit() ?: _rawLayer->getDefaultLineMiterLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineRoundLimit:(MGLStyleValue *)lineRoundLimit { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineRoundLimit); - self.rawLayer->setLineRoundLimit(mbglValue); + _rawLayer->setLineRoundLimit(mbglValue); } - (MGLStyleValue *)lineRoundLimit { - auto propertyValue = self.rawLayer->getLineRoundLimit() ?: self.rawLayer->getDefaultLineRoundLimit(); + auto propertyValue = _rawLayer->getLineRoundLimit() ?: _rawLayer->getDefaultLineRoundLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -124,101 +147,104 @@ - (void)setLineOpacity:(MGLStyleValue *)lineOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOpacity); - self.rawLayer->setLineOpacity(mbglValue); + _rawLayer->setLineOpacity(mbglValue); } - (MGLStyleValue *)lineOpacity { - auto propertyValue = self.rawLayer->getLineOpacity() ?: self.rawLayer->getDefaultLineOpacity(); + auto propertyValue = _rawLayer->getLineOpacity() ?: _rawLayer->getDefaultLineOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineColor:(MGLStyleValue *)lineColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineColor); - self.rawLayer->setLineColor(mbglValue); + _rawLayer->setLineColor(mbglValue); } - (MGLStyleValue *)lineColor { - auto propertyValue = self.rawLayer->getLineColor() ?: self.rawLayer->getDefaultLineColor(); + auto propertyValue = _rawLayer->getLineColor() ?: _rawLayer->getDefaultLineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineTranslate:(MGLStyleValue *)lineTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(lineTranslate); - self.rawLayer->setLineTranslate(mbglValue); + _rawLayer->setLineTranslate(mbglValue); } - (MGLStyleValue *)lineTranslate { - auto propertyValue = self.rawLayer->getLineTranslate() ?: self.rawLayer->getDefaultLineTranslate(); + auto propertyValue = _rawLayer->getLineTranslate() ?: _rawLayer->getDefaultLineTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setLineTranslateAnchor:(MGLStyleValue *)lineTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineTranslateAnchor); - self.rawLayer->setLineTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineTranslateAnchor); + _rawLayer->setLineTranslateAnchor(mbglValue); } - (MGLStyleValue *)lineTranslateAnchor { - auto propertyValue = self.rawLayer->getLineTranslateAnchor() ?: self.rawLayer->getDefaultLineTranslateAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getLineTranslateAnchor() ?: _rawLayer->getDefaultLineTranslateAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineWidth:(MGLStyleValue *)lineWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineWidth); - self.rawLayer->setLineWidth(mbglValue); + _rawLayer->setLineWidth(mbglValue); } - (MGLStyleValue *)lineWidth { - auto propertyValue = self.rawLayer->getLineWidth() ?: self.rawLayer->getDefaultLineWidth(); + auto propertyValue = _rawLayer->getLineWidth() ?: _rawLayer->getDefaultLineWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineGapWidth:(MGLStyleValue *)lineGapWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineGapWidth); - self.rawLayer->setLineGapWidth(mbglValue); + _rawLayer->setLineGapWidth(mbglValue); } - (MGLStyleValue *)lineGapWidth { - auto propertyValue = self.rawLayer->getLineGapWidth() ?: self.rawLayer->getDefaultLineGapWidth(); + auto propertyValue = _rawLayer->getLineGapWidth() ?: _rawLayer->getDefaultLineGapWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineOffset:(MGLStyleValue *)lineOffset { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOffset); - self.rawLayer->setLineOffset(mbglValue); + _rawLayer->setLineOffset(mbglValue); } - (MGLStyleValue *)lineOffset { - auto propertyValue = self.rawLayer->getLineOffset() ?: self.rawLayer->getDefaultLineOffset(); + auto propertyValue = _rawLayer->getLineOffset() ?: _rawLayer->getDefaultLineOffset(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineBlur:(MGLStyleValue *)lineBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineBlur); - self.rawLayer->setLineBlur(mbglValue); + _rawLayer->setLineBlur(mbglValue); } - (MGLStyleValue *)lineBlur { - auto propertyValue = self.rawLayer->getLineBlur() ?: self.rawLayer->getDefaultLineBlur(); + auto propertyValue = _rawLayer->getLineBlur() ?: _rawLayer->getDefaultLineBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineDasharray:(MGLStyleValue *> *)lineDasharray { auto mbglValue = MGLStyleValueTransformer, NSArray *, float>().toPropertyValue(lineDasharray); - self.rawLayer->setLineDasharray(mbglValue); + _rawLayer->setLineDasharray(mbglValue); } - (MGLStyleValue *> *)lineDasharray { - auto propertyValue = self.rawLayer->getLineDasharray() ?: self.rawLayer->getDefaultLineDasharray(); + auto propertyValue = _rawLayer->getLineDasharray() ?: _rawLayer->getDefaultLineDasharray(); return MGLStyleValueTransformer, NSArray *, float>().toStyleValue(propertyValue); } - (void)setLinePattern:(MGLStyleValue *)linePattern { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(linePattern); - self.rawLayer->setLinePattern(mbglValue); + _rawLayer->setLinePattern(mbglValue); } - (MGLStyleValue *)linePattern { - auto propertyValue = self.rawLayer->getLinePattern() ?: self.rawLayer->getDefaultLinePattern(); + auto propertyValue = _rawLayer->getLinePattern() ?: _rawLayer->getDefaultLinePattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 063f5e338..c6283d89e 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -10,6 +10,7 @@ #include + @interface MGLRasterStyleLayer () @property (nonatomic) mbgl::style::RasterLayer *rawLayer; @@ -26,13 +27,10 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -54,78 +52,78 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterOpacity); - self.rawLayer->setRasterOpacity(mbglValue); + _rawLayer->setRasterOpacity(mbglValue); } - (MGLStyleValue *)rasterOpacity { - auto propertyValue = self.rawLayer->getRasterOpacity() ?: self.rawLayer->getDefaultRasterOpacity(); + auto propertyValue = _rawLayer->getRasterOpacity() ?: _rawLayer->getDefaultRasterOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterHueRotate:(MGLStyleValue *)rasterHueRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterHueRotate); - self.rawLayer->setRasterHueRotate(mbglValue); + _rawLayer->setRasterHueRotate(mbglValue); } - (MGLStyleValue *)rasterHueRotate { - auto propertyValue = self.rawLayer->getRasterHueRotate() ?: self.rawLayer->getDefaultRasterHueRotate(); + auto propertyValue = _rawLayer->getRasterHueRotate() ?: _rawLayer->getDefaultRasterHueRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterBrightnessMin:(MGLStyleValue *)rasterBrightnessMin { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMin); - self.rawLayer->setRasterBrightnessMin(mbglValue); + _rawLayer->setRasterBrightnessMin(mbglValue); } - (MGLStyleValue *)rasterBrightnessMin { - auto propertyValue = self.rawLayer->getRasterBrightnessMin() ?: self.rawLayer->getDefaultRasterBrightnessMin(); + auto propertyValue = _rawLayer->getRasterBrightnessMin() ?: _rawLayer->getDefaultRasterBrightnessMin(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterBrightnessMax:(MGLStyleValue *)rasterBrightnessMax { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMax); - self.rawLayer->setRasterBrightnessMax(mbglValue); + _rawLayer->setRasterBrightnessMax(mbglValue); } - (MGLStyleValue *)rasterBrightnessMax { - auto propertyValue = self.rawLayer->getRasterBrightnessMax() ?: self.rawLayer->getDefaultRasterBrightnessMax(); + auto propertyValue = _rawLayer->getRasterBrightnessMax() ?: _rawLayer->getDefaultRasterBrightnessMax(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterSaturation:(MGLStyleValue *)rasterSaturation { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterSaturation); - self.rawLayer->setRasterSaturation(mbglValue); + _rawLayer->setRasterSaturation(mbglValue); } - (MGLStyleValue *)rasterSaturation { - auto propertyValue = self.rawLayer->getRasterSaturation() ?: self.rawLayer->getDefaultRasterSaturation(); + auto propertyValue = _rawLayer->getRasterSaturation() ?: _rawLayer->getDefaultRasterSaturation(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterContrast:(MGLStyleValue *)rasterContrast { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterContrast); - self.rawLayer->setRasterContrast(mbglValue); + _rawLayer->setRasterContrast(mbglValue); } - (MGLStyleValue *)rasterContrast { - auto propertyValue = self.rawLayer->getRasterContrast() ?: self.rawLayer->getDefaultRasterContrast(); + auto propertyValue = _rawLayer->getRasterContrast() ?: _rawLayer->getDefaultRasterContrast(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterFadeDuration:(MGLStyleValue *)rasterFadeDuration { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterFadeDuration); - self.rawLayer->setRasterFadeDuration(mbglValue); + _rawLayer->setRasterFadeDuration(mbglValue); } - (MGLStyleValue *)rasterFadeDuration { - auto propertyValue = self.rawLayer->getRasterFadeDuration() ?: self.rawLayer->getDefaultRasterFadeDuration(); + auto propertyValue = _rawLayer->getRasterFadeDuration() ?: _rawLayer->getDefaultRasterFadeDuration(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index d366a1955..894375e76 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -2,6 +2,7 @@ const type = locals.type; const layoutProperties = locals.layoutProperties; const paintProperties = locals.paintProperties; + const containsEnumerationProperties = locals.containsEnumerationProperties; -%> // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. @@ -15,6 +16,36 @@ #include _layer.hpp> +<% if (containsEnumerationProperties) { -%> +namespace mbgl { + +<% if (layoutProperties.length) { -%> +<% for (const property of layoutProperties) { -%> +<% if (property.type == "enum") { -%> + MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, { +<% for (const value in property.values) { -%> + { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, +<% } -%> + }); + +<% } -%> +<% } -%> +<% } -%> +<% if (paintProperties.length) { -%> +<% for (const property of paintProperties) { -%> +<% if (property.type == "enum") { -%> + MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, { +<% for (const value in property.values) { -%> + { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, +<% } -%> + }); + +<% } -%> +<% } -%> +<% } -%> +} +<% } -%> + @interface MGL<%- camelize(type) %>StyleLayer () @property (nonatomic) mbgl::style::<%- camelize(type) %>Layer *rawLayer; @@ -32,7 +63,7 @@ if (self = [super initWithIdentifier:identifier]) { auto layer = std::make_uniqueLayer>(identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } @@ -43,37 +74,33 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_uniqueLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - <% } -%> - <% if (type !== 'background' && type !== 'raster') { -%> - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - <% } -%> - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -95,7 +122,7 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_castLayer> &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } <% if (layoutProperties.length) { -%> @@ -103,13 +130,25 @@ <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { +<% if (property.type == "enum") { -%> + auto mbglValue = MGLStyleValueTransformer, + NSValue *, + mbgl::style::<%- mbglType(property) %>, + MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); + _rawLayer->set<%- camelize(property.name) %>(mbglValue); +<% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - self.rawLayer->set<%- camelize(property.name) %>(mbglValue); + _rawLayer->set<%- camelize(property.name) %>(mbglValue); +<% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = self.rawLayer->get<%- camelize(property.name) %>() ?: self.rawLayer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); +<% if (property.type == "enum") { -%> + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); +<% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); +<% } -%> } <% } -%> @@ -119,13 +158,25 @@ <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { +<% if (property.type == "enum") { -%> + auto mbglValue = MGLStyleValueTransformer, + NSValue *, + mbgl::style::<%- mbglType(property) %>, + MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); + _rawLayer->set<%- camelize(property.name) %>(mbglValue); +<% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - self.rawLayer->set<%- camelize(property.name) %>(mbglValue); + _rawLayer->set<%- camelize(property.name) %>(mbglValue); +<% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = self.rawLayer->get<%- camelize(property.name) %>() ?: self.rawLayer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); +<% if (property.type == "enum") { -%> + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); +<% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); +<% } -%> } <% } -%> diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index fdad07aaf..492ce20f1 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -4,6 +4,8 @@ #import "NSValue+MGLStyleAttributeAdditions.h" #import "MGLTypes.h" +#import "MGLLineStyleLayer.h" +#import #if TARGET_OS_IPHONE #import "UIColor+MGLAdditions.h" @@ -13,7 +15,7 @@ #include -template +template class MGLStyleValueTransformer { public: @@ -26,7 +28,26 @@ public: return nil; } } - + + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + MGLStyleValue *toEnumStyleValue(const mbgl::style::PropertyValue &mbglValue) { + if (mbglValue.isConstant()) { + return toEnumStyleConstantValue<>(mbglValue.asConstant()); + } else if (mbglValue.isFunction()) { + const auto &mbglStops = mbglValue.asFunction().getStops(); + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()]; + for (const auto &mbglStop : mbglStops) { + stops[@(mbglStop.first)] = toEnumStyleConstantValue<>(mbglStop.second); + } + return [MGLStyleFunction functionWithBase:mbglValue.asFunction().getBase() stops:stops]; + } else { + return nil; + } + } + mbgl::style::PropertyValue toPropertyValue(MGLStyleValue *value) { if ([value isKindOfClass:[MGLStyleConstantValue class]]) { MBGLType mbglValue; @@ -52,9 +73,39 @@ public: return {}; } } - + + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + mbgl::style::PropertyValue toEnumPropertyValue(MGLStyleValue *value) { + if ([value isKindOfClass:[MGLStyleConstantValue class]]) { + MBGLEnum mbglValue; + getMBGLValue([(MGLStyleConstantValue *)value rawValue], mbglValue); + return mbglValue; + } else if ([value isKindOfClass:[MGLStyleFunction class]]) { + MGLStyleFunction *function = (MGLStyleFunction *)value; + __block std::vector> mbglStops; + [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { + NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); + auto mbglStopValue = toEnumPropertyValue(stopValue); + NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); + mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); + }]; + return mbgl::style::Function({{mbglStops}}, function.base); + } else if (value) { + [NSException raise:@"MGLAbstractClassException" format: + @"The style value %@ cannot be applied to the style. " + @"Make sure the style value was created as a member of a concrete subclass of MGLStyleValue.", + NSStringFromClass([value class])]; + return {}; + } else { + return {}; + } + } + private: - + MGLStyleConstantValue *toStyleConstantValue(const MBGLType mbglValue) { auto rawValue = toMGLRawStyleValue(mbglValue); return [MGLStyleConstantValue valueWithRawValue:rawValue]; @@ -69,7 +120,17 @@ private: } return [MGLStyleFunction functionWithBase:mbglFunction.getBase() stops:stops]; } - + + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + MGLStyleConstantValue *toEnumStyleConstantValue(const MBGLEnum mbglValue) { + auto str = mbgl::Enum::toString(mbglValue); + MGLEnum mglType = *mbgl::Enum::toEnum(str); + return [MGLStyleConstantValue valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(MGLEnum)]]; + } + NSNumber *toMGLRawStyleValue(const bool mbglStopValue) { return @(mbglStopValue); } @@ -92,13 +153,6 @@ private: return [NSValue mgl_valueWithPaddingArray:mbglStopValue]; } - // Enumerations - template ::value>::type> - ObjCType toMGLRawStyleValue(const MBGLType &mbglStopValue) { - NSUInteger rawValue = static_cast(mbglStopValue); - return [NSValue value:&rawValue withObjCType:@encode(NSUInteger)]; - } - MGLColor *toMGLRawStyleValue(const mbgl::Color mbglStopValue) { return [MGLColor mgl_colorWithColor:mbglStopValue]; } @@ -110,9 +164,9 @@ private: } return array; } - + private: - + void getMBGLValue(NSNumber *rawValue, bool &mbglValue) { mbglValue = !!rawValue.boolValue; } @@ -135,12 +189,6 @@ private: mbglValue = rawValue.mgl_paddingArrayValue; } - // Enumerations - template ::value>::type> - void getMBGLValue(ObjCType rawValue, MBGLType &mbglValue) { - [rawValue getValue:&mbglValue]; - } - void getMBGLValue(MGLColor *rawValue, mbgl::Color &mbglValue) { mbglValue = rawValue.mgl_color; } @@ -153,4 +201,16 @@ private: mbglValue.push_back(mbglElement); } } + + // Enumerations + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + void getMBGLValue(ObjCType rawValue, MBGLEnum &mbglValue) { + MGLEnum mglEnum; + [rawValue getValue:&mglEnum]; + auto str = mbgl::Enum::toString(mglEnum); + mbglValue = *mbgl::Enum::toEnum(str); + } }; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 082743be5..636849e87 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -10,6 +10,74 @@ #include +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLSymbolPlacement, { + { MGLSymbolPlacementPoint, "point" }, + { MGLSymbolPlacementLine, "line" }, + }); + + MBGL_DEFINE_ENUM(MGLIconRotationAlignment, { + { MGLIconRotationAlignmentMap, "map" }, + { MGLIconRotationAlignmentViewport, "viewport" }, + { MGLIconRotationAlignmentAuto, "auto" }, + }); + + MBGL_DEFINE_ENUM(MGLIconTextFit, { + { MGLIconTextFitNone, "none" }, + { MGLIconTextFitWidth, "width" }, + { MGLIconTextFitHeight, "height" }, + { MGLIconTextFitBoth, "both" }, + }); + + MBGL_DEFINE_ENUM(MGLTextPitchAlignment, { + { MGLTextPitchAlignmentMap, "map" }, + { MGLTextPitchAlignmentViewport, "viewport" }, + { MGLTextPitchAlignmentAuto, "auto" }, + }); + + MBGL_DEFINE_ENUM(MGLTextRotationAlignment, { + { MGLTextRotationAlignmentMap, "map" }, + { MGLTextRotationAlignmentViewport, "viewport" }, + { MGLTextRotationAlignmentAuto, "auto" }, + }); + + MBGL_DEFINE_ENUM(MGLTextJustify, { + { MGLTextJustifyLeft, "left" }, + { MGLTextJustifyCenter, "center" }, + { MGLTextJustifyRight, "right" }, + }); + + MBGL_DEFINE_ENUM(MGLTextAnchor, { + { MGLTextAnchorCenter, "center" }, + { MGLTextAnchorLeft, "left" }, + { MGLTextAnchorRight, "right" }, + { MGLTextAnchorTop, "top" }, + { MGLTextAnchorBottom, "bottom" }, + { MGLTextAnchorTopLeft, "top-left" }, + { MGLTextAnchorTopRight, "top-right" }, + { MGLTextAnchorBottomLeft, "bottom-left" }, + { MGLTextAnchorBottomRight, "bottom-right" }, + }); + + MBGL_DEFINE_ENUM(MGLTextTransform, { + { MGLTextTransformNone, "none" }, + { MGLTextTransformUppercase, "uppercase" }, + { MGLTextTransformLowercase, "lowercase" }, + }); + + MBGL_DEFINE_ENUM(MGLIconTranslateAnchor, { + { MGLIconTranslateAnchorMap, "map" }, + { MGLIconTranslateAnchorViewport, "viewport" }, + }); + + MBGL_DEFINE_ENUM(MGLTextTranslateAnchor, { + { MGLTextTranslateAnchorMap, "map" }, + { MGLTextTranslateAnchorViewport, "viewport" }, + }); + +} + @interface MGLSymbolStyleLayer () @property (nonatomic) mbgl::style::SymbolLayer *rawLayer; @@ -26,34 +94,30 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -75,348 +139,372 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolPlacement); - self.rawLayer->setSymbolPlacement(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); + _rawLayer->setSymbolPlacement(mbglValue); } - (MGLStyleValue *)symbolPlacement { - auto propertyValue = self.rawLayer->getSymbolPlacement() ?: self.rawLayer->getDefaultSymbolPlacement(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolSpacing); - self.rawLayer->setSymbolSpacing(mbglValue); + _rawLayer->setSymbolSpacing(mbglValue); } - (MGLStyleValue *)symbolSpacing { - auto propertyValue = self.rawLayer->getSymbolSpacing() ?: self.rawLayer->getDefaultSymbolSpacing(); + auto propertyValue = _rawLayer->getSymbolSpacing() ?: _rawLayer->getDefaultSymbolSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setSymbolAvoidEdges:(MGLStyleValue *)symbolAvoidEdges { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolAvoidEdges); - self.rawLayer->setSymbolAvoidEdges(mbglValue); + _rawLayer->setSymbolAvoidEdges(mbglValue); } - (MGLStyleValue *)symbolAvoidEdges { - auto propertyValue = self.rawLayer->getSymbolAvoidEdges() ?: self.rawLayer->getDefaultSymbolAvoidEdges(); + auto propertyValue = _rawLayer->getSymbolAvoidEdges() ?: _rawLayer->getDefaultSymbolAvoidEdges(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconAllowOverlap:(MGLStyleValue *)iconAllowOverlap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconAllowOverlap); - self.rawLayer->setIconAllowOverlap(mbglValue); + _rawLayer->setIconAllowOverlap(mbglValue); } - (MGLStyleValue *)iconAllowOverlap { - auto propertyValue = self.rawLayer->getIconAllowOverlap() ?: self.rawLayer->getDefaultIconAllowOverlap(); + auto propertyValue = _rawLayer->getIconAllowOverlap() ?: _rawLayer->getDefaultIconAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconIgnorePlacement:(MGLStyleValue *)iconIgnorePlacement { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconIgnorePlacement); - self.rawLayer->setIconIgnorePlacement(mbglValue); + _rawLayer->setIconIgnorePlacement(mbglValue); } - (MGLStyleValue *)iconIgnorePlacement { - auto propertyValue = self.rawLayer->getIconIgnorePlacement() ?: self.rawLayer->getDefaultIconIgnorePlacement(); + auto propertyValue = _rawLayer->getIconIgnorePlacement() ?: _rawLayer->getDefaultIconIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOptional:(MGLStyleValue *)iconOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOptional); - self.rawLayer->setIconOptional(mbglValue); + _rawLayer->setIconOptional(mbglValue); } - (MGLStyleValue *)iconOptional { - auto propertyValue = self.rawLayer->getIconOptional() ?: self.rawLayer->getDefaultIconOptional(); + auto propertyValue = _rawLayer->getIconOptional() ?: _rawLayer->getDefaultIconOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotationAlignment); - self.rawLayer->setIconRotationAlignment(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); + _rawLayer->setIconRotationAlignment(mbglValue); } - (MGLStyleValue *)iconRotationAlignment { - auto propertyValue = self.rawLayer->getIconRotationAlignment() ?: self.rawLayer->getDefaultIconRotationAlignment(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getIconRotationAlignment() ?: _rawLayer->getDefaultIconRotationAlignment(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconSize:(MGLStyleValue *)iconSize { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconSize); - self.rawLayer->setIconSize(mbglValue); + _rawLayer->setIconSize(mbglValue); } - (MGLStyleValue *)iconSize { - auto propertyValue = self.rawLayer->getIconSize() ?: self.rawLayer->getDefaultIconSize(); + auto propertyValue = _rawLayer->getIconSize() ?: _rawLayer->getDefaultIconSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTextFit:(MGLStyleValue *)iconTextFit { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconTextFit); - self.rawLayer->setIconTextFit(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTextFit); + _rawLayer->setIconTextFit(mbglValue); } - (MGLStyleValue *)iconTextFit { - auto propertyValue = self.rawLayer->getIconTextFit() ?: self.rawLayer->getDefaultIconTextFit(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getIconTextFit() ?: _rawLayer->getDefaultIconTextFit(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconTextFitPadding:(MGLStyleValue *)iconTextFitPadding { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTextFitPadding); - self.rawLayer->setIconTextFitPadding(mbglValue); + _rawLayer->setIconTextFitPadding(mbglValue); } - (MGLStyleValue *)iconTextFitPadding { - auto propertyValue = self.rawLayer->getIconTextFitPadding() ?: self.rawLayer->getDefaultIconTextFitPadding(); + auto propertyValue = _rawLayer->getIconTextFitPadding() ?: _rawLayer->getDefaultIconTextFitPadding(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconImage:(MGLStyleValue *)iconImage { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconImage); - self.rawLayer->setIconImage(mbglValue); + _rawLayer->setIconImage(mbglValue); } - (MGLStyleValue *)iconImage { - auto propertyValue = self.rawLayer->getIconImage() ?: self.rawLayer->getDefaultIconImage(); + auto propertyValue = _rawLayer->getIconImage() ?: _rawLayer->getDefaultIconImage(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotate:(MGLStyleValue *)iconRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotate); - self.rawLayer->setIconRotate(mbglValue); + _rawLayer->setIconRotate(mbglValue); } - (MGLStyleValue *)iconRotate { - auto propertyValue = self.rawLayer->getIconRotate() ?: self.rawLayer->getDefaultIconRotate(); + auto propertyValue = _rawLayer->getIconRotate() ?: _rawLayer->getDefaultIconRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconPadding:(MGLStyleValue *)iconPadding { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconPadding); - self.rawLayer->setIconPadding(mbglValue); + _rawLayer->setIconPadding(mbglValue); } - (MGLStyleValue *)iconPadding { - auto propertyValue = self.rawLayer->getIconPadding() ?: self.rawLayer->getDefaultIconPadding(); + auto propertyValue = _rawLayer->getIconPadding() ?: _rawLayer->getDefaultIconPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconKeepUpright:(MGLStyleValue *)iconKeepUpright { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconKeepUpright); - self.rawLayer->setIconKeepUpright(mbglValue); + _rawLayer->setIconKeepUpright(mbglValue); } - (MGLStyleValue *)iconKeepUpright { - auto propertyValue = self.rawLayer->getIconKeepUpright() ?: self.rawLayer->getDefaultIconKeepUpright(); + auto propertyValue = _rawLayer->getIconKeepUpright() ?: _rawLayer->getDefaultIconKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOffset:(MGLStyleValue *)iconOffset { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconOffset); - self.rawLayer->setIconOffset(mbglValue); + _rawLayer->setIconOffset(mbglValue); } - (MGLStyleValue *)iconOffset { - auto propertyValue = self.rawLayer->getIconOffset() ?: self.rawLayer->getDefaultIconOffset(); + auto propertyValue = _rawLayer->getIconOffset() ?: _rawLayer->getDefaultIconOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPitchAlignment); - self.rawLayer->setTextPitchAlignment(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); + _rawLayer->setTextPitchAlignment(mbglValue); } - (MGLStyleValue *)textPitchAlignment { - auto propertyValue = self.rawLayer->getTextPitchAlignment() ?: self.rawLayer->getDefaultTextPitchAlignment(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotationAlignment); - self.rawLayer->setTextRotationAlignment(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); + _rawLayer->setTextRotationAlignment(mbglValue); } - (MGLStyleValue *)textRotationAlignment { - auto propertyValue = self.rawLayer->getTextRotationAlignment() ?: self.rawLayer->getDefaultTextRotationAlignment(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextField:(MGLStyleValue *)textField { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textField); - self.rawLayer->setTextField(mbglValue); + _rawLayer->setTextField(mbglValue); } - (MGLStyleValue *)textField { - auto propertyValue = self.rawLayer->getTextField() ?: self.rawLayer->getDefaultTextField(); + auto propertyValue = _rawLayer->getTextField() ?: _rawLayer->getDefaultTextField(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextFont:(MGLStyleValue *> *)textFont { auto mbglValue = MGLStyleValueTransformer, NSArray *, std::string>().toPropertyValue(textFont); - self.rawLayer->setTextFont(mbglValue); + _rawLayer->setTextFont(mbglValue); } - (MGLStyleValue *> *)textFont { - auto propertyValue = self.rawLayer->getTextFont() ?: self.rawLayer->getDefaultTextFont(); + auto propertyValue = _rawLayer->getTextFont() ?: _rawLayer->getDefaultTextFont(); return MGLStyleValueTransformer, NSArray *, std::string>().toStyleValue(propertyValue); } - (void)setTextSize:(MGLStyleValue *)textSize { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textSize); - self.rawLayer->setTextSize(mbglValue); + _rawLayer->setTextSize(mbglValue); } - (MGLStyleValue *)textSize { - auto propertyValue = self.rawLayer->getTextSize() ?: self.rawLayer->getDefaultTextSize(); + auto propertyValue = _rawLayer->getTextSize() ?: _rawLayer->getDefaultTextSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextMaxWidth:(MGLStyleValue *)textMaxWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxWidth); - self.rawLayer->setTextMaxWidth(mbglValue); + _rawLayer->setTextMaxWidth(mbglValue); } - (MGLStyleValue *)textMaxWidth { - auto propertyValue = self.rawLayer->getTextMaxWidth() ?: self.rawLayer->getDefaultTextMaxWidth(); + auto propertyValue = _rawLayer->getTextMaxWidth() ?: _rawLayer->getDefaultTextMaxWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLineHeight:(MGLStyleValue *)textLineHeight { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLineHeight); - self.rawLayer->setTextLineHeight(mbglValue); + _rawLayer->setTextLineHeight(mbglValue); } - (MGLStyleValue *)textLineHeight { - auto propertyValue = self.rawLayer->getTextLineHeight() ?: self.rawLayer->getDefaultTextLineHeight(); + auto propertyValue = _rawLayer->getTextLineHeight() ?: _rawLayer->getDefaultTextLineHeight(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLetterSpacing); - self.rawLayer->setTextLetterSpacing(mbglValue); + _rawLayer->setTextLetterSpacing(mbglValue); } - (MGLStyleValue *)textLetterSpacing { - auto propertyValue = self.rawLayer->getTextLetterSpacing() ?: self.rawLayer->getDefaultTextLetterSpacing(); + auto propertyValue = _rawLayer->getTextLetterSpacing() ?: _rawLayer->getDefaultTextLetterSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextJustify:(MGLStyleValue *)textJustify { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textJustify); - self.rawLayer->setTextJustify(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); + _rawLayer->setTextJustify(mbglValue); } - (MGLStyleValue *)textJustify { - auto propertyValue = self.rawLayer->getTextJustify() ?: self.rawLayer->getDefaultTextJustify(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextAnchor:(MGLStyleValue *)textAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAnchor); - self.rawLayer->setTextAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); + _rawLayer->setTextAnchor(mbglValue); } - (MGLStyleValue *)textAnchor { - auto propertyValue = self.rawLayer->getTextAnchor() ?: self.rawLayer->getDefaultTextAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextMaxAngle:(MGLStyleValue *)textMaxAngle { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxAngle); - self.rawLayer->setTextMaxAngle(mbglValue); + _rawLayer->setTextMaxAngle(mbglValue); } - (MGLStyleValue *)textMaxAngle { - auto propertyValue = self.rawLayer->getTextMaxAngle() ?: self.rawLayer->getDefaultTextMaxAngle(); + auto propertyValue = _rawLayer->getTextMaxAngle() ?: _rawLayer->getDefaultTextMaxAngle(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextRotate:(MGLStyleValue *)textRotate { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotate); - self.rawLayer->setTextRotate(mbglValue); + _rawLayer->setTextRotate(mbglValue); } - (MGLStyleValue *)textRotate { - auto propertyValue = self.rawLayer->getTextRotate() ?: self.rawLayer->getDefaultTextRotate(); + auto propertyValue = _rawLayer->getTextRotate() ?: _rawLayer->getDefaultTextRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextPadding:(MGLStyleValue *)textPadding { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPadding); - self.rawLayer->setTextPadding(mbglValue); + _rawLayer->setTextPadding(mbglValue); } - (MGLStyleValue *)textPadding { - auto propertyValue = self.rawLayer->getTextPadding() ?: self.rawLayer->getDefaultTextPadding(); + auto propertyValue = _rawLayer->getTextPadding() ?: _rawLayer->getDefaultTextPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textKeepUpright); - self.rawLayer->setTextKeepUpright(mbglValue); + _rawLayer->setTextKeepUpright(mbglValue); } - (MGLStyleValue *)textKeepUpright { - auto propertyValue = self.rawLayer->getTextKeepUpright() ?: self.rawLayer->getDefaultTextKeepUpright(); + auto propertyValue = _rawLayer->getTextKeepUpright() ?: _rawLayer->getDefaultTextKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTransform:(MGLStyleValue *)textTransform { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textTransform); - self.rawLayer->setTextTransform(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); + _rawLayer->setTextTransform(mbglValue); } - (MGLStyleValue *)textTransform { - auto propertyValue = self.rawLayer->getTextTransform() ?: self.rawLayer->getDefaultTextTransform(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextOffset:(MGLStyleValue *)textOffset { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textOffset); - self.rawLayer->setTextOffset(mbglValue); + _rawLayer->setTextOffset(mbglValue); } - (MGLStyleValue *)textOffset { - auto propertyValue = self.rawLayer->getTextOffset() ?: self.rawLayer->getDefaultTextOffset(); + auto propertyValue = _rawLayer->getTextOffset() ?: _rawLayer->getDefaultTextOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAllowOverlap); - self.rawLayer->setTextAllowOverlap(mbglValue); + _rawLayer->setTextAllowOverlap(mbglValue); } - (MGLStyleValue *)textAllowOverlap { - auto propertyValue = self.rawLayer->getTextAllowOverlap() ?: self.rawLayer->getDefaultTextAllowOverlap(); + auto propertyValue = _rawLayer->getTextAllowOverlap() ?: _rawLayer->getDefaultTextAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textIgnorePlacement); - self.rawLayer->setTextIgnorePlacement(mbglValue); + _rawLayer->setTextIgnorePlacement(mbglValue); } - (MGLStyleValue *)textIgnorePlacement { - auto propertyValue = self.rawLayer->getTextIgnorePlacement() ?: self.rawLayer->getDefaultTextIgnorePlacement(); + auto propertyValue = _rawLayer->getTextIgnorePlacement() ?: _rawLayer->getDefaultTextIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOptional:(MGLStyleValue *)textOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOptional); - self.rawLayer->setTextOptional(mbglValue); + _rawLayer->setTextOptional(mbglValue); } - (MGLStyleValue *)textOptional { - auto propertyValue = self.rawLayer->getTextOptional() ?: self.rawLayer->getDefaultTextOptional(); + auto propertyValue = _rawLayer->getTextOptional() ?: _rawLayer->getDefaultTextOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -424,142 +512,148 @@ - (void)setIconOpacity:(MGLStyleValue *)iconOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOpacity); - self.rawLayer->setIconOpacity(mbglValue); + _rawLayer->setIconOpacity(mbglValue); } - (MGLStyleValue *)iconOpacity { - auto propertyValue = self.rawLayer->getIconOpacity() ?: self.rawLayer->getDefaultIconOpacity(); + auto propertyValue = _rawLayer->getIconOpacity() ?: _rawLayer->getDefaultIconOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconColor:(MGLStyleValue *)iconColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconColor); - self.rawLayer->setIconColor(mbglValue); + _rawLayer->setIconColor(mbglValue); } - (MGLStyleValue *)iconColor { - auto propertyValue = self.rawLayer->getIconColor() ?: self.rawLayer->getDefaultIconColor(); + auto propertyValue = _rawLayer->getIconColor() ?: _rawLayer->getDefaultIconColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloColor:(MGLStyleValue *)iconHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloColor); - self.rawLayer->setIconHaloColor(mbglValue); + _rawLayer->setIconHaloColor(mbglValue); } - (MGLStyleValue *)iconHaloColor { - auto propertyValue = self.rawLayer->getIconHaloColor() ?: self.rawLayer->getDefaultIconHaloColor(); + auto propertyValue = _rawLayer->getIconHaloColor() ?: _rawLayer->getDefaultIconHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloWidth:(MGLStyleValue *)iconHaloWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloWidth); - self.rawLayer->setIconHaloWidth(mbglValue); + _rawLayer->setIconHaloWidth(mbglValue); } - (MGLStyleValue *)iconHaloWidth { - auto propertyValue = self.rawLayer->getIconHaloWidth() ?: self.rawLayer->getDefaultIconHaloWidth(); + auto propertyValue = _rawLayer->getIconHaloWidth() ?: _rawLayer->getDefaultIconHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloBlur:(MGLStyleValue *)iconHaloBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloBlur); - self.rawLayer->setIconHaloBlur(mbglValue); + _rawLayer->setIconHaloBlur(mbglValue); } - (MGLStyleValue *)iconHaloBlur { - auto propertyValue = self.rawLayer->getIconHaloBlur() ?: self.rawLayer->getDefaultIconHaloBlur(); + auto propertyValue = _rawLayer->getIconHaloBlur() ?: _rawLayer->getDefaultIconHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTranslate:(MGLStyleValue *)iconTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTranslate); - self.rawLayer->setIconTranslate(mbglValue); + _rawLayer->setIconTranslate(mbglValue); } - (MGLStyleValue *)iconTranslate { - auto propertyValue = self.rawLayer->getIconTranslate() ?: self.rawLayer->getDefaultIconTranslate(); + auto propertyValue = _rawLayer->getIconTranslate() ?: _rawLayer->getDefaultIconTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconTranslateAnchor:(MGLStyleValue *)iconTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconTranslateAnchor); - self.rawLayer->setIconTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTranslateAnchor); + _rawLayer->setIconTranslateAnchor(mbglValue); } - (MGLStyleValue *)iconTranslateAnchor { - auto propertyValue = self.rawLayer->getIconTranslateAnchor() ?: self.rawLayer->getDefaultIconTranslateAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getIconTranslateAnchor() ?: _rawLayer->getDefaultIconTranslateAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextOpacity:(MGLStyleValue *)textOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOpacity); - self.rawLayer->setTextOpacity(mbglValue); + _rawLayer->setTextOpacity(mbglValue); } - (MGLStyleValue *)textOpacity { - auto propertyValue = self.rawLayer->getTextOpacity() ?: self.rawLayer->getDefaultTextOpacity(); + auto propertyValue = _rawLayer->getTextOpacity() ?: _rawLayer->getDefaultTextOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextColor:(MGLStyleValue *)textColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textColor); - self.rawLayer->setTextColor(mbglValue); + _rawLayer->setTextColor(mbglValue); } - (MGLStyleValue *)textColor { - auto propertyValue = self.rawLayer->getTextColor() ?: self.rawLayer->getDefaultTextColor(); + auto propertyValue = _rawLayer->getTextColor() ?: _rawLayer->getDefaultTextColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloColor:(MGLStyleValue *)textHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloColor); - self.rawLayer->setTextHaloColor(mbglValue); + _rawLayer->setTextHaloColor(mbglValue); } - (MGLStyleValue *)textHaloColor { - auto propertyValue = self.rawLayer->getTextHaloColor() ?: self.rawLayer->getDefaultTextHaloColor(); + auto propertyValue = _rawLayer->getTextHaloColor() ?: _rawLayer->getDefaultTextHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloWidth:(MGLStyleValue *)textHaloWidth { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloWidth); - self.rawLayer->setTextHaloWidth(mbglValue); + _rawLayer->setTextHaloWidth(mbglValue); } - (MGLStyleValue *)textHaloWidth { - auto propertyValue = self.rawLayer->getTextHaloWidth() ?: self.rawLayer->getDefaultTextHaloWidth(); + auto propertyValue = _rawLayer->getTextHaloWidth() ?: _rawLayer->getDefaultTextHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloBlur:(MGLStyleValue *)textHaloBlur { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloBlur); - self.rawLayer->setTextHaloBlur(mbglValue); + _rawLayer->setTextHaloBlur(mbglValue); } - (MGLStyleValue *)textHaloBlur { - auto propertyValue = self.rawLayer->getTextHaloBlur() ?: self.rawLayer->getDefaultTextHaloBlur(); + auto propertyValue = _rawLayer->getTextHaloBlur() ?: _rawLayer->getDefaultTextHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTranslate:(MGLStyleValue *)textTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textTranslate); - self.rawLayer->setTextTranslate(mbglValue); + _rawLayer->setTextTranslate(mbglValue); } - (MGLStyleValue *)textTranslate { - auto propertyValue = self.rawLayer->getTextTranslate() ?: self.rawLayer->getDefaultTextTranslate(); + auto propertyValue = _rawLayer->getTextTranslate() ?: _rawLayer->getDefaultTextTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextTranslateAnchor:(MGLStyleValue *)textTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textTranslateAnchor); - self.rawLayer->setTextTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTranslateAnchor); + _rawLayer->setTextTranslateAnchor(mbglValue); } - (MGLStyleValue *)textTranslateAnchor { - auto propertyValue = self.rawLayer->getTextTranslateAnchor() ?: self.rawLayer->getDefaultTextTranslateAnchor(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getTextTranslateAnchor() ?: _rawLayer->getDefaultTextTranslateAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h new file mode 100644 index 000000000..63ff86941 --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h @@ -0,0 +1,232 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import + +#import "MGLFillStyleLayer.h" +#import "MGLLineStyleLayer.h" +#import "MGLSymbolStyleLayer.h" +#import "MGLCircleStyleLayer.h" +#import "MGLRasterStyleLayer.h" +#import "MGLBackgroundStyleLayer.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + Methods for round-tripping values for Mapbox style layer enumeration values. +*/ +@interface NSValue (MGLStyleEnumAttributeAdditions) + +#pragma mark Working with Style Layer Enumeration Attribute Values + +/** + Creates a new value object containing the given `MGLLineCap` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLLineCap:(MGLLineCap)lineCap; + +/** + The `MGLLineCap` enumeration representation of the value. +*/ +@property (readonly) MGLLineCap lineCap; + +/** + Creates a new value object containing the given `MGLLineJoin` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLLineJoin:(MGLLineJoin)lineJoin; + +/** + The `MGLLineJoin` enumeration representation of the value. +*/ +@property (readonly) MGLLineJoin lineJoin; + +/** + Creates a new value object containing the given `MGLSymbolPlacement` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement; + +/** + The `MGLSymbolPlacement` enumeration representation of the value. +*/ +@property (readonly) MGLSymbolPlacement symbolPlacement; + +/** + Creates a new value object containing the given `MGLIconRotationAlignment` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment; + +/** + The `MGLIconRotationAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLIconRotationAlignment iconRotationAlignment; + +/** + Creates a new value object containing the given `MGLIconTextFit` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit; + +/** + The `MGLIconTextFit` enumeration representation of the value. +*/ +@property (readonly) MGLIconTextFit iconTextFit; + +/** + Creates a new value object containing the given `MGLTextPitchAlignment` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment; + +/** + The `MGLTextPitchAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLTextPitchAlignment textPitchAlignment; + +/** + Creates a new value object containing the given `MGLTextRotationAlignment` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment; + +/** + The `MGLTextRotationAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLTextRotationAlignment textRotationAlignment; + +/** + Creates a new value object containing the given `MGLTextJustify` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextJustify:(MGLTextJustify)textJustify; + +/** + The `MGLTextJustify` enumeration representation of the value. +*/ +@property (readonly) MGLTextJustify textJustify; + +/** + Creates a new value object containing the given `MGLTextAnchor` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor; + +/** + The `MGLTextAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLTextAnchor textAnchor; + +/** + Creates a new value object containing the given `MGLTextTransform` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextTransform:(MGLTextTransform)textTransform; + +/** + The `MGLTextTransform` enumeration representation of the value. +*/ +@property (readonly) MGLTextTransform textTransform; + +/** + Creates a new value object containing the given `MGLFillTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor; + +/** + The `MGLFillTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLFillTranslateAnchor fillTranslateAnchor; + +/** + Creates a new value object containing the given `MGLLineTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor; + +/** + The `MGLLineTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLLineTranslateAnchor lineTranslateAnchor; + +/** + Creates a new value object containing the given `MGLIconTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor; + +/** + The `MGLIconTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLIconTranslateAnchor iconTranslateAnchor; + +/** + Creates a new value object containing the given `MGLTextTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor; + +/** + The `MGLTextTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLTextTranslateAnchor textTranslateAnchor; + +/** + Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; + +/** + The `MGLCircleTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLCircleTranslateAnchor circleTranslateAnchor; + +/** + Creates a new value object containing the given `MGLCirclePitchScale` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale; + +/** + The `MGLCirclePitchScale` enumeration representation of the value. +*/ +@property (readonly) MGLCirclePitchScale circlePitchScale; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs new file mode 100644 index 000000000..6748f7ec9 --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs @@ -0,0 +1,66 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +<% +const types = locals.types; +const layoutProperties = locals.layoutProperties; +const paintProperties = locals.paintProperties; +-%> +#import + +<% if (types) { -%> +<% for (const type of types) { -%> +#import "MGL<%- camelize(type) %>StyleLayer.h" +<% } -%> +<% } -%> + +NS_ASSUME_NONNULL_BEGIN + +/** + Methods for round-tripping values for Mapbox style layer enumeration values. +*/ +@interface NSValue (MGLStyleEnumAttributeAdditions) + +#pragma mark Working with Style Layer Enumeration Attribute Values + +<% if (layoutProperties.length) { -%> +<% for (const property of layoutProperties) { -%> +<% if (property.type == "enum") { -%> +/** + Creates a new value object containing the given `MGL<%- camelize(property.name) %>` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; + +/** + The `MGL<%- camelize(property.name) %>` enumeration representation of the value. +*/ +@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; + +<% } -%> +<% } -%> +<% } -%> +<% if (paintProperties.length) { -%> +<% for (const property of paintProperties) { -%> +<% if (property.type == "enum") { -%> +/** + Creates a new value object containing the given `MGL<%- camelize(property.name) %>` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; + +/** + The `MGL<%- camelize(property.name) %>` enumeration representation of the value. +*/ +@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; + +<% } -%> +<% } -%> +<% } -%> +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm new file mode 100644 index 000000000..dedff5cf3 --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm @@ -0,0 +1,169 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "NSValue+MGLStyleEnumAttributeAdditions.h" + +@implementation NSValue (MGLStyleEnumAttributeAdditions) + ++ (NSValue *)valueWithMGLLineCap:(MGLLineCap)lineCap { + return [NSValue value:&lineCap withObjCType:@encode(MGLLineCap)]; +} + +- (MGLLineCap)lineCap { + MGLLineCap value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLLineJoin:(MGLLineJoin)lineJoin { + return [NSValue value:&lineJoin withObjCType:@encode(MGLLineJoin)]; +} + +- (MGLLineJoin)lineJoin { + MGLLineJoin value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement { + return [NSValue value:&symbolPlacement withObjCType:@encode(MGLSymbolPlacement)]; +} + +- (MGLSymbolPlacement)symbolPlacement { + MGLSymbolPlacement value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment { + return [NSValue value:&iconRotationAlignment withObjCType:@encode(MGLIconRotationAlignment)]; +} + +- (MGLIconRotationAlignment)iconRotationAlignment { + MGLIconRotationAlignment value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit { + return [NSValue value:&iconTextFit withObjCType:@encode(MGLIconTextFit)]; +} + +- (MGLIconTextFit)iconTextFit { + MGLIconTextFit value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment { + return [NSValue value:&textPitchAlignment withObjCType:@encode(MGLTextPitchAlignment)]; +} + +- (MGLTextPitchAlignment)textPitchAlignment { + MGLTextPitchAlignment value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment { + return [NSValue value:&textRotationAlignment withObjCType:@encode(MGLTextRotationAlignment)]; +} + +- (MGLTextRotationAlignment)textRotationAlignment { + MGLTextRotationAlignment value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextJustify:(MGLTextJustify)textJustify { + return [NSValue value:&textJustify withObjCType:@encode(MGLTextJustify)]; +} + +- (MGLTextJustify)textJustify { + MGLTextJustify value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { + return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; +} + +- (MGLTextAnchor)textAnchor { + MGLTextAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextTransform:(MGLTextTransform)textTransform { + return [NSValue value:&textTransform withObjCType:@encode(MGLTextTransform)]; +} + +- (MGLTextTransform)textTransform { + MGLTextTransform value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor { +return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslateAnchor)]; +} + +- (MGLFillTranslateAnchor)fillTranslateAnchor { + MGLFillTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor { +return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslateAnchor)]; +} + +- (MGLLineTranslateAnchor)lineTranslateAnchor { + MGLLineTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor { +return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslateAnchor)]; +} + +- (MGLIconTranslateAnchor)iconTranslateAnchor { + MGLIconTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor { +return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslateAnchor)]; +} + +- (MGLTextTranslateAnchor)textTranslateAnchor { + MGLTextTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { +return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; +} + +- (MGLCircleTranslateAnchor)circleTranslateAnchor { + MGLCircleTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale { +return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; +} + +- (MGLCirclePitchScale)circlePitchScale { + MGLCirclePitchScale value; + [self getValue:&value]; + return value; +} + + +@end diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs new file mode 100644 index 000000000..d445fa0a5 --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs @@ -0,0 +1,46 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. +<% +const type = locals.type; +const layoutProperties = locals.layoutProperties; +const paintProperties = locals.paintProperties; +-%> + +#import "NSValue+MGLStyleEnumAttributeAdditions.h" + +@implementation NSValue (MGLStyleEnumAttributeAdditions) + +<% if (layoutProperties.length) { -%> +<% for (const property of layoutProperties) { -%> +<% if (property.type == "enum") { -%> ++ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; +} + +- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + MGL<%- camelize(property.name) %> value; + [self getValue:&value]; + return value; +} + +<% } -%> +<% } -%> +<% } -%> +<% if (paintProperties.length) { -%> +<% for (const property of paintProperties) { -%> +<% if (property.type == "enum") { -%> ++ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { +return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; +} + +- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + MGL<%- camelize(property.name) %> value; + [self getValue:&value]; + return value; +} + +<% } -%> +<% } -%> +<% } -%> + +@end diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 11247ea3f..91e934ed1 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -71,6 +71,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingVectorSource, MBXSettingsRuntimeStylingRasterSource, MBXSettingsRuntimeStylingCountryLabels, + MBXSettingsRuntimeStylingRouteLine, }; typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @@ -332,6 +333,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Style Vector Source", @"Style Raster Source", [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], + @"Add Route Line", ]]; break; case MBXSettingsMiscellaneous: @@ -490,6 +492,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsRuntimeStylingCountryLabels: [self styleCountryLabelsLanguage]; break; + case MBXSettingsRuntimeStylingRouteLine: + [self styleRouteLine]; + break; default: NSAssert(NO, @"All runtime styling setting rows should be implemented"); break; @@ -816,6 +821,18 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { }); } ++ (MGLStyleConstantValue *)testEnum:(NSUInteger)value type:(const char *)type +{ + return [MGLStyleConstantValue valueWithRawValue:[NSValue value:&value withObjCType:type]]; +} + ++ (MGLStyleFunction *)testEnumFunction:(NSUInteger)value type:(const char *)type +{ + return [MGLStyleFunction valueWithStops:@{ + @18: [self testEnum:value type:type], + }]; +} + - (void)styleFilteredLines { // set style and focus on lower 48 @@ -1081,6 +1098,44 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self styleLabelLanguageForLayersNamed:labelLayers]; } +- (void)styleRouteLine +{ + CLLocationCoordinate2D coords[] = { + { 43.84455590478528, 10.504238605499268 }, + { 43.84385562343126, 10.504125952720642 }, + { 43.84388657526694, 10.503299832344055 }, + { 43.84332557075269, 10.503235459327698 }, + { 43.843441641085036, 10.502264499664307 }, + { 43.84396395478592, 10.50242006778717 }, + { 43.84406067904351, 10.501744151115416 }, + { 43.84422317544319, 10.501792430877686 } + }; + NSInteger count = sizeof(coords) / sizeof(coords[0]); + + [self.mapView setCenterCoordinate:coords[0] zoomLevel:16 animated:YES]; + + MGLPolylineFeature *routeLine = [MGLPolylineFeature polylineWithCoordinates:coords count:count]; + + MGLGeoJSONSource *routeSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"style-route-source" features:@[routeLine] options:nil]; + [self.mapView.style addSource:routeSource]; + + MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; + baseRouteLayer.lineColor = [MGLStyleConstantValue valueWithRawValue:[UIColor orangeColor]]; + baseRouteLayer.lineWidth = [MGLStyleConstantValue valueWithRawValue:@20]; + baseRouteLayer.lineOpacity = [MGLStyleConstantValue valueWithRawValue:@0.5]; + baseRouteLayer.lineCap = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; + baseRouteLayer.lineJoin = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + [self.mapView.style addLayer:baseRouteLayer]; + + MGLLineStyleLayer *routeLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; + routeLayer.lineColor = [MGLStyleConstantValue valueWithRawValue:[UIColor whiteColor]]; + routeLayer.lineWidth = [MGLStyleConstantValue valueWithRawValue:@15]; + routeLayer.lineOpacity = [MGLStyleConstantValue valueWithRawValue:@0.8]; + routeLayer.lineCap = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; + routeLayer.lineJoin = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + [self.mapView.style addLayer:routeLayer]; +} + - (void)styleLabelLanguageForLayersNamed:(NSArray *)layers { _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 9561c741a..2149df9db 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -127,6 +127,10 @@ 4018B1C91CDC288A00F666AF /* MGLAnnotationView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */; }; 4018B1CA1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4032C5BF1DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4032C5C01DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4032C5C11DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; + 4032C5C21DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */; }; 4049C29D1DB6CD6C00B3F799 /* MGLPointCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4049C29B1DB6CD6C00B3F799 /* MGLPointCollection.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4049C29E1DB6CD6C00B3F799 /* MGLPointCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4049C29B1DB6CD6C00B3F799 /* MGLPointCollection.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -560,6 +564,10 @@ 4018B1C41CDC277F00F666AF /* MGLAnnotationView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAnnotationView.mm; sourceTree = ""; }; 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationView.h; sourceTree = ""; }; 402E9DE01CD2C76200FD4519 /* Mapbox.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Mapbox.playground; sourceTree = ""; }; + 4032C5B71DE1EBB90062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NSValue+MGLStyleEnumAttributeAdditions.h.ejs"; sourceTree = ""; }; + 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+MGLStyleEnumAttributeAdditions.h"; sourceTree = ""; }; + 4032C5BC1DE1FAFC0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NSValue+MGLStyleEnumAttributeAdditions.mm.ejs"; sourceTree = ""; }; + 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSValue+MGLStyleEnumAttributeAdditions.mm"; sourceTree = ""; }; 404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView_Private.h; sourceTree = ""; }; 4049C29B1DB6CD6C00B3F799 /* MGLPointCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPointCollection.h; sourceTree = ""; }; 4049C29C1DB6CD6C00B3F799 /* MGLPointCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLPointCollection.mm; sourceTree = ""; }; @@ -879,6 +887,8 @@ 35599DB81D46AD7F0048254D /* Categories */ = { isa = PBXGroup; children = ( + 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */, + 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */, 350098DA1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h */, 350098DB1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm */, ); @@ -1206,6 +1216,8 @@ DA8F25B91D51D2570010E6B5 /* MGLRuntimeStylingTests.m.ejs */, DA8F25BA1D51D2570010E6B5 /* MGLStyleLayer.h.ejs */, DA8F25BB1D51D2570010E6B5 /* MGLStyleLayer.mm.ejs */, + 4032C5B71DE1EBB90062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h.ejs */, + 4032C5BC1DE1FAFC0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm.ejs */, ); name = "Foundation Templates"; path = ../../darwin/src; @@ -1462,6 +1474,7 @@ DA88488B1CBB037E00AB86E3 /* SMCalloutView.h in Headers */, DA8847FE1CBAFA5100AB86E3 /* MGLTypes.h in Headers */, DA8847F11CBAFA5100AB86E3 /* MGLGeometry.h in Headers */, + 4032C5BF1DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */, DA8848221CBAFA6200AB86E3 /* MGLOfflineRegion_Private.h in Headers */, 35136D4C1D4277FC00C20EFD /* MGLSource.h in Headers */, 3566C76C1D4A8DFA008152BC /* MGLRasterSource.h in Headers */, @@ -1502,6 +1515,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 4032C5C01DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */, 35B82BF91D6C5F8400B1B721 /* NSPredicate+MGLAdditions.h in Headers */, DA35A2CA1CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */, 350098BC1D480108004B2AF0 /* MGLVectorSource.h in Headers */, @@ -1962,6 +1976,7 @@ DA8848301CBAFA6200AB86E3 /* NSProcessInfo+MGLAdditions.m in Sources */, 353AFA161D65AB17005A69F4 /* NSDate+MGLAdditions.mm in Sources */, 35D13AC51D3D19DD00AFB4E0 /* MGLFillStyleLayer.mm in Sources */, + 4032C5C11DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */, DA8848241CBAFA6200AB86E3 /* MGLOfflineStorage.mm in Sources */, DA88482A1CBAFA6200AB86E3 /* MGLTilePyramidOfflineRegion.mm in Sources */, 4049C29F1DB6CD6C00B3F799 /* MGLPointCollection.mm in Sources */, @@ -2034,6 +2049,7 @@ DAA4E4231CBB730400178DFB /* MGLPolygon.mm in Sources */, 353AFA171D65AB17005A69F4 /* NSDate+MGLAdditions.mm in Sources */, 35D13AC61D3D19DD00AFB4E0 /* MGLFillStyleLayer.mm in Sources */, + 4032C5C21DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */, DAA4E42A1CBB730400178DFB /* NSProcessInfo+MGLAdditions.m in Sources */, DAA4E4211CBB730400178DFB /* MGLOfflineStorage.mm in Sources */, 4049C2A01DB6CD6C00B3F799 /* MGLPointCollection.mm in Sources */, diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index c2fda1be1..766469531 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -51,5 +51,6 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLUserLocation.h" #import "MGLUserLocationAnnotationView.h" #import "NSValue+MGLAdditions.h" +#import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h" #import "MGLTileSet.h" diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 194d543f8..3ab9d4d9c 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -40,6 +40,8 @@ 35C5D84A1D6DD66D00E95907 /* NSCompoundPredicate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35C5D8461D6DD66D00E95907 /* NSCompoundPredicate+MGLAdditions.mm */; }; 35D65C5A1D65AD5500722C23 /* NSDate+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35D65C581D65AD5500722C23 /* NSDate+MGLAdditions.h */; }; 35D65C5B1D65AD5500722C23 /* NSDate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35D65C591D65AD5500722C23 /* NSDate+MGLAdditions.mm */; }; + 4032C5C51DE1FE930062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B91DE1EEBA0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4032C5C61DE1FE9B0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5C31DE1FE810062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; 4049C2A51DB6CE7F00B3F799 /* MGLPointCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4049C2A11DB6CE7800B3F799 /* MGLPointCollection.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4049C2AD1DB8020600B3F799 /* MGLPointCollection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4049C2A71DB6D09B00B3F799 /* MGLPointCollection.mm */; }; 408AA85B1DAEECFE00022900 /* MGLShape_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 408AA85A1DAEECF100022900 /* MGLShape_Private.h */; }; @@ -265,6 +267,10 @@ 35C5D84B1D6DD75B00E95907 /* MGLFilterTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFilterTests.mm; sourceTree = ""; }; 35D65C581D65AD5500722C23 /* NSDate+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+MGLAdditions.h"; sourceTree = ""; }; 35D65C591D65AD5500722C23 /* NSDate+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSDate+MGLAdditions.mm"; sourceTree = ""; }; + 4032C5B91DE1EEBA0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+MGLStyleEnumAttributeAdditions.h"; sourceTree = ""; }; + 4032C5BA1DE1EECB0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h.ejs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSValue+MGLStyleEnumAttributeAdditions.h.ejs"; sourceTree = ""; }; + 4032C5C31DE1FE810062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSValue+MGLStyleEnumAttributeAdditions.mm"; sourceTree = ""; }; + 4032C5C71DE1FEAB0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm.ejs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSValue+MGLStyleEnumAttributeAdditions.mm.ejs"; sourceTree = ""; }; 4049C2A11DB6CE7800B3F799 /* MGLPointCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPointCollection.h; sourceTree = ""; }; 4049C2A71DB6D09B00B3F799 /* MGLPointCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLPointCollection.mm; sourceTree = ""; }; 405C03961DB0004E001AC280 /* NSImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+MGLAdditions.h"; sourceTree = ""; }; @@ -505,6 +511,8 @@ 352742791D4C235C00A1ECE6 /* Categories */ = { isa = PBXGroup; children = ( + 4032C5B91DE1EEBA0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */, + 4032C5C31DE1FE810062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */, DA8F25A61D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.h */, DA8F25A71D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.mm */, ); @@ -666,6 +674,8 @@ DA8F25B81D51D2280010E6B5 /* Foundation Templates */ = { isa = PBXGroup; children = ( + 4032C5BA1DE1EECB0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h.ejs */, + 4032C5C71DE1FEAB0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm.ejs */, DA8F25B51D51D2240010E6B5 /* MGLRuntimeStylingTests.m.ejs */, DA8F25B61D51D2240010E6B5 /* MGLStyleLayer.h.ejs */, DA8F25B71D51D2240010E6B5 /* MGLStyleLayer.mm.ejs */, @@ -915,6 +925,7 @@ 352742781D4C220900A1ECE6 /* MGLStyleValue.h in Headers */, DAE6C35E1CC31E0400DB3429 /* MGLMultiPoint.h in Headers */, 35602BFF1D3EA9B40050646F /* MGLStyleLayer_Private.h in Headers */, + 4032C5C51DE1FE930062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */, DAE6C3971CC31E2A00DB3429 /* NSBundle+MGLAdditions.h in Headers */, DAED385F1D62CED700D7640F /* NSURL+MGLAdditions.h in Headers */, DAD165741CF4CD7A001FF4B9 /* MGLShapeCollection.h in Headers */, @@ -1176,6 +1187,7 @@ DAE6C3931CC31E2A00DB3429 /* MGLShape.mm in Sources */, 352742861D4C244700A1ECE6 /* MGLRasterSource.mm in Sources */, DAE6C39D1CC31E2A00DB3429 /* NSString+MGLAdditions.m in Sources */, + 4032C5C61DE1FE9B0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */, DAE6C3941CC31E2A00DB3429 /* MGLStyle.mm in Sources */, DAE6C3871CC31E2A00DB3429 /* MGLGeometry.mm in Sources */, 3527428E1D4C24AB00A1ECE6 /* MGLCircleStyleLayer.mm in Sources */, diff --git a/platform/macos/src/Mapbox.h b/platform/macos/src/Mapbox.h index cfddfe6e8..73b8624be 100644 --- a/platform/macos/src/Mapbox.h +++ b/platform/macos/src/Mapbox.h @@ -46,4 +46,5 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" #import "NSValue+MGLAdditions.h" +#import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h" From d6d16c189a3ab9ec531c1b51f6c318312f7f3c1a Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 22 Nov 2016 11:30:15 -0800 Subject: [PATCH 37/67] [ios, macos] Remove unused `MGLGeometryAdditions` category stub This fixes an issue where the documentation for all NSValue categories were described as `MGLGeometryAdditions`. --- .../darwin/src/MGLBackgroundStyleLayer.mm | 1 - platform/darwin/src/MGLCircleStyleLayer.mm | 11 +--- platform/darwin/src/MGLFillStyleLayer.mm | 6 +-- platform/darwin/src/MGLGeometry.h | 7 --- platform/darwin/src/MGLLineStyleLayer.mm | 16 ++---- platform/darwin/src/MGLRasterStyleLayer.mm | 1 - platform/darwin/src/MGLStyleLayer.mm.ejs | 11 +--- platform/darwin/src/MGLSymbolStyleLayer.mm | 51 ++++--------------- 8 files changed, 18 insertions(+), 86 deletions(-) diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 386c6322e..883a6d139 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -10,7 +10,6 @@ #include - @interface MGLBackgroundStyleLayer () @property (nonatomic) mbgl::style::BackgroundLayer *rawLayer; diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 4e5f2c7fd..16f27991f 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -9,7 +9,6 @@ #import "MGLCircleStyleLayer.h" #include - namespace mbgl { MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, { @@ -141,10 +140,7 @@ namespace mbgl { } - (void)setCircleTranslateAnchor:(MGLStyleValue *)circleTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circleTranslateAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circleTranslateAnchor); _rawLayer->setCircleTranslateAnchor(mbglValue); } @@ -154,10 +150,7 @@ namespace mbgl { } - (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); _rawLayer->setCirclePitchScale(mbglValue); } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 24c8a90f7..3a3b44384 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -9,7 +9,6 @@ #import "MGLFillStyleLayer.h" #include - namespace mbgl { MBGL_DEFINE_ENUM(MGLFillTranslateAnchor, { @@ -136,10 +135,7 @@ namespace mbgl { } - (void)setFillTranslateAnchor:(MGLStyleValue *)fillTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(fillTranslateAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(fillTranslateAnchor); _rawLayer->setFillTranslateAnchor(mbglValue); } diff --git a/platform/darwin/src/MGLGeometry.h b/platform/darwin/src/MGLGeometry.h index 5fc927697..e2a4d818b 100644 --- a/platform/darwin/src/MGLGeometry.h +++ b/platform/darwin/src/MGLGeometry.h @@ -117,11 +117,4 @@ NS_INLINE CLLocationDegrees MGLDegreesFromRadians(CGFloat radians) { return radians * 180 / M_PI; } -/** - Methods for round-tripping Mapbox geometry structure values. - */ -@interface NSValue (MGLGeometryAdditions) - -@end - NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 93e310603..e36729041 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -9,7 +9,6 @@ #import "MGLLineStyleLayer.h" #include - namespace mbgl { MBGL_DEFINE_ENUM(MGLLineCap, { @@ -98,10 +97,7 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineCap); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineCap); _rawLayer->setLineCap(mbglValue); } @@ -111,10 +107,7 @@ namespace mbgl { } - (void)setLineJoin:(MGLStyleValue *)lineJoin { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); _rawLayer->setLineJoin(mbglValue); } @@ -176,10 +169,7 @@ namespace mbgl { } - (void)setLineTranslateAnchor:(MGLStyleValue *)lineTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineTranslateAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineTranslateAnchor); _rawLayer->setLineTranslateAnchor(mbglValue); } diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index c6283d89e..b832b0ad2 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -10,7 +10,6 @@ #include - @interface MGLRasterStyleLayer () @property (nonatomic) mbgl::style::RasterLayer *rawLayer; diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 894375e76..f8b830561 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -15,7 +15,6 @@ #import "MGL<%- camelize(type) %>StyleLayer.h" #include _layer.hpp> - <% if (containsEnumerationProperties) { -%> namespace mbgl { @@ -131,10 +130,7 @@ namespace mbgl { <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer, - NSValue *, - mbgl::style::<%- mbglType(property) %>, - MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); + auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(property.name) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); @@ -159,10 +155,7 @@ namespace mbgl { <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer, - NSValue *, - mbgl::style::<%- mbglType(property) %>, - MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); + auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(property.name) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 636849e87..9ba1bd7bc 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -9,7 +9,6 @@ #import "MGLSymbolStyleLayer.h" #include - namespace mbgl { MBGL_DEFINE_ENUM(MGLSymbolPlacement, { @@ -145,10 +144,7 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); _rawLayer->setSymbolPlacement(mbglValue); } @@ -208,10 +204,7 @@ namespace mbgl { } - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); _rawLayer->setIconRotationAlignment(mbglValue); } @@ -231,10 +224,7 @@ namespace mbgl { } - (void)setIconTextFit:(MGLStyleValue *)iconTextFit { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTextFit); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTextFit); _rawLayer->setIconTextFit(mbglValue); } @@ -304,10 +294,7 @@ namespace mbgl { } - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); _rawLayer->setTextPitchAlignment(mbglValue); } @@ -317,10 +304,7 @@ namespace mbgl { } - (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); _rawLayer->setTextRotationAlignment(mbglValue); } @@ -390,10 +374,7 @@ namespace mbgl { } - (void)setTextJustify:(MGLStyleValue *)textJustify { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); _rawLayer->setTextJustify(mbglValue); } @@ -403,10 +384,7 @@ namespace mbgl { } - (void)setTextAnchor:(MGLStyleValue *)textAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); _rawLayer->setTextAnchor(mbglValue); } @@ -456,10 +434,7 @@ namespace mbgl { } - (void)setTextTransform:(MGLStyleValue *)textTransform { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); _rawLayer->setTextTransform(mbglValue); } @@ -571,10 +546,7 @@ namespace mbgl { } - (void)setIconTranslateAnchor:(MGLStyleValue *)iconTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTranslateAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTranslateAnchor); _rawLayer->setIconTranslateAnchor(mbglValue); } @@ -644,10 +616,7 @@ namespace mbgl { } - (void)setTextTranslateAnchor:(MGLStyleValue *)textTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTranslateAnchor); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTranslateAnchor); _rawLayer->setTextTranslateAnchor(mbglValue); } From 238197c3e2311a9e90af70f03652f36b002ee0aa Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 23 Nov 2016 06:04:11 -0800 Subject: [PATCH 38/67] ios-v3.4.0-beta.4 --- platform/ios/Mapbox-iOS-SDK-symbols.podspec | 2 +- platform/ios/Mapbox-iOS-SDK.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/Mapbox-iOS-SDK-symbols.podspec b/platform/ios/Mapbox-iOS-SDK-symbols.podspec index dbb6030ce..3ec0fb387 100644 --- a/platform/ios/Mapbox-iOS-SDK-symbols.podspec +++ b/platform/ios/Mapbox-iOS-SDK-symbols.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'Mapbox-iOS-SDK' - m.version = '3.4.0-beta.3-symbols' + m.version = '3.4.0-beta.4-symbols' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source, OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa Touch APIs.' diff --git a/platform/ios/Mapbox-iOS-SDK.podspec b/platform/ios/Mapbox-iOS-SDK.podspec index 110c6d4e7..be6322187 100644 --- a/platform/ios/Mapbox-iOS-SDK.podspec +++ b/platform/ios/Mapbox-iOS-SDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'Mapbox-iOS-SDK' - m.version = '3.4.0-beta.3' + m.version = '3.4.0-beta.4' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source, OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa Touch APIs.' From 75666e5b539010e08badf6e79b1269da1361f4b5 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 23 Nov 2016 08:20:47 -0800 Subject: [PATCH 39/67] [ios, macos] Use namespaced property names in style NSValue category (#7171) --- .../NSValue+MGLStyleEnumAttributeAdditions.h | 32 +++++++++---------- ...Value+MGLStyleEnumAttributeAdditions.h.ejs | 4 +-- .../NSValue+MGLStyleEnumAttributeAdditions.mm | 32 +++++++++---------- ...alue+MGLStyleEnumAttributeAdditions.mm.ejs | 4 +-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h index 63ff86941..835b22b02 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h @@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLLineCap` enumeration representation of the value. */ -@property (readonly) MGLLineCap lineCap; +@property (readonly) MGLLineCap MGLLineCapValue; /** Creates a new value object containing the given `MGLLineJoin` enumeration. @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLLineJoin` enumeration representation of the value. */ -@property (readonly) MGLLineJoin lineJoin; +@property (readonly) MGLLineJoin MGLLineJoinValue; /** Creates a new value object containing the given `MGLSymbolPlacement` enumeration. @@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLSymbolPlacement` enumeration representation of the value. */ -@property (readonly) MGLSymbolPlacement symbolPlacement; +@property (readonly) MGLSymbolPlacement MGLSymbolPlacementValue; /** Creates a new value object containing the given `MGLIconRotationAlignment` enumeration. @@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLIconRotationAlignment` enumeration representation of the value. */ -@property (readonly) MGLIconRotationAlignment iconRotationAlignment; +@property (readonly) MGLIconRotationAlignment MGLIconRotationAlignmentValue; /** Creates a new value object containing the given `MGLIconTextFit` enumeration. @@ -82,7 +82,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLIconTextFit` enumeration representation of the value. */ -@property (readonly) MGLIconTextFit iconTextFit; +@property (readonly) MGLIconTextFit MGLIconTextFitValue; /** Creates a new value object containing the given `MGLTextPitchAlignment` enumeration. @@ -95,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextPitchAlignment` enumeration representation of the value. */ -@property (readonly) MGLTextPitchAlignment textPitchAlignment; +@property (readonly) MGLTextPitchAlignment MGLTextPitchAlignmentValue; /** Creates a new value object containing the given `MGLTextRotationAlignment` enumeration. @@ -108,7 +108,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextRotationAlignment` enumeration representation of the value. */ -@property (readonly) MGLTextRotationAlignment textRotationAlignment; +@property (readonly) MGLTextRotationAlignment MGLTextRotationAlignmentValue; /** Creates a new value object containing the given `MGLTextJustify` enumeration. @@ -121,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextJustify` enumeration representation of the value. */ -@property (readonly) MGLTextJustify textJustify; +@property (readonly) MGLTextJustify MGLTextJustifyValue; /** Creates a new value object containing the given `MGLTextAnchor` enumeration. @@ -134,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextAnchor` enumeration representation of the value. */ -@property (readonly) MGLTextAnchor textAnchor; +@property (readonly) MGLTextAnchor MGLTextAnchorValue; /** Creates a new value object containing the given `MGLTextTransform` enumeration. @@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextTransform` enumeration representation of the value. */ -@property (readonly) MGLTextTransform textTransform; +@property (readonly) MGLTextTransform MGLTextTransformValue; /** Creates a new value object containing the given `MGLFillTranslateAnchor` structure. @@ -160,7 +160,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLFillTranslateAnchor` enumeration representation of the value. */ -@property (readonly) MGLFillTranslateAnchor fillTranslateAnchor; +@property (readonly) MGLFillTranslateAnchor MGLFillTranslateAnchorValue; /** Creates a new value object containing the given `MGLLineTranslateAnchor` structure. @@ -173,7 +173,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLLineTranslateAnchor` enumeration representation of the value. */ -@property (readonly) MGLLineTranslateAnchor lineTranslateAnchor; +@property (readonly) MGLLineTranslateAnchor MGLLineTranslateAnchorValue; /** Creates a new value object containing the given `MGLIconTranslateAnchor` structure. @@ -186,7 +186,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLIconTranslateAnchor` enumeration representation of the value. */ -@property (readonly) MGLIconTranslateAnchor iconTranslateAnchor; +@property (readonly) MGLIconTranslateAnchor MGLIconTranslateAnchorValue; /** Creates a new value object containing the given `MGLTextTranslateAnchor` structure. @@ -199,7 +199,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLTextTranslateAnchor` enumeration representation of the value. */ -@property (readonly) MGLTextTranslateAnchor textTranslateAnchor; +@property (readonly) MGLTextTranslateAnchor MGLTextTranslateAnchorValue; /** Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. @@ -212,7 +212,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLCircleTranslateAnchor` enumeration representation of the value. */ -@property (readonly) MGLCircleTranslateAnchor circleTranslateAnchor; +@property (readonly) MGLCircleTranslateAnchor MGLCircleTranslateAnchorValue; /** Creates a new value object containing the given `MGLCirclePitchScale` structure. @@ -225,7 +225,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGLCirclePitchScale` enumeration representation of the value. */ -@property (readonly) MGLCirclePitchScale circlePitchScale; +@property (readonly) MGLCirclePitchScale MGLCirclePitchScaleValue; @end diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs index 6748f7ec9..c078ac7d0 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGL<%- camelize(property.name) %>` enumeration representation of the value. */ -@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; +@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value; <% } -%> <% } -%> @@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN /** The `MGL<%- camelize(property.name) %>` enumeration representation of the value. */ -@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; +@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value; <% } -%> <% } -%> diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm index dedff5cf3..b6a64a785 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm @@ -9,7 +9,7 @@ return [NSValue value:&lineCap withObjCType:@encode(MGLLineCap)]; } -- (MGLLineCap)lineCap { +- (MGLLineCap)MGLLineCapValue { MGLLineCap value; [self getValue:&value]; return value; @@ -19,7 +19,7 @@ return [NSValue value:&lineJoin withObjCType:@encode(MGLLineJoin)]; } -- (MGLLineJoin)lineJoin { +- (MGLLineJoin)MGLLineJoinValue { MGLLineJoin value; [self getValue:&value]; return value; @@ -29,7 +29,7 @@ return [NSValue value:&symbolPlacement withObjCType:@encode(MGLSymbolPlacement)]; } -- (MGLSymbolPlacement)symbolPlacement { +- (MGLSymbolPlacement)MGLSymbolPlacementValue { MGLSymbolPlacement value; [self getValue:&value]; return value; @@ -39,7 +39,7 @@ return [NSValue value:&iconRotationAlignment withObjCType:@encode(MGLIconRotationAlignment)]; } -- (MGLIconRotationAlignment)iconRotationAlignment { +- (MGLIconRotationAlignment)MGLIconRotationAlignmentValue { MGLIconRotationAlignment value; [self getValue:&value]; return value; @@ -49,7 +49,7 @@ return [NSValue value:&iconTextFit withObjCType:@encode(MGLIconTextFit)]; } -- (MGLIconTextFit)iconTextFit { +- (MGLIconTextFit)MGLIconTextFitValue { MGLIconTextFit value; [self getValue:&value]; return value; @@ -59,7 +59,7 @@ return [NSValue value:&textPitchAlignment withObjCType:@encode(MGLTextPitchAlignment)]; } -- (MGLTextPitchAlignment)textPitchAlignment { +- (MGLTextPitchAlignment)MGLTextPitchAlignmentValue { MGLTextPitchAlignment value; [self getValue:&value]; return value; @@ -69,7 +69,7 @@ return [NSValue value:&textRotationAlignment withObjCType:@encode(MGLTextRotationAlignment)]; } -- (MGLTextRotationAlignment)textRotationAlignment { +- (MGLTextRotationAlignment)MGLTextRotationAlignmentValue { MGLTextRotationAlignment value; [self getValue:&value]; return value; @@ -79,7 +79,7 @@ return [NSValue value:&textJustify withObjCType:@encode(MGLTextJustify)]; } -- (MGLTextJustify)textJustify { +- (MGLTextJustify)MGLTextJustifyValue { MGLTextJustify value; [self getValue:&value]; return value; @@ -89,7 +89,7 @@ return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; } -- (MGLTextAnchor)textAnchor { +- (MGLTextAnchor)MGLTextAnchorValue { MGLTextAnchor value; [self getValue:&value]; return value; @@ -99,7 +99,7 @@ return [NSValue value:&textTransform withObjCType:@encode(MGLTextTransform)]; } -- (MGLTextTransform)textTransform { +- (MGLTextTransform)MGLTextTransformValue { MGLTextTransform value; [self getValue:&value]; return value; @@ -109,7 +109,7 @@ return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslateAnchor)]; } -- (MGLFillTranslateAnchor)fillTranslateAnchor { +- (MGLFillTranslateAnchor)MGLFillTranslateAnchorValue { MGLFillTranslateAnchor value; [self getValue:&value]; return value; @@ -119,7 +119,7 @@ return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslate return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslateAnchor)]; } -- (MGLLineTranslateAnchor)lineTranslateAnchor { +- (MGLLineTranslateAnchor)MGLLineTranslateAnchorValue { MGLLineTranslateAnchor value; [self getValue:&value]; return value; @@ -129,7 +129,7 @@ return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslate return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslateAnchor)]; } -- (MGLIconTranslateAnchor)iconTranslateAnchor { +- (MGLIconTranslateAnchor)MGLIconTranslateAnchorValue { MGLIconTranslateAnchor value; [self getValue:&value]; return value; @@ -139,7 +139,7 @@ return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslate return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslateAnchor)]; } -- (MGLTextTranslateAnchor)textTranslateAnchor { +- (MGLTextTranslateAnchor)MGLTextTranslateAnchorValue { MGLTextTranslateAnchor value; [self getValue:&value]; return value; @@ -149,7 +149,7 @@ return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslate return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; } -- (MGLCircleTranslateAnchor)circleTranslateAnchor { +- (MGLCircleTranslateAnchor)MGLCircleTranslateAnchorValue { MGLCircleTranslateAnchor value; [self getValue:&value]; return value; @@ -159,7 +159,7 @@ return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTrans return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; } -- (MGLCirclePitchScale)circlePitchScale { +- (MGLCirclePitchScale)MGLCirclePitchScaleValue { MGLCirclePitchScale value; [self getValue:&value]; return value; diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs index d445fa0a5..fab278aac 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs @@ -17,7 +17,7 @@ const paintProperties = locals.paintProperties; return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; } -- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { +- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value { MGL<%- camelize(property.name) %> value; [self getValue:&value]; return value; @@ -33,7 +33,7 @@ const paintProperties = locals.paintProperties; return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; } -- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { +- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value { MGL<%- camelize(property.name) %> value; [self getValue:&value]; return value; From 67e079f7268015f75b47090a6a0db5c3176d40d6 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 23 Nov 2016 12:21:52 -0800 Subject: [PATCH 40/67] [ios, macos] Fix integer formatting in formatted exception strings (#7173) --- platform/darwin/src/MGLMultiPoint.mm | 8 ++++---- platform/darwin/src/MGLPointCollection.mm | 4 ++-- platform/ios/app/MBXViewController.m | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index f086bcbc3..0133e03b3 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -58,8 +58,8 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException - format:@"Invalid coordinate range %@ extends beyond current coordinate count of %@", - NSStringFromRange(range), @([self pointCount])]; + format:@"Invalid coordinate range %@ extends beyond current coordinate count of %ld", + NSStringFromRange(range), (unsigned long)[self pointCount]]; } std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); @@ -83,8 +83,8 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) if (NSMaxRange(range) > _coordinates.size()) { [NSException raise:NSRangeException - format:@"Invalid range %@ for existing coordinate count %@", - NSStringFromRange(range), @([self pointCount])]; + format:@"Invalid range %@ for existing coordinate count %ld", + NSStringFromRange(range), (unsigned long)[self pointCount]]; } [self willChangeValueForKey:@"coordinates"]; diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index 21982ca7b..8c9d11f42 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -54,8 +54,8 @@ NS_ASSUME_NONNULL_BEGIN if (range.location + range.length > [self pointCount]) { [NSException raise:NSRangeException - format:@"Invalid coordinate range %@ extends beyond current coordinate count of %@", - NSStringFromRange(range), @([self pointCount])]; + format:@"Invalid coordinate range %@ extends beyond current coordinate count of %ld", + NSStringFromRange(range), (unsigned long)[self pointCount]]; } std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 91e934ed1..8a2ccee41 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1596,7 +1596,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { { queuedAnnotations += queue.count; } - self.hudLabel.text = [NSString stringWithFormat:@"Visible: %ld Queued: %ld", (long)mapView.visibleAnnotations.count, (long)queuedAnnotations]; + self.hudLabel.text = [NSString stringWithFormat:@"Visible: %ld Queued: %ld", (unsigned long)mapView.visibleAnnotations.count, (unsigned long)queuedAnnotations]; } } From 767044420d32f6030d25b6b0c979feac2fa1ff60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 18 Aug 2016 18:01:19 -0700 Subject: [PATCH 41/67] [ios, macos] Added debug descriptions for runtime styling classes --- platform/darwin/src/MGLForegroundStyleLayer.m | 7 +++++++ platform/darwin/src/MGLGeoJSONSource.mm | 6 ++++++ platform/darwin/src/MGLRasterSource.mm | 8 ++++++++ platform/darwin/src/MGLSource.mm | 5 +++++ platform/darwin/src/MGLStyleLayer.mm | 7 +++++++ platform/darwin/src/MGLTileSet.mm | 6 ++++++ platform/darwin/src/MGLVectorSource.mm | 6 ++++++ platform/darwin/src/MGLVectorStyleLayer.m | 9 +++++++++ 8 files changed, 54 insertions(+) diff --git a/platform/darwin/src/MGLForegroundStyleLayer.m b/platform/darwin/src/MGLForegroundStyleLayer.m index e3af96331..b7a0379af 100644 --- a/platform/darwin/src/MGLForegroundStyleLayer.m +++ b/platform/darwin/src/MGLForegroundStyleLayer.m @@ -10,4 +10,11 @@ return self; } +- (NSString *)description { + return [NSString stringWithFormat: + @"<%@: %p; identifier = %@; sourceIdentifier = %@; visible = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, + self.sourceIdentifier, self.visible ? @"YES" : @"NO"]; +} + @end diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index 0213b6a27..f7cd6be7d 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -192,4 +192,10 @@ const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"M _features = MGLFeaturesFromMBGLFeatures(featureCollection); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; geoJSONData = %@; features = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.geoJSONData, self.features]; +} + @end diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index 92494febf..53caae5af 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -73,4 +73,12 @@ 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]; +} + @end diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index 1b889d44d..4f9cfb014 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -12,4 +12,9 @@ return self; } +- (NSString *)description { + return [NSString stringWithFormat:@"<%@: %p; identifier = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier]; +} + @end diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm index 7f29041f8..d1943cd46 100644 --- a/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/darwin/src/MGLStyleLayer.mm @@ -51,4 +51,11 @@ return self.rawLayer->getMinZoom(); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@; visible = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, + self.visible ? @"YES" : @"NO"]; +} + @end diff --git a/platform/darwin/src/MGLTileSet.mm b/platform/darwin/src/MGLTileSet.mm index b2359bb92..f795545ee 100644 --- a/platform/darwin/src/MGLTileSet.mm +++ b/platform/darwin/src/MGLTileSet.mm @@ -84,4 +84,10 @@ return tileset; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; tileURLTemplates = %@>", + NSStringFromClass([self class]), (void *)self, self.tileURLTemplates]; +} + @end diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index 2c7b529d7..1b3406e5e 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -72,4 +72,10 @@ static NSString *MGLVectorSourceType = @"vector"; self.rawSource = _pendingSource.get(); } +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p; identifier = %@; URL = %@; tileSet = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, self.URL, self.tileSet]; +} + @end diff --git a/platform/darwin/src/MGLVectorStyleLayer.m b/platform/darwin/src/MGLVectorStyleLayer.m index 174256cbd..d8146f424 100644 --- a/platform/darwin/src/MGLVectorStyleLayer.m +++ b/platform/darwin/src/MGLVectorStyleLayer.m @@ -13,4 +13,13 @@ return nil; } +- (NSString *)description { + return [NSString stringWithFormat: + @"<%@: %p; identifier = %@; sourceIdentifier = %@; " + @"sourceLayerIdentifier = %@; predicate = %@; visible = %@>", + NSStringFromClass([self class]), (void *)self, self.identifier, + self.sourceIdentifier, self.sourceLayerIdentifier, self.predicate, + self.visible ? @"YES" : @"NO"]; +} + @end From f71dd14bb74be22fb27646b8732843d92cf72c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 18 Aug 2016 16:28:58 -0700 Subject: [PATCH 42/67] [ios, macos] Reorganized MGLStyle --- platform/darwin/src/MGLStyle.h | 71 +++++++++++---------- platform/darwin/src/MGLStyle.mm | 107 ++++++++++++++++++-------------- 2 files changed, 98 insertions(+), 80 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 7f01c230c..96dc8fba4 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -37,7 +37,7 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ @interface MGLStyle : NSObject -#pragma mark Default Style URLs +#pragma mark Accessing Common Styles /** Returns the URL to version 8 of the @@ -165,6 +165,8 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ + (NSURL *)satelliteStreetsStyleURLWithVersion:(NSInteger)version; +#pragma mark Accessing Metadata About the Style + /** The name of the style. @@ -172,26 +174,41 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ @property (readonly, copy, nullable) NSString *name; -#pragma mark Runtime Styling +#pragma mark Managing Sources /** - Returns a layer that conforms to `MGLStyleLayer` if any layer with the given - identifier was found. - - @return An instance of a concrete subclass of `MGLStyleLayer` associated with - the given identifier. - */ -- (nullable MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier; - - -/** - Returns a source if any source with the given identifier was found. + Returns a source with the given identifier in the current style. @return An instance of a concrete subclass of `MGLSource` associated with the - given identifier. + given identifier, or `nil` if the current style contains no such source. */ - (nullable MGLSource *)sourceWithIdentifier:(NSString *)identifier; +/** + Adds a new source to the current style. + + @param source The source to add to the current style. + */ +- (void)addSource:(MGLSource *)source; + +/** + Removes a source from the current style. + + @param source The source to remove from the current style. + */ +- (void)removeSource:(MGLSource *)source; + +#pragma mark Managing Style Layers + +/** + Returns a style layer with the given identifier in the current style. + + @return An instance of a concrete subclass of `MGLStyleLayer` associated with + the given identifier, or `nil` if the current style contains no such style + layer. + */ +- (nullable MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier; + /** Adds a new layer on top of existing layers. @@ -216,19 +233,7 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ - (void)removeLayer:(MGLStyleLayer *)layer; -/** - Adds a new source to the map view. - - @param source The source to add to the map view. - */ -- (void)addSource:(MGLSource *)source; - -/** - Removes a source from the map view. - - @param source The source to remove. - */ -- (void)removeSource:(MGLSource *)source; +#pragma mark Managing Style Classes /** Currently active style classes, represented as an array of string identifiers. @@ -258,12 +263,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ - (void)removeStyleClass:(NSString *)styleClass; +#pragma mark Managing a Style’s Images + /** -Adds or overrides an image used by the style’s layers. - -To use an image in a style layer, give it a unique name using this method, -then set the `iconImage` property of an `MGLSymbolStyleLayer` object to that name. - + Adds or overrides an image used by the style’s layers. + + To use an image in a style layer, give it a unique name using this method, then + set the `iconImage` property of an `MGLSymbolStyleLayer` object to that name. + @param image The image for the name. @param name The name of the image to set to the style. */ diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 980abe3e3..69d76614c 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -46,6 +46,8 @@ @implementation MGLStyle +#pragma mark Default style URLs + static_assert(mbgl::util::default_styles::currentVersion == MGLStyleDefaultVersion, "mbgl::util::default_styles::currentVersion and MGLStyleDefaultVersion disagree."); /// @param name The style’s marketing name, written in lower camelCase. @@ -96,6 +98,8 @@ static NSURL *MGLStyleURL_emerald; return MGLStyleURL_emerald; } +#pragma mark Metadata + - (NSString *)name { return @(self.mapView.mbglMap->getStyleName().c_str()); } @@ -104,6 +108,58 @@ static NSURL *MGLStyleURL_emerald; return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())]; } +#pragma mark Sources + +- (MGLSource *)sourceWithIdentifier:(NSString *)identifier +{ + auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String); + if (!mbglSource) { + return nil; + } + + // TODO: Fill in options specific to the respective source classes + // https://github.com/mapbox/mapbox-gl-native/issues/6584 + MGLSource *source; + if (mbglSource->is()) { + source = [[MGLVectorSource alloc] initWithIdentifier:identifier]; + } else if (mbglSource->is()) { + source = [[MGLGeoJSONSource alloc] initWithIdentifier:identifier]; + } else if (mbglSource->is()) { + source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; + } else { + NSAssert(NO, @"Unrecognized source type"); + return nil; + } + + source.rawSource = mbglSource; + + return source; +} + +- (void)addSource:(MGLSource *)source +{ + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be added to the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } + [source addToMapView:self.mapView]; +} + +- (void)removeSource:(MGLSource *)source +{ + if (!source.rawSource) { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be removed from the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + source]; + } + [source removeFromMapView:self.mapView]; +} + +#pragma mark Style layers + - (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier { auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String); @@ -139,33 +195,6 @@ static NSURL *MGLStyleURL_emerald; return styleLayer; } -- (MGLSource *)sourceWithIdentifier:(NSString *)identifier -{ - auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String); - - if (!mbglSource) { - return nil; - } - - // TODO: Fill in options specific to the respective source classes - // https://github.com/mapbox/mapbox-gl-native/issues/6584 - MGLSource *source; - if (mbglSource->is()) { - source = [[MGLVectorSource alloc] initWithIdentifier:identifier]; - } else if (mbglSource->is()) { - source = [[MGLGeoJSONSource alloc] initWithIdentifier:identifier]; - } else if (mbglSource->is()) { - source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; - } else { - NSAssert(NO, @"Unrecognized source type"); - return nil; - } - - source.rawSource = mbglSource; - - return source; -} - - (void)removeLayer:(MGLStyleLayer *)layer { if (!layer.rawLayer) { @@ -207,27 +236,7 @@ static NSURL *MGLStyleURL_emerald; [layer addToMapView:self.mapView belowLayer:otherLayer]; } -- (void)addSource:(MGLSource *)source -{ - if (!source.rawSource) { - [NSException raise:NSInvalidArgumentException format: - @"The source %@ cannot be added to the style. " - @"Make sure the source was created as a member of a concrete subclass of MGLSource.", - source]; - } - [source addToMapView:self.mapView]; -} - -- (void)removeSource:(MGLSource *)source -{ - if (!source.rawSource) { - [NSException raise:NSInvalidArgumentException format: - @"The source %@ cannot be removed from the style. " - @"Make sure the source was created as a member of a concrete subclass of MGLSource.", - source]; - } - [source removeFromMapView:self.mapView]; -} +#pragma mark Style classes - (NS_ARRAY_OF(NSString *) *)styleClasses { @@ -282,6 +291,8 @@ static NSURL *MGLStyleURL_emerald; } } +#pragma mark Style images + - (void)setImage:(MGLImage *)image forName:(NSString *)name { NSAssert(image, @"image is null"); From 850b70ff91e582916829c5248afcafa195070a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 18 Aug 2016 18:00:58 -0700 Subject: [PATCH 43/67] [core, ios, macos] Added layers and sources properties to MGLStyle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added new layers and sources properties to MGLStyle that contain all the style’s layers and sources, respectively. These properties are KVC-compliant with all the mutable to-many methods. Layers are ordered from topmost to bottommost, for consistency with Cocoa APIs where front/first means top and back/last means bottom. Also added storage for mbgl::style::Source in MGLSource proper for wrapping AnnotationSource. Until the style finishes loading, its name property is set to nil. Fixes #6003. --- include/mbgl/map/map.hpp | 2 + .../darwin/src/MGLBackgroundStyleLayer.mm | 3 + platform/darwin/src/MGLCircleStyleLayer.mm | 3 + platform/darwin/src/MGLFillStyleLayer.mm | 3 + platform/darwin/src/MGLLineStyleLayer.mm | 3 + platform/darwin/src/MGLRasterStyleLayer.mm | 3 + platform/darwin/src/MGLSource.mm | 22 ++ platform/darwin/src/MGLStyle.h | 35 +++- platform/darwin/src/MGLStyle.mm | 198 ++++++++++++++++-- platform/darwin/src/MGLStyleLayer.mm.ejs | 3 + platform/darwin/src/MGLSymbolStyleLayer.mm | 3 + platform/darwin/src/MGLVectorSource.mm | 2 - src/mbgl/map/map.cpp | 10 +- src/mbgl/style/style.cpp | 27 +++ src/mbgl/style/style.hpp | 3 + 15 files changed, 300 insertions(+), 20 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 0c14600c7..10153c54e 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -157,11 +157,13 @@ public: void removeAnnotation(AnnotationID); // Sources + std::vector getSources(); style::Source* getSource(const std::string& sourceID); void addSource(std::unique_ptr); std::unique_ptr removeSource(const std::string& sourceID); // Layers + std::vector getLayers(); style::Layer* getLayer(const std::string& layerID); void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); std::unique_ptr removeLayer(const std::string& layerID); diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 883a6d139..6e30a20c9 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -51,6 +51,9 @@ - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 16f27991f..aca8ff028 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -83,6 +83,9 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 3a3b44384..d670fd31e 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -78,6 +78,9 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index e36729041..34c58aa49 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -90,6 +90,9 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index b832b0ad2..49dc261be 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -50,6 +50,9 @@ - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm index 4f9cfb014..2fa580df8 100644 --- a/platform/darwin/src/MGLSource.mm +++ b/platform/darwin/src/MGLSource.mm @@ -2,6 +2,14 @@ #include +@interface MGLSource () + +// Even though this class is abstract, MGLStyle uses it to represent some +// special internal source types like mbgl::AnnotationSource. +@property (nonatomic) mbgl::style::Source *rawSource; + +@end + @implementation MGLSource - (instancetype)initWithIdentifier:(NSString *)identifier @@ -12,6 +20,20 @@ return self; } +- (void)addToMapView:(MGLMapView *)mapView { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be added to the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + self]; +} + +- (void)removeFromMapView:(MGLMapView *)mapView { + [NSException raise:NSInvalidArgumentException format: + @"The source %@ cannot be removed from the style. " + @"Make sure the source was created as a member of a concrete subclass of MGLSource.", + self]; +} + - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p; identifier = %@>", NSStringFromClass([self class]), (void *)self, self.identifier]; diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 96dc8fba4..b3e1b28ee 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -176,6 +176,11 @@ static const NSInteger MGLStyleDefaultVersion = 9; #pragma mark Managing Sources +/** + A set containing the style’s sources. + */ +@property (nonatomic, strong) NS_MUTABLE_SET_OF(MGLSource *) *sources; + /** Returns a source with the given identifier in the current style. @@ -200,6 +205,12 @@ static const NSInteger MGLStyleDefaultVersion = 9; #pragma mark Managing Style Layers +/** + The layers included in the style, arranged according to their front-to-back + ordering on the screen. + */ +@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *layers; + /** Returns a style layer with the given identifier in the current style. @@ -217,13 +228,31 @@ static const NSInteger MGLStyleDefaultVersion = 9; */ - (void)addLayer:(MGLStyleLayer *)layer; +/** + Inserts a new layer into the style at the given index. + + @param layer The layer to insert. + @param index The index at which to insert the layer. An index of 0 would send + the layer to the back; an index equal to the number of objects in the + `layers` property would bring the layer to the front. + */ +- (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index; + /** Inserts a new layer below another layer. - @param layer Layer to be inserted. - @param belowLayer A layer that's already on the map view. + @param layer The layer to insert. + @param sibling An existing layer in the style. */ -- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer; +- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)sibling; + +/** + Inserts a new layer above another layer. + + @param layer The layer to insert. + @param sibling An existing layer in the style. + */ +- (void)insertLayer:(MGLStyleLayer *)layer aboveLayer:(MGLStyleLayer *)sibling; /** Removes a layer from the map view. diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 69d76614c..4169c7a5d 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -101,7 +101,8 @@ static NSURL *MGLStyleURL_emerald; #pragma mark Metadata - (NSString *)name { - return @(self.mapView.mbglMap->getStyleName().c_str()); + std::string name = self.mapView.mbglMap->getStyleName(); + return name.empty() ? nil : @(name.c_str()); } - (NSURL *)URL { @@ -110,13 +111,43 @@ static NSURL *MGLStyleURL_emerald; #pragma mark Sources +- (NS_MUTABLE_SET_OF(MGLSource *) *)sources { + auto rawSources = self.mapView.mbglMap->getSources(); + NSMutableSet *sources = [NSMutableSet setWithCapacity:rawSources.size()]; + for (auto rawSource = rawSources.begin(); rawSource != rawSources.end(); ++rawSource) { + MGLSource *source = [self sourceFromMBGLSource:*rawSource]; + [sources addObject:source]; + } + return sources; +} + +- (void)setSources:(NS_MUTABLE_SET_OF(MGLSource *) *)sources { + for (MGLSource *source in self.sources) { + [self removeSource:source]; + } + for (MGLSource *source in sources) { + [self addSource:source]; + } +} + +- (NSUInteger)countOfSources { + auto rawSources = self.mapView.mbglMap->getSources(); + return rawSources.size(); +} + +- (MGLSource *)memberOfSources:(MGLSource *)object { + return [self sourceWithIdentifier:object.identifier]; +} + - (MGLSource *)sourceWithIdentifier:(NSString *)identifier { - auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String); - if (!mbglSource) { - return nil; - } + auto rawSource = self.mapView.mbglMap->getSource(identifier.UTF8String); + return rawSource ? [self sourceFromMBGLSource:rawSource] : nil; +} +- (MGLSource *)sourceFromMBGLSource:(mbgl::style::Source *)mbglSource { + NSString *identifier = @(mbglSource->getID().c_str()); + // TODO: Fill in options specific to the respective source classes // https://github.com/mapbox/mapbox-gl-native/issues/6584 MGLSource *source; @@ -160,13 +191,93 @@ static NSURL *MGLStyleURL_emerald; #pragma mark Style layers -- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier +- (NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers { - auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String); - if (!mbglLayer) { + auto layers = self.mapView.mbglMap->getLayers(); + NSMutableArray *styleLayers = [NSMutableArray arrayWithCapacity:layers.size()]; + for (auto layer = layers.rbegin(); layer != layers.rend(); ++layer) { + MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:*layer]; + [styleLayers addObject:styleLayer]; + } + return styleLayers; +} + +- (void)setLayers:(NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers { + for (MGLStyleLayer *layer in self.layers.reverseObjectEnumerator) { + [self removeLayer:layer]; + } + for (MGLStyleLayer *layer in layers.reverseObjectEnumerator) { + [self addLayer:layer]; + } +} + +- (NSUInteger)countOfLayers +{ + return self.mapView.mbglMap->getLayers().size(); +} + +- (MGLStyleLayer *)objectInLayersAtIndex:(NSUInteger)index +{ + auto layers = self.mapView.mbglMap->getLayers(); + if (index > layers.size() - 1) { + [NSException raise:NSRangeException + format:@"No style layer at index %lu.", (unsigned long)index]; return nil; } + auto layer = layers.at(layers.size() - 1 - index); + return [self layerFromMBGLLayer:layer]; +} +- (void)getLayers:(MGLStyleLayer **)buffer range:(NSRange)inRange +{ + auto layers = self.mapView.mbglMap->getLayers(); + if (NSMaxRange(inRange) > layers.size()) { + [NSException raise:NSRangeException + format:@"Style layer range %@ is out of bounds.", NSStringFromRange(inRange)]; + } + NSUInteger i = 0; + for (auto layer = *(layers.rbegin() + inRange.location); i < inRange.length; ++layer, ++i) { + MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:layer]; + buffer[i] = styleLayer; + } +} + +- (void)insertObject:(MGLStyleLayer *)styleLayer inLayersAtIndex:(NSUInteger)index +{ + if (!styleLayer.rawLayer) { + [NSException raise:NSInvalidArgumentException format: + @"The style layer %@ cannot be inserted into the style. " + @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", + styleLayer]; + } + auto layers = self.mapView.mbglMap->getLayers(); + if (index > layers.size()) { + [NSException raise:NSRangeException + format:@"Cannot insert style layer at out-of-bounds index %lu.", (unsigned long)index]; + } else if (index == 0) { + [styleLayer addToMapView:self.mapView]; + } else { + MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(layers.size() - index)]; + [styleLayer addToMapView:self.mapView belowLayer:sibling]; + } +} + +- (void)removeObjectFromLayersAtIndex:(NSUInteger)index +{ + auto layers = self.mapView.mbglMap->getLayers(); + if (index > layers.size() - 1) { + [NSException raise:NSRangeException + format:@"Cannot remove style layer at out-of-bounds index %lu.", (unsigned long)index]; + } + auto layer = layers.at(layers.size() - 1 - index); + self.mapView.mbglMap->removeLayer(layer->getID()); +} + +- (MGLStyleLayer *)layerFromMBGLLayer:(mbgl::style::Layer *)mbglLayer +{ + NSParameterAssert(mbglLayer); + + NSString *identifier = @(mbglLayer->getID().c_str()); MGLStyleLayer *styleLayer; if (auto fillLayer = mbglLayer->as()) { MGLSource *source = [self sourceWithIdentifier:@(fillLayer->getSourceID().c_str())]; @@ -195,6 +306,12 @@ static NSURL *MGLStyleURL_emerald; return styleLayer; } +- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier +{ + auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String); + return mbglLayer ? [self layerFromMBGLLayer:mbglLayer] : nil; +} + - (void)removeLayer:(MGLStyleLayer *)layer { if (!layer.rawLayer) { @@ -217,7 +334,11 @@ static NSURL *MGLStyleURL_emerald; [layer addToMapView:self.mapView]; } -- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer +- (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index { + [self insertObject:layer inLayersAtIndex:index]; +} + +- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)sibling { if (!layer.rawLayer) { [NSException raise:NSInvalidArgumentException @@ -226,14 +347,58 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } - if (!otherLayer.rawLayer) { + if (!sibling.rawLayer) { [NSException raise:NSInvalidArgumentException format: - @"A style layer cannot be placed before %@ in the style. " - @"Make sure otherLayer was obtained using -[MGLStyle layerWithIdentifier:].", - otherLayer]; + @"A style layer cannot be placed below %@ in the style. " + @"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].", + sibling]; } - [layer addToMapView:self.mapView belowLayer:otherLayer]; + [self willChangeValueForKey:@"layers"]; + [layer addToMapView:self.mapView belowLayer:sibling]; + [self didChangeValueForKey:@"layers"]; +} + +- (void)insertLayer:(MGLStyleLayer *)layer aboveLayer:(MGLStyleLayer *)sibling { + if (!layer.rawLayer) { + [NSException raise:NSInvalidArgumentException + format: + @"The style layer %@ cannot be added to the style. " + @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", + layer]; + } + if (!sibling.rawLayer) { + [NSException raise:NSInvalidArgumentException + format: + @"A style layer cannot be placed above %@ in the style. " + @"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].", + sibling]; + } + + auto layers = self.mapView.mbglMap->getLayers(); + std::string siblingIdentifier = sibling.identifier.UTF8String; + NSUInteger index = 0; + for (auto layer : layers) { + if (layer->getID() == siblingIdentifier) { + break; + } + index++; + } + + [self willChangeValueForKey:@"layers"]; + if (index + 1 > layers.size()) { + [NSException raise:NSInvalidArgumentException + format: + @"A style layer cannot be placed above %@ in the style. " + @"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].", + sibling]; + } else if (index + 1 == layers.size()) { + [layer addToMapView:self.mapView]; + } else { + MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(index + 1)]; + [layer addToMapView:self.mapView belowLayer:sibling]; + } + [self didChangeValueForKey:@"layers"]; } #pragma mark Style classes @@ -270,6 +435,11 @@ static NSURL *MGLStyleURL_emerald; self.mapView.mbglMap->setClasses(newAppliedClasses); } +- (NSUInteger)countOfStyleClasses { + const auto &classes = self.mapView.mbglMap->getClasses(); + return classes.size(); +} + - (BOOL)hasStyleClass:(NSString *)styleClass { return styleClass && self.mapView.mbglMap->hasClass([styleClass UTF8String]); diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index f8b830561..8febd69a2 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -120,6 +120,9 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_castLayer> &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 9ba1bd7bc..0acc36d2d 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -137,6 +137,9 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); + if (!removedLayer) { + return; + } _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); _rawLayer = _pendingLayer.get(); } diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index 1b3406e5e..ae69456b4 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -18,8 +18,6 @@ std::unique_ptr _pendingSource; } -static NSString *MGLVectorSourceType = @"vector"; - - (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url { if (self = [super initWithIdentifier:identifier]) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index bd1de6f18..68c20a313 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -803,6 +803,10 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) { #pragma mark - Style API +std::vector Map::getSources() { + return impl->style ? impl->style->getSources() : std::vector(); +} + style::Source* Map::getSource(const std::string& sourceID) { if (impl->style) { impl->styleMutated = true; @@ -825,8 +829,12 @@ std::unique_ptr Map::removeSource(const std::string& sourceID) { } return nullptr; } + +std::vector Map::getLayers() { + return impl->style ? impl->style->getLayers() : std::vector(); +} -style::Layer* Map::getLayer(const std::string& layerID) { +Layer* Map::getLayer(const std::string& layerID) { if (impl->style) { impl->styleMutated = true; return impl->style->getLayer(layerID); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 05dbc0843..d57f5cf98 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -165,6 +165,15 @@ std::vector Style::getLayers() const { return result; } +std::vector Style::getLayers() { + std::vector result; + result.reserve(layers.size()); + for (auto& layer : layers) { + result.push_back(layer.get()); + } + return result; +} + std::vector>::const_iterator Style::findLayer(const std::string& id) const { return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) { return layer->baseImpl->id == id; @@ -312,6 +321,24 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { } } +std::vector Style::getSources() const { + std::vector result; + result.reserve(sources.size()); + for (const auto& source : sources) { + result.push_back(source.get()); + } + return result; +} + +std::vector Style::getSources() { + std::vector result; + result.reserve(sources.size()); + for (auto& source : sources) { + result.push_back(source.get()); + } + return result; +} + Source* Style::getSource(const std::string& id) const { const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) { return source->getID() == id; diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 2875311c6..1da22b8cf 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -64,11 +64,14 @@ public: return lastError; } + std::vector getSources() const; + std::vector getSources(); Source* getSource(const std::string& id) const; void addSource(std::unique_ptr); std::unique_ptr removeSource(const std::string& sourceID); std::vector getLayers() const; + std::vector getLayers(); Layer* getLayer(const std::string& id) const; Layer* addLayer(std::unique_ptr, optional beforeLayerID = {}); From 9fac640bf35db408f56103b45f8ef7982204bfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 19 Aug 2016 13:56:46 -0700 Subject: [PATCH 44/67] [ios, macos] Key-value compliance for MGLStyle Replaced -[MGLMapView style] with a property. Keep the MGLStyle object around for the lifetime of the style. Bracket changes to layers in willChange and didChange calls. The built-in point annotation layer is added after the style is finished loading but before the map is finished loading. Cause a second wave of change notifications to go out, about both sources and layers. Issue change notifications for style layers when shape annotations are added or removed. --- platform/darwin/src/MGLStyle.mm | 28 +++++++++++++----- platform/darwin/src/MGLStyle_Private.h | 5 +++- platform/ios/src/MGLMapView.h | 15 +++++++--- platform/ios/src/MGLMapView.mm | 41 +++++++++++++++++++++----- platform/macos/src/MGLMapView.h | 15 +++++++--- platform/macos/src/MGLMapView.mm | 37 ++++++++++++++++++----- 6 files changed, 108 insertions(+), 33 deletions(-) diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 4169c7a5d..e11ceb028 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -40,8 +40,10 @@ #endif @interface MGLStyle() -@property (nonatomic, weak) MGLMapView *mapView; + +@property (nonatomic, readwrite, weak) MGLMapView *mapView; @property (readonly, copy, nullable) NSURL *URL; + @end @implementation MGLStyle @@ -98,17 +100,24 @@ static NSURL *MGLStyleURL_emerald; return MGLStyleURL_emerald; } -#pragma mark Metadata +#pragma mark - -- (NSString *)name { - std::string name = self.mapView.mbglMap->getStyleName(); - return name.empty() ? nil : @(name.c_str()); +- (instancetype)initWithMapView:(MGLMapView *)mapView { + if (self = [super init]) { + _mapView = mapView; + } + return self; } - (NSURL *)URL { return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())]; } +- (NSString *)name { + std::string name = self.mapView.mbglMap->getStyleName(); + return name.empty() ? nil : @(name.c_str()); +} + #pragma mark Sources - (NS_MUTABLE_SET_OF(MGLSource *) *)sources { @@ -158,8 +167,7 @@ static NSURL *MGLStyleURL_emerald; } else if (mbglSource->is()) { source = [[MGLRasterSource alloc] initWithIdentifier:identifier]; } else { - NSAssert(NO, @"Unrecognized source type"); - return nil; + source = [[MGLSource alloc] initWithIdentifier:identifier]; } source.rawSource = mbglSource; @@ -320,7 +328,9 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } - [layer removeFromMapView:self.mapView]; + [self willChangeValueForKey:@"layers"]; + [layer removeFromMapView:self.mapView]; + [self didChangeValueForKey:@"layers"]; } - (void)addLayer:(MGLStyleLayer *)layer @@ -331,7 +341,9 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.", layer]; } + [self willChangeValueForKey:@"layers"]; [layer addToMapView:self.mapView]; + [self didChangeValueForKey:@"layers"]; } - (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index { diff --git a/platform/darwin/src/MGLStyle_Private.h b/platform/darwin/src/MGLStyle_Private.h index 46291b37b..b7c2fa4cd 100644 --- a/platform/darwin/src/MGLStyle_Private.h +++ b/platform/darwin/src/MGLStyle_Private.h @@ -6,7 +6,10 @@ #include @interface MGLStyle (Private) -@property (nonatomic, weak) MGLMapView *mapView; + +- (instancetype)initWithMapView:(MGLMapView *)mapView; + +@property (nonatomic, readonly, weak) MGLMapView *mapView; - (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration; diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index e467495a4..e066387e2 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -117,6 +117,14 @@ IB_DESIGNABLE #pragma mark Configuring the Map’s Appearance +/** + The style currently displayed in the receiver. + + Unlike the `styleURL` property, this property is set to an object that allows + you to manipulate every aspect of the style locally. + */ +@property (nonatomic, readonly) MGLStyle *style; + /** URLs of the styles bundled with the library. @@ -134,6 +142,9 @@ IB_DESIGNABLE If you set this property to `nil`, the receiver will use the default style and this property will automatically be set to that style’s URL. + + If you want to modify the current style without replacing it outright, or if + you want to introspect individual style attributes, use the `style` property. */ @property (nonatomic, null_resettable) NSURL *styleURL; @@ -1077,10 +1088,6 @@ IB_DESIGNABLE */ - (void)removeOverlays:(NS_ARRAY_OF(id ) *)overlays; -#pragma mark - Runtime styling API - -- (MGLStyle *)style; - #pragma mark Accessing the Underlying Map Data /** diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e857a9fa4..b1ecf1c41 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -236,6 +236,9 @@ public: @property (nonatomic, readwrite) UIButton *attributionButton; @property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *attributionButtonConstraints; @property (nonatomic) UIActionSheet *attributionSheet; + +@property (nonatomic, readwrite) MGLStyle *style; + @property (nonatomic) UIPanGestureRecognizer *pan; @property (nonatomic) UIPinchGestureRecognizer *pinch; @property (nonatomic) UIRotationGestureRecognizer *rotate; @@ -284,6 +287,8 @@ public: std::vector _annotationsNearbyLastTap; CGPoint _initialImplicitCalloutViewOffset; NSDate *_userLocationAnimationCompletionDate; + /// True if a willChange notification has been issued for shape annotation layers and a didChange notification is pending. + BOOL _isChangingAnnotationLayers; BOOL _isWaitingForRedundantReachableNotification; BOOL _isTargetingInterfaceBuilder; @@ -355,14 +360,17 @@ public: - (void)setStyleURL:(nullable NSURL *)styleURL { if (_isTargetingInterfaceBuilder) return; - + if ( ! styleURL) { styleURL = [MGLStyle streetsStyleURLWithVersion:MGLStyleDefaultVersion]; } styleURL = styleURL.mgl_URLByStandardizingScheme; + [self willChangeValueForKey:@"style"]; + _style = [[MGLStyle alloc] initWithMapView:self]; _mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]); + [self didChangeValueForKey:@"style"]; } - (IBAction)reloadStyle:(__unused id)sender { @@ -620,13 +628,6 @@ public: return image; } -- (MGLStyle *)style -{ - MGLStyle *style = [[MGLStyle alloc] init]; - style.mapView = self; - return style; -} - - (void)reachabilityChanged:(NSNotification *)notification { MGLReachability *reachability = [notification object]; @@ -2895,6 +2896,7 @@ public: continue; } + _isChangingAnnotationLayers = YES; MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([multiPoint annotationObjectWithDelegate:self]); MGLAnnotationContext context; context.annotation = annotation; @@ -2991,6 +2993,10 @@ public: [self updateAnnotationContainerViewWithAnnotationViews:newAnnotationViews]; [self didChangeValueForKey:@"annotations"]; + if (_isChangingAnnotationLayers) + { + [self.style willChangeValueForKey:@"layers"]; + } if ([self.delegate respondsToSelector:@selector(mapView:didAddAnnotationViews:)]) { @@ -3213,11 +3219,16 @@ public: [(NSObject *)annotation removeObserver:self forKeyPath:@"coordinates" context:(void *)(NSUInteger)annotationTag]; } + _isChangingAnnotationLayers = YES; _mbglMap->removeAnnotation(annotationTag); } [self didChangeValueForKey:@"annotations"]; UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); + if (_isChangingAnnotationLayers) + { + [self.style willChangeValueForKey:@"layers"]; + } } - (void)addOverlay:(id )overlay @@ -4559,6 +4570,10 @@ public: } case mbgl::MapChangeDidFinishLoadingMap: { + [self.style willChangeValueForKey:@"sources"]; + [self.style didChangeValueForKey:@"sources"]; + [self.style willChangeValueForKey:@"layers"]; + [self.style didChangeValueForKey:@"layers"]; if ([self.delegate respondsToSelector:@selector(mapViewDidFinishLoadingMap:)]) { [self.delegate mapViewDidFinishLoadingMap:self]; @@ -4602,6 +4617,11 @@ public: case mbgl::MapChangeDidFinishRenderingFrame: case mbgl::MapChangeDidFinishRenderingFrameFullyRendered: { + if (_isChangingAnnotationLayers) + { + _isChangingAnnotationLayers = NO; + [self.style didChangeValueForKey:@"layers"]; + } [self updateAnnotationViews]; if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { @@ -4611,6 +4631,11 @@ public: } case mbgl::MapChangeDidFinishLoadingStyle: { + [self.style willChangeValueForKey:@"name"]; + [self.style willChangeValueForKey:@"sources"]; + [self.style didChangeValueForKey:@"sources"]; + [self.style willChangeValueForKey:@"layers"]; + [self.style didChangeValueForKey:@"layers"]; if ([self.delegate respondsToSelector:@selector(mapView:didFinishLoadingStyle:)]) { [self.delegate mapView:self didFinishLoadingStyle:self.style]; diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 3dbbbe3d8..5ffc04e65 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -88,6 +88,14 @@ IB_DESIGNABLE #pragma mark Configuring the Map’s Appearance +/** + The style currently displayed in the receiver. + + Unlike the `styleURL` property, this property is set to an object that allows + you to manipulate every aspect of the style locally. + */ +@property (nonatomic, readonly) MGLStyle *style; + /** URL of the style currently displayed in the receiver. @@ -97,6 +105,9 @@ IB_DESIGNABLE If you set this property to `nil`, the receiver will use the default style and this property will automatically be set to that style’s URL. + + If you want to modify the current style without replacing it outright, or if + you want to introspect individual style attributes, use the `style` property. */ @property (nonatomic, null_resettable) NSURL *styleURL; @@ -926,10 +937,6 @@ IB_DESIGNABLE */ @property (nonatomic) MGLMapDebugMaskOptions debugMask; -#pragma mark Runtime styling API - -- (MGLStyle *)style; - @end NS_ASSUME_NONNULL_END diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index c50d3d564..50b77bc81 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -152,6 +152,8 @@ public: @property (nonatomic, readwrite) NSImageView *logoView; @property (nonatomic, readwrite) NSView *attributionView; +@property (nonatomic, readwrite) MGLStyle *style; + /// Mapping from reusable identifiers to annotation images. @property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImagesByIdentifier; /// Currently shown popover representing the selected annotation. @@ -186,6 +188,8 @@ public: BOOL _wantsToolTipRects; /// True if any annotation images that have custom cursors have been installed. BOOL _wantsCursorRects; + /// True if a willChange notification has been issued for shape annotation layers and a didChange notification is pending. + BOOL _isChangingAnnotationLayers; // Cached checks for delegate method implementations that may be called from // MGLMultiPointDelegate methods. @@ -576,7 +580,7 @@ public: if (_isTargetingInterfaceBuilder) { return; } - + // Default to Streets. if (!styleURL) { // An access token is required to load any default style, including @@ -588,7 +592,10 @@ public: } styleURL = styleURL.mgl_URLByStandardizingScheme; + [self willChangeValueForKey:@"style"]; + _style = [[MGLStyle alloc] initWithMapView:self]; _mbglMap->setStyleURL(styleURL.absoluteString.UTF8String); + [self didChangeValueForKey:@"style"]; } - (IBAction)reloadStyle:(__unused id)sender { @@ -849,6 +856,10 @@ public: } case mbgl::MapChangeDidFinishLoadingMap: { + [self.style willChangeValueForKey:@"sources"]; + [self.style didChangeValueForKey:@"sources"]; + [self.style willChangeValueForKey:@"layers"]; + [self.style didChangeValueForKey:@"layers"]; if ([self.delegate respondsToSelector:@selector(mapViewDidFinishLoadingMap:)]) { [self.delegate mapViewDidFinishLoadingMap:self]; } @@ -888,6 +899,10 @@ public: case mbgl::MapChangeDidFinishRenderingFrame: case mbgl::MapChangeDidFinishRenderingFrameFullyRendered: { + if (_isChangingAnnotationLayers) { + _isChangingAnnotationLayers = NO; + [self.style didChangeValueForKey:@"layers"]; + } if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { BOOL fullyRendered = change == mbgl::MapChangeDidFinishRenderingFrameFullyRendered; [self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:fullyRendered]; @@ -896,6 +911,11 @@ public: } case mbgl::MapChangeDidFinishLoadingStyle: { + [self.style willChangeValueForKey:@"name"]; + [self.style willChangeValueForKey:@"sources"]; + [self.style didChangeValueForKey:@"sources"]; + [self.style willChangeValueForKey:@"layers"]; + [self.style didChangeValueForKey:@"layers"]; if ([self.delegate respondsToSelector:@selector(mapView:didFinishLoadingStyle:)]) { [self.delegate mapView:self didFinishLoadingStyle:self.style]; @@ -1705,6 +1725,7 @@ public: continue; } + _isChangingAnnotationLayers = YES; MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([multiPoint annotationObjectWithDelegate:self]); MGLAnnotationContext context; context.annotation = annotation; @@ -1762,6 +1783,9 @@ public: } [self didChangeValueForKey:@"annotations"]; + if (_isChangingAnnotationLayers) { + [self.style willChangeValueForKey:@"layers"]; + } [self updateAnnotationTrackingAreas]; } @@ -1843,10 +1867,14 @@ public: [(NSObject *)annotation removeObserver:self forKeyPath:@"coordinates" context:(void *)(NSUInteger)annotationTag]; } + _isChangingAnnotationLayers = YES; _mbglMap->removeAnnotation(annotationTag); } [self didChangeValueForKey:@"annotations"]; + if (_isChangingAnnotationLayers) { + [self.style willChangeValueForKey:@"layers"]; + } [self updateAnnotationTrackingAreas]; } @@ -2200,13 +2228,6 @@ public: #pragma mark - Runtime styling -- (MGLStyle *)style -{ - MGLStyle *style = [[MGLStyle alloc] init]; - style.mapView = self; - return style; -} - - (mbgl::Map *)mbglMap { return _mbglMap; From 03a2dbe3615cd525d091e49f640f960fa2b28a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 23 Nov 2016 12:03:34 -0800 Subject: [PATCH 45/67] [macos] Avoid first responder action name conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed a crash that often occurred when switching styles. MGLMapView was ahead of MapDocument in the responder chain, so calls to -setStyle: were going to MGLMapView’s private -setStyle: method. The sender was being passed in the first parameter instead of an MGLStyle method. --- platform/macos/app/Base.lproj/MainMenu.xib | 12 ++++++------ platform/macos/app/Base.lproj/MapDocument.xib | 2 +- platform/macos/app/MapDocument.h | 2 +- platform/macos/app/MapDocument.m | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 716872a32..7dd4d0843 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -366,32 +366,32 @@ - + - + - + - + - + - + diff --git a/platform/macos/app/Base.lproj/MapDocument.xib b/platform/macos/app/Base.lproj/MapDocument.xib index 2fb02f9c4..4e58490e6 100644 --- a/platform/macos/app/Base.lproj/MapDocument.xib +++ b/platform/macos/app/Base.lproj/MapDocument.xib @@ -86,7 +86,7 @@ - + diff --git a/platform/macos/app/MapDocument.h b/platform/macos/app/MapDocument.h index 86ad05e6e..fa70212cf 100644 --- a/platform/macos/app/MapDocument.h +++ b/platform/macos/app/MapDocument.h @@ -6,7 +6,7 @@ @property (weak) IBOutlet MGLMapView *mapView; -- (IBAction)setStyle:(id)sender; +- (IBAction)showStyle:(id)sender; - (IBAction)chooseCustomStyle:(id)sender; - (IBAction)reload:(id)sender; diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index e4fe202f3..f9477206a 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -143,7 +143,7 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id Date: Sun, 21 Aug 2016 13:01:09 -0700 Subject: [PATCH 46/67] [macos] Added Layers sidebar Added a sidebar to the main document window in macosapp that lists the layers in the current style and updates whenever the style changes or a layer is added or removed programmatically. Display an icon beside each layer in the sidebar that indicates the kind of layer. Double-click a layer or layers to toggle their visibility, which is an undoable action. Added a menu item and toolbar button to toggle the Layers sidebar. Added a context menu for toggling visibility of and deleting layers selected in the Layers sidebar. Checked in the original SVGs for layer icons. --- .../app/Assets.xcassets/Layers/Contents.json | 6 + .../Layers/background.imageset/Contents.json | 15 ++ .../Layers/background.imageset/background.pdf | 69 +++++++ .../Layers/circle.imageset/Contents.json | 15 ++ .../Layers/circle.imageset/circle.pdf | 70 +++++++ .../Layers/fill.imageset/Contents.json | 15 ++ .../Layers/fill.imageset/fill.pdf | Bin 0 -> 1046 bytes .../Layers/symbol.imageset/Contents.json | 15 ++ .../Layers/symbol.imageset/symbol.pdf | 71 +++++++ platform/macos/app/Base.lproj/MainMenu.xib | 5 + platform/macos/app/Base.lproj/MapDocument.xib | 185 ++++++++++++++++-- platform/macos/app/MapDocument.m | 150 +++++++++++++- .../macos/app/StyleLayerIconTransformer.h | 5 + .../macos/app/StyleLayerIconTransformer.m | 38 ++++ platform/macos/app/resources/background.svg | 90 +++++++++ platform/macos/app/resources/circle.svg | 67 +++++++ platform/macos/app/resources/fill.svg | 68 +++++++ platform/macos/app/resources/symbol.svg | 66 +++++++ .../macos/macos.xcodeproj/project.pbxproj | 6 + 19 files changed, 940 insertions(+), 16 deletions(-) create mode 100644 platform/macos/app/Assets.xcassets/Layers/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Layers/background.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Layers/background.imageset/background.pdf create mode 100644 platform/macos/app/Assets.xcassets/Layers/circle.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Layers/circle.imageset/circle.pdf create mode 100644 platform/macos/app/Assets.xcassets/Layers/fill.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Layers/fill.imageset/fill.pdf create mode 100644 platform/macos/app/Assets.xcassets/Layers/symbol.imageset/Contents.json create mode 100644 platform/macos/app/Assets.xcassets/Layers/symbol.imageset/symbol.pdf create mode 100644 platform/macos/app/StyleLayerIconTransformer.h create mode 100644 platform/macos/app/StyleLayerIconTransformer.m create mode 100644 platform/macos/app/resources/background.svg create mode 100644 platform/macos/app/resources/circle.svg create mode 100644 platform/macos/app/resources/fill.svg create mode 100644 platform/macos/app/resources/symbol.svg diff --git a/platform/macos/app/Assets.xcassets/Layers/Contents.json b/platform/macos/app/Assets.xcassets/Layers/Contents.json new file mode 100644 index 000000000..da4a164c9 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Layers/background.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Layers/background.imageset/Contents.json new file mode 100644 index 000000000..3d2c87887 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/background.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "background.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Layers/background.imageset/background.pdf b/platform/macos/app/Assets.xcassets/Layers/background.imageset/background.pdf new file mode 100644 index 000000000..95a50c144 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/background.imageset/background.pdf @@ -0,0 +1,69 @@ +%PDF-1.5 +%µí®û +3 0 obj +<< /Length 4 0 R + /Filter /FlateDecode +>> +stream +xœ}’Mjä@ …÷u +] š*Iõ£ ²H²f1x Ü‹�E®?OÕ¶» ChÚÖgÕ“T’>R¦ø½ü¤2½}¦Ìƒ¾ðõÿ÷ôë7eÎô7=Ñ•yø!^Epp¹$aŽCÏ «QeíÏQŽav²�ç¶ÑJ$”Œ‡6r–ÁåÎ\ú+•Â6"¨”uTÓÍw…tÈ‚›Ü„•³Cpo»ðz¥çôßÛ>(«�ò@˜ \QÖ@¸©Xx¼êÉ^‚¼o´ú娷6ÇÇf5ÂÙ8ÙKP³�Öè::�Û¨±ëî™v:DmæØEÎæQuÜ/³zÙ\'øæ²ÂÞ;*U æ‚2.‹Þ»2Uõp!ν5D>Ðè¨!²§éPäVà’QNvŒ×kßh�ü¥K¨:†W”E¯¾t1^�9du.!ÔY •Æ c¹:OðÝxñ®>„ò1`,iÛìDææÓi(ý1ä^mÇcÆÀ 3Ìʸ`Ã#(vçK ”Wt/ÞÐ�"³¥5íÎI7ag+vúܧXð1£ïsÖƒÒ!�ë?§°Ä8 +endstream +endobj +4 0 obj + 424 +endobj +2 0 obj +<< + /ExtGState << + /a0 << /CA 1 /ca 1 >> + >> +>> +endobj +5 0 obj +<< /Type /Page + /Parent 1 0 R + /MediaBox [ 0 0 12.8 12.8 ] + /Contents 3 0 R + /Group << + /Type /Group + /S /Transparency + /I true + /CS /DeviceRGB + >> + /Resources 2 0 R +>> +endobj +1 0 obj +<< /Type /Pages + /Kids [ 5 0 R ] + /Count 1 +>> +endobj +6 0 obj +<< /Creator (cairo 1.14.0 (http://cairographics.org)) + /Producer (cairo 1.14.0 (http://cairographics.org)) +>> +endobj +7 0 obj +<< /Type /Catalog + /Pages 1 0 R +>> +endobj +xref +0 8 +0000000000 65535 f +0000000826 00000 n +0000000538 00000 n +0000000015 00000 n +0000000516 00000 n +0000000610 00000 n +0000000891 00000 n +0000001018 00000 n +trailer +<< /Size 8 + /Root 7 0 R + /Info 6 0 R +>> +startxref +1070 +%%EOF diff --git a/platform/macos/app/Assets.xcassets/Layers/circle.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Layers/circle.imageset/Contents.json new file mode 100644 index 000000000..c924214fd --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/circle.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "circle.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Layers/circle.imageset/circle.pdf b/platform/macos/app/Assets.xcassets/Layers/circle.imageset/circle.pdf new file mode 100644 index 000000000..fde79a19b --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/circle.imageset/circle.pdf @@ -0,0 +1,70 @@ +%PDF-1.5 +%µí®û +3 0 obj +<< /Length 4 0 R + /Filter /FlateDecode +>> +stream +xœ]ŽM +1 …÷9Å»€1�?''£ËaRAf1¸ðú¦Ó X)ÍëGÞKº� �Ëû›àñ¦ÀAõ Š�µNv_4NÜ©Á šØ% ÷ˆ3™Z +×Úc†£r'•×ÂáQ›¶J2’ûWp{tÊî\ûù‹džIå†mÜóÿÃW 4Ðè4J +endstream +endobj +4 0 obj + 139 +endobj +2 0 obj +<< + /ExtGState << + /a0 << /CA 1 /ca 1 >> + >> +>> +endobj +5 0 obj +<< /Type /Page + /Parent 1 0 R + /MediaBox [ 0 0 12.8 12.8 ] + /Contents 3 0 R + /Group << + /Type /Group + /S /Transparency + /I true + /CS /DeviceRGB + >> + /Resources 2 0 R +>> +endobj +1 0 obj +<< /Type /Pages + /Kids [ 5 0 R ] + /Count 1 +>> +endobj +6 0 obj +<< /Creator (cairo 1.14.0 (http://cairographics.org)) + /Producer (cairo 1.14.0 (http://cairographics.org)) +>> +endobj +7 0 obj +<< /Type /Catalog + /Pages 1 0 R +>> +endobj +xref +0 8 +0000000000 65535 f +0000000541 00000 n +0000000253 00000 n +0000000015 00000 n +0000000231 00000 n +0000000325 00000 n +0000000606 00000 n +0000000733 00000 n +trailer +<< /Size 8 + /Root 7 0 R + /Info 6 0 R +>> +startxref +785 +%%EOF diff --git a/platform/macos/app/Assets.xcassets/Layers/fill.imageset/Contents.json b/platform/macos/app/Assets.xcassets/Layers/fill.imageset/Contents.json new file mode 100644 index 000000000..ea68330e7 --- /dev/null +++ b/platform/macos/app/Assets.xcassets/Layers/fill.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "fill.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/platform/macos/app/Assets.xcassets/Layers/fill.imageset/fill.pdf b/platform/macos/app/Assets.xcassets/Layers/fill.imageset/fill.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ca7e4cc505c09a5877c4827bb00ff7fe58f21d18 GIT binary patch literal 1046 zcma)6&ubGw6fOx1Wx=3S@#vEhNKyAkl1)-c3TD%UQpJ#X5G3eiGfB3@oiIC*)T0pa z=%GhX9z=>1FCKdIUyurVl^*oqrFav;H@n#+G#7_ucjuco^L^iYZ#P-5RBxG@r6xcA zI{Kq#zyQ|XQ;S8=?^3TP`jADap#p$jbq9iSd=7}973#1KRkyZOUvNsEs^ix;PSf?3 zPj7_sw-TTHZfo&UbIn)m_0oFNQEa>9#~r1WY8@QDdaHc7becFJtDnic-V@jBx8K(j z2WPSGH;;ZiRN|%h!e2m_B!Fz6JX8~dyjTpQf6a#gpdJdS}TON zRuFG9Pv8b0WOc$))HoXr7sQ7Q0UD`nA}=SNKa_0FegyA;;G;l?G;L#4g+6l~+NhOf zNa#dwP@j#sLw%5$Yb^MZs-q5>`|<;!yKcuv57K%ABJCq-b>V>A!T~mRj$j;84skgH zQ!}%g0ja(a!`nJ$AHg0c!@leI8soi> +stream +xœ]ŽA +Â@ E÷9Å¿€q’IgÒ‚‹êR\ÈŠÐEqáõíØqQ !ÿ…üð' +¨uÜa{ ¸¿HXRLQñ&Á~î'�/p#ÃäëØÔ!ÊŽ2’6ëaìæÑ0s—‰cïõR¥_CY£r씪KÝþ•FÊ–ó¼·9Oç¿×‹.pN’- ¨yVñ +ÿyOh ¢4 +endstream +endobj +4 0 obj + 152 +endobj +2 0 obj +<< + /ExtGState << + /a0 << /CA 1 /ca 1 >> + >> +>> +endobj +5 0 obj +<< /Type /Page + /Parent 1 0 R + /MediaBox [ 0 0 12.8 12.8 ] + /Contents 3 0 R + /Group << + /Type /Group + /S /Transparency + /I true + /CS /DeviceRGB + >> + /Resources 2 0 R +>> +endobj +1 0 obj +<< /Type /Pages + /Kids [ 5 0 R ] + /Count 1 +>> +endobj +6 0 obj +<< /Creator (cairo 1.14.0 (http://cairographics.org)) + /Producer (cairo 1.14.0 (http://cairographics.org)) +>> +endobj +7 0 obj +<< /Type /Catalog + /Pages 1 0 R +>> +endobj +xref +0 8 +0000000000 65535 f +0000000554 00000 n +0000000266 00000 n +0000000015 00000 n +0000000244 00000 n +0000000338 00000 n +0000000619 00000 n +0000000746 00000 n +trailer +<< /Size 8 + /Root 7 0 R + /Info 6 0 R +>> +startxref +798 +%%EOF diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 7dd4d0843..4efb8d4c4 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -429,6 +429,11 @@ + + + + + diff --git a/platform/macos/app/Base.lproj/MapDocument.xib b/platform/macos/app/Base.lproj/MapDocument.xib index 4e58490e6..9af40d461 100644 --- a/platform/macos/app/Base.lproj/MapDocument.xib +++ b/platform/macos/app/Base.lproj/MapDocument.xib @@ -1,40 +1,160 @@ - + - + + + + + + + style + + + + + + + + layers + + + + + + + + identifier + visible + + + + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + StyleLayerIconTransformer + + + + + + + + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - + - - - - + + + + @@ -89,8 +209,25 @@ + + + + + + + + + + @@ -135,8 +272,30 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index f9477206a..e312eccca 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -46,9 +46,12 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id +@interface MapDocument () +@property (weak) IBOutlet NSArrayController *styleLayersArrayController; +@property (weak) IBOutlet NSTableView *styleLayersTableView; @property (weak) IBOutlet NSMenu *mapViewContextMenu; +@property (weak) IBOutlet NSSplitView *splitView; @end @@ -98,6 +101,8 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id = 0 && ![indices containsIndex:clickedRow]) { + indices = [NSIndexSet indexSetWithIndex:clickedRow]; + } + [self toggleStyleLayersAtArrangedObjectIndexes:indices]; +} + +- (void)toggleStyleLayersAtArrangedObjectIndexes:(NSIndexSet *)indices { + NS_ARRAY_OF(MGLStyleLayer *) *layers = [self.mapView.style.layers objectsAtIndexes:indices]; + BOOL isVisible = layers.firstObject.visible; + [self.undoManager registerUndoWithTarget:self handler:^(MapDocument * _Nonnull target) { + [target toggleStyleLayersAtArrangedObjectIndexes:indices]; + }]; + + if (!self.undoManager.undoing) { + NSString *actionName; + if (indices.count == 1) { + actionName = [NSString stringWithFormat:@"%@ Layer “%@â€�", isVisible ? @"Hide" : @"Show", layers.firstObject.identifier]; + } else { + actionName = [NSString stringWithFormat:@"%@ %@ Layers", isVisible ? @"Hide" : @"Show", + [NSNumberFormatter localizedStringFromNumber:@(indices.count) + numberStyle:NSNumberFormatterDecimalStyle]]; + } + [self.undoManager setActionIsDiscardable:YES]; + [self.undoManager setActionName:actionName]; + } + + for (MGLStyleLayer *layer in layers) { + layer.visible = !isVisible; + } + + NSIndexSet *columnIndices = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]; + [self.styleLayersTableView reloadDataForRowIndexes:indices columnIndexes:columnIndices]; +} + +- (IBAction)deleteStyleLayers:(id)sender { + NSInteger clickedRow = self.styleLayersTableView.clickedRow; + NSIndexSet *indices = self.styleLayersTableView.selectedRowIndexes; + if (clickedRow >= 0 && ![indices containsIndex:clickedRow]) { + indices = [NSIndexSet indexSetWithIndex:clickedRow]; + } + [self deleteStyleLayersAtArrangedObjectIndexes:indices]; +} + +- (void)insertStyleLayers:(NS_ARRAY_OF(MGLStyleLayer *) *)layers atArrangedObjectIndexes:(NSIndexSet *)indices { + [self.undoManager registerUndoWithTarget:self handler:^(id _Nonnull target) { + [self deleteStyleLayersAtArrangedObjectIndexes:indices]; + }]; + + if (!self.undoManager.undoing) { + NSString *actionName; + if (indices.count == 1) { + actionName = [NSString stringWithFormat:@"Add Layer “%@â€�", layers.firstObject.identifier]; + } else { + actionName = [NSString stringWithFormat:@"Add %@ Layers", + [NSNumberFormatter localizedStringFromNumber:@(indices.count) numberStyle:NSNumberFormatterDecimalStyle]]; + } + [self.undoManager setActionName:actionName]; + } + + [self.styleLayersArrayController insertObjects:layers atArrangedObjectIndexes:indices]; +} + +- (void)deleteStyleLayersAtArrangedObjectIndexes:(NSIndexSet *)indices { + NS_ARRAY_OF(MGLStyleLayer *) *layers = [self.mapView.style.layers objectsAtIndexes:indices]; + [self.undoManager registerUndoWithTarget:self handler:^(id _Nonnull target) { + [self insertStyleLayers:layers atArrangedObjectIndexes:indices]; + }]; + + if (!self.undoManager.undoing) { + NSString *actionName; + if (indices.count == 1) { + actionName = [NSString stringWithFormat:@"Delete Layer “%@â€�", layers.firstObject.identifier]; + } else { + actionName = [NSString stringWithFormat:@"Delete %@ Layers", + [NSNumberFormatter localizedStringFromNumber:@(indices.count) numberStyle:NSNumberFormatterDecimalStyle]]; + } + [self.undoManager setActionName:actionName]; + } + + [self.styleLayersArrayController removeObjectsAtArrangedObjectIndexes:indices]; +} + - (void)applyPendingState { if (_inheritedStyleURL) { self.mapView.styleURL = _inheritedStyleURL; @@ -607,6 +715,27 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id = 0 || self.styleLayersTableView.selectedRow >= 0; + } if (menuItem.action == @selector(manipulateStyle:)) { return YES; } @@ -722,7 +851,8 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id )annotation { diff --git a/platform/macos/app/StyleLayerIconTransformer.h b/platform/macos/app/StyleLayerIconTransformer.h new file mode 100644 index 000000000..1af1d512d --- /dev/null +++ b/platform/macos/app/StyleLayerIconTransformer.h @@ -0,0 +1,5 @@ +#import + +@interface StyleLayerIconTransformer : NSValueTransformer + +@end diff --git a/platform/macos/app/StyleLayerIconTransformer.m b/platform/macos/app/StyleLayerIconTransformer.m new file mode 100644 index 000000000..93f59abb3 --- /dev/null +++ b/platform/macos/app/StyleLayerIconTransformer.m @@ -0,0 +1,38 @@ +#import "StyleLayerIconTransformer.h" + +#import + +@implementation StyleLayerIconTransformer + ++ (Class)transformedValueClass { + return [NSString class]; +} + ++ (BOOL)allowsReverseTransformation { + return NO; +} + +- (id)transformedValue:(MGLStyleLayer *)layer { + if ([layer isKindOfClass:[MGLBackgroundStyleLayer class]]) { + return [NSImage imageNamed:@"background"]; + } + if ([layer isKindOfClass:[MGLCircleStyleLayer class]]) { + return [NSImage imageNamed:@"circle"]; + } + if ([layer isKindOfClass:[MGLFillStyleLayer class]]) { + return [NSImage imageNamed:@"fill"]; + } + if ([layer isKindOfClass:[MGLLineStyleLayer class]]) { + return [NSImage imageNamed:@"NSListViewTemplate"]; + } + if ([layer isKindOfClass:[MGLRasterStyleLayer class]]) { + return [[NSWorkspace sharedWorkspace] iconForFileType:@"jpg"]; + } + if ([layer isKindOfClass:[MGLSymbolStyleLayer class]]) { + return [NSImage imageNamed:@"symbol"]; + } + + return nil; +} + +@end diff --git a/platform/macos/app/resources/background.svg b/platform/macos/app/resources/background.svg new file mode 100644 index 000000000..39451e8b1 --- /dev/null +++ b/platform/macos/app/resources/background.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/platform/macos/app/resources/circle.svg b/platform/macos/app/resources/circle.svg new file mode 100644 index 000000000..91e0b1199 --- /dev/null +++ b/platform/macos/app/resources/circle.svg @@ -0,0 +1,67 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/platform/macos/app/resources/fill.svg b/platform/macos/app/resources/fill.svg new file mode 100644 index 000000000..7860a5fdd --- /dev/null +++ b/platform/macos/app/resources/fill.svg @@ -0,0 +1,68 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/platform/macos/app/resources/symbol.svg b/platform/macos/app/resources/symbol.svg new file mode 100644 index 000000000..68847cb50 --- /dev/null +++ b/platform/macos/app/resources/symbol.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 3ab9d4d9c..0c28691cb 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -115,6 +115,7 @@ DA8F259C1D51CB000010E6B5 /* MGLStyleValue_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8F259B1D51CB000010E6B5 /* MGLStyleValue_Private.h */; }; DA8F25B21D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8F25A61D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.h */; }; DA8F25B31D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA8F25A71D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.mm */; }; + DAA48EFD1D6A4731006A7E36 /* StyleLayerIconTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = DAA48EFC1D6A4731006A7E36 /* StyleLayerIconTransformer.m */; }; DAC2ABC51CC6D343006D18C4 /* MGLAnnotationImage_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */; }; DACC22141CF3D3E200D220D9 /* MGLFeature.h in Headers */ = {isa = PBXBuildFile; fileRef = DACC22121CF3D3E200D220D9 /* MGLFeature.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACC22151CF3D3E200D220D9 /* MGLFeature.mm in Sources */ = {isa = PBXBuildFile; fileRef = DACC22131CF3D3E200D220D9 /* MGLFeature.mm */; }; @@ -356,6 +357,8 @@ DA8F25B51D51D2240010E6B5 /* MGLRuntimeStylingTests.m.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLRuntimeStylingTests.m.ejs; sourceTree = ""; }; DA8F25B61D51D2240010E6B5 /* MGLStyleLayer.h.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLStyleLayer.h.ejs; sourceTree = ""; }; DA8F25B71D51D2240010E6B5 /* MGLStyleLayer.mm.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLStyleLayer.mm.ejs; sourceTree = ""; }; + DAA48EFB1D6A4731006A7E36 /* StyleLayerIconTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleLayerIconTransformer.h; sourceTree = ""; }; + DAA48EFC1D6A4731006A7E36 /* StyleLayerIconTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StyleLayerIconTransformer.m; sourceTree = ""; }; DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationImage_Private.h; sourceTree = ""; }; DACC22121CF3D3E200D220D9 /* MGLFeature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature.h; sourceTree = ""; }; DACC22131CF3D3E200D220D9 /* MGLFeature.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFeature.mm; sourceTree = ""; }; @@ -588,6 +591,8 @@ DA839E9E1CC2E3400062CAFB /* MapDocument.xib */, DAE6C2E91CC3050F00DB3429 /* OfflinePackNameValueTransformer.h */, DAE6C2EA1CC3050F00DB3429 /* OfflinePackNameValueTransformer.m */, + DAA48EFB1D6A4731006A7E36 /* StyleLayerIconTransformer.h */, + DAA48EFC1D6A4731006A7E36 /* StyleLayerIconTransformer.m */, DAE6C2EB1CC3050F00DB3429 /* TimeIntervalTransformer.h */, DAE6C2EC1CC3050F00DB3429 /* TimeIntervalTransformer.m */, DA839EA11CC2E3400062CAFB /* Assets.xcassets */, @@ -1156,6 +1161,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DAA48EFD1D6A4731006A7E36 /* StyleLayerIconTransformer.m in Sources */, DA839E9D1CC2E3400062CAFB /* MapDocument.m in Sources */, DAE6C2ED1CC3050F00DB3429 /* DroppedPinAnnotation.m in Sources */, DAE6C2EE1CC3050F00DB3429 /* LocationCoordinate2DTransformer.m in Sources */, From f6113559126b5e5fa90c4f8c31ef589058998def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 25 Nov 2016 17:25:31 -0800 Subject: [PATCH 47/67] [macos] Name custom style in toolbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Display the custom style’s name in the Style toolbar button. --- platform/macos/app/Base.lproj/MapDocument.xib | 1 + platform/macos/app/MapDocument.m | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/macos/app/Base.lproj/MapDocument.xib b/platform/macos/app/Base.lproj/MapDocument.xib index 9af40d461..e147ba83d 100644 --- a/platform/macos/app/Base.lproj/MapDocument.xib +++ b/platform/macos/app/Base.lproj/MapDocument.xib @@ -26,6 +26,7 @@ layers + name diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index e312eccca..c05a85f96 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -865,10 +865,13 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id Date: Tue, 22 Nov 2016 23:40:54 -0800 Subject: [PATCH 48/67] [macos] Added option to localize labels Added a setting to macosapp to change all symbol layers in the current style to use the preferred language if available. If the setting is off, change all symbol layers to use local languages. --- platform/macos/app/Base.lproj/MainMenu.xib | 21 +++++++ platform/macos/app/MapDocument.m | 69 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 4efb8d4c4..cb9905d4a 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -434,6 +434,27 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index c05a85f96..d2e6a0f81 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -64,6 +64,7 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id *)layer.textField rawValue]; + textField = [nameTokenExpression stringByReplacingMatchesInString:textField + options:0 + range:NSMakeRange(0, textField.length) + withTemplate:preferredNameToken]; + layer.textField = [MGLStyleValue valueWithRawValue:textField]; + } else if ([layer.textField isKindOfClass:[MGLStyleFunction class]]) { + MGLStyleFunction *function = (MGLStyleFunction *)layer.textField; + NSMutableDictionary *stops = function.stops.mutableCopy; + [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLStyleConstantValue *stop, BOOL *done) { + NSString *textField = stop.rawValue; + textField = [nameTokenExpression stringByReplacingMatchesInString:textField + options:0 + range:NSMakeRange(0, textField.length) + withTemplate:preferredNameToken]; + stops[zoomLevel] = [MGLStyleValue valueWithRawValue:textField]; + }]; + function.stops = stops; + layer.textField = function; + } + } +} + +- (NSString *)preferredLanguageCode { + // Languages supported by Mapbox Streets v10. + NSSet *supportedLanguages = [NSSet setWithObjects:@"en", @"es", @"fr", @"de", @"ru", @"zh", nil]; + NSArray *preferredLanguages = [NSLocale preferredLanguages]; + + for (NSString *language in preferredLanguages) { + NSString *languageCode = [[NSLocale localeWithLocaleIdentifier:language] objectForKey:NSLocaleLanguageCode]; + if ([supportedLanguages containsObject:languageCode]) { + return languageCode; + } + } + + return @"en"; +} + - (void)applyPendingState { if (_inheritedStyleURL) { self.mapView.styleURL = _inheritedStyleURL; @@ -736,6 +793,14 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id = 0 || self.styleLayersTableView.selectedRow >= 0; } + if (menuItem.action == @selector(setLabelLanguage:)) { + menuItem.state = menuItem.tag == _isLocalizingLabels ? NSOnState: NSOffState; + if (menuItem.tag) { + NSLocale *locale = [NSLocale localeWithLocaleIdentifier:[NSBundle mainBundle].developmentLocalization]; + menuItem.title = [locale displayNameForKey:NSLocaleIdentifier value:self.preferredLanguageCode]; + } + return YES; + } if (menuItem.action == @selector(manipulateStyle:)) { return YES; } @@ -922,6 +987,10 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id )annotation { return YES; } From d830c48e4a6d656284df930a5fda03ba8f1521cc Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 29 Nov 2016 08:56:59 -0800 Subject: [PATCH 49/67] [ios, macos] Refcount view activations (#7208) This adds a ref count to guard against calling activate after it has already been called. This can happen when a layer is added during certain map lifecycle methods like MapChangeWillStartRenderingFrame that also triggers activation. This also protects against issues related to a deactivation of the context happening in an inner scope while an outer scope is still expecting to be able to use the context. --- platform/ios/src/MGLMapView.mm | 12 ++++++++++++ platform/macos/src/MGLMapView.mm | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index b1ecf1c41..e36f0299e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5093,16 +5093,28 @@ public: void activate() override { + if (activationCount++) + { + return; + } + [EAGLContext setCurrentContext:nativeView.context]; } void deactivate() override { + if (--activationCount) + { + return; + } + [EAGLContext setCurrentContext:nil]; } private: __weak MGLMapView *nativeView = nullptr; + + NSUInteger activationCount = 0; }; @end diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 50b77bc81..ba0704826 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -2611,11 +2611,19 @@ public: } void activate() override { + if (activationCount++) { + return; + } + MGLOpenGLLayer *layer = (MGLOpenGLLayer *)nativeView.layer; [layer.openGLContext makeCurrentContext]; } void deactivate() override { + if (--activationCount) { + return; + } + [NSOpenGLContext clearCurrentContext]; } @@ -2661,6 +2669,9 @@ private: /// The current framebuffer of the NSOpenGLLayer we are painting to. GLint fbo = 0; + + /// The reference counted count of activation calls + NSUInteger activationCount = 0; }; @end From 336d48df4852021f4b51a15220d8ab976a79a59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 29 Nov 2016 13:36:55 -0800 Subject: [PATCH 50/67] [ios, macos] Fixed spurious offline storage test failure Even if the expectation is immediately fulfilled, we still have to wait for it to be fulfilled, because the expectation only gets unregistered after waiting. The zombie expectation was fulfilling a stricter expectation in a test method. --- platform/darwin/test/MGLOfflineStorageTests.m | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m index cd13a9262..07540b564 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.m +++ b/platform/darwin/test/MGLOfflineStorageTests.m @@ -19,6 +19,7 @@ }]; if ([MGLOfflineStorage sharedOfflineStorage].packs) { [expectation fulfill]; + [self waitForExpectationsWithTimeout:0 handler:nil]; } else { [self waitForExpectationsWithTimeout:2 handler:nil]; } From 4096544188501c8e6e9220847fff910eb153d42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 28 Nov 2016 21:51:37 -0800 Subject: [PATCH 51/67] [ios, macos] Marked C array parameters as const Fixes #7214. --- platform/darwin/src/MGLMultiPoint.h | 4 ++-- platform/darwin/src/MGLMultiPoint.mm | 6 +++--- platform/darwin/src/MGLMultiPoint_Private.h | 2 +- platform/darwin/src/MGLPointCollection.h | 2 +- platform/darwin/src/MGLPointCollection.mm | 4 ++-- platform/darwin/src/MGLPointCollection_Private.h | 2 +- platform/darwin/src/MGLPolygon.h | 4 ++-- platform/darwin/src/MGLPolygon.mm | 6 +++--- platform/darwin/src/MGLPolyline.h | 2 +- platform/darwin/src/MGLPolyline.mm | 2 +- platform/ios/CHANGELOG.md | 3 ++- platform/ios/src/MGLMapView.h | 4 ++-- platform/ios/src/MGLMapView.mm | 10 +++++----- platform/macos/CHANGELOG.md | 1 + platform/macos/macos.xcodeproj/project.pbxproj | 2 +- 15 files changed, 28 insertions(+), 26 deletions(-) diff --git a/platform/darwin/src/MGLMultiPoint.h b/platform/darwin/src/MGLMultiPoint.h index 5a37e25cc..3431fc248 100644 --- a/platform/darwin/src/MGLMultiPoint.h +++ b/platform/darwin/src/MGLMultiPoint.h @@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN @param coords The array of coordinates defining the shape. The data in this array is copied to the object. */ -- (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(CLLocationCoordinate2D *)coords; +- (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(const CLLocationCoordinate2D *)coords; /** Appends one or more coordinates for the shape, which will instantaneously @@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN array is copied to the new object. @param count The number of items in the `coords` array. */ -- (void)appendCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; +- (void)appendCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; @end diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index 0133e03b3..57b57889f 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -18,7 +18,7 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) std::vector _coordinates; } -- (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count +- (instancetype)initWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { self = [super init]; @@ -65,7 +65,7 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) std::copy(_coordinates.begin() + range.location, _coordinates.begin() + NSMaxRange(range), coords); } -- (void)appendCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count +- (void)appendCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { [self willChangeValueForKey:@"coordinates"]; _coordinates.insert(_coordinates.end(), count, *coords); @@ -73,7 +73,7 @@ mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) [self didChangeValueForKey:@"coordinates"]; } -- (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(CLLocationCoordinate2D *)coords +- (void)replaceCoordinatesInRange:(NSRange)range withCoordinates:(const CLLocationCoordinate2D *)coords { if (range.length == 0) { diff --git a/platform/darwin/src/MGLMultiPoint_Private.h b/platform/darwin/src/MGLMultiPoint_Private.h index 7bc3cae58..a9b4b72ca 100644 --- a/platform/darwin/src/MGLMultiPoint_Private.h +++ b/platform/darwin/src/MGLMultiPoint_Private.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLMultiPoint (Private) -- (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; +- (instancetype)initWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; - (BOOL)intersectsOverlayBounds:(MGLCoordinateBounds)overlayBounds; /** Constructs a shape annotation object, asking the delegate for style values. */ diff --git a/platform/darwin/src/MGLPointCollection.h b/platform/darwin/src/MGLPointCollection.h index db497d0a5..ce3e95a16 100644 --- a/platform/darwin/src/MGLPointCollection.h +++ b/platform/darwin/src/MGLPointCollection.h @@ -26,7 +26,7 @@ @param count The number of items in the `coords` array. @return A new point collection object. */ -+ (instancetype)pointCollectionWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; ++ (instancetype)pointCollectionWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; /** The array of coordinates associated with the shape. */ @property (nonatomic, readonly) CLLocationCoordinate2D *coordinates NS_RETURNS_INNER_POINTER; diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index 8c9d11f42..ab4a9c978 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -12,12 +12,12 @@ NS_ASSUME_NONNULL_BEGIN std::vector _coordinates; } -+ (instancetype)pointCollectionWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count ++ (instancetype)pointCollectionWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { return [[self alloc] initWithCoordinates:coords count:count]; } -- (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count +- (instancetype)initWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { self = [super init]; if (self) diff --git a/platform/darwin/src/MGLPointCollection_Private.h b/platform/darwin/src/MGLPointCollection_Private.h index 039c1f18b..fc1c33fe4 100644 --- a/platform/darwin/src/MGLPointCollection_Private.h +++ b/platform/darwin/src/MGLPointCollection_Private.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLPointCollection (Private) -- (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; +- (instancetype)initWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; @end diff --git a/platform/darwin/src/MGLPolygon.h b/platform/darwin/src/MGLPolygon.h index 3d5b36abb..b9ec6b839 100644 --- a/platform/darwin/src/MGLPolygon.h +++ b/platform/darwin/src/MGLPolygon.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN @param count The number of items in the `coords` array. @return A new polygon object. */ -+ (instancetype)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; ++ (instancetype)polygonWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; /** Creates and returns an `MGLPolygon` object from the specified set of @@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN is considered to have no interior polygons. @return A new polygon object. */ -+ (instancetype)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(nullable NS_ARRAY_OF(MGLPolygon *) *)interiorPolygons; ++ (instancetype)polygonWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(nullable NS_ARRAY_OF(MGLPolygon *) *)interiorPolygons; @end diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm index eae2cfe75..7562db6e6 100644 --- a/platform/darwin/src/MGLPolygon.mm +++ b/platform/darwin/src/MGLPolygon.mm @@ -9,15 +9,15 @@ @dynamic overlayBounds; -+ (instancetype)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count { ++ (instancetype)polygonWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { return [self polygonWithCoordinates:coords count:count interiorPolygons:nil]; } -+ (instancetype)polygonWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons { ++ (instancetype)polygonWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons { return [[self alloc] initWithCoordinates:coords count:count interiorPolygons:interiorPolygons]; } -- (instancetype)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons { +- (instancetype)initWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count interiorPolygons:(NSArray *)interiorPolygons { if (self = [super initWithCoordinates:coords count:count]) { if (interiorPolygons.count) { _interiorPolygons = interiorPolygons; diff --git a/platform/darwin/src/MGLPolyline.h b/platform/darwin/src/MGLPolyline.h index d0274b44e..cb98df9a1 100644 --- a/platform/darwin/src/MGLPolyline.h +++ b/platform/darwin/src/MGLPolyline.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @param count The number of items in the `coords` array. @return A new polyline object. */ -+ (instancetype)polylineWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count; ++ (instancetype)polylineWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count; @end diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm index dd2fccf53..1801dfd44 100644 --- a/platform/darwin/src/MGLPolyline.mm +++ b/platform/darwin/src/MGLPolyline.mm @@ -9,7 +9,7 @@ @dynamic overlayBounds; -+ (instancetype)polylineWithCoordinates:(CLLocationCoordinate2D *)coords ++ (instancetype)polylineWithCoordinates:(const CLLocationCoordinate2D *)coords count:(NSUInteger)count { return [[self alloc] initWithCoordinates:coords count:count]; diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 8124fb3ac..b395fa6bb 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -49,7 +49,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Annotations * Added new methods to MGLMultiPoint for changing or appending vertices along polyline annotations and the exteriors of polygon annotations. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) -* Added new APIs to MGLMapView to query for visible annotations. Combined with `-[MGLMapView viewForAnnotation:]`, these APIs can be used to access all visible annotation views. ([6061](https://github.com/mapbox/mapbox-gl-native/pull/6061)) +* Added new APIs to MGLMapView to query for visible annotations. Combined with `-[MGLMapView viewForAnnotation:]`, these APIs can be used to access all visible annotation views. ([6061](https://github.com/mapbox/mapbox-gl-native/pull/6061)) * Fixed an issue causing offscreen annotation views to be updated even when they were in the reuse queue. ([#5987](https://github.com/mapbox/mapbox-gl-native/pull/5987)) * Fixed an issue preventing MGLAnnotationView from animating when its coordinate changes. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215)) * Fixed an issue causing the wrong annotation view to be selected when tapping an annotation view with a center offset applied. ([#5931](https://github.com/mapbox/mapbox-gl-native/pull/5931)) @@ -57,6 +57,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Per documentation, the first and last coordinates in an MGLPolygon must be identical in order for the polygon to draw correctly. The same is true for an MGLPolygon’s interior polygon. ([#5514](https://github.com/mapbox/mapbox-gl-native/pull/5514)) * To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088)) * Deprecated `-[MGLMapViewDelegate mapView:alphaForShapeAnnotation:]` in favor of specifying an alpha component via `-[MGLMapViewDelegate mapView:strokeColorForShapeAnnotation:]` or `-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]`. ([#6706](https://github.com/mapbox/mapbox-gl-native/pull/6706)) +* Various method arguments that are represented as C arrays of `CLLocationCoordinate2D` instances have been marked `const` to streamline bridging to Swift. ([#7215](https://github.com/mapbox/mapbox-gl-native/pull/7215)) * Fixed an issue that caused an annotation view to disappear if it isn’t created using the annotation view reuse queue. ([#6485](https://github.com/mapbox/mapbox-gl-native/pull/6485)) * Fixed an issue that could reset user-added transformations on annotation views. ([#6166](https://github.com/mapbox/mapbox-gl-native/pull/6166)) * Improved the performance of relocating a non-view-backed point annotation by changing its `coordinate` property. ([#5385](https://github.com/mapbox/mapbox-gl-native/pull/5385)) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index e066387e2..40d6519ac 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -601,7 +601,7 @@ IB_DESIGNABLE @param animated Specify `YES` to animate the change by smoothly scrolling and zooming or `NO` to immediately display the given bounds. */ -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated; +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated; /** Changes the receiver’s viewport to fit all of the given coordinates and @@ -618,7 +618,7 @@ IB_DESIGNABLE @param function The timing function to animate the change. @param completion The block executed after the animation finishes. */ -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; /** Sets the visible region so that the map displays the specified annotations. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e36f0299e..68a1196fa 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2352,27 +2352,27 @@ public: animated:animated]; } -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated { [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:self.direction animated:animated]; } -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction animated:(BOOL)animated +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction animated:(BOOL)animated { [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil]; } -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function { +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function { [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:direction duration:duration animationTimingFunction:function completionHandler:NULL]; } -- (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion +- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { self.userTrackingMode = MGLUserTrackingModeNone; [self _setVisibleCoordinates:coordinates count:count edgePadding:insets direction:direction duration:duration animationTimingFunction:function completionHandler:completion]; } -- (void)_setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion +- (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions(); diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 047ff9518..9675ec844 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -35,6 +35,7 @@ * Added new methods to MGLMultiPoint for changing or appending vertices along polyline annotations and the exteriors of polygon annotations. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) * Added new APIs to MGLMapView to query for visible annotations. ([6061](https://github.com/mapbox/mapbox-gl-native/pull/6061)) * Deprecated `-[MGLMapViewDelegate mapView:alphaForShapeAnnotation:]` in favor of specifying an alpha component via `-[MGLMapViewDelegate mapView:strokeColorForShapeAnnotation:]` or `-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]`. ([#6706](https://github.com/mapbox/mapbox-gl-native/pull/6706)) +* Various method arguments that are represented as C arrays of `CLLocationCoordinate2D` instances have been marked `const` to streamline bridging to Swift. ([#7215](https://github.com/mapbox/mapbox-gl-native/pull/7215)) * To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088)) * Fixed an issue where placing a point annotation on Null Island also placed a duplicate annotation on its antipode. ([#3563](https://github.com/mapbox/mapbox-gl-native/pull/3563)) * Improved the precision of annotations at zoom levels greater than 18. ([#5517](https://github.com/mapbox/mapbox-gl-native/pull/5517)) diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 0c28691cb..0a74d25d4 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -723,8 +723,8 @@ DAE6C36C1CC31E2A00DB3429 /* MGLGeometry_Private.h */, DAE6C34C1CC31E0400DB3429 /* MGLGeometry.h */, DAE6C36D1CC31E2A00DB3429 /* MGLGeometry.mm */, - DAE6C36F1CC31E2A00DB3429 /* MGLMultiPoint_Private.h */, DAE6C34E1CC31E0400DB3429 /* MGLMultiPoint.h */, + DAE6C36F1CC31E2A00DB3429 /* MGLMultiPoint_Private.h */, DAE6C3701CC31E2A00DB3429 /* MGLMultiPoint.mm */, DAE6C3521CC31E0400DB3429 /* MGLOverlay.h */, DAE6C3531CC31E0400DB3429 /* MGLPointAnnotation.h */, From 17db5210bf60171ee7dbc15de77fdea53b8f0d4d Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 21 Nov 2016 14:32:05 +0100 Subject: [PATCH 52/67] [ios, macos] rename style spec properties --- .../darwin/scripts/generate-style-code.js | 21 +- .../style-spec-cocoa-conventions-v8.json | 9 + platform/darwin/src/MGLBackgroundStyleLayer.h | 10 +- .../darwin/src/MGLBackgroundStyleLayer.mm | 20 +- platform/darwin/src/MGLCircleStyleLayer.h | 70 +-- platform/darwin/src/MGLCircleStyleLayer.mm | 60 +-- platform/darwin/src/MGLFillStyleLayer.h | 24 +- platform/darwin/src/MGLFillStyleLayer.mm | 40 +- platform/darwin/src/MGLLineStyleLayer.h | 88 ++-- platform/darwin/src/MGLLineStyleLayer.mm | 110 ++--- platform/darwin/src/MGLRasterStyleLayer.h | 52 +- platform/darwin/src/MGLRasterStyleLayer.mm | 76 +-- platform/darwin/src/MGLStyleLayer.mm.ejs | 28 +- platform/darwin/src/MGLSymbolStyleLayer.h | 464 +++++++++--------- platform/darwin/src/MGLSymbolStyleLayer.mm | 454 ++++++++--------- .../NSValue+MGLStyleEnumAttributeAdditions.h | 104 ++-- .../NSValue+MGLStyleEnumAttributeAdditions.mm | 80 +-- .../test/MGLBackgroundStyleLayerTests.m | 8 +- .../darwin/test/MGLCircleStyleLayerTests.m | 26 +- platform/darwin/test/MGLFillStyleLayerTests.m | 16 +- platform/darwin/test/MGLLineStyleLayerTests.m | 48 +- .../darwin/test/MGLRasterStyleLayerTests.m | 40 +- .../darwin/test/MGLSymbolStyleLayerTests.m | 226 ++++----- 23 files changed, 1048 insertions(+), 1026 deletions(-) create mode 100644 platform/darwin/scripts/style-spec-cocoa-conventions-v8.json diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 9090bb40e..b5689dca3 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -4,11 +4,20 @@ const fs = require('fs'); const ejs = require('ejs'); const _ = require('lodash'); const colorParser = require('csscolorparser'); -const spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json')); - +const cocoaConventions = require('./style-spec-cocoa-conventions-v8.json'); +let spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json')); const prefix = 'MGL'; const suffix = 'StyleLayer'; +// Rename properties and keep `original` for use with setters and getters +_.forOwn(cocoaConventions, function (properties, kind) { + _.forOwn(properties, function (newName, oldName) { + spec[kind][newName] = spec[kind][oldName]; + spec[kind][newName].original = oldName; + delete spec[kind][oldName]; + }) +}); + global.camelize = function (str) { return str.replace(/(?:^|-)(.)/g, function (_, x) { return x.toUpperCase(); @@ -212,6 +221,10 @@ global.propertyDefault = function (property, layerType) { return 'an `MGLStyleValue` object containing ' + describeValue(property.default, property, layerType); }; +global.originalPropertyName = function (property) { + return property.original || property.name; +} + global.propertyType = function (property) { switch (property.type) { case 'boolean': @@ -321,8 +334,8 @@ const layers = Object.keys(spec.layer.type.values).map((type) => { return { type: type, - layoutProperties: layoutProperties, - paintProperties: paintProperties, + layoutProperties: _.sortBy(layoutProperties, ['name']), + paintProperties: _.sortBy(paintProperties, ['name']), layoutPropertiesByName: spec[`layout_${type}`], paintPropertiesByName: spec[`paint_${type}`], }; diff --git a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json new file mode 100644 index 000000000..e37598406 --- /dev/null +++ b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json @@ -0,0 +1,9 @@ +{ + "layout_symbol": { + "icon-image": "icon-image-name" + }, + "paint_raster": { + "raster-brightness-min": "minimum-raster-brightness", + "raster-brightness-max": "maximum-raster-brightness" + } +} \ No newline at end of file diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h index a70383cc9..656e104bb 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer.h @@ -38,11 +38,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, null_resettable) MGLStyleValue *backgroundColor; #endif -/** - Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - */ -@property (nonatomic, null_resettable) MGLStyleValue *backgroundPattern; - /** The opacity at which the background will be drawn. @@ -50,6 +45,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, null_resettable) MGLStyleValue *backgroundOpacity; +/** + Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + */ +@property (nonatomic, null_resettable) MGLStyleValue *backgroundPattern; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 6e30a20c9..59aa06910 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -70,16 +70,6 @@ return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setBackgroundPattern:(MGLStyleValue *)backgroundPattern { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundPattern); - _rawLayer->setBackgroundPattern(mbglValue); -} - -- (MGLStyleValue *)backgroundPattern { - auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setBackgroundOpacity:(MGLStyleValue *)backgroundOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundOpacity); _rawLayer->setBackgroundOpacity(mbglValue); @@ -90,5 +80,15 @@ return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setBackgroundPattern:(MGLStyleValue *)backgroundPattern { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundPattern); + _rawLayer->setBackgroundPattern(mbglValue); +} + +- (MGLStyleValue *)backgroundPattern { + auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + @end diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index da7076e7d..2d88a664b 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -6,22 +6,6 @@ NS_ASSUME_NONNULL_BEGIN -/** - Controls the translation reference point. - - Values of this type are used in the `circleTranslateAnchor` property of `MGLCircleStyleLayer`. - */ -typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) { - /** - The circle is translated relative to the map. - */ - MGLCircleTranslateAnchorMap, - /** - The circle is translated relative to the viewport. - */ - MGLCircleTranslateAnchorViewport, -}; - /** Controls the scaling behavior of the circle when the map is pitched. @@ -38,6 +22,22 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { MGLCirclePitchScaleViewport, }; +/** + Controls the translation reference point. + + Values of this type are used in the `circleTranslateAnchor` property of `MGLCircleStyleLayer`. + */ +typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) { + /** + The circle is translated relative to the map. + */ + MGLCircleTranslateAnchorMap, + /** + The circle is translated relative to the viewport. + */ + MGLCircleTranslateAnchorViewport, +}; + /** A circle layer which allows customization of styling properties at runtime. You may instantiate a new circle layer to add to a map style or you may query an @@ -49,13 +49,11 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { #pragma mark - Accessing the Paint Attributes /** - Circle radius. - - This property is measured in points. + Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *circleRadius; +@property (nonatomic, null_resettable) MGLStyleValue *circleBlur; #if TARGET_OS_IPHONE /** @@ -73,13 +71,6 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { @property (nonatomic, null_resettable) MGLStyleValue *circleColor; #endif -/** - Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *circleBlur; - /** The opacity at which the circle will be drawn. @@ -87,6 +78,22 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { */ @property (nonatomic, null_resettable) MGLStyleValue *circleOpacity; +/** + Controls the scaling behavior of the circle when the map is pitched. + + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *circlePitchScale; + +/** + Circle radius. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *circleRadius; + /** The geometry's offset. @@ -105,13 +112,6 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) { */ @property (nonatomic, null_resettable) MGLStyleValue *circleTranslateAnchor; -/** - Controls the scaling behavior of the circle when the map is pitched. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *circlePitchScale; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index aca8ff028..1c903ab00 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -11,16 +11,16 @@ #include namespace mbgl { - MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, { - { MGLCircleTranslateAnchorMap, "map" }, - { MGLCircleTranslateAnchorViewport, "viewport" }, - }); - MBGL_DEFINE_ENUM(MGLCirclePitchScale, { { MGLCirclePitchScaleMap, "map" }, { MGLCirclePitchScaleViewport, "viewport" }, }); + MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, { + { MGLCircleTranslateAnchorMap, "map" }, + { MGLCircleTranslateAnchorViewport, "viewport" }, + }); + } @interface MGLCircleStyleLayer () @@ -92,13 +92,13 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setCircleRadius:(MGLStyleValue *)circleRadius { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleRadius); - _rawLayer->setCircleRadius(mbglValue); +- (void)setCircleBlur:(MGLStyleValue *)circleBlur { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleBlur); + _rawLayer->setCircleBlur(mbglValue); } -- (MGLStyleValue *)circleRadius { - auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius(); +- (MGLStyleValue *)circleBlur { + auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -112,16 +112,6 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setCircleBlur:(MGLStyleValue *)circleBlur { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleBlur); - _rawLayer->setCircleBlur(mbglValue); -} - -- (MGLStyleValue *)circleBlur { - auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setCircleOpacity:(MGLStyleValue *)circleOpacity { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleOpacity); _rawLayer->setCircleOpacity(mbglValue); @@ -132,6 +122,26 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); + _rawLayer->setCirclePitchScale(mbglValue); +} + +- (MGLStyleValue *)circlePitchScale { + auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +} + +- (void)setCircleRadius:(MGLStyleValue *)circleRadius { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleRadius); + _rawLayer->setCircleRadius(mbglValue); +} + +- (MGLStyleValue *)circleRadius { + auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setCircleTranslate:(MGLStyleValue *)circleTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(circleTranslate); _rawLayer->setCircleTranslate(mbglValue); @@ -152,15 +162,5 @@ namespace mbgl { return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } -- (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); - _rawLayer->setCirclePitchScale(mbglValue); -} - -- (MGLStyleValue *)circlePitchScale { - auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); -} - @end diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h index 799fa380c..9bbda26ce 100644 --- a/platform/darwin/src/MGLFillStyleLayer.h +++ b/platform/darwin/src/MGLFillStyleLayer.h @@ -39,13 +39,6 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *fillAntialias; -/** - The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1pt stroke around the fill, if the stroke is used. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *fillOpacity; - #if TARGET_OS_IPHONE /** The color of the filled part of this layer. @@ -66,6 +59,13 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *fillColor; #endif +/** + The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1pt stroke around the fill, if the stroke is used. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *fillOpacity; + /** The outline color of the fill. Matches the value of `fillColor` if unspecified. @@ -73,6 +73,11 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *fillOutlineColor; +/** + Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + */ +@property (nonatomic, null_resettable) MGLStyleValue *fillPattern; + /** The geometry's offset. @@ -91,11 +96,6 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *fillTranslateAnchor; -/** - Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - */ -@property (nonatomic, null_resettable) MGLStyleValue *fillPattern; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index d670fd31e..6f9c68f21 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -97,16 +97,6 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setFillOpacity:(MGLStyleValue *)fillOpacity { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOpacity); - _rawLayer->setFillOpacity(mbglValue); -} - -- (MGLStyleValue *)fillOpacity { - auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setFillColor:(MGLStyleValue *)fillColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillColor); _rawLayer->setFillColor(mbglValue); @@ -117,6 +107,16 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setFillOpacity:(MGLStyleValue *)fillOpacity { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOpacity); + _rawLayer->setFillOpacity(mbglValue); +} + +- (MGLStyleValue *)fillOpacity { + auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setFillOutlineColor:(MGLStyleValue *)fillOutlineColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOutlineColor); _rawLayer->setFillOutlineColor(mbglValue); @@ -127,6 +127,16 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setFillPattern:(MGLStyleValue *)fillPattern { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillPattern); + _rawLayer->setFillPattern(mbglValue); +} + +- (MGLStyleValue *)fillPattern { + auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setFillTranslate:(MGLStyleValue *)fillTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(fillTranslate); _rawLayer->setFillTranslate(mbglValue); @@ -147,15 +157,5 @@ namespace mbgl { return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } -- (void)setFillPattern:(MGLStyleValue *)fillPattern { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillPattern); - _rawLayer->setFillPattern(mbglValue); -} - -- (MGLStyleValue *)fillPattern { - auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - @end diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 68b0a73a2..74d8f7bfe 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -107,11 +107,13 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) { #pragma mark - Accessing the Paint Attributes /** - The opacity at which the line will be drawn. + Blur applied to the line, in points. + + This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *lineOpacity; +@property (nonatomic, null_resettable) MGLStyleValue *lineBlur; #if TARGET_OS_IPHONE /** @@ -133,6 +135,45 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *lineColor; #endif +/** + Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to points, multiply the length by the current line width. + + This property is measured in line widths. + + This property is only applied to the style if `linePattern` is set to `nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *> *lineDasharray; + +/** + Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *lineGapWidth; + +/** + The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *lineOffset; + +/** + The opacity at which the line will be drawn. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *lineOpacity; + +/** + Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). + */ +@property (nonatomic, null_resettable) MGLStyleValue *linePattern; + /** The geometry's offset. @@ -160,47 +201,6 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *lineWidth; -/** - Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. - - This property is measured in points. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *lineGapWidth; - -/** - The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. - - This property is measured in points. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *lineOffset; - -/** - Blur applied to the line, in points. - - This property is measured in points. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *lineBlur; - -/** - Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to points, multiply the length by the current line width. - - This property is measured in line widths. - - This property is only applied to the style if `linePattern` is set to `nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *> *lineDasharray; - -/** - Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). - */ -@property (nonatomic, null_resettable) MGLStyleValue *linePattern; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 34c58aa49..c37d1b659 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -141,13 +141,13 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setLineOpacity:(MGLStyleValue *)lineOpacity { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOpacity); - _rawLayer->setLineOpacity(mbglValue); +- (void)setLineBlur:(MGLStyleValue *)lineBlur { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineBlur); + _rawLayer->setLineBlur(mbglValue); } -- (MGLStyleValue *)lineOpacity { - auto propertyValue = _rawLayer->getLineOpacity() ?: _rawLayer->getDefaultLineOpacity(); +- (MGLStyleValue *)lineBlur { + auto propertyValue = _rawLayer->getLineBlur() ?: _rawLayer->getDefaultLineBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -161,6 +161,56 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setLineDasharray:(MGLStyleValue *> *)lineDasharray { + auto mbglValue = MGLStyleValueTransformer, NSArray *, float>().toPropertyValue(lineDasharray); + _rawLayer->setLineDasharray(mbglValue); +} + +- (MGLStyleValue *> *)lineDasharray { + auto propertyValue = _rawLayer->getLineDasharray() ?: _rawLayer->getDefaultLineDasharray(); + return MGLStyleValueTransformer, NSArray *, float>().toStyleValue(propertyValue); +} + +- (void)setLineGapWidth:(MGLStyleValue *)lineGapWidth { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineGapWidth); + _rawLayer->setLineGapWidth(mbglValue); +} + +- (MGLStyleValue *)lineGapWidth { + auto propertyValue = _rawLayer->getLineGapWidth() ?: _rawLayer->getDefaultLineGapWidth(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setLineOffset:(MGLStyleValue *)lineOffset { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOffset); + _rawLayer->setLineOffset(mbglValue); +} + +- (MGLStyleValue *)lineOffset { + auto propertyValue = _rawLayer->getLineOffset() ?: _rawLayer->getDefaultLineOffset(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setLineOpacity:(MGLStyleValue *)lineOpacity { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOpacity); + _rawLayer->setLineOpacity(mbglValue); +} + +- (MGLStyleValue *)lineOpacity { + auto propertyValue = _rawLayer->getLineOpacity() ?: _rawLayer->getDefaultLineOpacity(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setLinePattern:(MGLStyleValue *)linePattern { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(linePattern); + _rawLayer->setLinePattern(mbglValue); +} + +- (MGLStyleValue *)linePattern { + auto propertyValue = _rawLayer->getLinePattern() ?: _rawLayer->getDefaultLinePattern(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setLineTranslate:(MGLStyleValue *)lineTranslate { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(lineTranslate); _rawLayer->setLineTranslate(mbglValue); @@ -191,55 +241,5 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setLineGapWidth:(MGLStyleValue *)lineGapWidth { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineGapWidth); - _rawLayer->setLineGapWidth(mbglValue); -} - -- (MGLStyleValue *)lineGapWidth { - auto propertyValue = _rawLayer->getLineGapWidth() ?: _rawLayer->getDefaultLineGapWidth(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setLineOffset:(MGLStyleValue *)lineOffset { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOffset); - _rawLayer->setLineOffset(mbglValue); -} - -- (MGLStyleValue *)lineOffset { - auto propertyValue = _rawLayer->getLineOffset() ?: _rawLayer->getDefaultLineOffset(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setLineBlur:(MGLStyleValue *)lineBlur { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineBlur); - _rawLayer->setLineBlur(mbglValue); -} - -- (MGLStyleValue *)lineBlur { - auto propertyValue = _rawLayer->getLineBlur() ?: _rawLayer->getDefaultLineBlur(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setLineDasharray:(MGLStyleValue *> *)lineDasharray { - auto mbglValue = MGLStyleValueTransformer, NSArray *, float>().toPropertyValue(lineDasharray); - _rawLayer->setLineDasharray(mbglValue); -} - -- (MGLStyleValue *> *)lineDasharray { - auto propertyValue = _rawLayer->getLineDasharray() ?: _rawLayer->getDefaultLineDasharray(); - return MGLStyleValueTransformer, NSArray *, float>().toStyleValue(propertyValue); -} - -- (void)setLinePattern:(MGLStyleValue *)linePattern { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(linePattern); - _rawLayer->setLinePattern(mbglValue); -} - -- (MGLStyleValue *)linePattern { - auto propertyValue = _rawLayer->getLinePattern() ?: _rawLayer->getDefaultLinePattern(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - @end diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h index afae85001..68b187a90 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.h +++ b/platform/darwin/src/MGLRasterStyleLayer.h @@ -17,41 +17,18 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Accessing the Paint Attributes /** - The opacity at which the image will be drawn. + Increase or reduce the brightness of the image. The value is the maximum brightness. The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *rasterOpacity; - -/** - Rotates hues around the color wheel. - - This property is measured in degrees. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *rasterHueRotate; +@property (nonatomic, null_resettable) MGLStyleValue *maximumRasterBrightness; /** Increase or reduce the brightness of the image. The value is the minimum brightness. The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *rasterBrightnessMin; - -/** - Increase or reduce the brightness of the image. The value is the maximum brightness. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *rasterBrightnessMax; - -/** - Increase or reduce the saturation of the image. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *rasterSaturation; +@property (nonatomic, null_resettable) MGLStyleValue *minimumRasterBrightness; /** Increase or reduce the contrast of the image. @@ -69,6 +46,29 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, null_resettable) MGLStyleValue *rasterFadeDuration; +/** + Rotates hues around the color wheel. + + This property is measured in degrees. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *rasterHueRotate; + +/** + The opacity at which the image will be drawn. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *rasterOpacity; + +/** + Increase or reduce the saturation of the image. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + */ +@property (nonatomic, null_resettable) MGLStyleValue *rasterSaturation; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 49dc261be..cd1d135ff 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -59,53 +59,23 @@ #pragma mark - Accessing the Paint Attributes -- (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterOpacity); - _rawLayer->setRasterOpacity(mbglValue); -} - -- (MGLStyleValue *)rasterOpacity { - auto propertyValue = _rawLayer->getRasterOpacity() ?: _rawLayer->getDefaultRasterOpacity(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setRasterHueRotate:(MGLStyleValue *)rasterHueRotate { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterHueRotate); - _rawLayer->setRasterHueRotate(mbglValue); -} - -- (MGLStyleValue *)rasterHueRotate { - auto propertyValue = _rawLayer->getRasterHueRotate() ?: _rawLayer->getDefaultRasterHueRotate(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setRasterBrightnessMin:(MGLStyleValue *)rasterBrightnessMin { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMin); - _rawLayer->setRasterBrightnessMin(mbglValue); -} - -- (MGLStyleValue *)rasterBrightnessMin { - auto propertyValue = _rawLayer->getRasterBrightnessMin() ?: _rawLayer->getDefaultRasterBrightnessMin(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setRasterBrightnessMax:(MGLStyleValue *)rasterBrightnessMax { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterBrightnessMax); +- (void)setMaximumRasterBrightness:(MGLStyleValue *)maximumRasterBrightness { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(maximumRasterBrightness); _rawLayer->setRasterBrightnessMax(mbglValue); } -- (MGLStyleValue *)rasterBrightnessMax { +- (MGLStyleValue *)maximumRasterBrightness { auto propertyValue = _rawLayer->getRasterBrightnessMax() ?: _rawLayer->getDefaultRasterBrightnessMax(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setRasterSaturation:(MGLStyleValue *)rasterSaturation { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterSaturation); - _rawLayer->setRasterSaturation(mbglValue); +- (void)setMinimumRasterBrightness:(MGLStyleValue *)minimumRasterBrightness { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(minimumRasterBrightness); + _rawLayer->setRasterBrightnessMin(mbglValue); } -- (MGLStyleValue *)rasterSaturation { - auto propertyValue = _rawLayer->getRasterSaturation() ?: _rawLayer->getDefaultRasterSaturation(); +- (MGLStyleValue *)minimumRasterBrightness { + auto propertyValue = _rawLayer->getRasterBrightnessMin() ?: _rawLayer->getDefaultRasterBrightnessMin(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -129,5 +99,35 @@ return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setRasterHueRotate:(MGLStyleValue *)rasterHueRotate { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterHueRotate); + _rawLayer->setRasterHueRotate(mbglValue); +} + +- (MGLStyleValue *)rasterHueRotate { + auto propertyValue = _rawLayer->getRasterHueRotate() ?: _rawLayer->getDefaultRasterHueRotate(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterOpacity); + _rawLayer->setRasterOpacity(mbglValue); +} + +- (MGLStyleValue *)rasterOpacity { + auto propertyValue = _rawLayer->getRasterOpacity() ?: _rawLayer->getDefaultRasterOpacity(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setRasterSaturation:(MGLStyleValue *)rasterSaturation { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterSaturation); + _rawLayer->setRasterSaturation(mbglValue); +} + +- (MGLStyleValue *)rasterSaturation { + auto propertyValue = _rawLayer->getRasterSaturation() ?: _rawLayer->getDefaultRasterSaturation(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + @end diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 8febd69a2..ae90b67d3 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -21,9 +21,9 @@ namespace mbgl { <% if (layoutProperties.length) { -%> <% for (const property of layoutProperties) { -%> <% if (property.type == "enum") { -%> - MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, { + MBGL_DEFINE_ENUM(MGL<%- camelize(originalPropertyName(property)) %>, { <% for (const value in property.values) { -%> - { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, + { MGL<%- camelize(originalPropertyName(property)) %><%- camelize(value) %>, "<%-value%>" }, <% } -%> }); @@ -33,9 +33,9 @@ namespace mbgl { <% if (paintProperties.length) { -%> <% for (const property of paintProperties) { -%> <% if (property.type == "enum") { -%> - MBGL_DEFINE_ENUM(MGL<%- camelize(property.name) %>, { + MBGL_DEFINE_ENUM(MGL<%- camelize(originalPropertyName(property)) %>, { <% for (const value in property.values) { -%> - { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, + { MGL<%- camelize(originalPropertyName(property)) %><%- camelize(value) %>, "<%-value%>" }, <% } -%> }); @@ -133,18 +133,18 @@ namespace mbgl { <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(property.name) %>(mbglValue); + auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); + _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(property.name) %>(mbglValue); + _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> - return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); <% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); <% } -%> @@ -158,18 +158,18 @@ namespace mbgl { <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(property.name) %>(mbglValue); + auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); + _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); - _rawLayer->set<%- camelize(property.name) %>(mbglValue); + _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); <% } -%> } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { - auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); + auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> - return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); <% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); <% } -%> diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index dc0cd236c..dbb966b4e 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -6,22 +6,6 @@ NS_ASSUME_NONNULL_BEGIN -/** - Label placement relative to its geometry. - - Values of this type are used in the `symbolPlacement` property of `MGLSymbolStyleLayer`. - */ -typedef NS_ENUM(NSUInteger, MGLSymbolPlacement) { - /** - The label is placed at the point where the geometry is located. - */ - MGLSymbolPlacementPoint, - /** - The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. - */ - MGLSymbolPlacementLine, -}; - /** In combination with `symbolPlacement`, determines the rotation behavior of icons. @@ -67,63 +51,19 @@ typedef NS_ENUM(NSUInteger, MGLIconTextFit) { }; /** - Orientation of text when map is pitched. + Label placement relative to its geometry. - Values of this type are used in the `textPitchAlignment` property of `MGLSymbolStyleLayer`. + Values of this type are used in the `symbolPlacement` property of `MGLSymbolStyleLayer`. */ -typedef NS_ENUM(NSUInteger, MGLTextPitchAlignment) { +typedef NS_ENUM(NSUInteger, MGLSymbolPlacement) { /** - The text is aligned to the plane of the map. + The label is placed at the point where the geometry is located. */ - MGLTextPitchAlignmentMap, + MGLSymbolPlacementPoint, /** - The text is aligned to the plane of the viewport. + The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. */ - MGLTextPitchAlignmentViewport, - /** - Automatically matches the value of `textRotationAlignment`. - */ - MGLTextPitchAlignmentAuto, -}; - -/** - In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. - - Values of this type are used in the `textRotationAlignment` property of `MGLSymbolStyleLayer`. - */ -typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) { - /** - When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns text east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, aligns text x-axes with the line. - */ - MGLTextRotationAlignmentMap, - /** - Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. - */ - MGLTextRotationAlignmentViewport, - /** - When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is equivalent to `MGLTextRotationAlignmentViewport`. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, this is equivalent to `MGLTextRotationAlignmentMap`. - */ - MGLTextRotationAlignmentAuto, -}; - -/** - Text justification options. - - Values of this type are used in the `textJustify` property of `MGLSymbolStyleLayer`. - */ -typedef NS_ENUM(NSUInteger, MGLTextJustify) { - /** - The text is aligned to the left. - */ - MGLTextJustifyLeft, - /** - The text is centered. - */ - MGLTextJustifyCenter, - /** - The text is aligned to the right. - */ - MGLTextJustifyRight, + MGLSymbolPlacementLine, }; /** @@ -170,6 +110,66 @@ typedef NS_ENUM(NSUInteger, MGLTextAnchor) { MGLTextAnchorBottomRight, }; +/** + Text justification options. + + Values of this type are used in the `textJustify` property of `MGLSymbolStyleLayer`. + */ +typedef NS_ENUM(NSUInteger, MGLTextJustify) { + /** + The text is aligned to the left. + */ + MGLTextJustifyLeft, + /** + The text is centered. + */ + MGLTextJustifyCenter, + /** + The text is aligned to the right. + */ + MGLTextJustifyRight, +}; + +/** + Orientation of text when map is pitched. + + Values of this type are used in the `textPitchAlignment` property of `MGLSymbolStyleLayer`. + */ +typedef NS_ENUM(NSUInteger, MGLTextPitchAlignment) { + /** + The text is aligned to the plane of the map. + */ + MGLTextPitchAlignmentMap, + /** + The text is aligned to the plane of the viewport. + */ + MGLTextPitchAlignmentViewport, + /** + Automatically matches the value of `textRotationAlignment`. + */ + MGLTextPitchAlignmentAuto, +}; + +/** + In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. + + Values of this type are used in the `textRotationAlignment` property of `MGLSymbolStyleLayer`. + */ +typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) { + /** + When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns text east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, aligns text x-axes with the line. + */ + MGLTextRotationAlignmentMap, + /** + Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. + */ + MGLTextRotationAlignmentViewport, + /** + When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is equivalent to `MGLTextRotationAlignmentViewport`. When `symbolPlacement` is set to `MGLSymbolPlacementLine`, this is equivalent to `MGLTextRotationAlignmentMap`. + */ + MGLTextRotationAlignmentAuto, +}; + /** Specifies how to capitalize text. @@ -232,31 +232,6 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { #pragma mark - Accessing the Layout Attributes -/** - Label placement relative to its geometry. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementPoint`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *symbolPlacement; - -/** - Distance between two symbol anchors. - - This property is measured in points. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `250`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *symbolSpacing; - -/** - If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. - */ -@property (nonatomic, null_resettable) MGLStyleValue *symbolAvoidEdges; - /** If true, the icon will be visible even if it collides with other previously drawn symbols. @@ -275,6 +250,29 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *iconIgnorePlacement; +/** + A string with {tokens} replaced, referencing the data property to pull from. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconImageName; + +/** + If true, the icon may be flipped to prevent it from being rendered upside-down. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `iconImage` is non-`nil`, and `iconRotationAlignment` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLIconRotationAlignmentMap`, and `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconKeepUpright; + +/** + Offset distance of icon from its anchor. + + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing a `CGVector` struct set to 0 from the left and 0 from the top. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconOffset; + /** If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. @@ -284,6 +282,28 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *iconOptional; +/** + Size of the additional area around the icon bounding box used for detecting symbol collisions. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `2`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconPadding; + +/** + Rotates the icon clockwise. + + This property is measured in degrees. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconRotate; + /** In combination with `symbolPlacement`, determines the rotation behavior of icons. @@ -323,67 +343,47 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconTextFitPadding; /** - A string with {tokens} replaced, referencing the data property to pull from. + If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconImage; +@property (nonatomic, null_resettable) MGLStyleValue *symbolAvoidEdges; /** - Rotates the icon clockwise. - - This property is measured in degrees. + Label placement relative to its geometry. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementPoint`. Set this property to `nil` to reset it to the default value. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconRotate; +@property (nonatomic, null_resettable) MGLStyleValue *symbolPlacement; /** - Size of the additional area around the icon bounding box used for detecting symbol collisions. + Distance between two symbol anchors. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `2`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `250`. Set this property to `nil` to reset it to the default value. - This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + This property is only applied to the style if `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconPadding; +@property (nonatomic, null_resettable) MGLStyleValue *symbolSpacing; /** - If true, the icon may be flipped to prevent it from being rendered upside-down. + If true, the text will be visible even if it collides with other previously drawn symbols. The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. - This property is only applied to the style if `iconImage` is non-`nil`, and `iconRotationAlignment` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLIconRotationAlignmentMap`, and `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconKeepUpright; +@property (nonatomic, null_resettable) MGLStyleValue *textAllowOverlap; /** - Offset distance of icon from its anchor. + Part of the text placed closest to the anchor. - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing a `CGVector` struct set to 0 from the left and 0 from the top. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *iconOffset; - -/** - Orientation of text when map is pitched. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextPitchAlignmentAuto`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextAnchorCenter`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textPitchAlignment; - -/** - In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextRotationAlignmentAuto`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textRotationAlignment; +@property (nonatomic, null_resettable) MGLStyleValue *textAnchor; /** Value to use for a text label. Feature properties are specified using tokens like {field_name}. @@ -402,37 +402,31 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *> *textFont; /** - Font size. - - This property is measured in points. + If true, other symbols can be visible even if they collide with the text. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `16`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textSize; +@property (nonatomic, null_resettable) MGLStyleValue *textIgnorePlacement; /** - The maximum line width for text wrapping. - - This property is measured in ems. + Text justification options. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `10`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextJustifyCenter`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textMaxWidth; +@property (nonatomic, null_resettable) MGLStyleValue *textJustify; /** - Text leading value for multi-line text. - - This property is measured in ems. + If true, the text may be flipped vertically to prevent it from being rendered upside-down. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1.2`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `YES`. Set this property to `nil` to reset it to the default value. - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + This property is only applied to the style if `textField` is non-`nil`, and `textRotationAlignment` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextRotationAlignmentMap`, and `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textLineHeight; +@property (nonatomic, null_resettable) MGLStyleValue *textKeepUpright; /** Text tracking amount. @@ -446,22 +440,15 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textLetterSpacing; /** - Text justification options. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextJustifyCenter`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textJustify; + Text leading value for multi-line text. -/** - Part of the text placed closest to the anchor. + This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextAnchorCenter`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1.2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textAnchor; +@property (nonatomic, null_resettable) MGLStyleValue *textLineHeight; /** Maximum angle change between adjacent characters. @@ -475,44 +462,15 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textMaxAngle; /** - Rotates the text clockwise. + The maximum line width for text wrapping. - This property is measured in degrees. + This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `10`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textRotate; - -/** - Size of the additional area around the text bounding box used for detecting symbol collisions. - - This property is measured in points. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `2`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textPadding; - -/** - If true, the text may be flipped vertically to prevent it from being rendered upside-down. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `YES`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`, and `textRotationAlignment` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextRotationAlignmentMap`, and `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textKeepUpright; - -/** - Specifies how to capitalize text. - - The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextTransformNone`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textTransform; +@property (nonatomic, null_resettable) MGLStyleValue *textMaxWidth; /** Offset distance of text from its anchor. @@ -525,24 +483,6 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *textOffset; -/** - If true, the text will be visible even if it collides with other previously drawn symbols. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textAllowOverlap; - -/** - If true, other symbols can be visible even if they collide with the text. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing `NO`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textIgnorePlacement; - /** If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. @@ -552,16 +492,67 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *textOptional; -#pragma mark - Accessing the Paint Attributes +/** + Size of the additional area around the text bounding box used for detecting symbol collisions. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `2`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textPadding; /** - The opacity at which the icon will be drawn. + Orientation of text when map is pitched. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextPitchAlignmentAuto`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconOpacity; +@property (nonatomic, null_resettable) MGLStyleValue *textPitchAlignment; + +/** + Rotates the text clockwise. + + This property is measured in degrees. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textRotate; + +/** + In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. + + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextRotationAlignmentAuto`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textRotationAlignment; + +/** + Font size. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `16`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textSize; + +/** + Specifies how to capitalize text. + + The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLTextTransformNone`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textTransform; + +#pragma mark - Accessing the Paint Attributes #if TARGET_OS_IPHONE /** @@ -583,6 +574,17 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconColor; #endif +/** + Fade out the halo towards the outside. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *iconHaloBlur; + #if TARGET_OS_IPHONE /** The color of the icon's halo. Icon halos can only be used with SDF icons. @@ -615,15 +617,13 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *iconHaloWidth; /** - Fade out the halo towards the outside. - - This property is measured in points. + The opacity at which the icon will be drawn. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *iconHaloBlur; +@property (nonatomic, null_resettable) MGLStyleValue *iconOpacity; /** Distance that the icon's anchor is moved from its original placement. @@ -645,15 +645,6 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { */ @property (nonatomic, null_resettable) MGLStyleValue *iconTranslateAnchor; -/** - The opacity at which the text will be drawn. - - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. - - This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. - */ -@property (nonatomic, null_resettable) MGLStyleValue *textOpacity; - #if TARGET_OS_IPHONE /** The color with which the text will be drawn. @@ -674,6 +665,17 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textColor; #endif +/** + The halo's fadeout distance towards the outside. + + This property is measured in points. + + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + + This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. + */ +@property (nonatomic, null_resettable) MGLStyleValue *textHaloBlur; + #if TARGET_OS_IPHONE /** The color of the text's halo, which helps it stand out from backgrounds. @@ -706,15 +708,13 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) { @property (nonatomic, null_resettable) MGLStyleValue *textHaloWidth; /** - The halo's fadeout distance towards the outside. - - This property is measured in points. + The opacity at which the text will be drawn. - The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ -@property (nonatomic, null_resettable) MGLStyleValue *textHaloBlur; +@property (nonatomic, null_resettable) MGLStyleValue *textOpacity; /** Distance that the text's anchor is moved from its original placement. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 0acc36d2d..3e5834f7b 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -11,11 +11,6 @@ #include namespace mbgl { - MBGL_DEFINE_ENUM(MGLSymbolPlacement, { - { MGLSymbolPlacementPoint, "point" }, - { MGLSymbolPlacementLine, "line" }, - }); - MBGL_DEFINE_ENUM(MGLIconRotationAlignment, { { MGLIconRotationAlignmentMap, "map" }, { MGLIconRotationAlignmentViewport, "viewport" }, @@ -29,22 +24,9 @@ namespace mbgl { { MGLIconTextFitBoth, "both" }, }); - MBGL_DEFINE_ENUM(MGLTextPitchAlignment, { - { MGLTextPitchAlignmentMap, "map" }, - { MGLTextPitchAlignmentViewport, "viewport" }, - { MGLTextPitchAlignmentAuto, "auto" }, - }); - - MBGL_DEFINE_ENUM(MGLTextRotationAlignment, { - { MGLTextRotationAlignmentMap, "map" }, - { MGLTextRotationAlignmentViewport, "viewport" }, - { MGLTextRotationAlignmentAuto, "auto" }, - }); - - MBGL_DEFINE_ENUM(MGLTextJustify, { - { MGLTextJustifyLeft, "left" }, - { MGLTextJustifyCenter, "center" }, - { MGLTextJustifyRight, "right" }, + MBGL_DEFINE_ENUM(MGLSymbolPlacement, { + { MGLSymbolPlacementPoint, "point" }, + { MGLSymbolPlacementLine, "line" }, }); MBGL_DEFINE_ENUM(MGLTextAnchor, { @@ -59,6 +41,24 @@ namespace mbgl { { MGLTextAnchorBottomRight, "bottom-right" }, }); + MBGL_DEFINE_ENUM(MGLTextJustify, { + { MGLTextJustifyLeft, "left" }, + { MGLTextJustifyCenter, "center" }, + { MGLTextJustifyRight, "right" }, + }); + + MBGL_DEFINE_ENUM(MGLTextPitchAlignment, { + { MGLTextPitchAlignmentMap, "map" }, + { MGLTextPitchAlignmentViewport, "viewport" }, + { MGLTextPitchAlignmentAuto, "auto" }, + }); + + MBGL_DEFINE_ENUM(MGLTextRotationAlignment, { + { MGLTextRotationAlignmentMap, "map" }, + { MGLTextRotationAlignmentViewport, "viewport" }, + { MGLTextRotationAlignmentAuto, "auto" }, + }); + MBGL_DEFINE_ENUM(MGLTextTransform, { { MGLTextTransformNone, "none" }, { MGLTextTransformUppercase, "uppercase" }, @@ -146,36 +146,6 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes -- (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); - _rawLayer->setSymbolPlacement(mbglValue); -} - -- (MGLStyleValue *)symbolPlacement { - auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); -} - -- (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolSpacing); - _rawLayer->setSymbolSpacing(mbglValue); -} - -- (MGLStyleValue *)symbolSpacing { - auto propertyValue = _rawLayer->getSymbolSpacing() ?: _rawLayer->getDefaultSymbolSpacing(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setSymbolAvoidEdges:(MGLStyleValue *)symbolAvoidEdges { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolAvoidEdges); - _rawLayer->setSymbolAvoidEdges(mbglValue); -} - -- (MGLStyleValue *)symbolAvoidEdges { - auto propertyValue = _rawLayer->getSymbolAvoidEdges() ?: _rawLayer->getDefaultSymbolAvoidEdges(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setIconAllowOverlap:(MGLStyleValue *)iconAllowOverlap { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconAllowOverlap); _rawLayer->setIconAllowOverlap(mbglValue); @@ -196,6 +166,36 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setIconImageName:(MGLStyleValue *)iconImageName { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconImageName); + _rawLayer->setIconImage(mbglValue); +} + +- (MGLStyleValue *)iconImageName { + auto propertyValue = _rawLayer->getIconImage() ?: _rawLayer->getDefaultIconImage(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setIconKeepUpright:(MGLStyleValue *)iconKeepUpright { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconKeepUpright); + _rawLayer->setIconKeepUpright(mbglValue); +} + +- (MGLStyleValue *)iconKeepUpright { + auto propertyValue = _rawLayer->getIconKeepUpright() ?: _rawLayer->getDefaultIconKeepUpright(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setIconOffset:(MGLStyleValue *)iconOffset { + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconOffset); + _rawLayer->setIconOffset(mbglValue); +} + +- (MGLStyleValue *)iconOffset { + auto propertyValue = _rawLayer->getIconOffset() ?: _rawLayer->getDefaultIconOffset(); + return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); +} + - (void)setIconOptional:(MGLStyleValue *)iconOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOptional); _rawLayer->setIconOptional(mbglValue); @@ -206,6 +206,26 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setIconPadding:(MGLStyleValue *)iconPadding { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconPadding); + _rawLayer->setIconPadding(mbglValue); +} + +- (MGLStyleValue *)iconPadding { + auto propertyValue = _rawLayer->getIconPadding() ?: _rawLayer->getDefaultIconPadding(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setIconRotate:(MGLStyleValue *)iconRotate { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotate); + _rawLayer->setIconRotate(mbglValue); +} + +- (MGLStyleValue *)iconRotate { + auto propertyValue = _rawLayer->getIconRotate() ?: _rawLayer->getDefaultIconRotate(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); _rawLayer->setIconRotationAlignment(mbglValue); @@ -246,74 +266,54 @@ namespace mbgl { return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } -- (void)setIconImage:(MGLStyleValue *)iconImage { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconImage); - _rawLayer->setIconImage(mbglValue); +- (void)setSymbolAvoidEdges:(MGLStyleValue *)symbolAvoidEdges { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolAvoidEdges); + _rawLayer->setSymbolAvoidEdges(mbglValue); } -- (MGLStyleValue *)iconImage { - auto propertyValue = _rawLayer->getIconImage() ?: _rawLayer->getDefaultIconImage(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setIconRotate:(MGLStyleValue *)iconRotate { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotate); - _rawLayer->setIconRotate(mbglValue); -} - -- (MGLStyleValue *)iconRotate { - auto propertyValue = _rawLayer->getIconRotate() ?: _rawLayer->getDefaultIconRotate(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setIconPadding:(MGLStyleValue *)iconPadding { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconPadding); - _rawLayer->setIconPadding(mbglValue); -} - -- (MGLStyleValue *)iconPadding { - auto propertyValue = _rawLayer->getIconPadding() ?: _rawLayer->getDefaultIconPadding(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setIconKeepUpright:(MGLStyleValue *)iconKeepUpright { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconKeepUpright); - _rawLayer->setIconKeepUpright(mbglValue); -} - -- (MGLStyleValue *)iconKeepUpright { - auto propertyValue = _rawLayer->getIconKeepUpright() ?: _rawLayer->getDefaultIconKeepUpright(); +- (MGLStyleValue *)symbolAvoidEdges { + auto propertyValue = _rawLayer->getSymbolAvoidEdges() ?: _rawLayer->getDefaultSymbolAvoidEdges(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setIconOffset:(MGLStyleValue *)iconOffset { - auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconOffset); - _rawLayer->setIconOffset(mbglValue); +- (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); + _rawLayer->setSymbolPlacement(mbglValue); } -- (MGLStyleValue *)iconOffset { - auto propertyValue = _rawLayer->getIconOffset() ?: _rawLayer->getDefaultIconOffset(); - return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); +- (MGLStyleValue *)symbolPlacement { + auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } -- (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); - _rawLayer->setTextPitchAlignment(mbglValue); +- (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolSpacing); + _rawLayer->setSymbolSpacing(mbglValue); } -- (MGLStyleValue *)textPitchAlignment { - auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +- (MGLStyleValue *)symbolSpacing { + auto propertyValue = _rawLayer->getSymbolSpacing() ?: _rawLayer->getDefaultSymbolSpacing(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); - _rawLayer->setTextRotationAlignment(mbglValue); +- (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAllowOverlap); + _rawLayer->setTextAllowOverlap(mbglValue); } -- (MGLStyleValue *)textRotationAlignment { - auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +- (MGLStyleValue *)textAllowOverlap { + auto propertyValue = _rawLayer->getTextAllowOverlap() ?: _rawLayer->getDefaultTextAllowOverlap(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setTextAnchor:(MGLStyleValue *)textAnchor { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); + _rawLayer->setTextAnchor(mbglValue); +} + +- (MGLStyleValue *)textAnchor { + auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextField:(MGLStyleValue *)textField { @@ -336,23 +336,43 @@ namespace mbgl { return MGLStyleValueTransformer, NSArray *, std::string>().toStyleValue(propertyValue); } -- (void)setTextSize:(MGLStyleValue *)textSize { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textSize); - _rawLayer->setTextSize(mbglValue); +- (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textIgnorePlacement); + _rawLayer->setTextIgnorePlacement(mbglValue); } -- (MGLStyleValue *)textSize { - auto propertyValue = _rawLayer->getTextSize() ?: _rawLayer->getDefaultTextSize(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); +- (MGLStyleValue *)textIgnorePlacement { + auto propertyValue = _rawLayer->getTextIgnorePlacement() ?: _rawLayer->getDefaultTextIgnorePlacement(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextMaxWidth:(MGLStyleValue *)textMaxWidth { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxWidth); - _rawLayer->setTextMaxWidth(mbglValue); +- (void)setTextJustify:(MGLStyleValue *)textJustify { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); + _rawLayer->setTextJustify(mbglValue); } -- (MGLStyleValue *)textMaxWidth { - auto propertyValue = _rawLayer->getTextMaxWidth() ?: _rawLayer->getDefaultTextMaxWidth(); +- (MGLStyleValue *)textJustify { + auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +} + +- (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textKeepUpright); + _rawLayer->setTextKeepUpright(mbglValue); +} + +- (MGLStyleValue *)textKeepUpright { + auto propertyValue = _rawLayer->getTextKeepUpright() ?: _rawLayer->getDefaultTextKeepUpright(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLetterSpacing); + _rawLayer->setTextLetterSpacing(mbglValue); +} + +- (MGLStyleValue *)textLetterSpacing { + auto propertyValue = _rawLayer->getTextLetterSpacing() ?: _rawLayer->getDefaultTextLetterSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -366,36 +386,6 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLetterSpacing); - _rawLayer->setTextLetterSpacing(mbglValue); -} - -- (MGLStyleValue *)textLetterSpacing { - auto propertyValue = _rawLayer->getTextLetterSpacing() ?: _rawLayer->getDefaultTextLetterSpacing(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setTextJustify:(MGLStyleValue *)textJustify { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); - _rawLayer->setTextJustify(mbglValue); -} - -- (MGLStyleValue *)textJustify { - auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); -} - -- (void)setTextAnchor:(MGLStyleValue *)textAnchor { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); - _rawLayer->setTextAnchor(mbglValue); -} - -- (MGLStyleValue *)textAnchor { - auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); -} - - (void)setTextMaxAngle:(MGLStyleValue *)textMaxAngle { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxAngle); _rawLayer->setTextMaxAngle(mbglValue); @@ -406,46 +396,16 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextRotate:(MGLStyleValue *)textRotate { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotate); - _rawLayer->setTextRotate(mbglValue); +- (void)setTextMaxWidth:(MGLStyleValue *)textMaxWidth { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxWidth); + _rawLayer->setTextMaxWidth(mbglValue); } -- (MGLStyleValue *)textRotate { - auto propertyValue = _rawLayer->getTextRotate() ?: _rawLayer->getDefaultTextRotate(); +- (MGLStyleValue *)textMaxWidth { + auto propertyValue = _rawLayer->getTextMaxWidth() ?: _rawLayer->getDefaultTextMaxWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextPadding:(MGLStyleValue *)textPadding { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPadding); - _rawLayer->setTextPadding(mbglValue); -} - -- (MGLStyleValue *)textPadding { - auto propertyValue = _rawLayer->getTextPadding() ?: _rawLayer->getDefaultTextPadding(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textKeepUpright); - _rawLayer->setTextKeepUpright(mbglValue); -} - -- (MGLStyleValue *)textKeepUpright { - auto propertyValue = _rawLayer->getTextKeepUpright() ?: _rawLayer->getDefaultTextKeepUpright(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setTextTransform:(MGLStyleValue *)textTransform { - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); - _rawLayer->setTextTransform(mbglValue); -} - -- (MGLStyleValue *)textTransform { - auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); -} - - (void)setTextOffset:(MGLStyleValue *)textOffset { auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textOffset); _rawLayer->setTextOffset(mbglValue); @@ -456,26 +416,6 @@ namespace mbgl { return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } -- (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAllowOverlap); - _rawLayer->setTextAllowOverlap(mbglValue); -} - -- (MGLStyleValue *)textAllowOverlap { - auto propertyValue = _rawLayer->getTextAllowOverlap() ?: _rawLayer->getDefaultTextAllowOverlap(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - -- (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textIgnorePlacement); - _rawLayer->setTextIgnorePlacement(mbglValue); -} - -- (MGLStyleValue *)textIgnorePlacement { - auto propertyValue = _rawLayer->getTextIgnorePlacement() ?: _rawLayer->getDefaultTextIgnorePlacement(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setTextOptional:(MGLStyleValue *)textOptional { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOptional); _rawLayer->setTextOptional(mbglValue); @@ -486,18 +426,68 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -#pragma mark - Accessing the Paint Attributes - -- (void)setIconOpacity:(MGLStyleValue *)iconOpacity { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOpacity); - _rawLayer->setIconOpacity(mbglValue); +- (void)setTextPadding:(MGLStyleValue *)textPadding { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPadding); + _rawLayer->setTextPadding(mbglValue); } -- (MGLStyleValue *)iconOpacity { - auto propertyValue = _rawLayer->getIconOpacity() ?: _rawLayer->getDefaultIconOpacity(); +- (MGLStyleValue *)textPadding { + auto propertyValue = _rawLayer->getTextPadding() ?: _rawLayer->getDefaultTextPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); + _rawLayer->setTextPitchAlignment(mbglValue); +} + +- (MGLStyleValue *)textPitchAlignment { + auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +} + +- (void)setTextRotate:(MGLStyleValue *)textRotate { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotate); + _rawLayer->setTextRotate(mbglValue); +} + +- (MGLStyleValue *)textRotate { + auto propertyValue = _rawLayer->getTextRotate() ?: _rawLayer->getDefaultTextRotate(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); + _rawLayer->setTextRotationAlignment(mbglValue); +} + +- (MGLStyleValue *)textRotationAlignment { + auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +} + +- (void)setTextSize:(MGLStyleValue *)textSize { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textSize); + _rawLayer->setTextSize(mbglValue); +} + +- (MGLStyleValue *)textSize { + auto propertyValue = _rawLayer->getTextSize() ?: _rawLayer->getDefaultTextSize(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + +- (void)setTextTransform:(MGLStyleValue *)textTransform { + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); + _rawLayer->setTextTransform(mbglValue); +} + +- (MGLStyleValue *)textTransform { + auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); +} + +#pragma mark - Accessing the Paint Attributes + - (void)setIconColor:(MGLStyleValue *)iconColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconColor); _rawLayer->setIconColor(mbglValue); @@ -508,6 +498,16 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setIconHaloBlur:(MGLStyleValue *)iconHaloBlur { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloBlur); + _rawLayer->setIconHaloBlur(mbglValue); +} + +- (MGLStyleValue *)iconHaloBlur { + auto propertyValue = _rawLayer->getIconHaloBlur() ?: _rawLayer->getDefaultIconHaloBlur(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setIconHaloColor:(MGLStyleValue *)iconHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloColor); _rawLayer->setIconHaloColor(mbglValue); @@ -528,13 +528,13 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setIconHaloBlur:(MGLStyleValue *)iconHaloBlur { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloBlur); - _rawLayer->setIconHaloBlur(mbglValue); +- (void)setIconOpacity:(MGLStyleValue *)iconOpacity { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOpacity); + _rawLayer->setIconOpacity(mbglValue); } -- (MGLStyleValue *)iconHaloBlur { - auto propertyValue = _rawLayer->getIconHaloBlur() ?: _rawLayer->getDefaultIconHaloBlur(); +- (MGLStyleValue *)iconOpacity { + auto propertyValue = _rawLayer->getIconOpacity() ?: _rawLayer->getDefaultIconOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -558,16 +558,6 @@ namespace mbgl { return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } -- (void)setTextOpacity:(MGLStyleValue *)textOpacity { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOpacity); - _rawLayer->setTextOpacity(mbglValue); -} - -- (MGLStyleValue *)textOpacity { - auto propertyValue = _rawLayer->getTextOpacity() ?: _rawLayer->getDefaultTextOpacity(); - return MGLStyleValueTransformer().toStyleValue(propertyValue); -} - - (void)setTextColor:(MGLStyleValue *)textColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textColor); _rawLayer->setTextColor(mbglValue); @@ -578,6 +568,16 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } +- (void)setTextHaloBlur:(MGLStyleValue *)textHaloBlur { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloBlur); + _rawLayer->setTextHaloBlur(mbglValue); +} + +- (MGLStyleValue *)textHaloBlur { + auto propertyValue = _rawLayer->getTextHaloBlur() ?: _rawLayer->getDefaultTextHaloBlur(); + return MGLStyleValueTransformer().toStyleValue(propertyValue); +} + - (void)setTextHaloColor:(MGLStyleValue *)textHaloColor { auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloColor); _rawLayer->setTextHaloColor(mbglValue); @@ -598,13 +598,13 @@ namespace mbgl { return MGLStyleValueTransformer().toStyleValue(propertyValue); } -- (void)setTextHaloBlur:(MGLStyleValue *)textHaloBlur { - auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloBlur); - _rawLayer->setTextHaloBlur(mbglValue); +- (void)setTextOpacity:(MGLStyleValue *)textOpacity { + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOpacity); + _rawLayer->setTextOpacity(mbglValue); } -- (MGLStyleValue *)textHaloBlur { - auto propertyValue = _rawLayer->getTextHaloBlur() ?: _rawLayer->getDefaultTextHaloBlur(); +- (MGLStyleValue *)textOpacity { + auto propertyValue = _rawLayer->getTextOpacity() ?: _rawLayer->getDefaultTextOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h index 835b22b02..8aa07b2a0 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h @@ -45,19 +45,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly) MGLLineJoin MGLLineJoinValue; -/** - Creates a new value object containing the given `MGLSymbolPlacement` enumeration. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement; - -/** - The `MGLSymbolPlacement` enumeration representation of the value. -*/ -@property (readonly) MGLSymbolPlacement MGLSymbolPlacementValue; - /** Creates a new value object containing the given `MGLIconRotationAlignment` enumeration. @@ -84,6 +71,45 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly) MGLIconTextFit MGLIconTextFitValue; +/** + Creates a new value object containing the given `MGLSymbolPlacement` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement; + +/** + The `MGLSymbolPlacement` enumeration representation of the value. +*/ +@property (readonly) MGLSymbolPlacement MGLSymbolPlacementValue; + +/** + Creates a new value object containing the given `MGLTextAnchor` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor; + +/** + The `MGLTextAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLTextAnchor MGLTextAnchorValue; + +/** + Creates a new value object containing the given `MGLTextJustify` enumeration. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLTextJustify:(MGLTextJustify)textJustify; + +/** + The `MGLTextJustify` enumeration representation of the value. +*/ +@property (readonly) MGLTextJustify MGLTextJustifyValue; + /** Creates a new value object containing the given `MGLTextPitchAlignment` enumeration. @@ -110,32 +136,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly) MGLTextRotationAlignment MGLTextRotationAlignmentValue; -/** - Creates a new value object containing the given `MGLTextJustify` enumeration. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLTextJustify:(MGLTextJustify)textJustify; - -/** - The `MGLTextJustify` enumeration representation of the value. -*/ -@property (readonly) MGLTextJustify MGLTextJustifyValue; - -/** - Creates a new value object containing the given `MGLTextAnchor` enumeration. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor; - -/** - The `MGLTextAnchor` enumeration representation of the value. -*/ -@property (readonly) MGLTextAnchor MGLTextAnchorValue; - /** Creates a new value object containing the given `MGLTextTransform` enumeration. @@ -201,19 +201,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly) MGLTextTranslateAnchor MGLTextTranslateAnchorValue; -/** - Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; - -/** - The `MGLCircleTranslateAnchor` enumeration representation of the value. -*/ -@property (readonly) MGLCircleTranslateAnchor MGLCircleTranslateAnchorValue; - /** Creates a new value object containing the given `MGLCirclePitchScale` structure. @@ -227,6 +214,19 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly) MGLCirclePitchScale MGLCirclePitchScaleValue; +/** + Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. + + @param type The value for the new object. + @return A new value object that contains the style enumeration type. +*/ ++ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; + +/** + The `MGLCircleTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLCircleTranslateAnchor MGLCircleTranslateAnchorValue; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm index b6a64a785..89f0c07a5 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm @@ -25,16 +25,6 @@ return value; } -+ (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement { - return [NSValue value:&symbolPlacement withObjCType:@encode(MGLSymbolPlacement)]; -} - -- (MGLSymbolPlacement)MGLSymbolPlacementValue { - MGLSymbolPlacement value; - [self getValue:&value]; - return value; -} - + (NSValue *)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment { return [NSValue value:&iconRotationAlignment withObjCType:@encode(MGLIconRotationAlignment)]; } @@ -55,6 +45,36 @@ return value; } ++ (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement { + return [NSValue value:&symbolPlacement withObjCType:@encode(MGLSymbolPlacement)]; +} + +- (MGLSymbolPlacement)MGLSymbolPlacementValue { + MGLSymbolPlacement value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { + return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; +} + +- (MGLTextAnchor)MGLTextAnchorValue { + MGLTextAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextJustify:(MGLTextJustify)textJustify { + return [NSValue value:&textJustify withObjCType:@encode(MGLTextJustify)]; +} + +- (MGLTextJustify)MGLTextJustifyValue { + MGLTextJustify value; + [self getValue:&value]; + return value; +} + + (NSValue *)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment { return [NSValue value:&textPitchAlignment withObjCType:@encode(MGLTextPitchAlignment)]; } @@ -75,26 +95,6 @@ return value; } -+ (NSValue *)valueWithMGLTextJustify:(MGLTextJustify)textJustify { - return [NSValue value:&textJustify withObjCType:@encode(MGLTextJustify)]; -} - -- (MGLTextJustify)MGLTextJustifyValue { - MGLTextJustify value; - [self getValue:&value]; - return value; -} - -+ (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { - return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; -} - -- (MGLTextAnchor)MGLTextAnchorValue { - MGLTextAnchor value; - [self getValue:&value]; - return value; -} - + (NSValue *)valueWithMGLTextTransform:(MGLTextTransform)textTransform { return [NSValue value:&textTransform withObjCType:@encode(MGLTextTransform)]; } @@ -145,16 +145,6 @@ return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslate return value; } -+ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { -return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; -} - -- (MGLCircleTranslateAnchor)MGLCircleTranslateAnchorValue { - MGLCircleTranslateAnchor value; - [self getValue:&value]; - return value; -} - + (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale { return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; } @@ -165,5 +155,15 @@ return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale return value; } ++ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { +return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; +} + +- (MGLCircleTranslateAnchor)MGLCircleTranslateAnchorValue { + MGLCircleTranslateAnchor value; + [self getValue:&value]; + return value; +} + @end diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m index 2681b773a..09bed7665 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.m @@ -13,22 +13,22 @@ [self.mapView.style addLayer:layer]; layer.backgroundColor = [MGLRuntimeStylingHelper testColor]; - layer.backgroundPattern = [MGLRuntimeStylingHelper testString]; layer.backgroundOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.backgroundPattern = [MGLRuntimeStylingHelper testString]; MGLBackgroundStyleLayer *gLayer = (MGLBackgroundStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLBackgroundStyleLayer class]]); XCTAssertEqualObjects(gLayer.backgroundColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testString]); XCTAssertEqualObjects(gLayer.backgroundOpacity, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testString]); layer.backgroundColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.backgroundPattern = [MGLRuntimeStylingHelper testStringFunction]; layer.backgroundOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.backgroundPattern = [MGLRuntimeStylingHelper testStringFunction]; XCTAssertEqualObjects(gLayer.backgroundColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testStringFunction]); XCTAssertEqualObjects(gLayer.backgroundOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testStringFunction]); } @end diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m index 54ba8be6c..432d3ffa7 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ b/platform/darwin/test/MGLCircleStyleLayerTests.m @@ -16,41 +16,41 @@ MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; - layer.circleRadius = [MGLRuntimeStylingHelper testNumber]; - layer.circleColor = [MGLRuntimeStylingHelper testColor]; layer.circleBlur = [MGLRuntimeStylingHelper testNumber]; + layer.circleColor = [MGLRuntimeStylingHelper testColor]; layer.circleOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.circlePitchScale = [MGLRuntimeStylingHelper testEnum:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]; + layer.circleRadius = [MGLRuntimeStylingHelper testNumber]; layer.circleTranslate = [MGLRuntimeStylingHelper testOffset]; layer.circleTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLCircleTranslateAnchorViewport type:@encode(MGLCircleTranslateAnchor)]; - layer.circlePitchScale = [MGLRuntimeStylingHelper testEnum:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]; MGLCircleStyleLayer *gLayer = (MGLCircleStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLCircleStyleLayer class]]); - XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColor]); XCTAssertEqualObjects(gLayer.circleBlur, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColor]); XCTAssertEqualObjects(gLayer.circleOpacity, [MGLRuntimeStylingHelper testNumber]); + XCTAssert([gLayer.circlePitchScale isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.circlePitchScale, [MGLRuntimeStylingHelper testEnum:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]); + XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.circleTranslate, [MGLRuntimeStylingHelper testOffset]); XCTAssert([gLayer.circleTranslateAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.circleTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLCircleTranslateAnchorViewport type:@encode(MGLCircleTranslateAnchor)]); - XCTAssert([gLayer.circlePitchScale isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.circlePitchScale, [MGLRuntimeStylingHelper testEnum:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]); - layer.circleRadius = [MGLRuntimeStylingHelper testNumberFunction]; - layer.circleColor = [MGLRuntimeStylingHelper testColorFunction]; layer.circleBlur = [MGLRuntimeStylingHelper testNumberFunction]; + layer.circleColor = [MGLRuntimeStylingHelper testColorFunction]; layer.circleOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.circlePitchScale = [MGLRuntimeStylingHelper testEnumFunction:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]; + layer.circleRadius = [MGLRuntimeStylingHelper testNumberFunction]; layer.circleTranslate = [MGLRuntimeStylingHelper testOffsetFunction]; layer.circleTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLCircleTranslateAnchorViewport type:@encode(MGLCircleTranslateAnchor)]; - layer.circlePitchScale = [MGLRuntimeStylingHelper testEnumFunction:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]; - XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColorFunction]); XCTAssertEqualObjects(gLayer.circleBlur, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColorFunction]); XCTAssertEqualObjects(gLayer.circleOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.circlePitchScale, [MGLRuntimeStylingHelper testEnumFunction:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]); + XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.circleTranslate, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.circleTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLCircleTranslateAnchorViewport type:@encode(MGLCircleTranslateAnchor)]); - XCTAssertEqualObjects(gLayer.circlePitchScale, [MGLRuntimeStylingHelper testEnumFunction:MGLCirclePitchScaleViewport type:@encode(MGLCirclePitchScale)]); } @end diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m index 7b3120790..87846302e 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ b/platform/darwin/test/MGLFillStyleLayerTests.m @@ -17,39 +17,39 @@ [self.mapView.style addLayer:layer]; layer.fillAntialias = [MGLRuntimeStylingHelper testBool]; - layer.fillOpacity = [MGLRuntimeStylingHelper testNumber]; layer.fillColor = [MGLRuntimeStylingHelper testColor]; + layer.fillOpacity = [MGLRuntimeStylingHelper testNumber]; layer.fillOutlineColor = [MGLRuntimeStylingHelper testColor]; + layer.fillPattern = [MGLRuntimeStylingHelper testString]; layer.fillTranslate = [MGLRuntimeStylingHelper testOffset]; layer.fillTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLFillTranslateAnchorViewport type:@encode(MGLFillTranslateAnchor)]; - layer.fillPattern = [MGLRuntimeStylingHelper testString]; MGLFillStyleLayer *gLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLFillStyleLayer class]]); XCTAssertEqualObjects(gLayer.fillAntialias, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColor]); + XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColor]); + XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testString]); XCTAssertEqualObjects(gLayer.fillTranslate, [MGLRuntimeStylingHelper testOffset]); XCTAssert([gLayer.fillTranslateAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.fillTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLFillTranslateAnchorViewport type:@encode(MGLFillTranslateAnchor)]); - XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testString]); layer.fillAntialias = [MGLRuntimeStylingHelper testBoolFunction]; - layer.fillOpacity = [MGLRuntimeStylingHelper testNumberFunction]; layer.fillColor = [MGLRuntimeStylingHelper testColorFunction]; + layer.fillOpacity = [MGLRuntimeStylingHelper testNumberFunction]; layer.fillOutlineColor = [MGLRuntimeStylingHelper testColorFunction]; + layer.fillPattern = [MGLRuntimeStylingHelper testStringFunction]; layer.fillTranslate = [MGLRuntimeStylingHelper testOffsetFunction]; layer.fillTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLFillTranslateAnchorViewport type:@encode(MGLFillTranslateAnchor)]; - layer.fillPattern = [MGLRuntimeStylingHelper testStringFunction]; XCTAssertEqualObjects(gLayer.fillAntialias, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColorFunction]); + XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColorFunction]); + XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testStringFunction]); XCTAssertEqualObjects(gLayer.fillTranslate, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.fillTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLFillTranslateAnchorViewport type:@encode(MGLFillTranslateAnchor)]); - XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testStringFunction]); } @end diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m index 801bc12ff..95983b1f5 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ b/platform/darwin/test/MGLLineStyleLayerTests.m @@ -20,16 +20,16 @@ layer.lineJoin = [MGLRuntimeStylingHelper testEnum:MGLLineJoinMiter type:@encode(MGLLineJoin)]; layer.lineMiterLimit = [MGLRuntimeStylingHelper testNumber]; layer.lineRoundLimit = [MGLRuntimeStylingHelper testNumber]; - layer.lineOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.lineBlur = [MGLRuntimeStylingHelper testNumber]; layer.lineColor = [MGLRuntimeStylingHelper testColor]; + layer.lineDasharray = [MGLRuntimeStylingHelper testDashArray]; + layer.lineGapWidth = [MGLRuntimeStylingHelper testNumber]; + layer.lineOffset = [MGLRuntimeStylingHelper testNumber]; + layer.lineOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.linePattern = [MGLRuntimeStylingHelper testString]; layer.lineTranslate = [MGLRuntimeStylingHelper testOffset]; layer.lineTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLLineTranslateAnchorViewport type:@encode(MGLLineTranslateAnchor)]; layer.lineWidth = [MGLRuntimeStylingHelper testNumber]; - layer.lineGapWidth = [MGLRuntimeStylingHelper testNumber]; - layer.lineOffset = [MGLRuntimeStylingHelper testNumber]; - layer.lineBlur = [MGLRuntimeStylingHelper testNumber]; - layer.lineDasharray = [MGLRuntimeStylingHelper testDashArray]; - layer.linePattern = [MGLRuntimeStylingHelper testString]; MGLLineStyleLayer *gLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLLineStyleLayer class]]); @@ -39,47 +39,47 @@ XCTAssertEqualObjects(gLayer.lineJoin, [MGLRuntimeStylingHelper testEnum:MGLLineJoinMiter type:@encode(MGLLineJoin)]); XCTAssertEqualObjects(gLayer.lineMiterLimit, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.lineRoundLimit, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.lineColor, [MGLRuntimeStylingHelper testColor]); + XCTAssertEqualObjects(gLayer.lineDasharray, [MGLRuntimeStylingHelper testDashArray]); + XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testString]); XCTAssertEqualObjects(gLayer.lineTranslate, [MGLRuntimeStylingHelper testOffset]); XCTAssert([gLayer.lineTranslateAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.lineTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLLineTranslateAnchorViewport type:@encode(MGLLineTranslateAnchor)]); XCTAssertEqualObjects(gLayer.lineWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineDasharray, [MGLRuntimeStylingHelper testDashArray]); - XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testString]); layer.lineCap = [MGLRuntimeStylingHelper testEnumFunction:MGLLineCapSquare type:@encode(MGLLineCap)]; layer.lineJoin = [MGLRuntimeStylingHelper testEnumFunction:MGLLineJoinMiter type:@encode(MGLLineJoin)]; layer.lineMiterLimit = [MGLRuntimeStylingHelper testNumberFunction]; layer.lineRoundLimit = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.lineBlur = [MGLRuntimeStylingHelper testNumberFunction]; layer.lineColor = [MGLRuntimeStylingHelper testColorFunction]; + layer.lineDasharray = [MGLRuntimeStylingHelper testDashArrayFunction]; + layer.lineGapWidth = [MGLRuntimeStylingHelper testNumberFunction]; + layer.lineOffset = [MGLRuntimeStylingHelper testNumberFunction]; + layer.lineOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.linePattern = [MGLRuntimeStylingHelper testStringFunction]; layer.lineTranslate = [MGLRuntimeStylingHelper testOffsetFunction]; layer.lineTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLLineTranslateAnchorViewport type:@encode(MGLLineTranslateAnchor)]; layer.lineWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineGapWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineOffset = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineBlur = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineDasharray = [MGLRuntimeStylingHelper testDashArrayFunction]; - layer.linePattern = [MGLRuntimeStylingHelper testStringFunction]; XCTAssertEqualObjects(gLayer.lineCap, [MGLRuntimeStylingHelper testEnumFunction:MGLLineCapSquare type:@encode(MGLLineCap)]); XCTAssertEqualObjects(gLayer.lineJoin, [MGLRuntimeStylingHelper testEnumFunction:MGLLineJoinMiter type:@encode(MGLLineJoin)]); XCTAssertEqualObjects(gLayer.lineMiterLimit, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.lineRoundLimit, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.lineColor, [MGLRuntimeStylingHelper testColorFunction]); + XCTAssertEqualObjects(gLayer.lineDasharray, [MGLRuntimeStylingHelper testDashArrayFunction]); + XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testStringFunction]); XCTAssertEqualObjects(gLayer.lineTranslate, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.lineTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLLineTranslateAnchorViewport type:@encode(MGLLineTranslateAnchor)]); XCTAssertEqualObjects(gLayer.lineWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineDasharray, [MGLRuntimeStylingHelper testDashArrayFunction]); - XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testStringFunction]); } @end diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m index f68f6d328..84fd0fe3e 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ b/platform/darwin/test/MGLRasterStyleLayerTests.m @@ -16,39 +16,39 @@ MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; - layer.rasterOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumber]; - layer.rasterBrightnessMin = [MGLRuntimeStylingHelper testNumber]; - layer.rasterBrightnessMax = [MGLRuntimeStylingHelper testNumber]; - layer.rasterSaturation = [MGLRuntimeStylingHelper testNumber]; + layer.maximumRasterBrightness = [MGLRuntimeStylingHelper testNumber]; + layer.minimumRasterBrightness = [MGLRuntimeStylingHelper testNumber]; layer.rasterContrast = [MGLRuntimeStylingHelper testNumber]; layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumber]; + layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumber]; + layer.rasterOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.rasterSaturation = [MGLRuntimeStylingHelper testNumber]; MGLRasterStyleLayer *gLayer = (MGLRasterStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLRasterStyleLayer class]]); - XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterBrightnessMin, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterBrightnessMax, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.maximumRasterBrightness, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.minimumRasterBrightness, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumber]); - layer.rasterOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterBrightnessMin = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterBrightnessMax = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterSaturation = [MGLRuntimeStylingHelper testNumberFunction]; + layer.maximumRasterBrightness = [MGLRuntimeStylingHelper testNumberFunction]; + layer.minimumRasterBrightness = [MGLRuntimeStylingHelper testNumberFunction]; layer.rasterContrast = [MGLRuntimeStylingHelper testNumberFunction]; layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumberFunction]; + layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumberFunction]; + layer.rasterOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.rasterSaturation = [MGLRuntimeStylingHelper testNumberFunction]; - XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterBrightnessMin, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterBrightnessMax, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.maximumRasterBrightness, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.minimumRasterBrightness, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumberFunction]); } @end diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index f60ae7c2a..e77c4f6f3 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -16,211 +16,211 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; [self.mapView.style addLayer:layer]; - layer.symbolPlacement = [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; - layer.symbolSpacing = [MGLRuntimeStylingHelper testNumber]; - layer.symbolAvoidEdges = [MGLRuntimeStylingHelper testBool]; layer.iconAllowOverlap = [MGLRuntimeStylingHelper testBool]; layer.iconIgnorePlacement = [MGLRuntimeStylingHelper testBool]; + layer.iconImageName = [MGLRuntimeStylingHelper testString]; + layer.iconKeepUpright = [MGLRuntimeStylingHelper testBool]; + layer.iconOffset = [MGLRuntimeStylingHelper testOffset]; layer.iconOptional = [MGLRuntimeStylingHelper testBool]; + layer.iconPadding = [MGLRuntimeStylingHelper testNumber]; + layer.iconRotate = [MGLRuntimeStylingHelper testNumber]; layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]; layer.iconSize = [MGLRuntimeStylingHelper testNumber]; layer.iconTextFit = [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]; layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPadding]; - layer.iconImage = [MGLRuntimeStylingHelper testString]; - layer.iconRotate = [MGLRuntimeStylingHelper testNumber]; - layer.iconPadding = [MGLRuntimeStylingHelper testNumber]; - layer.iconKeepUpright = [MGLRuntimeStylingHelper testBool]; - layer.iconOffset = [MGLRuntimeStylingHelper testOffset]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; + layer.symbolAvoidEdges = [MGLRuntimeStylingHelper testBool]; + layer.symbolPlacement = [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; + layer.symbolSpacing = [MGLRuntimeStylingHelper testNumber]; + layer.textAllowOverlap = [MGLRuntimeStylingHelper testBool]; + layer.textAnchor = [MGLRuntimeStylingHelper testEnum:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; layer.textField = [MGLRuntimeStylingHelper testString]; layer.textFont = [MGLRuntimeStylingHelper testFont]; - layer.textSize = [MGLRuntimeStylingHelper testNumber]; - layer.textMaxWidth = [MGLRuntimeStylingHelper testNumber]; - layer.textLineHeight = [MGLRuntimeStylingHelper testNumber]; - layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumber]; - layer.textJustify = [MGLRuntimeStylingHelper testEnum:MGLTextJustifyRight type:@encode(MGLTextJustify)]; - layer.textAnchor = [MGLRuntimeStylingHelper testEnum:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; - layer.textMaxAngle = [MGLRuntimeStylingHelper testNumber]; - layer.textRotate = [MGLRuntimeStylingHelper testNumber]; - layer.textPadding = [MGLRuntimeStylingHelper testNumber]; - layer.textKeepUpright = [MGLRuntimeStylingHelper testBool]; - layer.textTransform = [MGLRuntimeStylingHelper testEnum:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; - layer.textOffset = [MGLRuntimeStylingHelper testOffset]; - layer.textAllowOverlap = [MGLRuntimeStylingHelper testBool]; layer.textIgnorePlacement = [MGLRuntimeStylingHelper testBool]; + layer.textJustify = [MGLRuntimeStylingHelper testEnum:MGLTextJustifyRight type:@encode(MGLTextJustify)]; + layer.textKeepUpright = [MGLRuntimeStylingHelper testBool]; + layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumber]; + layer.textLineHeight = [MGLRuntimeStylingHelper testNumber]; + layer.textMaxAngle = [MGLRuntimeStylingHelper testNumber]; + layer.textMaxWidth = [MGLRuntimeStylingHelper testNumber]; + layer.textOffset = [MGLRuntimeStylingHelper testOffset]; layer.textOptional = [MGLRuntimeStylingHelper testBool]; - layer.iconOpacity = [MGLRuntimeStylingHelper testNumber]; + layer.textPadding = [MGLRuntimeStylingHelper testNumber]; + layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; + layer.textRotate = [MGLRuntimeStylingHelper testNumber]; + layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; + layer.textSize = [MGLRuntimeStylingHelper testNumber]; + layer.textTransform = [MGLRuntimeStylingHelper testEnum:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; layer.iconColor = [MGLRuntimeStylingHelper testColor]; + layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumber]; layer.iconHaloColor = [MGLRuntimeStylingHelper testColor]; layer.iconHaloWidth = [MGLRuntimeStylingHelper testNumber]; - layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumber]; + layer.iconOpacity = [MGLRuntimeStylingHelper testNumber]; layer.iconTranslate = [MGLRuntimeStylingHelper testOffset]; layer.iconTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLIconTranslateAnchorViewport type:@encode(MGLIconTranslateAnchor)]; - layer.textOpacity = [MGLRuntimeStylingHelper testNumber]; layer.textColor = [MGLRuntimeStylingHelper testColor]; + layer.textHaloBlur = [MGLRuntimeStylingHelper testNumber]; layer.textHaloColor = [MGLRuntimeStylingHelper testColor]; layer.textHaloWidth = [MGLRuntimeStylingHelper testNumber]; - layer.textHaloBlur = [MGLRuntimeStylingHelper testNumber]; + layer.textOpacity = [MGLRuntimeStylingHelper testNumber]; layer.textTranslate = [MGLRuntimeStylingHelper testOffset]; layer.textTranslateAnchor = [MGLRuntimeStylingHelper testEnum:MGLTextTranslateAnchorViewport type:@encode(MGLTextTranslateAnchor)]; MGLSymbolStyleLayer *gLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; XCTAssertTrue([gLayer isKindOfClass:[MGLSymbolStyleLayer class]]); - XCTAssert([gLayer.symbolPlacement isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); - XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.symbolAvoidEdges, [MGLRuntimeStylingHelper testBool]); XCTAssertEqualObjects(gLayer.iconAllowOverlap, [MGLRuntimeStylingHelper testBool]); XCTAssertEqualObjects(gLayer.iconIgnorePlacement, [MGLRuntimeStylingHelper testBool]); + XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testString]); + XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBool]); + XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffset]); XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBool]); + XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumber]); XCTAssert([gLayer.iconRotationAlignment isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]); XCTAssertEqualObjects(gLayer.iconSize, [MGLRuntimeStylingHelper testNumber]); XCTAssert([gLayer.iconTextFit isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]); XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPadding]); - XCTAssertEqualObjects(gLayer.iconImage, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.textPitchAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); - XCTAssert([gLayer.textRotationAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); - XCTAssertEqualObjects(gLayer.textField, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.textFont, [MGLRuntimeStylingHelper testFont]); - XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textMaxWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.textJustify isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textJustify, [MGLRuntimeStylingHelper testEnum:MGLTextJustifyRight type:@encode(MGLTextJustify)]); + XCTAssertEqualObjects(gLayer.symbolAvoidEdges, [MGLRuntimeStylingHelper testBool]); + XCTAssert([gLayer.symbolPlacement isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); + XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBool]); XCTAssert([gLayer.textAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.textAnchor, [MGLRuntimeStylingHelper testEnum:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]); - XCTAssertEqualObjects(gLayer.textMaxAngle, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textRotate, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textField, [MGLRuntimeStylingHelper testString]); + XCTAssertEqualObjects(gLayer.textFont, [MGLRuntimeStylingHelper testFont]); + XCTAssertEqualObjects(gLayer.textIgnorePlacement, [MGLRuntimeStylingHelper testBool]); + XCTAssert([gLayer.textJustify isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.textJustify, [MGLRuntimeStylingHelper testEnum:MGLTextJustifyRight type:@encode(MGLTextJustify)]); XCTAssertEqualObjects(gLayer.textKeepUpright, [MGLRuntimeStylingHelper testBool]); + XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textMaxAngle, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textMaxWidth, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffset]); + XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBool]); + XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumber]); + XCTAssert([gLayer.textPitchAlignment isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); + XCTAssertEqualObjects(gLayer.textRotate, [MGLRuntimeStylingHelper testNumber]); + XCTAssert([gLayer.textRotationAlignment isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); + XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumber]); XCTAssert([gLayer.textTransform isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.textTransform, [MGLRuntimeStylingHelper testEnum:MGLTextTransformLowercase type:@encode(MGLTextTransform)]); - XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffset]); - XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.textIgnorePlacement, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColor]); + XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColor]); XCTAssertEqualObjects(gLayer.iconHaloWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.iconTranslate, [MGLRuntimeStylingHelper testOffset]); XCTAssert([gLayer.iconTranslateAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.iconTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLIconTranslateAnchorViewport type:@encode(MGLIconTranslateAnchor)]); - XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.textColor, [MGLRuntimeStylingHelper testColor]); + XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.textHaloColor, [MGLRuntimeStylingHelper testColor]); XCTAssertEqualObjects(gLayer.textHaloWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumber]); + XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.textTranslate, [MGLRuntimeStylingHelper testOffset]); XCTAssert([gLayer.textTranslateAnchor isKindOfClass:[MGLStyleConstantValue class]]); XCTAssertEqualObjects(gLayer.textTranslateAnchor, [MGLRuntimeStylingHelper testEnum:MGLTextTranslateAnchorViewport type:@encode(MGLTextTranslateAnchor)]); - layer.symbolPlacement = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; - layer.symbolSpacing = [MGLRuntimeStylingHelper testNumberFunction]; - layer.symbolAvoidEdges = [MGLRuntimeStylingHelper testBoolFunction]; layer.iconAllowOverlap = [MGLRuntimeStylingHelper testBoolFunction]; layer.iconIgnorePlacement = [MGLRuntimeStylingHelper testBoolFunction]; + layer.iconImageName = [MGLRuntimeStylingHelper testStringFunction]; + layer.iconKeepUpright = [MGLRuntimeStylingHelper testBoolFunction]; + layer.iconOffset = [MGLRuntimeStylingHelper testOffsetFunction]; layer.iconOptional = [MGLRuntimeStylingHelper testBoolFunction]; + layer.iconPadding = [MGLRuntimeStylingHelper testNumberFunction]; + layer.iconRotate = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]; layer.iconSize = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconTextFit = [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]; layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPaddingFunction]; - layer.iconImage = [MGLRuntimeStylingHelper testStringFunction]; - layer.iconRotate = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconPadding = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconKeepUpright = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconOffset = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; + layer.symbolAvoidEdges = [MGLRuntimeStylingHelper testBoolFunction]; + layer.symbolPlacement = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; + layer.symbolSpacing = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textAllowOverlap = [MGLRuntimeStylingHelper testBoolFunction]; + layer.textAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; layer.textField = [MGLRuntimeStylingHelper testStringFunction]; layer.textFont = [MGLRuntimeStylingHelper testFontFunction]; - layer.textSize = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textMaxWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textLineHeight = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textJustify = [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustifyRight type:@encode(MGLTextJustify)]; - layer.textAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; - layer.textMaxAngle = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textRotate = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textPadding = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textKeepUpright = [MGLRuntimeStylingHelper testBoolFunction]; - layer.textTransform = [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; - layer.textOffset = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.textAllowOverlap = [MGLRuntimeStylingHelper testBoolFunction]; layer.textIgnorePlacement = [MGLRuntimeStylingHelper testBoolFunction]; + layer.textJustify = [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustifyRight type:@encode(MGLTextJustify)]; + layer.textKeepUpright = [MGLRuntimeStylingHelper testBoolFunction]; + layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textLineHeight = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textMaxAngle = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textMaxWidth = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textOffset = [MGLRuntimeStylingHelper testOffsetFunction]; layer.textOptional = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconOpacity = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textPadding = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; + layer.textRotate = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; + layer.textSize = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textTransform = [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; layer.iconColor = [MGLRuntimeStylingHelper testColorFunction]; + layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconHaloColor = [MGLRuntimeStylingHelper testColorFunction]; layer.iconHaloWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; + layer.iconOpacity = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconTranslate = [MGLRuntimeStylingHelper testOffsetFunction]; layer.iconTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLIconTranslateAnchorViewport type:@encode(MGLIconTranslateAnchor)]; - layer.textOpacity = [MGLRuntimeStylingHelper testNumberFunction]; layer.textColor = [MGLRuntimeStylingHelper testColorFunction]; + layer.textHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; layer.textHaloColor = [MGLRuntimeStylingHelper testColorFunction]; layer.textHaloWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; + layer.textOpacity = [MGLRuntimeStylingHelper testNumberFunction]; layer.textTranslate = [MGLRuntimeStylingHelper testOffsetFunction]; layer.textTranslateAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLTextTranslateAnchorViewport type:@encode(MGLTextTranslateAnchor)]; - XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); - XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.symbolAvoidEdges, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.iconAllowOverlap, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.iconIgnorePlacement, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testStringFunction]); + XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]); XCTAssertEqualObjects(gLayer.iconSize, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]); XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPaddingFunction]); - XCTAssertEqualObjects(gLayer.iconImage, [MGLRuntimeStylingHelper testStringFunction]); - XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); - XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); + XCTAssertEqualObjects(gLayer.symbolAvoidEdges, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); + XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.textAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]); XCTAssertEqualObjects(gLayer.textField, [MGLRuntimeStylingHelper testStringFunction]); XCTAssertEqualObjects(gLayer.textFont, [MGLRuntimeStylingHelper testFontFunction]); - XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textMaxWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textJustify, [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustifyRight type:@encode(MGLTextJustify)]); - XCTAssertEqualObjects(gLayer.textAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]); - XCTAssertEqualObjects(gLayer.textMaxAngle, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textRotate, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.textTransform, [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]); - XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.textIgnorePlacement, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.textJustify, [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustifyRight type:@encode(MGLTextJustify)]); + XCTAssertEqualObjects(gLayer.textKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]); + XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textMaxAngle, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textMaxWidth, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); + XCTAssertEqualObjects(gLayer.textRotate, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); + XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textTransform, [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]); XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColorFunction]); + XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColorFunction]); XCTAssertEqualObjects(gLayer.iconHaloWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconTranslate, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.iconTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLIconTranslateAnchorViewport type:@encode(MGLIconTranslateAnchor)]); - XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.textColor, [MGLRuntimeStylingHelper testColorFunction]); + XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.textHaloColor, [MGLRuntimeStylingHelper testColorFunction]); XCTAssertEqualObjects(gLayer.textHaloWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); + XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.textTranslate, [MGLRuntimeStylingHelper testOffsetFunction]); XCTAssertEqualObjects(gLayer.textTranslateAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLTextTranslateAnchorViewport type:@encode(MGLTextTranslateAnchor)]); } From ba775404d88ddb61b7347eb14c5e39cf2df8e1dd Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 30 Nov 2016 09:26:21 -0800 Subject: [PATCH 53/67] [ios, macos] Add notes to APIs that rely on style and source ids (#6886) Update documentation to make the implications of identifiers clearer. --- platform/darwin/src/MGLStyle.h | 64 +++++++++++++++++++++++++++++++++ platform/ios/src/MGLMapView.h | 23 ++++++++++++ platform/macos/src/MGLMapView.h | 23 ++++++++++++ 3 files changed, 110 insertions(+) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index b3e1b28ee..10fad0196 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -184,6 +184,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Returns a source with the given identifier in the current style. + @note Source identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids source identifer name changes that will occur in the default + style’s sources over time. + @return An instance of a concrete subclass of `MGLSource` associated with the given identifier, or `nil` if the current style contains no such source. */ @@ -199,6 +207,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Removes a source from the current style. + @note Source identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids source identifer name changes that will occur in the default + style’s sources over time. + @param source The source to remove from the current style. */ - (void)removeSource:(MGLSource *)source; @@ -214,6 +230,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Returns a style layer with the given identifier in the current style. + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set + the style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. + @return An instance of a concrete subclass of `MGLStyleLayer` associated with the given identifier, or `nil` if the current style contains no such style layer. @@ -240,6 +264,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Inserts a new layer below another layer. + + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set + the style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. @param layer The layer to insert. @param sibling An existing layer in the style. @@ -248,6 +280,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Inserts a new layer above another layer. + + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set + the style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. @param layer The layer to insert. @param sibling An existing layer in the style. @@ -256,6 +296,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Removes a layer from the map view. + + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set + the style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. @param layer The layer object to remove from the map view. This object must conform to the `MGLStyleLayer` protocol. @@ -287,6 +335,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Deactivates the style class with the given identifier. + + @note Style class names are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids style class name changes that will occur in the default + style over time. @param styleClass The style class to deactivate. */ @@ -307,6 +363,14 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Removes a name and its associated image from the style. + + @note Names and their associated images are not guaranteed to exist across + styles or different versions of the same style. Applications that use this + API must first set the style URL to an explicitly versioned style using a + convenience method like `+[MGLStyle outdoorsStyleURLWithVersion:]`, + `MGLMapView`'s “Style URLâ€� inspectable in Interface Builder, or a manually + constructed `NSURL`. This approach also avoids image name changes that will + occur in the default style over time. @param name The name of the image to remove. */ diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 40d6519ac..771a48c7f 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -122,6 +122,13 @@ IB_DESIGNABLE Unlike the `styleURL` property, this property is set to an object that allows you to manipulate every aspect of the style locally. + + @note The default styles provided by Mapbox contain sources and layers with + identifiers that will change over time. Applications that use APIs that + manipulate a style's sources and layers must first set the style URL to an + explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. */ @property (nonatomic, readonly) MGLStyle *style; @@ -1142,6 +1149,14 @@ IB_DESIGNABLE To find out the layer names in a particular style, view the style in Mapbox Studio. + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. + @param point A point expressed in the map view’s coordinate system. @param styleLayerIdentifiers A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these @@ -1205,6 +1220,14 @@ IB_DESIGNABLE To find out the layer names in a particular style, view the style in Mapbox Studio. + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. + @param rect A rectangle expressed in the map view’s coordinate system. @param styleLayerIdentifiers A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 5ffc04e65..88745db21 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -93,6 +93,13 @@ IB_DESIGNABLE Unlike the `styleURL` property, this property is set to an object that allows you to manipulate every aspect of the style locally. + + @note The default styles provided by Mapbox contain sources and layers with + identifiers that will change over time. Applications that use APIs that + manipulate a style's sources and layers must first set the style URL to an + explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. */ @property (nonatomic, readonly) MGLStyle *style; @@ -793,6 +800,14 @@ IB_DESIGNABLE To find out the layer names in a particular style, view the style in Mapbox Studio. + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. + @param point A point expressed in the map view’s coordinate system. @param styleLayerIdentifiers A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these @@ -856,6 +871,14 @@ IB_DESIGNABLE To find out the layer names in a particular style, view the style in Mapbox Studio. + @note Layer identifiers are not guaranteed to exist across styles or different + versions of the same style. Applications that use this API must first set the + style URL to an explicitly versioned style using a convenience method like + `+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`'s “Style URLâ€� + inspectable in Interface Builder, or a manually constructed `NSURL`. This + approach also avoids layer identifer name changes that will occur in the default + style’s layers over time. + @param rect A rectangle expressed in the map view’s coordinate system. @param styleLayerIdentifiers A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these From 37a087c675b847f64dd73a570c11b4ddebac35fb Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 30 Nov 2016 11:59:29 -0800 Subject: [PATCH 54/67] [ios, macos] Avoid unsafe cast when removing style layers (#7227) This updates the code generation for style layers to add a test to check that the style object returned from mbgl can be safely cast into the expected type so ownership can be returned to the caller when removing layers. This scenario was previously possible if a layer of type T was added before a layer of type U but both layers shared the same identifier. In that case, if the pointer to the second layer of type U was used to remove a layer, a runtime exception would occur since mbgl returns the layer with type T (the first one added). Now, an exception will still occur if layers with the same identifier are manipulated as described above but it is done as part of a validation check for all public style layer methods at the Darwin platform level. The NSException attempts to warn developers about using and reusing style identifiers to avoid this issue in the first place. --- .../darwin/src/MGLBackgroundStyleLayer.mm | 25 +- platform/darwin/src/MGLCircleStyleLayer.mm | 49 +++- platform/darwin/src/MGLFillStyleLayer.mm | 49 +++- platform/darwin/src/MGLLineStyleLayer.mm | 77 ++++++- platform/darwin/src/MGLRasterStyleLayer.mm | 41 +++- platform/darwin/src/MGLStyleLayer.mm | 16 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 29 ++- platform/darwin/src/MGLStyleLayer_Private.h | 19 ++ platform/darwin/src/MGLSymbolStyleLayer.mm | 213 +++++++++++++++++- 9 files changed, 507 insertions(+), 11 deletions(-) diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 59aa06910..c8f8b39b3 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -50,42 +50,65 @@ - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::BackgroundLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setBackgroundColor:(MGLStyleValue *)backgroundColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundColor); _rawLayer->setBackgroundColor(mbglValue); } - (MGLStyleValue *)backgroundColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getBackgroundColor() ?: _rawLayer->getDefaultBackgroundColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundOpacity:(MGLStyleValue *)backgroundOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundOpacity); _rawLayer->setBackgroundOpacity(mbglValue); } - (MGLStyleValue *)backgroundOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getBackgroundOpacity() ?: _rawLayer->getDefaultBackgroundOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setBackgroundPattern:(MGLStyleValue *)backgroundPattern { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(backgroundPattern); _rawLayer->setBackgroundPattern(mbglValue); } - (MGLStyleValue *)backgroundPattern { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 1c903ab00..7768ff66c 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -45,22 +45,30 @@ namespace mbgl { } - (NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } #pragma mark - Adding to and removing from a map view @@ -82,82 +90,121 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::CircleLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setCircleBlur:(MGLStyleValue *)circleBlur { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleBlur); _rawLayer->setCircleBlur(mbglValue); } - (MGLStyleValue *)circleBlur { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleColor:(MGLStyleValue *)circleColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleColor); _rawLayer->setCircleColor(mbglValue); } - (MGLStyleValue *)circleColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleColor() ?: _rawLayer->getDefaultCircleColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleOpacity:(MGLStyleValue *)circleOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleOpacity); _rawLayer->setCircleOpacity(mbglValue); } - (MGLStyleValue *)circleOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleOpacity() ?: _rawLayer->getDefaultCircleOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); _rawLayer->setCirclePitchScale(mbglValue); } - (MGLStyleValue *)circlePitchScale { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setCircleRadius:(MGLStyleValue *)circleRadius { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(circleRadius); _rawLayer->setCircleRadius(mbglValue); } - (MGLStyleValue *)circleRadius { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setCircleTranslate:(MGLStyleValue *)circleTranslate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(circleTranslate); _rawLayer->setCircleTranslate(mbglValue); } - (MGLStyleValue *)circleTranslate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleTranslate() ?: _rawLayer->getDefaultCircleTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setCircleTranslateAnchor:(MGLStyleValue *)circleTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circleTranslateAnchor); _rawLayer->setCircleTranslateAnchor(mbglValue); } - (MGLStyleValue *)circleTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getCircleTranslateAnchor() ?: _rawLayer->getDefaultCircleTranslateAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 6f9c68f21..d1a96f723 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -40,22 +40,30 @@ namespace mbgl { } - (NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } #pragma mark - Adding to and removing from a map view @@ -77,82 +85,121 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::FillLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setFillAntialias:(MGLStyleValue *)fillAntialias { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillAntialias); _rawLayer->setFillAntialias(mbglValue); } - (MGLStyleValue *)fillAntialias { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillAntialias() ?: _rawLayer->getDefaultFillAntialias(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillColor:(MGLStyleValue *)fillColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillColor); _rawLayer->setFillColor(mbglValue); } - (MGLStyleValue *)fillColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillColor() ?: _rawLayer->getDefaultFillColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOpacity:(MGLStyleValue *)fillOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOpacity); _rawLayer->setFillOpacity(mbglValue); } - (MGLStyleValue *)fillOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillOutlineColor:(MGLStyleValue *)fillOutlineColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillOutlineColor); _rawLayer->setFillOutlineColor(mbglValue); } - (MGLStyleValue *)fillOutlineColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillOutlineColor() ?: _rawLayer->getDefaultFillOutlineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillPattern:(MGLStyleValue *)fillPattern { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(fillPattern); _rawLayer->setFillPattern(mbglValue); } - (MGLStyleValue *)fillPattern { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setFillTranslate:(MGLStyleValue *)fillTranslate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(fillTranslate); _rawLayer->setFillTranslate(mbglValue); } - (MGLStyleValue *)fillTranslate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillTranslate() ?: _rawLayer->getDefaultFillTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setFillTranslateAnchor:(MGLStyleValue *)fillTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(fillTranslateAnchor); _rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue *)fillTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index c37d1b659..a7ed2fc10 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -52,22 +52,30 @@ namespace mbgl { } - (NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } #pragma mark - Adding to and removing from a map view @@ -89,52 +97,79 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::LineLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineCap); _rawLayer->setLineCap(mbglValue); } - (MGLStyleValue *)lineCap { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineCap() ?: _rawLayer->getDefaultLineCap(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineJoin:(MGLStyleValue *)lineJoin { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); _rawLayer->setLineJoin(mbglValue); } - (MGLStyleValue *)lineJoin { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineJoin() ?: _rawLayer->getDefaultLineJoin(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineMiterLimit:(MGLStyleValue *)lineMiterLimit { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineMiterLimit); _rawLayer->setLineMiterLimit(mbglValue); } - (MGLStyleValue *)lineMiterLimit { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineMiterLimit() ?: _rawLayer->getDefaultLineMiterLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineRoundLimit:(MGLStyleValue *)lineRoundLimit { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineRoundLimit); _rawLayer->setLineRoundLimit(mbglValue); } - (MGLStyleValue *)lineRoundLimit { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineRoundLimit() ?: _rawLayer->getDefaultLineRoundLimit(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } @@ -142,101 +177,141 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes - (void)setLineBlur:(MGLStyleValue *)lineBlur { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineBlur); _rawLayer->setLineBlur(mbglValue); } - (MGLStyleValue *)lineBlur { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineBlur() ?: _rawLayer->getDefaultLineBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineColor:(MGLStyleValue *)lineColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineColor); _rawLayer->setLineColor(mbglValue); } - (MGLStyleValue *)lineColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineColor() ?: _rawLayer->getDefaultLineColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineDasharray:(MGLStyleValue *> *)lineDasharray { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSArray *, float>().toPropertyValue(lineDasharray); _rawLayer->setLineDasharray(mbglValue); } - (MGLStyleValue *> *)lineDasharray { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineDasharray() ?: _rawLayer->getDefaultLineDasharray(); return MGLStyleValueTransformer, NSArray *, float>().toStyleValue(propertyValue); } - (void)setLineGapWidth:(MGLStyleValue *)lineGapWidth { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineGapWidth); _rawLayer->setLineGapWidth(mbglValue); } - (MGLStyleValue *)lineGapWidth { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineGapWidth() ?: _rawLayer->getDefaultLineGapWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineOffset:(MGLStyleValue *)lineOffset { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOffset); _rawLayer->setLineOffset(mbglValue); } - (MGLStyleValue *)lineOffset { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineOffset() ?: _rawLayer->getDefaultLineOffset(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineOpacity:(MGLStyleValue *)lineOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineOpacity); _rawLayer->setLineOpacity(mbglValue); } - (MGLStyleValue *)lineOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineOpacity() ?: _rawLayer->getDefaultLineOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLinePattern:(MGLStyleValue *)linePattern { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(linePattern); _rawLayer->setLinePattern(mbglValue); } - (MGLStyleValue *)linePattern { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLinePattern() ?: _rawLayer->getDefaultLinePattern(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setLineTranslate:(MGLStyleValue *)lineTranslate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(lineTranslate); _rawLayer->setLineTranslate(mbglValue); } - (MGLStyleValue *)lineTranslate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineTranslate() ?: _rawLayer->getDefaultLineTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setLineTranslateAnchor:(MGLStyleValue *)lineTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineTranslateAnchor); _rawLayer->setLineTranslateAnchor(mbglValue); } - (MGLStyleValue *)lineTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineTranslateAnchor() ?: _rawLayer->getDefaultLineTranslateAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineWidth:(MGLStyleValue *)lineWidth { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(lineWidth); _rawLayer->setLineWidth(mbglValue); } - (MGLStyleValue *)lineWidth { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getLineWidth() ?: _rawLayer->getDefaultLineWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index cd1d135ff..24dba21c7 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -49,82 +49,121 @@ - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::RasterLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setMaximumRasterBrightness:(MGLStyleValue *)maximumRasterBrightness { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(maximumRasterBrightness); _rawLayer->setRasterBrightnessMax(mbglValue); } - (MGLStyleValue *)maximumRasterBrightness { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterBrightnessMax() ?: _rawLayer->getDefaultRasterBrightnessMax(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setMinimumRasterBrightness:(MGLStyleValue *)minimumRasterBrightness { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(minimumRasterBrightness); _rawLayer->setRasterBrightnessMin(mbglValue); } - (MGLStyleValue *)minimumRasterBrightness { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterBrightnessMin() ?: _rawLayer->getDefaultRasterBrightnessMin(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterContrast:(MGLStyleValue *)rasterContrast { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterContrast); _rawLayer->setRasterContrast(mbglValue); } - (MGLStyleValue *)rasterContrast { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterContrast() ?: _rawLayer->getDefaultRasterContrast(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterFadeDuration:(MGLStyleValue *)rasterFadeDuration { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterFadeDuration); _rawLayer->setRasterFadeDuration(mbglValue); } - (MGLStyleValue *)rasterFadeDuration { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterFadeDuration() ?: _rawLayer->getDefaultRasterFadeDuration(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterHueRotate:(MGLStyleValue *)rasterHueRotate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterHueRotate); _rawLayer->setRasterHueRotate(mbglValue); } - (MGLStyleValue *)rasterHueRotate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterHueRotate() ?: _rawLayer->getDefaultRasterHueRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterOpacity:(MGLStyleValue *)rasterOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterOpacity); _rawLayer->setRasterOpacity(mbglValue); } - (MGLStyleValue *)rasterOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterOpacity() ?: _rawLayer->getDefaultRasterOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setRasterSaturation:(MGLStyleValue *)rasterSaturation { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(rasterSaturation); _rawLayer->setRasterSaturation(mbglValue); } - (MGLStyleValue *)rasterSaturation { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getRasterSaturation() ?: _rawLayer->getDefaultRasterSaturation(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm index d1943cd46..6d9dabf25 100644 --- a/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/darwin/src/MGLStyleLayer.mm @@ -3,10 +3,6 @@ #include -@interface MGLStyleLayer () - -@end - @implementation MGLStyleLayer - (instancetype)initWithIdentifier:(NSString *)identifier @@ -19,6 +15,8 @@ - (void)setVisible:(BOOL)visible { + MGLAssertStyleLayerIsValid(); + mbgl::style::VisibilityType v = visible ? mbgl::style::VisibilityType::Visible : mbgl::style::VisibilityType::None; @@ -27,27 +25,37 @@ - (BOOL)isVisible { + MGLAssertStyleLayerIsValid(); + mbgl::style::VisibilityType v = self.rawLayer->getVisibility(); return (v == mbgl::style::VisibilityType::Visible); } - (void)setMaximumZoomLevel:(float)maximumZoomLevel { + MGLAssertStyleLayerIsValid(); + self.rawLayer->setMaxZoom(maximumZoomLevel); } - (float)maximumZoomLevel { + MGLAssertStyleLayerIsValid(); + return self.rawLayer->getMaxZoom(); } - (void)setMinimumZoomLevel:(float)minimumZoomLevel { + MGLAssertStyleLayerIsValid(); + self.rawLayer->setMinZoom(minimumZoomLevel); } - (float)minimumZoomLevel { + MGLAssertStyleLayerIsValid(); + return self.rawLayer->getMinZoom(); } diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index ae90b67d3..85a1af997 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -81,22 +81,30 @@ namespace mbgl { <% if (type !== 'background' && type !== 'raster') { -%> - (NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } <% } -%> @@ -119,11 +127,22 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_castLayer> &>(removedLayer)); + + mbgl::style::<%- camelize(type) %>Layer *layer = dynamic_castLayer *>(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptrLayer>(layer); _rawLayer = _pendingLayer.get(); } @@ -132,6 +151,8 @@ namespace mbgl { <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { + MGLAssertStyleLayerIsValid(); + <% if (property.type == "enum") { -%> auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); @@ -142,6 +163,8 @@ namespace mbgl { } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); @@ -157,6 +180,8 @@ namespace mbgl { <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { + MGLAssertStyleLayerIsValid(); + <% if (property.type == "enum") { -%> auto mbglValue = MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); @@ -167,6 +192,8 @@ namespace mbgl { } - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->get<%- camelize(originalPropertyName(property)) %>() ?: _rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); <% if (property.type == "enum") { -%> return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(originalPropertyName(property)) %>>().toEnumStyleValue(propertyValue); diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index bfce452a4..e723c8cf1 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -5,6 +5,25 @@ #include +/** + Assert that the style layer is valid. + + This macro should be used at the beginning of any public-facing instance method + of `MGLStyleLayer` and its subclasses. For private methods, an assertion is more appropriate. + */ +#define MGLAssertStyleLayerIsValid() \ + do { \ + if (!self.rawLayer) { \ + [NSException raise:@"Invalid style layer" \ + format: \ + @"-[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 " \ + @"different types."]; \ + } \ + } while (NO); + @class MGLMapView; @interface MGLStyleLayer (Private) diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 3e5834f7b..29fe32218 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -99,22 +99,30 @@ namespace mbgl { } - (NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { + MGLAssertStyleLayerIsValid(); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { + MGLAssertStyleLayerIsValid(); + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } #pragma mark - Adding to and removing from a map view @@ -136,352 +144,499 @@ namespace mbgl { - (void)removeFromMapView:(MGLMapView *)mapView { + _pendingLayer = nullptr; + _rawLayer = nullptr; + auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); if (!removedLayer) { return; } - _pendingLayer = std::move(reinterpret_cast &>(removedLayer)); + + mbgl::style::SymbolLayer *layer = dynamic_cast(removedLayer.get()); + if (!layer) { + return; + } + + removedLayer.release(); + + _pendingLayer = std::unique_ptr(layer); _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Layout Attributes - (void)setIconAllowOverlap:(MGLStyleValue *)iconAllowOverlap { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconAllowOverlap); _rawLayer->setIconAllowOverlap(mbglValue); } - (MGLStyleValue *)iconAllowOverlap { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconAllowOverlap() ?: _rawLayer->getDefaultIconAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconIgnorePlacement:(MGLStyleValue *)iconIgnorePlacement { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconIgnorePlacement); _rawLayer->setIconIgnorePlacement(mbglValue); } - (MGLStyleValue *)iconIgnorePlacement { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconIgnorePlacement() ?: _rawLayer->getDefaultIconIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconImageName:(MGLStyleValue *)iconImageName { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconImageName); _rawLayer->setIconImage(mbglValue); } - (MGLStyleValue *)iconImageName { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconImage() ?: _rawLayer->getDefaultIconImage(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconKeepUpright:(MGLStyleValue *)iconKeepUpright { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconKeepUpright); _rawLayer->setIconKeepUpright(mbglValue); } - (MGLStyleValue *)iconKeepUpright { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconKeepUpright() ?: _rawLayer->getDefaultIconKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOffset:(MGLStyleValue *)iconOffset { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconOffset); _rawLayer->setIconOffset(mbglValue); } - (MGLStyleValue *)iconOffset { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconOffset() ?: _rawLayer->getDefaultIconOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconOptional:(MGLStyleValue *)iconOptional { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOptional); _rawLayer->setIconOptional(mbglValue); } - (MGLStyleValue *)iconOptional { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconOptional() ?: _rawLayer->getDefaultIconOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconPadding:(MGLStyleValue *)iconPadding { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconPadding); _rawLayer->setIconPadding(mbglValue); } - (MGLStyleValue *)iconPadding { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconPadding() ?: _rawLayer->getDefaultIconPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotate:(MGLStyleValue *)iconRotate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconRotate); _rawLayer->setIconRotate(mbglValue); } - (MGLStyleValue *)iconRotate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconRotate() ?: _rawLayer->getDefaultIconRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); _rawLayer->setIconRotationAlignment(mbglValue); } - (MGLStyleValue *)iconRotationAlignment { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconRotationAlignment() ?: _rawLayer->getDefaultIconRotationAlignment(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconSize:(MGLStyleValue *)iconSize { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconSize); _rawLayer->setIconSize(mbglValue); } - (MGLStyleValue *)iconSize { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconSize() ?: _rawLayer->getDefaultIconSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTextFit:(MGLStyleValue *)iconTextFit { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTextFit); _rawLayer->setIconTextFit(mbglValue); } - (MGLStyleValue *)iconTextFit { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconTextFit() ?: _rawLayer->getDefaultIconTextFit(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconTextFitPadding:(MGLStyleValue *)iconTextFitPadding { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTextFitPadding); _rawLayer->setIconTextFitPadding(mbglValue); } - (MGLStyleValue *)iconTextFitPadding { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconTextFitPadding() ?: _rawLayer->getDefaultIconTextFitPadding(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setSymbolAvoidEdges:(MGLStyleValue *)symbolAvoidEdges { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolAvoidEdges); _rawLayer->setSymbolAvoidEdges(mbglValue); } - (MGLStyleValue *)symbolAvoidEdges { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getSymbolAvoidEdges() ?: _rawLayer->getDefaultSymbolAvoidEdges(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); _rawLayer->setSymbolPlacement(mbglValue); } - (MGLStyleValue *)symbolPlacement { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(symbolSpacing); _rawLayer->setSymbolSpacing(mbglValue); } - (MGLStyleValue *)symbolSpacing { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getSymbolSpacing() ?: _rawLayer->getDefaultSymbolSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textAllowOverlap); _rawLayer->setTextAllowOverlap(mbglValue); } - (MGLStyleValue *)textAllowOverlap { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextAllowOverlap() ?: _rawLayer->getDefaultTextAllowOverlap(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextAnchor:(MGLStyleValue *)textAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); _rawLayer->setTextAnchor(mbglValue); } - (MGLStyleValue *)textAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextField:(MGLStyleValue *)textField { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textField); _rawLayer->setTextField(mbglValue); } - (MGLStyleValue *)textField { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextField() ?: _rawLayer->getDefaultTextField(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextFont:(MGLStyleValue *> *)textFont { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSArray *, std::string>().toPropertyValue(textFont); _rawLayer->setTextFont(mbglValue); } - (MGLStyleValue *> *)textFont { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextFont() ?: _rawLayer->getDefaultTextFont(); return MGLStyleValueTransformer, NSArray *, std::string>().toStyleValue(propertyValue); } - (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textIgnorePlacement); _rawLayer->setTextIgnorePlacement(mbglValue); } - (MGLStyleValue *)textIgnorePlacement { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextIgnorePlacement() ?: _rawLayer->getDefaultTextIgnorePlacement(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextJustify:(MGLStyleValue *)textJustify { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); _rawLayer->setTextJustify(mbglValue); } - (MGLStyleValue *)textJustify { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textKeepUpright); _rawLayer->setTextKeepUpright(mbglValue); } - (MGLStyleValue *)textKeepUpright { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextKeepUpright() ?: _rawLayer->getDefaultTextKeepUpright(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLetterSpacing); _rawLayer->setTextLetterSpacing(mbglValue); } - (MGLStyleValue *)textLetterSpacing { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextLetterSpacing() ?: _rawLayer->getDefaultTextLetterSpacing(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextLineHeight:(MGLStyleValue *)textLineHeight { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textLineHeight); _rawLayer->setTextLineHeight(mbglValue); } - (MGLStyleValue *)textLineHeight { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextLineHeight() ?: _rawLayer->getDefaultTextLineHeight(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextMaxAngle:(MGLStyleValue *)textMaxAngle { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxAngle); _rawLayer->setTextMaxAngle(mbglValue); } - (MGLStyleValue *)textMaxAngle { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextMaxAngle() ?: _rawLayer->getDefaultTextMaxAngle(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextMaxWidth:(MGLStyleValue *)textMaxWidth { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textMaxWidth); _rawLayer->setTextMaxWidth(mbglValue); } - (MGLStyleValue *)textMaxWidth { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextMaxWidth() ?: _rawLayer->getDefaultTextMaxWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOffset:(MGLStyleValue *)textOffset { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textOffset); _rawLayer->setTextOffset(mbglValue); } - (MGLStyleValue *)textOffset { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextOffset() ?: _rawLayer->getDefaultTextOffset(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextOptional:(MGLStyleValue *)textOptional { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOptional); _rawLayer->setTextOptional(mbglValue); } - (MGLStyleValue *)textOptional { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextOptional() ?: _rawLayer->getDefaultTextOptional(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextPadding:(MGLStyleValue *)textPadding { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textPadding); _rawLayer->setTextPadding(mbglValue); } - (MGLStyleValue *)textPadding { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextPadding() ?: _rawLayer->getDefaultTextPadding(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); _rawLayer->setTextPitchAlignment(mbglValue); } - (MGLStyleValue *)textPitchAlignment { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextRotate:(MGLStyleValue *)textRotate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textRotate); _rawLayer->setTextRotate(mbglValue); } - (MGLStyleValue *)textRotate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextRotate() ?: _rawLayer->getDefaultTextRotate(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); _rawLayer->setTextRotationAlignment(mbglValue); } - (MGLStyleValue *)textRotationAlignment { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextSize:(MGLStyleValue *)textSize { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textSize); _rawLayer->setTextSize(mbglValue); } - (MGLStyleValue *)textSize { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextSize() ?: _rawLayer->getDefaultTextSize(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTransform:(MGLStyleValue *)textTransform { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); _rawLayer->setTextTransform(mbglValue); } - (MGLStyleValue *)textTransform { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } @@ -489,141 +644,197 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes - (void)setIconColor:(MGLStyleValue *)iconColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconColor); _rawLayer->setIconColor(mbglValue); } - (MGLStyleValue *)iconColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconColor() ?: _rawLayer->getDefaultIconColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloBlur:(MGLStyleValue *)iconHaloBlur { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloBlur); _rawLayer->setIconHaloBlur(mbglValue); } - (MGLStyleValue *)iconHaloBlur { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconHaloBlur() ?: _rawLayer->getDefaultIconHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloColor:(MGLStyleValue *)iconHaloColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloColor); _rawLayer->setIconHaloColor(mbglValue); } - (MGLStyleValue *)iconHaloColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconHaloColor() ?: _rawLayer->getDefaultIconHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconHaloWidth:(MGLStyleValue *)iconHaloWidth { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconHaloWidth); _rawLayer->setIconHaloWidth(mbglValue); } - (MGLStyleValue *)iconHaloWidth { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconHaloWidth() ?: _rawLayer->getDefaultIconHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconOpacity:(MGLStyleValue *)iconOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(iconOpacity); _rawLayer->setIconOpacity(mbglValue); } - (MGLStyleValue *)iconOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconOpacity() ?: _rawLayer->getDefaultIconOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setIconTranslate:(MGLStyleValue *)iconTranslate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(iconTranslate); _rawLayer->setIconTranslate(mbglValue); } - (MGLStyleValue *)iconTranslate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconTranslate() ?: _rawLayer->getDefaultIconTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setIconTranslateAnchor:(MGLStyleValue *)iconTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTranslateAnchor); _rawLayer->setIconTranslateAnchor(mbglValue); } - (MGLStyleValue *)iconTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getIconTranslateAnchor() ?: _rawLayer->getDefaultIconTranslateAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextColor:(MGLStyleValue *)textColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textColor); _rawLayer->setTextColor(mbglValue); } - (MGLStyleValue *)textColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextColor() ?: _rawLayer->getDefaultTextColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloBlur:(MGLStyleValue *)textHaloBlur { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloBlur); _rawLayer->setTextHaloBlur(mbglValue); } - (MGLStyleValue *)textHaloBlur { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextHaloBlur() ?: _rawLayer->getDefaultTextHaloBlur(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloColor:(MGLStyleValue *)textHaloColor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloColor); _rawLayer->setTextHaloColor(mbglValue); } - (MGLStyleValue *)textHaloColor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextHaloColor() ?: _rawLayer->getDefaultTextHaloColor(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextHaloWidth:(MGLStyleValue *)textHaloWidth { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textHaloWidth); _rawLayer->setTextHaloWidth(mbglValue); } - (MGLStyleValue *)textHaloWidth { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextHaloWidth() ?: _rawLayer->getDefaultTextHaloWidth(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextOpacity:(MGLStyleValue *)textOpacity { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toPropertyValue(textOpacity); _rawLayer->setTextOpacity(mbglValue); } - (MGLStyleValue *)textOpacity { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextOpacity() ?: _rawLayer->getDefaultTextOpacity(); return MGLStyleValueTransformer().toStyleValue(propertyValue); } - (void)setTextTranslate:(MGLStyleValue *)textTranslate { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toPropertyValue(textTranslate); _rawLayer->setTextTranslate(mbglValue); } - (MGLStyleValue *)textTranslate { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextTranslate() ?: _rawLayer->getDefaultTextTranslate(); return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); } - (void)setTextTranslateAnchor:(MGLStyleValue *)textTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTranslateAnchor); _rawLayer->setTextTranslateAnchor(mbglValue); } - (MGLStyleValue *)textTranslateAnchor { + MGLAssertStyleLayerIsValid(); + auto propertyValue = _rawLayer->getTextTranslateAnchor() ?: _rawLayer->getDefaultTextTranslateAnchor(); return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } From e9504912dc4eca1793be200cc46c14d81fbf1ee5 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 28 Nov 2016 16:14:02 -0800 Subject: [PATCH 55/67] [ios] Use new pinning cert for staging This updates the cert for the staging environment. It also adjusts the telem implementation to send along the horizontal accuracy for each location event and removes the previous battery level gathering logic. --- .../default/resources/api_mapbox_staging.der | Bin 0 -> 1334 bytes .../default/resources/star_tilestream_net.der | Bin 1273 -> 0 bytes platform/ios/ios.xcodeproj/project.pbxproj | 12 +++++------- platform/ios/src/MGLAPIClient.m | 2 +- platform/ios/src/MGLMapboxEvents.m | 15 ++++----------- 5 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 platform/default/resources/api_mapbox_staging.der delete mode 100644 platform/default/resources/star_tilestream_net.der diff --git a/platform/default/resources/api_mapbox_staging.der b/platform/default/resources/api_mapbox_staging.der new file mode 100644 index 0000000000000000000000000000000000000000..45f7df7c490f7a8e1b8c55bd5bf4098b6e89f613 GIT binary patch literal 1334 zcmXqLVl^^oVv$+SAZO- zXDDeP4t61rfRkLYerh#!HaV5ru{Yz}yS=r-?}Bv`USvLcC>{OU>A|-LFMkLd zvE(G)%IwV(*G+Fo^=wU>wyrz(c}cYK>eW7hN0~GZmkQiE@0YuuU8HV{&U3D%cY;YO-4eB(tU@239Dy$0e|tre*y;DZk_R4&$W;Dd7hB zlY0b=fBbuWz%}LUl>JfvcOGx4d3~m<)orTsHuq;fUc%bd%T`Hz6yy(^V0zEap(KAt z=!%m8hO8Qf??SRf6XSDWh&(os2L_|8GK++PSc3?EL!wNRVd7PNjpw~?7F%>49=rL-Ko+Ec zk420{L~iAi*t;*^bT8X0AnzL=#ClP(CBi@(BrV9IVxZK75fx2*Xi>ulQq0fD_@9M^ znTd4)#B5a-F#{1c4sA9@R#tXqMmUSfARDAyo+ZT~$v}UB?gH&L&5V+g0xNy}-}MBUWBvV52q_ZQ?^Cbp6AioHM!kNi{ z0XZ`OivVC|U}Wga`=pv=T6HJc)wg{5NwrHm_wIRKvetD;WBbHKQ@@_Rb^gXDG1li# zD*vw(oW)rE?WjuOCq@Yk6&7{3L#ee(DtNzmeNyLs@VokWSdRH!!!OA{+s>bu=x7|) z_bWxJNbmt{Wk z9{Tlg+QDO+y4UF0c2&e0bF{g#))l4PUfMVHM(A^i11<;TBToKO+1aqrwAWO|;yELe zL!^w>m(G({9&T~?RDZc{`me{HPZbKPr^S3Nz57~tFWdhBhmWTMUtZi%x28QZQnPs_ ZYj@!FM245Iu2gQRzNY$WN_vL^BLIrZ(PjVu literal 0 HcmV?d00001 diff --git a/platform/default/resources/star_tilestream_net.der b/platform/default/resources/star_tilestream_net.der deleted file mode 100644 index 3c7cea0ff72f758e9ca12610d4ec564defd23b45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1273 zcmXqLV)<&&#C&%FGZP~dlYp7~`S?rOQ+RuKKm3?grZLrkmyJ`a&78Jk*~T1FWZquK&Bje|$TC9}AsC^NZ4AwNyQ zIX|Z~Hz_mGP}o2aWEndTS9oG^MrK}mNq(N8sDUupWjs8-i3Lgd6*>@yNg9ZQ9mXS| zrB{-flL|C0H8EE&FSW#=iBSpJw~VX|%uS5^3_x)%rY1&4hGU_o4o}=S{hItyYnhvg z@7#0t^8>ECJ$|pDG=ufD?xF;R)vYtO@W|)s-LZwb_rfm;`ut}- zzj02hln^Oi`g(ickAIWqYft&Rn_G0r&ebcQhF<4vxi){&MV{ZH$LqGuo;HQAD#N>Gb01z z;wHvTzz|typbZR0SwR*R1EnU6plsqp3tCW$krifPGGH*^12Op-8UM4eFf*|(fS4l> zGRHt+f!qR_HmQt~k^(Dz{q#J&;>z6QB)#PPTo5O@D9502E=acmOXF07#z_W^{cLRM zjXc0)YtYzYV9&;(&Bn;e%Fe_nW(+c;7-&d&dAVMCYJLeQWr7VVN-fSWElN%;)-Ose z$S=+;$uFwZ&q+;B%rS6;8^B~>%0reBvLNTFvVd|0)G^GAa2At+JV;uZMZ!R=LF7{Y z_i0~R?Tc&-YL#!bR?J>p6IEjn4pYp?$l`6_3Df{J#(=R+7&Tl{K;AJ>gDYUd6L2NS z=^B`ef$5r&!Aw;>@c@hb=3ne9Q&miFt~^ Date: Tue, 29 Nov 2016 12:55:07 -0800 Subject: [PATCH 56/67] [ios, android] Move der files to ios platform .der files are used only by the iOS platform for SSL pinning. This moves them out of the `platform/default/resources` directory and into `platform/ios/resources`. The make configuration for Android is updated so that it stops attempting to copy the files at all. --- platform/android/config.cmake | 3 -- platform/ios/ios.xcodeproj/project.pbxproj | 34 +++++++++--------- .../resources/api_mapbox_com-digicert.der | Bin .../resources/api_mapbox_com-geotrust.der | Bin .../resources/api_mapbox_staging.der | Bin platform/ios/src/MGLMapboxEvents.m | 3 +- 6 files changed, 19 insertions(+), 21 deletions(-) rename platform/{default => ios}/resources/api_mapbox_com-digicert.der (100%) rename platform/{default => ios}/resources/api_mapbox_com-geotrust.der (100%) rename platform/{default => ios}/resources/api_mapbox_staging.der (100%) diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 74412e4ae..05037589f 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -180,9 +180,6 @@ add_custom_target(copy-files COMMAND ${STRIP_COMMAND} $ -o ${ANDROID_JNI_TARGET_DIR}$ COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_ASSETS_TARGET_DIR} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/common/ca-bundle.crt ${ANDROID_ASSETS_TARGET_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/api_mapbox_com-digicert.der ${ANDROID_ASSETS_TARGET_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/api_mapbox_com-geotrust.der ${ANDROID_ASSETS_TARGET_DIR} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/star_tilestream_net.der ${ANDROID_ASSETS_TARGET_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_TEST_APP_JNI_TARGET_DIR} COMMAND ${STRIP_COMMAND} $ -o ${ANDROID_TEST_APP_JNI_TARGET_DIR}$ ) diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index a1ad742b1..86f522439 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -143,7 +143,13 @@ 404C26E51D89B877000AA13D /* MGLTileSet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 404C26E11D89B877000AA13D /* MGLTileSet.mm */; }; 404C26E71D89C55D000AA13D /* MGLTileSet_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 404C26E61D89C515000AA13D /* MGLTileSet_Private.h */; }; 404C26E81D89C55D000AA13D /* MGLTileSet_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 404C26E61D89C515000AA13D /* MGLTileSet_Private.h */; }; + 40599F0C1DEE1B7600182B5D /* api_mapbox_staging.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F001DEE1B2400182B5D /* api_mapbox_staging.der */; }; + 40599F0D1DEE1B7A00182B5D /* api_mapbox_com-digicert.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F011DEE1B2400182B5D /* api_mapbox_com-digicert.der */; }; + 40599F0E1DEE1B7E00182B5D /* api_mapbox_com-geotrust.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F021DEE1B2400182B5D /* api_mapbox_com-geotrust.der */; }; 4085AF091D933DEA00F11B22 /* MGLTileSetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4085AF081D933DEA00F11B22 /* MGLTileSetTests.mm */; }; + 408982E91DEE208200754016 /* api_mapbox_staging.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F001DEE1B2400182B5D /* api_mapbox_staging.der */; }; + 408982EA1DEE208B00754016 /* api_mapbox_com-digicert.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F011DEE1B2400182B5D /* api_mapbox_com-digicert.der */; }; + 408982EB1DEE209100754016 /* api_mapbox_com-geotrust.der in Resources */ = {isa = PBXBuildFile; fileRef = 40599F021DEE1B2400182B5D /* api_mapbox_com-geotrust.der */; }; 408AA8571DAEDA1700022900 /* NSDictionary+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 408AA8551DAEDA0800022900 /* NSDictionary+MGLAdditions.h */; }; 408AA8581DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */; }; 408AA8591DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */; }; @@ -152,7 +158,6 @@ 40EDA1C01CFE0E0200D9EA68 /* MGLAnnotationContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */; }; 40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; }; 40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; }; - 40F2631B1DECE003009B635C /* api_mapbox_staging.der in Resources */ = {isa = PBXBuildFile; fileRef = 40F2631A1DECE003009B635C /* api_mapbox_staging.der */; }; 40F887701D7A1E58008ECB67 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */; }; 40F887711D7A1E59008ECB67 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */; }; 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; }; @@ -293,8 +298,6 @@ DA8848731CBAFCC100AB86E3 /* mapbox.png in Resources */ = {isa = PBXBuildFile; fileRef = DA8848691CBAFCC100AB86E3 /* mapbox.png */; }; DA8848741CBAFCC100AB86E3 /* mapbox@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DA88486A1CBAFCC100AB86E3 /* mapbox@2x.png */; }; DA8848751CBAFCC100AB86E3 /* mapbox@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = DA88486B1CBAFCC100AB86E3 /* mapbox@3x.png */; }; - DA88487A1CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der in Resources */ = {isa = PBXBuildFile; fileRef = DA8848771CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der */; }; - DA88487B1CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der in Resources */ = {isa = PBXBuildFile; fileRef = DA8848781CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der */; }; DA8848841CBB033F00AB86E3 /* FABAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8848801CBB033F00AB86E3 /* FABAttributes.h */; }; DA8848851CBB033F00AB86E3 /* FABKitProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8848811CBB033F00AB86E3 /* FABKitProtocol.h */; }; DA8848861CBB033F00AB86E3 /* Fabric+FABKits.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8848821CBB033F00AB86E3 /* Fabric+FABKits.h */; }; @@ -307,8 +310,6 @@ DA8933BF1CCD2CAD00E68420 /* Foundation.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DA8933BD1CCD2CAD00E68420 /* Foundation.stringsdict */; }; DA8933DB1CCD31D400E68420 /* Foundation.strings in Resources */ = {isa = PBXBuildFile; fileRef = DA8933BA1CCD2CA100E68420 /* Foundation.strings */; }; DA8933DC1CCD31D400E68420 /* Foundation.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DA8933BD1CCD2CAD00E68420 /* Foundation.stringsdict */; }; - DA8933DD1CCD31D400E68420 /* api_mapbox_com-digicert.der in Resources */ = {isa = PBXBuildFile; fileRef = DA8848771CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der */; }; - DA8933DE1CCD31D400E68420 /* api_mapbox_com-geotrust.der in Resources */ = {isa = PBXBuildFile; fileRef = DA8848781CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der */; }; DA8933E01CCD31DF00E68420 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DA89339F1CCC951200E68420 /* Localizable.strings */; }; DA8933E11CCD31DF00E68420 /* Compass.png in Resources */ = {isa = PBXBuildFile; fileRef = DA8848631CBAFCC100AB86E3 /* Compass.png */; }; DA8933E21CCD31DF00E68420 /* Compass@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DA8848641CBAFCC100AB86E3 /* Compass@2x.png */; }; @@ -574,6 +575,9 @@ 404C26E01D89B877000AA13D /* MGLTileSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLTileSet.h; sourceTree = ""; }; 404C26E11D89B877000AA13D /* MGLTileSet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLTileSet.mm; sourceTree = ""; }; 404C26E61D89C515000AA13D /* MGLTileSet_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLTileSet_Private.h; sourceTree = ""; }; + 40599F001DEE1B2400182B5D /* api_mapbox_staging.der */ = {isa = PBXFileReference; lastKnownFileType = file; path = api_mapbox_staging.der; sourceTree = ""; }; + 40599F011DEE1B2400182B5D /* api_mapbox_com-digicert.der */ = {isa = PBXFileReference; lastKnownFileType = file; path = "api_mapbox_com-digicert.der"; sourceTree = ""; }; + 40599F021DEE1B2400182B5D /* api_mapbox_com-geotrust.der */ = {isa = PBXFileReference; lastKnownFileType = file; path = "api_mapbox_com-geotrust.der"; sourceTree = ""; }; 4085AF081D933DEA00F11B22 /* MGLTileSetTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLTileSetTests.mm; path = ../../darwin/test/MGLTileSetTests.mm; sourceTree = ""; }; 408AA8551DAEDA0800022900 /* NSDictionary+MGLAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+MGLAdditions.h"; sourceTree = ""; }; 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSDictionary+MGLAdditions.mm"; sourceTree = ""; }; @@ -581,7 +585,6 @@ 40CFA6501D787579008103BD /* MGLGeoJSONSourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLGeoJSONSourceTests.mm; path = ../../darwin/test/MGLGeoJSONSourceTests.mm; sourceTree = ""; }; 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView.h; sourceTree = ""; }; 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAnnotationContainerView.m; sourceTree = ""; }; - 40F2631A1DECE003009B635C /* api_mapbox_staging.der */ = {isa = PBXFileReference; lastKnownFileType = file; name = api_mapbox_staging.der; path = ../../default/resources/api_mapbox_staging.der; sourceTree = ""; }; 40F8876F1D7A1DB8008ECB67 /* MGLGeoJSONSource_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLGeoJSONSource_Private.h; sourceTree = ""; }; 40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = ""; }; 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAnnotationView.m; sourceTree = ""; }; @@ -718,8 +721,6 @@ DA8848691CBAFCC100AB86E3 /* mapbox.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mapbox.png; sourceTree = ""; }; DA88486A1CBAFCC100AB86E3 /* mapbox@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "mapbox@2x.png"; sourceTree = ""; }; DA88486B1CBAFCC100AB86E3 /* mapbox@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "mapbox@3x.png"; sourceTree = ""; }; - DA8848771CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der */ = {isa = PBXFileReference; lastKnownFileType = file; name = "api_mapbox_com-digicert.der"; path = "../../default/resources/api_mapbox_com-digicert.der"; sourceTree = ""; }; - DA8848781CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der */ = {isa = PBXFileReference; lastKnownFileType = file; name = "api_mapbox_com-geotrust.der"; path = "../../default/resources/api_mapbox_com-geotrust.der"; sourceTree = ""; }; DA8848801CBB033F00AB86E3 /* FABAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FABAttributes.h; sourceTree = ""; }; DA8848811CBB033F00AB86E3 /* FABKitProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FABKitProtocol.h; sourceTree = ""; }; DA8848821CBB033F00AB86E3 /* Fabric+FABKits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Fabric+FABKits.h"; sourceTree = ""; }; @@ -1137,9 +1138,6 @@ children = ( DA89339F1CCC951200E68420 /* Localizable.strings */, DAC49C5F1CD02BC9009E1AA3 /* Localizable.stringsdict */, - 40F2631A1DECE003009B635C /* api_mapbox_staging.der */, - DA8848771CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der */, - DA8848781CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der */, DA8848631CBAFCC100AB86E3 /* Compass.png */, DA8848641CBAFCC100AB86E3 /* Compass@2x.png */, DA8848651CBAFCC100AB86E3 /* Compass@3x.png */, @@ -1150,6 +1148,9 @@ DA88486A1CBAFCC100AB86E3 /* mapbox@2x.png */, DA88486B1CBAFCC100AB86E3 /* mapbox@3x.png */, DA8933EF1CCD387900E68420 /* strip-frameworks.sh */, + 40599F001DEE1B2400182B5D /* api_mapbox_staging.der */, + 40599F011DEE1B2400182B5D /* api_mapbox_com-digicert.der */, + 40599F021DEE1B2400182B5D /* api_mapbox_com-geotrust.der */, ); name = "Kit Resources"; path = resources; @@ -1815,9 +1816,6 @@ DA8848731CBAFCC100AB86E3 /* mapbox.png in Resources */, DA8933BC1CCD2CA100E68420 /* Foundation.strings in Resources */, DA8848741CBAFCC100AB86E3 /* mapbox@2x.png in Resources */, - DA88487B1CBAFD5C00AB86E3 /* api_mapbox_com-geotrust.der in Resources */, - DA88487A1CBAFD5C00AB86E3 /* api_mapbox_com-digicert.der in Resources */, - 40F2631B1DECE003009B635C /* api_mapbox_staging.der in Resources */, DA8933A31CCC95B000E68420 /* Localizable.strings in Resources */, DA88486D1CBAFCC100AB86E3 /* Compass.png in Resources */, DA8848721CBAFCC100AB86E3 /* default_marker@3x.png in Resources */, @@ -1829,6 +1827,9 @@ DA8848751CBAFCC100AB86E3 /* mapbox@3x.png in Resources */, DAC49C5C1CD02BC9009E1AA3 /* Localizable.stringsdict in Resources */, DA8933BF1CCD2CAD00E68420 /* Foundation.stringsdict in Resources */, + 408982E91DEE208200754016 /* api_mapbox_staging.der in Resources */, + 408982EA1DEE208B00754016 /* api_mapbox_com-digicert.der in Resources */, + 408982EB1DEE209100754016 /* api_mapbox_com-geotrust.der in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1848,9 +1849,10 @@ DA8933E91CCD31DF00E68420 /* mapbox@3x.png in Resources */, DA8933DB1CCD31D400E68420 /* Foundation.strings in Resources */, DA8933DC1CCD31D400E68420 /* Foundation.stringsdict in Resources */, - DA8933DD1CCD31D400E68420 /* api_mapbox_com-digicert.der in Resources */, DAC49C5D1CD02BC9009E1AA3 /* Localizable.stringsdict in Resources */, - DA8933DE1CCD31D400E68420 /* api_mapbox_com-geotrust.der in Resources */, + 40599F0C1DEE1B7600182B5D /* api_mapbox_staging.der in Resources */, + 40599F0D1DEE1B7A00182B5D /* api_mapbox_com-digicert.der in Resources */, + 40599F0E1DEE1B7E00182B5D /* api_mapbox_com-geotrust.der in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/platform/default/resources/api_mapbox_com-digicert.der b/platform/ios/resources/api_mapbox_com-digicert.der similarity index 100% rename from platform/default/resources/api_mapbox_com-digicert.der rename to platform/ios/resources/api_mapbox_com-digicert.der diff --git a/platform/default/resources/api_mapbox_com-geotrust.der b/platform/ios/resources/api_mapbox_com-geotrust.der similarity index 100% rename from platform/default/resources/api_mapbox_com-geotrust.der rename to platform/ios/resources/api_mapbox_com-geotrust.der diff --git a/platform/default/resources/api_mapbox_staging.der b/platform/ios/resources/api_mapbox_staging.der similarity index 100% rename from platform/default/resources/api_mapbox_staging.der rename to platform/ios/resources/api_mapbox_staging.der diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m index a8de1bb58..210f66bc2 100644 --- a/platform/ios/src/MGLMapboxEvents.m +++ b/platform/ios/src/MGLMapboxEvents.m @@ -656,13 +656,12 @@ const NSTimeInterval MGLFlushInterval = 180; double accuracy = 10000000; double lat = floor(loc.coordinate.latitude * accuracy) / accuracy; double lng = floor(loc.coordinate.longitude * accuracy) / accuracy; - double horizontalAccuracy = loc.horizontalAccuracy; NSString *formattedDate = [self.rfc3339DateFormatter stringFromDate:loc.timestamp]; [MGLMapboxEvents pushEvent:MGLEventTypeLocation withAttributes:@{MGLEventKeyCreated: formattedDate, MGLEventKeyLatitude: @(lat), MGLEventKeyLongitude: @(lng), MGLEventKeyAltitude: @(round(loc.altitude)), - MGLEventHorizontalAccuracy: @(horizontalAccuracy)}]; + MGLEventHorizontalAccuracy: @(loc.horizontalAccuracy)}]; } } From 7e9457214a0672f4ba21fa48ce5491174633cb68 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 29 Nov 2016 16:30:37 -0800 Subject: [PATCH 57/67] [ios, macos] Add back support for CONTAINS operator This reverts commit 6877e3efe73fb6e103c2635f1e4b1c1866b17d5c. --- .../darwin/src/NSComparisonPredicate+MGLAdditions.mm | 7 ++++++- platform/darwin/test/MGLFilterTests.mm | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm index aa0e456bb..19c264aa4 100644 --- a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm @@ -68,6 +68,12 @@ filter.values = self.rightExpression.mgl_filterValues; return filter; } + case NSContainsPredicateOperatorType: { + auto filter = mbgl::style::InFilter(); + filter.key = [self.rightExpression.constantValue UTF8String]; + filter.values = self.leftExpression.mgl_filterValues; + return filter; + } case NSBetweenPredicateOperatorType: { auto filter = mbgl::style::AllFilter(); auto gteFilter = mbgl::style::GreaterThanEqualsFilter(); @@ -85,7 +91,6 @@ case NSBeginsWithPredicateOperatorType: case NSEndsWithPredicateOperatorType: case NSCustomSelectorPredicateOperatorType: - case NSContainsPredicateOperatorType: [NSException raise:@"Unsupported operator type" format:@"NSPredicateOperatorType:%lu is not supported.", (unsigned long)self.predicateOperatorType]; } diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index 2bb188575..b18400f83 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -74,6 +74,18 @@ [self.mapView.style addLayer:layer]; } +- (void)testContainsPredicate +{ + // core does not have a "contains" filter but we can achieve the equivalent by creating an `mbgl::style::InFilter` + // and searching the value for the key + NSPredicate *expectedPredicate = [NSPredicate predicateWithFormat:@"park IN %@", @[@"park", @"neighbourhood"]]; + NSPredicate *containsPredicate = [NSPredicate predicateWithFormat:@"%@ CONTAINS %@", @[@"park", @"neighbourhood"], @"park"]; + + layer.predicate = containsPredicate; + XCTAssertEqualObjects(layer.predicate, expectedPredicate); + [self.mapView.style addLayer:layer]; +} + - (void)testBetweenPredicate { // core does not have a "between" filter but we can achieve the equivalent by creating a set of greater than or equal / less than or equal From b2c2d4ebc4041d4ca5d71bf589dfa5826ec5bf46 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 30 Nov 2016 11:53:34 -0800 Subject: [PATCH 58/67] [ios, macos] Update style predicate documentation Note the support of CONTAINS and the lack of support for case and diacritic operator modifiers. --- platform/darwin/src/MGLVectorStyleLayer.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h index 13bb9e79a..e2a755083 100644 --- a/platform/darwin/src/MGLVectorStyleLayer.h +++ b/platform/darwin/src/MGLVectorStyleLayer.h @@ -52,10 +52,11 @@ NS_ASSUME_NONNULL_BEGIN
  • NSNotPredicateType (NOT, !)
  • - The following aggregate operator is supported: + The following aggregate operators are supported:
    • NSInPredicateOperatorType (IN)
    • +
    • NSContainsPredicateOperatorType (CONTAINS)
    To test whether a feature has or lacks a specific attribute, compare the attribute to `NULL` or `NIL`. Predicates created using the `+[NSPredicate predicateWithValue:]` method are also supported. String operators and custom operators are not supported. @@ -118,7 +119,9 @@ NS_ASSUME_NONNULL_BEGIN Automatic type casting is not performed. Therefore, a feature only matches this predicate if its value for the attribute in question is of the same type as the - value specified in the predicate. + value specified in the predicate. Also, operator modifiers `c`, `d`, and the + combined `cd` for case and diacritic insensitivity are unsupported for + comparison and aggregate operators that are used in the predicate. */ @property (nonatomic, nullable) NSPredicate *predicate; From 5dd71d3c3048c1a521f65f3a2f7b13c9c0fed279 Mon Sep 17 00:00:00 2001 From: Jesse Crocker Date: Thu, 1 Dec 2016 11:50:20 -0800 Subject: [PATCH 59/67] =?UTF-8?q?[ios,=20macos]=20Make=20tap=20gesture=20r?= =?UTF-8?q?ecognizer=20fail=20if=20it=20doesn=E2=80=99t=20do=20anything=20?= =?UTF-8?q?(#7246)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make tap gesture recognizer fail if it doesn’t do anything. * fix typo * Use the right nullable * update changelog * Make single click gesture recognizer fail if it doesn’t select an annotation * fix changelog typo * Remove singleTapGestureRecognizer from public header --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 64 +++++++++++++++++++++++--------- platform/macos/CHANGELOG.md | 1 + platform/macos/src/MGLMapView.mm | 24 ++++++++++-- 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index b395fa6bb..d904c3ceb 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -83,6 +83,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) * MGLMapDebugOverdrawVisualizationMask no longer has any effect in Release builds of the SDK. This debug mask has been disabled for performance reasons. ([#5555](https://github.com/mapbox/mapbox-gl-native/pull/5555)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) +* The UITapGestureRecognizer on MGLMapView that is used for selecting annotations now fails if a tap does not select an annotation. ([#7246](https://github.com/mapbox/mapbox-gl-native/pull/7246)) ## 3.3.6 - November 9, 2016 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 68a1196fa..5c365ad87 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -236,9 +236,8 @@ public: @property (nonatomic, readwrite) UIButton *attributionButton; @property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *attributionButtonConstraints; @property (nonatomic) UIActionSheet *attributionSheet; - @property (nonatomic, readwrite) MGLStyle *style; - +@property (nonatomic) UITapGestureRecognizer *singleTapGestureRecognizer; @property (nonatomic) UIPanGestureRecognizer *pan; @property (nonatomic) UIPinchGestureRecognizer *pinch; @property (nonatomic) UIRotationGestureRecognizer *rotate; @@ -502,9 +501,10 @@ public: doubleTap.numberOfTapsRequired = 2; [self addGestureRecognizer:doubleTap]; - UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)]; - [singleTap requireGestureRecognizerToFail:doubleTap]; - [self addGestureRecognizer:singleTap]; + _singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)]; + [_singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTap]; + _singleTapGestureRecognizer.delegate = self; + [self addGestureRecognizer:_singleTapGestureRecognizer]; UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTapGesture:)]; twoFingerTap.numberOfTouchesRequired = 2; @@ -1398,6 +1398,27 @@ public: return; } + idannotation = [self annotationForGestureRecognizer:singleTap persistingResults:YES]; + if(annotation) + { + [self selectAnnotation:annotation animated:YES]; + } + else + { + [self deselectAnnotation:self.selectedAnnotation animated:YES]; + } +} + +/** + Returns the annotation that would be selected by a tap gesture recognizer. + + This is used when a gesture is recognized, and to check if the gesture should be recognized. + + @param singleTap An in progress tap gesture recognizer. + @param persist True to remember the cycleable set of annotations. @see annotationTagAtPoint:persistingResults + */ +- (nullable id )annotationForGestureRecognizer:(UITapGestureRecognizer*)singleTap persistingResults:(BOOL)persist +{ CGPoint tapPoint = [singleTap locationInView:self]; if (self.userLocationVisible) @@ -1412,19 +1433,19 @@ public: // Get the tap point within the custom hit test layer. tapPointForUserLocation = [singleTap locationInView:self.userLocationAnnotationView]; } - + CALayer *hitLayer = [self.userLocationAnnotationView.hitTestLayer hitTest:tapPointForUserLocation]; - + if (hitLayer) { if ( ! _userLocationAnnotationIsSelected) { - [self selectAnnotation:self.userLocation animated:YES]; + return self.userLocation; } - return; + return nil; } } - + // Handle the case of an offset annotation view by converting the tap point to be the geo location // of the annotation itself that the view represents for (MGLAnnotationView *view in self.annotationContainerView.annotationViews) @@ -1436,21 +1457,19 @@ public: } } } - - MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:YES]; + + MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:persist]; if (hitAnnotationTag != MGLAnnotationTagNotFound) { if (hitAnnotationTag != _selectedAnnotationTag) { id annotation = [self annotationWithTag:hitAnnotationTag]; NSAssert(annotation, @"Cannot select nonexistent annotation with tag %u", hitAnnotationTag); - [self selectAnnotation:annotation animated:YES]; + return annotation; } } - else - { - [self deselectAnnotation:self.selectedAnnotation animated:YES]; - } + + return nil; } - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap @@ -1608,6 +1627,17 @@ public: } } } + else if (gestureRecognizer == _singleTapGestureRecognizer) + { + //Gesture will be recognized if it could deselect an annotation + if(!self.selectedAnnotation) + { + idannotation = [self annotationForGestureRecognizer:(UITapGestureRecognizer*)gestureRecognizer persistingResults:NO]; + if(!annotation) { + return NO; + } + } + } return YES; } diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 9675ec844..37e51d7c5 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -57,6 +57,7 @@ * Fixed an issue where the map view’s center would always be calculated as if the view occupied the entire window. ([#6102](https://github.com/mapbox/mapbox-gl-native/pull/6102)) * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) +* The NSClickGestureRecognizer on MGLMapView that is used for selecting annotations now fails if a click does not select an annotation. ([#7246](https://github.com/mapbox/mapbox-gl-native/pull/7246)) ## 0.2.1 - July 19, 2016 diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index ba0704826..204efd498 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -145,7 +145,7 @@ public: NSString *imageReuseIdentifier; }; -@interface MGLMapView () +@interface MGLMapView () @property (nonatomic, readwrite) NSSegmentedControl *zoomControls; @property (nonatomic, readwrite) NSSlider *compass; @@ -172,6 +172,7 @@ public: NSPanGestureRecognizer *_panGestureRecognizer; NSMagnificationGestureRecognizer *_magnificationGestureRecognizer; NSRotationGestureRecognizer *_rotationGestureRecognizer; + NSClickGestureRecognizer *_singleClickRecognizer; double _scaleAtBeginningOfGesture; CLLocationDirection _directionAtBeginningOfGesture; CGFloat _pitchAtBeginningOfGesture; @@ -408,9 +409,10 @@ public: _panGestureRecognizer.delaysKeyEvents = YES; [self addGestureRecognizer:_panGestureRecognizer]; - NSClickGestureRecognizer *clickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleClickGesture:)]; - clickGestureRecognizer.delaysPrimaryMouseButtonEvents = NO; - [self addGestureRecognizer:clickGestureRecognizer]; + _singleClickRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleClickGesture:)]; + _singleClickRecognizer.delaysPrimaryMouseButtonEvents = NO; + _singleClickRecognizer.delegate = self; + [self addGestureRecognizer:_singleClickRecognizer]; NSClickGestureRecognizer *rightClickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightClickGesture:)]; rightClickGestureRecognizer.buttonMask = 0x2; @@ -1540,6 +1542,20 @@ public: return nil; } +#pragma mark NSGestureRecognizerDelegate methods +- (BOOL)gestureRecognizer:(NSGestureRecognizer *)gestureRecognizer shouldAttemptToRecognizeWithEvent:(NSEvent *)event { + if (gestureRecognizer == _singleClickRecognizer) { + if (!self.selectedAnnotation) { + NSPoint gesturePoint = [self convertPoint:[event locationInWindow] fromView:nil]; + MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:gesturePoint persistingResults:NO]; + if (hitAnnotationTag == MGLAnnotationTagNotFound) { + return NO; + } + } + } + return YES; +} + #pragma mark Keyboard events - (void)keyDown:(NSEvent *)event { From 8317a11a10400c28e36017a9441e18d49f99acd0 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 1 Dec 2016 17:02:12 -0800 Subject: [PATCH 60/67] [ios] Update changlog for ios-v3.3.7 --- platform/ios/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index d904c3ceb..6c51404a3 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -85,6 +85,10 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) * The UITapGestureRecognizer on MGLMapView that is used for selecting annotations now fails if a tap does not select an annotation. ([#7246](https://github.com/mapbox/mapbox-gl-native/pull/7246)) +## 3.3.7 - November 17, 2016 + +* This version is the same as 3.3.6 but it is built with Xcode 8 that produces a smaller binary. Developers using this version in Swift applications built with Xcode 7.3.1 should use the unstripped, `*-symbols` framework. + ## 3.3.6 - November 9, 2016 * Fixed a crash that occurred during low-memory situations when multiple instances of MGLMapView were in the view hierarchy. The speculative fix in v3.3.5 has been reverted. ([#6972](https://github.com/mapbox/mapbox-gl-native/pull/6972)) From 2c4e7ae70f68eecf56707f0ebd9810340f41e6a3 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Mon, 28 Nov 2016 17:35:10 +0200 Subject: [PATCH 61/67] =?UTF-8?q?[core]=20guard=20against=20duplicate=20so?= =?UTF-8?q?urce=20id=E2=80=99s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mbgl/style/style.cpp | 10 ++++++++++ test/style/style.test.cpp | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index d57f5cf98..e55119f9f 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -136,6 +136,16 @@ void Style::setJSON(const std::string& json) { } void Style::addSource(std::unique_ptr source) { + //Guard against duplicate source ids + auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& existing) { + return existing->getID() == source->getID(); + }); + + if (it != sources.end()) { + std::string msg = "Source " + source->getID() + " already exists"; + throw std::runtime_error(msg.c_str()); + } + source->baseImpl->setObserver(this); sources.emplace_back(std::move(source)); } diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index 41f12f6ff..89c5c4ce6 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -3,10 +3,13 @@ #include #include +#include #include #include #include +#include + using namespace mbgl; using namespace mbgl::style; @@ -113,3 +116,21 @@ TEST(Style, Properties) { ASSERT_EQ(0, style.getDefaultZoom()); ASSERT_EQ(0, style.getDefaultPitch()); } + +TEST(Style, DuplicateSource) { + util::RunLoop loop; + + StubFileSource fileSource; + Style style { fileSource, 1.0 }; + + style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); + + style.addSource(std::make_unique("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); + + try { + style.addSource(std::make_unique("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); + FAIL() << "Should not have been allowed to add a duplicate source id"; + } catch (std::runtime_error) { + //Expected + } +} From d44d1c8401f38982905bce3166eaad8431661263 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 29 Nov 2016 17:38:34 +0200 Subject: [PATCH 62/67] [ios, macos] renamed MGLStyleLayerTests to MGLMapViewTests --- .../darwin/src/MGLRuntimeStylingTests.m.ejs | 4 ++-- .../test/MGLBackgroundStyleLayerTests.m | 4 ++-- .../darwin/test/MGLCircleStyleLayerTests.m | 4 ++-- platform/darwin/test/MGLFillStyleLayerTests.m | 4 ++-- platform/darwin/test/MGLFilterTests.mm | 4 ++-- platform/darwin/test/MGLLineStyleLayerTests.m | 4 ++-- ...MGLStyleLayerTests.h => MGLMapViewTests.h} | 2 +- ...MGLStyleLayerTests.m => MGLMapViewTests.m} | 6 +++--- ...tyleLayerTests.xib => MGLMapViewTests.xib} | 4 ++-- .../darwin/test/MGLRasterStyleLayerTests.m | 4 ++-- .../darwin/test/MGLSymbolStyleLayerTests.m | 4 ++-- platform/ios/ios.xcodeproj/project.pbxproj | 16 +++++++-------- .../macos/macos.xcodeproj/project.pbxproj | 20 +++++++++---------- 13 files changed, 40 insertions(+), 40 deletions(-) rename platform/darwin/test/{MGLStyleLayerTests.h => MGLMapViewTests.h} (75%) rename platform/darwin/test/{MGLStyleLayerTests.m => MGLMapViewTests.m} (81%) rename platform/darwin/test/{MGLStyleLayerTests.xib => MGLMapViewTests.xib} (91%) diff --git a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs index 720ee4547..c1492167b 100644 --- a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs +++ b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs @@ -6,9 +6,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGL<%- camelize(type) %>LayerTests : MGLStyleLayerTests +@interface MGL<%- camelize(type) %>LayerTests : MGLMapViewTests @end @implementation MGL<%- camelize(type) %>LayerTests diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m index 09bed7665..56e4297c2 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLBackgroundLayerTests : MGLStyleLayerTests +@interface MGLBackgroundLayerTests : MGLMapViewTests @end @implementation MGLBackgroundLayerTests diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m index 432d3ffa7..2a8d5432d 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ b/platform/darwin/test/MGLCircleStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLCircleLayerTests : MGLStyleLayerTests +@interface MGLCircleLayerTests : MGLMapViewTests @end @implementation MGLCircleLayerTests diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m index 87846302e..44319e801 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ b/platform/darwin/test/MGLFillStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLFillLayerTests : MGLStyleLayerTests +@interface MGLFillLayerTests : MGLMapViewTests @end @implementation MGLFillLayerTests diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index b18400f83..3e19a73f4 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -1,10 +1,10 @@ -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" #import "NSPredicate+MGLAdditions.h" #import "MGLValueEvaluator.h" -@interface MGLFilterTests : MGLStyleLayerTests { +@interface MGLFilterTests : MGLMapViewTests { MGLGeoJSONSource *source; MGLLineStyleLayer *layer; } diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m index 95983b1f5..521efe4de 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ b/platform/darwin/test/MGLLineStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLLineLayerTests : MGLStyleLayerTests +@interface MGLLineLayerTests : MGLMapViewTests @end @implementation MGLLineLayerTests diff --git a/platform/darwin/test/MGLStyleLayerTests.h b/platform/darwin/test/MGLMapViewTests.h similarity index 75% rename from platform/darwin/test/MGLStyleLayerTests.h rename to platform/darwin/test/MGLMapViewTests.h index f81e075e0..da9428116 100644 --- a/platform/darwin/test/MGLStyleLayerTests.h +++ b/platform/darwin/test/MGLMapViewTests.h @@ -2,7 +2,7 @@ #import "MGLRuntimeStylingHelper.h" #import -@interface MGLStyleLayerTests : XCTestCase +@interface MGLMapViewTests : XCTestCase @property (nonatomic) IBOutlet MGLMapView *mapView; @property (nonatomic) XCTestExpectation *expectation; diff --git a/platform/darwin/test/MGLStyleLayerTests.m b/platform/darwin/test/MGLMapViewTests.m similarity index 81% rename from platform/darwin/test/MGLStyleLayerTests.m rename to platform/darwin/test/MGLMapViewTests.m index 74c6b2f90..63ff3501c 100644 --- a/platform/darwin/test/MGLStyleLayerTests.m +++ b/platform/darwin/test/MGLMapViewTests.m @@ -1,6 +1,6 @@ -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@implementation MGLStyleLayerTests +@implementation MGLMapViewTests - (void)setUp { [super setUp]; @@ -14,7 +14,7 @@ _mapView.delegate = self; #else [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"MGLStyleLayerTests" owner:self]; + NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"MGLMapViewTests" owner:self]; [windowController showWindow:nil]; #endif } diff --git a/platform/darwin/test/MGLStyleLayerTests.xib b/platform/darwin/test/MGLMapViewTests.xib similarity index 91% rename from platform/darwin/test/MGLStyleLayerTests.xib rename to platform/darwin/test/MGLMapViewTests.xib index 23ad22e7e..cc336191e 100644 --- a/platform/darwin/test/MGLStyleLayerTests.xib +++ b/platform/darwin/test/MGLMapViewTests.xib @@ -4,14 +4,14 @@ - + - + diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m index 84fd0fe3e..4d37495e9 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ b/platform/darwin/test/MGLRasterStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLRasterLayerTests : MGLStyleLayerTests +@interface MGLRasterLayerTests : MGLMapViewTests @end @implementation MGLRasterLayerTests diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index e77c4f6f3..036a88fc1 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLStyleLayerTests.h" +#import "MGLMapViewTests.h" -@interface MGLSymbolLayerTests : MGLStyleLayerTests +@interface MGLSymbolLayerTests : MGLMapViewTests @end @implementation MGLSymbolLayerTests diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 86f522439..388d8172b 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -190,7 +190,7 @@ DA25D5CD1CCDA11500607828 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = DA25D5B91CCD9EDE00607828 /* Settings.bundle */; }; DA27C24E1CBB3811000B0ECD /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA27C24D1CBB3811000B0ECD /* GLKit.framework */; }; DA27C24F1CBB4C11000B0ECD /* MGLAccountManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8847FF1CBAFA6200AB86E3 /* MGLAccountManager_Private.h */; }; - DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */; }; + DA2DBBCE1D51E80400D38FF9 /* MGLMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */; }; DA2E88561CC036F400F24E7B /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA8847D21CBAF91600AB86E3 /* Mapbox.framework */; }; DA2E88611CC0382C00F24E7B /* MGLGeometryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */; }; DA2E88621CC0382C00F24E7B /* MGLOfflinePackTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */; }; @@ -619,8 +619,8 @@ DA25D5BF1CCD9F8400607828 /* Root.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Root.plist; sourceTree = ""; }; DA25D5C51CCDA06800607828 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Root.strings; sourceTree = ""; }; DA27C24D1CBB3811000B0ECD /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; - DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLStyleLayerTests.h; path = ../../darwin/test/MGLStyleLayerTests.h; sourceTree = ""; }; - DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLStyleLayerTests.m; path = ../../darwin/test/MGLStyleLayerTests.m; sourceTree = ""; }; + DA2DBBCC1D51E80400D38FF9 /* MGLMapViewTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLMapViewTests.h; path = ../../darwin/test/MGLMapViewTests.h; sourceTree = ""; }; + DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLMapViewTests.m; path = ../../darwin/test/MGLMapViewTests.m; sourceTree = ""; }; DA2E88511CC036F400F24E7B /* test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = test.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; DA2E88551CC036F400F24E7B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLGeometryTests.mm; path = ../../darwin/test/MGLGeometryTests.mm; sourceTree = ""; }; @@ -898,11 +898,11 @@ 357579811D502AD4000B822E /* Styling */ = { isa = PBXGroup; children = ( - DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */, 3575798F1D513EF1000B822E /* Layers */, 35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */, - 40CFA64E1D78754A008103BD /* Sources */, DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */, + 40CFA64E1D78754A008103BD /* Sources */, + DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */, ); name = Styling; sourceTree = ""; @@ -910,8 +910,6 @@ 3575798F1D513EF1000B822E /* Layers */ = { isa = PBXGroup; children = ( - DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */, - DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */, 3575797F1D501E09000B822E /* MGLFillStyleLayerTests.m */, 357579821D502AE6000B822E /* MGLRasterStyleLayerTests.m */, 357579841D502AF5000B822E /* MGLSymbolStyleLayerTests.m */, @@ -1058,6 +1056,8 @@ DA35A2A91CCA058D00E826B2 /* MGLCoordinateFormatterTests.m */, DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */, DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */, + DA2DBBCC1D51E80400D38FF9 /* MGLMapViewTests.h */, + DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */, 35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */, DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */, DA2E885E1CC0382C00F24E7B /* MGLOfflineRegionTests.m */, @@ -1895,7 +1895,7 @@ DA2E88611CC0382C00F24E7B /* MGLGeometryTests.mm in Sources */, 357579801D501E09000B822E /* MGLFillStyleLayerTests.m in Sources */, DA2E88641CC0382C00F24E7B /* MGLOfflineStorageTests.m in Sources */, - DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */, + DA2DBBCE1D51E80400D38FF9 /* MGLMapViewTests.m in Sources */, DA35A2C61CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m in Sources */, 3575798E1D502EC7000B822E /* MGLRuntimeStylingHelper.m in Sources */, 4085AF091D933DEA00F11B22 /* MGLTileSetTests.mm in Sources */, diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 0a74d25d4..7e1c84418 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -60,7 +60,7 @@ 55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; DA2207BC1DC076940002F84D /* MGLStyleValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2207BB1DC076940002F84D /* MGLStyleValueTests.swift */; }; - DA2DBBCB1D51E30A00D38FF9 /* MGLStyleLayerTests.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */; }; + DA2DBBCB1D51E30A00D38FF9 /* MGLMapViewTests.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */; }; DA35A2A41CC9EB1A00E826B2 /* MGLCoordinateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA35A2A61CC9EB2700E826B2 /* MGLCoordinateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */; }; DA35A2A81CC9F41600E826B2 /* MGLCoordinateFormatterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */; }; @@ -87,7 +87,7 @@ DA87A9981DC9D88400810D09 /* MGLGeoJSONSourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA87A9961DC9D88400810D09 /* MGLGeoJSONSourceTests.mm */; }; DA87A9991DC9D88400810D09 /* MGLTileSetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA87A9971DC9D88400810D09 /* MGLTileSetTests.mm */; }; DA87A99C1DC9D8DD00810D09 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA87A99B1DC9D8DD00810D09 /* MGLGeoJSONSource_Private.h */; }; - DA87A99D1DC9DB2E00810D09 /* MGLStyleLayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBC81D51E26600D38FF9 /* MGLStyleLayerTests.m */; }; + DA87A99D1DC9DB2E00810D09 /* MGLMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */; }; DA87A99E1DC9DC2100810D09 /* MGLFilterTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35C5D84B1D6DD75B00E95907 /* MGLFilterTests.mm */; }; DA87A9A01DC9DC6200810D09 /* MGLValueEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = DA87A99F1DC9DC6200810D09 /* MGLValueEvaluator.h */; }; DA87A9A11DC9DCB400810D09 /* MGLRuntimeStylingHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8F257B1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.m */; }; @@ -294,9 +294,9 @@ DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA2207BA1DC076930002F84D /* test-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "test-Bridging-Header.h"; sourceTree = ""; }; DA2207BB1DC076940002F84D /* MGLStyleValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MGLStyleValueTests.swift; sourceTree = ""; }; - DA2DBBC71D51E26600D38FF9 /* MGLStyleLayerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLStyleLayerTests.h; path = ../darwin/test/MGLStyleLayerTests.h; sourceTree = SOURCE_ROOT; }; - DA2DBBC81D51E26600D38FF9 /* MGLStyleLayerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLStyleLayerTests.m; path = ../darwin/test/MGLStyleLayerTests.m; sourceTree = SOURCE_ROOT; }; - DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MGLStyleLayerTests.xib; sourceTree = ""; }; + DA2DBBC71D51E26600D38FF9 /* MGLMapViewTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLMapViewTests.h; path = ../darwin/test/MGLMapViewTests.h; sourceTree = SOURCE_ROOT; }; + DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLMapViewTests.m; path = ../darwin/test/MGLMapViewTests.m; sourceTree = SOURCE_ROOT; }; + DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MGLMapViewTests.xib; sourceTree = ""; }; DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCoordinateFormatter.h; sourceTree = ""; }; DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLCoordinateFormatter.m; sourceTree = ""; }; DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLCoordinateFormatterTests.m; path = ../../darwin/test/MGLCoordinateFormatterTests.m; sourceTree = ""; }; @@ -649,8 +649,8 @@ isa = PBXGroup; children = ( DA2207BA1DC076930002F84D /* test-Bridging-Header.h */, - DA2DBBC71D51E26600D38FF9 /* MGLStyleLayerTests.h */, - DA2DBBC81D51E26600D38FF9 /* MGLStyleLayerTests.m */, + DA2DBBC71D51E26600D38FF9 /* MGLMapViewTests.h */, + DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */, DA8F25741D51C5F40010E6B5 /* MGLFillStyleLayerTests.m */, DA8F25751D51C5F40010E6B5 /* MGLRasterStyleLayerTests.m */, DA8F25761D51C5F40010E6B5 /* MGLSymbolStyleLayerTests.m */, @@ -659,7 +659,7 @@ DA8F25791D51C5F40010E6B5 /* MGLBackgroundStyleLayerTests.m */, DA8F257A1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.h */, DA8F257B1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.m */, - DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */, + DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */, ); name = Layers; sourceTree = ""; @@ -1150,7 +1150,7 @@ buildActionMask = 2147483647; files = ( 35724FC41D630502002A4AB4 /* amsterdam.geojson in Resources */, - DA2DBBCB1D51E30A00D38FF9 /* MGLStyleLayerTests.xib in Resources */, + DA2DBBCB1D51E30A00D38FF9 /* MGLMapViewTests.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1251,7 +1251,7 @@ DA87A9A41DCACC5000810D09 /* MGLSymbolStyleLayerTests.m in Sources */, DAE6C3D51CC34C9900DB3429 /* MGLOfflineStorageTests.m in Sources */, DA87A9A61DCACC5000810D09 /* MGLCircleStyleLayerTests.m in Sources */, - DA87A99D1DC9DB2E00810D09 /* MGLStyleLayerTests.m in Sources */, + DA87A99D1DC9DB2E00810D09 /* MGLMapViewTests.m in Sources */, DA87A99E1DC9DC2100810D09 /* MGLFilterTests.mm in Sources */, DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */, DA87A9A71DCACC5000810D09 /* MGLBackgroundStyleLayerTests.m in Sources */, From 37026a14ff12fcf2fbad02b95fc7847908ce31d5 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Mon, 28 Nov 2016 18:15:50 +0200 Subject: [PATCH 63/67] [ios, macos] handle duplicate source error --- platform/darwin/src/MGLStyle.mm | 7 ++++++- platform/ios/ios.xcodeproj/project.pbxproj | 4 ++++ platform/ios/test/MGLSourceTests.m | 24 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 platform/ios/test/MGLSourceTests.m diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index e11ceb028..a722c993a 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -183,7 +183,12 @@ static NSURL *MGLStyleURL_emerald; @"Make sure the source was created as a member of a concrete subclass of MGLSource.", source]; } - [source addToMapView:self.mapView]; + + try { + [source addToMapView:self.mapView]; + } catch (std::runtime_error & err) { + [NSException raise:@"Could not add source" format:@"%s", err.what()]; + } } - (void)removeSource:(MGLSource *)source diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 388d8172b..04d9648c0 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -171,6 +171,7 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; + 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; @@ -595,6 +596,7 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; + 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceTests.m; sourceTree = ""; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -900,6 +902,7 @@ children = ( 3575798F1D513EF1000B822E /* Layers */, 35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */, + 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */, DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */, 40CFA64E1D78754A008103BD /* Sources */, DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */, @@ -1913,6 +1916,7 @@ 357579831D502AE6000B822E /* MGLRasterStyleLayerTests.m in Sources */, 353D23961D0B0DFE002BE09D /* MGLAnnotationViewTests.m in Sources */, 35E208A71D24210F00EC9A46 /* MGLNSDataAdditionsTests.m in Sources */, + 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */, DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/ios/test/MGLSourceTests.m b/platform/ios/test/MGLSourceTests.m new file mode 100644 index 000000000..90ec4e3a0 --- /dev/null +++ b/platform/ios/test/MGLSourceTests.m @@ -0,0 +1,24 @@ +#import "MGLMapViewTests.h" + +@interface MGLSourceTests : MGLMapViewTests + +@end + +@implementation MGLSourceTests + +- (void)testDuplicateSources { + MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + + [self.mapView.style addSource: source1]; + + @try { + [self.mapView.style addSource: source2]; + XCTFail(@"Should not have reached this point"); + } + @catch (NSException *e) { + XCTAssertNotNil(e, @"Should have thrown an exception"); + } +} + +@end From 2db31be8bc0130ac2f02bc2245b1ff21103e9baf Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 2 Dec 2016 13:03:05 -0800 Subject: [PATCH 64/67] [ios, macos] Rename MGLMapViewTests back to MGLStyleLayerTests --- .../darwin/src/MGLRuntimeStylingTests.m.ejs | 4 ++-- .../test/MGLBackgroundStyleLayerTests.m | 4 ++-- .../darwin/test/MGLCircleStyleLayerTests.m | 4 ++-- platform/darwin/test/MGLFillStyleLayerTests.m | 4 ++-- platform/darwin/test/MGLFilterTests.mm | 4 ++-- platform/darwin/test/MGLLineStyleLayerTests.m | 4 ++-- .../darwin/test/MGLRasterStyleLayerTests.m | 4 ++-- ...MGLMapViewTests.h => MGLStyleLayerTests.h} | 2 +- ...MGLMapViewTests.m => MGLStyleLayerTests.m} | 6 +++--- ...apViewTests.xib => MGLStyleLayerTests.xib} | 0 .../darwin/test/MGLSymbolStyleLayerTests.m | 4 ++-- platform/ios/ios.xcodeproj/project.pbxproj | 12 +++++------ platform/ios/test/MGLSourceTests.m | 4 ++-- .../macos/macos.xcodeproj/project.pbxproj | 20 +++++++++---------- 14 files changed, 38 insertions(+), 38 deletions(-) rename platform/darwin/test/{MGLMapViewTests.h => MGLStyleLayerTests.h} (75%) rename platform/darwin/test/{MGLMapViewTests.m => MGLStyleLayerTests.m} (81%) rename platform/darwin/test/{MGLMapViewTests.xib => MGLStyleLayerTests.xib} (100%) diff --git a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs index c1492167b..720ee4547 100644 --- a/platform/darwin/src/MGLRuntimeStylingTests.m.ejs +++ b/platform/darwin/src/MGLRuntimeStylingTests.m.ejs @@ -6,9 +6,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGL<%- camelize(type) %>LayerTests : MGLMapViewTests +@interface MGL<%- camelize(type) %>LayerTests : MGLStyleLayerTests @end @implementation MGL<%- camelize(type) %>LayerTests diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m index 56e4297c2..09bed7665 100644 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLBackgroundLayerTests : MGLMapViewTests +@interface MGLBackgroundLayerTests : MGLStyleLayerTests @end @implementation MGLBackgroundLayerTests diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m index 2a8d5432d..432d3ffa7 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ b/platform/darwin/test/MGLCircleStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLCircleLayerTests : MGLMapViewTests +@interface MGLCircleLayerTests : MGLStyleLayerTests @end @implementation MGLCircleLayerTests diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m index 44319e801..87846302e 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ b/platform/darwin/test/MGLFillStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLFillLayerTests : MGLMapViewTests +@interface MGLFillLayerTests : MGLStyleLayerTests @end @implementation MGLFillLayerTests diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index 3e19a73f4..b18400f83 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -1,10 +1,10 @@ -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" #import "NSPredicate+MGLAdditions.h" #import "MGLValueEvaluator.h" -@interface MGLFilterTests : MGLMapViewTests { +@interface MGLFilterTests : MGLStyleLayerTests { MGLGeoJSONSource *source; MGLLineStyleLayer *layer; } diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m index 521efe4de..95983b1f5 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ b/platform/darwin/test/MGLLineStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLLineLayerTests : MGLMapViewTests +@interface MGLLineLayerTests : MGLStyleLayerTests @end @implementation MGLLineLayerTests diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m index 4d37495e9..84fd0fe3e 100644 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ b/platform/darwin/test/MGLRasterStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLRasterLayerTests : MGLMapViewTests +@interface MGLRasterLayerTests : MGLStyleLayerTests @end @implementation MGLRasterLayerTests diff --git a/platform/darwin/test/MGLMapViewTests.h b/platform/darwin/test/MGLStyleLayerTests.h similarity index 75% rename from platform/darwin/test/MGLMapViewTests.h rename to platform/darwin/test/MGLStyleLayerTests.h index da9428116..f81e075e0 100644 --- a/platform/darwin/test/MGLMapViewTests.h +++ b/platform/darwin/test/MGLStyleLayerTests.h @@ -2,7 +2,7 @@ #import "MGLRuntimeStylingHelper.h" #import -@interface MGLMapViewTests : XCTestCase +@interface MGLStyleLayerTests : XCTestCase @property (nonatomic) IBOutlet MGLMapView *mapView; @property (nonatomic) XCTestExpectation *expectation; diff --git a/platform/darwin/test/MGLMapViewTests.m b/platform/darwin/test/MGLStyleLayerTests.m similarity index 81% rename from platform/darwin/test/MGLMapViewTests.m rename to platform/darwin/test/MGLStyleLayerTests.m index 63ff3501c..74c6b2f90 100644 --- a/platform/darwin/test/MGLMapViewTests.m +++ b/platform/darwin/test/MGLStyleLayerTests.m @@ -1,6 +1,6 @@ -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@implementation MGLMapViewTests +@implementation MGLStyleLayerTests - (void)setUp { [super setUp]; @@ -14,7 +14,7 @@ _mapView.delegate = self; #else [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"MGLMapViewTests" owner:self]; + NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"MGLStyleLayerTests" owner:self]; [windowController showWindow:nil]; #endif } diff --git a/platform/darwin/test/MGLMapViewTests.xib b/platform/darwin/test/MGLStyleLayerTests.xib similarity index 100% rename from platform/darwin/test/MGLMapViewTests.xib rename to platform/darwin/test/MGLStyleLayerTests.xib diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index 036a88fc1..e77c4f6f3 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -1,9 +1,9 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLSymbolLayerTests : MGLMapViewTests +@interface MGLSymbolLayerTests : MGLStyleLayerTests @end @implementation MGLSymbolLayerTests diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 04d9648c0..25dcfc725 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -191,7 +191,7 @@ DA25D5CD1CCDA11500607828 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = DA25D5B91CCD9EDE00607828 /* Settings.bundle */; }; DA27C24E1CBB3811000B0ECD /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA27C24D1CBB3811000B0ECD /* GLKit.framework */; }; DA27C24F1CBB4C11000B0ECD /* MGLAccountManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8847FF1CBAFA6200AB86E3 /* MGLAccountManager_Private.h */; }; - DA2DBBCE1D51E80400D38FF9 /* MGLMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */; }; + DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */; }; DA2E88561CC036F400F24E7B /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA8847D21CBAF91600AB86E3 /* Mapbox.framework */; }; DA2E88611CC0382C00F24E7B /* MGLGeometryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */; }; DA2E88621CC0382C00F24E7B /* MGLOfflinePackTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */; }; @@ -621,8 +621,8 @@ DA25D5BF1CCD9F8400607828 /* Root.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Root.plist; sourceTree = ""; }; DA25D5C51CCDA06800607828 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Root.strings; sourceTree = ""; }; DA27C24D1CBB3811000B0ECD /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; - DA2DBBCC1D51E80400D38FF9 /* MGLMapViewTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLMapViewTests.h; path = ../../darwin/test/MGLMapViewTests.h; sourceTree = ""; }; - DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLMapViewTests.m; path = ../../darwin/test/MGLMapViewTests.m; sourceTree = ""; }; + DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLStyleLayerTests.h; path = ../../darwin/test/MGLStyleLayerTests.h; sourceTree = ""; }; + DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLStyleLayerTests.m; path = ../../darwin/test/MGLStyleLayerTests.m; sourceTree = ""; }; DA2E88511CC036F400F24E7B /* test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = test.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; DA2E88551CC036F400F24E7B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLGeometryTests.mm; path = ../../darwin/test/MGLGeometryTests.mm; sourceTree = ""; }; @@ -1059,8 +1059,8 @@ DA35A2A91CCA058D00E826B2 /* MGLCoordinateFormatterTests.m */, DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */, DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */, - DA2DBBCC1D51E80400D38FF9 /* MGLMapViewTests.h */, - DA2DBBCD1D51E80400D38FF9 /* MGLMapViewTests.m */, + DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */, + DA2DBBCD1D51E80400D38FF9 /* MGLStyleLayerTests.m */, 35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */, DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */, DA2E885E1CC0382C00F24E7B /* MGLOfflineRegionTests.m */, @@ -1898,7 +1898,7 @@ DA2E88611CC0382C00F24E7B /* MGLGeometryTests.mm in Sources */, 357579801D501E09000B822E /* MGLFillStyleLayerTests.m in Sources */, DA2E88641CC0382C00F24E7B /* MGLOfflineStorageTests.m in Sources */, - DA2DBBCE1D51E80400D38FF9 /* MGLMapViewTests.m in Sources */, + DA2DBBCE1D51E80400D38FF9 /* MGLStyleLayerTests.m in Sources */, DA35A2C61CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m in Sources */, 3575798E1D502EC7000B822E /* MGLRuntimeStylingHelper.m in Sources */, 4085AF091D933DEA00F11B22 /* MGLTileSetTests.mm in Sources */, diff --git a/platform/ios/test/MGLSourceTests.m b/platform/ios/test/MGLSourceTests.m index 90ec4e3a0..3e913d90f 100644 --- a/platform/ios/test/MGLSourceTests.m +++ b/platform/ios/test/MGLSourceTests.m @@ -1,6 +1,6 @@ -#import "MGLMapViewTests.h" +#import "MGLStyleLayerTests.h" -@interface MGLSourceTests : MGLMapViewTests +@interface MGLSourceTests : MGLStyleLayerTests @end diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 7e1c84418..fdfc1b9f0 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -54,13 +54,14 @@ 40ABDB561DB0022100372083 /* NSImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 405C03971DB0004E001AC280 /* NSImage+MGLAdditions.mm */; }; 40B77E451DB11BC9003DA2FE /* NSArray+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 40B77E431DB11BB0003DA2FE /* NSArray+MGLAdditions.h */; }; 40B77E461DB11BCD003DA2FE /* NSArray+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 40B77E421DB11BB0003DA2FE /* NSArray+MGLAdditions.mm */; }; + 40E1601D1DF217D6005EA6D9 /* MGLStyleLayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 40E1601B1DF216E6005EA6D9 /* MGLStyleLayerTests.m */; }; 52BECB0A1CC5A26F009CD791 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52BECB091CC5A26F009CD791 /* SystemConfiguration.framework */; }; 5548BE781D09E718005DDE81 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DAE6C3451CC31D1200DB3429 /* libmbgl-core.a */; }; 558F18221D0B13B100123F46 /* libmbgl-loop.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 558F18211D0B13B000123F46 /* libmbgl-loop.a */; }; 55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; DA2207BC1DC076940002F84D /* MGLStyleValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2207BB1DC076940002F84D /* MGLStyleValueTests.swift */; }; - DA2DBBCB1D51E30A00D38FF9 /* MGLMapViewTests.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */; }; + DA2DBBCB1D51E30A00D38FF9 /* MGLStyleLayerTests.xib in Resources */ = {isa = PBXBuildFile; fileRef = DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */; }; DA35A2A41CC9EB1A00E826B2 /* MGLCoordinateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA35A2A61CC9EB2700E826B2 /* MGLCoordinateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */; }; DA35A2A81CC9F41600E826B2 /* MGLCoordinateFormatterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */; }; @@ -87,7 +88,6 @@ DA87A9981DC9D88400810D09 /* MGLGeoJSONSourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA87A9961DC9D88400810D09 /* MGLGeoJSONSourceTests.mm */; }; DA87A9991DC9D88400810D09 /* MGLTileSetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA87A9971DC9D88400810D09 /* MGLTileSetTests.mm */; }; DA87A99C1DC9D8DD00810D09 /* MGLGeoJSONSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA87A99B1DC9D8DD00810D09 /* MGLGeoJSONSource_Private.h */; }; - DA87A99D1DC9DB2E00810D09 /* MGLMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */; }; DA87A99E1DC9DC2100810D09 /* MGLFilterTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35C5D84B1D6DD75B00E95907 /* MGLFilterTests.mm */; }; DA87A9A01DC9DC6200810D09 /* MGLValueEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = DA87A99F1DC9DC6200810D09 /* MGLValueEvaluator.h */; }; DA87A9A11DC9DCB400810D09 /* MGLRuntimeStylingHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8F257B1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.m */; }; @@ -285,6 +285,8 @@ 408AA8611DAEED3300022900 /* MGLPolyline+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolyline+MGLAdditions.h"; sourceTree = ""; }; 40B77E421DB11BB0003DA2FE /* NSArray+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSArray+MGLAdditions.mm"; sourceTree = ""; }; 40B77E431DB11BB0003DA2FE /* NSArray+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MGLAdditions.h"; sourceTree = ""; }; + 40E1601A1DF216E6005EA6D9 /* MGLStyleLayerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayerTests.h; sourceTree = ""; }; + 40E1601B1DF216E6005EA6D9 /* MGLStyleLayerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLStyleLayerTests.m; sourceTree = ""; }; 52BECB091CC5A26F009CD791 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 5548BE791D0ACBB2005DDE81 /* libmbgl-loop-darwin.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-loop-darwin.a"; path = "cmake/Debug/libmbgl-loop-darwin.a"; sourceTree = ""; }; 5548BE7B1D0ACBBD005DDE81 /* libmbgl-loop-darwin.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-loop-darwin.a"; path = "cmake/Debug/libmbgl-loop-darwin.a"; sourceTree = ""; }; @@ -294,9 +296,7 @@ DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA2207BA1DC076930002F84D /* test-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "test-Bridging-Header.h"; sourceTree = ""; }; DA2207BB1DC076940002F84D /* MGLStyleValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MGLStyleValueTests.swift; sourceTree = ""; }; - DA2DBBC71D51E26600D38FF9 /* MGLMapViewTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MGLMapViewTests.h; path = ../darwin/test/MGLMapViewTests.h; sourceTree = SOURCE_ROOT; }; - DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLMapViewTests.m; path = ../darwin/test/MGLMapViewTests.m; sourceTree = SOURCE_ROOT; }; - DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MGLMapViewTests.xib; sourceTree = ""; }; + DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MGLStyleLayerTests.xib; sourceTree = ""; }; DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCoordinateFormatter.h; sourceTree = ""; }; DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLCoordinateFormatter.m; sourceTree = ""; }; DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLCoordinateFormatterTests.m; path = ../../darwin/test/MGLCoordinateFormatterTests.m; sourceTree = ""; }; @@ -648,9 +648,9 @@ DA8F257C1D51C5F40010E6B5 /* Layers */ = { isa = PBXGroup; children = ( + 40E1601A1DF216E6005EA6D9 /* MGLStyleLayerTests.h */, + 40E1601B1DF216E6005EA6D9 /* MGLStyleLayerTests.m */, DA2207BA1DC076930002F84D /* test-Bridging-Header.h */, - DA2DBBC71D51E26600D38FF9 /* MGLMapViewTests.h */, - DA2DBBC81D51E26600D38FF9 /* MGLMapViewTests.m */, DA8F25741D51C5F40010E6B5 /* MGLFillStyleLayerTests.m */, DA8F25751D51C5F40010E6B5 /* MGLRasterStyleLayerTests.m */, DA8F25761D51C5F40010E6B5 /* MGLSymbolStyleLayerTests.m */, @@ -659,7 +659,7 @@ DA8F25791D51C5F40010E6B5 /* MGLBackgroundStyleLayerTests.m */, DA8F257A1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.h */, DA8F257B1D51C5F40010E6B5 /* MGLRuntimeStylingHelper.m */, - DA2DBBCA1D51E30A00D38FF9 /* MGLMapViewTests.xib */, + DA2DBBCA1D51E30A00D38FF9 /* MGLStyleLayerTests.xib */, ); name = Layers; sourceTree = ""; @@ -1150,7 +1150,7 @@ buildActionMask = 2147483647; files = ( 35724FC41D630502002A4AB4 /* amsterdam.geojson in Resources */, - DA2DBBCB1D51E30A00D38FF9 /* MGLMapViewTests.xib in Resources */, + DA2DBBCB1D51E30A00D38FF9 /* MGLStyleLayerTests.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1250,8 +1250,8 @@ DAE6C3D21CC34C9900DB3429 /* MGLGeometryTests.mm in Sources */, DA87A9A41DCACC5000810D09 /* MGLSymbolStyleLayerTests.m in Sources */, DAE6C3D51CC34C9900DB3429 /* MGLOfflineStorageTests.m in Sources */, + 40E1601D1DF217D6005EA6D9 /* MGLStyleLayerTests.m in Sources */, DA87A9A61DCACC5000810D09 /* MGLCircleStyleLayerTests.m in Sources */, - DA87A99D1DC9DB2E00810D09 /* MGLMapViewTests.m in Sources */, DA87A99E1DC9DC2100810D09 /* MGLFilterTests.mm in Sources */, DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */, DA87A9A71DCACC5000810D09 /* MGLBackgroundStyleLayerTests.m in Sources */, From 1db0a96927d53bc0216d48cf5add1254ae6cab89 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 1 Dec 2016 21:20:53 -0800 Subject: [PATCH 65/67] [ios, macos] Raise NSException if layer or source added more than once When MGLSource and MGLLayer instances are added to the style, they lose ownership of their std::unique_ptr after it is moved to the mbgl level. Subsequent attempts to add such instances result in a C++ exception. This adds logic in the Darwin platform to raise a NSException if the source and layer addToMapView methods are called more than once and the pointer is invalid. In addition, the documentation in MGLStyle for addSource: and addLayer: has been update to warn developers to avoid adding the same instance twice and, for that matter, instances with the same identifier. --- .../darwin/src/MGLBackgroundStyleLayer.mm | 6 ++ platform/darwin/src/MGLCircleStyleLayer.mm | 6 ++ platform/darwin/src/MGLFillStyleLayer.mm | 6 ++ platform/darwin/src/MGLGeoJSONSource.mm | 6 ++ platform/darwin/src/MGLLineStyleLayer.mm | 6 ++ platform/darwin/src/MGLRasterSource.mm | 6 ++ platform/darwin/src/MGLRasterStyleLayer.mm | 6 ++ platform/darwin/src/MGLStyle.h | 15 +++++ platform/darwin/src/MGLStyleLayer.mm.ejs | 6 ++ platform/darwin/src/MGLSymbolStyleLayer.mm | 6 ++ platform/darwin/src/MGLVectorSource.mm | 6 ++ platform/darwin/test/MGLStyleTests.mm | 61 ++++++++++++++++++- 12 files changed, 135 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index c8f8b39b3..253414852 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -35,6 +35,12 @@ - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 7768ff66c..91f91a7bc 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -75,6 +75,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index d1a96f723..87a5144c6 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -70,6 +70,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index f7cd6be7d..8b37ba47c 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -61,6 +61,12 @@ const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"M - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingSource == nullptr) { + [NSException raise:@"MGLRedundantSourceException" + format:@"This instance %@ was already added to %@. Adding the same source instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + mapView.mbglMap->addSource(std::move(_pendingSource)); } diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index a7ed2fc10..b155ec65d 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -82,6 +82,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index 53caae5af..62472050e 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -62,6 +62,12 @@ - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingSource == nullptr) { + [NSException raise:@"MGLRedundantSourceException" + format:@"This instance %@ was already added to %@. Adding the same source instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + mapView.mbglMap->addSource(std::move(_pendingSource)); } diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 24dba21c7..3b2c3bd83 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -34,6 +34,12 @@ - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 10fad0196..31808290f 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -200,6 +200,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new source to the current style. + @note Adding the same source instance more than once or reusing source + identifers in the sources you add will trigger exceptions. + @param source The source to add to the current style. */ - (void)addSource:(MGLSource *)source; @@ -247,6 +250,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new layer on top of existing layers. + @note Adding the same layer instance more than once or reusing layer + identifers in the layers you add will trigger exceptions. + @param layer The layer object to add to the map view. This object must be an instance of a concrete subclass of `MGLStyleLayer`. */ @@ -255,6 +261,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Inserts a new layer into the style at the given index. + @note Adding the same layer instance more than once or reusing layer + identifers in the layers you add will trigger exceptions. + @param layer The layer to insert. @param index The index at which to insert the layer. An index of 0 would send the layer to the back; an index equal to the number of objects in the @@ -272,6 +281,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; inspectable in Interface Builder, or a manually constructed `NSURL`. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time. + + Adding the same layer instance more than once or reusing layer identifers in + the layers you add will trigger exceptions. @param layer The layer to insert. @param sibling An existing layer in the style. @@ -288,6 +300,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; inspectable in Interface Builder, or a manually constructed `NSURL`. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time. + + Adding the same layer instance more than once or reusing layer identifers in + the layers you add will trigger exceptions. @param layer The layer to insert. @param sibling An existing layer in the style. diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 85a1af997..c89912c1f 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -112,6 +112,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 29fe32218..d1d66f8ff 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -129,6 +129,12 @@ namespace mbgl { - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingLayer == nullptr) { + [NSException raise:@"MGLRedundantLayerException" + format:@"This instance %@ was already added to %@. Adding the same layer instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + [self addToMapView:mapView belowLayer:nil]; } diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index ae69456b4..ab68d45ba 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -59,6 +59,12 @@ - (void)addToMapView:(MGLMapView *)mapView { + if (_pendingSource == nullptr) { + [NSException raise:@"MGLRedundantSourceException" + format:@"This instance %@ was already added to %@. Adding the same source instance " \ + "to the style more than once is invalid.", self, mapView.style]; + } + mapView.mbglMap->addSource(std::move(_pendingSource)); } diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 07e012edc..6a6a4a827 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -1,4 +1,16 @@ -#import "MGLStyle.h" +#import "MGLMapView.h" +#import "MGLStyle_Private.h" + +#import "MGLGeoJSONSource.h" +#import "MGLRasterSource.h" +#import "MGLVectorSource.h" + +#import "MGLBackgroundStyleLayer.h" +#import "MGLCircleStyleLayer.h" +#import "MGLFillStyleLayer.h" +#import "MGLLineStyleLayer.h" +#import "MGLRasterStyleLayer.h" +#import "MGLSymbolStyleLayer.h" #import "NSBundle+MGLAdditions.h" @@ -92,6 +104,53 @@ }]; } +- (void)testAddingSourcesTwice { + MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView]; + + MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; + [style addSource:geoJSONSource]; + XCTAssertThrowsSpecificNamed([style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException"); + + MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42]; + [style addSource:rasterSource]; + XCTAssertThrowsSpecificNamed([style addSource:rasterSource], NSException, @"MGLRedundantSourceException"); + + MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" URL:[NSURL new]]; + [style addSource:vectorSource]; + XCTAssertThrowsSpecificNamed([style addSource:vectorSource], NSException, @"MGLRedundantSourceException"); +} + +- (void)testAddingLayersTwice { + MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; + + MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"]; + [style addLayer:backgroundLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException"); + + MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" source:source]; + [style addLayer:circleLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:circleLayer], NSException, @"MGLRedundantLayerException"); + + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:source]; + [style addLayer:fillLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:fillLayer], NSException, @"MGLRedundantLayerException"); + + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"lineLayer" source:source]; + [style addLayer:lineLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:lineLayer], NSException, @"MGLRedundantLayerException"); + + MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"rasterLayer" source:source]; + [style addLayer:rasterLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException"); + + MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" source:source]; + [style addLayer:symbolLayer]; + XCTAssertThrowsSpecificNamed([style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException"); +} + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] From 179e9c610fcc771f0c94db09cda720aabc28b752 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 2 Dec 2016 13:47:48 -0800 Subject: [PATCH 66/67] [ios, macos] Consolidate tests of MGLStyle addSource in MGLStyleTests This replaces the integration test of `addSource` when duplicate identifiers are used in `MGLSourceTests` with a more direct unit test in the style class's unit test file `MGLStyleTests`. Although tests of the case where the same instance are actually integration tests where the source instance itself throws, it is easier to test all of this functionality in one place using the public facing MGLStyle API. --- platform/darwin/src/MGLStyle.mm | 2 +- platform/darwin/test/MGLStyleTests.mm | 60 +++++++++++++--------- platform/ios/ios.xcodeproj/project.pbxproj | 4 -- platform/ios/test/MGLSourceTests.m | 24 --------- 4 files changed, 38 insertions(+), 52 deletions(-) delete mode 100644 platform/ios/test/MGLSourceTests.m diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index a722c993a..56dc4ad8f 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -187,7 +187,7 @@ static NSURL *MGLStyleURL_emerald; try { [source addToMapView:self.mapView]; } catch (std::runtime_error & err) { - [NSException raise:@"Could not add source" format:@"%s", err.what()]; + [NSException raise:@"MGLRedundantSourceIdentiferException" format:@"%s", err.what()]; } } diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 6a6a4a827..4c0c163b3 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -20,10 +20,21 @@ #import @interface MGLStyleTests : XCTestCase + +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) MGLStyle *style; + @end @implementation MGLStyleTests +- (void)setUp { + [super setUp]; + + self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + self.style = [[MGLStyle alloc] initWithMapView:self.mapView]; +} + - (void)testUnversionedStyleURLs { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" @@ -105,50 +116,53 @@ } - (void)testAddingSourcesTwice { - MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; - MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView]; - MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; - [style addSource:geoJSONSource]; - XCTAssertThrowsSpecificNamed([style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException"); + [self.style addSource:geoJSONSource]; + XCTAssertThrowsSpecificNamed([self.style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException"); MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42]; - [style addSource:rasterSource]; - XCTAssertThrowsSpecificNamed([style addSource:rasterSource], NSException, @"MGLRedundantSourceException"); + [self.style addSource:rasterSource]; + XCTAssertThrowsSpecificNamed([self.style addSource:rasterSource], NSException, @"MGLRedundantSourceException"); MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" URL:[NSURL new]]; - [style addSource:vectorSource]; - XCTAssertThrowsSpecificNamed([style addSource:vectorSource], NSException, @"MGLRedundantSourceException"); + [self.style addSource:vectorSource]; + XCTAssertThrowsSpecificNamed([self.style addSource:vectorSource], NSException, @"MGLRedundantSourceException"); +} + +- (void)testAddingSourcesWithDuplicateIdentifiers { + MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + + [self.style addSource: source1]; + XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentiferException"); } - (void)testAddingLayersTwice { - MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; - MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"]; - [style addLayer:backgroundLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:backgroundLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException"); MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" source:source]; - [style addLayer:circleLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:circleLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:circleLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:circleLayer], NSException, @"MGLRedundantLayerException"); MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:source]; - [style addLayer:fillLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:fillLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:fillLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:fillLayer], NSException, @"MGLRedundantLayerException"); MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"lineLayer" source:source]; - [style addLayer:lineLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:lineLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:lineLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:lineLayer], NSException, @"MGLRedundantLayerException"); MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"rasterLayer" source:source]; - [style addLayer:rasterLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:rasterLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException"); MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" source:source]; - [style addLayer:symbolLayer]; - XCTAssertThrowsSpecificNamed([style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException"); + [self.style addLayer:symbolLayer]; + XCTAssertThrowsSpecificNamed([self.style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException"); } - (NSString *)stringWithContentsOfStyleHeader { diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 25dcfc725..a5c042a08 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -171,7 +171,6 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; - 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; @@ -596,7 +595,6 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; - 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceTests.m; sourceTree = ""; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -902,7 +900,6 @@ children = ( 3575798F1D513EF1000B822E /* Layers */, 35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */, - 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */, DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */, 40CFA64E1D78754A008103BD /* Sources */, DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */, @@ -1916,7 +1913,6 @@ 357579831D502AE6000B822E /* MGLRasterStyleLayerTests.m in Sources */, 353D23961D0B0DFE002BE09D /* MGLAnnotationViewTests.m in Sources */, 35E208A71D24210F00EC9A46 /* MGLNSDataAdditionsTests.m in Sources */, - 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */, DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/ios/test/MGLSourceTests.m b/platform/ios/test/MGLSourceTests.m deleted file mode 100644 index 3e913d90f..000000000 --- a/platform/ios/test/MGLSourceTests.m +++ /dev/null @@ -1,24 +0,0 @@ -#import "MGLStyleLayerTests.h" - -@interface MGLSourceTests : MGLStyleLayerTests - -@end - -@implementation MGLSourceTests - -- (void)testDuplicateSources { - MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; - MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; - - [self.mapView.style addSource: source1]; - - @try { - [self.mapView.style addSource: source2]; - XCTFail(@"Should not have reached this point"); - } - @catch (NSException *e) { - XCTAssertNotNil(e, @"Should have thrown an exception"); - } -} - -@end From 9eb7f88b2c292d322a104c4580c3ef29958b628b Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Fri, 2 Dec 2016 13:58:53 -0800 Subject: [PATCH 67/67] [ios, macos] Update MGLStyle API documentation with warnings for dupes This adds notes to the methods for adding sources and layers to warn of the hazards of using duplicate instances or identifiers. --- platform/darwin/src/MGLStyle.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index 31808290f..54ca267ba 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -199,9 +199,11 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new source to the current style. - - @note Adding the same source instance more than once or reusing source - identifers in the sources you add will trigger exceptions. + + @note Adding the same source instance more than once will result in a + `MGLRedundantSourceException`. Reusing the same source identifier, even with + different source instances, will result in a + `MGLRedundantSourceIdentiferException`. @param source The source to add to the current style. */ @@ -250,8 +252,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Adds a new layer on top of existing layers. - @note Adding the same layer instance more than once or reusing layer - identifers in the layers you add will trigger exceptions. + @note Adding the same layer instance more than once will result in a + `MGLRedundantLayerException`. Reusing the same layer identifer, even with + different layer instances, will also result in an exception. @param layer The layer object to add to the map view. This object must be an instance of a concrete subclass of `MGLStyleLayer`. @@ -261,9 +264,10 @@ static const NSInteger MGLStyleDefaultVersion = 9; /** Inserts a new layer into the style at the given index. - @note Adding the same layer instance more than once or reusing layer - identifers in the layers you add will trigger exceptions. - + @note Adding the same layer instance more than once will result in a + `MGLRedundantLayerException`. Reusing the same layer identifer, even with + different layer instances, will also result in an exception. + @param layer The layer to insert. @param index The index at which to insert the layer. An index of 0 would send the layer to the back; an index equal to the number of objects in the @@ -282,8 +286,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; approach also avoids layer identifer name changes that will occur in the default style’s layers over time. - Adding the same layer instance more than once or reusing layer identifers in - the layers you add will trigger exceptions. + Inserting the same layer instance more than once will result in a + `MGLRedundantLayerException`. Reusing the same layer identifer, even with + different layer instances, will also result in an exception. @param layer The layer to insert. @param sibling An existing layer in the style. @@ -301,8 +306,9 @@ static const NSInteger MGLStyleDefaultVersion = 9; approach also avoids layer identifer name changes that will occur in the default style’s layers over time. - Adding the same layer instance more than once or reusing layer identifers in - the layers you add will trigger exceptions. + Inserting the same layer instance more than once will result in a + `MGLRedundantLayerException`. Reusing the same layer identifer, even with + different layer instances, will also result in an exception. @param layer The layer to insert. @param sibling An existing layer in the style.