kartena / Proj4Leaflet

Smooth Proj4js integration with Leaflet.
http://kartena.github.io/Proj4Leaflet/
BSD 2-Clause "Simplified" License
590 stars 173 forks source link

EPSG:2263 does not seem to project correctly #113

Closed arctelix closed 8 years ago

arctelix commented 8 years ago

For some reason EPSG:2263 projections seem to be incorrect. The tile server works properly at all zoom levels as configured. However, the tiles are rendering at the incorrect latLng.

I feel like i have tried everything possible here, any ideas appreciated.

Current Proj4Leaflet config:

var empireStateBldg = new L.latLng(40.7484444, -73.9878441),
// Bounds from server: Top left (tl) works as origin.
tl = L.point(700000.0,  440000.0),
br = L.point(1366666.6683464567, -4444.4455643044785),
tr = L.point(1366666.6683464567, 440000.0),
bl = L.point(700000.0, -4444.4455643044785);

var nycCrs = new L.Proj.CRS("EPSG:2263",
    "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 " +
    "+lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 " +
    "+units=us-ft +no_defs",
    {
    resolutions: [
        434.0277788713911, 303.8194452099737, 222.22222278215222, 111.11111139107611, 55.555555695538054,
        27.777777847769027, 13.888888923884513, 6.944444461942257, 3.4722222309711284, 1.7361111154855642,
        0.8680555577427821, 0.43402777887139105, 0.21701388943569552, 0.10850694471784776
    ],
    origin: [tl.x, tl.y],

    //https://github.com/kartena/Proj4Leaflet/issues/4
    // (1, -x_origin, -1, y_origin)
    // transformation seems to have no effect
    transformation:new L.Transformation(1, -700000.0, -1, 440000.0),
    })

var map = L.map('map', {
    crs:nycCrs,
});

L.tileLayer.wms('http://maps.nyc.gov/geowebcache/service/wms/', {
    layers: 'dtm',
    format: 'image/png',
    maxZoom: nycCrs.options.resolutions.length,
    minZoom: 0,
    continuousWorld: true,
    tileSize: 512,
    worldCopyJump: false
}).addTo(map);

map.setView(empireStateBldg, 0);

L.grid().addTo(map);

L.marker(nycCrs.projection.unproject(tl)).addTo(map);
L.marker(nycCrs.projection.unproject(tr)).addTo(map);
L.marker(nycCrs.projection.unproject(bl)).addTo(map);
L.marker(nycCrs.projection.unproject(br)).addTo(map);
L.marker(empireStateBldg).addTo(map);

var popup = L.popup();

function onMapClick(e) {
    popup
        .setLatLng(e.latlng)
        .setContent("You clicked the map at " + e.latlng.toString())
        .openOn(map);
}

map.on('click', onMapClick);
arctelix commented 8 years ago

The issue was due to incorrect proj4js data from epsg.io. I used the data from spatialreference.org and it worked perfectly. Is there perhapse another setting for units. It appears the difference was with units=us-ft vs datum=NAD83 +to_meter=0.3048006096012192

epsg.io provided this (incorrect): "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs"

spatialreference.org provided this (correct): "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"

perliedman commented 8 years ago

Thanks for reporting, and thanks for also providing a fix.

I'm not sure, but it sounds possible this would be an issue in proj4js, interpreting the +units parameter the wrong way.

Do you know which proj4js version your using? If not latest, I would try that. The both proj4 strings look like they should be equivalent.