-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouteMap.js
More file actions
309 lines (286 loc) · 9.92 KB
/
routeMap.js
File metadata and controls
309 lines (286 loc) · 9.92 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import React from 'react';
import PropTypes from 'prop-types';
import MapImage from 'components/map/mapImageContainer';
import ItemContainer from 'components/labelPlacement/itemContainer';
import ItemFixed from 'components/labelPlacement/itemFixed';
import ItemPositioned from 'components/labelPlacement/itemPositioned';
import AZone from 'icons/icon-Zone-A';
import BZone from 'icons/icon-Zone-B';
import CZone from 'icons/icon-Zone-C';
import DZone from 'icons/icon-Zone-D';
import EZone from 'icons/icon-Zone-E';
import { preventFromOverlap } from '../../util/terminals';
import { getTransformedCoord } from '../../util/arrows';
import TerminalSymbol from './terminalSymbol';
import TerminusSymbol from './terminusSymbol';
import TerminusLabel from './terminusLabel';
import IntermediateLabel from './intermediateLabel';
import StationName from './stationName';
import DirectionArrow from './directionArrow';
import StopSymbol from '../map/stopSymbol';
import Scalebar from '../map/scalebar';
import styles from './routeMap.css';
const STOP_RADIUS = 3.5;
const TERMINUS_SIZE = 5;
const TERMINAL_SIZE = 14;
const ARROW_SIZE = 12;
const ARROW_DISTANCE_FROM_ROAD = 10;
// Overlays
const INFO_MARGIN_BOTTOM = 78;
const INFO_MARGIN_LEFT = 44;
const getZoneIcon = (zone, size) => {
switch (zone) {
case 'A':
return <AZone size={size} />;
case 'B':
return <BZone size={size} />;
case 'C':
return <CZone size={size} />;
case 'D':
return <DZone size={size} />;
case 'E':
return <EZone size={size} />;
default:
return <div />;
}
};
const ZoneSymbol = (props) => (
<div className={styles.zoneSymbol}>{getZoneIcon(props.zone, props.size)}</div>
);
const Attribution = () => <div className={styles.attribution}>© OpenStreetMap</div>;
ZoneSymbol.propTypes = {
size: PropTypes.string,
zone: PropTypes.string.isRequired,
};
ZoneSymbol.defaultProps = {
size: '200px',
};
const RouteMap = (props) => {
const mapStyle = {
width: props.mapOptions.width,
height: props.mapOptions.height,
};
const scaleStyle = {
fontSize: `${props.configuration.scaleFontSize ? props.configuration.scaleFontSize : 12}px`,
};
const nonOverlappingStations = preventFromOverlap(props.projectedStations, TERMINAL_SIZE);
const { projectedSymbols } = props;
return (
<div className={styles.root}>
<div className={styles.map} style={mapStyle}>
<MapImage
options={props.mapOptions}
components={props.mapComponents}
date={props.date}
routeFilter={props.configuration.routeFilter}
/>
</div>
<div className={styles.overlays}>
<ItemContainer
mapOptions={props.mapOptions}
mapComponents={props.mapComponents}
configuration={props.configuration}
alphaChannel={props.alphaChannel}
>
{props.projectedTerminuses.map((terminus, index) => (
<ItemFixed
key={index}
top={terminus.y - TERMINUS_SIZE / 2}
left={terminus.x - TERMINUS_SIZE / 2}
>
<TerminusSymbol size={TERMINUS_SIZE} />
</ItemFixed>
))}
{props.projectedStops.map((stop, index) => (
<ItemFixed
key={index}
top={stop.y - STOP_RADIUS}
left={stop.x - STOP_RADIUS}
allowCollision
>
<StopSymbol routes={stop.routes} size={STOP_RADIUS * 2} />
</ItemFixed>
))}
{nonOverlappingStations.map((station, index) => (
<ItemFixed
key={index}
top={station.y - TERMINAL_SIZE / 2}
left={station.x - TERMINAL_SIZE / 2}
>
<TerminalSymbol
nameFi={station.nameFi}
nameSv={station.nameSe}
node={station.mode}
size={TERMINAL_SIZE}
/>
</ItemFixed>
))}
{props.projectedIntermediates.map((intermediate, index) => (
<ItemPositioned
key={index}
x={intermediate.x}
y={intermediate.y}
distance={0}
allowHidden
anglePriority={1}
angle={intermediate.angle}
>
<IntermediateLabel
trunkRouteIds={props.trunkRouteIds}
label={intermediate.label}
configuration={props.configuration}
/>
</ItemPositioned>
))}
{props.projectedIntermediates
.filter((intermediate) => !!intermediate.oneDirectionalAngle)
.map((intermediate, index) => {
const { transformedX, transformedY } = getTransformedCoord(
intermediate.x,
intermediate.y,
intermediate.oneDirectionalAngle + 90,
ARROW_DISTANCE_FROM_ROAD,
);
return (
<ItemFixed
key={index}
top={transformedY - (ARROW_SIZE + 2) / 2}
left={transformedX - (ARROW_SIZE + 2) / 2}
transform={intermediate.oneDirectionalAngle}
fixedSize={ARROW_SIZE + 2}
>
<DirectionArrow size={ARROW_SIZE} />
</ItemFixed>
);
})}
{props.projectedStations
.filter((station) => station.mode === '06' || station.mode === '12')
.map((name, index) => (
<ItemPositioned
key={index}
x={name.x}
y={name.y}
distance={5}
anchorWidth={1}
maxDistance={40}
angle={45}
distancePriority={6}
alphaOverlapPriority={0.1}
>
<StationName
nameFi={name.nameFi}
nameSe={name.nameSe}
type={name.mode}
configuration={props.configuration}
/>
</ItemPositioned>
))}
{projectedSymbols &&
projectedSymbols.length > 0 &&
projectedSymbols.map((symbol, index) => {
const matchValues = symbol.size.match(/\d+/);
const symbolSizeNumber = matchValues ? parseInt(matchValues[0], 10) : null;
const offset = symbolSizeNumber ? symbolSizeNumber / 2 : 0;
return (
<ItemFixed key={index} left={symbol.sy - offset} top={symbol.sx - offset}>
<ZoneSymbol size={symbol.size} zone={symbol.zone} />
</ItemFixed>
);
})}
{props.projectedTerminuses.map((terminus, index) => (
<ItemPositioned
key={index}
x={terminus.x}
y={terminus.y}
distance={10}
anchorWidth={1}
distancePriority={terminus.lines.length > 5 ? 4 : 16}
angle={45}
>
<TerminusLabel
lines={terminus.lines}
nameFi={terminus.nameFi}
nameSe={terminus.nameSe}
type={terminus.type}
configuration={props.configuration}
trunkRouteIds={props.trunkRouteIds}
/>
</ItemPositioned>
))}
<ItemFixed top={mapStyle.height - INFO_MARGIN_BOTTOM} left={INFO_MARGIN_LEFT}>
<div style={scaleStyle}>
<Scalebar
targetWidth={
props.configuration.scaleLength ? props.configuration.scaleLength : 250
}
pixelsPerMeter={props.pxPerMeterRatio}
/>
<Attribution />
</div>
</ItemFixed>
</ItemContainer>
</div>
</div>
);
};
const TerminusType = PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
lines: PropTypes.arrayOf(PropTypes.string).isRequired,
nameFi: PropTypes.string,
nameSe: PropTypes.string,
});
const StationType = PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
nameFi: PropTypes.string,
nameSv: PropTypes.string,
mode: PropTypes.string.isRequired,
});
const IntermediateLabelType = PropTypes.shape({
type: PropTypes.string.isRequired,
text: PropTypes.string.isRequired,
});
const IntermediateType = PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
label: PropTypes.arrayOf(IntermediateLabelType).isRequired,
});
const MapOptions = {
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
zoom: PropTypes.number.isRequired,
center: PropTypes.arrayOf(PropTypes.number).isRequired,
};
const StopType = PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
routes: PropTypes.arrayOf(
PropTypes.shape({
routeId: PropTypes.string.isRequired,
routeIdParsed: PropTypes.string.isRequired,
mode: PropTypes.string.isRequired,
}),
).isRequired,
});
const ConfigurationOptionsProps = {
date: PropTypes.string.isRequired,
scaleFontSize: PropTypes.number.isRequired,
maxAnchorLength: PropTypes.number.isRequired,
scaleLength: PropTypes.number,
};
RouteMap.propTypes = {
date: PropTypes.string.isRequired,
alphaChannel: PropTypes.object.isRequired,
projectedStations: PropTypes.arrayOf(StationType).isRequired,
projectedTerminuses: PropTypes.arrayOf(TerminusType).isRequired,
projectedIntermediates: PropTypes.arrayOf(IntermediateType).isRequired,
projectedStops: PropTypes.arrayOf(StopType).isRequired,
projectedSymbols: PropTypes.arrayOf(Object).isRequired,
mapOptions: PropTypes.shape(MapOptions).isRequired,
mapComponents: PropTypes.object.isRequired, // eslint-disable-line
pxPerMeterRatio: PropTypes.number.isRequired,
configuration: PropTypes.shape(ConfigurationOptionsProps).isRequired,
trunkRouteIds: PropTypes.array.isRequired,
};
export default RouteMap;