svn commit: r776 - trunk/mapbender/http/javascripts/mod_geometryArray.js

christoph at osgeo.org christoph at osgeo.org
Fri Sep 29 04:14:28 EDT 2006


Author: christoph
Date: 2006-09-29 08:14:28+0000
New Revision: 776

Modified:
   trunk/mapbender/http/javascripts/mod_geometryArray.js

Log:
added method 'equals' for multigeometries and geometries

Modified: trunk/mapbender/http/javascripts/mod_geometryArray.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_geometryArray.js?view=diff&rev=776&p1=trunk/mapbender/http/javascripts/mod_geometryArray.js&p2=trunk/mapbender/http/javascripts/mod_geometryArray.js&r1=775&r2=776
==============================================================================
--- trunk/mapbender/http/javascripts/mod_geometryArray.js	(original)
+++ trunk/mapbender/http/javascripts/mod_geometryArray.js	2006-09-29 08:14:28+0000
@@ -54,6 +54,19 @@
 		this.m.length -= 1;
 	}
 
+	this.findMultiGeometry = function(m) {
+		for (var i=0; i < this.count(); i++) {
+			if (this.get(i).equals(m)) return i;
+		}
+		return null;
+	}
+	
+	this.removeMultiGeometry = function(m) {
+		var i = true;
+		i = this.findMultiGeometry(m);
+		if (i != null) this.del(i);
+	}
+	
 	this.delGeometry = function(i,j){
 		var res = this.get(i).del(j);
 		if (res == false) this.del(i);
@@ -125,9 +138,7 @@
 
 	this.get = function(i){
 		i = this.getIndex(i);
-		if (i != null){
-			return this.g[i];
-		}
+		if (i != null) return this.g[i];
 		return false;
 	}
 
@@ -139,6 +150,16 @@
 		this.g[this.g.length] = new Geometry(this.geomtype);
 	}
 	
+	this.equals = function(multigeom) {
+		if (this.geomtype != multigeom.geomtype) return false;
+		if (this.count() != multigeom.count()) return false;
+		if (this.getTotalPointCount() != multigeom.getTotalPointCount()) return false;
+		for (var i=0; i<this.count(); i++) {
+			if (!this.get(i).equals(multigeom.get(i))) return false;
+		}
+		return true;
+	}
+	
 	this.del = function(i){
 		i = this.getIndex(i);
 		if (i != null){
@@ -149,9 +170,7 @@
 			}
 			this.g.length -= 1;
 			
-			if (this.g.length == 0){
-				return false;
-			}
+			if (this.g.length == 0)	return false;
 		}
 		return true;
 	}
@@ -342,6 +361,15 @@
 		return str;
 	}
 	
+	this.equals = function(geom) {
+		if (this.geomtype != geom.geomtype) return false;
+		if (this.count() != geom.count()) return false;
+		for (var i in this.v) {
+			if (!this.get(i).equals(geom.get(i))) return false;
+		}
+		return true;
+	}
+	
 	this.getIndex = function(i){ //private
 		if ((i >= 0 && i < this.v.length) || (i*(-1)>0 && i*(-1) <=this.v.length)){
 			if (i >= 0) {return i;}	else {return this.v.length+i;}
@@ -395,9 +423,7 @@
 
 	this.setElement = function(aName, aValue){
 		var i = this.getElementIndexByName(aName);
-		if (i == -1){
-			i = this.name.length;
-		}
+		if (i == -1) i = this.name.length;
 		this.name[i] = aName;
 		this.value[i] = aValue;
 		return true;
@@ -451,11 +477,8 @@
 			}
 		}
 		if (this.coord.length>0 && minDist > this.tolerance) {this.min_i = -1;}
-	
 		this.clean();
-		if (this.min_i != -1){
-			this.draw(this.coord[this.min_i]['coord'], this.tolerance, 3);
-		}
+		if (this.min_i != -1) this.draw(this.coord[this.min_i]['coord'], this.tolerance, 3);
 	}
 
 	this.add = function(geom, k, j, i){
@@ -538,5 +561,4 @@
 	}
 	this.canvas.setStroke(3);
 	if (node == false) {alert("Fatal error: Element id is already taken!");}
-}
-
+}
\ No newline at end of file




More information about the Mapbender_commits mailing list