Skip to content
Snippets Groups Projects

Add interactive map

6 files
+ 91
5
Compare changes
  • Side-by-side
  • Inline

Files

+ 27
0
var map = L.map("map").setView([54.004, -2.55], 5);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"
}).addTo(map);
for (let workspace of mapData) {
L.marker(workspace.latlong).addTo(map)
.bindPopup(`<div class="popup"><div><a href="/workspace/${ encodeURIComponent(workspace.id) }" class="popup-title">${
escapeHTML(workspace.name)
}</a></div><div>Phone: <a href="tel:${ escapeHTML(workspace.phoneNumber) }">${
escapeHTML(workspace.phoneNumber)
}</a></div><div>Email: <a href="mailto:${ escapeHTML(workspace.email) }">${
escapeHTML(workspace.email)
}</a></div><div>Website: <a href="${ escapeHTML(workspace.website) }">${
escapeHTML(workspace.website)
}</a></div><div>${ escapeHTML(workspace.address) }</div></div>`);
}
function escapeHTML(html) {
let lookup = Object.create(null);
lookup["<"] = "&lt;"
lookup[">"] = "&gt;"
lookup["\""] = "&quot;"
lookup["&"] = "&amp";
return html.replace(/[<>"&]/g, v => lookup[v] || "");
}
\ No newline at end of file
Loading