OpenLayers OpenLayers

Changeset 1338

Show
Ignore:
Timestamp:
08/23/06 16:37:16 (2 years ago)
Author:
crschmidt
Message:

If we're zooming with this tool, we only want to actually change the zoom if
the box was bigger than 5px in one direction or another. If it was smaller
than that, the user probably just clicked, rather than drawing a box, because
the MouseToolbar icon is kind of misleading.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/openlayers/2.0/lib/OpenLayers/Control/MouseDefaults.js

    r1248 r1338  
    6161        this.map.setCenter(newCenter, this.map.zoom + 1); 
    6262        Event.stop(evt); 
     63        return false; 
    6364    }, 
    6465 
     
    125126        if (!Event.isLeftClick(evt)) return; 
    126127        if (this.zoomBox) { 
    127             var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );  
    128             var end = this.map.getLonLatFromViewPortPx( evt.xy ); 
    129             var top = Math.max(start.lat, end.lat); 
    130             var bottom = Math.min(start.lat, end.lat); 
    131             var left = Math.min(start.lon, end.lon); 
    132             var right = Math.max(start.lon, end.lon); 
    133             var bounds = new OpenLayers.Bounds(left, bottom, right, top); 
    134             var zoom = this.map.getZoomForExtent(bounds); 
    135             this.map.setCenter(new OpenLayers.LonLat( 
    136               (start.lon + end.lon) / 2, 
    137               (start.lat + end.lat) / 2 
    138              ), zoom); 
     128            if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||     
     129                Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {    
     130                var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );  
     131                var end = this.map.getLonLatFromViewPortPx( evt.xy ); 
     132                var top = Math.max(start.lat, end.lat); 
     133                var bottom = Math.min(start.lat, end.lat); 
     134                var left = Math.min(start.lon, end.lon); 
     135                var right = Math.max(start.lon, end.lon); 
     136                var bounds = new OpenLayers.Bounds(left, bottom, right, top); 
     137                var zoom = this.map.getZoomForExtent(bounds); 
     138                this.map.setCenter(new OpenLayers.LonLat( 
     139                  (start.lon + end.lon) / 2, 
     140                  (start.lat + end.lat) / 2 
     141                 ), zoom); 
     142            } 
    139143            this.map.viewPortDiv.removeChild(document.getElementById("zoomBox")); 
    140144            this.zoomBox = null; 
     145             
    141146        } else { 
    142147            if (this.performedDrag) { 
  • branches/openlayers/2.0/lib/OpenLayers/Control/MouseToolbar.js

    r1316 r1338  
    9696        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
    9797        this.map.setCenter(newCenter, this.map.zoom + 2); 
     98        Event.stop(evt); 
     99        return false; 
    98100    }, 
    99101 
     
    239241        switch (this.mode) { 
    240242            case "zoombox": 
    241                 var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );  
    242                 var end = this.map.getLonLatFromViewPortPx( evt.xy ); 
    243                 var top = Math.max(start.lat, end.lat); 
    244                 var bottom = Math.min(start.lat, end.lat); 
    245                 var left = Math.min(start.lon, end.lon); 
    246                 var right = Math.max(start.lon, end.lon); 
    247                 var bounds = new OpenLayers.Bounds(left, bottom, right, top); 
    248                 var zoom = this.map.getZoomForExtent(bounds); 
    249                 this.map.setCenter(new OpenLayers.LonLat( 
    250                   (start.lon + end.lon) / 2, 
    251                   (start.lat + end.lat) / 2 
    252                  ), zoom); 
     243                console.log(this.mouseDragStart, evt.xy); 
     244                console.log(Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||                        Math.abs((this.mouseDragStart.y - evt.xy.y)) > 5); 
     245                console.log(Math.abs(this.mouseDragStart.x-evt.xy.x) > 5);  
     246                console.log(Math.abs(this.mouseDragStart.y-evt.xy.y)>5);  
     247                if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||     
     248                    Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {   
     249                    var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );  
     250                    var end = this.map.getLonLatFromViewPortPx( evt.xy ); 
     251                    var top = Math.max(start.lat, end.lat); 
     252                    var bottom = Math.min(start.lat, end.lat); 
     253                    var left = Math.min(start.lon, end.lon); 
     254                    var right = Math.max(start.lon, end.lon); 
     255                    var bounds = new OpenLayers.Bounds(left, bottom, right, top); 
     256                    var zoom = this.map.getZoomForExtent(bounds); 
     257                    this.map.setCenter(new OpenLayers.LonLat( 
     258                      (start.lon + end.lon) / 2, 
     259                      (start.lat + end.lat) / 2 
     260                     ), zoom); 
     261                }     
    253262                this.map.viewPortDiv.removeChild(document.getElementById("zoomBox")); 
    254263                this.zoomBox = null;