add: map popup

dev
rrr-marble 4 years ago
parent 05a3796f72
commit 2d3baa5252

@ -28,7 +28,7 @@ export default {
layers: [] layers: []
}, },
center: [37.625, 55.751], // starting position [lng, lat] center: [37.625, 55.751], // starting position [lng, lat]
zoom: 5, // starting zoom zoom: 2, // starting zoom
maxZoom: 10 maxZoom: 10
})); }));
@ -69,25 +69,32 @@ export default {
'circle-stroke-color': '#FFFFFF', 'circle-stroke-color': '#FFFFFF',
'circle-color': '#1a9641', 'circle-color': '#1a9641',
'circle-opacity': 0.8, 'circle-opacity': 0.8,
'circle-radius': 6 'circle-radius': 16
} }
}); });
}); });
window.addEventListener("mouseenter", (e) => { const popup = new maplibregl.Popup({
if (e.target.id == "samples-layer") { closeButton: false,
// Change the cursor style as a UI indicator. closeOnClick: false,
map.value.getCanvas().style.cursor = 'pointer';
}
});
window.addEventListener("mouseenter", (e) => {
if (e.target.id == "samples-layer") {
// Change the cursor style as a UI indicator.
map.value.getCanvas().style.cursor = '';
}
}) })
map.value.on('mouseover', 'samples-layer', (e) => {
// Change the cursor style as a UI indicator.
map.value.getCanvas().style.cursor = 'pointer';
// Populate the popup and set its coordinates
// based on the feature found.
popup
.setLngLat(e.lngLat)
.setHTML(JSON.stringify(e.features[0].properties))
.addTo(map.value);
});
map.value.on('mouseleave', 'samples-layer', (e) => {
map.value.getCanvas().style.cursor = '';
popup.remove();
});
}); });
onUnmounted(() => { onUnmounted(() => {