From 444f0bc47c4be612afff3dc375a6462c35a29871 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 30 Dec 2021 22:36:34 +0100 Subject: [PATCH] Add check: layer and theme ids must be lowercase and match [a-z_-]* --- Models/ThemeConfig/LayerConfig.ts | 6 ++++++ Models/ThemeConfig/LayoutConfig.ts | 6 ++++++ assets/themes/aed/aed_brugge.json | 2 +- assets/themes/grb_import/grb.json | 18 +++++++++--------- assets/themes/grb_import/grb_fixme.json | 2 +- assets/themes/grb_import/missing_streets.json | 6 +++--- .../street_lighting/street_lighting_assen.json | 2 +- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Models/ThemeConfig/LayerConfig.ts b/Models/ThemeConfig/LayerConfig.ts index bce97c06c..091422bb6 100644 --- a/Models/ThemeConfig/LayerConfig.ts +++ b/Models/ThemeConfig/LayerConfig.ts @@ -73,7 +73,13 @@ export default class LayerConfig extends WithContextLoader { if (json.source.osmTags === undefined) { throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")" + } + if(json.id.toLowerCase() !== json.id){ + throw `${context}: The id of a layer should be lowercase: ${json.id}` + } + if(json.id.match(/[a-z0-9-_]/) == null){ + throw `${context}: The id of a layer should match [a-z0-9-_]*: ${json.id}` } this.maxAgeOfCache = json.source.maxCacheAge ?? 24 * 60 * 60 * 30 diff --git a/Models/ThemeConfig/LayoutConfig.ts b/Models/ThemeConfig/LayoutConfig.ts index 7fb99c32d..e18cd7d8f 100644 --- a/Models/ThemeConfig/LayoutConfig.ts +++ b/Models/ThemeConfig/LayoutConfig.ts @@ -58,6 +58,12 @@ export default class LayoutConfig { constructor(json: LayoutConfigJson, official = true, context?: string) { this.official = official; this.id = json.id; + if(json.id.toLowerCase() !== json.id){ + throw "The id of a theme should be lowercase: "+json.id + } + if(json.id.match(/[a-z0-9-_]/) == null){ + throw "The id of a theme should match [a-z0-9-_]*: "+json.id + } context = (context ?? "") + "." + this.id; this.maintainer = json.maintainer; this.credits = json.credits; diff --git a/assets/themes/aed/aed_brugge.json b/assets/themes/aed/aed_brugge.json index 92d829d22..01b530198 100644 --- a/assets/themes/aed/aed_brugge.json +++ b/assets/themes/aed/aed_brugge.json @@ -18,7 +18,7 @@ "layers": [ "defibrillator", { - "id": "Brugge", + "id": "brugge", "name": "Brugse dataset", "source": { "osmTags": "Brugs volgnummer~*", diff --git a/assets/themes/grb_import/grb.json b/assets/themes/grb_import/grb.json index 6b2948807..f3cc1d2fd 100644 --- a/assets/themes/grb_import/grb.json +++ b/assets/themes/grb_import/grb.json @@ -93,7 +93,7 @@ } }, { - "id": "OSM-buildings", + "id": "osm-buildings", "name": "All OSM-buildings", "source": { "osmTags": "building~*", @@ -372,13 +372,13 @@ "builtin": "crab_address", "override": { "calculatedTags+": [ - "_embedded_in=feat.overlapWith('OSM-buildings').filter(b => /* Do not match newly created objects */ b.feat.properties.id.indexOf('-') < 0)[0]?.feat?.properties ?? {}", + "_embedded_in=feat.overlapWith('osm-buildings').filter(b => /* Do not match newly created objects */ b.feat.properties.id.indexOf('-') < 0)[0]?.feat?.properties ?? {}", "_embedding_nr=feat.get('_embedded_in')['addr:housenumber']+(feat.get('_embedded_in')['addr:unit'] ?? '')", "_embedding_street=feat.get('_embedded_in')['addr:street']", "_embedding_id=feat.get('_embedded_in').id", "_closeby_addresses=feat.closestn('address',10,undefined,50).map(f => f.feat).filter(addr => addr.properties['addr:street'] == feat.properties['STRAATNM'] && feat.properties['HNRLABEL'] == addr.properties['addr:housenumber'] + (addr.properties['addr:unit']??'') ).length", "_has_identical_closeby_address=feat.get('_closeby_addresses') >= 1 ? 'yes' : 'no'", - "_embedded_in_grb=feat.overlapWith('GRB')[0]?.feat?.properties ?? {}", + "_embedded_in_grb=feat.overlapWith('grb')[0]?.feat?.properties ?? {}", "_embedding_nr_grb=feat.get('_embedded_in_grb')['addr:housenumber']", "_embedding_street_grb=feat.get('_embedded_in_grb')['addr:street']" ], @@ -452,7 +452,7 @@ }, { "id": "import-button", - "render": "{import_button(address, addr:street=$STRAATNM; addr:housenumber=$_HNRLABEL,Voeg dit adres als een nieuw adrespunt toe,,OSM-buildings,5)}", + "render": "{import_button(address, addr:street=$STRAATNM; addr:housenumber=$_HNRLABEL,Voeg dit adres als een nieuw adrespunt toe,,osm-buildings,5)}", "condition": { "and": [ "_embedding_id!=", @@ -469,7 +469,7 @@ } }, { - "id": "GRB", + "id": "grb", "description": "Geometry which comes from GRB with tools to import them", "source": { "osmTags": { @@ -486,7 +486,7 @@ "name": "GRB geometries", "title": "GRB outline", "calculatedTags": [ - "_overlaps_with_buildings=feat.overlapWith('OSM-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)", + "_overlaps_with_buildings=feat.overlapWith('osm-buildings').filter(f => f.feat.properties.id.indexOf('-') < 0)", "_overlaps_with=feat.get('_overlaps_with_buildings').filter(f => f.overlap > 1 /* square meter */ )[0] ?? ''", "_overlap_absolute=feat.get('_overlaps_with')?.overlap", "_overlap_percentage=Math.round(100 * feat.get('_overlap_absolute') / feat.get('_surface')) ", @@ -507,7 +507,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,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": [ { "#": "Hide import button if intersection with other objects are detected", @@ -524,11 +524,11 @@ "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,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": "_overlaps_with!=", - "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,building=$_target_building_type; source:geometry:date=$_grb_date; source:geometry:ref=$_grb_ref, Replace the geometry in OpenStreetMap,,_osm_obj:id)}" } ] }, diff --git a/assets/themes/grb_import/grb_fixme.json b/assets/themes/grb_import/grb_fixme.json index 9a00f3ad1..e1687783f 100644 --- a/assets/themes/grb_import/grb_fixme.json +++ b/assets/themes/grb_import/grb_fixme.json @@ -31,7 +31,7 @@ }, "layers": [ { - "id": "OSM-buildings-fixme", + "id": "osm-buildings-fixme", "name": "OSM-buildings with a fixme", "source": { "osmTags": { diff --git a/assets/themes/grb_import/missing_streets.json b/assets/themes/grb_import/missing_streets.json index 7630d5903..dc82fc85b 100644 --- a/assets/themes/grb_import/missing_streets.json +++ b/assets/themes/grb_import/missing_streets.json @@ -42,7 +42,7 @@ } ], "calculatedTags": [ - "_overlapping=Number(feat.properties.zoom) >= 14 ? feat.overlapWith('OSM-buildings').map(ff => ff.feat.properties) : undefined", + "_overlapping=Number(feat.properties.zoom) >= 14 ? feat.overlapWith('osm-buildings').map(ff => ff.feat.properties) : undefined", "_applicable=feat.get('_overlapping').filter(p => (p._spelling_is_correct === 'true') && (p._singular_import === 'true')).map(p => p.id)", "_applicable_count=feat.get('_applicable')?.length" ], @@ -67,7 +67,7 @@ }, { "id": "autoapply", - "render": "{auto_apply(OSM-buildings, _applicable, apply_streetname, Automatically add all missing streetnames on buildings in view)}" + "render": "{auto_apply(osm-buildings, _applicable, apply_streetname, Automatically add all missing streetnames on buildings in view)}" } ] } @@ -89,7 +89,7 @@ } }, { - "id": "OSM-buildings", + "id": "osm-buildings", "name": "Alle OSM-gebouwen met een huisnummer en zonder straat", "source": { "osmTags": { diff --git a/assets/themes/street_lighting/street_lighting_assen.json b/assets/themes/street_lighting/street_lighting_assen.json index 7f98cdcd7..fe515dba0 100644 --- a/assets/themes/street_lighting/street_lighting_assen.json +++ b/assets/themes/street_lighting/street_lighting_assen.json @@ -19,7 +19,7 @@ "layers": [ "street_lamps", { - "id": "Assen", + "id": "assen", "name": "Dataset Assen", "source": { "osmTags": "Lichtmastnummer~*",