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. git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1338 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -60,6 +60,7 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||||
this.map.setCenter(newCenter, this.map.zoom + 1);
|
this.map.setCenter(newCenter, this.map.zoom + 1);
|
||||||
Event.stop(evt);
|
Event.stop(evt);
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,20 +125,24 @@ 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) {
|
||||||
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
|
||||||
var end = this.map.getLonLatFromViewPortPx( evt.xy );
|
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
|
||||||
var top = Math.max(start.lat, end.lat);
|
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
||||||
var bottom = Math.min(start.lat, end.lat);
|
var end = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||||
var left = Math.min(start.lon, end.lon);
|
var top = Math.max(start.lat, end.lat);
|
||||||
var right = Math.max(start.lon, end.lon);
|
var bottom = Math.min(start.lat, end.lat);
|
||||||
var bounds = new OpenLayers.Bounds(left, bottom, right, top);
|
var left = Math.min(start.lon, end.lon);
|
||||||
var zoom = this.map.getZoomForExtent(bounds);
|
var right = Math.max(start.lon, end.lon);
|
||||||
this.map.setCenter(new OpenLayers.LonLat(
|
var bounds = new OpenLayers.Bounds(left, bottom, right, top);
|
||||||
(start.lon + end.lon) / 2,
|
var zoom = this.map.getZoomForExtent(bounds);
|
||||||
(start.lat + end.lat) / 2
|
this.map.setCenter(new OpenLayers.LonLat(
|
||||||
), zoom);
|
(start.lon + end.lon) / 2,
|
||||||
|
(start.lat + end.lat) / 2
|
||||||
|
), zoom);
|
||||||
|
}
|
||||||
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
||||||
this.zoomBox = null;
|
this.zoomBox = null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.performedDrag) {
|
if (this.performedDrag) {
|
||||||
this.map.setCenter(this.map.center);
|
this.map.setCenter(this.map.center);
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
this.performedDrag = false;
|
this.performedDrag = false;
|
||||||
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||||
this.map.setCenter(newCenter, this.map.zoom + 2);
|
this.map.setCenter(newCenter, this.map.zoom + 2);
|
||||||
|
Event.stop(evt);
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,18 +240,25 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
if (!Event.isLeftClick(evt)) return;
|
if (!Event.isLeftClick(evt)) return;
|
||||||
switch (this.mode) {
|
switch (this.mode) {
|
||||||
case "zoombox":
|
case "zoombox":
|
||||||
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
console.log(this.mouseDragStart, evt.xy);
|
||||||
var end = this.map.getLonLatFromViewPortPx( evt.xy );
|
console.log(Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 || Math.abs((this.mouseDragStart.y - evt.xy.y)) > 5);
|
||||||
var top = Math.max(start.lat, end.lat);
|
console.log(Math.abs(this.mouseDragStart.x-evt.xy.x) > 5);
|
||||||
var bottom = Math.min(start.lat, end.lat);
|
console.log(Math.abs(this.mouseDragStart.y-evt.xy.y)>5);
|
||||||
var left = Math.min(start.lon, end.lon);
|
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
|
||||||
var right = Math.max(start.lon, end.lon);
|
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
|
||||||
var bounds = new OpenLayers.Bounds(left, bottom, right, top);
|
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
|
||||||
var zoom = this.map.getZoomForExtent(bounds);
|
var end = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||||
this.map.setCenter(new OpenLayers.LonLat(
|
var top = Math.max(start.lat, end.lat);
|
||||||
(start.lon + end.lon) / 2,
|
var bottom = Math.min(start.lat, end.lat);
|
||||||
(start.lat + end.lat) / 2
|
var left = Math.min(start.lon, end.lon);
|
||||||
), zoom);
|
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.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
|
||||||
this.zoomBox = null;
|
this.zoomBox = null;
|
||||||
this.leaveMode();
|
this.leaveMode();
|
||||||
|
|||||||
Reference in New Issue
Block a user