with openlayers , how do i make sure a list of poi

2019-06-07 03:20发布

问题:

I have an OpenLayers map object, and I have added markers to a layer, and added it to the map.

But how do I make sure all the markers are in the display area?

Thanks,

Gil

回答1:

In order to display all markers on the map
Firstly,make sure you have all markers in one layer.
Secondly,you need to zoom to bound where all markers in marker layer are extended.
To do that,simply

   var bounds = markerLayer.getDataExtent();
   map.zoomToExtent(bounds);
   //has a second parameter that decides to find closest zoom level
   //default is false

Please check OpenLayers Document for Marker Layer

Best Regards
Myra