kartena / Proj4Leaflet

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

Question Getting Started #86

Closed avipersin closed 9 years ago

avipersin commented 9 years ago

This is not an issue, just a question.

I'm trying to use this (http://spatialreference.org/ref/epsg/4326/) full world projection with this (http://{s}.tile.osm.org/{z}/{x}/{y}.png) osm tile layer.

So far I have this but its not displaying the right projection. Also when I zoom in or out its giving me invalid tile requests, returning 404s. Probably something I'm doing wrong as it's my first time experimenting with this.

var crs = new L.Proj.CRS('EPSG:4326', "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", { resolutions: [ 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5 ], }), map = new L.Map('map', { crs: crs, continuousWorld: true, worldCopyJump: false });

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { maxZoom: 14, minZoom: 0, continuousWorld: true, attribution: 'Map data © OpenStreetMap contributors, Imagery © 2013 Kartena' }).addTo(map);

map.setView([57.704, 11.965], 0);

perliedman commented 9 years ago

Unfortunately, the tile set you're using must be rendered with the same projection as you're trying to use. OpenStreetMap's tiles are rendered in spherical Mercator (EPSG:3857), so you can't use EPSG:4326 with it.

Also note that EPSG:4326 is built in to Leaflet's core, so you don't need Proj4Leaflet to use this projection, although you can if you want.

avipersin commented 9 years ago

Thanks for your response!

Do you know if there are any open source full world tile layers that would support a robinson-like projection like this: http://spatialreference.org/ref/esri/54030/ and weather leaflet would support this?

I'm trying to find a tile layer with a projection that doesn't emphasize the poles as much.

perliedman commented 9 years ago

@avipersin sorry, no, can't say I've heard of one. Tile sets in projections other than spherical mercator are sort of rare, and most of them are use some local projection, typically from different countries' government agencies or similar. Can't remember seeing anything global except for spherical Mercator and EPSG:4326.

Depending on your requirements, you might want to look at generating your own tiles. I've written a blog post on using TileMill for other projections than spherical Mercator, that you might find useful: http://blog.kartena.se/using-tilemill-without-spherical-mercator/

avipersin commented 9 years ago

Okay, thanks I will have a look at your blog post.