From 3ffdcc9639764f41d0a87a0f1fd6810feb05ba46 Mon Sep 17 00:00:00 2001 From: orangemug Date: Mon, 17 Feb 2020 11:52:40 +0000 Subject: [PATCH] Added the ability to convert from data/zoom function to expression --- src/components/fields/FunctionSpecField.jsx | 13 ++++++++++++- src/components/fields/_DataProperty.jsx | 6 ++++++ src/components/fields/_ZoomProperty.jsx | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/fields/FunctionSpecField.jsx b/src/components/fields/FunctionSpecField.jsx index fb12a45b..e5a45375 100644 --- a/src/components/fields/FunctionSpecField.jsx +++ b/src/components/fields/FunctionSpecField.jsx @@ -5,6 +5,7 @@ import SpecProperty from './_SpecProperty' import DataProperty from './_DataProperty' import ZoomProperty from './_ZoomProperty' import ExpressionProperty from './_ExpressionProperty' +import {function as styleFunction} from '@mapbox/mapbox-gl-style-spec'; function isLiteralExpression (value) { @@ -218,7 +219,15 @@ export default class FunctionSpecProperty extends React.Component { } makeExpression = () => { - const expression = ["literal", this.props.value || this.props.fieldSpec.default]; + const {value, fieldSpec} = this.props; + let expression; + + if (typeof(value) === "object" && 'stops' in value) { + expression = styleFunction.convertFunction(value, fieldSpec); + } + else { + expression = ["literal", value || this.props.fieldSpec.default]; + } this.props.onChange(this.props.fieldName, expression); } @@ -277,6 +286,7 @@ export default class FunctionSpecProperty extends React.Component { value={this.props.value} onDeleteStop={this.deleteStop} onAddStop={this.addStop} + onExpressionClick={this.makeExpression} /> ) } @@ -291,6 +301,7 @@ export default class FunctionSpecProperty extends React.Component { value={this.props.value} onDeleteStop={this.deleteStop} onAddStop={this.addStop} + onExpressionClick={this.makeExpression} /> ) } diff --git a/src/components/fields/_DataProperty.jsx b/src/components/fields/_DataProperty.jsx index f3cef010..7503d62c 100644 --- a/src/components/fields/_DataProperty.jsx +++ b/src/components/fields/_DataProperty.jsx @@ -269,6 +269,12 @@ export default class DataProperty extends React.Component { > Add stop + } } diff --git a/src/components/fields/_ZoomProperty.jsx b/src/components/fields/_ZoomProperty.jsx index 21bb7f7b..3db421f2 100644 --- a/src/components/fields/_ZoomProperty.jsx +++ b/src/components/fields/_ZoomProperty.jsx @@ -177,6 +177,12 @@ export default class ZoomProperty extends React.Component { > Add stop + } }