GeoJSON input should accept 3D coords, p=sgillies, r=me (closes #2070)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9700 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-10-05 09:21:07 +00:00
parent 5fad952e8a
commit 2633f9ba88
2 changed files with 22 additions and 2 deletions

View File

@@ -24,6 +24,13 @@
*/
OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
/**
* APIProperty: ignoreExtraDims
* {Boolean} Ignore dimensions higher than 2 when reading geometry
* coordinates.
*/
ignoreExtraDims: false,
/**
* Constructor: OpenLayers.Format.GeoJSON
* Create a new parser for GeoJSON.
@@ -269,8 +276,9 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
* {<OpenLayers.Geometry>} A geometry.
*/
"point": function(array) {
if(array.length != 2) {
throw "Only 2D points are supported: " + array;
if (this.ignoreExtraDims == false &&
array.length != 2) {
throw "Only 2D points are supported: " + array;
}
return new OpenLayers.Geometry.Point(array[0], array[1]);
},

View File

@@ -409,6 +409,18 @@
t.eq(data[0].bounds.top, 74.0, "read top left bound is correct");
}
function test_Format_GeoJSON_point_extradims(t) {
t.plan(3);
var point_feature_3d = '{"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875, 0.0]}, "type": "Feature", "id": 573, "properties": {"strokeColor": "blue", "title": "Feature 5", "author": "Your Name Here"}}';
p = new OpenLayers.Format.GeoJSON({"ignoreExtraDims": true});
data = p.read(point_feature_3d);
t.eq(data[0].fid, 573, "Fid is correct on point feature");
t.eq(data[0].geometry.x, 94.21875, 'Reading point feature gives correct x');
data = p.read(point_feature_3d, "Feature");
t.eq(data.fid, 573, 'Reading point feature with type gives feature instead of array of features ');
}
</script>
</head>
<body>