Add docstrings for selectors, improve selectors

load-bicycle-parking
Jake Coppinger 2023-01-28 13:26:42 +11:00
rodzic 66a3ad80f3
commit 7fbd8ac1d3
2 zmienionych plików z 62 dodań i 9 usunięć

Wyświetl plik

@ -1,30 +1,81 @@
import { Geometry, GeoJsonProperties, Feature } from 'geojson';
/**
* Is a red (dangerous) road if:
* - Speed is higher than 40kmh
* - Road is a residental street with default speed limit (50kph)
* @param feature
* @returns
*/
export function isRedRoad(feature: Feature<Geometry, GeoJsonProperties>): boolean {
const p = feature.properties;
if (p === null) {
return false;
}
return (p.maxspeed > 40 || (p.highway === 'residential' && p.maxspeed === undefined))
if (p.maxspeed > 40) {
return true;
}
if (p.highway === 'residential' && p.maxspeed === undefined) {
return true;
}
return false;
}
/**
* Is an orange (caution) road if:
* - Road has a speed limit less than 40kph and greater than 30kmh
* - Has an on road, painted (non-separated) bike lane
* @param feature
* @returns
*/
export function isOrangeRoad(feature: Feature<Geometry, GeoJsonProperties>): boolean {
const p = feature.properties;
if (p === null) {
return false;
}
return (p.maxspeed <= 40 || p.cycleway === 'lane')
if (p.maxspeed <= 40) {
return true;
}
if (p.cycleway === 'lane') {
return true;
}
return false;
}
/**
* Is a green (safe) road if:
* - Speed is less than or equal to 30kph
* - Is a [living street](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dliving_street)
* - Is a separated cycleway
* - Is a cycle lane separated from the road
* - Is a shared path (bikes + pedestrians allowed)
* @param feature
* @returns
*/
export function isGreenRoad(feature: Feature<Geometry, GeoJsonProperties>): boolean {
const p = feature.properties;
if (p === null) {
return false;
}
return (p.maxspeed <= 30 || p.highway === 'cycleway' || p.highway === 'pedestrian'
|| p.highway === 'living_street'
)
if (p.maxspeed <= 30) {
return true;
}
if (p.highway === 'cycleway') {
return true;
}
if (p.highway === 'shared_lane') {
return true;
}
if (p.bicycle === 'designated') {
return true;
}
if (p.highway === 'living_street') {
return true;
}
if (p.cycleway === 'track' || p['cycleway:left'] === 'track' || p['cycleway:right'] === 'track') {
return true;
}
return false
}

Wyświetl plik

@ -23,7 +23,7 @@ export const safeCycleways = (boundsStr: string) => `
/* Select road types to display */
(
way[highway]["highway"!~"cycleway|path|footway|pedestrian"]["bicycle"!~"no"][maxspeed](if:t["maxspeed"]<=50);
way[highway]["highway"!~"cycleway|path|footway|pedestrian"]["bicycle"!~"no"];
way["highway"="residential"];
way[highway=cycleway];
@ -32,6 +32,8 @@ export const safeCycleways = (boundsStr: string) => `
way[highway=construction][construction=cycleway];
way[proposed=cycleway];
way[cycleway=lane];
way["cycleway:left"=track];
way[cycleway=track];
);