Merge pull request #579 from orangemug/fix/function-field-fixes

Function field fixes
This commit is contained in:
Orange Mug 2019-10-27 17:58:06 +00:00 committed by GitHub
commit 4644e78fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View file

@ -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.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 /** 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)

View file

@ -11,7 +11,7 @@ import ArrayInput from '../inputs/ArrayInput'
import DynamicArrayInput from '../inputs/DynamicArrayInput' import DynamicArrayInput from '../inputs/DynamicArrayInput'
import FontInput from '../inputs/FontInput' import FontInput from '../inputs/FontInput'
import IconInput from '../inputs/IconInput' import IconInput from '../inputs/IconInput'
import EnumInput from '../inputs/SelectInput' import EnumInput from '../inputs/EnumInput'
import capitalize from 'lodash.capitalize' import capitalize from 'lodash.capitalize'
const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image'] const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image']