Skip to content

Commit

Permalink
Added bridge knockout and casing
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 4, 2024
1 parent 092df7c commit bde2dbf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
32 changes: 29 additions & 3 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ export function layerClone(def, id) {
//Make a clone of a layer definition, with a filter added
export function filteredClone(def, filterStep, idSuffix) {
var clone = layerClone(def, def.id + idSuffix);
if (!["all", "any"].includes(clone.filter[0])) {
throw new TypeError("Unlikely filter");
switch (clone.filter[0]) {
case "all":
case "any":
clone.filter.push(filterStep);
break;
case "interpolate":
case "interpolate-hcl":
case "interpolate-lab":
case "step":
clone.filter = mapRampExpression(clone.filter, (input, output) => ["all", output, filterStep]);
break;
default:
throw new TypeError("Unlikely filter");
}
clone.filter.push(filterStep);
return clone;
}

Expand All @@ -38,3 +48,19 @@ export function zoomMultiply(arr, multiplier) {
}
return transformedArray;
}

/**
* Returns a copy of the interpolate or step expression with each output replaced with the return value of the callback.
*
* @param expression An interpolate or step expression.
* @param callback A function that takes the expression's input value and output expression and returns a replacement expression.
* @returns A copy of the interpolate or step expression with the output expressions replaced.
*/
export function mapRampExpression(expression, callback) {
let copy = [...expression];
let start = copy[0] === "step" ? 1 : 3;
for (var i = start; i + 1 < copy.length; i += 2) {
copy[i + 1] = callback(copy[i], copy[i + 1]);
}
return copy;
}
4 changes: 3 additions & 1 deletion src/layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function build(locales) {
lyrAeroway.taxiway,
lyrAeroway.taxiwayArea,

lyrRoad.roadBridgeCasing,
lyrRoad.road,

lyrRail.rail.dashes(),
Expand All @@ -109,7 +110,8 @@ export function build(locales) {
var bridgeLayers = [
lyrRail.bridgeCasing,

//lyrRoad.road,
lyrRoad.roadBridgeKnockout,
lyrRoad.road,

lyrRail.railBridge.dashes(),
lyrRail.railServiceBridge.dashes(),
Expand Down
39 changes: 28 additions & 11 deletions src/layer/road.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

import * as Color from "../constants/color.js";
import * as Util from "../js/util.js";

const motorwayHue = 218;
Expand Down Expand Up @@ -36,14 +37,6 @@ 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"],
Expand All @@ -62,7 +55,7 @@ export const road = {
type: "line",
source: "openmaptiles",
"source-layer": "transportation",
filter: 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 Down Expand Up @@ -168,15 +161,39 @@ export const road = {
export const roadTunnel = {
...road,
id: "road-tunnel",
filter: 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": 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"]]),
paint: {
"line-color": Color.backgroundFill,
"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"]]),
paint: {
"line-color": "#9c9c9c",
"line-width": 0.5,
"line-gap-width": roadBridgeKnockout.paint["line-width"],
"line-blur": 0,
}
};

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

0 comments on commit bde2dbf

Please sign in to comment.