-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathosm-selectors.ts
84 lines (79 loc) · 1.99 KB
/
osm-selectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}
if(p.highway === 'primary' && p.maxspeed === undefined) {
return true;
}
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;
}
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;
}
if (p.maxspeed <= 30) {
return true;
}
if (p.highway === 'cycleway') {
return true;
}
if (p.highway === 'shared_lane') {
return true;
}
if (p.bicycle === 'designated' && p.highway === 'cycleway') {
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
}