-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathscopes.js
132 lines (124 loc) · 2.81 KB
/
scopes.js
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
import { groupBy } from 'ramda'
const omitUselessProperties = (object) => {
const {
distance,
elevation,
weight,
opacity,
toPoint,
fromPoint,
dashArray,
...result
} = object
return result
}
const coordinatesHash = (s) =>
s.geometry.coordinates.map((point) => point.join(',')).join(',')
const compressSegments = (segments) => {
console.log('will compress segments', segments.length)
console.time('compress')
const duplicateGeometrySegments0 = segments.map((segment) =>
coordinatesHash(segment)
)
console.log('did build segment hash fake', duplicateGeometrySegments0.length)
console.timeLog('compress')
const duplicateGeometrySegments = groupBy(coordinatesHash, segments)
console.log('did build segment hash table')
console.timeLog('compress')
const result = Object.entries(duplicateGeometrySegments).map(
([hash, values]) => ({
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: values[0].geometry.coordinates.map(
(point) => point.slice(0, 2) // remove elevation, useless
),
},
properties: {
...omitUselessProperties(values[0].properties),
rides: values.map((v) => [
v.properties.toPoint,
v.properties.fromPoint,
v.properties.backboneRide,
]),
},
})
)
console.log('did compress')
console.timeEnd('compress')
return result
}
export default {
cycling: [
[
'meta', // get data only for the front page, lightweight request
({ score }) => ({
score,
}),
],
[
'merged', //all the above, plus data to visualise the merged polygon from which the area is computed
({
points,
segments,
score,
pointsCenter,
rides,
compressedSegments,
ridesLength,
}) => ({
points,
//segments,
segments: compressedSegments ? segments : compressSegments(segments),
compressedSegments: true,
score,
pointsCenter,
ridesLength: ridesLength || rides.length,
}),
],
[
'complete', // not implemented yet
({}) => ({}),
],
],
walking: [
[
'meta', // get data only for the front page, lightweight request
({
pedestrianArea,
relativeArea,
meanStreetWidth,
streetsWithWidthCount,
geoAPI,
}) => ({
pedestrianArea,
relativeArea,
meanStreetWidth,
streetsWithWidthCount,
geoAPI,
}),
],
[
'merged', //all the above, plus data to visualise the merged polygon from which the area is computed
({
mergedPolygons,
pedestrianArea,
relativeArea,
meanStreetWidth,
streetsWithWidthCount,
geoAPI,
}) => ({
mergedPolygons,
relativeArea,
meanStreetWidth,
streetsWithWidthCount,
pedestrianArea,
geoAPI,
}),
],
[
'complete', // all the above, plus all the polygons, to debug the request result and exclude shapes on the website
({ polygons, geoAPI }) => ({ polygons, geoAPI }),
],
],
}