forked from MapComplete/MapComplete
Merge develop
This commit is contained in:
commit
897c59f97a
35 changed files with 1792 additions and 1172 deletions
|
@ -55,6 +55,8 @@ export interface LayerConfigJson {
|
|||
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
|
||||
* to use a tiled geojson source. The web server must offer multiple geojsons. {z}, {x} and {y} are substituted by the location; {layer} is substituted with the id of the loaded layer
|
||||
*
|
||||
* Some API's use a BBOX instead of a tile, this can be used by specifying {y_min}, {y_max}, {x_min} and {x_max}
|
||||
* Some API's use a mercator-projection (EPSG:900913) instead of WGS84. Set the flag `mercatorCrs: true` in the source for this
|
||||
*
|
||||
* Note that both geojson-options might set a flag 'isOsmCache' indicating that the data originally comes from OSM too
|
||||
*
|
||||
|
@ -63,7 +65,7 @@ export interface LayerConfigJson {
|
|||
* While still supported, this is considered deprecated
|
||||
*/
|
||||
source: ({ osmTags: AndOrTagConfigJson | string, overpassScript?: string } |
|
||||
{ osmTags: AndOrTagConfigJson | string, geoJson: string, geoJsonZoomLevel?: number, isOsmCache?: boolean }) & ({
|
||||
{ osmTags: AndOrTagConfigJson | string, geoJson: string, geoJsonZoomLevel?: number, isOsmCache?: boolean, mercatorCrs?: boolean }) & ({
|
||||
/**
|
||||
* The maximum amount of seconds that a tile is allowed to linger in the cache
|
||||
*/
|
||||
|
|
|
@ -89,6 +89,7 @@ export interface TagRenderingConfigJson {
|
|||
* Allows fixed-tag inputs, shown either as radiobuttons or as checkboxes
|
||||
*/
|
||||
mappings?: {
|
||||
|
||||
/**
|
||||
* If this condition is met, then the text under `then` will be shown.
|
||||
* If no value matches, and the user selects this mapping as an option, then these tags will be uploaded to OSM.
|
||||
|
@ -173,5 +174,12 @@ export interface TagRenderingConfigJson {
|
|||
* If this is important to your usecase, consider using multiple radiobutton-fields without `multiAnswer`
|
||||
*/
|
||||
ifnot?: AndOrTagConfigJson | string
|
||||
|
||||
/**
|
||||
* If chosen as answer, these tags will be applied as well onto the object.
|
||||
* Not compatible with multiAnswer
|
||||
*/
|
||||
addExtraTags: string[]
|
||||
|
||||
}[]
|
||||
}
|
|
@ -96,6 +96,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
geojsonSourceLevel: json.source["geoJsonZoomLevel"],
|
||||
overpassScript: json.source["overpassScript"],
|
||||
isOsmCache: json.source["isOsmCache"],
|
||||
mercatorCrs: json.source["mercatorCrs"]
|
||||
},
|
||||
json.id
|
||||
);
|
||||
|
|
|
@ -270,7 +270,6 @@ export default class LayoutConfig {
|
|||
}
|
||||
rewriting.forEach((value, key) => {
|
||||
console.log("Rewriting", key, "==>", value)
|
||||
|
||||
originalJson = originalJson.replace(new RegExp(key, "g"), value)
|
||||
})
|
||||
return new LayoutConfig(JSON.parse(originalJson), false, "Layout rewriting")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import {RegexTag} from "../../Logic/Tags/RegexTag";
|
||||
|
||||
export default class SourceConfig {
|
||||
|
||||
|
@ -7,8 +8,10 @@ export default class SourceConfig {
|
|||
public readonly geojsonSource?: string;
|
||||
public readonly geojsonZoomLevel?: number;
|
||||
public readonly isOsmCacheLayer: boolean;
|
||||
public readonly mercatorCrs: boolean;
|
||||
|
||||
constructor(params: {
|
||||
mercatorCrs?: boolean;
|
||||
osmTags?: TagsFilter,
|
||||
overpassScript?: string,
|
||||
geojsonSource?: string,
|
||||
|
@ -33,10 +36,15 @@ export default class SourceConfig {
|
|||
console.error(params)
|
||||
throw `Source said it is a OSM-cached layer, but didn't define the actual source of the cache (in context ${context})`
|
||||
}
|
||||
this.osmTags = params.osmTags;
|
||||
if(params.geojsonSource !== undefined && params.geojsonSourceLevel !== undefined){
|
||||
if(! ["x","y","x_min","x_max","y_min","Y_max"].some(toSearch => params.geojsonSource.indexOf(toSearch) > 0)){
|
||||
throw `Source defines a geojson-zoomLevel, but does not specify {x} nor {y} (or equivalent), this is probably a bug (in context ${context})`
|
||||
}}
|
||||
this.osmTags = params.osmTags ?? new RegexTag("id",/.*/);
|
||||
this.overpassScript = params.overpassScript;
|
||||
this.geojsonSource = params.geojsonSource;
|
||||
this.geojsonZoomLevel = params.geojsonSourceLevel;
|
||||
this.isOsmCacheLayer = params.isOsmCache ?? false;
|
||||
this.mercatorCrs = params.mercatorCrs ?? false;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import {TagUtils} from "../../Logic/Tags/TagUtils";
|
|||
import {And} from "../../Logic/Tags/And";
|
||||
import ValidatedTextField from "../../UI/Input/ValidatedTextField";
|
||||
import {Utils} from "../../Utils";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
|
||||
/***
|
||||
* The parsed version of TagRenderingConfigJSON
|
||||
|
@ -37,6 +38,7 @@ export default class TagRenderingConfig {
|
|||
readonly ifnot?: TagsFilter,
|
||||
readonly then: Translation
|
||||
readonly hideInAnswer: boolean | TagsFilter
|
||||
readonly addExtraTags: Tag[]
|
||||
}[]
|
||||
|
||||
constructor(json: string | TagRenderingConfigJson, context?: string) {
|
||||
|
@ -118,21 +120,24 @@ export default class TagRenderingConfig {
|
|||
|
||||
this.mappings = json.mappings.map((mapping, i) => {
|
||||
|
||||
|
||||
const ctx = `${context}.mapping[${i}]`
|
||||
if (mapping.then === undefined) {
|
||||
throw `${context}.mapping[${i}]: Invalid mapping: if without body`
|
||||
throw `${ctx}: Invalid mapping: if without body`
|
||||
}
|
||||
if (mapping.ifnot !== undefined && !this.multiAnswer) {
|
||||
throw `${context}.mapping[${i}]: Invalid mapping: ifnot defined, but the tagrendering is not a multianswer`
|
||||
throw `${ctx}: Invalid mapping: ifnot defined, but the tagrendering is not a multianswer`
|
||||
}
|
||||
|
||||
if (mapping.if === undefined) {
|
||||
throw `${context}.mapping[${i}]: Invalid mapping: "if" is not defined, but the tagrendering is not a multianswer`
|
||||
throw `${ctx}: Invalid mapping: "if" is not defined, but the tagrendering is not a multianswer`
|
||||
}
|
||||
if (typeof mapping.if !== "string" && mapping.if["length"] !== undefined) {
|
||||
throw `${context}.mapping[${i}]: Invalid mapping: "if" is defined as an array. Use {"and": <your conditions>} or {"or": <your conditions>} instead`
|
||||
throw `${ctx}: Invalid mapping: "if" is defined as an array. Use {"and": <your conditions>} or {"or": <your conditions>} instead`
|
||||
}
|
||||
|
||||
if(mapping.addExtraTags !== undefined && this.multiAnswer){
|
||||
throw `${ctx}: Invalid mapping: got a multi-Answer with addExtraTags; this is not allowed`
|
||||
}
|
||||
|
||||
|
||||
let hideInAnswer: boolean | TagsFilter = false;
|
||||
if (typeof mapping.hideInAnswer === "boolean") {
|
||||
|
@ -140,12 +145,12 @@ export default class TagRenderingConfig {
|
|||
} else if (mapping.hideInAnswer !== undefined) {
|
||||
hideInAnswer = TagUtils.Tag(mapping.hideInAnswer, `${context}.mapping[${i}].hideInAnswer`);
|
||||
}
|
||||
const mappingContext = `${context}.mapping[${i}]`
|
||||
const mp = {
|
||||
if: TagUtils.Tag(mapping.if, `${mappingContext}.if`),
|
||||
ifnot: (mapping.ifnot !== undefined ? TagUtils.Tag(mapping.ifnot, `${mappingContext}.ifnot`) : undefined),
|
||||
then: Translations.T(mapping.then, `${mappingContext}.then`),
|
||||
hideInAnswer: hideInAnswer
|
||||
if: TagUtils.Tag(mapping.if, `${ctx}.if`),
|
||||
ifnot: (mapping.ifnot !== undefined ? TagUtils.Tag(mapping.ifnot, `${ctx}.ifnot`) : undefined),
|
||||
then: Translations.T(mapping.then, `${ctx}.then`),
|
||||
hideInAnswer: hideInAnswer,
|
||||
addExtraTags: (mapping.addExtraTags??[]).map((str, j) => TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`))
|
||||
};
|
||||
if (this.question) {
|
||||
if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue