mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-29 07:10:27 +01:00
Merge pull request #168 from orangemug/feature/issue-114-boolean-types
Added true/false conversion to filter field
This commit is contained in:
commit
36cd15f4f1
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