From 791c6c4f55aa25caa55457f52caeb7be57c47102 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 25 Jan 2022 18:20:15 +0100 Subject: [PATCH] Include route=foot in trails --- .../Sources/FilteringFeatureSource.ts | 2 +- Utils.ts | 5 +++- assets/layers/trail/trail.json | 7 ++--- package.json | 1 + scripts/generateCache.ts | 27 ++++++++++++++++--- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts index 125018406..ff6a9a5c4 100644 --- a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts +++ b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts @@ -82,7 +82,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti } } - const tagsFilter = Array.from(layer.appliedFilters.data.values()); + const tagsFilter = Array.from(layer.appliedFilters?.data?.values() ?? []); for (const filter of tagsFilter ?? []) { const neededTags : TagsFilter = filter?.currentFilter if (neededTags !== undefined && !neededTags.matchesProperties(f.feature.properties)) { diff --git a/Utils.ts b/Utils.ts index 25f898575..ee835e2ea 100644 --- a/Utils.ts +++ b/Utils.ts @@ -495,7 +495,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } const data = await Utils.download(url, Utils.Merge({"accept": "application/json"}, headers ?? {})) try { - return JSON.parse(data) + if(typeof data === "string"){ + return JSON.parse(data) + } + return data } catch (e) { console.error("Could not parse ", data, "due to", e, "\n", e.stack) throw e; diff --git a/assets/layers/trail/trail.json b/assets/layers/trail/trail.json index 72e945213..84416e15f 100644 --- a/assets/layers/trail/trail.json +++ b/assets/layers/trail/trail.json @@ -13,9 +13,10 @@ "and": [ { "or": [ - "route=hiking", - "route=bycicle", - "route=horse" + "route~.*foot.*", + "route~.*hiking.*", + "route~.*bycicle.*", + "route~.*horse.*" ] } ] diff --git a/package.json b/package.json index 759fe910d..ee01179db 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "generate:cache:speelplekken:mini": "ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache_mini/ 51.181710380278176 4.423413276672363 51.193007664772495 4.444141387939452", "generate:cache:speelplekken": "npm run generate:layeroverview && ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache/ 51.20 4.35 51.09 4.56", "generate:cache:natuurpunt": "npm run generate:layeroverview && ts-node scripts/generateCache.ts natuurpunt 12 ../MapComplete-data/natuurpunt_cache/ 50.40 2.1 51.54 6.4 --generate-point-overview nature_reserve,visitor_information_centre", + "generate:cache:natuurpunt:mini": "ts-node scripts/generateCache.ts natuurpunt 12 ../../git/MapComplete-data/natuurpunt_cache_mini/ 51.00792239979105 4.497699737548828 51.0353492224462554 4.539070129394531 --generate-point-overview nature_reserve,visitor_information_centre", "generate:layeroverview": "ts-node scripts/generateLayerOverview.ts --no-fail", "generate:licenses": "ts-node scripts/generateLicenseInfo.ts --no-fail", "query:licenses": "ts-node scripts/generateLicenseInfo.ts --query", diff --git a/scripts/generateCache.ts b/scripts/generateCache.ts index 9980c1959..029e014d7 100644 --- a/scripts/generateCache.ts +++ b/scripts/generateCache.ts @@ -376,9 +376,29 @@ async function main(args: string[]) { const lat1 = Number(args[5]) const lon1 = Number(args[6]) + if(isNaN(lat0)){ + throw "The first number (a latitude) is not a valid number" + } + + if(isNaN(lon0)){ + throw "The second number (a longitude) is not a valid number" + } + if(isNaN(lat1)){ + throw "The third number (a latitude) is not a valid number" + } + + if(isNaN(lon1)){ + throw "The first number (a longitude) is not a valid number" + } + + const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1) + if(isNaN(tileRange.total)){ + throw "Something has gone wrong: tilerange is NAN" + } + if (tileRange.total === 0) { console.log("Tilerange has zero tiles - this is probably an error") return @@ -440,8 +460,9 @@ async function main(args: string[]) { let args = [...process.argv] args.splice(0, 2) try { - main(args).catch(e => console.error("Error building cache:", e)); + main(args) + .then(() => console.log("All done!")) + .catch(e => console.error("Error building cache:", e)); } catch (e) { console.error("Error building cache:", e) -} -console.log("All done!") \ No newline at end of file +} \ No newline at end of file