Merge pull request #1566 from twpayne/geoserver-geojson-crs

Parse out-of-spec CRSs generated by GeoServer
This commit is contained in:
Tom Payne
2014-01-21 07:12:13 -08:00
3 changed files with 32 additions and 1 deletions

View File

@@ -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
*/

View File

@@ -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;

View File

@@ -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() {