create car/motorcycle category and add garage, related to #7

This commit is contained in:
vcoppe
2024-07-18 11:45:35 +02:00
parent a068340fa5
commit db1aa3e3d1
3 changed files with 51 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
import { TramFront, Utensils, ShoppingBasket, Droplet, ShowerHead, Fuel, CircleParking, Fence, FerrisWheel, Telescope, Bed, Mountain, Pickaxe, Store, TrainFront, Bus, Ship, Croissant, House, Tent } from 'lucide-static';
import { TramFront, Utensils, ShoppingBasket, Droplet, ShowerHead, Fuel, CircleParking, Fence, FerrisWheel, Telescope, Bed, Mountain, Pickaxe, Store, TrainFront, Bus, Ship, Croissant, House, Tent, Wrench } from 'lucide-static';
import { type AnySourceData, type Style } from 'mapbox-gl';
export const basemaps: { [key: string]: string | Style; } = {
@@ -552,10 +552,7 @@ export const overpassTree: LayerTreeType = {
amenities: {
toilets: true,
"water": true,
"water-spring": true,
shower: true,
"fuel-station": true,
parking: true,
barrier: true
},
tourism: {
@@ -579,6 +576,11 @@ export const overpassTree: LayerTreeType = {
"bus-stop": true,
ferry: true
},
motorized: {
"fuel-station": true,
parking: true,
garage: true
},
},
};
@@ -638,10 +640,7 @@ export const defaultOverpassQueries: LayerTreeType = {
amenities: {
toilets: false,
"water": false,
"water-spring": false,
shower: false,
"fuel-station": false,
parking: false,
barrier: false
},
tourism: {
@@ -665,6 +664,11 @@ export const defaultOverpassQueries: LayerTreeType = {
"bus-stop": false,
ferry: false
},
motorized: {
"fuel-station": false,
parking: false,
garage: false
},
},
};
@@ -774,10 +778,7 @@ export const defaultOverpassTree: LayerTreeType = {
amenities: {
toilets: true,
"water": true,
"water-spring": false,
shower: false,
"fuel-station": false,
parking: false,
barrier: false
},
tourism: {
@@ -801,6 +802,11 @@ export const defaultOverpassTree: LayerTreeType = {
"bus-stop": true,
ferry: false
},
motorized: {
"fuel-station": false,
parking: false,
garage: false
},
},
};
@@ -819,7 +825,7 @@ type OverpassQueryData = {
svg: string,
color: string,
},
tags: Record<string, string | boolean | string[]>,
tags: Record<string, string | boolean | string[]> | Record<string, string | boolean | string[]>[],
};
export const overpassQueryData: Record<string, OverpassQueryData> = {
@@ -864,19 +870,12 @@ export const overpassQueryData: Record<string, OverpassQueryData> = {
svg: Droplet,
color: "DeepSkyBlue",
},
tags: {
tags: [{
amenity: ["drinking_water", "water_point"]
}
},
"water-spring": {
icon: {
svg: Droplet,
color: "DeepSkyBlue",
},
tags: {
}, {
natural: "spring",
drinking_water: "yes"
}
}]
},
shower: {
icon: {
@@ -905,6 +904,15 @@ export const overpassQueryData: Record<string, OverpassQueryData> = {
amenity: "parking"
}
},
garage: {
icon: {
svg: Wrench,
color: "#000000",
},
tags: {
shop: ["car_repair", "motorcycle_repair"]
}
},
barrier: {
icon: {
svg: Fence,

View File

@@ -260,20 +260,36 @@ function getQueries(queries: string[]) {
}
function getQuery(query: string) {
let arrayEntry = Object.entries(overpassQueryData[query].tags).find(([_, value]) => Array.isArray(value));
if (Array.isArray(overpassQueryData[query].tags)) {
return overpassQueryData[query].tags.map((tags) => getQueryItem(tags)).join('');
} else {
return getQueryItem(overpassQueryData[query].tags);
}
}
function getQueryItem(tags: Record<string, string | boolean | string[]>) {
let arrayEntry = Object.entries(tags).find(([_, value]) => Array.isArray(value));
if (arrayEntry !== undefined) {
return arrayEntry[1].map((val) => `nwr${Object.entries(overpassQueryData[query].tags)
return arrayEntry[1].map((val) => `nwr${Object.entries(tags)
.map(([tag, value]) => `[${tag}=${tag === arrayEntry[0] ? val : value}]`)
.join('')};`).join('');
} else {
return `nwr${Object.entries(overpassQueryData[query].tags)
return `nwr${Object.entries(tags)
.map(([tag, value]) => `[${tag}=${value}]`)
.join('')};`;
}
}
function belongsToQuery(element: any, query: string) {
return Object.entries(overpassQueryData[query].tags)
if (Array.isArray(overpassQueryData[query].tags)) {
return overpassQueryData[query].tags.some((tags) => belongsToQueryItem(element, tags));
} else {
return belongsToQueryItem(element, overpassQueryData[query].tags);
}
}
function belongsToQueryItem(element: any, tags: Record<string, string | boolean | string[]>) {
return Object.entries(tags)
.every(([tag, value]) => Array.isArray(value) ? value.includes(element.tags[tag]) : element.tags[tag] === value);
}

View File

@@ -294,10 +294,11 @@
"amenities": "Amenities",
"toilets": "Toilets",
"water": "Water",
"water-spring": "Water Spring",
"shower": "Shower",
"motorized": "Cars and Motorcycles",
"fuel-station": "Fuel Station",
"parking": "Parking",
"garage": "Garage",
"barrier": "Barrier",
"tourism": "Tourism",
"attraction": "Attraction",