WebWorldWind
WebWorldWind copied to clipboard
Inaccurate 3857 to 4326 conversion causes poor WMTS tile registration
Description
The WWMath.epsg3857ToEpsg4326 doesn't use sufficient precision to convert coordinates correctly. The radius used in the function is 6.3781e6, it should be 6.378137e6 (note the addition of the "3" and "7" digits). The problem is manifest when displaying higher resolution tiles.
The following screen shot shows a blend of two USGS layers. The WMTS topographic layer uses the 3857 projection and you can see the streets are displaced to the west compared the WMS NAIP imagery layer.
Additional Information
Workaround
Applications can override and correct the epsg3857ToEpsg4326 function by running the following function after loading the WebWorldWind library.
WorldWind.WWMath.epsg3857ToEpsg4326 = function (easting, northing) {
var r = 6.378137e6,
latRadians = (Math.PI / 2) - 2 * Math.atan(Math.exp(-northing / r)),
lonRadians = easting / r;
return [
WorldWind.WWMath.clamp(latRadians * WorldWind.Angle.RADIANS_TO_DEGREES, -90, 90),
WorldWind.WWMath.clamp(lonRadians * WorldWind.Angle.RADIANS_TO_DEGREES, -180, 180)
];
};