Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit eb12456

Browse files
committed
[ios, macos] Added $lineProgress expression variable
1 parent f03a81f commit eb12456

9 files changed

+43
-0
lines changed

platform/darwin/docs/guides/For Style Authors.md.ejs

+1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ In style specification | Method, function, or predicate type | Format string syn
402402
`tan` | `mgl_tan:` | `mgl_tan(0)`
403403
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
404404
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
405+
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
405406
406407
For operators that have no corresponding `NSExpression` symbol, use the
407408
`MGL_FUNCTION()` format string syntax.

platform/darwin/docs/guides/Predicates and Expressions.md

+11
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ The following variables are defined by this SDK for use with style layers:
290290
<code>NSExpression.zoomLevelVariableExpression</code> property.
291291
</td>
292292
</tr>
293+
<tr>
294+
<td><code>$lineProgress</code></td>
295+
<td>Number</td>
296+
<td>
297+
A number that indicates the relative distance along a line at a given
298+
point along the line. This variable evaluates to 0 at the beginning of the
299+
line and 1 at the end of the line. It can only be used with the
300+
`MGLLineStyleLayer.lineGradient` property. It corresponds to the
301+
<code>NSExpression.lineProgressVariableExpression</code> property.
302+
</td>
303+
</tr>
293304
</tbody>
294305
</table>
295306

platform/darwin/src/NSExpression+MGLAdditions.h

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionI
6161
*/
6262
@property (class, nonatomic, readonly) NSExpression *heatmapDensityVariableExpression;
6363

64+
/**
65+
`NSExpression` variable that corresponds to the
66+
<a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-line-progress"><code>line-progress</code></a>
67+
expression operator in the Mapbox Style Specification.
68+
*/
69+
@property (class, nonatomic, readonly) NSExpression *lineProgressVariableExpression;
70+
6471
/**
6572
`NSExpression` variable that corresponds to the
6673
<a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#eexpressions-geometry-type"><code>geometry-type</code></a>

platform/darwin/src/NSExpression+MGLAdditions.mm

+9
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ + (NSExpression *)heatmapDensityVariableExpression {
542542
return [NSExpression expressionForVariable:@"heatmapDensity"];
543543
}
544544

545+
+ (NSExpression *)lineProgressVariableExpression {
546+
return [NSExpression expressionForVariable:@"lineProgress"];
547+
}
548+
545549
+ (NSExpression *)geometryTypeVariableExpression {
546550
return [NSExpression expressionForVariable:@"geometryType"];
547551
}
@@ -814,6 +818,8 @@ + (instancetype)expressionWithMGLJSONObject:(id)object {
814818
return NSExpression.zoomLevelVariableExpression;
815819
} else if ([op isEqualToString:@"heatmap-density"]) {
816820
return NSExpression.heatmapDensityVariableExpression;
821+
} else if ([op isEqualToString:@"line-progress"]) {
822+
return NSExpression.lineProgressVariableExpression;
817823
} else if ([op isEqualToString:@"geometry-type"]) {
818824
return NSExpression.geometryTypeVariableExpression;
819825
} else if ([op isEqualToString:@"id"]) {
@@ -911,6 +917,9 @@ - (id)mgl_jsonExpressionObject {
911917
if ([self.variable isEqualToString:@"heatmapDensity"]) {
912918
return @[@"heatmap-density"];
913919
}
920+
if ([self.variable isEqualToString:@"lineProgress"]) {
921+
return @[@"line-progress"];
922+
}
914923
if ([self.variable isEqualToString:@"zoomLevel"]) {
915924
return @[@"zoom"];
916925
}

platform/darwin/test/MGLExpressionTests.mm

+8
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ - (void)testVariableExpressionObject {
170170
NSMutableDictionary *context = [@{@"heatmapDensity": @1} mutableCopy];
171171
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:context], @1);
172172
}
173+
{
174+
NSExpression *expression = [NSExpression expressionForVariable:@"lineProgress"];
175+
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, @[@"line-progress"]);
176+
XCTAssertEqualObjects([NSExpression expressionWithFormat:@"$lineProgress"].mgl_jsonExpressionObject, @[@"line-progress"]);
177+
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:@[@"line-progress"]], expression);
178+
NSMutableDictionary *context = [@{@"lineProgress": @1} mutableCopy];
179+
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:context], @1);
180+
}
173181
{
174182
NSExpression *expression = [NSExpression expressionForVariable:@"geometryType"];
175183
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, @[@"geometry-type"]);

platform/ios/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.
44

5+
## master
6+
7+
* Fixed a crash setting the `MGLLineStyleLayer.lineGradient` property to an expression containing the `$lineProgress` variable. Added an `NSExpression.lineProgressVariableExpression` class property that returns an expression for the `$lineProgress` variable. ([#13192](https://github.com/mapbox/mapbox-gl-native/pull/13192))
8+
59
## 4.6.0
610

711
### Styles and rendering

platform/ios/docs/guides/For Style Authors.md

+1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ In style specification | Method, function, or predicate type | Format string syn
388388
`tan` | `mgl_tan:` | `mgl_tan(0)`
389389
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
390390
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
391+
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
391392

392393
For operators that have no corresponding `NSExpression` symbol, use the
393394
`MGL_FUNCTION()` format string syntax.

platform/macos/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Added an `MGLSymbolStyleLayer.symbolZOrder` property for forcing point features in a symbol layer to be layered in the same order that they are specified in the layer’s associated source. ([#12783](https://github.com/mapbox/mapbox-gl-native/pull/12783))
88
* Fixed a crash when a style layer `*-pattern` property evaluates to nil for a particular feature. ([#12896](https://github.com/mapbox/mapbox-gl-native/pull/12896))
9+
* Fixed a crash setting the `MGLLineStyleLayer.lineGradient` property to an expression containing the `$lineProgress` variable. Added an `NSExpression.lineProgressVariableExpression` class property that returns an expression for the `$lineProgress` variable. ([#13192](https://github.com/mapbox/mapbox-gl-native/pull/13192))
910
* Fixed an issue where fill and line layers would occasionally flicker on zoom ([#12982](https://github.com/mapbox/mapbox-gl-native/pull/12982))
1011

1112
### Offline maps

platform/macos/docs/guides/For Style Authors.md

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ In style specification | Method, function, or predicate type | Format string syn
381381
`tan` | `mgl_tan:` | `mgl_tan(0)`
382382
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
383383
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
384+
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
384385

385386
For operators that have no corresponding `NSExpression` symbol, use the
386387
`MGL_FUNCTION()` format string syntax.

0 commit comments

Comments
 (0)