Add detection for negative tagging in layers, fix issue with 'key!=' being interpreted as 'key!=*', add tests
This commit is contained in:
parent
360f83f04f
commit
b5e289764e
10 changed files with 49 additions and 3 deletions
|
@ -238,4 +238,8 @@ export class And extends TagsFilter {
|
|||
|
||||
return new And(newAnds)
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return !this.and.some(t => !t.isNegative());
|
||||
}
|
||||
}
|
|
@ -59,4 +59,8 @@ export default class ComparingTag implements TagsFilter {
|
|||
optimize(): TagsFilter | boolean {
|
||||
return this;
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -167,6 +167,10 @@ export class Or extends TagsFilter {
|
|||
|
||||
return new Or(newOrs)
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return this.or.some(t => t.isNegative());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -197,4 +197,8 @@ export class RegexTag extends TagsFilter {
|
|||
optimize(): TagsFilter | boolean {
|
||||
return this;
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return this.invert;
|
||||
}
|
||||
}
|
|
@ -89,4 +89,8 @@ export default class SubstitutingTag implements TagsFilter {
|
|||
optimize(): TagsFilter | boolean {
|
||||
return this;
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -120,4 +120,8 @@ export class Tag extends TagsFilter {
|
|||
optimize(): TagsFilter | boolean {
|
||||
return this;
|
||||
}
|
||||
|
||||
isNegative(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -172,7 +172,7 @@ export class TagUtils {
|
|||
*
|
||||
* TagUtils.Tag("key=value") // => new Tag("key", "value")
|
||||
* TagUtils.Tag("key=") // => new Tag("key", "")
|
||||
* TagUtils.Tag("key!=") // => new RegexTag("key", "^..*$", true)
|
||||
* TagUtils.Tag("key!=") // => new RegexTag("key", "^..*$")
|
||||
* TagUtils.Tag("key!=value") // => new RegexTag("key", /^value$/, true)
|
||||
* TagUtils.Tag("vending~.*bicycle_tube.*") // => new RegexTag("vending", /^.*bicycle_tube.*$/)
|
||||
* TagUtils.Tag("x!~y") // => new RegexTag("x", /^y$/, true)
|
||||
|
@ -298,6 +298,7 @@ export class TagUtils {
|
|||
}
|
||||
if (split[1] === "") {
|
||||
split[1] = "..*"
|
||||
return new RegexTag(split[0], /^..*$/)
|
||||
}
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
|
|
|
@ -33,5 +33,21 @@ export abstract class TagsFilter {
|
|||
*/
|
||||
abstract optimize(): TagsFilter | boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Returns 'true' if the tagsfilter might select all features (i.e. the filter will return everything from OSM, except a few entries).
|
||||
*
|
||||
* A typical negative tagsfilter is 'key!=value'
|
||||
*
|
||||
* import {RegexTag} from "./RegexTag";
|
||||
* import {Tag} from "./Tag";
|
||||
* import {And} from "./And";
|
||||
* import {Or} from "./Or";
|
||||
*
|
||||
* new Tag("key","value").isNegative() // => false
|
||||
* new And([new RegexTag("key","value", true)]).isNegative() // => true
|
||||
* new Or([new RegexTag("key","value", true), new Tag("x","y")]).isNegative() // => true
|
||||
* new And([new RegexTag("key","value", true), new Tag("x","y")]).isNegative() // => false
|
||||
*/
|
||||
abstract isNegative(): boolean
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@ import {Utils} from "../Utils";
|
|||
|
||||
export default class Constants {
|
||||
|
||||
public static vNumber = "0.17.0";
|
||||
public static vNumber = "0.17.1";
|
||||
|
||||
public static ImgurApiKey = '7070e7167f0a25a'
|
||||
public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85"
|
||||
|
|
|
@ -101,6 +101,10 @@ export default class LayerConfig extends WithContextLoader {
|
|||
context + "source.osmTags"
|
||||
);
|
||||
|
||||
if(Constants.priviliged_layers.indexOf(this.id) < 0 && osmTags.isNegative()){
|
||||
throw context + "The source states tags which give a very wide selection: it only uses negative expressions, which will result in too much and unexpected data. Add at least one required tag. The tags are:\n\t"+osmTags.asHumanString(false, false, {});
|
||||
}
|
||||
|
||||
if (json.source["geoJsonSource"] !== undefined) {
|
||||
throw context + "Use 'geoJson' instead of 'geoJsonSource'";
|
||||
}
|
||||
|
@ -108,6 +112,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
if (json.source["geojson"] !== undefined) {
|
||||
throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)";
|
||||
}
|
||||
|
||||
|
||||
this.source = new SourceConfig(
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue