Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/components/utilities/map/js/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ maps.forEach(container => {
})
})

const titlePopup = new System.Popup({
...popupObject,
closeOnClick: false
})

mapElement.on('click', 'woodlands-map-detail', (event) => {
const coordinates = event.features[0].geometry.coordinates.slice()
const html = event.features[0].properties.html
Expand All @@ -168,6 +173,7 @@ maps.forEach(container => {
coordinates[0] += event.lngLat.lng > coordinates[0] ? 360 : -360
}

titlePopup.remove()
new System.Popup(popupObject)
.setLngLat(coordinates)
.setHTML(html)
Expand All @@ -182,12 +188,28 @@ maps.forEach(container => {
mapElement.getCanvas().style.cursor = ''
})

mapElement.on('mouseenter', 'woodlands-map-detail', () => {
mapElement.on('mouseenter', 'woodlands-map-detail', (event) => {
const coordinates = event.features[0].geometry.coordinates.slice()
const description = event.features[0].properties.title

mapElement.getCanvas().style.cursor = 'pointer'

// Ensure that if the map is zoomed out such that
// multiple copies of the feature are visible, the
// popup appears over the copy being pointed to.
while (Math.abs(event.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += event.lngLat.lng > coordinates[0] ? 360 : -360
}

titlePopup
.setLngLat(coordinates)
.setHTML(description)
.addTo(mapElement)
})

mapElement.on('mouseleave', 'woodlands-map-detail', () => {
mapElement.getCanvas().style.cursor = ''
titlePopup.remove()
})

const countPopup = new System.Popup({
Expand Down