Skip to content

Commit

Permalink
Merge pull request #27 from mblaine/main
Browse files Browse the repository at this point in the history
When clicking feature, make @id a hyper link and highlight the featur…
  • Loading branch information
watmildon authored May 22, 2024
2 parents 5e1c06e + 5b28916 commit 246fc83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/mapstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,19 @@ var mapstyle_layers = [
},
source: "redlined",
"source-layer": "redlined-D",
},
{
id: "highlight",
type: "line",
paint: {
"line-color": "#f5812f",
"line-width": 5,
},
"layout": {
"line-cap": "round",
"line-join": "round",
"visibility": "visible"
},
source: "highlight"
}
];
23 changes: 22 additions & 1 deletion docs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ document.addEventListener("alpine:init", async () => {
url: "pmtiles://" + url_prefix + "AllUSCounties.pmtiles",
attribution: "© Public Domain, USDOT",
},
highlight: {
type: "geojson",
data: {
"type": "FeatureCollection",
"features": [
]
},
attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>',
},
osmcarto: {
type: "raster",
tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"],
Expand Down Expand Up @@ -93,16 +102,28 @@ document.addEventListener("alpine:init", async () => {
let html = `<h4>feature #${i+1}</h4>`;
html += "<ul>"
for (const [key, val] of Object.entries(properties)) {
html += `<li>${key}=${val}</li>`;
if(key === "@id" && typeof(properties["@type"]) !== "undefined") {
let t = properties["@type"];
html += `<li>${key}=<a target="_blank" href="https://www.openstreetmap.org/${t}/${val}">${val}</a></li>`;
} else {
html += `<li>${key}=${val}</li>`;
}
}
html += "</ul>";
return html;
}
const newHighlightSource = {
"type": "FeatureCollection",
"features": [
]
};
const features = {};
for (const f of e.features) {
features[f.properties['@type'] + f.properties['@id']] = f;
newHighlightSource["features"].push(f);
}
const html = `<div class="inspect-popup">${Array.from(Object.values(features)).map(feature2html).join("<br>")}</div>`;
window.tigerMap.getSource("highlight").setData(newHighlightSource);

const popup = new maplibregl.Popup()
.setLngLat(e.lngLat)
Expand Down

0 comments on commit 246fc83

Please sign in to comment.