diff options
| author | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-03-08 00:51:07 +0000 |
|---|---|---|
| committer | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-03-08 00:51:07 +0000 |
| commit | 5f1fa4936a3b45139c2bc111ecd602f3d13c2e90 (patch) | |
| tree | 99c1735cefee4cfc4292f920e0178711725db5f9 /web/public | |
| parent | 97ae21bf83fb04526269442e2fa3954d99d18665 (diff) | |
rezooming map using leaflet bounds to show all markers
Diffstat (limited to 'web/public')
| -rw-r--r-- | web/public/javascripts/map.js | 8 |
1 files changed, 8 insertions, 0 deletions
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 "<p>" + JSON.stringify(layer.feature.geometry) + "</p>"; }).addTo(map) + +// rezoom the map so that all the markers fit in the view +map.fitBounds(latlngbounds); |
