简体   繁体   English

Openlayers停止zoomstart事件

[英]Openlayers stop zoomstart event

I work with Openlayers 2.x and I have zoomstart event 我使用Openlayers 2.x并且有zoomstart事件

  map.events.register('zoomstart', map, function(e) {

            // 1. OpenLayers.Event.stop(event);
            // 2. return ;
            // 3. e.preventDefault();
        }
    });

My way (1,2,3) not working and event does not stop and change zoom level. 我的方式(1,2,3)无法正常工作,事件也无法停止并更改缩放级别。 Can anybody help me? 有谁能够帮助我?

The zoom event is triggered by the zoomBarUp function in PanZoomBar control, see: http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/PanZoomBar.js and the line 缩放事件由PanZoomBar控件中的zoomBarUp函数触发,请参见: http ://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/PanZoomBar.js和该行

this.map.zoomTo(zoomLevel);

One way to prevent zoom for zoom levels above 13 would be to override this function, which you can do by adding your own version, either in a standalone js file or by using prototype within you OpenLayers init function, ie, after OpenLayers has loaded. 防止高于13的缩放级别进行缩放的一种方法是重写此功能,您可以通过在独立的js文件中添加自己的版本或通过在OpenLayers初始化函数中使用原型(即,在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);
  }};

There may be a more elegant way, but this should work. 也许有一种更优雅的方法,但这应该可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM