-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathElectrifications.tsx
155 lines (145 loc) · 4.33 KB
/
Electrifications.tsx
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
import { isNil } from 'lodash';
import { Source } from 'react-map-gl/maplibre';
import type { LayerProps } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';
import { MAP_URL } from 'common/Map/const';
import OrderedLayer from 'common/Map/Layers/OrderedLayer';
import type { RootState } from 'reducers';
import type { Theme } from 'types';
interface ElectrificationsProps {
colors: Theme;
layerOrder: number;
infraID: number | undefined;
}
export function getElectrificationsProps({
colors,
sourceTable,
}: {
colors: Theme;
sourceTable?: string;
}) {
const res: LayerProps = {
type: 'line',
minzoom: 5,
maxzoom: 24,
layout: {
visibility: 'visible',
'line-join': 'miter',
},
paint: {
'line-color': [
'let',
'voltageString',
['to-string', ['get', 'voltage']],
[
'case',
['==', ['var', 'voltageString'], '25000V'],
colors.powerline.color25000V,
['==', ['var', 'voltageString'], '15000V'],
colors.powerline.color15000V1623,
['==', ['var', 'voltageString'], '3000V'],
colors.powerline.color3000V,
['==', ['var', 'voltageString'], '1500V'],
colors.powerline.color1500V,
['==', ['var', 'voltageString'], '850V'],
colors.powerline.color850V,
['==', ['var', 'voltageString'], '800V'],
colors.powerline.color800V,
['==', ['var', 'voltageString'], '750V'],
colors.powerline.color750V,
colors.powerline.colorOther,
],
],
'line-width': 6,
'line-offset': 0,
'line-opacity': 1,
'line-dasharray': [0.1, 0.3],
},
};
if (!isNil(sourceTable)) res['source-layer'] = sourceTable;
return res;
}
export function getElectrificationsTextParams({
colors,
sourceTable,
}: {
colors: Theme;
sourceTable?: string;
}) {
const res: LayerProps = {
type: 'symbol',
minzoom: 5,
maxzoom: 24,
layout: {
visibility: 'visible',
'text-font': ['Roboto Medium'],
'symbol-placement': 'line-center',
'text-field': '{voltage}',
'text-offset': [0, -1],
'text-size': ['interpolate', ['linear'], ['zoom'], 10, 9, 14, 10],
'text-allow-overlap': false,
'text-ignore-placement': false,
'text-pitch-alignment': 'auto',
'text-rotation-alignment': 'auto',
},
paint: {
'text-color': [
'let',
'voltageString',
['to-string', ['get', 'voltage']],
[
'case',
['==', ['var', 'voltageString'], '25000V'],
colors.powerline.color25000V,
['==', ['var', 'voltageString'], '15000V'],
colors.powerline.color15000V1623,
['==', ['var', 'voltageString'], '3000V'],
colors.powerline.color3000V,
['==', ['var', 'voltageString'], '1500V'],
colors.powerline.color1500V,
['==', ['var', 'voltageString'], '850V'],
colors.powerline.color850V,
['==', ['var', 'voltageString'], '800V'],
colors.powerline.color800V,
['==', ['var', 'voltageString'], '750V'],
colors.powerline.color750V,
colors.powerline.colorOther,
],
],
},
};
if (!isNil(sourceTable)) res['source-layer'] = sourceTable;
return res;
}
export default function Electrifications({ colors, layerOrder, infraID }: ElectrificationsProps) {
const { layersSettings } = useSelector((state: RootState) => state.map);
const electrificationsParams: LayerProps = getElectrificationsProps({
colors,
sourceTable: 'electrifications',
});
const electrificationsTextParams: LayerProps = getElectrificationsTextParams({
colors,
sourceTable: 'electrifications',
});
if (!layersSettings.electrifications || isNil(infraID)) return null;
return (
<Source
id="electrifications_geo"
type="vector"
url={`${MAP_URL}/layer/electrifications/mvt/geo/?infra=${infraID}`}
>
<OrderedLayer
{...electrificationsParams}
// beforeId={`chartis/tracks-geo/main`}
id="chartis/electrifications/geo"
layerOrder={layerOrder}
/>
<OrderedLayer
{...electrificationsTextParams}
// beforeId={`chartis/tracks-geo/main`}
id="chartis/electrifications_names/geo"
layerOrder={layerOrder}
/>
</Source>
);
}