Search code examples
openlayers-3

OpenLayers: Zoom multiple layers to best common extent?


Is there an easy way (other than getting layer extents separately and doing the calculation) to group the layers and zoom to the extent that is best for displaying shapes on all of the grouped layers?


Solution

  • Solution:

    bounds = @get('siblingsLayer').getDataExtent()
    bounds.extend(@get('vectorLayer').getDataExtent())
    bounds.extend(@get('parentLayer').getDataExtent())
    
    @get('map').zoomToExtent(bounds)