From f9e0167b669754a214e3ced67f994e68f4b1ea74 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 21 Jan 2014 16:02:02 +0100 Subject: [PATCH] Parse out-of-spec CRSs generated by GeoServer --- externs/geojson.js | 17 ++++++++++++++++- src/ol/format/geojsonformat.js | 4 ++++ test/spec/ol/format/geojsonformat.test.js | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/externs/geojson.js b/externs/geojson.js index 0352da86e2..46869a4ff2 100644 --- a/externs/geojson.js +++ b/externs/geojson.js @@ -34,12 +34,27 @@ var GeoJSONCRS = function() {}; /** - * @type {!GeoJSONCRSName|!GeoJSONLink} + * @type {!GeoJSONCRSCode|!GeoJSONCRSName|!GeoJSONLink} */ GeoJSONCRS.prototype.properties; +/** + * `GeoJSONCRSCode` is not part of the GeoJSON specification, but is generated + * by GeoServer. + * @constructor + */ +var GeoJSONCRSCode = function() {}; + + +/** + * @type {string} + */ +GeoJSONCRSName.prototype.code; + + + /** * @constructor */ diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index b9f3b59886..daaa6a242d 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -370,6 +370,10 @@ ol.format.GeoJSON.prototype.readProjection = function(object) { if (goog.isDefAndNotNull(crs)) { if (crs.type == 'name') { return ol.proj.get(crs.properties.name); + } else if (crs.type == 'EPSG') { + // 'EPSG' is not part of the GeoJSON specification, but is generated by + // GeoServer. + return ol.proj.get('EPSG:' + crs.properties.code); } else { goog.asserts.fail(); return null; diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index d9248b6661..deef17769d 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -391,6 +391,18 @@ describe('ol.format.GeoJSON', function() { }); + it('can read out-of-specification CRS generated by GeoServer', function() { + var json = { + crs: { + type: 'EPSG', + properties: { + code: '4326' + } + } + }; + expect(format.readProjection(json)).to.be(ol.proj.get('EPSG:4326')); + }); + }); describe('#writeFeatures', function() {