覆盖OpenLayers.Map的moveTo和moveByPx方法

时间:2013-06-18 19:37:44

标签: events methods override openlayers zooming

如何覆盖OpenLayers.Map的moveTo和moveByPx方法,以消除“movestart”事件触发除缩放以外的任何操作?

1 个答案:

答案 0 :(得分:-1)

map = new OpenLayers.Map("map");

OpenLayers.Map.prototype.moveByPx = function (a, b) { 
    var c = this.size.w / 2, 
        d = this.size.h / 2, 
        e = c + a, 
        f = d + b, 
        g = this.baseLayer.wrapDateLine, 
        h = 0, 
        k = 0;

    this.restrictedExtent && (h = c, k = d, g = !1);

    a = g || e <= this.maxPx.x - h && e >= this.minPx.x + h ? Math.round(a) : 0;
    b = f <= this.maxPx.y - k && f >= this.minPx.y + k ? Math.round(b) : 0;

    if (a || b) { 
        this.dragging || (this.dragging = !0);
        this.center = null;
        a && (this.layerContainerOriginPx.x -= a, this.minPx.x -= a, this.maxPx.x -= a);
        b && (this.layerContainerOriginPx.y -= b, this.minPx.y -= b, this.maxPx.y -= b);
        this.applyTransform();
        d = 0;
        for (e = this.layers.length; d < e; ++d) 
            c = this.layers[d], c.visibility && (c === this.baseLayer || c.inRange) && (c.moveByPx(a, b), c.events.triggerEvent("move"));
        this.events.triggerEvent("move") 
    } 
}

map.events.register("movestart", map, function (e) {
  My Code...
});