Changeset 26910 in osm for applications/viewer
- Timestamp:
- 2011-10-20T13:02:13+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
r26245 r26910 6 6 7 7 public 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 10 22 public TemplatedTMSTileSource(String name, String url, int maxZoom) { 11 23 super(name, url, maxZoom); … … 14 26 public TemplatedTMSTileSource(String name, String url, int minZoom, int maxZoom) { 15 27 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()) { 18 30 rand = new Random(); 19 31 randomParts = m.group(1).split(","); … … 24 36 public String getTileUrl(int zoom, int tilex, int tiley) { 25 37 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)]); 33 44 } 34 45 return r;
Note:
See TracChangeset
for help on using the changeset viewer.