forked from MapComplete/MapComplete
Add observation towers, add override capabilities
This commit is contained in:
parent
6db3ce3ab6
commit
550a2030ad
5 changed files with 42 additions and 20 deletions
|
@ -2,18 +2,20 @@ import * as questions from "../assets/tagRenderings/questions.json";
|
||||||
import * as icons from "../assets/tagRenderings/icons.json";
|
import * as icons from "../assets/tagRenderings/icons.json";
|
||||||
import {Utils} from "../Utils";
|
import {Utils} from "../Utils";
|
||||||
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
|
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
|
||||||
|
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||||
|
|
||||||
export default class SharedTagRenderings {
|
export default class SharedTagRenderings {
|
||||||
|
|
||||||
public static SharedTagRendering: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields();
|
public static SharedTagRendering: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields();
|
||||||
|
public static SharedTagRenderingJson: Map<string, TagRenderingConfigJson> = SharedTagRenderings.generatedSharedFieldsJsons();
|
||||||
public static SharedIcons: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(true);
|
public static SharedIcons: Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(true);
|
||||||
|
|
||||||
private static generatedSharedFields(iconsOnly = false): Map<string, TagRenderingConfig> {
|
private static generatedSharedFields(iconsOnly = false): Map<string, TagRenderingConfig> {
|
||||||
const dict = new Map<string, TagRenderingConfig>();
|
const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly)
|
||||||
|
const d = new Map<string, TagRenderingConfig>()
|
||||||
function add(key, store) {
|
for (const key of Array.from(configJsons.keys())) {
|
||||||
try {
|
try {
|
||||||
dict.set(key, new TagRenderingConfig(store[key], undefined, `SharedTagRenderings.${key}`))
|
d.set(key, new TagRenderingConfig(configJsons.get(key), undefined, `SharedTagRenderings.${key}`))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!Utils.runningFromConsole) {
|
if (!Utils.runningFromConsole) {
|
||||||
console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e)
|
console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e)
|
||||||
|
@ -21,14 +23,19 @@ export default class SharedTagRenderings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
private static generatedSharedFieldsJsons(iconsOnly = false): Map<string, TagRenderingConfigJson> {
|
||||||
|
const dict = new Map<string, TagRenderingConfigJson>();
|
||||||
|
|
||||||
if (!iconsOnly) {
|
if (!iconsOnly) {
|
||||||
for (const key in questions) {
|
for (const key in questions) {
|
||||||
add(key, questions);
|
dict.set(key, <TagRenderingConfigJson>questions[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const key in icons) {
|
for (const key in icons) {
|
||||||
add(key, icons);
|
dict.set(key, <TagRenderingConfigJson>icons[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {Utils} from "../Utils";
|
||||||
|
|
||||||
export default class Constants {
|
export default class Constants {
|
||||||
|
|
||||||
public static vNumber = "0.9.6";
|
public static vNumber = "0.9.7";
|
||||||
|
|
||||||
// The user journey states thresholds when a new feature gets unlocked
|
// The user journey states thresholds when a new feature gets unlocked
|
||||||
public static userJourney = {
|
public static userJourney = {
|
||||||
|
|
|
@ -256,7 +256,7 @@ export interface LayerConfigJson {
|
||||||
* A special value is 'questions', which indicates the location of the questions box. If not specified, it'll be appended to the bottom of the featureInfobox.
|
* A special value is 'questions', which indicates the location of the questions box. If not specified, it'll be appended to the bottom of the featureInfobox.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
tagRenderings?: (string | TagRenderingConfigJson) [],
|
tagRenderings?: (string | {builtin: string, override: any} | TagRenderingConfigJson) [],
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -214,7 +214,7 @@ export default class LayerConfig {
|
||||||
* A string is interpreted as a name to call
|
* A string is interpreted as a name to call
|
||||||
*/
|
*/
|
||||||
function trs(
|
function trs(
|
||||||
tagRenderings?: (string | TagRenderingConfigJson)[],
|
tagRenderings?: (string | { builtin: string, override: any } | TagRenderingConfigJson)[],
|
||||||
readOnly = false
|
readOnly = false
|
||||||
) {
|
) {
|
||||||
if (tagRenderings === undefined) {
|
if (tagRenderings === undefined) {
|
||||||
|
@ -224,7 +224,12 @@ export default class LayerConfig {
|
||||||
return Utils.NoNull(
|
return Utils.NoNull(
|
||||||
tagRenderings.map((renderingJson, i) => {
|
tagRenderings.map((renderingJson, i) => {
|
||||||
if (typeof renderingJson === "string") {
|
if (typeof renderingJson === "string") {
|
||||||
if (renderingJson === "questions") {
|
renderingJson = {builtin: renderingJson, override: undefined}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderingJson["builtin"] !== undefined) {
|
||||||
|
const renderingId = renderingJson["builtin"]
|
||||||
|
if (renderingId === "questions") {
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
throw `A tagrendering has a question, but asking a question does not make sense here: is it a title icon or a geojson-layer? ${context}. The offending tagrendering is ${JSON.stringify(
|
throw `A tagrendering has a question, but asking a question does not make sense here: is it a title icon or a geojson-layer? ${context}. The offending tagrendering is ${JSON.stringify(
|
||||||
renderingJson
|
renderingJson
|
||||||
|
@ -234,26 +239,34 @@ export default class LayerConfig {
|
||||||
return new TagRenderingConfig("questions", undefined);
|
return new TagRenderingConfig("questions", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared =
|
if (renderingJson["override"] !== undefined) {
|
||||||
SharedTagRenderings.SharedTagRendering.get(renderingJson);
|
const sharedJson = SharedTagRenderings.SharedTagRenderingJson.get(renderingId)
|
||||||
|
return new TagRenderingConfig(
|
||||||
|
Utils.Merge(renderingJson["override"], sharedJson),
|
||||||
|
self.source.osmTags,
|
||||||
|
`${context}.tagrendering[${i}]+override`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const shared = SharedTagRenderings.SharedTagRendering.get(renderingId);
|
||||||
|
|
||||||
if (shared !== undefined) {
|
if (shared !== undefined) {
|
||||||
return shared;
|
return shared;
|
||||||
}
|
}
|
||||||
|
if (Utils.runningFromConsole) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const keys = Array.from(
|
const keys = Array.from(
|
||||||
SharedTagRenderings.SharedTagRendering.keys()
|
SharedTagRenderings.SharedTagRendering.keys()
|
||||||
);
|
);
|
||||||
|
throw `Predefined tagRendering ${renderingId} not found in ${context}.\n Try one of ${keys.join(
|
||||||
if (Utils.runningFromConsole) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw `Predefined tagRendering ${renderingJson} not found in ${context}.\n Try one of ${keys.join(
|
|
||||||
", "
|
", "
|
||||||
)}\n If you intent to output this text literally, use {\"render\": <your text>} instead"}`;
|
)}\n If you intent to output this text literally, use {\"render\": <your text>} instead"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TagRenderingConfig(
|
return new TagRenderingConfig(
|
||||||
renderingJson,
|
<TagRenderingConfigJson>renderingJson,
|
||||||
self.source.osmTags,
|
self.source.osmTags,
|
||||||
`${context}.tagrendering[${i}]`
|
`${context}.tagrendering[${i}]`
|
||||||
);
|
);
|
||||||
|
|
|
@ -67,7 +67,9 @@ export default class TagRenderingConfig {
|
||||||
}
|
}
|
||||||
if (json.freeform) {
|
if (json.freeform) {
|
||||||
|
|
||||||
|
if(json.freeform.addExtraTags !== undefined && json.freeform.addExtraTags.length === undefined){
|
||||||
|
throw `Freeform.addExtraTags should be a list of strings - not a single string (at ${context})`
|
||||||
|
}
|
||||||
this.freeform = {
|
this.freeform = {
|
||||||
key: json.freeform.key,
|
key: json.freeform.key,
|
||||||
type: json.freeform.type ?? "string",
|
type: json.freeform.type ?? "string",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue