mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-13 03:14:14 +01:00
Make up defaults from function field if we can't find one from the spec.
This commit is contained in:
parent
ca202d7701
commit
4cbcf14588
1 changed files with 23 additions and 4 deletions
|
@ -14,6 +14,25 @@ function isDataField(value) {
|
||||||
return typeof value === 'object' && value.stops && typeof value.property !== 'undefined'
|
return typeof value === 'object' && value.stops && typeof value.property !== 'undefined'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we don't have a default value just make one up
|
||||||
|
*/
|
||||||
|
function findDefaultFromSpec (spec) {
|
||||||
|
if (spec.default) {
|
||||||
|
return spec.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
'color': '#000000',
|
||||||
|
'string': '',
|
||||||
|
'boolean': false,
|
||||||
|
'number': 0,
|
||||||
|
'array': [],
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaults[spec.type] || '';
|
||||||
|
}
|
||||||
|
|
||||||
/** Supports displaying spec field for zoom function objects
|
/** Supports displaying spec field for zoom function objects
|
||||||
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
||||||
*/
|
*/
|
||||||
|
@ -82,8 +101,8 @@ export default class FunctionSpecProperty extends React.Component {
|
||||||
makeZoomFunction = () => {
|
makeZoomFunction = () => {
|
||||||
const zoomFunc = {
|
const zoomFunc = {
|
||||||
stops: [
|
stops: [
|
||||||
[6, this.props.value],
|
[6, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
[10, this.props.value]
|
[10, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
this.props.onChange(this.props.fieldName, zoomFunc)
|
this.props.onChange(this.props.fieldName, zoomFunc)
|
||||||
|
@ -96,8 +115,8 @@ export default class FunctionSpecProperty extends React.Component {
|
||||||
property: "",
|
property: "",
|
||||||
type: functionType,
|
type: functionType,
|
||||||
stops: [
|
stops: [
|
||||||
[{zoom: 6, value: stopValue}, this.props.value || stopValue],
|
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
[{zoom: 10, value: stopValue}, this.props.value || stopValue]
|
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
this.props.onChange(this.props.fieldName, dataFunc)
|
this.props.onChange(this.props.fieldName, dataFunc)
|
||||||
|
|
Loading…
Reference in a new issue