mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-14 20:33:26 +01:00
Merge pull request #579 from orangemug/fix/function-field-fixes
Function field fixes
This commit is contained in:
commit
4644e78fd2
2 changed files with 24 additions and 5 deletions
|
@ -14,6 +14,25 @@ function isDataField(value) {
|
|||
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.hasOwnProperty('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
|
||||
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
||||
*/
|
||||
|
@ -82,8 +101,8 @@ export default class FunctionSpecProperty extends React.Component {
|
|||
makeZoomFunction = () => {
|
||||
const zoomFunc = {
|
||||
stops: [
|
||||
[6, this.props.value],
|
||||
[10, this.props.value]
|
||||
[6, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||
[10, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||
]
|
||||
}
|
||||
this.props.onChange(this.props.fieldName, zoomFunc)
|
||||
|
@ -96,8 +115,8 @@ export default class FunctionSpecProperty extends React.Component {
|
|||
property: "",
|
||||
type: functionType,
|
||||
stops: [
|
||||
[{zoom: 6, value: stopValue}, this.props.value || stopValue],
|
||||
[{zoom: 10, value: stopValue}, this.props.value || stopValue]
|
||||
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||
]
|
||||
}
|
||||
this.props.onChange(this.props.fieldName, dataFunc)
|
||||
|
|
|
@ -11,7 +11,7 @@ import ArrayInput from '../inputs/ArrayInput'
|
|||
import DynamicArrayInput from '../inputs/DynamicArrayInput'
|
||||
import FontInput from '../inputs/FontInput'
|
||||
import IconInput from '../inputs/IconInput'
|
||||
import EnumInput from '../inputs/SelectInput'
|
||||
import EnumInput from '../inputs/EnumInput'
|
||||
import capitalize from 'lodash.capitalize'
|
||||
|
||||
const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image']
|
||||
|
|
Loading…
Reference in a new issue