OpenLayers OpenLayers

Changeset 204

Show
Ignore:
Timestamp:
05/19/06 22:29:39 (3 years ago)
Author:
crschmidt
Message:

Migrate Map MouseControls to MouseDefaults.js. This moves event handling into a control, where we can modify it and edit it without mucking about in the main map class, bringing this portion of the code more into line with the way other aspects of the controls situation work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers.js

    r191 r204  
    5555        "OpenLayers/Layer/WFS.js", 
    5656        "OpenLayers/Control.js", 
     57        "OpenLayers/Control/MouseDefaults.js", 
    5758        "OpenLayers/Control/PanZoom.js", 
    5859        "OpenLayers/Control/PanZoomBar.js", 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r201 r204  
    9494        this.controls = []; 
    9595        this.addControl( new OpenLayers.Control.PanZoom() ); 
    96  
    97         this.events.register( "dblclick", this, this.defaultDblClick ); 
    98         this.events.register( "mousedown", this, this.defaultMouseDown ); 
    99         this.events.register( "mouseup", this, this.defaultMouseUp ); 
    100         this.events.register( "mousemove", this, this.defaultMouseMove ); 
    101         this.events.register( "mouseout", this, this.defaultMouseUp ); 
     96        this.addControl( new OpenLayers.Control.MouseDefaults() ); 
    10297 
    10398        // always call map.destroy() 
     
    150145        control.map = this; 
    151146        this.controls.push(control); 
    152         this.controlDiv.appendChild( control.draw() ); 
     147        var div = control.draw(); 
     148        if (div) { 
     149            this.controlDiv.appendChild( div ); 
     150        } 
    153151    }, 
    154152 
     
    346344    }, 
    347345 
    348     /** 
    349     * @param {Event} evt 
    350     */ 
    351     defaultDblClick: function (evt) { 
    352         var newCenter = this.getLonLatFromPixel( evt.xy );  
    353         this.setCenter(newCenter, this.zoom + 1); 
    354     }, 
    355  
    356     /** 
    357     * @param {Event} evt 
    358     */ 
    359     defaultMouseDown: function (evt) { 
    360         this.mouseDragStart = evt.xy.copyOf(); 
    361         this.div.style.cursor = "move"; 
    362         Event.stop(evt); 
    363     }, 
    364  
    365     /** 
    366     * @param {Event} evt 
    367     */ 
    368     defaultMouseMove: function (evt) { 
    369         if (this.mouseDragStart != null) { 
    370             var deltaX = this.mouseDragStart.x - evt.xy.x; 
    371             var deltaY = this.mouseDragStart.y - evt.xy.y 
    372             var size = this.getSize(); 
    373             var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 
    374                                              size.h / 2 + deltaY); 
    375             var newCenter = this.getLonLatFromPixel( newXY );  
    376             this.setCenter(newCenter); 
    377             this.mouseDragStart = evt.xy.copyOf(); 
    378         } 
    379     }, 
    380  
    381     /** 
    382     * @param {Event} evt 
    383     */ 
    384     defaultMouseUp: function (evt) { 
    385         this.mouseDragStart = null; 
    386         this.div.style.cursor = "default"; 
    387     }, 
    388  
    389346    CLASS_NAME: "OpenLayers.Map" 
    390347};