Changeset 26910 in osm for applications/viewer


Ignore:
Timestamp:
2011-10-20T13:02:13+02:00 (13 years ago)
Author:
donvip
Message:

see #josm6982 - Let JOSM know supported TMS pattern values

File:
1 edited

Legend:

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

    r26245 r26910  
    66
    77public class TemplatedTMSTileSource extends TMSTileSource {
    8     Random rand = null;
    9     String[] randomParts = null;
     8   
     9    private Random rand = null;
     10    private String[] randomParts = null;
     11   
     12    public static final String PATTERN_ZOOM    = "\\{zoom\\}";
     13    public static final String PATTERN_X       = "\\{x\\}";
     14    public static final String PATTERN_Y       = "\\{y\\}";
     15    public static final String PATTERN_Y_YAHOO = "\\{!y\\}";
     16    public static final String PATTERN_SWITCH  = "\\{switch:[^}]+\\}";
     17   
     18    public static final String[] ALL_PATTERNS = {
     19        PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_SWITCH
     20    };
     21   
    1022    public TemplatedTMSTileSource(String name, String url, int maxZoom) {
    1123        super(name, url, maxZoom);
     
    1426    public TemplatedTMSTileSource(String name, String url, int minZoom, int maxZoom) {
    1527        super(name, url, minZoom, maxZoom);
    16         Matcher m = Pattern.compile(".*\\{switch:([^}]+)\\}.*").matcher(url);
    17         if(m.matches()) {
     28        Matcher m = Pattern.compile(".*"+PATTERN_SWITCH+".*").matcher(url);
     29        if (m.matches()) {
    1830            rand = new Random();
    1931            randomParts = m.group(1).split(",");
     
    2436    public String getTileUrl(int zoom, int tilex, int tiley) {
    2537        String r = this.baseUrl
    26         .replaceAll("\\{zoom\\}", Integer.toString(zoom))
    27         .replaceAll("\\{x\\}", Integer.toString(tilex))
    28         .replaceAll("\\{y\\}", Integer.toString(tiley))
    29         .replaceAll("\\{!y\\}", Integer.toString((int)Math.pow(2, zoom)-1-tiley));
    30         if(rand != null) {
    31             r = r.replaceAll("\\{switch:[^}]+\\}",
    32             randomParts[rand.nextInt(randomParts.length)]);
     38            .replaceAll(PATTERN_ZOOM, Integer.toString(zoom))
     39            .replaceAll(PATTERN_X, Integer.toString(tilex))
     40            .replaceAll(PATTERN_Y, Integer.toString(tiley))
     41            .replaceAll(PATTERN_Y_YAHOO, Integer.toString((int)Math.pow(2, zoom)-1-tiley));
     42        if (rand != null) {
     43            r = r.replaceAll(PATTERN_SWITCH, randomParts[rand.nextInt(randomParts.length)]);
    3344        }
    3445        return r;
Note: See TracChangeset for help on using the changeset viewer.