Setup projection on Leafletjs
Asked Answered
O

1

6

Im using an Leafletjs for an home project(This is have it looks, right now. But i can't find have to setup the projection, i have found it for OpenLayers, which looks like this:

// Openlayers settings 
    //var defaultMaxExtent = new OpenLayers.Bounds(427304, 6032920, 927142, 6485144); 
    var defaultMaxExtent = new OpenLayers.Bounds(427304, 6032920, 927142, 6485144);

    var defaultProjection = "EPSG:25832";
    var defaultUnits = "Meters";
    var defaultResolutions = new Array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024);
    var defaultExtent = new OpenLayers.Bounds(215446, 2103547, 706886, 6203897); //this extent is used when the page is loaded.
    //var defaultExtent = new OpenLayers.Bounds(705446, 6203547, 706886, 6203897); //this extent is used when the page is loaded.
    map = new OpenLayers.Map('map', { projection: defaultProjection, units: defaultUnits, maxExtent: defaultMaxExtent, resolutions: defaultResolutions, controls: [

        // Hide controls by default
    new OpenLayers.Control.Navigation({ wheelChange: HideInfoBox() }),
    new OpenLayers.Control.ArgParser(),
    new OpenLayers.Control.Attribution()]
    });
    layer = new OpenLayers.Layer.WMS("kort", "http://serverAddress?", { nbr: '', username: 'admin', password: 'adminadmin', layers: 'Overlayer', format: 'image/png' });

Anybody that can help me?

Update: I have tried to take the standard projection from Leaflet and customized it, like so

L.CRS.EPSG25832 = L.extend({}, L.CRS, {
    code: 'EPSG:25832',
    projection: L.Projection.SphericalMercator,
    transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5),

    project: function (latlng) { // (LatLng) -> Point
        var projectedPoint = this.projection.project(latlng),
                earthRadius = 6378137;
        return projectedPoint.multiplyBy(earthRadius);
    }
});

Now the projection is correct. But the problem now is the coordinates is wrong, so forexample if i get the coordinates from Leaflet, Kolding is now loacted in mid france not in Denmark.

Outwardly answered 5/3, 2013 at 12:49 Comment(2)
Maybe sources help: github.com/Leaflet/Leaflet/blob/master/src/map/Map.js#L10 and github.com/Leaflet/Leaflet/tree/master/src/geo/crs.Ween
@flup The should be stretch more like this picture from the source dl.dropbox.com/u/2230967/DKv2.PNGOutwardly
O
7

I found the solution to the problem myself. By doing this instead:

var crs = L.CRS.proj4js('EPSG:25832', '+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs', new L.Transformation(0.5 / (Math.PI * L.Projection.Mercator.R_MAJOR), 0.5, -0.5 / (Math.PI * L.Projection.Mercator.R_MINOR), 0.5));

  var map = new L.Map('Krak-Map', { center: new L.LatLng(latitude, longitude), zoom: 17, crs: crs });
Outwardly answered 6/3, 2013 at 9:50 Comment(2)
Hi Morten, I have similar problems here with other projection: #31071449 Question: Where did you go to find out the transformation part?Serajevo
So was the problem that EPSG:25832 wasn't supported but you corrected it by adding utm + zone 32 and so on?Boony

© 2022 - 2024 — McMap. All rights reserved.