Skip to content

Commit

Permalink
fix(parser): GeoJsonParser add legacy identifier to fct readCRS()
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff authored and gchoqueux committed Feb 25, 2022
1 parent 1db1ae7 commit a0195c6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Parser/GeoJsonParser.js
Expand Up @@ -8,14 +8,15 @@ function readCRS(json) {
if (json.crs.type.toLowerCase() == 'epsg') {
return `EPSG:${json.crs.properties.code}`;
} else if (json.crs.type.toLowerCase() == 'name') {
const epsgIdx = json.crs.properties.name.toLowerCase().indexOf('epsg:');
if (epsgIdx >= 0) {
// authority:version:code => EPSG:[...]:code
const codeStart = json.crs.properties.name.indexOf(':', epsgIdx + 5);
if (json.crs.properties.name.toLowerCase().includes('epsg:')) {
// OGC CRS URN: urn:ogc:def:crs:authority:version:code => EPSG:[...]:code
// legacy identifier: authority:code => EPSG:code
const codeStart = json.crs.properties.name.lastIndexOf(':');
if (codeStart > 0) {
return `EPSG:${json.crs.properties.name.substr(codeStart + 1)}`;
}
}
throw new Error(`Unsupported CRS authority '${json.crs.properties.name}'`);
}
throw new Error(`Unsupported CRS type '${json.crs}'`);
}
Expand Down

0 comments on commit a0195c6

Please sign in to comment.