Skip to content

Commit

Permalink
Add mouse position control to Leaflet map
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed May 16, 2024
1 parent 3f785e7 commit 454a9f7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions frontend/src/components/TheLeafletMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@ onMounted(() => {
zoom.value = e.target._zoom;
});
let Position = L.Control.extend({
_container: null,
options: {
position: 'bottomleft'
},
onAdd: function () {
const latlng = L.DomUtil.create('div', 'mouseposition');
this._latlng = latlng;
return latlng;
},
updateHTML: function (lat, lng) {
this._latlng.innerHTML = `Lat/Lng: ${lat} ${lng}`
}
});
const position = new Position();
leaflet.addControl(position);
leaflet.addEventListener('mousemove', (e) => {
const [lat, lng] = getLatLong(e);
position.updateHTML(lat, lng);
});
function getLatLong(e) {
let lat = Math.round(e.latlng.lat * 100000) / 100000;
let lng = Math.round(e.latlng.lng * 100000) / 100000;
return [lat, lng];
}
// add lakes features layer to map
let url = 'https://arcgis.cuahsi.org/arcgis/rest/services/SWOT/world_swot_lakes/FeatureServer/0'
const lakesFeatures = esriLeaflet.featureLayer({
Expand Down

0 comments on commit 454a9f7

Please sign in to comment.