Changeset 26950 in osm


Ignore:
Timestamp:
2011-10-23T14:39:08+02:00 (13 years ago)
Author:
stoecker
Message:

fixed templates for TMS

File:
1 edited

Legend:

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

    r26938 r26950  
    1313    private Map<String, String> headers = new HashMap<String, String>();
    1414   
    15     public static final String PATTERN_ZOOM    = "\\{zoom([+-]\\d+)?\\}";
     15    public static final String PATTERN_ZOOM    = "\\{(?:(\\d+)-)?zoom([+-]\\d+)?\\}";
    1616    public static final String PATTERN_X       = "\\{x\\}";
    1717    public static final String PATTERN_Y       = "\\{y\\}";
    1818    public static final String PATTERN_Y_YAHOO = "\\{!y\\}";
    19     public static final String PATTERN_SWITCH  = "\\{switch:[^}]+\\}";
     19    public static final String PATTERN_SWITCH  = "\\{switch:([^}]+)\\}";
    2020    public static final String PATTERN_HEADER  = "\\{header\\(([^,]+),([^}]+)\\)\\}";
    2121   
     
    5858    @Override
    5959    public String getTileUrl(int zoom, int tilex, int tiley) {
     60        int finalZoom = zoom;
    6061        Matcher m = Pattern.compile(".*"+PATTERN_ZOOM+".*").matcher(this.baseUrl);
    61         if (m.matches() && !m.group(1).isEmpty()) {
    62             String ofs = m.group(1);
    63             if(ofs.startsWith("+"))
    64                 ofs = ofs.substring(1);
    65             zoom += Integer.valueOf(ofs);
     62        if (m.matches()) {
     63            if(m.group(1) != null) {
     64                finalZoom = Integer.valueOf(m.group(1))-zoom;
     65            }
     66            if(m.group(2) != null) {
     67                String ofs = m.group(2);
     68                if(ofs.startsWith("+"))
     69                    ofs = ofs.substring(1);
     70                finalZoom += Integer.valueOf(ofs);
     71            }
    6672        }
    6773        String r = this.baseUrl
    68             .replaceAll(PATTERN_ZOOM, Integer.toString(zoom))
     74            .replaceAll(PATTERN_ZOOM, Integer.toString(finalZoom))
    6975            .replaceAll(PATTERN_X, Integer.toString(tilex))
    7076            .replaceAll(PATTERN_Y, Integer.toString(tiley))
    71             .replaceAll(PATTERN_Y_YAHOO, Integer.toString((int)Math.pow(2, zoom)-1-tiley));
     77            .replaceAll(PATTERN_Y_YAHOO, Integer.toString((int)Math.pow(2, zoom-1)-1-tiley));
    7278        if (rand != null) {
    7379            r = r.replaceAll(PATTERN_SWITCH, randomParts[rand.nextInt(randomParts.length)]);
Note: See TracChangeset for help on using the changeset viewer.