From d0da958e5775cfe9f956f76594a053935ba9989d Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sun, 21 May 2006 00:35:04 +0000 Subject: [PATCH] 1. Change the calling syntax for events on this control so that they go from this instead of this.map. This has practical as well as idealogical benefits, namely that we can now call other methods on the control from within a control. This is neccesary for... 2. When the shift key is lifted, stop the zoomBox. This is the way in which users can *not* zoom once they've started. git-svn-id: http://svn.openlayers.org/trunk/openlayers@217 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/MouseDefaults.js | 66 ++++++++++++++----------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/OpenLayers/Control/MouseDefaults.js b/lib/OpenLayers/Control/MouseDefaults.js index 7ea639e488..da8d3d2202 100644 --- a/lib/OpenLayers/Control/MouseDefaults.js +++ b/lib/OpenLayers/Control/MouseDefaults.js @@ -7,19 +7,19 @@ OpenLayers.Control.MouseDefaults.prototype = }, draw: function() { - this.map.events.register( "dblclick", this.map, this.defaultDblClick ); - this.map.events.register( "mousedown", this.map, this.defaultMouseDown ); - this.map.events.register( "mouseup", this.map, this.defaultMouseUp ); - this.map.events.register( "mousemove", this.map, this.defaultMouseMove ); - //this.map.events.register( "mouseout", this.map, this.defaultMouseUp ); + this.map.events.register( "dblclick", this, this.defaultDblClick ); + this.map.events.register( "mousedown", this, this.defaultMouseDown ); + this.map.events.register( "mouseup", this, this.defaultMouseUp ); + this.map.events.register( "mousemove", this, this.defaultMouseMove ); + //this.map.events.register( "mouseout", this, this.defaultMouseUp ); }, /** * @param {Event} evt */ defaultDblClick: function (evt) { - var newCenter = this.getLonLatFromPixel( evt.xy ); - this.setCenter(newCenter, this.zoom + 1); + var newCenter = this.map.getLonLatFromPixel( evt.xy ); + this.map.setCenter(newCenter, this.map.zoom + 1); }, /** @@ -28,16 +28,16 @@ OpenLayers.Control.MouseDefaults.prototype = defaultMouseDown: function (evt) { this.mouseDragStart = evt.xy.copyOf(); if (evt.shiftKey) { - this.div.style.cursor = "crosshair"; + this.map.div.style.cursor = "crosshair"; this.zoomBox = OpenLayers.Util.createDiv('zoomBox'); this.zoomBox.style.border = '1px solid red'; this.zoomBox.style.position="absolute"; this.zoomBox.style.zIndex=1000; this.zoomBox.style.top=this.mouseDragStart.y; this.zoomBox.style.left=this.mouseDragStart.x; - this.viewPortDiv.appendChild(this.zoomBox); + this.map.viewPortDiv.appendChild(this.zoomBox); } else { - this.div.style.cursor = "move"; + this.map.div.style.cursor = "move"; } Event.stop(evt); }, @@ -48,6 +48,10 @@ OpenLayers.Control.MouseDefaults.prototype = defaultMouseMove: function (evt) { if (this.mouseDragStart != null) { if (this.zoomBox) { + if (!evt.shiftKey) { + this.defaultMouseUp(evt); + return; + } var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x); var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y); this.zoomBox.style.width = deltaX+"px"; @@ -59,14 +63,14 @@ OpenLayers.Control.MouseDefaults.prototype = this.zoomBox.style.top = evt.xy.y+"px"; } } else { - var deltaX = this.mouseDragStart.x - evt.xy.x; - var deltaY = this.mouseDragStart.y - evt.xy.y; - var size = this.getSize(); + var deltaX = this.map.mouseDragStart.x - evt.xy.x; + var deltaY = this.map.mouseDragStart.y - evt.xy.y; + var size = this.map.getSize(); var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, size.h / 2 + deltaY); - var newCenter = this.getLonLatFromPixel( newXY ); - this.setCenter(newCenter); - this.mouseDragStart = evt.xy.copyOf(); + var newCenter = this.map.getLonLatFromPixel( newXY ); + this.map.setCenter(newCenter); + this.map.mouseDragStart = evt.xy.copyOf(); } } }, @@ -76,23 +80,25 @@ OpenLayers.Control.MouseDefaults.prototype = */ defaultMouseUp: function (evt) { if (this.zoomBox) { - var start = this.getLonLatFromPixel( this.mouseDragStart ); - var end = this.getLonLatFromPixel( evt.xy ); - var top = (start.lat > end.lat ? start.lat : end.lat); - var bottom = (start.lat < end.lat ? start.lat : end.lat); - var left = (start.lon < end.lon ? start.lon : end.lon); - var right = (start.lon > end.lon ? start.lon : end.lon); - var bounds = new OpenLayers.Bounds(left, bottom, right, top); - var zoom = this.getZoomForExtent(bounds); - this.setCenter(new OpenLayers.LonLat( - (start.lon + end.lon) / 2, - (start.lat + end.lat) / 2 - ), zoom); - this.viewPortDiv.removeChild(document.getElementById("zoomBox")); + if (evt.shiftKey) { + var start = this.map.getLonLatFromPixel( this.mouseDragStart ); + var end = this.map.getLonLatFromPixel( evt.xy ); + var top = Math.max(start.lat, end.lat); + var bottom = Math.min(start.lat, end.lat); + var left = Math.min(start.lon, end.lon); + var right = Math.max(start.lon, end.lon); + var bounds = new OpenLayers.Bounds(left, bottom, right, top); + var zoom = this.map.getZoomForExtent(bounds); + this.map.setCenter(new OpenLayers.LonLat( + (start.lon + end.lon) / 2, + (start.lat + end.lat) / 2 + ), zoom); + } + this.map.viewPortDiv.removeChild(document.getElementById("zoomBox")); this.zoomBox = null; } this.mouseDragStart = null; - this.div.style.cursor = "default"; + this.map.div.style.cursor = "default"; } });