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 {Utils} from "../Utils";
|
||||
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig";
|
||||
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||
|
||||
export default class SharedTagRenderings {
|
||||
|
||||
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);
|
||||
|
||||
private static generatedSharedFields(iconsOnly = false): Map<string, TagRenderingConfig> {
|
||||
const dict = new Map<string, TagRenderingConfig>();
|
||||
|
||||
function add(key, store) {
|
||||
const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly)
|
||||
const d = new Map<string, TagRenderingConfig>()
|
||||
for (const key of Array.from(configJsons.keys())) {
|
||||
try {
|
||||
dict.set(key, new TagRenderingConfig(store[key], undefined, `SharedTagRenderings.${key}`))
|
||||
d.set(key, new TagRenderingConfig(configJsons.get(key), undefined, `SharedTagRenderings.${key}`))
|
||||
} catch (e) {
|
||||
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)
|
||||
|
@ -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) {
|
||||
for (const key in questions) {
|
||||
add(key, questions);
|
||||
dict.set(key, <TagRenderingConfigJson>questions[key])
|
||||
}
|
||||
}
|
||||
for (const key in icons) {
|
||||
add(key, icons);
|
||||
dict.set(key, <TagRenderingConfigJson>icons[key])
|
||||
}
|
||||
|
||||
return dict;
|
||||
|
|
|
@ -2,7 +2,7 @@ import {Utils} from "../Utils";
|
|||
|
||||
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
|
||||
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.
|
||||
*
|
||||
*/
|
||||
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
|
||||
*/
|
||||
function trs(
|
||||
tagRenderings?: (string | TagRenderingConfigJson)[],
|
||||
tagRenderings?: (string | { builtin: string, override: any } | TagRenderingConfigJson)[],
|
||||
readOnly = false
|
||||
) {
|
||||
if (tagRenderings === undefined) {
|
||||
|
@ -224,7 +224,12 @@ export default class LayerConfig {
|
|||
return Utils.NoNull(
|
||||
tagRenderings.map((renderingJson, i) => {
|
||||
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) {
|
||||
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
|
||||
|
@ -234,26 +239,34 @@ export default class LayerConfig {
|
|||
return new TagRenderingConfig("questions", undefined);
|
||||
}
|
||||
|
||||
const shared =
|
||||
SharedTagRenderings.SharedTagRendering.get(renderingJson);
|
||||
if (renderingJson["override"] !== undefined) {
|
||||
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) {
|
||||
return shared;
|
||||
}
|
||||
if (Utils.runningFromConsole) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const keys = Array.from(
|
||||
SharedTagRenderings.SharedTagRendering.keys()
|
||||
);
|
||||
|
||||
if (Utils.runningFromConsole) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
throw `Predefined tagRendering ${renderingJson} not found in ${context}.\n Try one of ${keys.join(
|
||||
throw `Predefined tagRendering ${renderingId} not found in ${context}.\n Try one of ${keys.join(
|
||||
", "
|
||||
)}\n If you intent to output this text literally, use {\"render\": <your text>} instead"}`;
|
||||
}
|
||||
|
||||
return new TagRenderingConfig(
|
||||
renderingJson,
|
||||
<TagRenderingConfigJson>renderingJson,
|
||||
self.source.osmTags,
|
||||
`${context}.tagrendering[${i}]`
|
||||
);
|
||||
|
|
|
@ -67,7 +67,9 @@ export default class TagRenderingConfig {
|
|||
}
|
||||
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 = {
|
||||
key: json.freeform.key,
|
||||
type: json.freeform.type ?? "string",
|
||||
|
|
Loading…
Reference in a new issue