summaryrefslogtreecommitdiff
path: root/scripts/generate-style-code.js
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-28 16:39:50 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-02 09:44:42 -0800
commit141e995806576364d185626176c1b993fc519291 (patch)
treeecdc41fc7699f2a1a9e9456157348451ebe99597 /scripts/generate-style-code.js
parent6a6bddb4537004cc1bfc506e76772de74d33f3f7 (diff)
downloadqtlocation-mapboxgl-141e995806576364d185626176c1b993fc519291.tar.gz
[core] Add support for data-driven styling
Diffstat (limited to 'scripts/generate-style-code.js')
-rw-r--r--scripts/generate-style-code.js45
1 files changed, 40 insertions, 5 deletions
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index d090dff872..de68c33ceb 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -14,7 +14,11 @@ function parseCSSColor(str) {
];
}
-global.propertyType = function (property) {
+global.isDataDriven = function (property) {
+ return property['property-function'] === true;
+};
+
+global.evaluatedType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
}
@@ -34,14 +38,45 @@ global.propertyType = function (property) {
return `Color`;
case 'array':
if (property.length) {
- return `std::array<${propertyType({type: property.value})}, ${property.length}>`;
+ return `std::array<${evaluatedType({type: property.value})}, ${property.length}>`;
} else {
- return `std::vector<${propertyType({type: property.value})}>`;
+ return `std::vector<${evaluatedType({type: property.value})}>`;
}
default: throw new Error(`unknown type for ${property.name}`)
}
};
+function attributeType(property, type) {
+ const name = property.name.replace(type + '-', '').replace('-', '_');
+ return `attributes::a_${name}${name === 'offset' ? '<1>' : ''}`;
+}
+
+global.layoutPropertyType = function (property) {
+ if (isDataDriven(property)) {
+ return `DataDrivenLayoutProperty<${evaluatedType(property)}>`;
+ } else {
+ return `LayoutProperty<${evaluatedType(property)}>`;
+ }
+};
+
+global.paintPropertyType = function (property, type) {
+ if (isDataDriven(property)) {
+ return `DataDrivenPaintProperty<${evaluatedType(property)}, ${attributeType(property, type)}>`;
+ } else if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') {
+ return `CrossFadedPaintProperty<${evaluatedType(property)}>`;
+ } else {
+ return `PaintProperty<${evaluatedType(property)}>`;
+ }
+};
+
+global.propertyValueType = function (property) {
+ if (isDataDriven(property)) {
+ return `DataDrivenPropertyValue<${evaluatedType(property)}>`;
+ } else {
+ return `PropertyValue<${evaluatedType(property)}>`;
+ }
+};
+
global.defaultValue = function (property) {
// https://github.com/mapbox/mapbox-gl-native/issues/5258
if (property.name === 'line-round-limit') {
@@ -59,9 +94,9 @@ global.defaultValue = function (property) {
return JSON.stringify(property.default || "");
case 'enum':
if (property.default === undefined) {
- return `${propertyType(property)}::Undefined`;
+ return `${evaluatedType(property)}::Undefined`;
} else {
- return `${propertyType(property)}::${camelize(property.default)}`;
+ return `${evaluatedType(property)}::${camelize(property.default)}`;
}
case 'color':
const color = parseCSSColor(property.default).join(', ');