Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
TMS layer with custom resolutions not giving the proper coordinates #31
This is not a bug report. It's more of a cry for help
Sorry about posting this here but since I'm dealing with a custom projection I figured out this didn't belong in the LeafletJS forum.
I was a given set of tiles and an OpenLayers map. I wanted to migrate that to LeafletJS.
Although it's a simple TMS layer with the tiles generated in EPSG:900913, I figured that I have a custom set of resolutions. That's why I ended up using the Proj4Leaflet plugin.
I can see the map but zooming in/out doesn't take me to the place where the zoom was made. Also, clicking on the map doesn't return the correct coordinates.
I have set up a demo here: http://queixinhas.com/map_test/
The code is all in this file: http://queixinhas.com/map_test/app2.js
You can see the LeafletJS map and the OpenLayers map.
I thought it was a matter os providing the resolutions array and tile origin but apparently I'm missing something.
Btw, I had to comment line 116 on proj4leaflet.js file because I was getting the "Projected bounds does not match grid at zoom 0" error. This might be the cause of the problem...
Again, sorry for posting this help request here, I'm happy to move it to another place if you wish of course.
Any help would be appreciated, thanks!
As you can see in issue #29, the error message you saw is something we're planning to resolve. On the other hand, before it is addressed, it is crucial that you do not remove that check, or at least provide bounds that actually align with the tiles on all zoom levels.
Usually, the easiest way is to simply calculate the upper bounds by rounding the value up to align with the grid. Pseudo-code/formula:
Also note that this will only work if your zoom levels resolution's are multiples of each other.
Hm, of course I made an error in the formula. Here's a working example built from your code: http://jsfiddle.net/S8FL2/
The only change I made was the TMS upper bound, which I calculated to 9691950.164.
The correct formula should be:
Thank you very much Per! It's working perfectly.
Hope you don't mind I wrote about this and mentioned you and Kartena here: http://jdduarte.com/stories/2013/06/06/leaflet-js-with-custom-projection/