// Calculate bounds var bounds = new L.LatLngBounds(); locations.forEach(function(location) { bounds.extend([location.lat, location.lng]); }); // Set center to the midpoint of the bounds var centerLatLng = bounds.getCenter(); var map = L.map('OSM-map', mapOptions).setView(centerLatLng, 1); // Adjust the map to fit all markers within the bounds map.fitBounds(bounds); // Zoom out a bit more by decreasing the zoom level map.setZoom(map.getZoom() - 1); // Decrease zoom level by 1
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter