- /*
- * To convert y-coordinates to map coordinates in ruler, use:
- * double val = (y-offsetY)/scaleY;
- * val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
- * String str = formatValue(val);
- */
-
- double minx = Math.min(get180Scaled(), Math.max(viewbox.getMinX(), -get180Scaled()));
- double maxx = Math.min(get180Scaled(), Math.max(viewbox.getMaxX(), -get180Scaled()));
-
- double miny = Math.min(get360Scaled(), Math.max(viewbox.getMinY()+get180Scaled(), 0));
- double maxy = Math.min(get360Scaled(), Math.max(viewbox.getMaxY()+get180Scaled(), 0));
-
- g.setTransform(new AffineTransform());
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-
- int levels = (1 << level);
-
- // http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
- int left = (int)Math.floor( (minx + get180Scaled()) / get360Scaled() * (1<<level) );
- int right = (int)Math.floor( (maxx + get180Scaled()) / get360Scaled() * (1<<level) );
- int top = (int)Math.floor(miny / get360Scaled() * (1<<level));// (int)Math.floor( (1 - Math.log(Math.tan(Math.toRadians(miny)) + 1 / Math.cos(Math.toRadians(miny))) / Math.PI) / 2 * (1<<level) );
- int bottom = (int)Math.floor(maxy / get360Scaled() * (1<<level));// (int)Math.floor( (1 - Math.log(Math.tan(Math.toRadians(maxy)) + 1 / Math.cos(Math.toRadians(maxy))) / Math.PI) / 2 * (1<<level) );
-
- double tsx = get360Scaled() / (double)levels; // Size of tile on zoom level
- for(int tx = left; tx <= right; tx++) {
- if(tx < 0 || tx >= levels) continue;
- for(int ty = top; ty <= bottom; ty++) {
- if(ty < 0 || ty >= levels) continue;
- TileKey tile = new TileKey(level, tx, ty);
- double y = (double)ty - (double)levels/2; // In level 0 we have only one tile
- paintTile(tileCache, g, tr, tile, tx*tsx-get180Scaled(), y*tsx, tsx);