Change zoomBox function to be a 'zoom in' if the user draws a very small box.
In order to remove duplicate code, make MouseToolbar a subclass of MouseDefaults, and create zoomBoxEnd method. git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1356 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -125,24 +125,7 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
defaultMouseUp: function (evt) {
|
defaultMouseUp: function (evt) {
|
||||||
if (!Event.isLeftClick(evt)) return;
|
if (!Event.isLeftClick(evt)) return;
|
||||||
if (this.zoomBox) {
|
if (this.zoomBox) {
|
||||||
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
|
this.zoomBoxEnd(evt);
|
||||||
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
|
|
||||||
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
|
||||||
var end = this.map.getLonLatFromViewPortPx( 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;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.performedDrag) {
|
if (this.performedDrag) {
|
||||||
this.map.setCenter(this.map.center);
|
this.map.setCenter(this.map.center);
|
||||||
@@ -178,6 +161,35 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
this.map.zoomOut();
|
this.map.zoomOut();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** Zoombox function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
zoomBoxEnd: function(evt) {
|
||||||
|
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
|
||||||
|
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
|
||||||
|
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
||||||
|
var end = this.map.getLonLatFromViewPortPx( 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);
|
||||||
|
} else {
|
||||||
|
var end = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||||
|
this.map.setCenter(new OpenLayers.LonLat(
|
||||||
|
(end.lon),
|
||||||
|
(end.lat)
|
||||||
|
), this.map.getZoom() + 1);
|
||||||
|
}
|
||||||
|
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
||||||
|
this.zoomBox = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
|
* Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
|
||||||
|
|||||||
@@ -6,12 +6,14 @@
|
|||||||
* @class
|
* @class
|
||||||
*
|
*
|
||||||
* @requires OpenLayers/Control.js
|
* @requires OpenLayers/Control.js
|
||||||
|
* @requires OpenLayers/Control/MouseDefaults.js
|
||||||
*/
|
*/
|
||||||
OpenLayers.Control.MouseToolbar = Class.create();
|
OpenLayers.Control.MouseToolbar = Class.create();
|
||||||
OpenLayers.Control.MouseToolbar.X = 6;
|
OpenLayers.Control.MouseToolbar.X = 6;
|
||||||
OpenLayers.Control.MouseToolbar.Y = 300;
|
OpenLayers.Control.MouseToolbar.Y = 300;
|
||||||
OpenLayers.Control.MouseToolbar.prototype =
|
OpenLayers.Control.MouseToolbar.prototype =
|
||||||
Object.extend( new OpenLayers.Control(), {
|
Object.extend( new OpenLayers.Control(),
|
||||||
|
Object.extend( new OpenLayers.Control.MouseDefaults(), {
|
||||||
|
|
||||||
mode: null,
|
mode: null,
|
||||||
|
|
||||||
@@ -242,23 +244,7 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
if (!Event.isLeftClick(evt)) return;
|
if (!Event.isLeftClick(evt)) return;
|
||||||
switch (this.mode) {
|
switch (this.mode) {
|
||||||
case "zoombox":
|
case "zoombox":
|
||||||
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
|
this.zoomBoxEnd(evt);
|
||||||
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
|
|
||||||
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
|
||||||
var end = this.map.getLonLatFromViewPortPx( 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;
|
|
||||||
if (this.startViaKeyboard) this.leaveMode();
|
if (this.startViaKeyboard) this.leaveMode();
|
||||||
break;
|
break;
|
||||||
case "pan":
|
case "pan":
|
||||||
@@ -283,5 +269,5 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user