Openlayers停止缩放启动事件



我与Openlayers 2.x一起工作,我有zoomstart事件

  map.events.register('zoomstart', map, function(e) {
            // 1. OpenLayers.Event.stop(event);
            // 2. return ;
            // 3. e.preventDefault();
        }
    });

我的方式(1,2,3)不工作,事件不停止和改变缩放级别。有人能帮帮我吗?

缩放事件是由PanZoomBar控件中的zoomBarUp函数触发的,参见:http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/PanZoomBar.js和

this.map.zoomTo(zoomLevel);

防止缩放级别高于13的缩放的一种方法是重写此函数,您可以通过添加自己的版本来实现,无论是在独立的js文件中,还是在OpenLayers初始化函数中使用prototype,即在OpenLayers加载后。

OpenLayers.Control.PanZoomBar.prototype.zoomBarUp = function(evt){
  //copy here the code from the actual function
  if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") {
        return;
  }
  //rest of code .....

 //put in your check for zoom level here before calling this.map.zoomTo(zoomLevel);
 if(this.map.zoom<13){
     this.map.zoomTo(zoomLevel);
        this.mouseDragStart = null;
        this.zoomStart = null;
        this.deltaY = 0;
        OpenLayers.Event.stop(evt);
  }};

可能有一种更优雅的方式,但这应该可以工作。

最新更新