Skip to content

Commit

Permalink
better usage of OSM tile cache and YaCy cache by usage of better tile…
Browse files Browse the repository at this point in the history
… server computation based on a coordinate hash

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7026 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Aug 8, 2010
1 parent 388aa02 commit b12bfe1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions source/de/anomic/yacy/graphics/OSMTile.java
Expand Up @@ -71,6 +71,7 @@ public static RasterPlotter getCombinedTiles(final tileCoordinates t, int width,
place = new Place(m, t.xtile - w + i, t.ytile - h + j, 256 * i, 256 * j, t.zoom);
place.start();
tileLoader.add(place);
if (t.zoom >= 17) try {Thread.sleep(100);} catch (InterruptedException e) {} // be nice with tile server for uncached tiles
}
}
// wait until all tiles are loaded
Expand All @@ -88,7 +89,7 @@ public void run() {
tileCoordinates t = new tileCoordinates(xt, yt, z);
BufferedImage bi = null;
for (int i = 0; i < 5; i++) {
bi = getSingleTile(t);
bi = getSingleTile(t, i);
if (bi != null) {
m.insertBitmap(bi, xc, yc);
return;
Expand All @@ -99,10 +100,10 @@ public void run() {
}
}

public static BufferedImage getSingleTile(final tileCoordinates tile) {
public static BufferedImage getSingleTile(final tileCoordinates tile, int retry) {
DigestURI tileURL;
try {
tileURL = new DigestURI(tile.url(), null);
tileURL = new DigestURI(tile.url(retry), null);
} catch (final MalformedURLException e) {
return null;
}
Expand All @@ -114,7 +115,7 @@ public static BufferedImage getSingleTile(final tileCoordinates tile) {
try {
entry = Switchboard.getSwitchboard().loader.load(Switchboard.getSwitchboard().loader.request(tileURL, false, false), CrawlProfile.CacheStrategy.IFEXIST, Long.MAX_VALUE);
} catch (IOException e) {
Log.logWarning("yamyOSM", "cannot load: " + e.getMessage());
Log.logWarning("OSMTile", "cannot load: " + e.getMessage());
return null;
}
tileb = entry.getContent();
Expand All @@ -135,6 +136,7 @@ public static class tileCoordinates {
int xtile, ytile, zoom;

public tileCoordinates(final double lat, final double lon, final int zoom) {
// see http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
this.zoom = zoom;
this.xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
this.ytile = (int) Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom));
Expand All @@ -146,9 +148,13 @@ public tileCoordinates(final int xtile, final int ytile, final int zoom) {
this.ytile = ytile;
}

public String url() {
char server = (char) ((int)'a' + r.nextInt(3));
return("http://" + server + ".tile.openstreetmap.org/" + zoom + "/" + xtile + "/" + ytile + ".png");
public String url(int retry) {
// see http://wiki.openstreetmap.org/wiki/Public_Domain_Map
int hash = (xtile + 7 * ytile + 13 * zoom + retry) % 4;
String host = (hash == 3) ? "tile.openstreetmap.org" : ((char) ((int)'a' + r.nextInt(3))) + ".tile.openstreetmap.org";
String url = "http://" + host + "/" + zoom + "/" + xtile + "/" + ytile + ".png";
//System.out.println("OSM URL = " + url);
return url;
}

}
Expand Down

0 comments on commit b12bfe1

Please sign in to comment.