[Mapbender-commits] r6003 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Apr 22 08:36:59 EDT 2010


Author: christoph
Date: 2010-04-22 08:36:56 -0400 (Thu, 22 Apr 2010)
New Revision: 6003

Modified:
   trunk/mapbender/http/javascripts/geometry.js
Log:
added isValid, isRectangle

changed behaviour of close method

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2010-04-22 11:59:01 UTC (rev 6002)
+++ trunk/mapbender/http/javascripts/geometry.js	2010-04-22 12:36:56 UTC (rev 6003)
@@ -101,7 +101,10 @@
  */
 GeometryArray.prototype.getGeometry = function(i,j){
 	var tmp = this.get(i);
-	return tmp.get(j);
+	if (tmp) {
+		return tmp.get(j);
+	}
+	return false;
 };
 
 /**
@@ -114,10 +117,22 @@
  * @returns the Point object at the given indices
  */
 GeometryArray.prototype.getPoint = function(i, j, k, l){
-	if (l === undefined) {
-		return this.get(i).get(j).get(k);
+	var mg = this.get(i);
+	if (mg) {
+		var g = mg.get(j);
+		if (g) {
+			if (l === undefined) {
+				return g.get(k);
+			}
+			else {
+				var r = g.innerRings.get(k);
+				if (r) {
+					return r.get(l);
+				}
+			}
+		}
 	}
-	return this.get(i).get(j).innerRings.get(k).get(l);
+	return false;
 };
 
 GeometryArray.prototype.clone = function () {
@@ -894,6 +909,21 @@
 	return str;
 };
 
+MultiGeometry.prototype.isRectangle = function () {
+	if (this.geomType !== Mapbender.geometryType.polygon || this.count() !== 1 || this.get(0).count() !== 5) {
+		return false;
+	}
+	var p1 = this.getPoint(0, 0);
+	var p2 = this.getPoint(0, 1);
+	var p3 = this.getPoint(0, 2);
+	var p4 = this.getPoint(0, 3);
+
+	if (p1.y === p2.y && p1.x === p4.x && p3.y === p4.y && p3.x === p2.x) {
+		return true;
+	}
+	return false;
+};
+
 MultiGeometry.prototype.toStringWithoutProperties = function () {
 	var str = "{\"type\": \"Feature\", ";
 
@@ -944,9 +974,12 @@
 		}
 		str += "]";
 	}
-	else {
+	else if (len === 1) {
 		str += this.get(0).toString();
 	}
+	else {
+		str += "[]";
+	}
 
 	str += "}";
 
@@ -1130,21 +1163,34 @@
 	this.close = function(){
 		complete = true;
 		if (this.geomType == geomType.polygon){
-			if (this.count() > 2){
-				if (!this.get(0).equals(this.get(-1))) {
+//			if (this.count() > 2){
+				if (this.count() > 0 && !this.get(0).equals(this.get(-1))) {
 					this.addPoint(this.get(0));
 				}
-			}
-			else {return false;}
+//			}
+//			else {return false;}
 		}
 		if (this.geomType == geomType.line){
-			if (this.count() < 2){return false;}
+//			if (this.count() < 2){return false;}
 		}
 		if (this.geomType == geomType.point){
 			if (this.count() === 0){return false;}
 		}
 		return true;
 	};
+
+	this.isValid = function(){
+		if (this.geomType === geomType.polygon){
+			return (this.count() > 3 && this.get(0).equals(this.get(-1))) ? true : false;
+		}
+		if (this.geomType === geomType.line){
+			return (this.count() < 2) ? false : true;
+		}
+		if (this.geomType == geomType.point){
+			return (this.count() === 0) ? false : true;
+		}
+		return false;
+	};
 	
 	this.reopen = function () {
 		if (!complete) {
@@ -1459,6 +1505,9 @@
 			}
 			str += this.get(i).toString();
 		}
+		if (this.count() > 0 && !this.get(0).equals(this.get(i-1))) {
+			str += ", " + this.get(0).toString();
+		}
 
 		if (typeof(this.innerRings) == "object" && this.innerRings.count() > 0) {
 			for (var j = 0; j < this.innerRings.count(); j++) {
@@ -1471,6 +1520,9 @@
 					}
 					str += currentRing.get(i).toString();
 				}
+				if (currentRing.count() > 0 && !this.currentRing(0).equals(this.currentRing(i-1))) {
+					str += ", " + this.currentRing(0).toString();
+				}
 			}
 		}
 		str += "]]";
@@ -1837,9 +1889,6 @@
 				"stroke-width": lineWidth,
 				"fill-opacity": 0.5
 			});		
-			c.animate({
-				"r" : diameter
-			}, 500, "bounce");
 		}
 		else {
 			canvas.setColor(color);



More information about the Mapbender_commits mailing list