1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

Added error handling for leaflet initialisation errors

This commit is contained in:
Dean 2023-03-03 14:51:54 +00:00
parent 75fad90880
commit 7988f8c2d9

View file

@ -283,27 +283,32 @@
if (mapInstance) {
mapInstance.remove()
}
mapInstance = L.map(embeddedMapId, mapOptions)
mapMarkerGroup.addTo(mapInstance)
candidateMarkerGroup.addTo(mapInstance)
// Add attribution
const cleanAttribution = sanitizeHtml(attribution, {
allowedTags: ["a"],
allowedAttributes: {
a: ["href", "target"],
},
})
L.tileLayer(tileURL, {
attribution: "© " + cleanAttribution,
zoom,
}).addTo(mapInstance)
try {
mapInstance = L.map(embeddedMapId, mapOptions)
mapMarkerGroup.addTo(mapInstance)
candidateMarkerGroup.addTo(mapInstance)
// Add click handler
mapInstance.on("click", handleMapClick)
// Add attribution
const cleanAttribution = sanitizeHtml(attribution, {
allowedTags: ["a"],
allowedAttributes: {
a: ["href", "target"],
},
})
L.tileLayer(tileURL, {
attribution: "© " + cleanAttribution,
zoom,
}).addTo(mapInstance)
// Reset view
resetView()
// Add click handler
mapInstance.on("click", handleMapClick)
// Reset view
resetView()
} catch (e) {
console.log("There was a problem with the map", e)
}
}
const handleMapClick = e => {