Ignore:
Timestamp:
2011-07-01T09:27:15+02:00 (13 years ago)
Author:
stoecker
Message:

improve TMS zoom handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r3974 r4188  
    44import java.util.ArrayList;
    55import java.util.Collection;
     6import java.util.regex.Matcher;
     7import java.util.regex.Pattern;
    68
    79import org.openstreetmap.josm.io.OsmApi;
     
    3840    double pixelPerDegree = 0.0;
    3941    int maxZoom = 0;
     42    int defaultMaxZoom = 0;
     43    int defaultMinZoom = 0;
    4044
    4145    public ImageryInfo(String name) {
     
    135139        this.cookies=i.cookies;
    136140        this.imageryType=i.imageryType;
     141        this.defaultMaxZoom=i.defaultMaxZoom;
    137142        this.pixelPerDegree=i.pixelPerDegree;
    138143        this.eulaAcceptanceRequired = null;
     
    169174       
    170175        for (ImageryType type : ImageryType.values()) {
    171             if (url.startsWith(type.getUrlString() + ":")) {
    172                 this.url = url.substring(type.getUrlString().length() + 1);
     176            Matcher m = Pattern.compile(type.getUrlString()+"(?:\\[(?:(\\d+),)?(\\d+)\\])?:(.*)").matcher(url);
     177            if(m.matches()) {
     178                this.url = m.group(3);
    173179                this.imageryType = type;
     180                if(m.group(2) != null) {
     181                    defaultMaxZoom = Integer.valueOf(m.group(2));
     182                    maxZoom = defaultMaxZoom;
     183                }
     184                if(m.group(1) != null) {
     185                    defaultMinZoom = Integer.valueOf(m.group(1));
     186                }
    174187                return;
    175188            }
     
    205218    }
    206219
     220    public int getMinZoom() {
     221        return this.defaultMinZoom;
     222    }
     223
    207224    public String getFullUrl() {
    208         return imageryType.getUrlString() + ":" + url;
     225        return imageryType.getUrlString() + (defaultMaxZoom != 0
     226            ? "["+(defaultMinZoom != 0 ? defaultMinZoom+",":"")+defaultMaxZoom+"]" : "") + ":" + url;
    209227    }
    210228
     
    223241        if(pixelPerDegree != 0.0) {
    224242            res += " ("+pixelPerDegree+")";
    225         } else if(maxZoom != 0) {
     243        } else if(maxZoom != 0 && maxZoom != defaultMaxZoom) {
    226244            res += " (z"+maxZoom+")";
    227245        }
Note: See TracChangeset for help on using the changeset viewer.