Ignore:
Timestamp:
2011-07-01T23:55:33+02:00 (14 years ago)
Author:
stoecker
Message:

add switch statement to TMS tile urls

File:
1 edited

Legend:

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

    r26235 r26244  
    11package org.openstreetmap.gui.jmapviewer.tilesources;
    22
     3import java.util.Random;
     4import java.util.regex.Pattern;
     5import java.util.regex.Matcher;
    36
    47public class TemplatedTMSTileSource extends TMSTileSource {
     8    Random rand = null;
     9    String[] randomParts = null;
    510    public TemplatedTMSTileSource(String name, String url, int maxZoom) {
    611        super(name, url, maxZoom);
     
    914    public TemplatedTMSTileSource(String name, String url, int minZoom, int maxZoom) {
    1015        super(name, url, minZoom, maxZoom);
     16        Matcher m = Pattern.compile(".*\\{switch:([^}]+)\\}.*").matcher(url);
     17        if(m.matches()) {
     18            rand = new Random();
     19            randomParts = m.group(1).split(",");
     20        }
    1121    }
    1222
    1323    @Override
    1424    public String getTileUrl(int zoom, int tilex, int tiley) {
    15         return this.baseUrl
     25        String r = this.baseUrl
    1626        .replaceAll("\\{zoom\\}", Integer.toString(zoom))
    1727        .replaceAll("\\{x\\}", Integer.toString(tilex))
    1828        .replaceAll("\\{y\\}", Integer.toString(tiley))
    1929        .replaceAll("\\{!y\\}", Integer.toString((int)Math.pow(2, zoom)-1-tiley));
    20 
     30        if(r != null) {
     31            r = r.replaceAll("\\{switch:[^}]+\\}",
     32            randomParts[rand.nextInt(randomParts.length)]);
     33        }
     34        return r;
    2135    }
    2236}
Note: See TracChangeset for help on using the changeset viewer.