Add support for distance measuring. Do more catching errors and the like. Move icons to be vertical, below panzoombar -- this is not yet configurable, but needs to be.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@555 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-06-08 03:38:02 +00:00
parent bacb0a917c
commit 9ebfa46552

View File

@@ -16,6 +16,7 @@ OpenLayers.Control.MouseToolbar.prototype =
if (direction) {
this.direction = direction;
}
this.measureDivs = [];
},
draw: function() {
@@ -27,10 +28,14 @@ OpenLayers.Control.MouseToolbar.prototype =
this.map.events.register( "mousemove", this, this.defaultMouseMove );
this.map.events.register( "mouseout", this, this.defaultMouseOut );
var sz = new OpenLayers.Size(28,28);
var centered = new OpenLayers.Pixel(100, 20);
var centered = new OpenLayers.Pixel(12, 300);
this._addButton("zoombox", "drag-rectangle-off.png", "drag-rectangle-on.png", centered, sz);
this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", new OpenLayers.Pixel(100,47), sz);
this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", new OpenLayers.Pixel(12,328), sz);
this._addButton("measure", "measuring-stick-off.png", "measuring-stick-on.png", new OpenLayers.Pixel(12,356), sz);
this.switchModeTo("pan");
this.map.events.register("zoomend", this, function() { this.switchModeTo("pan"); });
return this.div;
},
_addButton:function(id, img, activeImg, xy, sz) {
@@ -70,6 +75,7 @@ OpenLayers.Control.MouseToolbar.prototype =
* @param {Event} evt
*/
defaultDblClick: function (evt) {
this.switchModeTo("pan");
var newCenter = this.map.getLonLatFromScreenPx( evt.xy );
this.map.setCenter(newCenter, this.map.zoom + 2);
},
@@ -103,6 +109,44 @@ OpenLayers.Control.MouseToolbar.prototype =
this.map.viewPortDiv.appendChild(this.zoomBox);
break;
case "measure":
var distance = "";
if (this.measureStart) {
measureEnd = this.map.getLonLatFromScreenPx(this.mouseDragStart);
distance = OpenLayers.Util.distVincenty(this.measureStart, measureEnd);
distance = Math.round(distance * 100) / 100;
distance = distance + "km";
this.measureStartBox = this.measureBox;
}
this.measureStart = this.map.getLonLatFromScreenPx(this.mouseDragStart);;
this.measureBox = OpenLayers.Util.createDiv(null,
this.mouseDragStart.add(
-2-parseInt(this.map.layerContainerDiv.style.left),
-2-parseInt(this.map.layerContainerDiv.style.top)),
null,
null,
"absolute");
this.measureBox.style.width="4px";
this.measureBox.style.height="4px";
this.measureBox.style.backgroundColor="red";
this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
this.map.layerContainerDiv.appendChild(this.measureBox);
if (distance) {
this.measureBoxDistance = OpenLayers.Util.createDiv(null,
this.mouseDragStart.add(
-2-parseInt(this.map.layerContainerDiv.style.left),
2-parseInt(this.map.layerContainerDiv.style.top)),
null,
null,
"absolute");
this.measureBoxDistance.innerHTML = distance;
this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
this.map.layerContainerDiv.appendChild(this.measureBoxDistance);
this.measureDivs.append(this.measureBoxDistance);
}
this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
this.map.layerContainerDiv.appendChild(this.measureBox);
this.measureDivs.append(this.measureBox);
break;
default:
this.map.div.style.cursor = "move";
@@ -113,19 +157,25 @@ OpenLayers.Control.MouseToolbar.prototype =
switchModeTo: function(mode) {
if (mode != this.mode) {
if (this.mode) {
this.buttons[this.mode].firstChild.src = this.buttons[this.mode].imgLocation;
}
if (this.mode == "measure" && mode != "measure") {
for(var i = 0; i < this.measureDivs.length; i++) {
if (this.measureDivs[i]) {
this.map.layerContainerDiv.removeChild(this.measureDivs[i]);
}
}
this.measureDivs = [];
this.measureStart = null;
}
this.mode = mode;
this.buttons[mode].firstChild.src = this.buttons[mode].activeImgLocation;
} else {
this.leaveMode();
}
}
},
leaveMode: function() {
var oldMode = this.mode;
this.mode = null;
if (oldMode) {
this.buttons[oldMode].firstChild.src = this.buttons[oldMode].imgLocation;
}
this.switchModeTo("pan");
},
/**
@@ -179,11 +229,9 @@ OpenLayers.Control.MouseToolbar.prototype =
), zoom);
this.map.viewPortDiv.removeChild(document.getElementById("zoomBox"));
this.zoomBox = null;
this.leaveMode();
break;
}
if (this.mouseDragStart) {
this.leaveMode();
}
this.mouseDragStart = null;
this.map.div.style.cursor = "default";
},