-
Notifications
You must be signed in to change notification settings - Fork 56
/
highway_shield.js
123 lines (116 loc) · 2.51 KB
/
highway_shield.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
"use strict";
export const namedRouteNetworks = [
"US:CT:Parkway",
"US:KY:Parkway",
"US:NH:Turnpike",
"US:NY:Parkway",
"US:TX:Fort_Bend:FBCTRA",
"US:TX:Harris:HCTRA",
];
export function getImageNameExpression(routeIndex) {
return [
"concat",
"shield\n",
["get", "route_" + routeIndex],
[
"match",
["get", "route_" + routeIndex],
namedRouteNetworks.map((n) => n + "="),
["concat", "\n", ["get", "name"]],
"",
],
];
}
function routeConcurrency(routeIndex) {
return [
"case",
["!=", ["get", "route_" + routeIndex], null],
["image", getImageNameExpression(routeIndex)],
["literal", ""],
];
}
/**
* Returns a structured representation of the given image name.
*
* @param name An image name in the format returned by `routeConcurrency`.
*/
export function parseImageName(imageName) {
let lines = imageName.split("\n");
let [, network, ref] = lines[1].match(/^(.*?)=(.*)/) || [];
let name = lines[2];
return { imageName, network, ref, name };
}
let shieldTextField = ["format"];
for (var i = 1; i <= 6; i++) {
shieldTextField.push(routeConcurrency(i));
}
let shieldLayout = {
"text-rotation-alignment": "viewport-glyph",
"text-font": ["Americana-Regular"],
"text-field": shieldTextField,
"text-anchor": "center",
"text-letter-spacing": 0.7,
"symbol-placement": "line",
"text-max-angle": 180,
"text-pitch-alignment": "viewport",
"symbol-sort-key": [
"match",
["get", "class"],
"motorway",
0,
"trunk",
1,
"primary",
2,
"secondary",
3,
"tertiary",
4,
5,
],
};
export const shield = {
type: "symbol",
source: "openmaptiles",
"source-layer": "transportation_name",
id: "highway-shield",
layout: shieldLayout,
paint: {
"text-opacity": [
"step",
["zoom"],
["match", ["get", "class"], "motorway", 1, 0],
8,
["match", ["get", "class"], ["motorway", "trunk"], 1, 0],
10,
["match", ["get", "class"], ["motorway", "trunk", "primary"], 1, 0],
11,
[
"match",
["get", "class"],
["motorway", "trunk", "primary", "secondary"],
1,
0,
],
12,
[
"match",
["get", "class"],
["motorway", "trunk", "primary", "secondary", "tertiary"],
1,
0,
],
14,
1,
],
},
filter: [
"any",
["has", "route_1"],
["has", "route_2"],
["has", "route_3"],
["has", "route_4"],
["has", "route_5"],
["has", "route_6"],
],
};