forked from benoitdemaegdt/voieslyonnaises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
148 lines (128 loc) · 3.25 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
export type LaneType =
| 'bidirectionnelle'
| 'bilaterale'
| 'voie-bus'
| 'voie-bus-elargie'
| 'velorue'
| 'voie-verte'
| 'bandes-cyclables'
| 'zone-de-rencontre'
| 'chaucidou'
| 'heterogene'
| 'aucun'
| 'inconnu';
export type LaneStatus = 'done' | 'wip' | 'planned' | 'tested' | 'postponed' | 'unknown' | 'variante' | 'variante-postponed';
export type Quality = 'bad' | 'fair' | 'good';
export type PolygonFeature = {
type: 'Feature';
geometry: {
type: "Polygon",
coordinates: [number, number][];
}
}
export type LineStringFeature = {
type: 'Feature';
properties: {
id?: string
line: string;
name: string;
status: LaneStatus;
quality: Quality;
type: LaneType;
doneAt?: string;
link?: string;
};
geometry: {
type: 'LineString';
coordinates: [number, number][];
};
};
export type DisplayedLane = LineStringFeature & { properties: { color: string, lane_index: number, nb_lanes: number } };
export type PerspectiveFeature = {
type: 'Feature';
properties: {
type: 'perspective';
line: number;
name: string;
imgUrl: string;
};
geometry: {
type: 'Point';
coordinates: [number, number];
};
};
export type CompteurFeature = {
type: 'Feature';
properties: {
type: 'compteur-velo' | 'compteur-voiture';
line?: number;
name: string;
link?: string;
counts: Array<{
month: string;
count: number;
}>;
/**
* z-index like
*/
circleSortKey?: number;
circleRadius?: number;
circleStrokeWidth?: number;
};
geometry: {
type: 'Point';
coordinates: [number, number];
};
};
export type PumpFeature = {
type: 'Feature';
properties: {
type: 'pump',
name: string
}
geometry: {
type: 'Point';
coordinates: [number, number];
};
}
export type DangerFeature = {
type: 'Feature';
properties: {
type: 'danger',
name: string
}
geometry: {
type: 'Point';
coordinates: [number, number];
};
}
type PointFeature = PerspectiveFeature | CompteurFeature | PumpFeature | DangerFeature;
export type Feature = LineStringFeature | PointFeature | DisplayedLane | PolygonFeature;
export type Geojson = {
type: string;
features: Feature[];
};
/**
* type helpers
*/
export function isLineStringFeature(feature: Feature): feature is LineStringFeature {
return feature.geometry.type === 'LineString';
}
export function isPointFeature(feature: Feature): feature is PointFeature {
return feature.geometry.type === 'Point';
}
export function isPolygonFeature(feature: Feature): feature is PolygonFeature {
return feature.geometry.type === 'Polygon';
}
export function isPerspectiveFeature(feature: Feature): feature is PerspectiveFeature {
return isPointFeature(feature) && feature.properties.type === 'perspective';
}
export function isDangerFeature(feature: Feature): feature is PerspectiveFeature {
return isPointFeature(feature) && feature.properties.type === 'danger';
}
export function isPumpFeature(feature: Feature): feature is PumpFeature {
return isPointFeature(feature) && feature.properties.type === 'pump';
}
export function isCompteurFeature(feature: Feature): feature is CompteurFeature {
return isPointFeature(feature) && ['compteur-velo', 'compteur-voiture'].includes(feature.properties.type);
}