Search code examples
javascriptmappingopenlayers

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 the 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?


Solution

  • 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....