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:
@@ -24,6 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
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
|
* Constructor: OpenLayers.Format.GeoJSON
|
||||||
* Create a new parser for GeoJSON.
|
* Create a new parser for GeoJSON.
|
||||||
@@ -269,8 +276,9 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
|||||||
* {<OpenLayers.Geometry>} A geometry.
|
* {<OpenLayers.Geometry>} A geometry.
|
||||||
*/
|
*/
|
||||||
"point": function(array) {
|
"point": function(array) {
|
||||||
if(array.length != 2) {
|
if (this.ignoreExtraDims == false &&
|
||||||
throw "Only 2D points are supported: " + array;
|
array.length != 2) {
|
||||||
|
throw "Only 2D points are supported: " + array;
|
||||||
}
|
}
|
||||||
return new OpenLayers.Geometry.Point(array[0], array[1]);
|
return new OpenLayers.Geometry.Point(array[0], array[1]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -409,6 +409,18 @@
|
|||||||
t.eq(data[0].bounds.top, 74.0, "read top left bound is correct");
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user