Added 'base' to functions.

This commit is contained in:
orangemug 2020-09-08 16:50:29 +01:00
parent 8b766777ac
commit 9103d9560a
3 changed files with 61 additions and 0 deletions

View file

@ -206,6 +206,7 @@ export default class FieldFunction extends React.Component {
if (typeof(value) === "object") { if (typeof(value) === "object") {
if (value.stops) { if (value.stops) {
zoomFunc = { zoomFunc = {
base: value.base,
stops: value.stops.map(stop => { stops: value.stops.map(stop => {
return [stop[0].zoom, stop[1] || findDefaultFromSpec(this.props.fieldSpec)]; return [stop[0].zoom, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
}) })
@ -213,6 +214,7 @@ export default class FieldFunction extends React.Component {
} }
else { else {
zoomFunc = { zoomFunc = {
base: value.base,
stops: [ stops: [
[6, findDefaultFromSpec(this.props.fieldSpec)], [6, findDefaultFromSpec(this.props.fieldSpec)],
[10, findDefaultFromSpec(this.props.fieldSpec)] [10, findDefaultFromSpec(this.props.fieldSpec)]
@ -289,6 +291,7 @@ export default class FieldFunction extends React.Component {
dataFunc = { dataFunc = {
property: "", property: "",
type: functionType, type: functionType,
base: value.base,
stops: value.stops.map(stop => { stops: value.stops.map(stop => {
return [{zoom: stop[0], value: stopValue}, stop[1] || findDefaultFromSpec(this.props.fieldSpec)]; return [{zoom: stop[0], value: stopValue}, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
}) })
@ -298,6 +301,7 @@ export default class FieldFunction extends React.Component {
dataFunc = { dataFunc = {
property: "", property: "",
type: functionType, type: functionType,
base: value.base,
stops: [ stops: [
[{zoom: 6, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)], [{zoom: 6, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)],
[{zoom: 10, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)] [{zoom: 10, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)]
@ -309,6 +313,7 @@ export default class FieldFunction extends React.Component {
dataFunc = { dataFunc = {
property: "", property: "",
type: functionType, type: functionType,
base: value.base,
stops: [ stops: [
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)], [{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)] [{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]

View file

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import {mdiFunctionVariant, mdiTableRowPlusAfter} from '@mdi/js'; import {mdiFunctionVariant, mdiTableRowPlusAfter} from '@mdi/js';
import {latest} from '@mapbox/mapbox-gl-style-spec'
import InputButton from './InputButton' import InputButton from './InputButton'
import InputSpec from './InputSpec' import InputSpec from './InputSpec'
@ -167,6 +168,18 @@ export default class DataProperty extends React.Component {
this.onChange(this.props.fieldName, changedValue) this.onChange(this.props.fieldName, changedValue)
} }
changeBase(newValue) {
const changedValue = {
...this.props.value,
base: newValue
}
if (changedValue.base === undefined) {
delete changedValue["base"];
}
this.props.onChange(this.props.fieldName, changedValue)
}
changeDataType(propVal) { changeDataType(propVal) {
if (propVal === "interpolate") { if (propVal === "interpolate") {
this.props.onChangeToZoomFunction(); this.props.onChangeToZoomFunction();
@ -292,6 +305,7 @@ export default class DataProperty extends React.Component {
<div className="maputnik-data-fieldset-inner"> <div className="maputnik-data-fieldset-inner">
<Block <Block
label={"Function"} label={"Function"}
key="function"
> >
<div className="maputnik-data-spec-property-input"> <div className="maputnik-data-spec-property-input">
<InputSelect <InputSelect
@ -302,8 +316,24 @@ export default class DataProperty extends React.Component {
/> />
</div> </div>
</Block> </Block>
{this.props.value.type !== "identity" &&
<Block
label={"Base"}
key="base"
>
<div className="maputnik-data-spec-property-input">
<InputSpec
fieldName={"base"}
fieldSpec={latest.function.base}
value={this.props.value.base}
onChange={(_, newValue) => this.changeBase(newValue)}
/>
</div>
</Block>
}
<Block <Block
label={"Property"} label={"Property"}
key="property"
> >
<div className="maputnik-data-spec-property-input"> <div className="maputnik-data-spec-property-input">
<InputString <InputString
@ -316,6 +346,7 @@ export default class DataProperty extends React.Component {
{dataFields && {dataFields &&
<Block <Block
label={"Default"} label={"Default"}
key="default"
> >
<InputSpec <InputSpec
fieldName={this.props.fieldName} fieldName={this.props.fieldName}

View file

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import {mdiFunctionVariant, mdiTableRowPlusAfter} from '@mdi/js'; import {mdiFunctionVariant, mdiTableRowPlusAfter} from '@mdi/js';
import {latest} from '@mapbox/mapbox-gl-style-spec'
import InputButton from './InputButton' import InputButton from './InputButton'
import InputSpec from './InputSpec' import InputSpec from './InputSpec'
@ -126,6 +127,18 @@ export default class ZoomProperty extends React.Component {
this.props.onChange(this.props.fieldName, changedValue) this.props.onChange(this.props.fieldName, changedValue)
} }
changeBase(newValue) {
const changedValue = {
...this.props.value,
base: newValue
}
if (changedValue.base === undefined) {
delete changedValue["base"];
}
this.props.onChange(this.props.fieldName, changedValue)
}
changeDataType = (type) => { changeDataType = (type) => {
if (type !== "interpolate") { if (type !== "interpolate") {
this.props.onChangeToDataFunction(type); this.props.onChangeToDataFunction(type);
@ -195,6 +208,18 @@ export default class ZoomProperty extends React.Component {
/> />
</div> </div>
</Block> </Block>
<Block
label={"Base"}
>
<div className="maputnik-data-spec-property-input">
<InputSpec
fieldName={"base"}
fieldSpec={latest.function.base}
value={this.props.value.base}
onChange={(_, newValue) => this.changeBase(newValue)}
/>
</div>
</Block>
<div className="maputnik-function-stop"> <div className="maputnik-function-stop">
<table className="maputnik-function-stop-table maputnik-function-stop-table--zoom"> <table className="maputnik-function-stop-table maputnik-function-stop-table--zoom">
<caption>Stops</caption> <caption>Stops</caption>