ZoomToExtent OpenLayers 3

Tyl*_*itt 20 openlayers openlayers-3

OpenLayers 2有一个非常有用的map.zoomToExtent(extent)功能.OpenLayers 3中有类似的东西吗?我可以获得感兴趣的程度source.getExtent(),但我无法弄清楚如何将该范围应用为"缩放级别".

Tyl*_*itt 47

关闭链接到的函数sfletche:

var extent = source.getExtent();
map.getView().fitExtent(extent, map.getSize());
Run Code Online (Sandbox Code Playgroud)

编辑2013年7月23日

显然fitExtent已被弃用.应该是ol.View.fit,所以这样的事情(未经测试):

var extent = source.getExtent();
map.getView().fit(extent, map.getSize()); 
Run Code Online (Sandbox Code Playgroud)

  • 它在3.7中替换为[`ol.View.fit`](http://openlayers.org/en/v3.7.0/apidoc/ol.View.html#fit). (3认同)