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) {
	if (workspace.latlong == null)
		continue;

	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) }" target="_blank">${
			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] || "");
}