[Mapbender-commits] r4890 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Oct 30 07:36:31 EDT 2009
Author: christoph
Date: 2009-10-30 07:36:31 -0400 (Fri, 30 Oct 2009)
New Revision: 4890
Modified:
trunk/mapbender/http/javascripts/mod_digitize_tab.php
Log:
Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php 2009-10-30 11:36:00 UTC (rev 4889)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php 2009-10-30 11:36:31 UTC (rev 4890)
@@ -74,6 +74,63 @@
var mapDomElement;
var mapType = "";
+var DigitizeHistory = function () {
+ var historyItemArray = [];
+ var currentIndex = 0;
+
+ this.addItem = function (obj) {
+ if (typeof obj == "object"
+ && obj.back && typeof obj.back === "function"
+ && obj.forward && typeof obj.forward === "function"
+ ) {
+ for (var i = currentIndex; i < historyItemArray.length; i++) {
+ delete historyItemArray[i];
+ }
+ historyItemArray.length = currentIndex;
+ historyItemArray.push({
+ back: obj.back,
+ forward: obj.forward
+ });
+ return true;
+ }
+ return false;
+ };
+
+ this.back = function () {
+// console.log("HistoryItems: %s", historyItemArray);
+ if (currentIndex > 0) {
+ currentIndex --;
+ historyItemArray[currentIndex].back();
+// console.log("B-----");
+// console.log(s);
+// console.log("EXECUTING %s", historyItemArray[currentIndex].back);
+// console.log("GeomArray (post): %s", d);
+// console.log("Index: %s", currentIndex);
+ executeDigitizeSubFunctions();
+ return true;
+ }
+ return false;
+ };
+
+ this.forward = function () {
+// console.log("HistoryItems: %s", historyItemArray);
+ if (currentIndex < historyItemArray.length) {
+ historyItemArray[currentIndex].forward();
+// console.log("F-----");
+// console.log("EXECUTING %s", historyItemArray[currentIndex].forward);
+// console.log("GeomArray (post): %s", d);
+// console.log(s);
+ currentIndex ++;
+// console.log("Index: %s", currentIndex);
+ executeDigitizeSubFunctions();
+ return true;
+ }
+ return false;
+ };
+};
+
+var digitizeHistory = new DigitizeHistory();
+
parent.eventInit.register(function () {
var mapIndex = parent.getMapObjIndexByName(mod_digitize_target);
mapDomElement = parent.mb_mapObj[mapIndex].getDomElement();
@@ -89,6 +146,9 @@
}
eventCloseGeometry = new parent.Mapbender.Event();
+ eventCloseGeometry.register(function () {
+ d.close();
+ });
if (openMetadataEditorAfterNewGeometryHasBeenCreated) {
eventCloseGeometry.register(function (obj) {
if (typeof obj !== "object") {
@@ -119,9 +179,9 @@
var mod_digitizeEvent = false;
var nonTransactionalHighlight;
-var button_point = "Point";
-var button_line = "Line";
-var button_polygon = "Polygon";
+var button_point;
+var button_line;
+var button_polygon;
var button_move = "dragBasePoint";
var button_insert = "setBasePoint";
var button_delete = "delBasePoint";
@@ -150,6 +210,10 @@
var featuresMustHaveUniqueId = false;
}
+if (typeof allowUndoPolygonBySnapping === "undefined") {
+ var allowUndoPolygonBySnapping = false;
+}
+
if (typeof openMetadataEditorAfterNewGeometryHasBeenCreated === "undefined") {
var openMetadataEditorAfterNewGeometryHasBeenCreated = false;
}
@@ -224,6 +288,9 @@
Geometry = parent.Geometry;
Point = parent.Point;
geomType = parent.geomType;
+ button_point = parent.geomType.point; //"Point";
+ button_line = parent.geomType.line; //"Line";
+ button_polygon = parent.geomType.polygon; //"Polygon";
}
/**
@@ -261,15 +328,8 @@
if (e) {
// track mouse position
var currentPos = getMousePosition(e);
-
s.check(currentPos);
}
- else {
-// s.clean();
- }
-
- var el = mapDomElement;
- el.onmousedown = mod_digitize_start;
}
function mod_digitize_timeout(){
@@ -279,16 +339,54 @@
el.onmousemove = null;
}
+var isLastLinePointSnapped = function (newPoint) {
+ return d.get(-1).geomType === parent.geomType.line
+ && d.getGeometry(-1,-1).count() > 1
+ && d.getGeometry(-1,-1).get(-1).equals(newPoint);
+};
+
+var innerPointSnapped = function (newPoint) {
+ if (d.count() === 0) {
+ return null;
+ }
+ var start = 1;
+ if (d.getGeometry(-1, -1).count() < 3) {
+ start = 0;
+ }
+ for (var i = start; i < d.getGeometry(-1, -1).count(); i++) {
+ if (d.getGeometry(-1,-1).get(i).equals(newPoint)) {
+ return i;
+ }
+ }
+ return null;
+};
+
+var isFirstPolygonPointSnapped = function (newPoint) {
+ return d.get(-1).geomType == parent.geomType.polygon
+ && d.getGeometry(-1,-1).count() >= 3
+ && d.getGeometry(-1,-1).get(0).equals(newPoint);
+};
+
+var editingPolygonAndThreePointsHaveBeenInserted = function () {
+ return d.get(-1).geomType == parent.geomType.polygon && d.getGeometry(-1,-1).count() == 2;
+};
+
+var editingLineAndTwoPointsHaveBeenInserted = function () {
+ return d.get(-1).geomType == parent.geomType.line && d.getGeometry(-1,-1).count() >= 1;
+};
+
function mod_digitize_start(e){
- // check if a proper geometry is selected
- if (d.getGeometry(-1,-1).isComplete() || d.count() == 0){
-
- if (mod_digitizeEvent != false) {
- alert(msgObj.errorMessageNoGeometrySelected);
- }
+ if (mod_digitizeEvent !== button_point
+ && mod_digitizeEvent !== button_line
+ && mod_digitizeEvent !== button_polygon) {
+
+ alert(msgObj.errorMessageNoGeometrySelected);
return false;
}
+ //
+ // get the last point the user digitized
+ //
var realWorldPos;
if (s.isSnapped()) {
realWorldPos = s.getSnappedPoint();
@@ -298,59 +396,150 @@
var currentPos = getMousePosition(e);
realWorldPos = parent.mapToReal(mod_digitize_target,currentPos);
}
-
- if (d.get(-1).geomType == parent.geomType.polygon && d.getGeometry(-1,-1).count() > 1 && d.getGeometry(-1,-1).get(0).equals(realWorldPos)) {
-
- // close the polygon
- d.close();
- eventCloseGeometry.trigger({
- index: d.count() - 1,
- geometry: d.get(-1)
- });
- parent.mb_disableThisButton(button_polygon);
- return true;
- }
- else if (d.get(-1).geomType == parent.geomType.line && d.getGeometry(-1,-1).count() > 1 && d.getGeometry(-1,-1).get(-1).equals(realWorldPos)) {
- // close the line
- d.close();
- eventCloseGeometry.trigger({
- index: d.count() - 1,
- geometry: d.get(-1)
- });
- parent.mb_disableThisButton(button_line);
- return true;
- }
- else {
- // set the calculated real world position as point of the geometry
- d.getGeometry(-1,-1).addPoint(realWorldPos);
- var mapIndex = parent.getMapObjIndexByName(mod_digitize_target);
- d.getGeometry(-1,-1).setEpsg(parent.mb_mapObj[mapIndex].epsg);
-
- if(d.get(-1).geomType == parent.geomType.point){
- d.close();
- eventCloseGeometry.trigger({
- index: d.count() - 1,
- geometry: d.get(-1)
+ (function () {
+ var geometryType = mod_digitizeEvent;
+ var currentPoint = realWorldPos;
+ var currentEpsg = parent.mb_mapObj[parent.getMapObjIndexByName(mod_digitize_target)].epsg;
+
+ //
+ // A new geometry has to be created
+ //
+ if (d.count() === 0 || (d.get(-1).count()> 0 && d.getGeometry(-1, -1).isComplete())) {
+
+ digitizeHistory.addItem({
+ // remove the entire multigeometry
+ back: function () {
+ s.removePoint(d.getPoint(-1, -1, -1));
+ d.del(-1);
+ },
+ // add the multigeometry to the geometry array
+ forward: function () {
+ parent.mb_enableButton(geometryType);
+ d.addMember(geometryType);
+ d.get(-1).addGeometry();
+ d.getGeometry(-1,-1).setEpsg(currentEpsg);
+ d.getGeometry(-1,-1).addPoint(realWorldPos);
+ if (geometryType == parent.geomType.point){
+ eventCloseGeometry.trigger({
+ index: d.count() - 1,
+ geometry: d.get(-1)
+ });
+ parent.mb_disableThisButton(geometryType);
+ }
+ else {
+ s.add(d.getPoint(-1, -1, -1));
+ }
+ }
});
- parent.mb_disableThisButton(button_point);
- return true;
}
-
- // add first point of polygon to snapping list (if three points have been inserted).
- else if (d.get(-1).geomType == parent.geomType.polygon && d.getGeometry(-1,-1).count() == 3) {
- s.add(d.getPoint(-1, -1, 0));
+ //
+ // a point is added to an existing multigeometry
+ //
+ else {
+ var innerPointIndex = innerPointSnapped(realWorldPos);
+ //
+ // editing polygon and first point is snapped -> close polygon
+ //
+ if (isFirstPolygonPointSnapped(realWorldPos)) {
+
+ digitizeHistory.addItem({
+ back: function () {
+ d.getGeometry(-1, -1).reopen();
+ parent.mb_enableButton(d.get(-1).geomType);
+ // activate button
+ },
+ forward: function () {
+ // close the polygon
+ eventCloseGeometry.trigger({
+ index: d.count() - 1,
+ geometry: d.get(-1)
+ });
+ parent.mb_disableThisButton(button_polygon);
+ }
+ });
+ }
+ //
+ // editing line and last point is snapped -> close line
+ //
+ else if (isLastLinePointSnapped(realWorldPos)) {
+ digitizeHistory.addItem({
+ back: function () {
+ d.getGeometry(-1, -1).reopen();
+ parent.mb_enableButton(d.get(-1).geomType);
+ },
+ forward: function () {
+ // close the polygon
+ eventCloseGeometry.trigger({
+ index: d.count() - 1,
+ geometry: d.get(-1)
+ });
+ parent.mb_disableThisButton(button_line);
+ }
+ });
+ }
+ //
+ // another point is snapped (undo)
+ //
+ else if (innerPointIndex !== null && allowUndoPolygonBySnapping) {
+ while (d.getGeometry(-1, -1).count() > innerPointIndex) {
+ digitizeHistory.back();
+ }
+ // avoids the forward!
+ return;
+ }
+ //
+ // just add the point
+ //
+ else {
+ if (editingPolygonAndThreePointsHaveBeenInserted()) {
+ digitizeHistory.addItem({
+ back: function () {
+// s.removePoint(d.getPoint(-1, -1, 0));
+ s.removePoint(d.getPoint(-1, -1, -1));
+ d.getGeometry(-1, -1).del(-1);
+ },
+ forward: function () {
+ d.getGeometry(-1,-1).addPoint(realWorldPos);
+ s.add(d.getPoint(-1, -1, -1));
+// s.add(d.getPoint(-1, -1, 0));
+ }
+ });
+ }
+ else if (editingLineAndTwoPointsHaveBeenInserted()) {
+ digitizeHistory.addItem({
+ back: function () {
+ s.removePoint(d.getPoint(-1, -1, -1));
+ d.getGeometry(-1, -1).del(-1);
+ },
+ forward: function () {
+ d.getGeometry(-1,-1).addPoint(realWorldPos);
+ s.add(d.getPoint(-1, -1, -1));
+ }
+ });
+ }
+ else {
+ digitizeHistory.addItem({
+ back: function () {
+ s.removePoint(d.getPoint(-1, -1, -1));
+ d.getGeometry(-1, -1).del(-1);
+ },
+ forward: function () {
+ d.getGeometry(-1,-1).addPoint(realWorldPos);
+ s.add(d.getPoint(-1, -1, -1));
+ }
+ });
+ }
+ }
}
+ digitizeHistory.forward();
+ })();
- // add last point of line to snapping list (if at least two points have been inserted).
- else if (d.get(-1).geomType == parent.geomType.line && d.getGeometry(-1,-1).count() >= 2) {
- if (mod_digitizeEvent != button_move) {
- s.store(d);
- }
- s.add(d.getPoint(-1, -1, -1));
- }
- }
- executeDigitizeSubFunctions();
+
+// if (mod_digitizeEvent != button_move) {
+// s.store(d);
+// }
+
return true;
}
// --- polygon, line, point insertion (begin) ----------------------------------------------------------------------------------------------
@@ -697,7 +886,7 @@
var currentStatus = buttonDig_id[i].status;
var currentTitle = "";
switch (buttonDig_id[i]) {
- case "Point":
+ case "point":
if (currentStatus == 1) {
currentTitle = msgObj.buttonLabelPointOn;
}
@@ -705,7 +894,7 @@
currentTitle = msgObj.buttonLabelPointOff;
}
break;
- case "Line":
+ case "line":
if (currentStatus == 1) {
currentTitle = msgObj.buttonLabelLineOn;
}
@@ -713,7 +902,7 @@
currentTitle = msgObj.buttonLabelLineOff;
}
break;
- case "Polygon":
+ case "polygon":
if (currentStatus == 1) {
currentTitle = msgObj.buttonLabelPolygonOn;
}
@@ -809,113 +998,75 @@
var el = mapDomElement;
el.onmousemove = mod_digitize_go;
+ el.onmousedown = mod_digitize_start;
+
mod_digitizeEvent = obj.id;
if (mod_digitizeEvent == button_point || mod_digitizeEvent == button_line || mod_digitizeEvent == button_polygon || mod_digitizeEvent == button_insert ) {
- s.store(d);
+ //
+ // complete a previously unfinished geometry
+ //
+ (function () {
+ var currentGeometryDoesNotCorrespondToTheCurrentButton =
+ (d.count() > 0 && d.get(-1).count() > 0 &&
+ !d.get(-1).get(-1).isComplete() &&
+ mod_digitizeEvent !== d.get(-1).geomType);
+ var currentGeometryType = mod_digitizeEvent;
+
+ if (currentGeometryDoesNotCorrespondToTheCurrentButton) {
+ var currentEpsg = parent.mb_mapObj[parent.getMapObjIndexByName(mod_digitize_target)].epsg;
+ digitizeHistory.addItem({
+ back: function(){
+ d.del(-1);
+ d.getGeometry(-1, -1).reopen();
+ },
+ forward: function(){
+ d.close();
+ d.addMember(currentGeometryType);
+ d.get(-1).addGeometry();
+ d.getGeometry(-1,-1).setEpsg(currentEpsg);
+ }
+ });
+ digitizeHistory.forward();
+ }
+ })();
+
+// s.store(d);
}
executeDigitizePreFunctions();
obj.title = obj.title_on;
- if (obj.id == button_point) {
+ if (obj.id == button_polygon) {
+ // close previous open polygons
if (d.count() > 0 && d.get(-1).count() > 0 && !d.get(-1).get(-1).isComplete()) {
- if (d.get(-1).geomType != parent.geomType.point) {
- d.close();
- executeDigitizeSubFunctions();
+ if (d.get(-1).geomType !== parent.geomType.polygon) {
+// d.close();
+// executeDigitizeSubFunctions();
}
else {
- s.add(d.getPoint(-1, -1, 0));
+// s.add(d.getPoint(-1, -1, 0));
}
}
- if (d.count() == 0 || (d.count() > 0 && d.get(-1).count() > 0 && d.get(-1).get(-1).isComplete())) {
- d.addMember(parent.geomType.point);
- d.get(-1).addGeometry();
- }
- else {
-/*
-//
-// delete existing line or polygon
-//
- d.del(-1);
- d.addMember(parent.geomType.point);
- d.get(-1).addGeometry();
-*/
- }
}
- else if (obj.id == button_polygon) {
- if (d.count() > 0 && d.get(-1).count() > 0 && !d.get(-1).get(-1).isComplete()) {
- if (d.get(-1).geomType != parent.geomType.polygon) {
- d.close();
- executeDigitizeSubFunctions();
- }
- else {
- s.add(d.getPoint(-1, -1, 0));
- }
- }
- if (d.count() == 0 || (d.count() > 0 && d.get(-1).count() > 0 && d.get(-1).get(-1).isComplete())) {
- // new geometry
- d.addMember(parent.geomType.polygon);
- d.get(-1).addGeometry();
- }
- else {
-/*
-//
-// continue a line as a polygon
-//
- if (d.get(-1).geomType != parent.geomType.polygon) {
- var geometryTemplate = parent.cloneObject(d.get(-1));
- d.del(-1);
- d.addMember(parent.geomType.polygon);
- for (var i = 0; i < geometryTemplate.count(); i++) {
- d.get(-1).addGeometry();
- for (var j = 0; j < geometryTemplate.get(i).count(); j++) {
- d.get(-1).get(-1).addPoint(geometryTemplate.get(i).get(j));
- }
- }
- }
- s.add(d.getPoint(-1, -1, 0));
-*/
- }
- }
else if (obj.id == button_line) {
if (d.count() > 0 && d.get(-1).count() > 0 && !d.get(-1).get(-1).isComplete()) {
if (d.get(-1).geomType != parent.geomType.line) {
- d.close();
- executeDigitizeSubFunctions();
+// d.close();
+// executeDigitizeSubFunctions();
}
else {
- s.add(d.getPoint(-1, -1, 0));
+// s.add(d.getPoint(-1, -1, -1));
}
}
- if (d.count() == 0 || (d.count() > 0 && d.get(-1).count() > 0 && d.get(-1).get(-1).isComplete())) {
- d.addMember(parent.geomType.line);
- d.get(-1).addGeometry();
- }
- else {
-/*
-//
-// continue a polygon as a line
-//
- if (d.get(-1).geomType != parent.geomType.line) {
- var geometryTemplate = parent.cloneObject(d.get(-1));
- d.del(-1);
- d.addMember(parent.geomType.line);
- for (var i = 0; i < geometryTemplate.count(); i++) {
- d.get(-1).addGeometry();
- for (var j = 0; j < geometryTemplate.get(i).count(); j++) {
- d.get(-1).get(-1).addPoint(geometryTemplate.get(i).get(j));
- }
- }
- }
-*/
- }
}
else if (obj.id == button_clear) {
var clear = confirm(msgObj.messageConfirmDeleteAllGeomFromList);
if (clear) {
d = new parent.GeometryArray();
+ s.resetPoints();
parent.mb_disableThisButton(button_clear);
+ digitizeHistory = new DigitizeHistory();
}
}
else if (obj.id == button_merge) {
@@ -1010,36 +1161,15 @@
});
}
}
+ else {
+ alert("unknown type: " + obj.id);
+ }
}
function digitizeDisable(obj) {
- if (obj.id == button_point || obj.id == button_line ||
- obj.id == button_polygon){
- obj.title = obj.title_off;
-
- // remove geometries without basepoints
- if (d.get(-1).get(-1).count() == 0) {
- d.delGeometry(-1,-1);
- }
- mod_digitize_timeout();
- executeDigitizeSubFunctions();
- }
- else if (obj.id == button_clear) {
- mod_digitize_timeout();
- executeDigitizeSubFunctions();
- }
- else if (obj.id == button_merge) {
- mod_digitize_timeout();
- executeDigitizeSubFunctions();
- }
- else if (obj.id == button_split) {
- mod_digitize_timeout();
- executeDigitizeSubFunctions();
- }
- else if (obj.id == button_difference) {
- mod_digitize_timeout();
- executeDigitizeSubFunctions();
- }
+ obj.title = obj.title_off;
+ mod_digitize_timeout();
+ executeDigitizeSubFunctions();
mod_digitizeEvent = false;
}
// --- button handling (end) ----------------------------------------------------------------------------------------------
@@ -2245,6 +2375,8 @@
</script>
</head>
<body onload="registerFunctions();displayButtons();">
+ <img id="digitizeBack" style="position:absolute;top:28;left:84" src="../img/button_digitize/back_on.png" title="" onclick="digitizeHistory.back()" name="digitizeBack"/>
+ <img id="digitizeForward" style="position:absolute;top:28;left:112" src="../img/button_digitize/forward_on.png" title="" onclick="digitizeHistory.forward()" name="digitizeForward"/>
<div id='digButtons'></div>
<div id='listOfGeometries' class='digitizeGeometryList'></div>
</body>
More information about the Mapbender_commits
mailing list