forked from MapComplete/MapComplete
I should have commited sooner...
This commit is contained in:
parent
2685b6e734
commit
16612b10ef
35 changed files with 570 additions and 177 deletions
|
@ -8,23 +8,33 @@ import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
|||
import {Translation} from "../../UI/i18n/Translation";
|
||||
import {Img} from "../../UI/Img";
|
||||
import Svg from "../../Svg";
|
||||
import {SubstitutedTranslation} from "../../UI/SpecialVisualizations";
|
||||
import {Utils} from "../../Utils";
|
||||
import Combine from "../../UI/Base/Combine";
|
||||
import {Browser} from "leaflet";
|
||||
|
||||
export default class LayerConfig {
|
||||
|
||||
|
||||
id: string;
|
||||
|
||||
name: Translation
|
||||
|
||||
description: Translation;
|
||||
overpassTags: TagsFilter;
|
||||
doNotDownload: boolean;
|
||||
|
||||
passAllFeatures: boolean;
|
||||
|
||||
minzoom: number;
|
||||
|
||||
title: TagRenderingConfig;
|
||||
title?: TagRenderingConfig;
|
||||
|
||||
titleIcons: TagRenderingConfig[];
|
||||
|
||||
icon: TagRenderingConfig;
|
||||
iconSize: TagRenderingConfig;
|
||||
rotation: TagRenderingConfig;
|
||||
color: TagRenderingConfig;
|
||||
width: TagRenderingConfig;
|
||||
dashArray: TagRenderingConfig;
|
||||
|
@ -53,10 +63,11 @@ export default class LayerConfig {
|
|||
this.name = Translations.T(json.name);
|
||||
this.description = Translations.T(json.name);
|
||||
this.overpassTags = FromJSON.Tag(json.overpassTags, context + ".overpasstags");
|
||||
this.doNotDownload = json.doNotDownload ?? false,
|
||||
this.passAllFeatures = json.passAllFeatures ?? false;
|
||||
this.minzoom = json.minzoom;
|
||||
this.wayHandling = json.wayHandling ?? 0;
|
||||
this.hideUnderlayingFeaturesMinPercentage = json.hideUnderlayingFeaturesMinPercentage ?? 0;
|
||||
this.title = new TagRenderingConfig(json.title);
|
||||
this.presets = (json.presets ?? []).map(pr =>
|
||||
({
|
||||
title: Translations.T(pr.title),
|
||||
|
@ -93,7 +104,10 @@ export default class LayerConfig {
|
|||
|
||||
function tr(key, deflt) {
|
||||
const v = json[key];
|
||||
if (v === undefined) {
|
||||
if (v === undefined || v === null) {
|
||||
if (deflt === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return new TagRenderingConfig(deflt);
|
||||
}
|
||||
if (typeof v === "string") {
|
||||
|
@ -107,11 +121,19 @@ export default class LayerConfig {
|
|||
}
|
||||
|
||||
|
||||
this.title = tr("title", "");
|
||||
this.title = tr("title", undefined);
|
||||
this.icon = tr("icon", Img.AsData(Svg.bug));
|
||||
const iconPath = this.icon.GetRenderValue({id: "node/-1"}).txt;
|
||||
if (iconPath.startsWith(Utils.assets_path)) {
|
||||
const iconKey = iconPath.substr(Utils.assets_path.length);
|
||||
if (Svg.All[iconKey] === undefined) {
|
||||
throw "Builtin SVG asset not found: " + iconPath
|
||||
}
|
||||
}
|
||||
this.iconSize = tr("iconSize", "40,40,center");
|
||||
this.color = tr("color", "#0000ff");
|
||||
this.width = tr("width", "7");
|
||||
this.rotation = tr("rotation", "0");
|
||||
this.dashArray = tr("dashArray", "");
|
||||
|
||||
|
||||
|
@ -121,13 +143,16 @@ export default class LayerConfig {
|
|||
public GenerateLeafletStyle(tags: any):
|
||||
{
|
||||
color: string;
|
||||
icon: { popupAnchor: [number, number]; iconAnchor: [number, number]; iconSize: [number, number]; iconUrl: string }; weight: number; dashArray: number[]
|
||||
icon: {
|
||||
iconUrl: string,
|
||||
popupAnchor: [number, number];
|
||||
iconAnchor: [number, number];
|
||||
iconSize: [number, number];
|
||||
html: string;
|
||||
rotation: number;
|
||||
};
|
||||
weight: number; dashArray: number[]
|
||||
} {
|
||||
const iconUrl = this.icon?.GetRenderValue(tags)?.txt;
|
||||
const iconSize = (this.iconSize?.GetRenderValue(tags)?.txt ?? "40,40,center").split(",");
|
||||
|
||||
|
||||
const dashArray = this.dashArray.GetRenderValue(tags)?.txt.split(" ").map(Number);
|
||||
|
||||
function num(str, deflt = 40) {
|
||||
const n = Number(str);
|
||||
|
@ -137,6 +162,33 @@ export default class LayerConfig {
|
|||
return n;
|
||||
}
|
||||
|
||||
function rendernum(tr: TagRenderingConfig, deflt: number) {
|
||||
const str = Number(render(tr, "" + deflt));
|
||||
const n = Number(str);
|
||||
if (isNaN(n)) {
|
||||
return deflt;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function render(tr: TagRenderingConfig, deflt?: string) {
|
||||
const str = (tr?.GetRenderValue(tags)?.txt ?? deflt);
|
||||
return SubstitutedTranslation.SubstituteKeys(str, tags);
|
||||
}
|
||||
|
||||
const iconUrl = render(this.icon);
|
||||
const iconSize = render(this.iconSize, "40,40,center").split(",");
|
||||
const dashArray = render(this.dashArray).split(" ").map(Number);
|
||||
let color = render(this.color, "#00f");
|
||||
|
||||
if (color.startsWith("--")) {
|
||||
color = getComputedStyle(document.body).getPropertyValue("--catch-detail-color")
|
||||
}
|
||||
|
||||
const weight = rendernum(this.width, 5);
|
||||
const rotation = rendernum(this.rotation, 0);
|
||||
|
||||
|
||||
const iconW = num(iconSize[0]);
|
||||
const iconH = num(iconSize[1]);
|
||||
const mode = iconSize[2] ?? "center"
|
||||
|
@ -157,16 +209,22 @@ export default class LayerConfig {
|
|||
anchorH = iconH;
|
||||
}
|
||||
|
||||
|
||||
const color = this.color?.GetRenderValue(tags)?.txt ?? "#00f";
|
||||
let weight = num(this.width?.GetRenderValue(tags)?.txt, 5);
|
||||
let html = `<img src="${iconUrl}" style="width:100%;height:100%;rotate:${rotation}deg;display:block;" />`;
|
||||
if (iconUrl.startsWith(Utils.assets_path)) {
|
||||
const key = iconUrl.substr(Utils.assets_path.length);
|
||||
html = new Combine([
|
||||
(Svg.All[key] as string).replace(/stop-color:#000000/g, 'stop-color:' + color)
|
||||
]).SetStyle(`width:100%;height:100%;rotate:${rotation}deg;display:block;`).Render();
|
||||
}
|
||||
return {
|
||||
icon:
|
||||
{
|
||||
iconUrl: iconUrl,
|
||||
html: html,
|
||||
iconSize: [iconW, iconH],
|
||||
iconAnchor: [anchorW, anchorH],
|
||||
popupAnchor: [0, 3 - anchorH]
|
||||
popupAnchor: [0, 3 - anchorH],
|
||||
rotation: rotation,
|
||||
iconUrl: iconUrl
|
||||
},
|
||||
color: color,
|
||||
weight: weight,
|
||||
|
|
|
@ -29,6 +29,12 @@ export interface LayerConfigJson {
|
|||
*/
|
||||
overpassTags: AndOrTagConfigJson | string;
|
||||
|
||||
/**
|
||||
* If set, this layer will not query overpass; but it'll still match the tags above which are by chance returned by other layers.
|
||||
* Works well together with 'passAllFeatures', to add decoration
|
||||
*/
|
||||
doNotDownload?: boolean;
|
||||
|
||||
/**
|
||||
* The zoomlevel at which point the data is shown and loaded.
|
||||
*/
|
||||
|
@ -39,8 +45,13 @@ export interface LayerConfigJson {
|
|||
/**
|
||||
* The title shown in a popup for elements of this layer.
|
||||
*/
|
||||
title: string | TagRenderingConfigJson;
|
||||
|
||||
title?: string | TagRenderingConfigJson;
|
||||
|
||||
/**
|
||||
* Small icons shown next to the title.
|
||||
* If not specified, the OsmLink and wikipedia links will be used by default.
|
||||
* Use an empty array to hide them
|
||||
*/
|
||||
titleIcons?: (string | TagRenderingConfigJson)[];
|
||||
|
||||
/**
|
||||
|
@ -54,9 +65,14 @@ export interface LayerConfigJson {
|
|||
* Default is '40,40,center'
|
||||
*/
|
||||
iconSize?: string | TagRenderingConfigJson;
|
||||
|
||||
/**
|
||||
* The color for way-elements
|
||||
* The rotation of an icon, useful for e.g. directions
|
||||
*/
|
||||
rotation?: string | TagRenderingConfigJson;
|
||||
|
||||
/**
|
||||
* The color for way-elements and SVG-elements.
|
||||
* If the value starts with "--", the style of the body element will be queried for the corresponding variable instead
|
||||
*/
|
||||
color?: string | TagRenderingConfigJson;
|
||||
/**
|
||||
|
@ -87,6 +103,11 @@ export interface LayerConfigJson {
|
|||
*/
|
||||
hideUnderlayingFeaturesMinPercentage?:number;
|
||||
|
||||
/**
|
||||
* If set, this layer will pass all the features it receives onto the next layer
|
||||
*/
|
||||
passAllFeatures?:boolean
|
||||
|
||||
/**
|
||||
* Presets for this layer
|
||||
*/
|
||||
|
@ -98,6 +119,7 @@ export interface LayerConfigJson {
|
|||
|
||||
/**
|
||||
* All the tag renderings.
|
||||
* A tag rendering is a block that either shows the known value or asks a question.
|
||||
*/
|
||||
tagRenderings?: (string | TagRenderingConfigJson) []
|
||||
}
|
|
@ -102,7 +102,19 @@ export interface LayoutConfigJson {
|
|||
|
||||
|
||||
/**
|
||||
* The layers to display
|
||||
* The layers to display.
|
||||
*
|
||||
* Every layer contains a description of which feature to display - the overpassTags which are queried.
|
||||
* Instead of running one query for every layer, the query is fused.
|
||||
*
|
||||
* Afterwards, every layer is given the list of features.
|
||||
* Every layer takes away the features that match with them*, and give the leftovers to the next layers.
|
||||
*
|
||||
* This implies that the _order_ of the layers is important in the case of features with the same tags;
|
||||
* as the later layers might never receive their feature.
|
||||
*
|
||||
* *layers can also remove 'leftover'-features if the leftovers overlap with a feature in the layer itself
|
||||
*
|
||||
*/
|
||||
layers: (LayerConfigJson | string)[],
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue