如何在初始缩放视图中避免平移地图

How to avoid pan map at initial zoom view

我想避免在加载应用程序并开始用户交互时在初始缩放时平移地图。 Openlayers 3 的正常行为是允许用户平移(如果他愿意的话)只是到地图的中间,但我需要在初始缩放时限制它以防止显示 bbox 之外的制图。

可以做到吗?

更改地图的范围我没有得到预期的结果。

提前致谢

仅发布代码的相关部分

  var panInteraction = new ol.interaction.DragPan();

  var map = new ol.Map({
      layers: [raster, vector],
      interactions : [panInteraction],
        target: 'map',
        view: new ol.View({
          center: [-11000000, 4600000],
          zoom: 4
        })
  });

  var zoomLevel = map.getView().getZoom();

  if (zoomLevel == 4) {
      panInteraction.setActive(false);
      //alert("deactivating");
  }