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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Dec 12 11:45:44 EST 2007


Author: christoph
Date: 2007-12-12 11:45:44 -0500 (Wed, 12 Dec 2007)
New Revision: 1917

Modified:
   trunk/mapbender/http/javascripts/geometry.js
Log:
added function import geoJSON

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2007-12-12 16:37:54 UTC (rev 1916)
+++ trunk/mapbender/http/javascripts/geometry.js	2007-12-12 16:45:44 UTC (rev 1917)
@@ -345,6 +345,124 @@
 	return str;
 }
 
+GeometryArray.prototype.importGeoJSON = function (geoJSON) {
+	var isFeatureCollection = false;
+	//
+	// FEATURE COLLECTION
+	//
+	for (var i in geoJSON) {
+		if (typeof(geoJSON[i]) != "function") {
+			switch (i) {
+				case "type":
+					isFeatureCollection = (geoJSON[i] == "FeatureCollection") ? true : false;
+					break;
+				case "features":
+					if (isFeatureCollection) {
+						
+						//
+						// FEATURE
+						//
+						var featureArray = geoJSON[i];
+						for (var j = 0; j < featureArray.length; j++) {
+							var currentFeature = featureArray[j];
+							var isFeature = false;
+
+							for (var k in currentFeature) {
+								if (typeof(currentFeature[k]) != "function") {
+									var geometrytype;
+
+									switch(k) {
+										case "type":
+											isFeature = (currentFeature[k] == "Feature") ? true : false;
+											break;
+
+										case "properties":
+											var properties = currentFeature[k];
+											
+											// 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]);
+													}
+												}
+											}
+											break;
+										
+										case "geometry":
+											if (isFeature) {
+
+												//
+												// GEOMETRY
+												//
+												var currentGeometry = currentFeature[k];
+												for (var l in currentGeometry) {
+													
+													if (typeof(currentGeometry[l]) != "function") {
+														if (l == "type") {
+															geometrytype = currentGeometry[l];
+														}
+														else if (l == "coordinates") {
+															var coordinates = currentGeometry[l];
+															switch (geometrytype) {
+																case "Point":
+																	//
+																	// POINT
+																	//
+																	this.addMember(geomType.point);
+																	
+																	this.get(-1).addGeometry();
+																	this.getGeometry(-1,-1).addPointByCoordinates(coordinates[0], coordinates[1]);
+																	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]);
+																	}
+																	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]);
+																		}
+																	}
+																	this.close();
+																	break;
+						
+																case "GeometryCollection":
+																	var exc = new Mb_exception("Geometry: GeometryCollections are not yet supported");
+																	break;
+															}
+														}
+													}
+												}
+											}
+									}
+								}
+							}
+						}
+					}
+			}
+		}
+	}
+}
+
 GeometryArray.prototype.toString = function () {
 	var str = "{\"type\": \"FeatureCollection\", \"features\": [";
 



More information about the Mapbender_commits mailing list