[Mapbender-commits] r3566 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Feb 18 03:52:26 EST 2009
Author: christoph
Date: 2009-02-18 03:52:26 -0500 (Wed, 18 Feb 2009)
New Revision: 3566
Modified:
trunk/mapbender/http/javascripts/geometry.js
Log:
added multigeometry support in geojson export
Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js 2009-02-18 08:50:24 UTC (rev 3565)
+++ trunk/mapbender/http/javascripts/geometry.js 2009-02-18 08:52:26 UTC (rev 3566)
@@ -461,7 +461,14 @@
}
}
+GeometryArray.prototype.featureToString = function (i) {
+ var str = "{\"type\": \"FeatureCollection\", \"features\": [";
+ str += this.get(i).toString();
+ str += "]}";
+ return str;
+};
+
GeometryArray.prototype.toString = function () {
var str = "{\"type\": \"FeatureCollection\", \"features\": [";
@@ -767,15 +774,55 @@
if (epsg) {
str += "\"crs\": {\"type\": \"EPSG\", \"properties\": {\"code\": " + epsg + "}}, ";
}
- str += "\"geometry\": ";
+ str += "\"geometry\": {";
+ var len = this.count();
+
+ switch (this.geomType) {
+ case geomType.polygon:
+ if (len > 1) {
+ str += "\"type\": \"MultiPolygon\", ";
+ }
+ else {
+ str += "\"type\": \"Polygon\", ";
+ }
+ break;
+ case geomType.line:
+ if (len > 1) {
+ str += "\"type\": \"MultiLineString\", ";
+ }
+ else {
+ str += "\"type\": \"LineString\", ";
+ }
+ break;
+ case geomType.point:
+ if (len > 1) {
+ str += "\"type\": \"MultiPoint\", ";
+ }
+ else {
+ str += "\"type\": \"Point\", ";
+ }
+ break;
+ }
+
+ str += "\"coordinates\": "
// geometries
- for (var i = 0, len = this.count(); i < len; i++) {
- if (i > 0) {
- str += ",";
- }
- str += this.get(i).toString();
+ if (len > 1) {
+ str += "[";
+ for (var i = 0; i < len; i++) {
+ if (i > 0) {
+ str += ",";
+ }
+ str += this.get(i).toString();
+ }
+ str += "]";
}
+ else {
+ str += this.get(0).toString();
+ }
+
+ str += "}";
+
// this closing curly bracket is added in toString()
// str += "}";
@@ -1255,15 +1302,8 @@
Geometry.prototype.toString = function () {
var str = "";
-
- var epsgStr = "";
- var epsg = this.getEpsg();
- if (epsg) {
- epsgStr = "\"crs\": {\"type\": \"EPSG\", \"properties\": {\"code\": " + epsg + "}}, ";
- }
-
if (this.geomType == geomType.polygon) {
- str += "{\"type\": \"Polygon\", " + epsgStr + "\"coordinates\": [[";
+ str += "[[";
for (var i = 0; i < this.count(); i++) {
if (i > 0) {
str += ", ";
@@ -1284,22 +1324,20 @@
}
}
}
- str += "]]}";
+ str += "]]";
}
else if (this.geomType == geomType.line) {
- str += "{\"type\": \"LineString\", " + epsgStr + "\"coordinates\": [";
+ str += "[";
for (var i = 0; i < this.count(); i++) {
if (i > 0) {
str += ", ";
}
str += this.get(i).toString();
}
- str += "]}";
+ str += "]";
}
else if (this.geomType == geomType.point) {
- str += "{\"type\": \"Point\", " + epsgStr + "\"coordinates\": ";
str += this.get(0).toString();
- str += "}";
}
return str;
More information about the Mapbender_commits
mailing list