Skip to content

Commit

Permalink
Add cases for filtering on 2 keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
watmildon committed Apr 4, 2024
1 parent e302aa3 commit ba99d00
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions docs/WAMap/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var filterTextBox = document.getElementById("filterTextBox");
var filterText = filterTextBox.value;


if (filterText === "") {
clearFilter();
return;
Expand All @@ -15,6 +14,13 @@
const newURL = `${window.location.pathname}?${newQueryString}${window.location.hash}`;
window.history.replaceState({}, '', newURL);

// supported query strings:
// key
// -key
// key1,-key2
// key=*
// key=value
// key=value1,value2,value3
if (filterText.includes("=")) {
var kvp = filterText.split("=");
if (filterText.includes(",")) {
Expand Down Expand Up @@ -50,12 +56,28 @@
window.tigerMap.setLayoutProperty("allFeatures-node", "visibility", "visible");
}
} else {
if (filterText[0] === "-") {
window.tigerMap.setFilter("allFeatures", ["!", ["has", filterText.substring(1)]]);
window.tigerMap.setFilter("allFeatures-node", ["!", ["has", filterText.substring(1)]]);
// key1,-key2
// ["all",["has","highway"],["!",["has","maxspeed"]]]
if (filterText.includes(",")) {
var values = filterText.split(",");
if (values[1][0] === "-")
{
window.tigerMap.setFilter("allFeatures",["all",["has",values[0]],["!",["has",values[1].substring(1)]]]);
window.tigerMap.setFilter("allFeatures-node",["all",["has",values[0]],["!",["has",values[1].substring(1)]]]);
}
else
{
window.tigerMap.setFilter("allFeatures",["all",["has",values[0]],["has",values[1]]]);
window.tigerMap.setFilter("allFeatures-node",["all",["has",values[0]],["has",values[1]]]);
}
} else {
window.tigerMap.setFilter("allFeatures", ["has", filterText]);
window.tigerMap.setFilter("allFeatures-node", ["has", filterText]);
if (filterText[0] === "-") {
window.tigerMap.setFilter("allFeatures", ["!", ["has", filterText.substring(1)]]);
window.tigerMap.setFilter("allFeatures-node", ["!", ["has", filterText.substring(1)]]);
} else {
window.tigerMap.setFilter("allFeatures", ["has", filterText]);
window.tigerMap.setFilter("allFeatures-node", ["has", filterText]);
}
}
}
}
Expand Down

0 comments on commit ba99d00

Please sign in to comment.