From 5f1fa4936a3b45139c2bc111ecd602f3d13c2e90 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Thu, 7 Mar 2019 19:51:07 -0500 Subject: rezooming map using leaflet bounds to show all markers --- web/public/javascripts/map.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'web/public/javascripts/map.js') diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index 190307d..bad07c8 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -12,12 +12,20 @@ L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r} ext: 'png' }).addTo(map); +// keep track of the boundary of the markers so that we can update the +// map to fit them all +var latlngbounds = new L.latLngBounds(); + L.geoJson(points, { pointToLayer: function (feature, latlng) { //return L.circleMarker(latlng); + latlngbounds.extend(latlng); return L.marker(latlng); } }).bindPopup(function (layer) { // layer.feature.geometry gives you access to all the fields return "

" + JSON.stringify(layer.feature.geometry) + "

"; }).addTo(map) + +// rezoom the map so that all the markers fit in the view +map.fitBounds(latlngbounds); -- cgit v1.2.3 From 54e468b728dbdce20f98bae88caaaaa74b122d24 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Thu, 7 Mar 2019 20:37:51 -0500 Subject: added padding for distant points just in case --- web/public/javascripts/map.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'web/public/javascripts/map.js') diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index bad07c8..3dbf517 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -27,5 +27,6 @@ L.geoJson(points, { return "

" + JSON.stringify(layer.feature.geometry) + "

"; }).addTo(map) -// rezoom the map so that all the markers fit in the view -map.fitBounds(latlngbounds); +// rezoom the map so that all the markers fit in the view, add 20% padding so +// that marker dont cut off +map.fitBounds(latlngbounds.pad(0.20)); -- cgit v1.2.3