[Mapbender-commits] r5306 - in trunk/mapbender/http: img/button_digitize javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 12 11:17:58 EST 2010


Author: christoph
Date: 2010-01-12 11:17:56 -0500 (Tue, 12 Jan 2010)
New Revision: 5306

Added:
   trunk/mapbender/http/img/button_digitize/line_continue_off.png
   trunk/mapbender/http/img/button_digitize/line_continue_on.png
   trunk/mapbender/http/img/button_digitize/line_continue_over.png
   trunk/mapbender/http/php/mod_digitize_splitLine.php
Modified:
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
   trunk/mapbender/http/php/mod_digitize_messages.php
   trunk/mapbender/http/php/mod_digitize_splitPolygon.php
Log:
continue a previously digitized line

Added: trunk/mapbender/http/img/button_digitize/line_continue_off.png
===================================================================
(Binary files differ)


Property changes on: trunk/mapbender/http/img/button_digitize/line_continue_off.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/mapbender/http/img/button_digitize/line_continue_on.png
===================================================================
(Binary files differ)


Property changes on: trunk/mapbender/http/img/button_digitize/line_continue_on.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/mapbender/http/img/button_digitize/line_continue_over.png
===================================================================
(Binary files differ)


Property changes on: trunk/mapbender/http/img/button_digitize/line_continue_over.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-01-12 15:54:57 UTC (rev 5305)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-01-12 16:17:56 UTC (rev 5306)
@@ -1,21 +1,9 @@
 <?php
-# $Id$
-# http://www.mapbender.org/index.php/mod_digitize_tab.php
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License 
+# and Simplified BSD license.  
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
 
 require_once(dirname(__FILE__) . "/../php/mb_validateSession.php");
 
@@ -134,8 +122,8 @@
 	}
 
 	eventCloseGeometry = new parent.Mapbender.Event();
-	eventCloseGeometry.register(function () {
-		d.close();
+	eventCloseGeometry.register(function (obj) {
+		d.close(obj.index);
 	});
 	if (openMetadataEditorAfterNewGeometryHasBeenCreated) {
 		eventCloseGeometry.register(function (obj) {
@@ -148,6 +136,7 @@
 			showWfs(obj.index);
 		});
 	}
+	
 	parent.Mapbender.modules[mod_digitize_elName].events = {
 		closeGeometry: eventCloseGeometry,
 		beforeUpdateOrInsert: new parent.Mapbender.Event(),
@@ -155,6 +144,10 @@
 		beforeInsert: new parent.Mapbender.Event()
 	};
 
+	eventCloseGeometry.register(function () {
+		_currentGeomIndex = -1;
+	});
+
 	parent.Mapbender.modules[mod_digitize_elName].cancelAjaxRequest = false;
 	parent.Mapbender.modules[mod_digitize_elName].cancelAjaxRequestMessage = "An error occured.";
 });
@@ -179,6 +172,7 @@
 var button_point;
 var button_line;
 var button_polygon;
+var button_line_continue = "lineContinue";
 var button_move = "dragBasePoint";
 var button_insert = "setBasePoint";
 var button_delete = "delBasePoint";
@@ -186,6 +180,7 @@
 var button_split = "digitizeSplit";
 var button_merge = "digitizeMerge";
 var button_difference = "digitizeDifference";
+var _currentGeomIndex = -1;
 
 var digitizeDivTag;
 
@@ -318,15 +313,9 @@
 }
 
 function mod_digitize_go(e){
-	// ie workaround
-	if (e == undefined) {
-		e = mapWindow.event;
-	}
-	if (e) {
-		// track mouse position
-		var currentPos = getMousePosition(e);
-		s.check(currentPos);
-	}
+	// track mouse position
+	var currentPos = getMousePosition(e);
+	s.check(currentPos);
 }
 
 function mod_digitize_timeout(){
@@ -337,9 +326,9 @@
 }
 
 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);
+	return d.get(_currentGeomIndex).geomType === parent.geomType.line 
+		&& d.getGeometry(_currentGeomIndex,-1).count() > 1 
+		&& d.getGeometry(_currentGeomIndex,-1).get(-1).equals(newPoint);
 };
 
 var innerPointSnapped = function (newPoint) {
@@ -347,11 +336,11 @@
 		return null;
 	}
 	var start = 1;
-	if (d.getGeometry(-1, -1).count() < 3) {
+	if (d.getGeometry(_currentGeomIndex, -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)) {
+	for (var i = start; i < d.getGeometry(_currentGeomIndex, -1).count(); i++) {
+		if (d.getGeometry(_currentGeomIndex,-1).get(i).equals(newPoint)) {
 			return i;
 		}
 	}
@@ -359,74 +348,130 @@
 };
 
 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);
+	return d.get(_currentGeomIndex).geomType == parent.geomType.polygon 
+		&& d.getGeometry(_currentGeomIndex,-1).count() >= 3 
+		&& d.getGeometry(_currentGeomIndex,-1).get(0).equals(newPoint);
 };
 
 var editingPolygonAndThreePointsHaveBeenInserted = function () {
-	return d.get(-1).geomType == parent.geomType.polygon && d.getGeometry(-1,-1).count() == 2;
+	return d.get(_currentGeomIndex).geomType == parent.geomType.polygon && d.getGeometry(_currentGeomIndex,-1).count() == 2;
 };
 
 var editingLineAndTwoPointsHaveBeenInserted = function () {
-	return d.get(-1).geomType == parent.geomType.line && d.getGeometry(-1,-1).count() >= 1;				
+	return d.get(_currentGeomIndex).geomType == parent.geomType.line && d.getGeometry(_currentGeomIndex,-1).count() >= 1;				
 };
 
 function mod_digitize_start(e){
 	if (mod_digitizeEvent !== button_point
 		&& mod_digitizeEvent !== button_line
+		&& mod_digitizeEvent !== button_line_continue
 		&& mod_digitizeEvent !== button_polygon) {
 
 		alert(msgObj.errorMessageNoGeometrySelected);
 		return false;
 	}
 	
-	//
-	// get the last point the user digitized
-	//
-	var realWorldPos;
-	if (s.isSnapped()) {
-		realWorldPos = s.getSnappedPoint(); 
-		s.clean();
-	}
-	else {
-		var currentPos = getMousePosition(e);
-		realWorldPos = parent.mapToReal(mod_digitize_target,currentPos);
-	}
+	(function () {
+		//
+		// get the last point the user digitized
+		//
+		var realWorldPos;
+		var isSnapped = s.isSnapped();
+		if (isSnapped) {
+			realWorldPos = s.getSnappedPoint(); 
+			s.clean();
+		}
+		else {
+			var currentPos = getMousePosition(e);
+			realWorldPos = parent.mapToReal(mod_digitize_target,currentPos);
+		}
 
-	(function () {
 		var geometryType = mod_digitizeEvent;
 		var currentPoint = realWorldPos;
 		var currentEpsg = parent.mb_mapObj[parent.getMapObjIndexByName(mod_digitize_target)].epsg;
+		var currentGeomIndex = _currentGeomIndex;
 
+		if (mod_digitizeEvent === button_line_continue) {
+			if (isSnapped) {
+				// find corresponding line
+				for (var i = 0; i < d.count(); i++) {
+					var lastPointSnapped = false;
+					var firstPointSnapped = false;
+					if (d.get(i).geomType !== parent.geomType.line) {
+						continue;
+					}
+					if (d.getPoint(i, -1, -1) === realWorldPos) {
+						lastPointSnapped = true;
+					}
+					else if (d.getPoint(i, -1, 0) === realWorldPos) {
+						firstPointSnapped = true;
+					}
+					else {
+						continue;
+					}
+					if (firstPointSnapped) {
+						// reverse line!
+						// we can only add points to the end of the line, not insert them at the beginning
+						var oldLine = parent.cloneObject(d.getGeometry(i, -1));
+						var newLine = d.getGeometry(i, -1);
+						var len = oldLine.count();
+						for (var j = len-1; j >= 0; j--) {
+							newLine.updatePointAtIndex(oldLine.get(j), len-j-1);
+						}
+					}
+					// enable snapping to all points except 
+					// the ones from this line
+					s.resetPoints();
+					s.store(d);
+					for (var j = 0; j < d.get(i).count(); j++) {
+						var currentLine = d.getGeometry(i, j);
+						for (var k = 0; k < currentLine.count(); k++) {
+							s.removePoint(currentLine.get(k));
+						}
+					}
+					// delete last point, will be added again below, 
+					// as the event has changed to "button_line"
+					d.getGeometry(i, -1).del(-1);
+					d.getGeometry(i, -1).reopen();
+					currentGeomIndex = i;
+					_currentGeomIndex = i;
+					
+					parent.mb_enableButton(d.get(i).geomType);
+					break;
+				}
+			}
+			// check if event is still "line continue", 
+			// as it might have changed
+			if (mod_digitizeEvent === button_line_continue) {
+				return;
+			}
+		}
 		//
 		// A new geometry has to be created
 		//
-		if (d.count() === 0 || (d.get(-1).count()> 0 && d.getGeometry(-1, -1).isComplete())) {
-			
+		if (d.count() === 0 || (d.get(currentGeomIndex).count()> 0 && d.getGeometry(currentGeomIndex, -1).isComplete())) {
 			digitizeHistory.addItem({
 				// remove the entire multigeometry
 				back: function () {
-					s.removePoint(d.getPoint(-1, -1, -1));
-					d.del(-1);
+					s.resetPoints();
+					d.del(currentGeomIndex);
+					s.store(d);
 				},
 				// add the multigeometry to the geometry array
 				forward: function () {
+					s.store(d);
 					parent.mb_enableButton(geometryType);
 					d.addMember(geometryType);
-					d.get(-1).addGeometry();
-					d.getGeometry(-1,-1).setEpsg(currentEpsg);
-					d.getGeometry(-1,-1).addPoint(realWorldPos);
+					d.get(currentGeomIndex).addGeometry();
+					d.getGeometry(currentGeomIndex,-1).setEpsg(currentEpsg);
+					d.getGeometry(currentGeomIndex,-1).addPoint(realWorldPos);
 					if (geometryType == parent.geomType.point){
 						eventCloseGeometry.trigger({
-							index: d.count() - 1,
-							geometry: d.get(-1)
+							index: currentGeomIndex,
+							geometry: d.get(currentGeomIndex)
 						});
-						parent.mb_disableThisButton(geometryType);
+						parent.mb_disableThisButton(mod_digitizeEvent);
 					}
-					else {
-						s.add(d.getPoint(-1, -1, -1));
-					}
 				}
 			});
 		}
@@ -439,20 +484,19 @@
 			// 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);
+						d.getGeometry(currentGeomIndex, -1).reopen();
+						parent.mb_enableButton(d.get(currentGeomIndex).geomType);
 						// activate button
 					},
 					forward: function () {
 						// close the polygon
 						eventCloseGeometry.trigger({
-							index: d.count() - 1,
-							geometry: d.get(-1)
+							index: currentGeomIndex,
+							geometry: d.get(currentGeomIndex)
 						});
-						parent.mb_disableThisButton(button_polygon);
+						parent.mb_disableThisButton(mod_digitizeEvent);
 					}
 				});
 			}
@@ -462,27 +506,27 @@
 			else if (isLastLinePointSnapped(realWorldPos)) {
 				digitizeHistory.addItem({
 					back: function () {
-						d.getGeometry(-1, -1).reopen();
-						parent.mb_enableButton(d.get(-1).geomType);
+						d.getGeometry(currentGeomIndex, -1).reopen();
+						parent.mb_enableButton(d.get(currentGeomIndex).geomType);
 					},
 					forward: function () {
 						// close the polygon
 						eventCloseGeometry.trigger({
-							index: d.count() - 1,
-							geometry: d.get(-1)
+							index: currentGeomIndex,
+							geometry: d.get(currentGeomIndex)
 						});
-						parent.mb_disableThisButton(button_line);
+						parent.mb_disableThisButton(mod_digitizeEvent);
 					}
 				});
 			}
 			//
-			// another point is snapped (undo)
+			// another point is snapped (undo for polygons!)
 			//
-			else if (innerPointIndex !== null && allowUndoPolygonBySnapping) {
-				while (d.getGeometry(-1, -1).count() > innerPointIndex) {
+			else if (innerPointIndex !== null && allowUndoPolygonBySnapping && geometryType == parent.geomType.polygon) {
+				while (d.getGeometry(currentGeomIndex, -1).count() > innerPointIndex) {
 					digitizeHistory.back();
 				}
-				// avoids the forward!
+				// avoids the history.forward()!
 				return;
 			}
 			//
@@ -492,38 +536,54 @@
 				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);
+							s.removePoint(d.getPoint(currentGeomIndex, -1, 0));
+							if (allowUndoPolygonBySnapping && geometryType == parent.geomType.polygon) {
+								s.removePoint(d.getPoint(currentGeomIndex, -1, -1));
+							}
+							d.getGeometry(currentGeomIndex, -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));
+							d.getGeometry(currentGeomIndex,-1).addPoint(realWorldPos);
+							s.add(d.getPoint(currentGeomIndex, -1, 0));
+							if (allowUndoPolygonBySnapping && geometryType == parent.geomType.polygon) {
+								s.add(d.getPoint(currentGeomIndex, -1, -1));
+							}
 						}
 					});
 				}
 				else if (editingLineAndTwoPointsHaveBeenInserted()) {
+
 					digitizeHistory.addItem({
 						back: function () {
-							s.removePoint(d.getPoint(-1, -1, -1));
-							d.getGeometry(-1, -1).del(-1);
+							s.removePoint(d.getPoint(currentGeomIndex, -1, -1));
+							s.add(d.getPoint(currentGeomIndex, -1, -2));
+							d.getGeometry(currentGeomIndex, -1).del(-1);
 						},
 						forward: function () {
-							d.getGeometry(-1,-1).addPoint(realWorldPos);
-							s.add(d.getPoint(-1, -1, -1));
+							d.getGeometry(currentGeomIndex,-1).addPoint(realWorldPos);
+							s.removePoint(d.getPoint(currentGeomIndex, -1, -2));
+							s.add(d.getPoint(currentGeomIndex, -1, -1));
 						}
 					});
 				}
 				else {
 					digitizeHistory.addItem({
 						back: function () {
-							s.removePoint(d.getPoint(-1, -1, -1));
-							d.getGeometry(-1, -1).del(-1);
+							if (allowUndoPolygonBySnapping && geometryType == parent.geomType.polygon) {
+								s.removePoint(d.getPoint(currentGeomIndex, -1, -1));
+							}
+							if (geometryType === parent.geomType.line) {
+								d.getGeometry(currentGeomIndex, -1).del(-1);
+							}
+							else {
+								d.getGeometry(currentGeomIndex, -1).del(-1);
+							}
 						},
 						forward: function () {
-							d.getGeometry(-1,-1).addPoint(realWorldPos);
-							s.add(d.getPoint(-1, -1, -1));
+							d.getGeometry(currentGeomIndex, -1).addPoint(realWorldPos);
+							if (allowUndoPolygonBySnapping && geometryType == parent.geomType.polygon) {
+								s.add(d.getPoint(currentGeomIndex, -1, -1));
+							}
 						}
 					});
 				}
@@ -532,9 +592,6 @@
 		digitizeHistory.forward();
 	})();
 
-		
-
-
 	return true;
 }
 // --- polygon, line, point insertion (begin) ----------------------------------------------------------------------------------------------
@@ -841,12 +898,12 @@
 
 function updateMeasureTag () {
 	if (d.count() > 0 ) {
-		if (d.get(-1).count() > 0) {
-			if (d.getGeometry(-1, -1).count() > 0) {
+		if (d.get(_currentGeomIndex).count() > 0) {
+			if (d.getGeometry(_currentGeomIndex, -1).count() > 0) {
 				if (mod_digitizeEvent == button_line || mod_digitizeEvent == button_polygon) {
 					var measureString = "";
-					measureString += msgObj.measureTagLabelCurrent + d.getGeometry(-1, -1).getCurrentDist(measureNumberOfDigits) + "<br>";
-					measureString += msgObj.measureTagLabelTotal + d.getGeometry(-1, -1).getTotalDist(measureNumberOfDigits);
+					measureString += msgObj.measureTagLabelCurrent + d.getGeometry(_currentGeomIndex, -1).getCurrentDist(measureNumberOfDigits) + "<br>";
+					measureString += msgObj.measureTagLabelTotal + d.getGeometry(_currentGeomIndex, -1).getTotalDist(measureNumberOfDigits);
 					measureDivTag.write(measureString);
 					return true;
 				}
@@ -899,6 +956,14 @@
 						currentTitle = msgObj.buttonLabelLineOff;
 					}
 					break;
+				case "lineContinue":
+					if (currentStatus == 1) {
+						currentTitle = msgObj.buttonLabelLineContinueOn;
+					}
+					else {
+						currentTitle = msgObj.buttonLabelLineContinueOff;
+					}
+					break;
 				case "polygon":
 					if (currentStatus == 1) {
 						currentTitle = msgObj.buttonLabelPolygonOn;
@@ -991,10 +1056,8 @@
 	else if (obj.id == button_point || obj.id == button_line || 
 			obj.id == button_polygon || obj.id == button_clear || 
 			obj.id == button_split || obj.id == button_merge ||
-			obj.id == button_difference){
+			obj.id == button_difference || obj.id == button_line_continue){
 					
-		s.store(d);
-
 		var el = mapDomElement;
 		$(el).mousemove(function (e) {
 			mod_digitize_go(e);
@@ -1009,40 +1072,43 @@
 			//
 			// 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);
+					(d.count() > 0 && d.get(_currentGeomIndex).count() > 0 &&
+					!d.get(_currentGeomIndex).get(-1).isComplete() &&
+					mod_digitizeEvent !== d.get(_currentGeomIndex).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();
+							s.resetPoints();
+							d.del(_currentGeomIndex);
+							s.store(d);
+							d.getGeometry(_currentGeomIndex, -1).reopen();
 						},
 						forward: function(){
-							d.close();
+							d.close(-1);
+							s.store(d);
 							d.addMember(currentGeometryType);
-							d.get(-1).addGeometry();
-							d.getGeometry(-1,-1).setEpsg(currentEpsg);
+							d.get(_currentGeomIndex).addGeometry();
+							d.getGeometry(_currentGeomIndex,-1).setEpsg(currentEpsg);
 						}
 					});
 					digitizeHistory.forward();
 				}
 			})();
 	
-//			s.store(d);
 		}
 
 		executeDigitizePreFunctions();
 		obj.title = obj.title_on;
 		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.polygon) {
+			if (d.count() > 0 && d.get(_currentGeomIndex).count() > 0 && !d.get(_currentGeomIndex).get(-1).isComplete()) {
+				if (d.get(_currentGeomIndex).geomType !== parent.geomType.polygon) {
 //					d.close();
 //					executeDigitizeSubFunctions();
 				}
@@ -1052,8 +1118,8 @@
 			}
 		}
 		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) {
+			if (d.count() > 0 && d.get(_currentGeomIndex).count() > 0 && !d.get(_currentGeomIndex).get(-1).isComplete()) {
+				if (d.get(_currentGeomIndex).geomType != parent.geomType.line) {
 //					d.close();
 //					executeDigitizeSubFunctions();
 				}
@@ -1062,12 +1128,22 @@
 				}
 			}
 		}
+		else if (obj.id == button_line_continue) {
+			s.resetPoints();
+			for (var i = 0; i < d.count(); i++) {
+				if (d.get(i).geomType !== parent.geomType.line) {
+					continue;
+				}
+				s.add(d.getPoint(i, -1, 0));
+				s.add(d.getPoint(i, -1, -1));
+			}
+		}
 		else if (obj.id == button_clear) {
 			var clear = confirm(msgObj.messageConfirmDeleteAllGeomFromList);
 			if (clear) {
 				d = new parent.GeometryArray();
 				s.resetPoints();
-				parent.mb_disableThisButton(button_clear);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 				digitizeHistory = new DigitizeHistory();
 			}
 		}
@@ -1086,7 +1162,7 @@
 
 			if (!applicable) {
 				alert(msgObj.messageErrorMergeNotApplicable);
-				parent.mb_disableThisButton(button_merge);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 				return false;
 			}
 			
@@ -1101,36 +1177,62 @@
 				for (var i = 0; i < len-1; i++) {
 					d.del(0);
 				}
-				parent.mb_disableThisButton(button_merge);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 			});
 		}
 		else if (obj.id == button_split) {
 			var applicable = (d.count() == 2) && 
-							(d.get(0).geomType == parent.geomType.polygon) &&
-							(d.get(1).geomType == parent.geomType.line);
+				(
+					d.get(0).geomType == parent.geomType.polygon ||
+					d.get(0).geomType == parent.geomType.line
+				) && (d.get(1).geomType == parent.geomType.line);
 			if (!applicable) {
 				alert(msgObj.messageErrorSplitNotApplicable);
-				parent.mb_disableThisButton(button_split);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 				return false;
 			}
 			
-			var polygonText = d.get(0).toText();
-			var lineText = d.get(1).toText();
-			
-			parent.mb_ajax_post("../php/mod_digitize_splitPolygon.php", {polygon: polygonText, line: lineText}, function(json, status) {
+			var splitCallback = function (json, status) {
 				var response = eval('(' + json + ')');
-				var polygonArray = response.polygons;
+				var resultArray = response.geometries;
 				var wfsConfId = d.get(0).wfs_conf;
 				var mapIndex = parent.getMapObjIndexByName(mod_digitize_target);
-				for (var i in polygonArray) {
-					d.importGeometryFromText(polygonArray[i], parent.mb_mapObj[mapIndex].epsg);
+				for (var i in resultArray) {
+					d.importGeometryFromText(resultArray[i], parent.mb_mapObj[mapIndex].epsg);
 					d.get(-1).wfs_conf = wfsConfId;
+					var wfsProperties = d.get(0).e;
+
+					for (var i = 0; i < wfsProperties.count(); i++) {
+						if (wfsProperties.getName(i) === "fid") {
+							continue;
+						}
+						d.get(-1).e.setElement(wfsProperties.getName(i), wfsProperties.getValue(i));
+					}
 				}
-				// remove the original polygon and the temporary line
+				// remove the original geometry and the temporary line
 				d.del(0);
 				d.del(0);
-				parent.mb_disableThisButton(button_split);
-			});
+				parent.mb_disableThisButton(mod_digitizeEvent);
+			};
+
+			if (d.get(0).geomType == parent.geomType.polygon) {
+				var polygonText = d.get(0).toText();
+				var lineText = d.get(1).toText();
+				
+				parent.mb_ajax_post("../php/mod_digitize_splitPolygon.php", {
+					polygon: polygonText, 
+					line: lineText
+				}, splitCallback);
+			}
+			else {
+				var line1text = d.get(0).toText();
+				var line2text = d.get(1).toText();
+				
+				parent.mb_ajax_post("../php/mod_digitize_splitLine.php", {
+					line1: line1text, 
+					line2: line2text
+				}, splitCallback);
+			}
 		}
 		else if (obj.id == button_difference) {
 			var applicable = (d.count() == 2) && 
@@ -1138,7 +1240,7 @@
 							(d.get(1).geomType == parent.geomType.polygon);
 			if (!applicable) {
 				alert(msgObj.messageErrorDifferenceNotApplicable);
-				parent.mb_disableThisButton(button_difference);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 				return false;
 			}
 			
@@ -1154,12 +1256,17 @@
 				for (var i in polygonArray) {
 					d.importGeometryFromText(polygonArray[i], parent.mb_mapObj[mapIndex].epsg);
 					d.get(-1).wfs_conf = wfsConfId;
-					d.get(-1).e = wfsProperties;
+					for (var i = 0; i < wfsProperties.count(); i++) {
+						if (wfsProperties.getName(i) === "fid") {
+							continue;
+						}
+						d.get(-1).e.setElement(wfsProperties.getName(i), wfsProperties.getValue(i));
+					}
 				}
 				// remove the original and the temporary polygon
 				d.del(0);
 				d.del(0);
-				parent.mb_disableThisButton(button_difference);
+				parent.mb_disableThisButton(mod_digitizeEvent);
 			});
 		}
 	}
@@ -1452,7 +1559,7 @@
 					listOfGeom += "<img src = '"+buttonDig_imgdir+buttonDig_removeDb_src+"' title='"+msgObj.buttonDig_removeDb_title+"' onclick=\"var deltrans = confirm('"+msgObj.messageConfirmDeleteGeomFromDb+"');if (deltrans) dbGeom('delete', "+i+")\">";
 				}
 				listOfGeom += "<div class='digitizeGeometryListItem' onmouseover='parent.mb_wfs_perform(\"over\",d.get("+i+"),\""+geomHighlightColour+"\");' ";
-				listOfGeom += " onmouseout='parent.mb_wfs_perform(\"out\",d.get("+i+"),\""+geomHighlightColour+"\")' ";
+				listOfGeom += " onmouseout='parent.mb_wfs_perform(\"clean\",d.get("+i+"),\""+geomHighlightColour+"\")' ";
 				listOfGeom += " onclick='parent.mb_wfs_perform(\"click\",d.get("+i+"),\""+geomHighlightColour+"\");' ";
 				var geomName = getName(d.get(i)); 
 				var currentGeomType;

Modified: trunk/mapbender/http/php/mod_digitize_messages.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_messages.php	2010-01-12 15:54:57 UTC (rev 5305)
+++ trunk/mapbender/http/php/mod_digitize_messages.php	2010-01-12 16:17:56 UTC (rev 5306)
@@ -1,21 +1,9 @@
 <?php
-#$Id: mod_insertWmcIntoDb.php 507 2006-11-20 10:55:57Z christoph $
-#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License 
+# and Simplified BSD license.  
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
@@ -36,7 +24,7 @@
 $msg_obj["messageErrorFormEvaluation"] = _mb("Failure during form evaluation.");
 $msg_obj["messageErrorWfsWrite"] = _mb("An error occured.");
 $msg_obj["messageErrorMergeNotApplicable"] = _mb("At least two geometries must be available. Only polygons are allowed in the geometry list.");
-$msg_obj["messageErrorSplitNotApplicable"] = _mb("Exactly two geometries must be available. The first geometry shall be a polygon, the second geometry shall be a line.");
+$msg_obj["messageErrorSplitNotApplicable"] = _mb("Exactly two geometries must be available. The first geometry shall be a polygon or a line, the second geometry shall be a line.");
 $msg_obj["messageErrorDifferenceNotApplicable"] = _mb("Exactly two polygons must be available.");
 $msg_obj["messageSuccessWfsWrite"] = _mb("Success.");
 $msg_obj["messageConfirmDeleteGeomFromDb"] = _mb("Delete geometry from database?");
@@ -52,6 +40,8 @@
 $msg_obj["buttonLabelPointOn"] = _mb("cancel editing");
 $msg_obj["buttonLabelLineOff"] = _mb("add line");
 $msg_obj["buttonLabelLineOn"] = _mb("finish line");
+$msg_obj["buttonLabelLineContinueOff"] = _mb("continue line");
+$msg_obj["buttonLabelLineContinueOn"] = _mb("finish line");
 $msg_obj["buttonLabelPolygonOff"] = _mb("add polygon");
 $msg_obj["buttonLabelPolygonOn"] = _mb("close polygon");
 $msg_obj["buttonLabelMoveBasepointOff"] = _mb("move basepoint");
@@ -64,8 +54,8 @@
 $msg_obj["buttonLabelClearListOn"] = _mb("clear list of geometries");
 $msg_obj["buttonLabelMergeOff"] = _mb("Merge two polygons into a single polygon (will be added to the geometry list)");
 $msg_obj["buttonLabelMergeOn"] = _mb("Merge two polygons into a single polygon (will be added to the geometry list)");
-$msg_obj["buttonLabelSplitOff"] = _mb("Split a polygon by a line (the new polygons will be added to the geometry list)");
-$msg_obj["buttonLabelSplitOn"] = _mb("Split a polygon by a line (the new polygons will be added to the geometry list)");
+$msg_obj["buttonLabelSplitOff"] = _mb("Split a polygon/line by a line (the new polygons/lines will be added to the geometry list)");
+$msg_obj["buttonLabelSplitOn"] = _mb("Split a polygon/line by a line (the new polygons/lines will be added to the geometry list)");
 $msg_obj["buttonLabelDifferenceOff"] = _mb("Combine two polygons (to create en- and exclave or to compute the difference)");
 $msg_obj["buttonLabelDifferenceOn"] = _mb("Split geometries");
 $msg_obj["buttonDig_wfs_title"] = _mb("save / update / delete");

Added: trunk/mapbender/http/php/mod_digitize_splitLine.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_splitLine.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_digitize_splitLine.php	2010-01-12 16:17:56 UTC (rev 5306)
@@ -0,0 +1,49 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License 
+# and Simplified BSD license.  
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
+
+$json = new Mapbender_JSON();
+
+$line1Text = $_REQUEST["line1"];
+$line2Text = $_REQUEST["line2"];
+
+
+$floatPattern = "-?\d+(\.\d+)?";
+$pointPattern = $floatPattern . " " . $floatPattern;
+$linePattern = "LINESTRING \(" . $pointPattern . ",( )*" . $pointPattern . "(,( )*" . $pointPattern . ")*\)";
+
+$pattern = "/" . $linePattern . "/";
+if (!preg_match($pattern, $line1Text)) {
+	echo "not a line.";
+	die();
+}
+
+if (!preg_match($pattern, $line2Text)) {
+	echo "not a line.";
+	die();
+}
+
+$sql = sprintf("SELECT astext(multi(geom)) FROM dump ((" . 
+	"SELECT ST_AsText(ST_FORCE_COLLECTION(ST_Difference(" . 
+	"'%s'::geometry,'%s'::geometry)))))", $line1Text, $line2Text);
+
+$res = db_query($sql);    
+
+$lineArray = array();
+while ($row = db_fetch_array($res)) {
+	array_push($lineArray, $row[0]);
+}
+
+$data = array("geometries" => $lineArray);
+
+$output = $json->encode($data);
+
+header("Content-type:application/x-json; charset=utf-8");
+echo $output;
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_digitize_splitPolygon.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_splitPolygon.php	2010-01-12 15:54:57 UTC (rev 5305)
+++ trunk/mapbender/http/php/mod_digitize_splitPolygon.php	2010-01-12 16:17:56 UTC (rev 5306)
@@ -1,21 +1,9 @@
 <?php
-# $Id$
-# http://www.mapbender.org/index.php/DeleteWMS
-# Copyright (C) 2002 CCGIS 
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License 
+# and Simplified BSD license.  
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
 
 require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_json.php");
@@ -64,7 +52,7 @@
 	array_push($polygonArray, $row[0]);
 }
 
-$data = array("polygons" => $polygonArray);
+$data = array("geometries" => $polygonArray);
 
 $output = $json->encode($data);
 



More information about the Mapbender_commits mailing list