How do I change the zoom magnification so that all markers installed in OpenLayers fit in?

Asked 1 years ago, Updated 1 years ago, 67 views

OpenStreetMap and OpenLayers have multiple markers on the map.

The position of this marker varies, so I would like to make it like the Google Maps API fitBounds method so that all markers can be seen when the map is displayed.

Does OpenLayers offer these features? I looked for it, but I couldn't find it.

Please let me know if there are any alternatives.

javascript openstreetmap openlayers

2022-09-30 20:14

1 Answers

I think it will be like this.

var bound=new OpenLayers.Bounds();
for (marker: yourMarkers) {
  bound.extend(marker.lonlat.transform(your_projection)));
}
map.zoomToExtent (bound);


2022-09-30 20:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.