with openlayers , how do i make sure the markers in TWO layers are all dsiplayed
I have markers in two marker layers,which i need to keep separate, so I can clear one or t开发者_StackOverflowhe other in the application.
What is the best way to make sure all markers are displayed. Doing it for one layer is easy with zoomToExtent. But how to do it for more then one layer?
Get the bounds from layer 1, use .extend(layer 2's bounds), and then zoomToExtent on the extended bounds.
http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/BaseTypes/Bounds-js.html#OpenLayers.Bounds.extend
is the extend method on a bounds.
sketchy and quick, sorry....
Use a new bounds object and use Bounds.extend.
var myNewBounds = Layer1.zoomToExtent.getExtent();
myNewBounds.extend(Layer2.zoomToExtent.getExtent());
Use that new bounds variable to set the bounds on your map. The syntax is wrong, but that's the direction you want to go.
精彩评论