mirror of
https://github.com/proj4js/proj4js.git
synced 2026-02-01 17:20:57 +00:00
insensative matching
This commit is contained in:
parent
fa921845f4
commit
9625c69842
@ -4,7 +4,7 @@ var projections = require('./projections');
|
||||
var deriveConstants = require('./deriveConstants');
|
||||
var Datum = require('./constants/Datum');
|
||||
var datum = require('./datum');
|
||||
|
||||
var match = require('./match');
|
||||
|
||||
function Projection(srsCode,callback) {
|
||||
if (!(this instanceof Projection)) {
|
||||
@ -26,7 +26,7 @@ function Projection(srsCode,callback) {
|
||||
return;
|
||||
}
|
||||
if (json.datumCode && json.datumCode !== 'none') {
|
||||
var datumDef = Datum[json.datumCode];
|
||||
var datumDef = match(Datum, json.datumCode);
|
||||
if (datumDef) {
|
||||
json.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
|
||||
json.ellps = datumDef.ellipse;
|
||||
|
||||
@ -212,4 +212,4 @@ exports.sphere = {
|
||||
a: 6370997.0,
|
||||
b: 6370997.0,
|
||||
ellipseName: "Normal Sphere (r=6370997)"
|
||||
};
|
||||
};
|
||||
|
||||
@ -6,7 +6,7 @@ var RA4 = 0.04722222222222222222;
|
||||
var RA6 = 0.02215608465608465608;
|
||||
var EPSLN = 1.0e-10;
|
||||
var Ellipsoid = require('./constants/Ellipsoid');
|
||||
|
||||
var match = require('./match');
|
||||
exports.eccentricity = function(a, b, rf, R_A) {
|
||||
var a2 = a * a; // used in geocentric
|
||||
var b2 = b * b; // used in geocentric
|
||||
@ -26,11 +26,12 @@ exports.eccentricity = function(a, b, rf, R_A) {
|
||||
ep2: ep2
|
||||
};
|
||||
};
|
||||
var wms84 = match(Ellipsoid, 'WGS84');
|
||||
exports.sphere = function (a, b, rf, ellps, sphere) {
|
||||
if (!a) { // do we have an ellipsoid?
|
||||
var ellipse = Ellipsoid[ellps];
|
||||
var ellipse = match(Ellipsoid, ellps);
|
||||
if (!ellipse) {
|
||||
ellipse = Ellipsoid.WGS84;
|
||||
ellipse = wms84;
|
||||
}
|
||||
a = ellipse.a;
|
||||
b = ellipse.b;
|
||||
|
||||
18
lib/match.js
Normal file
18
lib/match.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = match;
|
||||
var ignoredChar = /[\s_\-\/\(\)]/g;
|
||||
function match(obj, key) {
|
||||
if (obj[key]) {
|
||||
return obj[key];
|
||||
}
|
||||
var keys = Object.keys(obj);
|
||||
var lkey = key.toLowerCase().replace(ignoredChar, '');
|
||||
var i = -1;
|
||||
var testkey, processedKey;
|
||||
while (++i < keys.length) {
|
||||
testkey = keys[i];
|
||||
processedKey = testkey.toLowerCase().replace(ignoredChar, '');
|
||||
if (processedKey === lkey) {
|
||||
return obj[testkey];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ function testObj(code){
|
||||
function testDef(code){
|
||||
return code in defs;
|
||||
}
|
||||
var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
|
||||
var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
|
||||
|
||||
function testWKT(code){
|
||||
return codeWords.some(function (word) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var D2R = 0.01745329251994329577;
|
||||
var PrimeMeridian = require('./constants/PrimeMeridian');
|
||||
var units = require('./constants/units');
|
||||
|
||||
var match = require('./match');
|
||||
module.exports = function(defData) {
|
||||
var self = {};
|
||||
var paramObj = defData.split('+').map(function(v) {
|
||||
@ -85,15 +85,17 @@ module.exports = function(defData) {
|
||||
},
|
||||
units: function(v) {
|
||||
self.units = v;
|
||||
if (units[v]) {
|
||||
self.to_meter = units[v].to_meter;
|
||||
var unit = match(units, v);
|
||||
if (unit) {
|
||||
self.to_meter = unit.to_meter;
|
||||
}
|
||||
},
|
||||
from_greenwich: function(v) {
|
||||
self.from_greenwich = v * D2R;
|
||||
},
|
||||
pm: function(v) {
|
||||
self.from_greenwich = (PrimeMeridian[v] ? PrimeMeridian[v] : parseFloat(v)) * D2R;
|
||||
var pm = match(PrimeMeridian, v);
|
||||
self.from_greenwich = (pm ? pm : parseFloat(v)) * D2R;
|
||||
},
|
||||
nadgrids: function(v) {
|
||||
if (v === '@null') {
|
||||
|
||||
@ -36,6 +36,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"mgrs": "~0.0.2",
|
||||
"wkt-parser": "^1.0.2"
|
||||
"wkt-parser": "^1.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user