Compare commits

...

12 Commits

Author SHA1 Message Date
crschmidt
48445f0878 And I said "Ship it, or I will want to kill the next reporter of an IE bug".
And so it was done.


git-svn-id: http://svn.openlayers.org/tags/openlayers/release-2.0@1368 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-25 17:55:07 +00:00
crschmidt
a0cd93cb41 Document restriction on when to add permalink control.
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1367 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-25 11:55:45 +00:00
crschmidt
0a01ef899e Commit r1365 against 2.0, rather than sandbox.
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1366 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-25 02:08:20 +00:00
crschmidt
5987d5ea33 (continuation of r1359) -- tschaub points out that zoomBox and measureBox
are not the same thing, and also points out that he's already fixed the 
problem in a different and better way. Add in half of his patch, and keep
the other on the back burner until I can review post 2.0 and see how much
of this code needs a rewrite anyway.


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1360 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 15:20:48 +00:00
crschmidt
b5153746f6 git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1359 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf 2006-08-24 15:19:18 +00:00
crschmidt
fb663b5127 If we turn on the zooming tool, then click on the panzoombar in IE,
because the click drops through (Why god Why?!) we get an error telling
us that evt.xy doesn't exist, so we wrap it in an if statement which
protects us. (Deliver us, o if statement, from IEvil...) 


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1358 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 15:07:18 +00:00
crschmidt
1f9cb14069 When you click and don't drag, we zoom in, but we want to set performedDrag,
since that's how we ensure that we don't fire click.


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1357 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 14:52:39 +00:00
crschmidt
6fe0826a54 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
2006-08-24 14:21:45 +00:00
crschmidt
e61545167d Map should change zoom level to maximum for the baseLayer when the baseLayer
changes, rather than trying to set it to 17, which will fail, and leave the 
zoom level as null, and then everything explodes. Thanks to Heidi Fox at MC
for this report.


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1355 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 14:08:18 +00:00
crschmidt
d564f2da47 Add tests for MouseToolbar. This is relatively minimal compared to what
really should be done, but this will catch the problems encountered in RC3
automatically if the tests are run in IE. 


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1354 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 13:35:55 +00:00
crschmidt
5320cd290c Dragging stopped by Event.stop call when it shouldn't have been -- no
need for this. Only stop event if mousedown started in zoombar. 


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1353 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 05:59:12 +00:00
crschmidt
a50b175b66 Because we've removed the ruler button, its image no longer needs changing
when we change modes to/from that mode. Remember that.


git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1352 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-24 05:49:02 +00:00
7 changed files with 112 additions and 49 deletions

View File

@@ -1,6 +1,6 @@
OpenLayers.Control.Permalink
A small control which updates a "Permalink" to the map every time the viewport changes. This allows users to copy a link to a specfic map view. By default, it places itself in the lower right corner of the map,
A small control which updates a "Permalink" to the map every time the viewport changes. This allows users to copy a link to a specfic map view. By default, it places itself in the lower right corner of the map. This control must be added to the map after a baselayer has been set.
* Constructor
OpenLayers.Control.Scale({DOMElement|element}?, {String|base}) -- Creates a new permalink control. The DOMElement is used, if passed, as the element on which the 'href' is set. If you prefer to put this link on an element outside of the map, set this element to an anchor element to have its href updated when the map moves. If you wish to make the link go to some other URL (for example, an editing interface rather than the current URL), the 'base' property can be used, to which the ?lat=&lon=&zoom= will be appended after the map has moved.

View File

@@ -81,6 +81,7 @@ OpenLayers.Control.MouseDefaults.prototype =
this.zoomBox.style.backgroundColor = "white";
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
this.zoomBox.style.opacity = "0.50";
this.zoomBox.style.fontSize = "1px";
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
this.map.viewPortDiv.appendChild(this.zoomBox);
}
@@ -96,8 +97,8 @@ OpenLayers.Control.MouseDefaults.prototype =
if (this.zoomBox) {
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";
this.zoomBox.style.height = deltaY+"px";
this.zoomBox.style.width = Math.max(1, deltaX) + "px";
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
if (evt.xy.x < this.mouseDragStart.x) {
this.zoomBox.style.left = evt.xy.x+"px";
}
@@ -125,24 +126,7 @@ OpenLayers.Control.MouseDefaults.prototype =
defaultMouseUp: function (evt) {
if (!Event.isLeftClick(evt)) return;
if (this.zoomBox) {
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);
}
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
this.zoomBox = null;
this.zoomBoxEnd(evt);
} else {
if (this.performedDrag) {
this.map.setCenter(this.map.center);
@@ -178,6 +162,37 @@ OpenLayers.Control.MouseDefaults.prototype =
this.map.zoomOut();
},
/** Zoombox function.
*
*/
zoomBoxEnd: function(evt) {
if (this.mouseDragStart != null) {
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/
@@ -194,7 +209,7 @@ OpenLayers.Control.MouseDefaults.prototype =
var inMap = false;
var elem = Event.element(e);
while(elem != null) {
if (elem == this.map.div) {
if (this.map && elem == this.map.div) {
inMap = true;
break;
}

View File

@@ -6,12 +6,14 @@
* @class
*
* @requires OpenLayers/Control.js
* @requires OpenLayers/Control/MouseDefaults.js
*/
OpenLayers.Control.MouseToolbar = Class.create();
OpenLayers.Control.MouseToolbar.X = 6;
OpenLayers.Control.MouseToolbar.Y = 300;
OpenLayers.Control.MouseToolbar.prototype =
Object.extend( new OpenLayers.Control(), {
Object.extend( new OpenLayers.Control(),
Object.extend( new OpenLayers.Control.MouseDefaults(), {
mode: null,
@@ -126,8 +128,10 @@ OpenLayers.Control.MouseToolbar.prototype =
this.zoomBox.style.backgroundColor = "white";
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
this.zoomBox.style.opacity = "0.50";
this.zoomBox.style.fontSize = "1px";
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
this.map.viewPortDiv.appendChild(this.zoomBox);
this.performedDrag = true;
break;
case "measure":
var distance = "";
@@ -180,7 +184,7 @@ OpenLayers.Control.MouseToolbar.prototype =
switchModeTo: function(mode) {
if (mode != this.mode) {
if (this.mode) {
if (this.mode && this.buttons[this.mode]) {
OpenLayers.Util.modifyAlphaImageDiv(this.buttons[this.mode], null, null, null, this.buttons[this.mode].imgLocation);
}
if (this.mode == "measure" && mode != "measure") {
@@ -193,7 +197,9 @@ OpenLayers.Control.MouseToolbar.prototype =
this.measureStart = null;
}
this.mode = mode;
OpenLayers.Util.modifyAlphaImageDiv(this.buttons[mode], null, null, null, this.buttons[mode].activeImgLocation);
if (this.buttons[mode]) {
OpenLayers.Util.modifyAlphaImageDiv(this.buttons[mode], null, null, null, this.buttons[mode].activeImgLocation);
}
}
},
@@ -210,8 +216,8 @@ OpenLayers.Control.MouseToolbar.prototype =
case "zoombox":
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";
this.zoomBox.style.height = deltaY+"px";
this.zoomBox.style.width = Math.max(1, deltaX) + "px";
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
if (evt.xy.x < this.mouseDragStart.x) {
this.zoomBox.style.left = evt.xy.x+"px";
}
@@ -240,23 +246,7 @@ OpenLayers.Control.MouseToolbar.prototype =
if (!Event.isLeftClick(evt)) return;
switch (this.mode) {
case "zoombox":
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);
}
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
this.zoomBox = null;
this.zoomBoxEnd(evt);
if (this.startViaKeyboard) this.leaveMode();
break;
case "pan":
@@ -281,5 +271,5 @@ OpenLayers.Control.MouseToolbar.prototype =
return false;
}
}
});
}));

View File

@@ -184,8 +184,8 @@ OpenLayers.Control.PanZoomBar.prototype =
this.slider.style.top = newTop+"px";
}
this.mouseDragStart = evt.xy.clone();
Event.stop(evt);
}
Event.stop(evt);
},
/*

View File

@@ -371,9 +371,12 @@ OpenLayers.Map.prototype = {
if (center != null) {
var zoom = this.getZoom();
this.zoom = null;
if (zoom > this.baseLayer.numZoomLevels - 1) {
zoom = this.baseLayer.numZoomLevels - 1;
}
this.setCenter(center, zoom);
}
if ((noEvent == null) || (noEvent == false)) {
this.events.triggerEvent("changebaselayer");
}
@@ -562,7 +565,6 @@ OpenLayers.Map.prototype = {
* trigger movestart/end events
*/
setCenter: function (lonlat, zoom, minor) {
var zoomChanged = (this.isValidZoomLevel(zoom)) &&
(zoom != this.getZoom());
@@ -599,7 +601,7 @@ OpenLayers.Map.prototype = {
this.popups[i].updatePosition();
}
}
//send the move call to the baselayer and all the overlays
var bounds = this.getExtent();
for (var i = 0; i < this.layers.length; i++) {

View File

@@ -22,6 +22,7 @@
<li>test_Tile.html</li>
<li>test_Tile_Image.html</li>
<li>test_Control.html</li>
<li>test_Control_MouseToolbar.html</li>
<li>test_Control_LayerSwitcher.html</li>
<li>test_Control_PanZoom.html</li>
<li>test_Control_PanZoomBar.html</li>

View File

@@ -0,0 +1,55 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var map;
function test_01_Control_MouseToolbar_constructor (t) {
t.plan( 1 );
control = new OpenLayers.Control.MouseToolbar();
t.ok( control instanceof OpenLayers.Control.MouseToolbar, "new OpenLayers.Control.MouseToolbar returns object" );
}
function test_02_Control_MouseToolbar_addControl (t) {
t.plan( 7 );
map = new OpenLayers.Map('map');
control = new OpenLayers.Control.MouseToolbar();
t.ok( control instanceof OpenLayers.Control.MouseToolbar, "new OpenLayers.Control.MouseToolbar returns object" );
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
map.addControl(control);
t.ok( control.map === map, "Control.map is set to the map object" );
t.ok( map.controls[2] === control, "map.controls contains control" );
t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Control div zIndexed properly" );
t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Viewport div contains control div" );
t.eq( control.div.style.top, "6px", "Control div top located correctly by default");
}
function test_03_Control_MouseToolbar_control_events (t) {
t.plan( 1 );
var evt = {which: 1}; // control expects left-click
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.MouseToolbar();
map.addControl(control);
var centerLL = new OpenLayers.LonLat(0,0);
map.setCenter(centerLL, 5);
evt.shiftKey = true;
evt.xy = new OpenLayers.Size(5,5);
control.defaultMouseDown(evt);
evt.xy = new OpenLayers.Size(15,15);
control.defaultMouseUp(evt);
t.eq(map.getZoom(), 5, "Map zoom set correctly after zoombox");
}
// -->
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>