Studio: WIP

This commit is contained in:
Pieter Vander Vennet 2023-09-19 14:04:13 +02:00
parent 3549a10a15
commit dc82ebbd58
165 changed files with 2588 additions and 3294 deletions

View file

@ -2,7 +2,6 @@ import { Conversion } from "./Conversion"
import LayerConfig from "../LayerConfig"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import Translations from "../../../UI/i18n/Translations"
import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"
import { Translation, TypedTranslation } from "../../../UI/i18n/Translation"
export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, LayerConfigJson> {
@ -45,13 +44,6 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
isShownIfAny.push({ and: mustMatchAll })
}
const pointRenderings = (layerJson.mapRendering ?? []).filter(
(r) => r !== null && r["location"] !== undefined
)
const firstRender = <PointRenderingConfigJson>pointRenderings[0]
if (firstRender === undefined) {
throw `Layer ${layerJson.id} does not have a pointRendering: ` + context
}
const title = layer.presets[0].title
const importButton = {}
@ -186,7 +178,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
},
},
],
mapRendering: [
pointRendering: [
{
location: ["point"],
icon: {

View file

@ -82,8 +82,8 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
if (config.mapRendering === undefined) {
config.mapRendering = []
if (config["mapRendering"] === undefined) {
config["mapRendering"] = []
// This is a legacy format, lets create a pointRendering
let location: ("point" | "centroid")[] = ["point"]
let wayHandling: number = config["wayHandling"] ?? 0
@ -99,7 +99,7 @@ export class UpdateLegacyLayer extends DesugaringStep<
location,
rotation: config["rotation"],
}
config.mapRendering.push(pointConfig)
config["mapRendering"].push(pointConfig)
}
if (wayHandling !== 1) {
@ -109,10 +109,10 @@ export class UpdateLegacyLayer extends DesugaringStep<
dashArray: config["dashArray"],
}
if (Object.keys(lineRenderConfig).length > 0) {
config.mapRendering.push(lineRenderConfig)
config["mapRendering"].push(lineRenderConfig)
}
}
if (config.mapRendering.length === 0) {
if (config["mapRendering"].length === 0) {
throw (
"Could not convert the legacy theme into a new theme: no renderings defined for layer " +
config.id
@ -132,7 +132,7 @@ export class UpdateLegacyLayer extends DesugaringStep<
delete config["wayHandling"]
delete config["hideUnderlayingFeaturesMinPercentage"]
for (const mapRenderingElement of config.mapRendering ?? []) {
for (const mapRenderingElement of config["mapRendering"] ?? []) {
if (mapRenderingElement["iconOverlays"] !== undefined) {
mapRenderingElement["iconBadges"] = mapRenderingElement["iconOverlays"]
}
@ -144,13 +144,28 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
for (const rendering of config.mapRendering ?? []) {
if (!rendering["iconSize"]) {
if (config["mapRendering"]) {
const pointRenderings: PointRenderingConfigJson[] = []
const lineRenderings: LineRenderingConfigJson[] = []
for (const mapRenderingElement of config["mapRendering"]) {
if (mapRenderingElement["location"]) {
// This is a pointRendering
pointRenderings.push(<any>mapRenderingElement)
} else {
lineRenderings.push(<any>mapRenderingElement)
}
}
config["pointRendering"] = pointRenderings
config["lineRendering"] = lineRenderings
delete config["mapRendering"]
}
for (const rendering of config.pointRendering ?? []) {
const pr = rendering
let iconSize = pr.iconSize
if (!iconSize) {
continue
}
const pr = <PointRenderingConfigJson>rendering
let iconSize = pr.iconSize
console.log("Iconsize is", iconSize)
if (Object.keys(pr.iconSize).length === 1 && pr.iconSize["render"] !== undefined) {
iconSize = pr.iconSize["render"]
@ -164,7 +179,22 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
for (const rendering of config.mapRendering) {
for (const rendering of config.pointRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue
}
if (
typeof rendering[key]["render"] === "string" &&
Object.keys(rendering[key]).length === 1
) {
console.log("Rewrite: ", rendering[key])
rendering[key] = rendering[key]["render"]
}
}
}
for (const rendering of config.lineRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue

View file

@ -9,6 +9,8 @@ import LineRenderingConfigJson from "./LineRenderingConfigJson"
import { QuestionableTagRenderingConfigJson } from "./QuestionableTagRenderingConfigJson"
import RewritableConfigJson from "./RewritableConfigJson"
import { Translatable } from "./Translatable"
import { Point } from "geojson"
import PointRenderingConfig from "../PointRenderingConfig"
type MapRendering = {}
@ -238,12 +240,16 @@ export interface LayerConfigJson {
titleIcons?: (string | TagRenderingConfigJson)[] | ["defaults"]
/**
* Visualisation of the items on the map
* Set 'null' explicitly if you do not want a maprendering
* Creates points to render on the map.
* This can render points for point-objects, lineobjects or areaobjects; use 'location' to indicate where it should be rendered
* group: maprendering
* types: PointRendering ; LineRendering
*/
mapRendering?: (PointRenderingConfigJson | LineRenderingConfigJson)[]
pointRendering: PointRenderingConfigJson[]
/**
* Creates lines and areas to render on the map
* group: maprendering
*/
lineRendering?: LineRenderingConfigJson[]
/**
* If set, this layer will pass all the features it receives onto the next layer.

View file

@ -12,8 +12,6 @@ import MoveConfig from "./MoveConfig"
import PointRenderingConfig from "./PointRenderingConfig"
import WithContextLoader from "./WithContextLoader"
import LineRenderingConfig from "./LineRenderingConfig"
import PointRenderingConfigJson from "./Json/PointRenderingConfigJson"
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import BaseUIElement from "../../UI/BaseUIElement"
import Combine from "../../UI/Base/Combine"
@ -265,34 +263,27 @@ export default class LayerConfig extends WithContextLoader {
return config
})
if (json.mapRendering === undefined) {
throw "MapRendering is undefined in " + context
if (json.pointRendering === undefined && json.lineRendering === undefined) {
throw "Both pointRendering and lineRendering are undefined in " + context
}
if (json.mapRendering === null) {
this.mapRendering = []
this.lineRendering = []
if (json.lineRendering) {
this.lineRendering = Utils.NoNull(json.lineRendering).map(
(r, i) => new LineRenderingConfig(r, `${context}[${i}]`)
)
} else {
this.mapRendering = Utils.NoNull(json.mapRendering)
.filter((r) => r["location"] !== undefined)
.map(
(r, i) =>
new PointRenderingConfig(
<PointRenderingConfigJson>r,
context + ".mapRendering[" + i + "]"
)
)
this.lineRendering = []
}
this.lineRendering = Utils.NoNull(json.mapRendering)
.filter((r) => r["location"] === undefined)
.map(
(r, i) =>
new LineRenderingConfig(
<LineRenderingConfigJson>r,
context + ".mapRendering[" + i + "]"
)
)
if (json.pointRendering) {
this.mapRendering = Utils.NoNull(json.pointRendering).map(
(r, i) => new PointRenderingConfig(r, `${context}[${i}]`)
)
} else {
this.mapRendering = []
}
{
const hasCenterRendering = this.mapRendering.some(
(r) =>
r.location.has("centroid") ||
@ -301,16 +292,22 @@ export default class LayerConfig extends WithContextLoader {
r.location.has("end")
)
if (this.lineRendering.length === 0 && this.mapRendering.length === 0) {
if (
json.pointRendering !== null &&
json.lineRendering !== null &&
this.lineRendering.length === 0 &&
this.mapRendering.length === 0
) {
throw (
"The layer " +
this.id +
" does not have any maprenderings defined and will thus not show up on the map at all. If this is intentional, set maprenderings to 'null' instead of '[]'"
" does not have any maprenderings defined and will thus not show up on the map at all. If this is intentional, set `pointRendering` and `lineRendering` to 'null' instead of '[]'"
)
} else if (
!hasCenterRendering &&
this.lineRendering.length === 0 &&
Constants.priviliged_layers.indexOf(<any>this.id) < 0 &&
this.source !== null /*library layer*/ &&
!this.source?.geojsonSource?.startsWith(
"https://api.openstreetmap.org/api/0.6/notes.json"
)

View file

@ -404,7 +404,7 @@ class LineRenderingLayer {
export default class ShowDataLayer {
private static rangeLayer = new LayerConfig(
<LayerConfigJson>range_layer,
<any>range_layer,
"ShowDataLayer.ts:range.json"
)
private readonly _map: Store<MlMap>

View file

@ -44,7 +44,13 @@ export default class QueryParameterDocumentation {
source: {
osmTags: "id~*",
},
mapRendering: null,
lineRendering: [
{
color: "#000000",
width: 5,
},
],
pointRendering: null,
},
],
})