mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-29 08:00:32 +01:00
Added true/false conversion to filter fields. Fixes #114
This commit is contained in:
parent
c950a33031
commit
611e170b5e
1 changed files with 24 additions and 1 deletions
|
@ -11,6 +11,29 @@ function tryParseInt(v) {
|
||||||
return parseFloat(v)
|
return parseFloat(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tryParseBool(v) {
|
||||||
|
const isString = (typeof(v) === "string");
|
||||||
|
if(!isString) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(v.match(/^\s*true\s*$/)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(v.match(/^\s*false\s*$/)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseFilter(v) {
|
||||||
|
v = tryParseInt(v);
|
||||||
|
v = tryParseBool(v);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
class SingleFilterEditor extends React.Component {
|
class SingleFilterEditor extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
filter: React.PropTypes.array.isRequired,
|
filter: React.PropTypes.array.isRequired,
|
||||||
|
@ -23,7 +46,7 @@ class SingleFilterEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onFilterPartChanged(filterOp, propertyName, filterArgs) {
|
onFilterPartChanged(filterOp, propertyName, filterArgs) {
|
||||||
let newFilter = [filterOp, propertyName, ...filterArgs.map(tryParseInt)]
|
let newFilter = [filterOp, propertyName, ...filterArgs.map(parseFilter)]
|
||||||
if(filterOp === 'has' || filterOp === '!has') {
|
if(filterOp === 'has' || filterOp === '!has') {
|
||||||
newFilter = [filterOp, propertyName]
|
newFilter = [filterOp, propertyName]
|
||||||
} else if(filterArgs.length === 0) {
|
} else if(filterArgs.length === 0) {
|
||||||
|
|
Loading…
Reference in a new issue