Added the ability to convert from data/zoom function to expression

This commit is contained in:
orangemug 2020-02-17 11:52:40 +00:00
parent 793b5d15ad
commit 3ffdcc9639
3 changed files with 24 additions and 1 deletions

View file

@ -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}
/>
)
}

View file

@ -269,6 +269,12 @@ export default class DataProperty extends React.Component {
>
Add stop
</Button>
<Button
className="maputnik-add-stop"
onClick={this.props.onExpressionClick.bind(this)}
>
Convert to expression
</Button>
</div>
}
}

View file

@ -177,6 +177,12 @@ export default class ZoomProperty extends React.Component {
>
Add stop
</Button>
<Button
className="maputnik-add-stop"
onClick={this.props.onExpressionClick.bind(this)}
>
Convert to expression
</Button>
</div>
}
}