2

So i am using leaflet in order to create my project, which is a world map that certain layers would be add on top of it.

I am wondering whether I should change the CRS property of the map object, which is by default EPSG3857. The map I am using as tilelayer is from openstreetmap, whose maps i think are in EPSG3857. However, the layers I want to add on top of the map, are in EPSG 4326 when I view them on QGIS.

For example, this is my map object:

var map = L.map('map').setView([40, 25], 9);
L.tileLayer('http://{s}.tile.openstreetmap.se/hydda/base/{z}/{x}/{y}.png', {
//crs: L.CRS.EPSG4326,
attribution: 'Tiles courtesy of <a href="http://openstreetmap.se/" target="_blank">OpenStreetMap Sweden</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo( map );

and I load the layers from Geoserver, like this:

var randomlayer = L.tileLayer.wms("http://localhost:8080/geoserver/wms", {
layers: 'workspace_name:random-layer',
format: 'image/png',
transparent: true,
version: '1.1.0',
attribution: "myattribution"
});

Leaflet clearly mentions about CRS "Coordinate Reference System to use. Don't change this if you're not sure what it means." and that EPSG3857 is "The most common CRS for online maps, used by almost all free and commercial tile providers. Uses Spherical Mercator projection. Set in by default in Map's crs option."

So basically, should I change the crs property of my map object, aka add:

crs: L.CRS.EPSG4326,

on it, in order for it to be the same as the layers, or should I leave it as default which I think is the same as the map tilelayer?

2 Answers 2

4

Do read the Leaflet tutorial on using WMS - it specifically addresses how to use WMS services in other projections.

Also note that you can not have raster layers in different CRSs in Leaflet. It's simply not supported due to the complexity of on-the-fly raster reprojection.

0

The best thing is to keep things simple. Most of all tile provider use 3857 and the simple way is to publish wms also in 3857. For wms server like geoserver is not big deal, he will give you wms in every projection you want.

Your Answer

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

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