proj4
Version:
Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.
36 lines (35 loc) • 751 B
JavaScript
var defs = require('./defs');
var wkt = require('./wkt');
var projStr = require('./projString');
function testObj(code){
return typeof code === 'string';
}
function testDef(code){
return code in defs;
}
function testWKT(code){
var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
return codeWords.reduce(function(a,b){
return a+1+code.indexOf(b);
},0);
}
function testProj(code){
return code[0] === '+';
}
function parse(code){
if (testObj(code)) {
//check to see if this is a WKT string
if (testDef(code)) {
return defs[code];
}
else if (testWKT(code)) {
return wkt(code);
}
else if (testProj(code)) {
return projStr(code);
}
}else{
return code;
}
}
module.exports = parse;