Added error handling for leaflet initialisation errors
This commit is contained in:
parent
75fad90880
commit
7988f8c2d9
|
@ -283,27 +283,32 @@
|
||||||
if (mapInstance) {
|
if (mapInstance) {
|
||||||
mapInstance.remove()
|
mapInstance.remove()
|
||||||
}
|
}
|
||||||
mapInstance = L.map(embeddedMapId, mapOptions)
|
|
||||||
mapMarkerGroup.addTo(mapInstance)
|
|
||||||
candidateMarkerGroup.addTo(mapInstance)
|
|
||||||
|
|
||||||
// Add attribution
|
try {
|
||||||
const cleanAttribution = sanitizeHtml(attribution, {
|
mapInstance = L.map(embeddedMapId, mapOptions)
|
||||||
allowedTags: ["a"],
|
mapMarkerGroup.addTo(mapInstance)
|
||||||
allowedAttributes: {
|
candidateMarkerGroup.addTo(mapInstance)
|
||||||
a: ["href", "target"],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
L.tileLayer(tileURL, {
|
|
||||||
attribution: "© " + cleanAttribution,
|
|
||||||
zoom,
|
|
||||||
}).addTo(mapInstance)
|
|
||||||
|
|
||||||
// Add click handler
|
// Add attribution
|
||||||
mapInstance.on("click", handleMapClick)
|
const cleanAttribution = sanitizeHtml(attribution, {
|
||||||
|
allowedTags: ["a"],
|
||||||
|
allowedAttributes: {
|
||||||
|
a: ["href", "target"],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
L.tileLayer(tileURL, {
|
||||||
|
attribution: "© " + cleanAttribution,
|
||||||
|
zoom,
|
||||||
|
}).addTo(mapInstance)
|
||||||
|
|
||||||
// Reset view
|
// Add click handler
|
||||||
resetView()
|
mapInstance.on("click", handleMapClick)
|
||||||
|
|
||||||
|
// Reset view
|
||||||
|
resetView()
|
||||||
|
} catch (e) {
|
||||||
|
console.log("There was a problem with the map", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleMapClick = e => {
|
const handleMapClick = e => {
|
||||||
|
|
Loading…
Reference in New Issue