view proportional to leaflet point diagram, openlayers [closed]

0

I'm making a point map with leaflet, and at the beginning I have to define the view along with the scale;

     var map = L.map('map').
     setView([41.66, -4.72],
     5);

It happens that after I have a diagram of points that will be generated automatically, with different coordinates, I would like if the view could generate coordinates that encompassed the diagrams of points at a proportional scale.

    
asked by David Kenobi 25.07.2017 в 14:14
source

1 answer

0

Assuming that your point layer is a geojson, the simplest way is to ask that layer what its bounding box with getBounds , that is, the smallest rectangle or box that encompasses all geometries. And then set that bounding box on the map with fitBounds .

let geojsonData = null; // el geojson que representa tus puntos
let myLayer = L.geoJSON(geojsonData).addTo(map);
let bounds = myLayer.getBounds();
map.fitBounds(bounds);

Sometimes when using fitBounds the map may be too tight to the layer and you want to give it a little padding, that is, leave more space between the geometries and the margins. You can do it with the options of fitBounds , or by running the pad about bounds

    
answered by 25.07.2017 / 16:46
source