Ignore:
Timestamp:
2016-01-24T14:39:06+01:00 (9 years ago)
Author:
stoecker
Message:

add checksum based no-tile detection, see #josm12425

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r31573 r32021  
    44import java.awt.Point;
    55import java.io.IOException;
     6import java.security.MessageDigest;
     7import java.security.NoSuchAlgorithmException;
    68import java.util.HashMap;
    79import java.util.List;
     
    2729    protected String id;
    2830    private final Map<String, String> noTileHeaders;
     31    private final Map<String, String> noTileChecksums;
    2932    private final Map<String, String> metadataHeaders;
    3033    protected int tileSize;
     
    4447        this.id = info.getUrl();
    4548        this.noTileHeaders = info.getNoTileHeaders();
     49        this.noTileChecksums = info.getNoTileChecksums();
    4650        this.metadataHeaders = info.getMetadataHeaders();
    4751        this.tileSize = info.getTileSize();
     
    219223            }
    220224        }
     225        if (noTileChecksums != null) {
     226            for (Entry<String, String> searchEntry: noTileChecksums.entrySet()) {
     227                MessageDigest md = null;
     228                try {
     229                    md = MessageDigest.getInstance(searchEntry.getKey());
     230                } catch (NoSuchAlgorithmException e) {
     231                    break;
     232                }
     233                byte[] byteDigest = md.digest(content);
     234                final int len = byteDigest.length;
     235
     236                char[] hexChars = new char[len * 2];
     237                for (int i = 0, j = 0; i < len; i++) {
     238                    final int v = byteDigest[i];
     239                    int vn = (v & 0xf0) >> 4;
     240                    hexChars[j++] = (char)(vn + (vn >= 10 ? 'a'-10 : '0'));
     241                    vn = (v & 0xf);
     242                    hexChars[j++] = (char)(vn + (vn >= 10 ? 'a'-10 : '0'));
     243                }
     244                if (new String(hexChars).equalsIgnoreCase(searchEntry.getValue())) {
     245                    return true;
     246                }
     247            }
     248        }
    221249        return super.isNoTileAtZoom(headers, statusCode, content);
    222250    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java

    r31791 r32021  
    2323    /** headers meaning, that there is no tile at this zoom level */
    2424    protected Map<String, String> noTileHeaders;
     25
     26    /** checksum of empty tiles */
     27    protected Map<String, String> noTileChecksums;
    2528
    2629    /** minimum zoom level supported by the tile source */
     
    102105
    103106    /**
     107     * Checkusm for empty tiles for servers delivering such tile types
     108     * @return map of checksums, that when detected, means that this is "no tile at this zoom level" situation
     109     * @since 32021
     110     */
     111    public Map<String, String> getNoTileChecksums() {
     112        return noTileChecksums;
     113    }
     114
     115    /**
    104116     * Request supported minimum zoom level
    105117     * @return minimum zoom level supported by tile source
Note: See TracChangeset for help on using the changeset viewer.