Changeset 26244 in osm for applications/viewer/jmapviewer/src/org
- Timestamp:
- 2011-07-01T23:55:33+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
r26235 r26244 1 1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 2 3 import java.util.Random; 4 import java.util.regex.Pattern; 5 import java.util.regex.Matcher; 3 6 4 7 public class TemplatedTMSTileSource extends TMSTileSource { 8 Random rand = null; 9 String[] randomParts = null; 5 10 public TemplatedTMSTileSource(String name, String url, int maxZoom) { 6 11 super(name, url, maxZoom); … … 9 14 public TemplatedTMSTileSource(String name, String url, int minZoom, int maxZoom) { 10 15 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 } 11 21 } 12 22 13 23 @Override 14 24 public String getTileUrl(int zoom, int tilex, int tiley) { 15 returnthis.baseUrl25 String r = this.baseUrl 16 26 .replaceAll("\\{zoom\\}", Integer.toString(zoom)) 17 27 .replaceAll("\\{x\\}", Integer.toString(tilex)) 18 28 .replaceAll("\\{y\\}", Integer.toString(tiley)) 19 29 .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; 21 35 } 22 36 }
Note:
See TracChangeset
for help on using the changeset viewer.