Skip to content

Commit

Permalink
Color-code roads by functional classification
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Apr 4, 2024
1 parent be1f0ab commit 37629ca
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions src/layer/road.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as Color from "../constants/color.js";
import * as Util from "../js/util.js";

const motorwayHue = 218;
const stateHue = 40;
const tollRoadHue = 100;
const trunkHue = 0;
const tollRoadHue = 50;

// Common filter expressions
const isRoad = [
Expand All @@ -31,16 +31,19 @@ const isToll = ["==", ["get", "toll"], 1];
const isNotToll = ["!", isToll];
const isMotorway = ["all", ["==", ["get", "class"], "motorway"], isNotRamp];
const isNotMotorway = ["!=", ["get", "class"], "motorway"];
const isState = [
const isTrunk = ["all", ["==", ["get", "class"], "trunk"], isNotRamp];
const isNotTrunk = ["!", isTrunk];
const isExpressway = ["==", ["get", "expressway"], 1];
const isNotExpressway = ["!", isExpressway];
const isDivided = ["any", isMotorway, isExpressway];
const isArterial = [
"match",
["get", "network"],
["us-highway", "us-state"],
isNotRamp,
["get", "class"],
["primary", "secondary"],
true,
false,
];
const isNotState = ["!", isState];
const isExpressway = ["==", ["get", "expressway"], 1];
const isNotExpressway = ["!", isExpressway];
const isNotArterial = ["!", isArterial];
const isService = ["==", ["get", "class"], "service"];
const isNotService = ["!", isService];
const isMinorService = [
Expand Down Expand Up @@ -101,8 +104,7 @@ export const road = {
"line-join": "round",
"line-sort-key": [
"+",
["to-number", isMotorway],
["to-number", isState],
["index-of", ["get", "class"], ["literal", ["tertiary", "secondary", "primary", "trunk", "motorway"]]],
["to-number", isRamp],
],
},
Expand All @@ -118,8 +120,8 @@ export const road = {
`hsl(${tollRoadHue}, 60%, 70%)`,
isMotorway,
`hsl(${motorwayHue}, 60%, 70%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
isTrunk,
`hsl(${trunkHue}, 60%, 70%)`,
"#9c9c9c",
],
8,
Expand All @@ -129,8 +131,8 @@ export const road = {
`hsl(${tollRoadHue}, 100%, 40%)`,
isMotorway,
`hsl(${motorwayHue}, 100%, 45%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
isTrunk,
`hsl(${trunkHue}, 60%, 60%)`,
"#9c9c9c",
],
14,
Expand All @@ -140,10 +142,12 @@ export const road = {
`hsl(${tollRoadHue}, 100%, 35%)`,
isMotorway,
`hsl(${motorwayHue}, 100%, 35%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
isTrunk,
`hsl(${trunkHue}, 60%, 60%)`,
["all", ["==", ["get", "class"], "motorway"], isRamp],
"#000",
"hsl(0, 0%, 20%)",
isArterial,
"hsl(0, 0%, 30%)",
"#9c9c9c",
],
],
Expand All @@ -153,30 +157,30 @@ export const road = {
["zoom"],
4,
1,
7,
1,
8,
[
"case",
isMotorway,
3,
isExpressway,
isDivided,
1,
isState,
isTrunk,
2,
["match", ["get", "class"], ["trunk", "primary"], isNotRamp, false],
2,
1,
0.25,
],
18,
[
"case",
isMotorway,
6,
["all", isState, isNotExpressway],
["all", isMotorway, isNotExpressway],
4,
["all", isTrunk, isNotExpressway],
4,
[
"match",
["get", "class"],
["trunk", "primary", "secondary", "tertiary"],
["motorway", "trunk", "primary", "secondary", "tertiary"],
isNotRamp,
false,
],
Expand All @@ -188,14 +192,14 @@ export const road = {
20,
[
"case",
isMotorway,
10,
["all", isState, isNotExpressway],
["all", isMotorway, isNotExpressway],
8,
["all", isTrunk, isNotExpressway],
8,
[
"match",
["get", "class"],
["trunk", "primary", "secondary", "tertiary"],
["motorway", "trunk", "primary", "secondary", "tertiary"],
isNotRamp,
false,
],
Expand All @@ -209,10 +213,12 @@ export const road = {
"interpolate",
["exponential", 1.2],
["zoom"],
4,
["case", isExpressway, 1, 0],
7,
0,
8,
["case", isDivided, 1, 0],
12,
["case", isExpressway, 3, 0],
["case", isDivided, 3, 0],
14,
0,
],
Expand Down Expand Up @@ -288,29 +294,35 @@ export const roadBridgeCasing = {

export const legendEntries = [
{
description: "Controlled-access highway",
description: "Freeway (controlled access, divided)",
layers: [road.id],
filter: ["all", isMotorway, isNotToll],
},
{
description: "Limited-access highway",
description: "Expressway (limited access, divided)",
layers: [road.id],
filter: ["all", isExpressway, isNotToll],
},
{
description: "State highway",
description: "Principal highway",
layers: [road.id],
filter: ["all", isTrunk, isNotToll, isNotExpressway],
},
{
description: "Arterial road",
layers: [road.id],
filter: ["all", isState, isNotToll, isNotExpressway],
filter: ["all", isArterial, isNotToll, isNotExpressway],
},
{
description: "Local road",
layers: [road.id],
filter: [
"all",
isNotMotorway,
isNotState,
isNotTrunk,
isNotToll,
isNotExpressway,
isNotArterial,
isNotRamp,
isNotService,
],
Expand Down

0 comments on commit 37629ca

Please sign in to comment.