4

I am new to leaflet.

I am trying to change Leaflet project to EPSG:32624 but it is not working. The map is not showing neither the marker.

var crs = new L.Proj.CRS('EPSG:32634',
    '+proj=utm +zone=34  +datum=WGS84 +units=m +no_defs',
    {
        resolutions: [
            8192, 4096, 2048, 1024, 512, 256, 128,
            64, 32, 16, 8, 4, 2, 1, 0.5
        ],
        //transformation: new L.Transformation(1, XOrigin, -1, YOrigin),
        origin: [0, 0]
        //bounds: L.bounds([218128.7031, 6126002.9379], [1083427.2970, 7692850.9468])
    });
    map = new L.Map('map', {
        crs: crs
    });

L.tileLayer('https://api.geosition.com/tile/osm-bright-3006/{z}/{x}/{y}.png', {
    maxZoom: 14,
    minZoom: 0,
    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>, Imagery &copy; <a href="http://www.kartena.se/">Kartena</a>'
}).addTo(map);

map.setView([375776.24622049765, 4509140.3932434358], 7);
var m = new L.marker([375776.24622049765, 4509140.3932434358]).addTo(map);
console.log(m);

1 Answer 1

1

Looks like this question was overlooked despite the fact that errors are quite obvious.

Base of the code is taken from Proj4Leaflet plugin example http://www.liedman.net/Proj4Leaflet/examples/osm-tiled/, but then there are several errors that cause problems:

  1. Orginal example uses CRS EPSG 3009 (Sweden, UTM zone 34), so this is CRS of the source map. Code above uses different CRS EPSG 32634, which is for UTM zone 33 and so cannot work here.
  2. map.setView call uses projected coordinates instead of geographic ones. Correct call would be map.setView(map.unproject([375776.24622049765, 4509140.3932434358]), 7); Same goes for marker definition call.
  3. Marker definitionn call is wrong, it should be either var m = new L.Marker(... or var m = L.marker(...
  4. Projected coordinate [375776.24622049765, 4509140.3932434358] is completely off and outside of area covered by EPSG 32634. LatLong is [-40.72,19.53], which is below Africa.
1
  • EPSG 32634 is UTM 34 (last two digits are the zone ) with datum WGS 84 ( EPSG:4326 which is assumed equivalent to EPSG:3009)
    – radouxju
    Commented Jun 14, 2023 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.