[Mapbender-commits] r4339 - branches/2.6/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 10 11:32:43 EDT 2009


Author: christoph
Date: 2009-07-10 11:32:42 -0400 (Fri, 10 Jul 2009)
New Revision: 4339

Modified:
   branches/2.6/http/javascripts/geometry.js
Log:


Modified: branches/2.6/http/javascripts/geometry.js
===================================================================
--- branches/2.6/http/javascripts/geometry.js	2009-07-10 15:29:55 UTC (rev 4338)
+++ branches/2.6/http/javascripts/geometry.js	2009-07-10 15:32:42 UTC (rev 4339)
@@ -311,6 +311,150 @@
 	}
 };
 
+GeometryArray.prototype.importPoint = function(currentGeometry, featureEpsg){
+	var coordinates = currentGeometry.coordinates;
+
+	this.addMember(geomType.point);
+	
+	this.get(-1).addGeometry();
+	this.getGeometry(-1,-1).addPointByCoordinates(coordinates[0], coordinates[1], coordinates[2]);
+	this.getGeometry(-1,-1).setEpsg(featureEpsg);
+	this.close();
+};
+
+GeometryArray.prototype.importLine = function(currentGeometry, featureEpsg){
+	var coordinates = currentGeometry.coordinates;
+
+	this.addMember(geomType.line);
+	this.get(-1).addGeometry();
+	for (var m = 0; m < coordinates.length; m++) {
+		var currentPoint = coordinates[m];
+		this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+	}
+	this.getGeometry(-1,-1).setEpsg(featureEpsg);
+	this.close();
+};
+
+GeometryArray.prototype.importMultiLine = function(currentGeometry, featureEpsg){
+	var coordinates = currentGeometry.coordinates;
+
+	this.addMember(geomType.line);
+	for (var m = 0; m < coordinates.length; m++) {
+		this.get(-1).addGeometry();
+		var currentLine = coordinates[m];
+		for (var n = 0; n < currentLine.length; n++) {
+			var currentPoint = currentLine[n];
+			this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+		}
+		this.getGeometry(-1,-1).setEpsg(featureEpsg);
+	}
+	this.close();
+};
+
+GeometryArray.prototype.importPolygon = function(currentGeometry, featureEpsg){
+	var coordinates = currentGeometry.coordinates;
+
+	this.addMember(geomType.polygon);
+	for (var m = 0; m < coordinates.length; m++) {
+		this.get(-1).addGeometry();
+		var currentPolygon = coordinates[m];
+		for (var n = 0; n < currentPolygon.length; n++) {
+			var currentPoint = currentPolygon[n];
+			this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+		}
+		this.getGeometry(-1,-1).setEpsg(featureEpsg);
+	}
+	this.close();
+};
+
+GeometryArray.prototype.importMultiPolygon = function(currentGeometry, featureEpsg){
+	var coordinates = currentGeometry.coordinates;
+
+	this.addMember(geomType.polygon);
+	for (var m = 0; m < coordinates.length; m++) {
+		this.get(-1).addGeometry();
+		var currentPolygon = coordinates[m];
+		for (var n = 0; n < currentPolygon.length; n++) {
+			var currentRing = currentPolygon[n];
+			if (n == 0) {
+				for (var p = 0; p < currentRing.length; p++) {
+					var currentPoint = currentRing[p];
+					this.getGeometry(-1, -1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+				}
+			}
+			else {
+				var ring = new Geometry(geomType.polygon);
+				for (var p = 0; p < currentRing.length; p++) {
+					var currentPoint = currentRing[p];
+					ring.addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+				}
+				ring.close();
+				this.getGeometry(-1,-1).addInnerRing(ring);				
+			}
+		}
+		this.getGeometry(-1,-1).setEpsg(featureEpsg);
+	}
+	this.close();
+};
+
+GeometryArray.prototype.importFeature = function(currentFeature){
+	var isFeature = (currentFeature.type == "Feature") ? true : false;
+
+	// add geometry ...
+	if (currentFeature.geometry && isFeature) {
+		var featureEpsg = "EPSG:4326";
+		if (!currentFeature.crs || currentFeature.crs.type !== "name" || !currentFeature.crs.properties.name) {
+			var e = new Mb_warning("SRS not set or unknown in GeoJSON. Using 'EPSG:4326'.");
+		}
+		else {
+			featureEpsg = currentFeature.crs.properties.name;
+		}
+
+		//
+		// GEOMETRY
+		//
+		var currentGeometry = currentFeature.geometry;
+		var geometrytype = currentGeometry.type;
+		switch (geometrytype) {
+			case "Point":
+				this.importPoint(currentGeometry, featureEpsg);
+				break;
+			
+			case "LineString":
+				this.importLine(currentGeometry, featureEpsg);
+				break;
+				
+			case "MultiLineString":
+				this.importMultiLine(currentGeometry, featureEpsg);
+				break;
+			
+			case "Polygon":
+				this.importPolygon(currentGeometry, featureEpsg);
+				break;
+				
+			case "MultiPolygon":
+				this.importMultiPolygon(currentGeometry, featureEpsg);
+				break;
+
+			case "GeometryCollection":
+				var exc = new Mb_exception("Geometry: GeometryCollections are not yet supported");
+				break;
+		}
+	}
+	
+	if (currentFeature.properties) {
+		var properties = currentFeature.properties;
+		// GeometryCollections are NOT YET IMPLEMENTED
+		if (geometrytype != "GeometryCollection") {
+			for (var l in properties) {
+				if (typeof(properties[l]) != "function") {
+					this.get(-1).e.setElement(l, properties[l]);
+				}
+			}
+			this.get(-1).e.setElement("fid", currentFeature.id);
+		}
+	}
+}
 GeometryArray.prototype.importGeoJSON = function (geoJSON) {
 	// you can pass either geoJSON or the evaluated geoJSON string
 	// for backwards compatibility
@@ -322,142 +466,17 @@
 	// FEATURE COLLECTION
 	//
 	var isFeatureCollection = (geoJSON.type == "FeatureCollection") ? true : false;
-	if (isFeatureCollection) {
-		//
-		// FEATURE
-		//
-		var featureArray = geoJSON.features;
-		for (var j = 0; j < featureArray.length; j++) {
-			var currentFeature = featureArray[j];
-			var isFeature = (currentFeature.type == "Feature") ? true : false;
-	
-			// add geometry ...
-			if (currentFeature.geometry && isFeature) {
-				var featureEpsg = "EPSG:4326";
-				if (!currentFeature.crs || currentFeature.crs.type !== "name" || !currentFeature.crs.properties.name) {
-					var e = new Mb_warning("SRS not set or unknown in GeoJSON. Using 'EPSG:4326'.");
-				}
-				else {
-					featureEpsg = currentFeature.crs.properties.name;
-				}
-
-				//
-				// GEOMETRY
-				//
-				var currentGeometry = currentFeature.geometry;
-				var geometrytype = currentGeometry.type;
-				var coordinates = currentGeometry.coordinates;
-				switch (geometrytype) {
-					case "Point":
-						//
-						// POINT
-						//
-						this.addMember(geomType.point);
-						
-						this.get(-1).addGeometry();
-						this.getGeometry(-1,-1).addPointByCoordinates(coordinates[0], coordinates[1], coordinates[2]);
-						this.getGeometry(-1,-1).setEpsg(featureEpsg);
-						this.close();
-						break;
-					
-					case "LineString":
-						//
-						// LINESTRING
-						//
-						this.addMember(geomType.line);
-						this.get(-1).addGeometry();
-						for (var m = 0; m < coordinates.length; m++) {
-							var currentPoint = coordinates[m];
-							this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
-						}
-						this.getGeometry(-1,-1).setEpsg(featureEpsg);
-						this.close();
-						break;
-						
-					case "MultiLineString":
-						//
-						// MULTILINESTRING
-						//
-						this.addMember(geomType.line);
-						for (var m = 0; m < coordinates.length; m++) {
-							this.get(-1).addGeometry();
-							var currentLine = coordinates[m];
-							for (var n = 0; n < currentLine.length; n++) {
-								var currentPoint = currentLine[n];
-								this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
-							}
-							this.getGeometry(-1,-1).setEpsg(featureEpsg);
-						}
-						this.close();
-						break;
-					
-					case "Polygon":
-						//
-						// POLYGON
-						//
-						this.addMember(geomType.polygon);
-						for (var m = 0; m < coordinates.length; m++) {
-							this.get(-1).addGeometry();
-							var currentPolygon = coordinates[m];
-							for (var n = 0; n < currentPolygon.length; n++) {
-								var currentPoint = currentPolygon[n];
-								this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
-							}
-							this.getGeometry(-1,-1).setEpsg(featureEpsg);
-						}
-						this.close();
-						break;
-						
-					case "MultiPolygon":
-						//
-						// MULTIPOLYGON
-						//
-						this.addMember(geomType.polygon);
-						for (var m = 0; m < coordinates.length; m++) {
-							this.get(-1).addGeometry();
-							var currentPolygon = coordinates[m];
-							for (var n = 0; n < currentPolygon.length; n++) {
-								var currentRing = currentPolygon[n];
-								if (n == 0) {
-									for (var p = 0; p < currentRing.length; p++) {
-										var currentPoint = currentRing[p];
-										this.getGeometry(-1, -1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
-									}
-								}
-								else {
-									var ring = new Geometry(geomType.polygon);
-									for (var p = 0; p < currentRing.length; p++) {
-										var currentPoint = currentRing[p];
-										ring.addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
-									}
-									ring.close();
-									this.getGeometry(-1,-1).addInnerRing(ring);				
-								}
-							}
-							this.getGeometry(-1,-1).setEpsg(featureEpsg);
-						}
-						this.close();
-						break;
-	
-					case "GeometryCollection":
-						var exc = new Mb_exception("Geometry: GeometryCollections are not yet supported");
-						break;
-				}
+	switch (geoJSON.type) {
+		case "FeatureCollection" :
+			var featureArray = geoJSON.features;
+			for (var j = 0; j < featureArray.length; j++) {
+				var currentFeature = featureArray[j];
+				this.importFeature(currentFeature);
 			}
-			
-			if (currentFeature.properties) {
-				var properties = currentFeature.properties;
-				// GeometryCollections are NOT YET IMPLEMENTED
-				if (geometrytype != "GeometryCollection") {
-					for (var l in properties) {
-						if (typeof(properties[l]) != "function") {
-							this.get(-1).e.setElement(l, properties[l]);
-						}
-					}
-					this.get(-1).e.setElement("fid", currentFeature.id);
-				}
-			}
-		}
+			break;
+		case "Feature" :
+			this.importFeature(geoJSON);
+			break;
 	}
 	return true;
 }
@@ -751,6 +770,11 @@
 		str += "," + propString;
 	}
 
+	var fid = this.e.getElementValueByName("fid");
+	if (fid) {
+		str += ", \"id\":\"" + fid + "\"";
+	}
+
 	str += "}";
 	
 	return str;



More information about the Mapbender_commits mailing list