forked from MapComplete/MapComplete
Add the possibility to snap onto another layer with imports, add location confirm on input, add metalayer exporting all nodes, various fixes
This commit is contained in:
parent
f5d6441b70
commit
23ae9d39c8
24 changed files with 807 additions and 390 deletions
|
@ -15,6 +15,8 @@ import LineRenderingConfig from "./LineRenderingConfig";
|
|||
import PointRenderingConfigJson from "./Json/PointRenderingConfigJson";
|
||||
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson";
|
||||
import {TagRenderingConfigJson} from "./Json/TagRenderingConfigJson";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import BaseUIElement from "../../UI/BaseUIElement";
|
||||
|
||||
export default class LayerConfig extends WithContextLoader {
|
||||
|
||||
|
@ -59,11 +61,11 @@ export default class LayerConfig extends WithContextLoader {
|
|||
this.id = json.id;
|
||||
|
||||
if (json.source === undefined) {
|
||||
throw "Layer " + this.id + " does not define a source section ("+context+")"
|
||||
throw "Layer " + this.id + " does not define a source section (" + context + ")"
|
||||
}
|
||||
|
||||
if (json.source.osmTags === undefined) {
|
||||
throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers ("+context+")"
|
||||
throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")"
|
||||
|
||||
}
|
||||
|
||||
|
@ -262,6 +264,15 @@ export default class LayerConfig extends WithContextLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public defaultIcon() : BaseUIElement | undefined{
|
||||
const mapRendering = this.mapRendering.filter(r => r.location.has("point"))[0]
|
||||
if (mapRendering === undefined) {
|
||||
return undefined
|
||||
}
|
||||
const defaultTags = new UIEventSource(TagUtils.changeAsProperties(this.source.osmTags.asChange({id: "node/-1"})))
|
||||
return mapRendering.GenerateLeafletStyle(defaultTags, false, {noSize: true}).html
|
||||
}
|
||||
|
||||
public ExtractLayerTagRenderings(json: LayerConfigJson): TagRenderingConfig[] {
|
||||
|
||||
if (json.tagRenderings === undefined) {
|
||||
|
@ -358,7 +369,6 @@ export default class LayerConfig extends WithContextLoader {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public CustomCodeSnippets(): string[] {
|
||||
if (this.calculatedTags === undefined) {
|
||||
return [];
|
||||
|
@ -366,7 +376,6 @@ export default class LayerConfig extends WithContextLoader {
|
|||
return this.calculatedTags.map((code) => code[1]);
|
||||
}
|
||||
|
||||
|
||||
public ExtractImages(): Set<string> {
|
||||
const parts: Set<string>[] = [];
|
||||
parts.push(...this.tagRenderings?.map((tr) => tr.ExtractImages(false)));
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import {Translation} from "../../UI/i18n/Translation";
|
||||
import TagRenderingConfig from "./TagRenderingConfig";
|
||||
import {LayoutConfigJson} from "./Json/LayoutConfigJson";
|
||||
import SharedTagRenderings from "../../Customizations/SharedTagRenderings";
|
||||
import AllKnownLayers from "../../Customizations/AllKnownLayers";
|
||||
import {Utils} from "../../Utils";
|
||||
import LayerConfig from "./LayerConfig";
|
||||
|
@ -54,6 +52,7 @@ export default class LayoutConfig {
|
|||
public readonly overpassMaxZoom: number
|
||||
public readonly osmApiTileSize: number
|
||||
public readonly official: boolean;
|
||||
public readonly trackAllNodes : boolean;
|
||||
|
||||
constructor(json: LayoutConfigJson, official = true, context?: string) {
|
||||
this.official = official;
|
||||
|
@ -63,6 +62,8 @@ export default class LayoutConfig {
|
|||
this.credits = json.credits;
|
||||
this.version = json.version;
|
||||
this.language = [];
|
||||
this.trackAllNodes = false
|
||||
|
||||
if (typeof json.language === "string") {
|
||||
this.language = [json.language];
|
||||
} else {
|
||||
|
@ -92,12 +93,16 @@ export default class LayoutConfig {
|
|||
if(json.widenFactor > 20){
|
||||
throw "Widenfactor is very big, use a value between 1 and 5 (current value is "+json.widenFactor+") at "+context
|
||||
}
|
||||
|
||||
this.widenFactor = json.widenFactor ?? 1.5;
|
||||
|
||||
this.defaultBackgroundId = json.defaultBackgroundId;
|
||||
this.tileLayerSources = (json.tileLayerSources??[]).map((config, i) => new TilesourceConfig(config, `${this.id}.tileLayerSources[${i}]`))
|
||||
this.layers = LayoutConfig.ExtractLayers(json, official, context);
|
||||
|
||||
const layerInfo = LayoutConfig.ExtractLayers(json, official, context);
|
||||
this.layers = layerInfo.layers
|
||||
this.trackAllNodes = layerInfo.extractAllNodes
|
||||
|
||||
|
||||
this.clustering = {
|
||||
maxZoom: 16,
|
||||
minNeededElements: 25,
|
||||
|
@ -147,10 +152,11 @@ export default class LayoutConfig {
|
|||
|
||||
}
|
||||
|
||||
private static ExtractLayers(json: LayoutConfigJson, official: boolean, context: string): LayerConfig[] {
|
||||
private static ExtractLayers(json: LayoutConfigJson, official: boolean, context: string): {layers: LayerConfig[], extractAllNodes: boolean} {
|
||||
const result: LayerConfig[] = []
|
||||
|
||||
let exportAllNodes = false
|
||||
json.layers.forEach((layer, i) => {
|
||||
|
||||
if (typeof layer === "string") {
|
||||
if (AllKnownLayers.sharedLayersJson.get(layer) !== undefined) {
|
||||
if (json.overrideAll !== undefined) {
|
||||
|
@ -177,12 +183,19 @@ export default class LayoutConfig {
|
|||
result.push(newLayer)
|
||||
return
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
let names = layer.builtin;
|
||||
if (typeof names === "string") {
|
||||
names = [names]
|
||||
}
|
||||
names.forEach(name => {
|
||||
|
||||
if(name === "type_node"){
|
||||
// This is a very special layer which triggers special behaviour
|
||||
exportAllNodes = true;
|
||||
}
|
||||
|
||||
const shared = AllKnownLayers.sharedLayersJson.get(name);
|
||||
if (shared === undefined) {
|
||||
throw `Unknown shared/builtin layer ${name} at ${context}.layers[${i}]. Available layers are ${Array.from(AllKnownLayers.sharedLayersJson.keys()).join(", ")}`;
|
||||
|
@ -199,7 +212,7 @@ export default class LayoutConfig {
|
|||
|
||||
});
|
||||
|
||||
return result
|
||||
return {layers: result, extractAllNodes: exportAllNodes}
|
||||
}
|
||||
|
||||
public CustomCodeSnippets(): string[] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue