summaryrefslogtreecommitdiff
path: root/platform/darwin/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src')
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLBackgroundStyleLayer.mm2
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.h10
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLFillExtrusionStyleLayer.h6
-rw-r--r--platform/darwin/src/MGLFillExtrusionStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLGeometry_Private.h11
-rw-r--r--platform/darwin/src/MGLHeatmapStyleLayer.h8
-rw-r--r--platform/darwin/src/MGLHeatmapStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLHillshadeStyleLayer.h4
-rw-r--r--platform/darwin/src/MGLHillshadeStyleLayer.mm2
-rw-r--r--platform/darwin/src/MGLLight.h2
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLMapSnapshotter.mm11
-rw-r--r--platform/darwin/src/MGLMultiPoint.mm2
-rw-r--r--platform/darwin/src/MGLOverlay.h5
-rw-r--r--platform/darwin/src/MGLPointCollection.mm2
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.h14
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.mm2
-rw-r--r--platform/darwin/src/MGLShapeSource.mm2
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm.ejs4
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h34
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.mm4
-rw-r--r--platform/darwin/src/MGLVectorTileSource.mm25
-rw-r--r--platform/darwin/src/MGLVectorTileSource_Private.h2
-rw-r--r--platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm2
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm77
-rw-r--r--platform/darwin/src/NSPredicate+MGLAdditions.h51
-rw-r--r--platform/darwin/src/NSPredicate+MGLAdditions.mm221
-rw-r--r--platform/darwin/src/NSPredicate+MGLPrivateAdditions.h25
33 files changed, 242 insertions, 324 deletions
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h
index d5c3ed5403..31755c8bad 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.h
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.h
@@ -96,7 +96,7 @@ which it is added.
The opacity at which the background will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm
index 993645d3a8..acea3441fa 100644
--- a/platform/darwin/src/MGLBackgroundStyleLayer.mm
+++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h
index 06b4de32f0..69b6e41c9c 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.h
+++ b/platform/darwin/src/MGLCircleStyleLayer.h
@@ -117,7 +117,7 @@ MGL_EXPORT
full opacity.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -186,7 +186,7 @@ MGL_EXPORT
The opacity at which the circle will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -235,7 +235,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 5. Set this property to `nil` to reset it to the default value.
+ `5`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -334,7 +334,7 @@ MGL_EXPORT
The opacity of the circle's stroke.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -361,7 +361,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm
index 0be3920987..b03ab8a7a6 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.mm
+++ b/platform/darwin/src/MGLCircleStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -75,7 +75,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.h b/platform/darwin/src/MGLFillExtrusionStyleLayer.h
index 7c3a0773e4..bca2a99f1e 100644
--- a/platform/darwin/src/MGLFillExtrusionStyleLayer.h
+++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.h
@@ -78,7 +78,7 @@ MGL_EXPORT
This property is measured in meters.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `fillExtrusionHeight` is
non-`nil`. Otherwise, it is ignored.
@@ -164,7 +164,7 @@ MGL_EXPORT
This property is measured in meters.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -189,7 +189,7 @@ MGL_EXPORT
per-layer, not per-feature, basis, and data-driven styling is not available.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm
index 688ce4c1ac..4f3bfee18e 100644
--- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm
+++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -65,7 +65,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h
index 90740223eb..af82482c62 100644
--- a/platform/darwin/src/MGLFillStyleLayer.h
+++ b/platform/darwin/src/MGLFillStyleLayer.h
@@ -151,7 +151,7 @@ MGL_EXPORT
value will also affect the 1pt stroke around the fill, if the stroke is used.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm
index c975e28d6b..12e3643ce6 100644
--- a/platform/darwin/src/MGLFillStyleLayer.mm
+++ b/platform/darwin/src/MGLFillStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -65,7 +65,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h
index 0bff9b09f5..d0d9446a5f 100644
--- a/platform/darwin/src/MGLGeometry_Private.h
+++ b/platform/darwin/src/MGLGeometry_Private.h
@@ -71,6 +71,17 @@ NS_INLINE MGLCoordinateQuad MGLCoordinateQuadFromLatLngArray(std::array<mbgl::La
MGLLocationCoordinate2DFromLatLng(quad[1]) };
}
+/**
+ YES if the coordinate is valid or NO if it is not.
+ Considers extended coordinates.
+ */
+NS_INLINE BOOL MGLLocationCoordinate2DIsValid(CLLocationCoordinate2D coordinate) {
+ return (coordinate.latitude <= 90.0 &&
+ coordinate.latitude >= -90.0 &&
+ coordinate.longitude <= 360.0 &&
+ coordinate.longitude >= -360.0);
+}
+
#if TARGET_OS_IPHONE
NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) {
return { insets.top, insets.left, insets.bottom, insets.right };
diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.h b/platform/darwin/src/MGLHeatmapStyleLayer.h
index ad7ba5de01..167c5bafbe 100644
--- a/platform/darwin/src/MGLHeatmapStyleLayer.h
+++ b/platform/darwin/src/MGLHeatmapStyleLayer.h
@@ -116,7 +116,7 @@ MGL_EXPORT
Primarily used for adjusting the heatmap based on zoom level.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -142,7 +142,7 @@ MGL_EXPORT
The global opacity at which the heatmap layer will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -171,7 +171,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 30. Set this property to `nil` to reset it to the default value.
+ `30`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -197,7 +197,7 @@ MGL_EXPORT
Especially useful when combined with clustering.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.mm b/platform/darwin/src/MGLHeatmapStyleLayer.mm
index a394dbda3b..925b3ac750 100644
--- a/platform/darwin/src/MGLHeatmapStyleLayer.mm
+++ b/platform/darwin/src/MGLHeatmapStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -56,7 +56,7 @@
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.h b/platform/darwin/src/MGLHillshadeStyleLayer.h
index 224680160a..45b0e66751 100644
--- a/platform/darwin/src/MGLHillshadeStyleLayer.h
+++ b/platform/darwin/src/MGLHillshadeStyleLayer.h
@@ -130,7 +130,7 @@ MGL_EXPORT
Intensity of the hillshade
The default value of this property is an expression that evaluates to the float
- 0.5. Set this property to `nil` to reset it to the default value.
+ `0.5`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -232,7 +232,7 @@ MGL_EXPORT
`hillshadeIlluminationAnchor` is set to `MGLHillshadeIlluminationAnchorMap`.
The default value of this property is an expression that evaluates to the float
- 335. Set this property to `nil` to reset it to the default value.
+ `335`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm
index 2383c1ce26..70fab24e33 100644
--- a/platform/darwin/src/MGLHillshadeStyleLayer.mm
+++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h
index cf4aa50112..13c925d9bd 100644
--- a/platform/darwin/src/MGLLight.h
+++ b/platform/darwin/src/MGLLight.h
@@ -188,7 +188,7 @@ MGL_EXPORT
more extreme contrast.
The default value of this property is an expression that evaluates to the float
- 0.5.
+ `0.5`.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h
index 32c8ece6c5..1080244bdb 100644
--- a/platform/darwin/src/MGLLineStyleLayer.h
+++ b/platform/darwin/src/MGLLineStyleLayer.h
@@ -180,7 +180,7 @@ MGL_EXPORT
Used to automatically convert miter joins to bevel joins for sharp angles.
The default value of this property is an expression that evaluates to the float
- 2. Set this property to `nil` to reset it to the default value.
+ `2`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `lineJoin` is set to an
expression that evaluates to `miter`. Otherwise, it is ignored.
@@ -202,7 +202,7 @@ MGL_EXPORT
Used to automatically convert round joins to miter joins for shallow angles.
The default value of this property is an expression that evaluates to the float
- 1.05. Set this property to `nil` to reset it to the default value.
+ `1.05`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `lineJoin` is set to an
expression that evaluates to `round`. Otherwise, it is ignored.
@@ -228,7 +228,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -346,7 +346,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -375,7 +375,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -399,7 +399,7 @@ MGL_EXPORT
The opacity at which the line will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -545,7 +545,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm
index 619cc70afe..84412073cd 100644
--- a/platform/darwin/src/MGLLineStyleLayer.mm
+++ b/platform/darwin/src/MGLLineStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -77,7 +77,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm
index 19fa0223a4..923c8fb2a1 100644
--- a/platform/darwin/src/MGLMapSnapshotter.mm
+++ b/platform/darwin/src/MGLMapSnapshotter.mm
@@ -122,8 +122,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_snapshotCallback = std::make_unique<mbgl::Actor<mbgl::MapSnapshotter::Callback>>(*mbgl::Scheduler::GetCurrent(), [=](std::exception_ptr mbglError, mbgl::PremultipliedImage image, mbgl::MapSnapshotter::Attributions attributions, mbgl::MapSnapshotter::PointForFn pointForFn) {
__typeof__(self) strongSelf = weakSelf;
strongSelf.loading = false;
-
-
+
if (mbglError) {
NSString *description = @(mbgl::util::toString(mbglError).c_str());
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description};
@@ -145,9 +144,13 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
}
_snapshotCallback = NULL;
});
- dispatch_async(queue, ^{
- _mbglMapSnapshotter->snapshot(_snapshotCallback->self());
+ dispatch_async(queue, ^{
+ __typeof__(self) strongSelf = weakSelf;
+ if (!strongSelf) {
+ return;
+ }
+ strongSelf->_mbglMapSnapshotter->snapshot(strongSelf->_snapshotCallback->self());
});
}
diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm
index 5a7262b0a4..d4518e3d8f 100644
--- a/platform/darwin/src/MGLMultiPoint.mm
+++ b/platform/darwin/src/MGLMultiPoint.mm
@@ -163,7 +163,7 @@
if (!_bounds) {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
for (auto coordinate : _coordinates) {
- if (!CLLocationCoordinate2DIsValid(coordinate)) {
+ if (!MGLLocationCoordinate2DIsValid(coordinate)) {
bounds = mbgl::LatLngBounds::empty();
break;
}
diff --git a/platform/darwin/src/MGLOverlay.h b/platform/darwin/src/MGLOverlay.h
index 462a0c1031..7706b741e2 100644
--- a/platform/darwin/src/MGLOverlay.h
+++ b/platform/darwin/src/MGLOverlay.h
@@ -30,6 +30,11 @@ NS_ASSUME_NONNULL_BEGIN
This property contains the smallest rectangle that completely encompasses the
overlay. Implementers of this protocol must set this area when implementing
their overlay class, and after setting it, you must not change it.
+
+ If this overlay spans the antimeridian, its bounds may extend west of −180 degrees
+ longitude or east of 180 degrees longitude. For example, an overlay covering the
+ Pacific Ocean from Tokyo to San Francisco might have a bounds extending
+ from (35.68476, −220.24257) to (37.78428, −122.41310).
*/
@property (nonatomic, readonly) MGLCoordinateBounds overlayBounds;
diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm
index 8f20d91a42..efb9497a1f 100644
--- a/platform/darwin/src/MGLPointCollection.mm
+++ b/platform/darwin/src/MGLPointCollection.mm
@@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!_bounds) {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
for (auto coordinate : _coordinates) {
- if (!CLLocationCoordinate2DIsValid(coordinate)) {
+ if (!MGLLocationCoordinate2DIsValid(coordinate)) {
bounds = mbgl::LatLngBounds::empty();
break;
}
diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h
index bca9649e5d..ff055d24f6 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.h
+++ b/platform/darwin/src/MGLRasterStyleLayer.h
@@ -64,7 +64,7 @@ MGL_EXPORT
brightness.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-brightness-max"><code>raster-brightness-max</code></a>
@@ -97,7 +97,7 @@ MGL_EXPORT
brightness.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-brightness-min"><code>raster-brightness-min</code></a>
@@ -129,7 +129,7 @@ MGL_EXPORT
Increase or reduce the contrast of the image.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -157,7 +157,7 @@ MGL_EXPORT
This property is measured in milliseconds.
The default value of this property is an expression that evaluates to the float
- 300. Set this property to `nil` to reset it to the default value.
+ `300`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -178,7 +178,7 @@ MGL_EXPORT
This property is measured in degrees.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-hue-rotate"><code>raster-hue-rotate</code></a>
@@ -210,7 +210,7 @@ MGL_EXPORT
The opacity at which the image will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
@@ -236,7 +236,7 @@ MGL_EXPORT
Increase or reduce the saturation of the image.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
You can set this property to an expression containing any of the following:
diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm
index 94a58409de..0e31512491 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.mm
+++ b/platform/darwin/src/MGLRasterStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm
index 31e5867703..1425269012 100644
--- a/platform/darwin/src/MGLShapeSource.mm
+++ b/platform/darwin/src/MGLShapeSource.mm
@@ -6,7 +6,7 @@
#import "MGLFeature_Private.h"
#import "MGLShape_Private.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSURL+MGLAdditions.h"
#include <mbgl/map/map.hpp>
diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs
index 5405598124..f3e75b492c 100644
--- a/platform/darwin/src/MGLStyleLayer.mm.ejs
+++ b/platform/darwin/src/MGLStyleLayer.mm.ejs
@@ -8,7 +8,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -103,7 +103,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index e27f039b75..2c899fe76f 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -564,7 +564,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 2. Set this property to `nil` to reset it to the default value.
+ `2`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -615,7 +615,7 @@ MGL_EXPORT
This property is measured in degrees.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -678,7 +678,7 @@ MGL_EXPORT
This property is measured in factor of the original icon sizes.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -858,7 +858,7 @@ MGL_EXPORT
This property is measured in degrees.
The default value of this property is an expression that evaluates to the float
- 45. Set this property to `nil` to reset it to the default value.
+ `45`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`, and
`symbolPlacement` is set to an expression that evaluates to `line`. Otherwise,
@@ -890,7 +890,7 @@ MGL_EXPORT
This property is measured in ems.
The default value of this property is an expression that evaluates to the float
- 10. Set this property to `nil` to reset it to the default value.
+ `10`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -973,7 +973,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 250. Set this property to `nil` to reset it to the default value.
+ `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
expression that evaluates to `line`. Otherwise, it is ignored.
@@ -1129,7 +1129,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 16. Set this property to `nil` to reset it to the default value.
+ `16`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1219,7 +1219,7 @@ MGL_EXPORT
This property is measured in ems.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1241,7 +1241,7 @@ MGL_EXPORT
This property is measured in ems.
The default value of this property is an expression that evaluates to the float
- 1.2. Set this property to `nil` to reset it to the default value.
+ `1.2`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1338,7 +1338,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 2. Set this property to `nil` to reset it to the default value.
+ `2`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1389,7 +1389,7 @@ MGL_EXPORT
This property is measured in degrees.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1529,7 +1529,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -1611,7 +1611,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -1638,7 +1638,7 @@ MGL_EXPORT
The opacity at which the icon will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
@@ -1819,7 +1819,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1900,7 +1900,7 @@ MGL_EXPORT
This property is measured in points.
The default value of this property is an expression that evaluates to the float
- 0. Set this property to `nil` to reset it to the default value.
+ `0`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
@@ -1927,7 +1927,7 @@ MGL_EXPORT
The opacity at which the text will be drawn.
The default value of this property is an expression that evaluates to the float
- 1. Set this property to `nil` to reset it to the default value.
+ `1`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm
index 0d9fac4808..7ec7816c3b 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.mm
+++ b/platform/darwin/src/MGLSymbolStyleLayer.mm
@@ -2,7 +2,7 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
@@ -142,7 +142,7 @@ namespace mbgl {
{
MGLAssertStyleLayerIsValid();
- self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter());
+ self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter());
}
- (NSPredicate *)predicate
diff --git a/platform/darwin/src/MGLVectorTileSource.mm b/platform/darwin/src/MGLVectorTileSource.mm
index c6715d1759..e55ed13060 100644
--- a/platform/darwin/src/MGLVectorTileSource.mm
+++ b/platform/darwin/src/MGLVectorTileSource.mm
@@ -6,7 +6,7 @@
#import "MGLStyle_Private.h"
#import "MGLMapView_Private.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSURL+MGLAdditions.h"
#include <mbgl/map/map.hpp>
@@ -112,7 +112,8 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[
return [[NSLocale localeWithLocaleIdentifier:language].languageCode isEqualToString:@"en"];
}]].count;
- NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:MGLMapboxStreetsAlternativeLanguages
+ NSArray<NSString *> *availableLanguages = acceptsEnglish ? MGLMapboxStreetsLanguages : MGLMapboxStreetsAlternativeLanguages;
+ NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:availableLanguages
forPreferences:preferencesArray];
NSString *mostSpecificLanguage;
for (NSString *language in preferredLanguages) {
@@ -120,10 +121,7 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[
mostSpecificLanguage = language;
}
}
- if ([mostSpecificLanguage isEqualToString:@"mul"]) {
- return acceptsEnglish ? @"en" : nil;
- }
- return mostSpecificLanguage;
+ return [mostSpecificLanguage isEqualToString:@"mul"] ? nil : mostSpecificLanguage;
}
- (BOOL)isMapboxStreets {
@@ -135,19 +133,4 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[
return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"];
}
-- (NSDictionary<NSString *, NSString *> *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage {
- if (!self.mapboxStreets) {
- return @{};
- }
-
- // Replace {name} and {name_*} with the matching localized name tag.
- NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name";
- NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"];
- for (NSString *languageCode in [MGLVectorTileSource mapboxStreetsLanguages]) {
- NSString *key = [NSString stringWithFormat:@"name_%@", languageCode];
- localizedKeysByKey[key] = localizedKey;
- }
- return localizedKeysByKey;
-}
-
@end
diff --git a/platform/darwin/src/MGLVectorTileSource_Private.h b/platform/darwin/src/MGLVectorTileSource_Private.h
index 8042e2cfee..8d287ae4c4 100644
--- a/platform/darwin/src/MGLVectorTileSource_Private.h
+++ b/platform/darwin/src/MGLVectorTileSource_Private.h
@@ -11,8 +11,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (nullable NSString *)preferredMapboxStreetsLanguage;
+ (nullable NSString *)preferredMapboxStreetsLanguageForPreferences:(NSArray<NSString *> *)preferencesArray;
-- (NSDictionary<NSString *, NSString *> *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
index 5a98b763ea..a8ae19b172 100644
--- a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm
@@ -2,7 +2,7 @@
#import "MGLStyleValue_Private.h"
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "NSExpression+MGLPrivateAdditions.h"
#include <mbgl/style/conversion/property_value.hpp>
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index a42a2d276e..be93b13f3c 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -798,6 +798,22 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
} else if ([op isEqualToString:@"to-string"] || [op isEqualToString:@"string"]) {
NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
return [NSExpression expressionWithFormat:@"CAST(%@, 'NSString')", operand];
+ } else if ([op isEqualToString:@"to-color"]) {
+ NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
+
+ if (argumentObjects.count == 1) {
+#if TARGET_OS_IPHONE
+ return [NSExpression expressionWithFormat:@"CAST(%@, 'UIColor')", operand];
+#else
+ return [NSExpression expressionWithFormat:@"CAST(%@, 'NSColor')", operand];
+#endif
+ }
+ NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(array);
+ return [NSExpression expressionForFunction:@"MGL_FUNCTION" arguments:subexpressions];
+
+ } else if ([op isEqualToString:@"to-rgba"]) {
+ NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject];
+ return [NSExpression expressionWithFormat:@"CAST(noindex(%@), 'NSArray')", operand];
} else if ([op isEqualToString:@"get"]) {
if (argumentObjects.count == 2) {
NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.lastObject];
@@ -909,7 +925,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
for (NSUInteger index = 0; index < argumentObjects.count; index++) {
if (index % 2 == 0 && index != argumentObjects.count - 1) {
- NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:argumentObjects[index]];
+ NSPredicate *predicate = [NSPredicate predicateWithMGLJSONObject:argumentObjects[index]];
NSExpression *argument = [NSExpression expressionForConstantValue:predicate];
[arguments addObject:argument];
} else {
@@ -1091,7 +1107,22 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
NSArray *arguments = self.arguments.mgl_jsonExpressionObject;
return [@[@"concat", self.operand.mgl_jsonExpressionObject] arrayByAddingObjectsFromArray:arguments];
} else if ([function isEqualToString:@"objectFrom:withIndex:"]) {
- return @[@"at", self.arguments[1].mgl_jsonExpressionObject, self.arguments[0].mgl_jsonExpressionObject];
+ id index = self.arguments[1].mgl_jsonExpressionObject;
+
+ if ([self.arguments[1] expressionType] == NSConstantValueExpressionType
+ && [[self.arguments[1] constantValue] isKindOfClass:[NSString class]]) {
+ id value = self.arguments[1].constantValue;
+
+ if ([value isEqualToString:@"FIRST"]) {
+ index = [NSExpression expressionForConstantValue:@0].mgl_jsonExpressionObject;
+ } else if ([value isEqualToString:@"LAST"]) {
+ index = [NSExpression expressionWithFormat:@"count(%@) - 1", self.arguments[0]].mgl_jsonExpressionObject;
+ } else if ([value isEqualToString:@"SIZE"]) {
+ return [NSExpression expressionWithFormat:@"count(%@)", self.arguments[0]].mgl_jsonExpressionObject;
+ }
+ }
+
+ return @[@"at", index, self.arguments[0].mgl_jsonExpressionObject];
} else if ([function isEqualToString:@"boolValue"]) {
return @[@"to-boolean", self.operand.mgl_jsonExpressionObject];
} else if ([function isEqualToString:@"mgl_number"] ||
@@ -1144,6 +1175,26 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
} else if ([type isEqualToString:@"NSNumber"]) {
return @[@"to-number", object];
}
+#if TARGET_OS_IPHONE
+ else if ([type isEqualToString:@"UIColor"] || [type isEqualToString:@"MGLColor"]) {
+ return @[@"to-color", object];
+ }
+#else
+ else if ([type isEqualToString:@"NSColor"] || [type isEqualToString:@"MGLColor"]) {
+ return @[@"to-color", object];
+ }
+#endif
+ else if ([type isEqualToString:@"NSArray"]) {
+ NSExpression *operand = self.arguments.firstObject;
+ if ([operand expressionType] == NSFunctionExpressionType ) {
+ operand = self.arguments.firstObject.arguments.firstObject;
+ }
+ if (([operand expressionType] != NSConstantValueExpressionType) ||
+ ([operand expressionType] == NSConstantValueExpressionType &&
+ [[operand constantValue] isKindOfClass:[MGLColor class]])) {
+ return @[@"to-rgba", object];
+ }
+ }
[NSException raise:NSInvalidArgumentException
format:@"Casting expression to %@ not yet implemented.", type];
} else if ([function isEqualToString:@"MGL_FUNCTION"]) {
@@ -1212,7 +1263,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
case NSAnyKeyExpressionType:
case NSBlockExpressionType:
[NSException raise:NSInvalidArgumentException
- format:@"Expression type %lu not yet implemented.", self.expressionType];
+ format:@"Expression type %lu not yet implemented.", (unsigned long)self.expressionType];
}
// NSKeyPathSpecifierExpression
@@ -1234,11 +1285,11 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
if (self.arguments.count < expectedArgumentCount) {
[NSException raise:NSInvalidArgumentException format:
@"Too few arguments to ‘%@’ function; expected %lu arguments.",
- self.function, expectedArgumentCount];
+ self.function, (unsigned long)expectedArgumentCount];
} else if (self.arguments.count > expectedArgumentCount) {
[NSException raise:NSInvalidArgumentException format:
@"%lu unexpected arguments to ‘%@’ function; expected %lu arguments.",
- self.arguments.count - expectedArgumentCount, self.function, expectedArgumentCount];
+ self.arguments.count - (unsigned long)expectedArgumentCount, self.function, (unsigned long)expectedArgumentCount];
}
BOOL isAftermarketFunction = [self.function isEqualToString:@"mgl_interpolate:withCurveType:parameters:stops:"];
@@ -1252,9 +1303,15 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
NSArray *controlPoints = [self.arguments[curveTypeIndex + 1].collection mgl_jsonExpressionObject];
[interpolationArray addObjectsFromArray:controlPoints];
}
+
+ NSDictionary<NSNumber *, NSExpression *> *stops = self.arguments[curveTypeIndex + 2].constantValue;
+
+ if (stops.count == 0) {
+ [NSException raise:NSInvalidArgumentException format:@"‘stops‘ dictionary argument to ‘%@’ function must not be empty.", self.function];
+ }
+
NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"interpolate", interpolationArray, nil];
[expressionObject addObject:(isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject];
- NSDictionary<NSNumber *, NSExpression *> *stops = self.arguments[curveTypeIndex + 2].constantValue;
for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) {
[expressionObject addObject:key];
[expressionObject addObject:[stops[key] mgl_jsonExpressionObject]];
@@ -1266,8 +1323,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
BOOL isAftermarketFunction = [self.function isEqualToString:@"mgl_step:from:stops:"];
NSUInteger minimumIndex = isAftermarketFunction ? 1 : 0;
id minimum = self.arguments[minimumIndex].mgl_jsonExpressionObject;
- NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", (isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject, minimum, nil];
NSDictionary<NSNumber *, NSExpression *> *stops = self.arguments[minimumIndex + 1].constantValue;
+
+ if (stops.count == 0) {
+ [NSException raise:NSInvalidArgumentException format:@"‘stops‘ dictionary argument to ‘%@’ function must not be empty.", self.function];
+ }
+
+ NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", (isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject, minimum, nil];
+
for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) {
[expressionObject addObject:key];
[expressionObject addObject:[stops[key] mgl_jsonExpressionObject]];
diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.h b/platform/darwin/src/NSPredicate+MGLAdditions.h
index a73b1a61ba..6c4b878d37 100644
--- a/platform/darwin/src/NSPredicate+MGLAdditions.h
+++ b/platform/darwin/src/NSPredicate+MGLAdditions.h
@@ -1,23 +1,44 @@
#import <Foundation/Foundation.h>
-#import "NSExpression+MGLPrivateAdditions.h"
+NS_ASSUME_NONNULL_BEGIN
@interface NSPredicate (MGLAdditions)
-- (mbgl::style::Filter)mgl_filter;
-
-+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
-
-@end
-
-@interface NSPredicate (MGLExpressionAdditions)
-
-+ (instancetype)mgl_predicateWithJSONObject:(id)object;
-
+#pragma mark Converting JSON Expressions
+
+/**
+ Returns a predicate equivalent to the given Foundation object deserialized
+ from JSON data.
+
+ The Foundation object is interpreted according to the
+ [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions).
+ See the
+ “[Predicates and Expressions](../predicates-and-expressions.html)”
+ guide for a correspondence of operators and types between the style
+ specification and the `NSPredicate` representation used by this SDK.
+
+ @param object A Foundation object deserialized from JSON data, for example
+ using `NSJSONSerialization`.
+ @return An initialized predicate equivalent to `object`, suitable for use
+ with the `MGLVectorStyleLayer.predicate` property.
+ */
++ (instancetype)predicateWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:));
+
+/**
+ An equivalent Foundation object that can be serialized as JSON.
+
+ The Foundation object conforms to the
+ [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions).
+ See the
+ “[Predicates and Expressions](../predicates-and-expressions.html)”
+ guide for a correspondence of operators and types between the style
+ specification and the `NSPredicate` representation used by this SDK.
+
+ You can use `NSJSONSerialization` to serialize the Foundation object as data to
+ write to a file.
+ */
@property (nonatomic, readonly) id mgl_jsonExpressionObject;
-- (id)mgl_if:(id)firstValue, ...;
-
-- (id)mgl_match:(NSExpression *)firstCase, ...;
-
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm
index bbd324bb63..4b9a4177cb 100644
--- a/platform/darwin/src/NSPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm
@@ -1,210 +1,11 @@
-#import "NSPredicate+MGLAdditions.h"
+#import "NSPredicate+MGLPrivateAdditions.h"
#import "MGLValueEvaluator.h"
#import "MGLStyleValue_Private.h"
#include <mbgl/style/conversion/filter.hpp>
-class FilterEvaluator {
-public:
-
- NSArray *getPredicates(std::vector<mbgl::style::Filter> filters) {
- NSMutableArray *predicates = [NSMutableArray arrayWithCapacity:filters.size()];
- for (auto filter : filters) {
- [predicates addObject:mbgl::style::Filter::visit(filter, FilterEvaluator())];
- }
- return predicates;
- }
-
- template <typename MBGLType>
- NSExpression *getValues(std::vector<MBGLType> values) {
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:values.size()];
- for (auto value : values) {
- id constantValue = MBGLType::visit(value, ValueEvaluator());
- [array addObject:[NSExpression expressionForConstantValue:constantValue]];
- }
- return [NSExpression expressionForAggregate:array];
- }
-
- NSString *getFeatureTypeString(mbgl::FeatureType type) {
- switch (type) {
- case mbgl::FeatureType::Point:
- return @"Point";
-
- case mbgl::FeatureType::LineString:
- return @"LineString";
-
- case mbgl::FeatureType::Polygon:
- return @"Polygon";
-
- default:
- NSCAssert(NO, @"Unrecognized feature type %hhu", type);
- return nil;
- }
- }
-
- NSExpression *getFeatureTypeStrings(std::vector<mbgl::FeatureType> values) {
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:values.size()];
- for (auto value : values) {
- id typeString = getFeatureTypeString(value);
- [array addObject:[NSExpression expressionForConstantValue:typeString]];
- }
- return [NSExpression expressionForAggregate:array];
- }
-
- NSPredicate *operator()(mbgl::style::NullFilter filter) {
- return nil;
- }
-
- NSPredicate *operator()(mbgl::style::EqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K == %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::NotEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K != %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::GreaterThanFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K > %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::GreaterThanEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K >= %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::LessThanFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K < %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::LessThanEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K <= %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::InFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K IN %@", @(filter.key.c_str()), getValues(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::NotInFilter filter) {
- return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @(filter.key.c_str()), getValues(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::TypeEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K == %@", @"$type", getFeatureTypeString(filter.value)];
- }
-
- NSPredicate *operator()(mbgl::style::TypeNotEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K != %@", @"$type", getFeatureTypeString(filter.value)];
- }
-
- NSPredicate *operator()(mbgl::style::TypeInFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K IN %@", @"$type", getFeatureTypeStrings(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::TypeNotInFilter filter) {
- return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @"$type", getFeatureTypeStrings(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::IdentifierEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K == %@", @"$id", mbgl::FeatureIdentifier::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::IdentifierNotEqualsFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K != %@", @"$id", mbgl::FeatureIdentifier::visit(filter.value, ValueEvaluator())];
- }
-
- NSPredicate *operator()(mbgl::style::IdentifierInFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K IN %@", @"$id", getValues(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::IdentifierNotInFilter filter) {
- return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @"$id", getValues(filter.values)];
- }
-
- NSPredicate *operator()(mbgl::style::AnyFilter filter) {
- NSArray *subpredicates = getPredicates(filter.filters);
- if (subpredicates.count) {
- return [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
- }
- return [NSPredicate predicateWithValue:NO];
- }
-
- NSPredicate *operator()(mbgl::style::AllFilter filter) {
- // Convert [all, [>=, key, lower], [<=, key, upper]] to key BETWEEN {lower, upper}
- if (filter.filters.size() == 2) {
- auto leftFilter = filter.filters[0];
- auto rightFilter = filter.filters[1];
-
- std::string lowerKey;
- std::string upperKey;
- mbgl::Value lowerBound;
- mbgl::Value upperBound;
- if (leftFilter.is<mbgl::style::GreaterThanEqualsFilter>()) {
- lowerKey = leftFilter.get<mbgl::style::GreaterThanEqualsFilter>().key;
- lowerBound = leftFilter.get<mbgl::style::GreaterThanEqualsFilter>().value;
- } else if (rightFilter.is<mbgl::style::GreaterThanEqualsFilter>()) {
- lowerKey = rightFilter.get<mbgl::style::GreaterThanEqualsFilter>().key;
- lowerBound = rightFilter.get<mbgl::style::GreaterThanEqualsFilter>().value;
- }
-
- if (leftFilter.is<mbgl::style::LessThanEqualsFilter>()) {
- upperKey = leftFilter.get<mbgl::style::LessThanEqualsFilter>().key;
- upperBound = leftFilter.get<mbgl::style::LessThanEqualsFilter>().value;
- } else if (rightFilter.is<mbgl::style::LessThanEqualsFilter>()) {
- upperKey = rightFilter.get<mbgl::style::LessThanEqualsFilter>().key;
- upperBound = rightFilter.get<mbgl::style::LessThanEqualsFilter>().value;
- }
-
- if (!lowerBound.is<mbgl::NullValue>() && !upperBound.is<mbgl::NullValue>()
- && lowerKey == upperKey) {
- return [NSPredicate predicateWithFormat:@"%K BETWEEN {%@, %@}",
- @(lowerKey.c_str()),
- mbgl::Value::visit(lowerBound, ValueEvaluator()),
- mbgl::Value::visit(upperBound, ValueEvaluator())];
- }
- }
-
- NSArray *subpredicates = getPredicates(filter.filters);
- if (subpredicates.count) {
- return [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
- }
- return [NSPredicate predicateWithValue:YES];
- }
-
- NSPredicate *operator()(mbgl::style::NoneFilter filter) {
- NSArray *subpredicates = getPredicates(filter.filters);
- if (subpredicates.count > 1) {
- NSCompoundPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
- return [NSCompoundPredicate notPredicateWithSubpredicate:predicate];
- } else if (subpredicates.count) {
- return [NSCompoundPredicate notPredicateWithSubpredicate:subpredicates.firstObject];
- } else {
- return [NSPredicate predicateWithValue:YES];
- }
- }
-
- NSPredicate *operator()(mbgl::style::HasFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K != nil", @(filter.key.c_str())];
- }
-
- NSPredicate *operator()(mbgl::style::NotHasFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K == nil", @(filter.key.c_str())];
- }
-
- NSPredicate *operator()(mbgl::style::HasIdentifierFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K != nil", @"$id"];
- }
-
- NSPredicate *operator()(mbgl::style::NotHasIdentifierFilter filter) {
- return [NSPredicate predicateWithFormat:@"%K == nil", @"$id"];
- }
-
- NSPredicate *operator()(mbgl::style::ExpressionFilter filter) {
- id jsonObject = MGLJSONObjectFromMBGLExpression(*filter.expression);
- return [NSPredicate mgl_predicateWithJSONObject:jsonObject];
- }
-};
-
-@implementation NSPredicate (MGLAdditions)
+@implementation NSPredicate (MGLPrivateAdditions)
- (mbgl::style::Filter)mgl_filter
{
@@ -224,24 +25,28 @@ public:
+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter
{
- FilterEvaluator evaluator;
- return mbgl::style::Filter::visit(filter, evaluator);
+ if (filter.expression) {
+ id jsonObject = MGLJSONObjectFromMBGLExpression(**filter.expression);
+ return [NSPredicate predicateWithMGLJSONObject:jsonObject];
+ } else {
+ return nil;
+ }
}
@end
-@implementation NSPredicate (MGLExpressionAdditions)
+@implementation NSPredicate (MGLAdditions)
NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) {
NSMutableArray *subpredicates = [NSMutableArray arrayWithCapacity:objects.count];
for (id object in objects) {
- NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:object];
+ NSPredicate *predicate = [NSPredicate predicateWithMGLJSONObject:object];
[subpredicates addObject:predicate];
}
return subpredicates;
}
-+ (instancetype)mgl_predicateWithJSONObject:(id)object {
++ (instancetype)predicateWithMGLJSONObject:(id)object {
if ([object isEqual:@YES]) {
return [NSPredicate predicateWithValue:YES];
}
@@ -360,6 +165,10 @@ NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) {
return nil;
}
+@end
+
+@implementation NSPredicate (MGLExpressionAdditions)
+
- (id)mgl_if:(id)firstValue, ... {
if ([self evaluateWithObject:nil]) {
diff --git a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
new file mode 100644
index 0000000000..1828009678
--- /dev/null
+++ b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
@@ -0,0 +1,25 @@
+#import <Foundation/Foundation.h>
+
+#import "NSPredicate+MGLAdditions.h"
+
+#include <mbgl/style/filter.hpp>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSPredicate (MGLPrivateAdditions)
+
+- (mbgl::style::Filter)mgl_filter;
+
++ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
+
+@end
+
+@interface NSPredicate (MGLExpressionAdditions)
+
+- (id)mgl_if:(id)firstValue, ...;
+
+- (id)mgl_match:(NSExpression *)firstCase, ...;
+
+@end
+
+NS_ASSUME_NONNULL_END