Skip to content

Commit

Permalink
Added tunnel layer
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 4, 2024
1 parent 8f8ba05 commit 092df7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export function build(locales) {

lyrConstruction.road,

//lyrRoad.roadTunnel.casing(),
//
//lyrRoad.roadTunnel.fill(),
lyrRoad.roadTunnel,

lyrOneway.tunnel,

Expand Down
46 changes: 34 additions & 12 deletions src/layer/road.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,33 @@ const isConstruction = ["in", "_construction", ["get", "class"]];
const isNotConstruction = ["!", isConstruction];
const isUnpaved = ["==", ["get", "surface"], "unpaved"];

function mapRampExpression(expression, callback) {
let start = expression[0] === "step" ? 1 : 3;
for (var i = start; i + 1 < expression.length; i += 2) {
expression[i + 1] = callback(expression[i], expression[i + 1]);
}
return expression;
}

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],
];

export const road = {
id: "road",
type: "line",
source: "openmaptiles",
"source-layer": "transportation",
filter: [
"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],
],
filter: mapRampExpression([...roadFilter], (input, output) => ["all", output, ["!=", ["get", "brunnel"], "tunnel"]]),
layout: {
"line-cap": "butt",
"line-join": "round",
Expand Down Expand Up @@ -155,6 +165,18 @@ export const road = {
},
};

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

export const legendEntries = [
{
description: "Controlled-access highway",
Expand Down

0 comments on commit 092df7c

Please sign in to comment.