Better tag rendering stealing capacity
This commit is contained in:
parent
c940890eca
commit
b5693304f2
4 changed files with 104 additions and 213 deletions
|
@ -10,23 +10,75 @@ export default class AllKnownLayers {
|
|||
|
||||
public static inited = (_ => {
|
||||
WithContextLoader.getKnownTagRenderings = (id => AllKnownLayers.getTagRendering(id))
|
||||
return true
|
||||
return true
|
||||
})()
|
||||
|
||||
|
||||
|
||||
// Must be below the list...
|
||||
public static sharedLayers: Map<string, LayerConfig> = AllKnownLayers.getSharedLayers();
|
||||
public static sharedLayersJson: Map<string, any> = AllKnownLayers.getSharedLayersJson();
|
||||
|
||||
|
||||
public static added_by_default: string[] = ["gps_location","gps_location_history", "home_location", "gps_track",]
|
||||
public static no_include: string[] = [ "conflation", "left_right_style"]
|
||||
public static added_by_default: string[] = ["gps_location", "gps_location_history", "home_location", "gps_track",]
|
||||
public static no_include: string[] = ["conflation", "left_right_style"]
|
||||
/**
|
||||
* Layer IDs of layers which have special properties through built-in hooks
|
||||
*/
|
||||
public static priviliged_layers: string[] = [...AllKnownLayers.added_by_default, "type_node",...AllKnownLayers.no_include]
|
||||
public static priviliged_layers: string[] = [...AllKnownLayers.added_by_default, "type_node", ...AllKnownLayers.no_include]
|
||||
|
||||
/**
|
||||
* Gets the appropriate tagRenderingJSON
|
||||
* Allows to steal them from other layers.
|
||||
* This will add the tags of the layer to the configuration though!
|
||||
* @param renderingId
|
||||
*/
|
||||
static getTagRendering(renderingId: string): TagRenderingConfigJson[] {
|
||||
if (renderingId.indexOf(".") < 0) {
|
||||
const found = SharedTagRenderings.SharedTagRenderingJson.get(renderingId)
|
||||
if(found === undefined){
|
||||
return []
|
||||
}
|
||||
return [found]
|
||||
}
|
||||
|
||||
const [layerId, id] = renderingId.split(".")
|
||||
const layer = AllKnownLayers.getSharedLayersJson().get(layerId)
|
||||
if (layer === undefined) {
|
||||
if (Utils.runningFromConsole) {
|
||||
// Probably generating the layer overview
|
||||
return <TagRenderingConfigJson[]>[{
|
||||
id: "dummy"
|
||||
}]
|
||||
}
|
||||
throw "Builtin layer " + layerId + " not found"
|
||||
}
|
||||
|
||||
const renderings = layer?.tagRenderings ?? []
|
||||
if (id === "*") {
|
||||
return <TagRenderingConfigJson[]>JSON.parse(JSON.stringify(renderings))
|
||||
}
|
||||
|
||||
const selectByGroup = id.startsWith("*")
|
||||
const expectedGroupName = id.substring(1)
|
||||
|
||||
const allValidValues = []
|
||||
for (const rendering of renderings) {
|
||||
if ((!selectByGroup && rendering["id"] === id) || (selectByGroup && rendering["group"] === expectedGroupName)) {
|
||||
const found = <TagRenderingConfigJson>JSON.parse(JSON.stringify(rendering))
|
||||
if (found.condition === undefined) {
|
||||
found.condition = layer.source.osmTags
|
||||
} else {
|
||||
found.condition = {and: [found.condition, layer.source.osmTags]}
|
||||
}
|
||||
allValidValues.push(found)
|
||||
}
|
||||
}
|
||||
if(allValidValues.length === 0){
|
||||
|
||||
throw `The rendering with id ${id} was not found in the builtin layer ${layerId}. Try one of ${Utils.NoNull(renderings.map(r => r["id"])).join(", ")}`
|
||||
}
|
||||
return allValidValues
|
||||
}
|
||||
|
||||
private static getSharedLayers(): Map<string, LayerConfig> {
|
||||
const sharedLayers = new Map<string, LayerConfig>();
|
||||
|
@ -75,41 +127,4 @@ export default class AllKnownLayers {
|
|||
return sharedLayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the appropriate tagRenderingJSON
|
||||
* Allows to steal them from other layers.
|
||||
* This will add the tags of the layer to the configuration though!
|
||||
* @param renderingId
|
||||
*/
|
||||
static getTagRendering(renderingId: string): TagRenderingConfigJson {
|
||||
if(renderingId.indexOf(".") < 0){
|
||||
return SharedTagRenderings.SharedTagRenderingJson.get(renderingId)
|
||||
}
|
||||
|
||||
const [layerId, id] = renderingId.split(".")
|
||||
const layer = AllKnownLayers.getSharedLayersJson().get(layerId)
|
||||
if(layer === undefined){
|
||||
if(Utils.runningFromConsole){
|
||||
// Probably generating the layer overview
|
||||
return <TagRenderingConfigJson> {
|
||||
id: "dummy"
|
||||
}
|
||||
}
|
||||
throw "Builtin layer "+layerId+" not found"
|
||||
}
|
||||
const renderings = layer?.tagRenderings ?? []
|
||||
for (const rendering of renderings) {
|
||||
if(rendering["id"] === id){
|
||||
const found = <TagRenderingConfigJson> JSON.parse(JSON.stringify(rendering))
|
||||
if(found.condition === undefined){
|
||||
found.condition = layer.source.osmTags
|
||||
}else{
|
||||
found.condition = {and: [found.condition, layer.source.osmTags]}
|
||||
}
|
||||
return found
|
||||
}
|
||||
}
|
||||
throw `The rendering with id ${id} was not found in the builtin layer ${layerId}. Try one of ${Utils.NoNull(renderings.map(r => r["id"])).join(", ")}`
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue