Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured this one out after discovering how <code>OpenStreetMap</code> stores its tiles. The basics are:</p> <ul> <li>Tiles are 256 × 256 pixel PNG files</li> <li>Each zoom level is a directory, each column is a subdirectory, and each tile in that column is a file</li> <li>To access a file use <code>http://localhost/osm/${z}/${x}/${y}.png</code></li> <li>Calculate the <code>${z} ${x} and ${y}</code> values based on the latitude and longitude.</li> </ul> <p>There is some excellent documentation on this subject on the <a href="http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames" rel="nofollow">OpenStreetMap Wiki</a>, including code blocks in various languages to calculate the tile names. I needed a Java solution so the code I ended up using is:</p> <pre><code>public class Mapper { public static void main(String[] args) { int zoom = 11; double lat = -33.77651d; double lon = 150.94712d; System.out.println("http://localhost/osm/" + getTileNumber(lat, lon, zoom) + ".png"); } public static String getTileNumber(double lat, double lon, int zoom) { int xtile = (int)Math.floor((lon + 180) / 360 * (1&lt;&lt;zoom)); int ytile = (int)Math.floor((1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1&lt;&lt;zoom)); return ("" + zoom + "/" + xtile + "/" + ytile); } } </code></pre> <p>This returns a URL for the required image tile, eg: <code>http://localhost/osm/11/1882/1228.png</code> which you can then use to acquire the image. I then used <a href="https://code.google.com/p/thumbnailator/" rel="nofollow">Thumbnailator</a> to generate the 128x128 thumbnail size:</p> <pre><code>Thumbnails.of(new File("tile.png")) .size(128, 128) .toFile(new File("thumbnail.png")); </code></pre> <p>Happy days.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload