Skip to content

Incorrect Web Mercator transforms with newest versions of proj4js #1526

Open
@geographika

Description

@geographika

It looks like there was a change between proj4js 2.3.15 and 2.3.16 that has broken EPSG:4326 to EPSG:3857 transformations:

        var pt = new OpenLayers.Geometry.Point(-898447, 6907203);
        var epsg4326 = new OpenLayers.Projection("EPSG:4326");
        var epsg3857 = new OpenLayers.Projection("EPSG:3857");
        pt.transform(epsg3857, epsg4326);
        console.log(pt.x);
        console.log(pt.y);

        expect(Math.round(pt.x)).toEqual(-8);
        expect(Math.round(pt.y)).toEqual(53);

In 2.3.16 and later the results are:

        // proj4 - 2.3.16.js
        // -0.14086354683193542
        // 0.9178388206728668
        // console.log(JSON.stringify(proj4.defs["EPSG:4326"]))
        // { "title": "WGS 84 (long/lat)", "projName": "longlat", "ellps": "WGS84", "datumCode": "WGS84", "units": "degrees", "k0": 1, "axis": "enu" }
        // console.log(JSON.stringify(proj4.defs["EPSG:3857"]))
        // { "title": "WGS 84 / Pseudo-Mercator", "projName": "merc", "a": 6378137, "b": 6378137, "lat_ts": 0, "long0": 0, "x0": 0, "y0": 0, "k0": 1, "units": "m", "datumCode": "none", "no_defs": true, "axis": "enu" }

In 2.3.15 they are:

        // proj4-2.3.15
        // -8.070886720713318
        // 52.588290697820085
        // console.log(JSON.stringify(proj4.defs["EPSG:4326"]))
        // { "title": "WGS 84 (long/lat)", "projName": "longlat", "ellps": "WGS84", "datumCode": "WGS84", "units": "degrees", "a": 6378137, "rf": 298.257223563, "ellipseName": "WGS 84", "b": 6356752.314245179, "a2": 40680631590769, "b2": 40408299984661.445, "es": 0.006694379990141316, "e": 0.08181919084262149, "ep2": 0.006739496742276434, "k0": 1, "axis": "enu", "datum": { "datum_type": 4, "a": 6378137, "b": 6356752.314245179, "es": 0.006694379990141316, "ep2": 0.006739496742276434 } }
        // console.log(JSON.stringify(proj4.defs["EPSG:3857"]))
        // {"title":"WGS 84 / Pseudo-Mercator","projName":"merc","a":6378137,"b":6378137,"lat_ts":0,"long0":0,"x0":0,"y0":0,"k0":1,"units":"m","datumCode":"none","no_defs":true,"sphere":true,"a2":40680631590769,"b2":40680631590769,"es":0,"e":0,"ep2":0,"axis":"enu","datum":{"datum_type":5,"a":6378137,"b":6378137,"es":0,"ep2":0}}

However proj4js works fine independently of ol2:


        var toProj = proj4('EPSG:4326');
        var fromProj = proj4('EPSG:3857');
        var res = proj4(fromProj, toProj, [-898447, 6907203]);
        expect(Math.round(res[0])).toEqual(-8);
        expect(Math.round(res[1])).toEqual(53);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions