Ignore:
Timestamp:
2009-07-12T20:30:29+02:00 (15 years ago)
Author:
dhansen
Message:

I noticed that some of the debugging lines were not getting
drawn directly. There were a few cases where the TileSet
didn't quite cover tiles on the edegs of the view area.

This creates a TileSet::tileMax variable which we can use
to determine when we hit the edges of valid tile numbers.
It also pads the tile searches by one to make sure that we
don't miss any tiles. The tileMax will keep us from going
out of bounds here.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java

    r16460 r16461  
    495495                int z12x0, z12x1, z12y0, z12y1;
    496496                int zoom;
    497 
     497                int tileMax;
    498498                TileSet(LatLon topLeft, LatLon botRight, int zoom) {
    499499                        this.zoom = zoom;
    500                         z12x0 = lonToTileX(topLeft.lon(), zoom);
    501                         z12x1 = lonToTileX(botRight.lon(), zoom);
    502                         z12y0 = latToTileY(topLeft.lat(), zoom);
    503                         z12y1 = latToTileY(botRight.lat(), zoom);
     500                        z12x0 = lonToTileX(topLeft.lon(), zoom) - 1;
     501                        z12y0 = latToTileY(topLeft.lat(),  zoom) - 1;
     502                        z12x1 = lonToTileX(botRight.lon(), zoom) + 1;
     503                        z12y1 = latToTileY(botRight.lat(), zoom) + 1;
    504504                        if (z12x0 > z12x1) {
    505505                                int tmp = z12x0;
     
    512512                                z12y1 = tmp;
    513513                        }
     514                        tileMax = (int)Math.pow(2.0, zoom);
     515                        if (z12x0 < 0) z12x0 = 0;
     516                        if (z12y0 < 0) z12y0 = 0;
     517                        if (z12x1 > tileMax) z12x1 = tileMax;
     518                        if (z12y1 > tileMax) z12y1 = tileMax;
    514519                }
    515520
     
    527532        {
    528533            List<Tile> ret = new ArrayList<Tile>();
    529                         int tileMax = (int)Math.pow(2.0, zoom);
    530             for (int x = z12x0 - 1; x <= z12x1 + 1; x++) {
    531                 if (x < 0)
    532                     continue;
    533                 for (int y = z12y0 - 1; y <= z12y1 + 1; y++) {
    534                     if (y < 0)
    535                         continue;
     534            for (int x = z12x0; x <= z12x1; x++) {
     535                for (int y = z12y0; y <= z12y1; y++) {
    536536                    Tile t = new Tile(x % tileMax, y % tileMax);
    537537                    ret.add(t);
     
    542542
    543543                boolean topTile(Tile t) {
    544                         if (t.y == z12y0 - 1)
     544                        if (t.y == z12y0 )
    545545                                return true;
    546546                        return false;
     
    548548
    549549                boolean leftTile(Tile t) {
    550                         if (t.x == z12x0 - 1)
     550                        if (t.x == z12x0 )
    551551                                return true;
    552552                        return false;
Note: See TracChangeset for help on using the changeset viewer.