Support OGC WKT proj4 def.units and def.to_meter

This commit is contained in:
Torben Barsbsballe
2015-10-06 15:57:01 -07:00
parent da830a7670
commit 7cefe56167
3 changed files with 30 additions and 3 deletions

View File

@@ -55,7 +55,7 @@
"mocha-phantomjs": "3.5.1", "mocha-phantomjs": "3.5.1",
"mustache": "2.1.3", "mustache": "2.1.3",
"phantomjs": "1.9.10", "phantomjs": "1.9.10",
"proj4": "2.3.6", "proj4": "2.3.12",
"resemblejs": "1.2.0", "resemblejs": "1.2.0",
"sinon": "1.10.3", "sinon": "1.10.3",
"slimerjs-edge": "0.10.0-pre-2", "slimerjs-edge": "0.10.0-pre-2",

View File

@@ -153,8 +153,9 @@ ol.proj.Projection = function(options) {
} }
if (options.units === undefined) { if (options.units === undefined) {
var units = def.units; var units = def.units;
if (units === undefined) {
if (def.to_meter !== undefined) { if (def.to_meter !== undefined) {
if (units === undefined ||
ol.proj.METERS_PER_UNIT[units] === undefined) {
units = def.to_meter.toString(); units = def.to_meter.toString();
ol.proj.METERS_PER_UNIT[units] = def.to_meter; ol.proj.METERS_PER_UNIT[units] = def.to_meter;
} }

View File

@@ -495,11 +495,28 @@ describe('ol.proj', function() {
'+lon_0=-110.0833333333333 +k=0.9999375 +x_0=800000.0000101599 ' + '+lon_0=-110.0833333333333 +k=0.9999375 +x_0=800000.0000101599 ' +
'+y_0=99999.99998983997 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 ' + '+y_0=99999.99998983997 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 ' +
'+units=us-ft +no_defs'); '+units=us-ft +no_defs');
proj4.defs('EPSG:4269', 'GEOGCS["NAD83",' +
'DATUM["North_American_Datum_1983",' +
'SPHEROID["GRS 1980",6378137,298.257222101,' +
'AUTHORITY["EPSG","7019"]],' +
'AUTHORITY["EPSG","6269"]],' +
'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' +
'UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],' +
'AUTHORITY["EPSG","4269"]]');
proj4.defs('EPSG:4279', 'GEOGCS["OS(SN)80",DATUM["OS_SN_1980",' +
'SPHEROID["Airy 1830",6377563.396,299.3249646,' +
'AUTHORITY["EPSG","7001"]],' +
'AUTHORITY["EPSG","6279"]],' +
'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' +
'UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],' +
'AUTHORITY["EPSG","4279"]]');
}); });
afterEach(function() { afterEach(function() {
delete proj4.defs['EPSG:26782']; delete proj4.defs['EPSG:26782'];
delete proj4.defs['EPSG:3739']; delete proj4.defs['EPSG:3739'];
delete proj4.defs['EPSG:4269'];
delete proj4.defs['EPSG:4279'];
}); });
it('returns value in meters', function() { it('returns value in meters', function() {
@@ -517,6 +534,15 @@ describe('ol.proj', function() {
expect(epsg3739.getMetersPerUnit()).to.eql(1200 / 3937); expect(epsg3739.getMetersPerUnit()).to.eql(1200 / 3937);
}); });
it('works for proj4js OGC WKT GEOGCS projections', function() {
var epsg4269 = ol.proj.get('EPSG:4269');
expect(epsg4269.getMetersPerUnit()).to.eql(
6378137 * 0.01745329251994328);
var epsg4279 = ol.proj.get('EPSG:4279');
expect(epsg4279.getMetersPerUnit()).to.eql(
6377563.396 * 0.01745329251994328);
});
}); });
}); });