Skip to content

Commit 0a5da0f

Browse files
committed
Color-code roads by functional classification
1 parent 86e6b30 commit 0a5da0f

1 file changed

Lines changed: 51 additions & 39 deletions

File tree

src/layer/road.js

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import * as Color from "../constants/color.js";
44
import * as Util from "../js/util.js";
55

66
const motorwayHue = 218;
7-
const stateHue = 40;
8-
const tollRoadHue = 100;
7+
const trunkHue = 0;
8+
const tollRoadHue = 50;
99

1010
// Common filter expressions
1111
const isRoad = [
@@ -31,16 +31,19 @@ const isToll = ["==", ["get", "toll"], 1];
3131
const isNotToll = ["!", isToll];
3232
const isMotorway = ["all", ["==", ["get", "class"], "motorway"], isNotRamp];
3333
const isNotMotorway = ["!=", ["get", "class"], "motorway"];
34-
const isState = [
34+
const isTrunk = ["all", ["==", ["get", "class"], "trunk"], isNotRamp];
35+
const isNotTrunk = ["!", isTrunk];
36+
const isExpressway = ["==", ["get", "expressway"], 1];
37+
const isNotExpressway = ["!", isExpressway];
38+
const isDivided = ["any", isMotorway, isExpressway];
39+
const isArterial = [
3540
"match",
36-
["get", "network"],
37-
["us-highway", "us-state"],
38-
isNotRamp,
41+
["get", "class"],
42+
["primary", "secondary"],
43+
true,
3944
false,
4045
];
41-
const isNotState = ["!", isState];
42-
const isExpressway = ["==", ["get", "expressway"], 1];
43-
const isNotExpressway = ["!", isExpressway];
46+
const isNotArterial = ["!", isArterial];
4447
const isService = ["==", ["get", "class"], "service"];
4548
const isNotService = ["!", isService];
4649
const isMinorService = [
@@ -101,8 +104,7 @@ export const road = {
101104
"line-join": "round",
102105
"line-sort-key": [
103106
"+",
104-
["to-number", isMotorway],
105-
["to-number", isState],
107+
["index-of", ["get", "class"], ["literal", ["tertiary", "secondary", "primary", "trunk", "motorway"]]],
106108
["to-number", isRamp],
107109
],
108110
},
@@ -118,8 +120,8 @@ export const road = {
118120
`hsl(${tollRoadHue}, 60%, 70%)`,
119121
isMotorway,
120122
`hsl(${motorwayHue}, 60%, 70%)`,
121-
isState,
122-
`hsl(${stateHue}, 77%, 50%)`,
123+
isTrunk,
124+
`hsl(${trunkHue}, 60%, 70%)`,
123125
"#9c9c9c",
124126
],
125127
8,
@@ -129,8 +131,8 @@ export const road = {
129131
`hsl(${tollRoadHue}, 100%, 40%)`,
130132
isMotorway,
131133
`hsl(${motorwayHue}, 100%, 45%)`,
132-
isState,
133-
`hsl(${stateHue}, 77%, 50%)`,
134+
isTrunk,
135+
`hsl(${trunkHue}, 60%, 60%)`,
134136
"#9c9c9c",
135137
],
136138
14,
@@ -140,10 +142,12 @@ export const road = {
140142
`hsl(${tollRoadHue}, 100%, 35%)`,
141143
isMotorway,
142144
`hsl(${motorwayHue}, 100%, 35%)`,
143-
isState,
144-
`hsl(${stateHue}, 77%, 50%)`,
145+
isTrunk,
146+
`hsl(${trunkHue}, 60%, 60%)`,
145147
["all", ["==", ["get", "class"], "motorway"], isRamp],
146-
"#000",
148+
"hsl(0, 0%, 20%)",
149+
isArterial,
150+
"hsl(0, 0%, 30%)",
147151
"#9c9c9c",
148152
],
149153
],
@@ -153,30 +157,30 @@ export const road = {
153157
["zoom"],
154158
4,
155159
1,
160+
7,
161+
1,
156162
8,
157163
[
158164
"case",
159-
isMotorway,
160-
3,
161-
isExpressway,
165+
isDivided,
162166
1,
163-
isState,
167+
isTrunk,
164168
2,
165169
["match", ["get", "class"], ["trunk", "primary"], isNotRamp, false],
166-
2,
170+
1,
167171
0.25,
168172
],
169173
18,
170174
[
171175
"case",
172-
isMotorway,
173-
6,
174-
["all", isState, isNotExpressway],
176+
["all", isMotorway, isNotExpressway],
177+
4,
178+
["all", isTrunk, isNotExpressway],
175179
4,
176180
[
177181
"match",
178182
["get", "class"],
179-
["trunk", "primary", "secondary", "tertiary"],
183+
["motorway", "trunk", "primary", "secondary", "tertiary"],
180184
isNotRamp,
181185
false,
182186
],
@@ -188,14 +192,14 @@ export const road = {
188192
20,
189193
[
190194
"case",
191-
isMotorway,
192-
10,
193-
["all", isState, isNotExpressway],
195+
["all", isMotorway, isNotExpressway],
196+
8,
197+
["all", isTrunk, isNotExpressway],
194198
8,
195199
[
196200
"match",
197201
["get", "class"],
198-
["trunk", "primary", "secondary", "tertiary"],
202+
["motorway", "trunk", "primary", "secondary", "tertiary"],
199203
isNotRamp,
200204
false,
201205
],
@@ -209,10 +213,12 @@ export const road = {
209213
"interpolate",
210214
["exponential", 1.2],
211215
["zoom"],
212-
4,
213-
["case", isExpressway, 1, 0],
216+
7,
217+
0,
218+
8,
219+
["case", isDivided, 1, 0],
214220
12,
215-
["case", isExpressway, 3, 0],
221+
["case", isDivided, 3, 0],
216222
14,
217223
0,
218224
],
@@ -288,29 +294,35 @@ export const roadBridgeCasing = {
288294

289295
export const legendEntries = [
290296
{
291-
description: "Controlled-access highway",
297+
description: "Freeway (controlled access, divided)",
292298
layers: [road.id],
293299
filter: ["all", isMotorway, isNotToll],
294300
},
295301
{
296-
description: "Limited-access highway",
302+
description: "Expressway (limited access, divided)",
297303
layers: [road.id],
298304
filter: ["all", isExpressway, isNotToll],
299305
},
300306
{
301-
description: "State highway",
307+
description: "Principal highway",
308+
layers: [road.id],
309+
filter: ["all", isTrunk, isNotToll, isNotExpressway],
310+
},
311+
{
312+
description: "Arterial road",
302313
layers: [road.id],
303-
filter: ["all", isState, isNotToll, isNotExpressway],
314+
filter: ["all", isArterial, isNotToll, isNotExpressway],
304315
},
305316
{
306317
description: "Local road",
307318
layers: [road.id],
308319
filter: [
309320
"all",
310321
isNotMotorway,
311-
isNotState,
322+
isNotTrunk,
312323
isNotToll,
313324
isNotExpressway,
325+
isNotArterial,
314326
isNotRamp,
315327
isNotService,
316328
],

0 commit comments

Comments
 (0)