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
This commit is contained in:
@@ -7,19 +7,19 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
},
|
},
|
||||||
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
this.map.events.register( "dblclick", this.map, this.defaultDblClick );
|
this.map.events.register( "dblclick", this, this.defaultDblClick );
|
||||||
this.map.events.register( "mousedown", this.map, this.defaultMouseDown );
|
this.map.events.register( "mousedown", this, this.defaultMouseDown );
|
||||||
this.map.events.register( "mouseup", this.map, this.defaultMouseUp );
|
this.map.events.register( "mouseup", this, this.defaultMouseUp );
|
||||||
this.map.events.register( "mousemove", this.map, this.defaultMouseMove );
|
this.map.events.register( "mousemove", this, this.defaultMouseMove );
|
||||||
//this.map.events.register( "mouseout", this.map, this.defaultMouseUp );
|
//this.map.events.register( "mouseout", this, this.defaultMouseUp );
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Event} evt
|
* @param {Event} evt
|
||||||
*/
|
*/
|
||||||
defaultDblClick: function (evt) {
|
defaultDblClick: function (evt) {
|
||||||
var newCenter = this.getLonLatFromPixel( evt.xy );
|
var newCenter = this.map.getLonLatFromPixel( evt.xy );
|
||||||
this.setCenter(newCenter, this.zoom + 1);
|
this.map.setCenter(newCenter, this.map.zoom + 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,16 +28,16 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
defaultMouseDown: function (evt) {
|
defaultMouseDown: function (evt) {
|
||||||
this.mouseDragStart = evt.xy.copyOf();
|
this.mouseDragStart = evt.xy.copyOf();
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
this.div.style.cursor = "crosshair";
|
this.map.div.style.cursor = "crosshair";
|
||||||
this.zoomBox = OpenLayers.Util.createDiv('zoomBox');
|
this.zoomBox = OpenLayers.Util.createDiv('zoomBox');
|
||||||
this.zoomBox.style.border = '1px solid red';
|
this.zoomBox.style.border = '1px solid red';
|
||||||
this.zoomBox.style.position="absolute";
|
this.zoomBox.style.position="absolute";
|
||||||
this.zoomBox.style.zIndex=1000;
|
this.zoomBox.style.zIndex=1000;
|
||||||
this.zoomBox.style.top=this.mouseDragStart.y;
|
this.zoomBox.style.top=this.mouseDragStart.y;
|
||||||
this.zoomBox.style.left=this.mouseDragStart.x;
|
this.zoomBox.style.left=this.mouseDragStart.x;
|
||||||
this.viewPortDiv.appendChild(this.zoomBox);
|
this.map.viewPortDiv.appendChild(this.zoomBox);
|
||||||
} else {
|
} else {
|
||||||
this.div.style.cursor = "move";
|
this.map.div.style.cursor = "move";
|
||||||
}
|
}
|
||||||
Event.stop(evt);
|
Event.stop(evt);
|
||||||
},
|
},
|
||||||
@@ -48,6 +48,10 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
defaultMouseMove: function (evt) {
|
defaultMouseMove: function (evt) {
|
||||||
if (this.mouseDragStart != null) {
|
if (this.mouseDragStart != null) {
|
||||||
if (this.zoomBox) {
|
if (this.zoomBox) {
|
||||||
|
if (!evt.shiftKey) {
|
||||||
|
this.defaultMouseUp(evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
|
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
|
||||||
var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y);
|
var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y);
|
||||||
this.zoomBox.style.width = deltaX+"px";
|
this.zoomBox.style.width = deltaX+"px";
|
||||||
@@ -59,14 +63,14 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
this.zoomBox.style.top = evt.xy.y+"px";
|
this.zoomBox.style.top = evt.xy.y+"px";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var deltaX = this.mouseDragStart.x - evt.xy.x;
|
var deltaX = this.map.mouseDragStart.x - evt.xy.x;
|
||||||
var deltaY = this.mouseDragStart.y - evt.xy.y;
|
var deltaY = this.map.mouseDragStart.y - evt.xy.y;
|
||||||
var size = this.getSize();
|
var size = this.map.getSize();
|
||||||
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
|
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
|
||||||
size.h / 2 + deltaY);
|
size.h / 2 + deltaY);
|
||||||
var newCenter = this.getLonLatFromPixel( newXY );
|
var newCenter = this.map.getLonLatFromPixel( newXY );
|
||||||
this.setCenter(newCenter);
|
this.map.setCenter(newCenter);
|
||||||
this.mouseDragStart = evt.xy.copyOf();
|
this.map.mouseDragStart = evt.xy.copyOf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -76,23 +80,25 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
*/
|
*/
|
||||||
defaultMouseUp: function (evt) {
|
defaultMouseUp: function (evt) {
|
||||||
if (this.zoomBox) {
|
if (this.zoomBox) {
|
||||||
var start = this.getLonLatFromPixel( this.mouseDragStart );
|
if (evt.shiftKey) {
|
||||||
var end = this.getLonLatFromPixel( evt.xy );
|
var start = this.map.getLonLatFromPixel( this.mouseDragStart );
|
||||||
var top = (start.lat > end.lat ? start.lat : end.lat);
|
var end = this.map.getLonLatFromPixel( evt.xy );
|
||||||
var bottom = (start.lat < end.lat ? start.lat : end.lat);
|
var top = Math.max(start.lat, end.lat);
|
||||||
var left = (start.lon < end.lon ? start.lon : end.lon);
|
var bottom = Math.min(start.lat, end.lat);
|
||||||
var right = (start.lon > end.lon ? start.lon : end.lon);
|
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 bounds = new OpenLayers.Bounds(left, bottom, right, top);
|
||||||
var zoom = this.getZoomForExtent(bounds);
|
var zoom = this.map.getZoomForExtent(bounds);
|
||||||
this.setCenter(new OpenLayers.LonLat(
|
this.map.setCenter(new OpenLayers.LonLat(
|
||||||
(start.lon + end.lon) / 2,
|
(start.lon + end.lon) / 2,
|
||||||
(start.lat + end.lat) / 2
|
(start.lat + end.lat) / 2
|
||||||
), zoom);
|
), zoom);
|
||||||
this.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
}
|
||||||
|
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
||||||
this.zoomBox = null;
|
this.zoomBox = null;
|
||||||
}
|
}
|
||||||
this.mouseDragStart = null;
|
this.mouseDragStart = null;
|
||||||
this.div.style.cursor = "default";
|
this.map.div.style.cursor = "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user