diff --git a/src/osm-selectors.ts b/src/osm-selectors.ts index 37e2f6f..867dc41 100644 --- a/src/osm-selectors.ts +++ b/src/osm-selectors.ts @@ -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): 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): 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): 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 } \ No newline at end of file diff --git a/src/overpass-requests.ts b/src/overpass-requests.ts index 5326205..7670491 100644 --- a/src/overpass-requests.ts +++ b/src/overpass-requests.ts @@ -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]; );