0

I am new to Leaflet and I have a large image which I have been attempting to break up into tiles and save them using the correct filenames so that they can be displayed using Leaflet's tileLayer. I am trying to keep it simple first by breaking up the large image into just one layer of tiles. But I have not been able to get Leaflet to load the tiles correctly. Can anyone show me how a one layer custom tile should be set up in Leaflet?

1

When your map is not georeferenced, you can follow this tutorial first for georeferencing it.

Now you can use gdal2tiles.py to create the tiles for your image. As a result you get a folder with all tiles from your image. gdal2tiles can be installed e.g. through the OSGeo4W Installer.

Now you can add this folder to your map with only some code lines:

L.tileLayer('./folder/path/{z}/{x}/{y}.png',
{ 
  tms:true
}).addTo(map);

If there is no need to use "real coordinates" you can also try this plugin to gdal which makes it a bit easier to work with plain non-georeferenced maps in leaflet.

  • Although the image is a map of the U.S. (in Lambert Conformal projection), I don't think it is georeferenced. How do I make it geo-referenced? Alternatively, can I use tileLayer for non-georeferenced tiles? Thanks again. – kykong Apr 9 '17 at 11:59
  • @kykong Do you want to visualize only your map or do you want to show additional "real" geodata like a map in the background and streets or railways as overlays on your map? – tallistroan Apr 9 '17 at 12:21
  • Yes, I basically just want to visualize my map in Leaflet. It would be great if some geo-referencing capability (such as the latitude/longitude) is available but I can go without it. – kykong Apr 9 '17 at 21:04
  • Alright, I added a solution for both ways to my answer. – tallistroan Apr 10 '17 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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