ZoomToExtent OpenLayers 3

前端 未结 3 507
不知归路
不知归路 2021-01-01 14:28

OpenLayers 2 had a very useful map.zoomToExtent(extent) feature. Is there something similar in OpenLayers 3? I can get the extent of interest with source

3条回答
  •  甜味超标
    2021-01-01 14:32

    With OpenLayers 4.x this is still a valid solution:

    map.getView().fit(source.getExtent(), map.getSize()); 
    

    Make sure to set the optional second parameter to prevent console errors, if there are no points on the map.

提交回复
热议问题