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

Commit

Permalink
[core] Port expression spec changes
Browse files Browse the repository at this point in the history
Ports mapbox/mapbox-gl-js#6521: for the sake of gl-native this only requires tweak to code generation scripts.
  • Loading branch information
Lauren Budorick committed May 4, 2018
1 parent 27b2136 commit 7e26976
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 232 deletions.
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 244 files
10 changes: 7 additions & 3 deletions platform/android/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,13 @@ global.propertyValueDoc = function (property, value) {
};

global.isDataDriven = function (property) {
return property['property-function'] === true;
return property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven';
};

global.isInterpolable = function(property) {
return property.expression && property.expression.interpolated;
}

global.isLightProperty = function (property) {
return property['light-property'] === true;
};
Expand Down Expand Up @@ -318,11 +322,11 @@ global.evaluatedType = function (property) {
};

global.supportsZoomFunction = function (property) {
return property['zoom-function'] === true;
return property.expression && property.expression.parameters.indexOf('zoom') > -1;
};

global.supportsPropertyFunction = function (property) {
return property['property-function'] === true;
return property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven';
};

// Template processing //
Expand Down
8 changes: 6 additions & 2 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
'* Conditional expressions\n' +
'* Variable assignments and references to assigned variables\n';
const inputVariable = property.name === 'heatmap-color' ? '$heatmapDensity' : '$zoomLevel';
if (property["property-function"]) {
if (isDataDriven(property)) {
doc += `* Interpolation and step functions applied to the \`${inputVariable}\` variable and/or feature attributes\n`;
} else if (property.function === "interpolated") {
} else if (property.expression && property.expression.interpolated) {
doc += `* Interpolation and step functions applied to the \`${inputVariable}\` variable\n\n` +
'This property does not support applying interpolation or step functions to feature attributes.';
} else {
Expand All @@ -332,6 +332,10 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
return doc;
};

global.isDataDriven = function (property) {
return property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven';
};

global.propertyReqs = function (property, propertiesByName, type) {
return 'This property is only applied to the style if ' + property.requires.map(function (req) {
if (typeof req === 'string') {
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLStyleLayer.mm.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace mbgl {
- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> {
MGLAssertStyleLayerIsValid();
<% if (property["property-function"]) { -%>
<% if (isDataDriven(property)) { -%>
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>);
<% } else { -%>
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>);
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace mbgl {
<% if (property.name === 'heatmap-color') { -%>
auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::HeatmapColorPropertyValue>(heatmapColor);
<% } else if (property["property-function"]) { -%>
<% } else if (isDataDriven(property)) { -%>
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>);
<% } else { -%>
auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>);
Expand Down
9 changes: 3 additions & 6 deletions platform/darwin/test/MGLBackgroundStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ - (void)testProperties {
{ 18, { 1, 0, 0, 1 } },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops };

XCTAssertEqual(rawLayer->getBackgroundColor(), propertyValue,
@"Setting backgroundColor to a camera expression should update background-color.");
XCTAssertEqualObjects(layer.backgroundColor, functionExpression,
@"backgroundColor should round-trip camera expressions.");



layer.backgroundColor = nil;
XCTAssertTrue(rawLayer->getBackgroundColor().isUndefined(),
Expand Down Expand Up @@ -103,13 +102,12 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getBackgroundOpacity(), propertyValue,
@"Setting backgroundOpacity to a camera expression should update background-opacity.");
XCTAssertEqualObjects(layer.backgroundOpacity, functionExpression,
@"backgroundOpacity should round-trip camera expressions.");



layer.backgroundOpacity = nil;
XCTAssertTrue(rawLayer->getBackgroundOpacity().isUndefined(),
Expand Down Expand Up @@ -156,13 +154,12 @@ - (void)testProperties {
{ 18, "Background Pattern" },
}};
propertyValue = mbgl::style::CameraFunction<std::string> { intervalStops };

XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue,
@"Setting backgroundPattern to a camera expression should update background-pattern.");
XCTAssertEqualObjects(layer.backgroundPattern, functionExpression,
@"backgroundPattern should round-trip camera expressions.");



layer.backgroundPattern = nil;
XCTAssertTrue(rawLayer->getBackgroundPattern().isUndefined(),
Expand Down
33 changes: 11 additions & 22 deletions platform/darwin/test/MGLCircleStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue,
@"Setting circleBlur to a camera expression should update circle-blur.");
XCTAssertEqualObjects(layer.circleBlur, functionExpression,
Expand Down Expand Up @@ -102,7 +102,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleBlur, pedanticFunctionExpression,
@"circleBlur should round-trip camera-data expressions.");


layer.circleBlur = nil;
XCTAssertTrue(rawLayer->getCircleBlur().isUndefined(),
Expand Down Expand Up @@ -143,7 +142,7 @@ - (void)testProperties {
{ 18, { 1, 0, 0, 1 } },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops };

XCTAssertEqual(rawLayer->getCircleColor(), propertyValue,
@"Setting circleColor to a camera expression should update circle-color.");
XCTAssertEqualObjects(layer.circleColor, functionExpression,
Expand Down Expand Up @@ -174,7 +173,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleColor, pedanticFunctionExpression,
@"circleColor should round-trip camera-data expressions.");


layer.circleColor = nil;
XCTAssertTrue(rawLayer->getCircleColor().isUndefined(),
Expand Down Expand Up @@ -215,7 +213,7 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue,
@"Setting circleOpacity to a camera expression should update circle-opacity.");
XCTAssertEqualObjects(layer.circleOpacity, functionExpression,
Expand Down Expand Up @@ -246,7 +244,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleOpacity, pedanticFunctionExpression,
@"circleOpacity should round-trip camera-data expressions.");


layer.circleOpacity = nil;
XCTAssertTrue(rawLayer->getCircleOpacity().isUndefined(),
Expand Down Expand Up @@ -287,13 +284,12 @@ - (void)testProperties {
{ 18, mbgl::style::AlignmentType::Viewport },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::style::AlignmentType> { intervalStops };

XCTAssertEqual(rawLayer->getCirclePitchAlignment(), propertyValue,
@"Setting circlePitchAlignment to a camera expression should update circle-pitch-alignment.");
XCTAssertEqualObjects(layer.circlePitchAlignment, functionExpression,
@"circlePitchAlignment should round-trip camera expressions.");



layer.circlePitchAlignment = nil;
XCTAssertTrue(rawLayer->getCirclePitchAlignment().isUndefined(),
Expand Down Expand Up @@ -331,7 +327,7 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue,
@"Setting circleRadius to a camera expression should update circle-radius.");
XCTAssertEqualObjects(layer.circleRadius, functionExpression,
Expand Down Expand Up @@ -362,7 +358,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleRadius, pedanticFunctionExpression,
@"circleRadius should round-trip camera-data expressions.");


layer.circleRadius = nil;
XCTAssertTrue(rawLayer->getCircleRadius().isUndefined(),
Expand Down Expand Up @@ -403,13 +398,12 @@ - (void)testProperties {
{ 18, mbgl::style::CirclePitchScaleType::Viewport },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::style::CirclePitchScaleType> { intervalStops };

XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue,
@"Setting circleScaleAlignment to a camera expression should update circle-pitch-scale.");
XCTAssertEqualObjects(layer.circleScaleAlignment, functionExpression,
@"circleScaleAlignment should round-trip camera expressions.");



layer.circleScaleAlignment = nil;
XCTAssertTrue(rawLayer->getCirclePitchScale().isUndefined(),
Expand Down Expand Up @@ -447,7 +441,7 @@ - (void)testProperties {
{ 18, { 1, 0, 0, 1 } },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::Color> { intervalStops };

XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue,
@"Setting circleStrokeColor to a camera expression should update circle-stroke-color.");
XCTAssertEqualObjects(layer.circleStrokeColor, functionExpression,
Expand Down Expand Up @@ -478,7 +472,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleStrokeColor, pedanticFunctionExpression,
@"circleStrokeColor should round-trip camera-data expressions.");


layer.circleStrokeColor = nil;
XCTAssertTrue(rawLayer->getCircleStrokeColor().isUndefined(),
Expand Down Expand Up @@ -519,7 +512,7 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue,
@"Setting circleStrokeOpacity to a camera expression should update circle-stroke-opacity.");
XCTAssertEqualObjects(layer.circleStrokeOpacity, functionExpression,
Expand Down Expand Up @@ -550,7 +543,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleStrokeOpacity, pedanticFunctionExpression,
@"circleStrokeOpacity should round-trip camera-data expressions.");


layer.circleStrokeOpacity = nil;
XCTAssertTrue(rawLayer->getCircleStrokeOpacity().isUndefined(),
Expand Down Expand Up @@ -591,7 +583,7 @@ - (void)testProperties {
{ 18, 0xff },
}};
propertyValue = mbgl::style::CameraFunction<float> { intervalStops };

XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue,
@"Setting circleStrokeWidth to a camera expression should update circle-stroke-width.");
XCTAssertEqualObjects(layer.circleStrokeWidth, functionExpression,
Expand Down Expand Up @@ -622,7 +614,6 @@ - (void)testProperties {
pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
XCTAssertEqualObjects(layer.circleStrokeWidth, pedanticFunctionExpression,
@"circleStrokeWidth should round-trip camera-data expressions.");


layer.circleStrokeWidth = nil;
XCTAssertTrue(rawLayer->getCircleStrokeWidth().isUndefined(),
Expand Down Expand Up @@ -669,13 +660,12 @@ - (void)testProperties {
{ 18, { 1, 1 } },
}};
propertyValue = mbgl::style::CameraFunction<std::array<float, 2>> { intervalStops };

XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue,
@"Setting circleTranslation to a camera expression should update circle-translate.");
XCTAssertEqualObjects(layer.circleTranslation, functionExpression,
@"circleTranslation should round-trip camera expressions.");



layer.circleTranslation = nil;
XCTAssertTrue(rawLayer->getCircleTranslate().isUndefined(),
Expand Down Expand Up @@ -713,13 +703,12 @@ - (void)testProperties {
{ 18, mbgl::style::TranslateAnchorType::Viewport },
}};
propertyValue = mbgl::style::CameraFunction<mbgl::style::TranslateAnchorType> { intervalStops };

XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue,
@"Setting circleTranslationAnchor to a camera expression should update circle-translate-anchor.");
XCTAssertEqualObjects(layer.circleTranslationAnchor, functionExpression,
@"circleTranslationAnchor should round-trip camera expressions.");



layer.circleTranslationAnchor = nil;
XCTAssertTrue(rawLayer->getCircleTranslateAnchor().isUndefined(),
Expand Down
Loading

0 comments on commit 7e26976

Please sign in to comment.