Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 136393864b | |||
| 5987d5ea33 | |||
| b5153746f6 | |||
| fb663b5127 | |||
| 1f9cb14069 | |||
| 6fe0826a54 | |||
| e61545167d | |||
| d564f2da47 | |||
| 5320cd290c | |||
| a50b175b66 | |||
| 739b821570 |
@@ -81,6 +81,7 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
this.zoomBox.style.backgroundColor = "white";
|
this.zoomBox.style.backgroundColor = "white";
|
||||||
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
|
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
|
||||||
this.zoomBox.style.opacity = "0.50";
|
this.zoomBox.style.opacity = "0.50";
|
||||||
|
this.zoomBox.style.fontSize = "1px";
|
||||||
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
||||||
this.map.viewPortDiv.appendChild(this.zoomBox);
|
this.map.viewPortDiv.appendChild(this.zoomBox);
|
||||||
}
|
}
|
||||||
@@ -96,8 +97,8 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
if (this.zoomBox) {
|
if (this.zoomBox) {
|
||||||
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 = Math.max(1, deltaX) + "px";
|
||||||
this.zoomBox.style.height = deltaY+"px";
|
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
|
||||||
if (evt.xy.x < this.mouseDragStart.x) {
|
if (evt.xy.x < this.mouseDragStart.x) {
|
||||||
this.zoomBox.style.left = evt.xy.x+"px";
|
this.zoomBox.style.left = evt.xy.x+"px";
|
||||||
}
|
}
|
||||||
@@ -125,24 +126,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 +162,37 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
this.map.zoomOut();
|
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/
|
* 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,
|
||||||
|
|
||||||
@@ -126,8 +128,10 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
this.zoomBox.style.backgroundColor = "white";
|
this.zoomBox.style.backgroundColor = "white";
|
||||||
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
|
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
|
||||||
this.zoomBox.style.opacity = "0.50";
|
this.zoomBox.style.opacity = "0.50";
|
||||||
|
this.zoomBox.style.fontSize = "1px";
|
||||||
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
||||||
this.map.viewPortDiv.appendChild(this.zoomBox);
|
this.map.viewPortDiv.appendChild(this.zoomBox);
|
||||||
|
this.performedDrag = true;
|
||||||
break;
|
break;
|
||||||
case "measure":
|
case "measure":
|
||||||
var distance = "";
|
var distance = "";
|
||||||
@@ -180,7 +184,7 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
|
|
||||||
switchModeTo: function(mode) {
|
switchModeTo: function(mode) {
|
||||||
if (mode != this.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);
|
OpenLayers.Util.modifyAlphaImageDiv(this.buttons[this.mode], null, null, null, this.buttons[this.mode].imgLocation);
|
||||||
}
|
}
|
||||||
if (this.mode == "measure" && mode != "measure") {
|
if (this.mode == "measure" && mode != "measure") {
|
||||||
@@ -193,7 +197,9 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
this.measureStart = null;
|
this.measureStart = null;
|
||||||
}
|
}
|
||||||
this.mode = mode;
|
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":
|
case "zoombox":
|
||||||
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 = Math.max(1, deltaX) + "px";
|
||||||
this.zoomBox.style.height = deltaY+"px";
|
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
|
||||||
if (evt.xy.x < this.mouseDragStart.x) {
|
if (evt.xy.x < this.mouseDragStart.x) {
|
||||||
this.zoomBox.style.left = evt.xy.x+"px";
|
this.zoomBox.style.left = evt.xy.x+"px";
|
||||||
}
|
}
|
||||||
@@ -240,24 +246,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;
|
|
||||||
console.log(this.startViaKeyboard);
|
|
||||||
if (this.startViaKeyboard) this.leaveMode();
|
if (this.startViaKeyboard) this.leaveMode();
|
||||||
break;
|
break;
|
||||||
case "pan":
|
case "pan":
|
||||||
@@ -282,5 +271,5 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -184,8 +184,8 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
this.slider.style.top = newTop+"px";
|
this.slider.style.top = newTop+"px";
|
||||||
}
|
}
|
||||||
this.mouseDragStart = evt.xy.clone();
|
this.mouseDragStart = evt.xy.clone();
|
||||||
|
Event.stop(evt);
|
||||||
}
|
}
|
||||||
Event.stop(evt);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -371,9 +371,12 @@ OpenLayers.Map.prototype = {
|
|||||||
if (center != null) {
|
if (center != null) {
|
||||||
var zoom = this.getZoom();
|
var zoom = this.getZoom();
|
||||||
this.zoom = null;
|
this.zoom = null;
|
||||||
|
if (zoom > this.baseLayer.numZoomLevels - 1) {
|
||||||
|
zoom = this.baseLayer.numZoomLevels - 1;
|
||||||
|
}
|
||||||
this.setCenter(center, zoom);
|
this.setCenter(center, zoom);
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
if ((noEvent == null) || (noEvent == false)) {
|
if ((noEvent == null) || (noEvent == false)) {
|
||||||
this.events.triggerEvent("changebaselayer");
|
this.events.triggerEvent("changebaselayer");
|
||||||
}
|
}
|
||||||
@@ -562,7 +565,6 @@ OpenLayers.Map.prototype = {
|
|||||||
* trigger movestart/end events
|
* trigger movestart/end events
|
||||||
*/
|
*/
|
||||||
setCenter: function (lonlat, zoom, minor) {
|
setCenter: function (lonlat, zoom, minor) {
|
||||||
|
|
||||||
var zoomChanged = (this.isValidZoomLevel(zoom)) &&
|
var zoomChanged = (this.isValidZoomLevel(zoom)) &&
|
||||||
(zoom != this.getZoom());
|
(zoom != this.getZoom());
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<li>test_Tile.html</li>
|
<li>test_Tile.html</li>
|
||||||
<li>test_Tile_Image.html</li>
|
<li>test_Tile_Image.html</li>
|
||||||
<li>test_Control.html</li>
|
<li>test_Control.html</li>
|
||||||
|
<li>test_Control_MouseToolbar.html</li>
|
||||||
<li>test_Control_LayerSwitcher.html</li>
|
<li>test_Control_LayerSwitcher.html</li>
|
||||||
<li>test_Control_PanZoom.html</li>
|
<li>test_Control_PanZoom.html</li>
|
||||||
<li>test_Control_PanZoomBar.html</li>
|
<li>test_Control_PanZoomBar.html</li>
|
||||||
|
|||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user