From b0f71c270237f020f39a93178d810b674602c87e Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 3 Apr 2009 20:26:35 +0000 Subject: [PATCH] Fix for GeoJSON + Reprojection problems for GeometryCollections. Original patch/ diagnosis by ibolmo, refactored by me. Includes manual test. (Closes #2024) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9181 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/GeoJSON.js | 7 +- .../manual/geojson-geomcoll-reprojection.html | 74 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/manual/geojson-geomcoll-reprojection.html diff --git a/lib/OpenLayers/Format/GeoJSON.js b/lib/OpenLayers/Format/GeoJSON.js index d70b9fa2c4..5a0bd39575 100644 --- a/lib/OpenLayers/Format/GeoJSON.js +++ b/lib/OpenLayers/Format/GeoJSON.js @@ -212,7 +212,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { if (obj == null) { return null; } - var geometry; + var geometry, collection = false; if(obj.type == "GeometryCollection") { if(!(obj.geometries instanceof Array)) { throw "GeometryCollection must have geometries array: " + obj; @@ -225,6 +225,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { ); } geometry = new OpenLayers.Geometry.Collection(components); + collection = true; } else { if(!(obj.coordinates instanceof Array)) { throw "Geometry must have coordinates array: " + obj; @@ -241,7 +242,9 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { throw err; } } - if (this.internalProjection && this.externalProjection) { + // We don't reproject collections because the children are reprojected + // for us when they are created. + if (this.internalProjection && this.externalProjection && !collection) { geometry.transform(this.externalProjection, this.internalProjection); } diff --git a/tests/manual/geojson-geomcoll-reprojection.html b/tests/manual/geojson-geomcoll-reprojection.html new file mode 100644 index 0000000000..e82e08a330 --- /dev/null +++ b/tests/manual/geojson-geomcoll-reprojection.html @@ -0,0 +1,74 @@ + + + + + + + + + +
+ +