From 893966dfae6e9f2e376e08eccbf6b4474de56cd7 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 19 Dec 2012 22:23:45 +0100 Subject: [PATCH] 'm' and 'Meters' in OpenLayers.INCHES_PER_UNIT are not the same OpenLayers.INCHES_PER_UNIT.m should equal OpenLayers.INCHES_PER_UNIT.Meters, just like OpenLayers.INCHES_PER_UNIT.km should equal OpenLayers.Inches_PER_UNIT.Kilometers. This confusion probably comes from mixing International inches with US Survey inches when compiling the unit conversion list (1 meter is 39.37007874 International inches, but 39.37 US Survey inches. It may not be obvious, but 'inches'/'Inch' in OpenLayers means US Survey inch, and 'IInch' means International inch). This change also fixes offsets caused by incorrect resolution calculations in OpenLayers.Format.WMTSCapabilities. --- lib/OpenLayers/Util.js | 4 ++-- tests/Util.html | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index f4948edc37..a8c4a5de42 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -962,8 +962,8 @@ OpenLayers.INCHES_PER_UNIT = { 'inches': 1.0, 'ft': 12.0, 'mi': 63360.0, - 'm': 39.3701, - 'km': 39370.1, + 'm': 39.37, + 'km': 39370, 'dd': 4374754, 'yd': 36 }; diff --git a/tests/Util.html b/tests/Util.html index 4a7507e451..3972d68d84 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -706,6 +706,12 @@ t.ok(OpenLayers.String.startsWith(id, "chicken"), "OpenLayers.Util.createUniqueID starts id correctly"); } + + function test_units(t) { + t.plan(2); + t.eq(OpenLayers.INCHES_PER_UNIT.m, OpenLayers.INCHES_PER_UNIT.Meter, 'Same inches per m and Meters'); + t.eq(OpenLayers.INCHES_PER_UNIT.km, OpenLayers.INCHES_PER_UNIT.Kilometer, 'Same inches per km and Kilometers'); + } function test_Util_normalizeScale(t) { t.plan(2); @@ -728,7 +734,7 @@ var scale = 1/150000000; var resolution = OpenLayers.Util.getResolutionFromScale(scale, 'm'); - t.eq(resolution.toFixed(6), "52916.638092", "Calculated correct resolution for " + scale); + t.eq(resolution.toFixed(6), "52916.772500", "Calculated correct resolution for " + scale); scale = 150000000; resolution = OpenLayers.Util.getResolutionFromScale(scale);