2

In a leaflet map that uses EPSG 25831 to get WMS request, it works fine to call to "project" function to get UTM coordinates of one coordinates pair that I got from the map in WGS84, but inverse function to "unproject" a pair of coordinates in UTM in order to get this equivalent in WGS84 doesn't work.

The console message is "unproject is not a function"

The example code:

var crs = new L.Proj.CRS('EPSG:25831',
'+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
{
    resolutions: [2000, 1100, 550, 275, 100, 50, 25, 10, 5, 2, 1, 0.5, 0.25]//,
    //origin: [0, 0]
}),
map = new L.Map('map', {
    crs: crs,
    continuousWorld: true
});


L.tileLayer.wms("http://server/service?", {
layers: 'topographic',
format: 'image/png',
transparent: true,
continuousWorld: true
}).addTo(map);

map.setView([41.3, 1], 6);

// UTM to 4326
var point = L.point(4651000,400000);
var newPoint = crs.unproject(point);
console.info(newPoint);

In the other hand, "project" function, works fine:

var testPoint = new L.latLng(42.12, 1);
var geo_point = crs.project(testPoint);
console.info(geo_point);

Versions used are, Leaflet: 0.7.7, proj4leaflet: 0.7.2, proj4: I don't know, it was at the Proj4Leaflet-0.7.2.zip from: github.com/kartena/Proj4Leaflet/releases

Any suggestion?

  • 1
    Can you please specify which versions of Leaflet, proj4 and proj4leaflet you're using? – IvanSanchez Jun 26 '17 at 17:25
  • 1
    Does it work with L.point(400000,4651000)? – AndreJ Jun 26 '17 at 17:34
  • spatialreference.org/ref/epsg/etrs89-utm-zone-31n says the valid projected bounds are (238379.2278, 4265559.3497, 761620.7722, 6914547.3835), which your point is not in. – BradHards Jun 27 '17 at 4:10
  • Versions used are, Leaflet: 0.7.7, proj4leaflet: 0.7.2, proj4: I don't know, it was at the Proj4Leaflet-0.7.2.zip from: github.com/kartena/Proj4Leaflet/releases – Toni BCN Jun 27 '17 at 6:19
  • It doesn't work using L.point(400000,4651000), the same error – Toni BCN Jun 27 '17 at 6:20
1

Finnally a collegue has found the solution. "project" and "unproject" functions are inside a L.Proj.Projection object, so to call unproject, the right way is: crs.projection.unproject(point);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.