Skip to content

Commit

Permalink
Fully support namespaced oneway tags on oneway arrows filter (re: #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Jul 24, 2024
1 parent c25c1e2 commit adbd037
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions js/mapController.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ function loadTrailLayers(name) {
}

var accessHierarchy = {
all: [],
atv: ['vehicle', 'motor_vehicle', 'atv'],
bicycle: ['vehicle', 'bicycle'],
canoe: ['boat', 'canoe'],
Expand Down Expand Up @@ -914,12 +915,12 @@ function isSpecifiedExpressionForLens(lens, travelMode) {
[
"all",
specifiedAttributeExpression,
["has", "waterway"],
["!has", "highway"],
],
[
"all",
attributeIsSpecifiedExpression(specifyingKeysForLens(lens, 'portage')),
["has", "portage"],
["!has", "waterway"],
],
];
}
Expand Down Expand Up @@ -963,6 +964,39 @@ function trailPoisFilter(travelMode) {
];
}

function onewayArrowsFilter(travelMode) {
var filter = ['any'];
var onewayKeys = onewayKeysForTravelMode(travelMode);
while (onewayKeys.length) {
var leastSpecificKey = onewayKeys.shift();
filter.push([
"all",
// if there isn't a more specific key (e.g. 'oneway:foot')
...onewayKeys.map(function(key) {
return ["!has", key];
}),
// then pay attention to the most specific key we have (e.g. 'oneway')
["in", leastSpecificKey, "yes", "-1", "alternating", "reversible"],
]);
}
if (travelMode === 'canoe') {
filter = [
"any",
[
"all",
filter,
["!has", "highway"],
],
[
"all",
onewayArrowsFilter('portage'),
["!has", "waterway"],
],
];
}
return filter;
}

function updateTrailLayers() {
toggleWaterTrailsIfNeeded();

Expand All @@ -979,31 +1013,12 @@ function updateTrailLayers() {
var pathsColors = colors.trail;
var waterwaysColors = colors.water;

var onewayArrowsFilter = [
"in", "oneway", "yes", "-1", "alternating", "reversible"
];

if (travelMode !== 'all') {

var modes = [travelMode];
if (travelMode == 'canoe') modes.push('portage');

allowedAccessExpression = ["any"];

onewayArrowsFilter = [
"any",
[
"all",
...modes.map(function(mode) {
return ["!has", "oneway:" + mode];
}),
["==", "oneway", "yes"],
],
...modes.map(function(mode) {
return ["==", "oneway:" + mode, "yes"];
}),
];

specifiedAccessExpression = ["any"];

modes.forEach(function(mode) {
Expand Down Expand Up @@ -1147,7 +1162,7 @@ function updateTrailLayers() {
.setPaintProperty('informal-paths', 'line-color', pathsColors)
.setPaintProperty('waterways', 'line-color', waterwaysColors)
.setFilter('bridge-casings', ["all", ["has", "bridge"], ["!in", "bridge", "no", "abandoned", "raised", "proposed", "dismantled"], combinedFilterExpression])
.setFilter('oneway-arrows', ["all", onewayArrowsFilter, combinedFilterExpression])
.setFilter('oneway-arrows', ["all", onewayArrowsFilter(travelMode), combinedFilterExpression])
.setFilter('trails-qa', ["all", showFixmesExpression, combinedFilterExpression])
.setFilter('trails-labels', combinedFilterExpression)
.setFilter('trails-pointer-targets', combinedFilterExpression)
Expand Down

0 comments on commit adbd037

Please sign in to comment.