LayerServer: make all layer ids unique

This commit is contained in:
Pieter Vander Vennet 2024-01-23 22:03:02 +01:00
parent ef2f1487c6
commit 1d6c9ec1ef
12 changed files with 74 additions and 46 deletions

View file

@ -45,7 +45,7 @@
"hideFromOverview": true,
"layers": [
{
"id": "osm:buildings",
"id": "osm_buildings",
"name": "OSM Buildings",
"title": "OSM Building",
"description": "Layer showing buildings that are in OpenStreetMap",
@ -147,7 +147,7 @@
]
},
{
"id": "osm:adresses",
"id": "osm_adresses",
"name": "OSM Adresses",
"title": "OSM Adress",
"description": "Layer showing adresses that are in OpenStreetMap",
@ -185,7 +185,7 @@
]
},
{
"id": "bag:pand",
"id": "bag_pand",
"name": "BAG Buildings",
"title": "BAG Building",
"description": {
@ -207,7 +207,7 @@
},
"minzoom": 18,
"calculatedTags": [
"_overlaps_with_buildings=overlapWith(feat)('osm:buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)",
"_overlaps_with_buildings=overlapWith(feat)('osm_buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)",
"_overlaps_with=feat(get)('_overlaps_with_buildings').find(f => f.overlap > 1 /* square meter */ )",
"_overlaps_with_properties=feat(get)('_overlaps_with')?.feat?.properties",
"_overlap_percentage=Math.round(100 * (feat(get)('_overlaps_with')?.overlap / feat(get)('_overlaps_with_properties')['_surface:strict']))",
@ -228,7 +228,7 @@
"render": {
"special": {
"type": "import_way_button",
"targetLayer": "osm:buildings",
"targetLayer": "osm_buildings",
"tags": "building=$_bag_obj:building; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date; start_date=$_bag_obj:start_date",
"text": {
"*": "Upload this building to OpenStreetMap"
@ -258,7 +258,7 @@
},
{
"if": "_overlaps_with!=",
"then": "{conflate_button(osm:buildings, building=$_bag_obj:building; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date; start_date=$_bag_obj:start_date, Replace the geometry in OpenStreetMap, , _osm_obj:id)}"
"then": "{conflate_button(osm_buildings, building=$_bag_obj:building; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date; start_date=$_bag_obj:start_date, Replace the geometry in OpenStreetMap, , _osm_obj:id)}"
},
{
"if": {
@ -268,7 +268,7 @@
"_bag_obj:in_construction=true"
]
},
"then": "{import_way_button(osm:buildings, building=$_bag_obj:building; construction=$_bag_obj:construction; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date; start_date=$_bag_obj:start_date, Upload this building to OpenStreetMap)}"
"then": "{import_way_button(osm_buildings, building=$_bag_obj:building; construction=$_bag_obj:construction; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date; start_date=$_bag_obj:start_date, Upload this building to OpenStreetMap)}"
}
]
},
@ -348,7 +348,7 @@
},
{
"id": "Overlapping building",
"render": "<div>The overlapping <a href=https://osm.org/{_osm_obj:id} target=_blank>osm:buildings</a> is a <b>{_osm_obj:building}</b> and covers <b>{_overlap_percentage}%</b> of the BAG building.<br>The BAG-building covers <b>{_reverse_overlap_percentage}%</b> of the OSM building<div><h3>BAG geometry:</h3>{minimap(21, id):height:10rem;border-radius:1rem;overflow:hidden}<h3>OSM geometry:</h3>{minimap(21,_osm_obj:id):height:10rem;border-radius:1rem;overflow:hidden}</div></div>",
"render": "<div>The overlapping <a href=https://osm.org/{_osm_obj:id} target=_blank>osm_buildings</a> is a <b>{_osm_obj:building}</b> and covers <b>{_overlap_percentage}%</b> of the BAG building.<br>The BAG-building covers <b>{_reverse_overlap_percentage}%</b> of the OSM building<div><h3>BAG geometry:</h3>{minimap(21, id):height:10rem;border-radius:1rem;overflow:hidden}<h3>OSM geometry:</h3>{minimap(21,_osm_obj:id):height:10rem;border-radius:1rem;overflow:hidden}</div></div>",
"condition": "_overlaps_with!="
},
{
@ -386,7 +386,7 @@
]
},
{
"id": "bag:verblijfsobject",
"id": "bag_verblijfsobject",
"name": "BAG Addresses",
"title": "BAG Address",
"description": "Address information from the BAG register",
@ -398,7 +398,7 @@
},
"minzoom": 18,
"calculatedTags": [
"_closed_osm_addr:=closest(feat)('osm:adresses').properties",
"_closed_osm_addr:=closest(feat)('osm_adresses').properties",
"_bag_obj:addr:housenumber=`${feat.properties.huisnummer}${feat.properties.huisletter}${(feat.properties.toevoeging != '') ? '-' : ''}${feat.properties.toevoeging}`",
"_bag_obj:ref:bag=Number(feat.properties.identificatie)",
"_bag_obj:source:date=new Date().toISOString().split('T')[0]",
@ -411,7 +411,7 @@
"tagRenderings": [
{
"id": "Import button",
"render": "{import_button(osm:adresses, addr:city=$woonplaats; addr:housenumber=$_bag_obj:addr:housenumber; addr:postcode=$postcode; addr:street=$openbare_ruimte; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date, Upload this adress to OpenStreetMap)}",
"render": "{import_button(osm_adresses, addr:city=$woonplaats; addr:housenumber=$_bag_obj:addr:housenumber; addr:postcode=$postcode; addr:street=$openbare_ruimte; ref:bag=$_bag_obj:ref:bag; source=BAG; source:date=$_bag_obj:source:date, Upload this adress to OpenStreetMap)}",
"condition": "_imported_osm_object_found=false"
},
{

View file

@ -32,7 +32,7 @@
"hideFromOverview": true,
"layers": [
{
"id": "node2node",
"id": "node2node_bicycle",
"name": {
"en": "Node to node links",
"de": "Knotenpunktverbindungen",
@ -126,7 +126,7 @@
"pointRendering": null
},
{
"id": "node",
"id": "node_bicycle",
"name": {
"en": "Nodes",
"de": "Knotenpunkte",
@ -321,6 +321,7 @@
],
"override": {
"minzoom": 16,
"id": "bicycle_guidepost",
"source": {
"osmTags": {
"and": [

View file

@ -290,7 +290,7 @@
]
},
{
"id": "all_streets",
"id": "not_cyclestreets",
"name": {
"nl": "Alle straten",
"en": "All streets",

View file

@ -29,7 +29,7 @@
"hideFromOverview": true,
"layers": [
{
"id": "osm-buildings",
"id": "osm_buildings_no_points",
"name": "All OSM-buildings",
"source": {
"osmTags": {
@ -296,7 +296,7 @@
"name": "GRB geometries",
"title": "GRB outline",
"calculatedTags": [
"_overlaps_with_buildings=overlapWith(feat)('osm-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0) ?? []",
"_overlaps_with_buildings=overlapWith(feat)('osm_buildings_no_points').filter(f => f.feat.properties.id.indexOf('-') < 0) ?? []",
"_overlaps_with=get(feat)('_overlaps_with_buildings').find(f => f.overlap > 1 /* square meter */ )",
"_osm_obj:source:ref=get(feat)('_overlaps_with')?.feat?.properties['source:geometry:ref']",
"_osm_obj:id=get(feat)('_overlaps_with')?.feat?.properties?.id",
@ -319,7 +319,7 @@
"tagRenderings": [
{
"id": "Import-button",
"render": "{import_way_button(osm-buildings,building=$building;man_made=$man_made; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref; addr:street=$addr:street; addr:housenumber=$addr:housenumber; building:min_level=$_building:min_level, Upload this building to OpenStreetMap,,_is_part_of_building=true,1,_moveable=true)}",
"render": "{import_way_button(osm_buildings_no_points,building=$building;man_made=$man_made; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref; addr:street=$addr:street; addr:housenumber=$addr:housenumber; building:min_level=$_building:min_level, Upload this building to OpenStreetMap,,_is_part_of_building=true,1,_moveable=true)}",
"mappings": [
{
"#": "Failsafe",
@ -371,7 +371,7 @@
"addr:housenumber!:={_osm_obj:addr:housenumber}"
]
},
"then": "{conflate_button(osm-buildings,building=$_target_building_type; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref; addr:street=$addr:street; addr:housenumber=$addr:housenumber, Replace the geometry in OpenStreetMap and add the address,,_osm_obj:id)}"
"then": "{conflate_button(osm_buildings_no_points,building=$_target_building_type; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref; addr:street=$addr:street; addr:housenumber=$addr:housenumber, Replace the geometry in OpenStreetMap and add the address,,_osm_obj:id)}"
},
{
"if": {
@ -380,7 +380,7 @@
"_reverse_overlap_percentage>50"
]
},
"then": "{conflate_button(osm-buildings,building=$_target_building_type; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref, Replace the geometry in OpenStreetMap,,_osm_obj:id)}"
"then": "{conflate_button(osm_buildings_no_points,building=$_target_building_type; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref, Replace the geometry in OpenStreetMap,,_osm_obj:id)}"
}
]
},
@ -612,7 +612,7 @@
"builtin": "crab_address",
"override": {
"calculatedTags+": [
"_embedded_in=overlapWith(feat)('osm-buildings').filter(b => /* Do not match newly created objects */ b.feat.properties.id.indexOf('-') < 0)[0]?.feat?.properties ?? {}",
"_embedded_in=overlapWith(feat)('osm_buildings_no_points').filter(b => /* Do not match newly created objects */ b.feat.properties.id.indexOf('-') < 0)[0]?.feat?.properties ?? {}",
"_embedding_nr=get(feat)('_embedded_in')['addr:housenumber']+(get(feat)('_embedded_in')['addr:unit'] ?? '')",
"_embedding_street=get(feat)('_embedded_in')['addr:street']",
"_embedding_id=get(feat)('_embedded_in').id",
@ -709,7 +709,7 @@
"text": {
"nl": "Voeg dit adres als een nieuw adrespunt toe"
},
"snap_onto_layers": "osm-buildings"
"snap_onto_layers": "osm_buildings_no_points"
}
},
"mappings": [

View file

@ -39,7 +39,7 @@
{
"builtin": "shops",
"override": {
"id": "medical-shops",
"id": "medical_shops",
"minzoom": 13,
"=filter": [
"open_now",

View file

@ -46,6 +46,7 @@
{
"builtin": "crossings",
"override": {
"id": "crossings_no_traffic_lights",
"=presets": [
{
"title": {

View file

@ -258,6 +258,7 @@
{
"builtin": "parking_spaces",
"override": {
"id": "parking_spaces_disabled",
"source": {
"osmTags": "parking_space=disabled"
},

View file

@ -14,7 +14,7 @@
{
"builtin": "shops",
"override": {
"id": "erotic-shop",
"id": "erotic_shop",
"source": {
"osmTags": "shop=erotic"
},

View file

@ -53,6 +53,7 @@
"builtin": "shelter",
"override": {
"minzoom": 18,
"id": "pt_shelter",
"source": {
"osmTags": {
"and": [

View file

@ -185,7 +185,7 @@
]
},
{
"id": "address",
"id": "uk_address",
"name": {
"en": "Known addresses in OSM"
},

View file

@ -21,7 +21,7 @@
"hideFromOverview": true,
"layers": [
{
"id": "node2node",
"id": "node2node_hiking",
"name": {
"en": "Node to node links",
"de": "Knotenpunktverbindungen",
@ -120,7 +120,7 @@
]
},
{
"id": "node",
"id": "node_hiking",
"name": {
"en": "Nodes",
"de": "Knotenpunkte",
@ -279,6 +279,7 @@
],
"override": {
"minzoom": 16,
"id": "guidepost_hiking",
"source": {
"osmTags": {
"and": [

View file

@ -33,12 +33,14 @@ class LuaSnippets{
].join("\n")
}
}
class GenerateLayerLua {
private readonly _layer: LayerConfig
constructor(layer: LayerConfig) {
this._layer = layer
}
public functionName() {
const l = this._layer
if (!l.source?.osmTags) {
@ -75,10 +77,38 @@ class GenerateLayerLua {
" ",
` pois_${l.id}:insert(a)`,
"end",
""
"",
].join("\n")
}
private regexTagToLua(tag: RegexTag) {
if (typeof tag.value === "string" && tag.invert) {
return `object.tags["${tag.key}"] ~= "${tag.value}"`
}
if ("" + tag.value === "/.+/is" && !tag.invert) {
return `object.tags["${tag.key}"] ~= nil`
}
if ("" + tag.value === "/.+/is" && tag.invert) {
return `object.tags["${tag.key}"] == nil`
}
if (tag.matchesEmpty && !tag.invert) {
return `object.tags["${tag.key}"] == nil or object.tags["${tag.key}"] == ""`
}
if (tag.matchesEmpty && tag.invert) {
return `object.tags["${tag.key}"] ~= nil or object.tags["${tag.key}"] ~= ""`
}
if (tag.invert) {
return `object.tags["${tag.key}"] == nil or not string.find(object.tags["${tag.key}"], "${tag.value}")`
}
return `(object.tags["${tag.key}"] ~= nil and string.find(object.tags["${tag.key}"], "${tag.value}"))`
}
private toLuaFilter(tag: TagsFilter, useParens: boolean = false): string {
if (tag instanceof Tag) {
@ -99,14 +129,7 @@ class GenerateLayerLua {
return expr
}
if (tag instanceof RegexTag) {
if(typeof tag.value === "string" && tag.invert){
return `object.tags["${tag.key}"] ~= "${tag.value}"`
}
let expr = `not string.find(object.tags["${tag.key}"], "${tag.value}")`
if (!tag.invert) {
expr = "not " + expr
}
let expr = this.regexTagToLua(tag)
if (useParens) {
expr = "(" + expr + ")"
}
@ -124,14 +147,14 @@ class GenerateLayerFile extends Script {
}
async main(args: string[]) {
const layerNames = Array.from(AllSharedLayers.sharedLayers.values())
const layers = Array.from(AllSharedLayers.sharedLayers.values())
const generators = layerNames.map(l => new GenerateLayerLua(l))
const generators = layers.filter(l => l.source.geojsonSource === undefined).map(l => new GenerateLayerLua(l))
const script = [
...generators.map(g => g.generateFunction()),
LuaSnippets.combine(Utils.NoNull(generators.map(g => g.functionName()))),
LuaSnippets.tail
LuaSnippets.tail,
].join("\n\n\n")
const path = "build_db.lua"
fs.writeFileSync(path, script, "utf-8")