Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Oct 31, 2023
1 parent 225c936 commit 6868d35
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 49 deletions.
6 changes: 5 additions & 1 deletion src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export function filteredClone(def, filterStep, idSuffix) {
case "interpolate-hcl":
case "interpolate-lab":
case "step":
clone.filter = mapRampExpression(clone.filter, (input, output) => ["all", output, filterStep]);
clone.filter = mapRampExpression(clone.filter, (input, output) => [
"all",
output,
filterStep,
]);
break;
default:
throw new TypeError("Unlikely filter");
Expand Down
12 changes: 6 additions & 6 deletions src/layer/construction.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"use strict";

const motorwayHue = 218;
const majorConstruction = [
"match",
["get", "class"],
"motorway_construction",
];
const majorConstruction = ["match", ["get", "class"], "motorway_construction"];

export const road = {
id: "highway-construction",
Expand Down Expand Up @@ -37,7 +33,11 @@ export const road = {
10,
[...majorConstruction, `hsl(${motorwayHue}, 60%, 70%)`, "lightslategray"],
13,
[...majorConstruction, `hsl(${motorwayHue}, 100%, 45%)`, "lightslategray"],
[
...majorConstruction,
`hsl(${motorwayHue}, 100%, 45%)`,
"lightslategray",
],
15,
[...majorConstruction, `hsl(${motorwayHue}, 100%, 35%)`, "slategray"],
],
Expand Down
184 changes: 142 additions & 42 deletions src/layer/road.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ const tollRoadHue = 100;
const isRoad = [
"match",
["get", "class"],
["motorway", "trunk", "primary", "secondary", "tertiary", "minor", "service", "busway", "bus_guideway"],
[
"motorway",
"trunk",
"primary",
"secondary",
"tertiary",
"minor",
"service",
"busway",
"bus_guideway",
],
true,
false,
];
Expand All @@ -21,7 +31,13 @@ const isToll = ["==", ["get", "toll"], 1];
const isNotToll = ["!", isToll];
const isMotorway = ["all", ["==", ["get", "class"], "motorway"], isNotRamp];
const isNotMotorway = ["!=", ["get", "class"], "motorway"];
const isState = ["match", ["get", "network"], ["us-highway", "us-state"], isNotRamp, false];
const isState = [
"match",
["get", "network"],
["us-highway", "us-state"],
isNotRamp,
false,
];
const isNotState = ["!", isState];
const isExpressway = ["==", ["get", "expressway"], 1];
const isNotExpressway = ["!", isExpressway];
Expand All @@ -31,7 +47,8 @@ const isMinorService = [
"match",
["get", "service"],
["parking_aisle", "driveway"],
true, false,
true,
false,
];
const isConstruction = ["in", "_construction", ["get", "class"]];
const isNotConstruction = ["!", isConstruction];
Expand All @@ -41,21 +58,44 @@ const roadFilter = [
"step",
["zoom"],
false,
4, ["all", ["==", ["get", "network"], "us-interstate"], isNotConstruction],
5, ["match", ["get", "class"], ["motorway", "trunk"], isNotRamp, false],
7, ["match", ["get", "class"], ["motorway", "trunk", "primary"], isNotRamp, false],
9, ["match", ["get", "class"], ["motorway", "trunk", "primary", "secondary"], true, false],
11, ["all", isRoad, isNotService, isNotConstruction],
12, ["all", isRoad, ["!", isMinorService], isNotConstruction],
13, ["all", isRoad, isNotConstruction],
4,
["all", ["==", ["get", "network"], "us-interstate"], isNotConstruction],
5,
["match", ["get", "class"], ["motorway", "trunk"], isNotRamp, false],
7,
[
"match",
["get", "class"],
["motorway", "trunk", "primary"],
isNotRamp,
false,
],
9,
[
"match",
["get", "class"],
["motorway", "trunk", "primary", "secondary"],
true,
false,
],
11,
["all", isRoad, isNotService, isNotConstruction],
12,
["all", isRoad, ["!", isMinorService], isNotConstruction],
13,
["all", isRoad, isNotConstruction],
];

export const road = {
id: "road",
type: "line",
source: "openmaptiles",
"source-layer": "transportation",
filter: Util.mapRampExpression(roadFilter, (input, output) => ["all", output, ["!=", ["get", "brunnel"], "tunnel"]]),
filter: Util.mapRampExpression(roadFilter, (input, output) => [
"all",
output,
["!=", ["get", "brunnel"], "tunnel"],
]),
layout: {
"line-cap": "butt",
"line-join": "round",
Expand All @@ -74,26 +114,36 @@ export const road = {
4,
[
"case",
isToll, `hsl(${tollRoadHue}, 60%, 70%)`,
isMotorway, `hsl(${motorwayHue}, 60%, 70%)`,
isState, `hsl(${stateHue}, 77%, 50%)`,
isToll,
`hsl(${tollRoadHue}, 60%, 70%)`,
isMotorway,
`hsl(${motorwayHue}, 60%, 70%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
"#9c9c9c",
],
8,
[
"case",
isToll, `hsl(${tollRoadHue}, 100%, 40%)`,
isMotorway, `hsl(${motorwayHue}, 100%, 45%)`,
isState, `hsl(${stateHue}, 77%, 50%)`,
isToll,
`hsl(${tollRoadHue}, 100%, 40%)`,
isMotorway,
`hsl(${motorwayHue}, 100%, 45%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
"#9c9c9c",
],
14,
[
"case",
isToll, `hsl(${tollRoadHue}, 100%, 35%)`,
isMotorway, `hsl(${motorwayHue}, 100%, 35%)`,
isState, `hsl(${stateHue}, 77%, 50%)`,
["all", ["==", ["get", "class"], "motorway"], isRamp], "#000",
isToll,
`hsl(${tollRoadHue}, 100%, 35%)`,
isMotorway,
`hsl(${motorwayHue}, 100%, 35%)`,
isState,
`hsl(${stateHue}, 77%, 50%)`,
["all", ["==", ["get", "class"], "motorway"], isRamp],
"#000",
"#9c9c9c",
],
],
Expand All @@ -106,28 +156,52 @@ export const road = {
8,
[
"case",
isMotorway, 3,
isExpressway, 1,
isState, 2,
["match", ["get", "class"], ["trunk", "primary"], isNotRamp, false], 2,
isMotorway,
3,
isExpressway,
1,
isState,
2,
["match", ["get", "class"], ["trunk", "primary"], isNotRamp, false],
2,
0.25,
],
18,
[
"case",
isMotorway, 6,
["all", isState, isNotExpressway], 4,
["match", ["get", "class"], ["trunk", "primary", "secondary", "tertiary"], isNotRamp, false], 4,
isService, 1,
isMotorway,
6,
["all", isState, isNotExpressway],
4,
[
"match",
["get", "class"],
["trunk", "primary", "secondary", "tertiary"],
isNotRamp,
false,
],
4,
isService,
1,
3,
],
20,
[
"case",
isMotorway, 10,
["all", isState, isNotExpressway], 8,
["match", ["get", "class"], ["trunk", "primary", "secondary", "tertiary"], isNotRamp, false], 8,
isService, 1,
isMotorway,
10,
["all", isState, isNotExpressway],
8,
[
"match",
["get", "class"],
["trunk", "primary", "secondary", "tertiary"],
isNotRamp,
false,
],
8,
isService,
1,
6,
],
],
Expand All @@ -154,44 +228,62 @@ export const road = {
["case", isUnpaved, 3, 0],
20,
["case", isUnpaved, 6, 0],
]
],
},
};

export const roadTunnel = {
...road,
id: "road-tunnel",
filter: Util.mapRampExpression(roadFilter, (input, output) => ["all", output, ["==", ["get", "brunnel"], "tunnel"]]),
filter: Util.mapRampExpression(roadFilter, (input, output) => [
"all",
output,
["==", ["get", "brunnel"], "tunnel"],
]),
paint: {
...road.paint,
"line-width": 1,
"line-gap-width": Util.mapRampExpression(road.paint["line-width"], (input, output) => ["-", output, 1]),
"line-gap-width": Util.mapRampExpression(
road.paint["line-width"],
(input, output) => ["-", output, 1]
),
"line-dasharray": [5, 5],
},
};

export const roadBridgeKnockout = {
...road,
id: "road-bridge-knockout",
filter: Util.mapRampExpression(roadFilter, (input, output) => ["all", output, ["==", ["get", "brunnel"], "bridge"]]),
filter: Util.mapRampExpression(roadFilter, (input, output) => [
"all",
output,
["==", ["get", "brunnel"], "bridge"],
]),
paint: {
"line-color": Color.backgroundFill,
"line-width": Util.mapRampExpression(road.paint["line-width"], (input, output) => ["*", output, 2]),
"line-width": Util.mapRampExpression(
road.paint["line-width"],
(input, output) => ["*", output, 2]
),
"line-gap-width": 0,
"line-blur": 0,
}
},
};

export const roadBridgeCasing = {
...road,
id: "road-bridge-casing",
filter: Util.mapRampExpression(roadFilter, (input, output) => ["all", output, ["==", ["get", "brunnel"], "bridge"]]),
filter: Util.mapRampExpression(roadFilter, (input, output) => [
"all",
output,
["==", ["get", "brunnel"], "bridge"],
]),
paint: {
"line-color": "#9c9c9c",
"line-width": 0.5,
"line-gap-width": roadBridgeKnockout.paint["line-width"],
"line-blur": 0,
}
},
};

export const legendEntries = [
Expand All @@ -213,7 +305,15 @@ export const legendEntries = [
{
description: "Local road",
layers: [road.id],
filter: ["all", isNotMotorway, isNotState, isNotToll, isNotExpressway, isNotRamp, isNotService],
filter: [
"all",
isNotMotorway,
isNotState,
isNotToll,
isNotExpressway,
isNotRamp,
isNotService,
],
},
{
description: "Service road",
Expand Down

0 comments on commit 6868d35

Please sign in to comment.