[Mapbender-commits] r7194 - in trunk/mapbender/http: plugins widgets
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Dec 9 10:37:34 EST 2010
Author: christoph
Date: 2010-12-09 07:37:34 -0800 (Thu, 09 Dec 2010)
New Revision: 7194
Modified:
trunk/mapbender/http/plugins/mb_measure_widget.js
trunk/mapbender/http/widgets/w_measure.js
Log:
bug fixes
Modified: trunk/mapbender/http/plugins/mb_measure_widget.js
===================================================================
--- trunk/mapbender/http/plugins/mb_measure_widget.js 2010-12-08 10:58:17 UTC (rev 7193)
+++ trunk/mapbender/http/plugins/mb_measure_widget.js 2010-12-09 15:37:34 UTC (rev 7194)
@@ -49,21 +49,23 @@
"<div>Aktuelle Koordinaten: <span class='mb-measure-current-point' /></div>" +
"<div>Distanz (zum letzten Punkt): <span class='mb-measure-distance-last' /> <span class='mb-measure-distance-last-unit' /></div>" +
"<div>Distanz (gesamt): <span class='mb-measure-distance-total' /> <span class='mb-measure-distance-total-unit' /></div>" +
+ "<div>Umring (gesamt): <span class='mb-measure-perimeter' /> <span class='mb-measure-perimeter-unit' /></div>" +
"<div>Fläche: <span class='mb-measure-area' /> <span class='mb-measure-area-unit' /></div>" +
"<a class='mb-measure-clear' href='#' title='Messung löschen'/>";
var hideMeasureData = function () {
measureDialog.find(".mb-measure-clicked-point").parent().hide();
-// measureDialog.find(".mb-measure-current-point").parent().hide();
+ measureDialog.find(".mb-measure-current-point").parent().hide();
measureDialog.find(".mb-measure-distance-last").parent().hide();
measureDialog.find(".mb-measure-distance-total").parent().hide();
+ measureDialog.find(".mb-measure-perimeter").parent().hide();
measureDialog.find(".mb-measure-area").parent().hide();
};
var changeDialogContent = function () {
measureDialog.html(informationHtml);
hideMeasureData();
- o.$target.unbind("mouseenter", changeDialogContent);
+ o.$target.unbind("click", changeDialogContent);
};
var create = function () {
@@ -93,107 +95,99 @@
});
};
- var updateCurrentPoint = function (evt, p) {
- measureDialog.find(".mb-measure-current-point").text(
- p.pos.x + " " + p.pos.y
- ).parent().show();
- };
-
- var updateClickedPoint = function (evt, p) {
- totalDistance = typeof totalDistance === "number" ? totalDistance + currentDistance : currentDistance;
-
- measureDialog.find(".mb-measure-clicked-point").text(
- p.pos.x + " " + p.pos.y
- ).parent().show();
- };
-
- var updateDistance = function (evt, dist) {
- if (typeof dist !== "number") {
- return;
+ var updateCurrentPoint = function (evt, data) {
+ if (data.pos) {
+ var p = data.pos;
+ measureDialog.find(".mb-measure-current-point").text(
+ p.pos.x + " " + p.pos.y
+ ).parent().show();
}
- var lastDistanceUnit = "m";
- currentDistance = dist;
- displayDistance = dist;
- if (displayDistance > 10000){
- displayDistance /= 1000;
- lastDistanceUnit = "km";
- }
- measureDialog.find(".mb-measure-distance-last-unit").html(lastDistanceUnit);
- measureDialog.find(".mb-measure-distance-last").text(Math.round(displayDistance*10)/10).parent().show();
-
- var totalDistanceUnit = "m";
- var displayTotalDistance = typeof totalDistance === "number" ? totalDistance + dist : dist;
- if (displayTotalDistance > 10000){
- displayTotalDistance = displayTotalDistance / 1000;
- totalDistanceUnit = "km";
- }
-
- measureDialog.find(".mb-measure-distance-total-unit").html(totalDistanceUnit);
- measureDialog.find(".mb-measure-distance-total").text(Math.round(displayTotalDistance*10)/10).parent().show();
};
- var updateArea = function (evt, area) {
- if (area === null) {
- return;
+ var updateClickedPoint = function (evt, data) {
+ if (data.pos) {
+ var p = data.pos;
+ measureDialog.find(".mb-measure-clicked-point").text(
+ p.pos.x + " " + p.pos.y
+ ).parent().show();
}
- var areaUnit = "m²";
- if (area > 10000000){
- area /= 1000000;
- areaUnit = "km²";
- }
- else if (area > 100000){
- area /= 10000;
- areaUnit = "ha";
- }
- area = Math.round(area*10)/10;
-
- measureDialog.find(".mb-measure-area-unit").html(areaUnit);
- measureDialog.find(".mb-measure-area").text(area).parent().show();
};
- var updateView = function (evt, data) {
- if (perimeter === null) {
- return;
- }
-
- if (data.distance) {
+ var updateCurrentDistance = function (evt, data) {
+ if (data.currentDistance) {
var lastDistanceUnit = "m";
- var displayDistance = data.distance;
+ var displayDistance = data.currentDistance;
if (displayDistance > 10000){
displayDistance /= 1000;
lastDistanceUnit = "km";
}
measureDialog.find(".mb-measure-distance-last-unit").html(lastDistanceUnit);
measureDialog.find(".mb-measure-distance-last").text(Math.round(displayDistance*10)/10).parent().show();
-
}
+ };
+ var updateTotalDistance = function (evt, data) {
if (data.totalDistance) {
var totalDistanceUnit = "m";
- var displayTotalDistance = typeof totalDistance === "number" ? totalDistance + dist : dist;
+ var displayTotalDistance = data.totalDistance;
if (displayTotalDistance > 10000){
displayTotalDistance = displayTotalDistance / 1000;
totalDistanceUnit = "km";
}
-
measureDialog.find(".mb-measure-distance-total-unit").html(totalDistanceUnit);
measureDialog.find(".mb-measure-distance-total").text(Math.round(displayTotalDistance*10)/10).parent().show();
}
};
+ var updatePerimeter = function (evt, data) {
+ if (data.perimeter) {
+ var unit = "m";
+ var displayPerimeter = data.perimeter;
+ if (displayPerimeter > 10000){
+ displayPerimeter = displayPerimeter / 1000;
+ totalDistanceUnit = "km";
+ }
+ measureDialog.find(".mb-measure-perimeter-unit").html(unit);
+ measureDialog.find(".mb-measure-perimeter").text(Math.round(displayPerimeter*10)/10).parent().show();
+
+ }
+ };
+
+ var updateArea = function (evt, data) {
+ if (data.area) {
+ var areaUnit = "m²";
+ var area = data.area;
+ if (area > 10000000){
+ area /= 1000000;
+ areaUnit = "km²";
+ }
+ else if (area > 100000){
+ area /= 10000;
+ areaUnit = "ha";
+ }
+ area = Math.round(area*10)/10;
+
+ measureDialog.find(".mb-measure-area-unit").html(areaUnit);
+ measureDialog.find(".mb-measure-area").text(area).parent().show();
+ }
+ };
+
+ var updateView = function (evt, data) {
+ updateCurrentPoint(evt, data);
+ updateCurrentDistance(evt, data);
+ updateTotalDistance(evt, data);
+ updateArea(evt, data);
+ updatePerimeter(evt, data);
+ };
+
this.activate = function () {
if (o.$target.size() > 0) {
o.$target
.mb_measure()
.bind("mb_measureupdate", updateView)
-/* .bind("mb_measurepointadded", updateClickedPoint)
- .bind("mb_measureonmeasure", updateCurrentPoint)
- .bind("mb_measureonmeasuredistance", updateDistance)
- .bind("mb_measureonmeasurearea", updateArea)
- .bind("mb_measureonmeasureperimeter", updatePerimeter)
- */
- .bind("mouseenter", changeDialogContent);
+ .bind("mb_measurepointadded", updateClickedPoint)
+ .bind("click", changeDialogContent);
}
measureDialog.dialog("open");
};
Modified: trunk/mapbender/http/widgets/w_measure.js
===================================================================
--- trunk/mapbender/http/widgets/w_measure.js 2010-12-08 10:58:17 UTC (rev 7193)
+++ trunk/mapbender/http/widgets/w_measure.js 2010-12-09 15:37:34 UTC (rev 7194)
@@ -92,15 +92,18 @@
if (this._measurePoints.length < 2) {
return null;
}
-
- var area = 0;
+ this._measurePoints.push(pos);
+ var part, area = 0;
var p0 = this._measurePoints[0].pos, pi, pj;
for (var i = 0; i < this._measurePoints.length - 1; i++) {
pi = this._measurePoints[i].pos;
pj = this._measurePoints[i + 1].pos;
- area += (pi.y + pj.y) * (pi.x - pj.x) / 2;
+ part = (pi.y + pj.y) * (pi.x - pj.x) / 2;
+ area += part;
}
- area += (p0.y + pj.y) * (p0.x - pj.x) / 2;
+ part = (pj.y + p0.y) * (pj.x - p0.x) / 2;
+ area += part;
+ this._measurePoints.pop();
return Math.abs(area);
},
_calculateAreaGeographic: function (pos) {
@@ -172,14 +175,6 @@
}
return null;
},
- _calculateTotalDistance: function () {
- for (var i = 0; i < count(this._measurePoints); i++) {
-
- }
- },
- _calculatePerimeter: function () {
-
- },
_isPointSnapped: function (p1, p2) {
return p1.dist(p2) <= this.options.measurePointDiameter/2;
},
@@ -276,59 +271,61 @@
line.toFront();
},
_measure: function (e) {
- if (this._srs !== this._map.getSrs()){
-// button.stop();
- return;
- }
-
var mousePos = this._map.getMousePosition(e);
-
-
var firstPointSnapped = this._isFirstPointSnapped(mousePos)
&& !this._polygonIsInvalid;
var lastPointSnapped = this._isLastPointSnapped(mousePos);
- var pos = {
- mousePos: mousePos,
- pos: firstPointSnapped ?
- this._measurePoints[0].pos : lastPointSnapped ?
- this._measurePoints[this._measurePoints.length - 1].pos :
- this._map.convertPixelToReal(mousePos)
- };
-
-
var measureData = {
- pos: pos
+ pos: {
+ mousePos: mousePos,
+ pos: firstPointSnapped ?
+ this._measurePoints[0].pos : lastPointSnapped ?
+ this._measurePoints[this._measurePoints.length - 1].pos :
+ this._map.convertPixelToReal(mousePos)
+ }
};
+ //
+ // calculate distance
+ //
var len = this._measurePoints.length;
var previousPoint = len > 0 ?
this._measurePoints[len - 1].pos : null;
this._currentDistance = this._calculateDistance(
previousPoint,
- pos.pos
+ measureData.pos.pos
);
+ //
+ // calculate total distance and perimeter
+ //
if (len > 0) {
measureData.currentDistance = this._currentDistance;
- measureData.totalDistance = this._measurePoints[len - 1].totalDistance + this._currentDistance;
+ this._totalDistance = this._currentDistance;
+ measureData.totalDistance = this._totalDistance ;
if (len > 1) {
+ this._totalDistance = this._measurePoints[len - 1].totalDistance + this._currentDistance;
+ measureData.totalDistance = this._totalDistance ;
measureData.perimeter = measureData.totalDistance + this._calculateDistance(
this._measurePoints[0].pos,
- pos.pos
+ measureData.pos.pos
);
}
}
- if (this._isPolygon(this._measurePoints, pos) && !this._polygonIsInvalid) {
- this._currentArea = this._calculateArea(pos);
+ //
+ // calculate area
+ //
+ if (this._isPolygon(this._measurePoints, measureData.pos) && !this._polygonIsInvalid) {
+ this._currentArea = this._calculateArea(measureData.pos);
measureData.area = this._currentArea;
}
this._trigger("update", null, measureData);
- this._draw(pos, {
+ this._draw(measureData.pos, {
highlightFirst: firstPointSnapped,
highlightLast: lastPointSnapped,
drawPoints: true
@@ -340,8 +337,6 @@
this._measurePoints.closedPolygon = false;
this._measurePoints.closedLine = false;
-// hideMeasureData();
-
this._polygonIsInvalid = false;
this._currentPolygonIsInvalid = false;
this._totalDistance = 0;
@@ -364,28 +359,29 @@
var len = this._measurePoints.length;
- var pos = {
- mousePos: mousePos,
- pos: this._map.convertPixelToReal(mousePos),
- distance: this._currentDistance,
- totalDistance: len > 0 ?
- this._measurePoints[len - 1].totalDistance + this._currentDistance :
- this._currentDistance
+ var data = {
+ pos: {
+ mousePos: mousePos,
+ pos: this._map.convertPixelToReal(mousePos)
+ }
};
-// this._trigger("pointadded", null, pos);
+ if (this._totalDistance) {
+ data.pos.totalDistance = this._totalDistance;
+ }
+ this._trigger("pointadded", e, data);
var firstPointSnapped = this._isFirstPointSnapped(mousePos);
var lastPointSnapped = this._isLastPointSnapped(mousePos);
- this._isPolygon(this._measurePoints, pos);
+ this._isPolygon(this._measurePoints, data.pos);
if (this._currentPolygonIsInvalid) {
this._polygonIsInvalid = true;
}
this._currentPolygonIsInvalid = false;
if (lastPointSnapped || firstPointSnapped) {
- this._draw(pos, {
+ this._draw(data.pos, {
highlightFirst: firstPointSnapped,
highlightLast: lastPointSnapped,
drawPoints: false
@@ -395,13 +391,13 @@
this._measurePoints.closedLine = lastPointSnapped;
}
else {
- this._measurePoints.push(pos);
+ this._measurePoints.push(data.pos);
this._totalDistance += this._currentDistance;
this._currentDistance = 0;
- lastPointSnapped = this._isLastPointSnapped(pos.mousePos);
- this._draw(pos, {
+ lastPointSnapped = this._isLastPointSnapped(mousePos);
+ this._draw(data.pos, {
highlightFirst: firstPointSnapped,
highlightLast: lastPointSnapped,
drawPoints: true
More information about the Mapbender_commits
mailing list