Changeset 4188 in josm


Ignore:
Timestamp:
Jul 1, 2011 9:27:15 AM (23 months ago)
Author:
stoecker
Message:

improve TMS zoom handling

Location:
trunk/src/org/openstreetmap/josm
Files:
3 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        } 
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4183 r4188  
    9292    public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", DEFAULT_MIN_ZOOM); 
    9393    public static final IntegerProperty PROP_MAX_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".max_zoom_lvl", DEFAULT_MAX_ZOOM); 
    94     public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 
     94    //public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 
    9595    public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER = new BooleanProperty(PREFERENCE_PREFIX + ".add_to_slippymap_chooser", true); 
    9696    public static final StringProperty PROP_TILECACHE_DIR; 
     
    105105    } 
    106106 
    107     boolean debug = false; 
    108     void out(String s) 
    109     { 
    110         Main.debug(s); 
    111     } 
     107    /*boolean debug = false;*/ 
    112108 
    113109    protected MemoryTileCache tileCache; 
     
    131127        Main.map.repaint(100); 
    132128        tileRequestsOutstanding.remove(tile); 
    133         if (debug) { 
    134             out("tileLoadingFinished() tile: " + tile + " success: " + success); 
    135         } 
     129        /*if (debug) { 
     130            Main.debug("tileLoadingFinished() tile: " + tile + " success: " + success); 
     131        }*/ 
    136132    } 
    137133    @Override 
     
    142138    void clearTileCache() 
    143139    { 
    144         if (debug) { 
    145             out("clearing tile storage"); 
    146         } 
     140        /*if (debug) { 
     141            Main.debug("clearing tile storage"); 
     142        }*/ 
    147143        tileCache = new MemoryTileCache(); 
    148144        tileCache.setCacheSize(200); 
     
    185181    { 
    186182        if(maxZoomLvl > MAX_ZOOM) { 
    187             System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 
     183            /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/ 
    188184            maxZoomLvl = MAX_ZOOM; 
    189185        } 
    190186        if(maxZoomLvl < PROP_MIN_ZOOM_LVL.get()) { 
    191             System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl."); 
     187            /*Main.debug("Max. zoom level should not be more than min. zoom level! Setting to min.");*/ 
    192188            maxZoomLvl = PROP_MIN_ZOOM_LVL.get(); 
    193189        } 
     
    211207    { 
    212208        if(minZoomLvl < MIN_ZOOM) { 
    213             System.err.println("minZoomLvl shouldnt be lees than "+MIN_ZOOM+"! Setting to that."); 
     209            /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/ 
    214210            minZoomLvl = MIN_ZOOM; 
    215211        } 
    216212        if(minZoomLvl > PROP_MAX_ZOOM_LVL.get()) { 
    217             System.err.println("minZoomLvl shouldnt be more than maxZoomLvl! Setting to maxZoomLvl."); 
     213            /*Main.debug("Min. zoom level should not be more than Max. zoom level! Setting to Max.");*/ 
    218214            minZoomLvl = getMaxZoomLvl(ts); 
    219215        } 
    220216        if (ts != null && ts.getMinZoom() > minZoomLvl) { 
    221             System.err.println("increasomg minZoomLvl to match tile source"); 
     217            /*Main.debug("Increasing min. zoom level to match tile source");*/ 
    222218            minZoomLvl = ts.getMinZoom(); 
    223219        } 
     
    238234        if (info.getImageryType() == ImageryType.TMS) { 
    239235            if(ImageryInfo.isUrlWithPatterns(info.getUrl())) 
    240                 return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMaxZoom()); 
     236                return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
    241237            else 
    242                 return new TMSTileSource(info.getName(),info.getUrl(), info.getMaxZoom()); 
     238                return new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
    243239        } else if (info.getImageryType() == ImageryType.BING) 
    244240            return new BingAerialTileSource(); 
     
    254250        if(requireAttr) { 
    255251            attrImage = tileSource.getAttributionImage(); 
    256             if(attrImage == null) { 
    257                 System.out.println("Attribution image was null."); 
     252            /*if(attrImage == null) { 
     253                Main.debug("Attribution image was null."); 
    258254            } else { 
    259                 System.out.println("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this)); 
    260             } 
     255                Main.debug("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this)); 
     256            }*/ 
    261257 
    262258            attrTermsUrl = tileSource.getTermsOfUseURL(); 
     
    374370            @Override 
    375371            public void actionPerformed(ActionEvent ae) { 
    376                 out("info tile: " + clickedTile); 
     372                //Main.debug("info tile: " + clickedTile); 
    377373                if (clickedTile != null) { 
    378374                    showMetadataTile = clickedTile; 
     
    438434                    @Override 
    439435                    public void actionPerformed(ActionEvent ae) { 
    440                         System.out.print("flushing all tiles..."); 
     436                        //Main.debug("flushing all tiles..."); 
    441437                        clearTileCache(); 
    442                         System.out.println("done"); 
     438                        //Main.debug("done"); 
    443439                    } 
    444440                })); 
     
    508504    void zoomChanged() 
    509505    { 
    510         if (debug) { 
    511             out("zoomChanged(): " + currentZoomLevel); 
    512         } 
     506        /*if (debug) { 
     507            Main.debug("zoomChanged(): " + currentZoomLevel); 
     508        }*/ 
    513509        needRedraw = true; 
    514510        jobDispatcher.cancelOutstandingJobs(); 
     
    537533    { 
    538534        boolean zia = currentZoomLevel < this.getMaxZoomLvl(); 
    539         if (debug) { 
    540             out("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() ); 
    541         } 
     535        /*if (debug) { 
     536            Main.debug("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() ); 
     537        }*/ 
    542538        return zia; 
    543539    } 
     
    546542        if (zoomIncreaseAllowed()) { 
    547543            currentZoomLevel++; 
    548             if (debug) { 
    549                 out("increasing zoom level to: " + currentZoomLevel); 
    550             } 
     544            /*if (debug) { 
     545                Main.debug("increasing zoom level to: " + currentZoomLevel); 
     546            }*/ 
    551547            zoomChanged(); 
    552548        } else { 
    553             System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+ 
    554                     "MaxZoomLvl ("+this.getMaxZoomLvl()+") reached."); 
     549            Main.warn("Current zoom level ("+currentZoomLevel+") could not be increased. "+ 
     550                    "Max.zZoom Level "+this.getMaxZoomLvl()+" reached."); 
    555551            return false; 
    556552        } 
     
    580576        int minZoom = this.getMinZoomLvl(); 
    581577        if (zoomDecreaseAllowed()) { 
    582             if (debug) { 
    583                 out("decreasing zoom level to: " + currentZoomLevel); 
    584             } 
     578            /*if (debug) { 
     579                Main.debug("decreasing zoom level to: " + currentZoomLevel); 
     580            }*/ 
    585581            currentZoomLevel--; 
    586582            zoomChanged(); 
    587583        } else { 
    588             System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl("+minZoom+") reached."); 
     584            /*Main.debug("Current zoom level could not be decreased. Min. zoom level "+minZoom+" reached.");*/ 
    589585            return false; 
    590586        } 
     
    671667        boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 
    672668        needRedraw = true; 
    673         if (debug) { 
    674             out("imageUpdate() done: " + done + " calling repaint"); 
    675         } 
     669        /*if (debug) { 
     670            Main.debug("imageUpdate() done: " + done + " calling repaint"); 
     671        }*/ 
    676672        Main.map.repaint(done ? 0 : 100); 
    677673        return !done; 
     
    730726        if (border != null) { 
    731727            target = source.intersection(border); 
    732             if (debug) { 
    733                 out("source: " + source + "\nborder: " + border + "\nintersection: " + target); 
    734             } 
     728            /*if (debug) { 
     729                Main.debug("source: " + source + "\nborder: " + border + "\nintersection: " + target); 
     730            }*/ 
    735731        } 
    736732 
     
    757753        int img_y_end   = img_y_offset + (int)(target.getHeight() * imageYScaling); 
    758754 
    759         if (debug) { 
    760             out("drawing image into target rect: " + target); 
    761         } 
     755        /*if (debug) { 
     756            Main.debug("drawing image into target rect: " + target); 
     757        }*/ 
    762758        g.drawImage(sourceImg, 
    763759                target.x, target.y, 
     
    792788            Image img = getLoadedTileImage(tile); 
    793789            if (img == null || tile.hasError()) { 
    794                 if (debug) { 
    795                     out("missed tile: " + tile); 
    796                 } 
     790                /*if (debug) { 
     791                    Main.debug("missed tile: " + tile); 
     792                }*/ 
    797793                missedTiles.add(tile); 
    798794                continue; 
     
    822818        int texty = p.y + 2 + fontHeight; 
    823819 
    824         if (PROP_DRAW_DEBUG.get()) { 
     820        /*if (PROP_DRAW_DEBUG.get()) { 
    825821            myDrawString(g, "x=" + t.getXtile() + " y=" + t.getYtile() + " z=" + zoom + "", p.x + 2, texty); 
    826822            texty += 1 + fontHeight; 
     
    829825                texty += 1 + fontHeight; 
    830826            } 
    831         }// end of if draw debug 
     827        }*/// end of if draw debug 
    832828 
    833829        if (tile == showMetadataTile) { 
     
    847843 
    848844        String tileStatus = tile.getStatus(); 
    849         if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) { 
     845        /*if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) { 
    850846            myDrawString(g, tr("image " + tileStatus), p.x + 2, texty); 
    851847            texty += 1 + fontHeight; 
    852         } 
     848        }*/ 
    853849 
    854850        if (tile.hasError()) { 
     
    857853        } 
    858854 
    859         int xCursor = -1; 
     855        /*int xCursor = -1; 
    860856        int yCursor = -1; 
    861857        if (PROP_DRAW_DEBUG.get()) { 
     
    880876                xCursor = t.getXtile(); 
    881877            } 
    882         } 
     878        }*/ 
    883879    } 
    884880 
     
    10071003                } 
    10081004            } 
    1009             if (debug) 
     1005            /*if (debug) 
    10101006                if (nr_queued > 0) { 
    1011                     out("queued to load: " + nr_queued + "/" + tiles.size() + " tiles at zoom: " + zoom); 
    1012                 } 
     1007                    Main.debug("queued to load: " + nr_queued + "/" + tiles.size() + " tiles at zoom: " + zoom); 
     1008                }*/ 
    10131009        } 
    10141010    } 
     
    10841080 
    10851081        if (botRight.east() == 0.0 || botRight.north() == 0) { 
    1086             Main.debug("still initializing??"); 
     1082            /*Main.debug("still initializing??");*/ 
    10871083            // probably still initializing 
    10881084            return; 
     
    11431139        // Too many tiles... refuse to download 
    11441140        if (!ts.tooLarge()) { 
    1145             //out("size: " + ts.size() + " spanned: " + ts.tilesSpanned()); 
     1141            //Main.debug("size: " + ts.size() + " spanned: " + ts.tilesSpanned()); 
    11461142            ts.loadAllTiles(false); 
    11471143        } 
     
    11841180            missedTiles = newlyMissedTiles; 
    11851181        } 
    1186         if (debug && missedTiles.size() > 0) { 
    1187             out("still missed "+missedTiles.size()+" in the end"); 
    1188         } 
     1182        /*if (debug && missedTiles.size() > 0) { 
     1183            Main.debug("still missed "+missedTiles.size()+" in the end"); 
     1184        }*/ 
    11891185        g.setColor(Color.red); 
    11901186        g.setFont(InfoFont); 
     
    12511247            myDrawString(g, tr("No tiles at this zoom level"), 120, 120); 
    12521248        } 
    1253         if (debug) { 
     1249        /*if (debug) { 
    12541250            myDrawString(g, tr("Current zoom: {0}", currentZoomLevel), 50, 140); 
    12551251            myDrawString(g, tr("Display zoom: {0}", displayZoomLevel), 50, 155); 
    12561252            myDrawString(g, tr("Pixel scale: {0}", getScaleFactor(currentZoomLevel)), 50, 170); 
    12571253            myDrawString(g, tr("Best zoom: {0}", Math.log(getScaleFactor(1))/Math.log(2)/2+1), 50, 185); 
    1258         } 
     1254        }*/ 
    12591255    }// end of paint method 
    12601256 
     
    12641260     */ 
    12651261    Tile getTileForPixelpos(int px, int py) { 
    1266         if (debug) { 
    1267             out("getTileForPixelpos("+px+", "+py+")"); 
    1268         } 
     1262        /*if (debug) { 
     1263            Main.debug("getTileForPixelpos("+px+", "+py+")"); 
     1264        }*/ 
    12691265        MapView mv = Main.map.mapView; 
    12701266        Point clicked = new Point(px, py); 
     
    12821278            Rectangle r = new Rectangle(pixelPos(t1)); 
    12831279            r.add(pixelPos(t2)); 
    1284             if (debug) { 
    1285                 out("r: " + r + " clicked: " + clicked); 
    1286             } 
     1280            /*if (debug) { 
     1281                Main.debug("r: " + r + " clicked: " + clicked); 
     1282            }*/ 
    12871283            if (!r.contains(clicked)) { 
    12881284                continue; 
     
    12931289        if (clickedTile == null) 
    12941290            return null; 
    1295         System.out.println("clicked on tile: " + clickedTile.getXtile() + " " + clickedTile.getYtile() + 
    1296                 " currentZoomLevel: " + currentZoomLevel); 
     1291        /*Main.debug("Clicked on tile: " + clickedTile.getXtile() + " " + clickedTile.getYtile() + 
     1292                " currentZoomLevel: " + currentZoomLevel);*/ 
    12971293        return clickedTile; 
    12981294    } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/AddWMSLayerPanel.java

    r4164 r4188  
    33 
    44import static org.openstreetmap.josm.tools.I18n.tr; 
     5import static org.openstreetmap.josm.tools.I18n.trc; 
    56 
    67import java.awt.Component; 
     
    7980    private boolean previouslyShownUnsupportedCrsError = false; 
    8081    private JTextArea tmsURL; 
     82    private JTextField tmsZoom; 
    8183 
    8284    public AddWMSLayerPanel() { 
     
    200202                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 
    201203        tmsView.add(tmsUrlScrollPane, GBC.eop().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 
     204        tmsView.add(new JLabel(trc("layer", "Zoom")), GBC.std().insets(0,0,5,0)); 
     205        tmsZoom = new JTextField(3); 
     206        tmsZoom.addKeyListener(new KeyAdapter() { 
     207            @Override 
     208            public void keyReleased(KeyEvent e) { 
     209                resultingLayerField.setText(buildTMSUrl()); 
     210            } 
     211        }); 
     212        tmsView.add(tmsZoom, GBC.eop().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 
    202213        tabbedPane.addTab(tr("TMS"), tmsView); 
    203214 
     
    229240 
    230241    private String buildTMSUrl() { 
    231         StringBuilder a = new StringBuilder("tms:"); 
     242        StringBuilder a = new StringBuilder("tms"); 
     243        String z = sanitize(tmsZoom.getText()); 
     244        if(!z.isEmpty()) 
     245            a.append("["+z+"]"); 
     246        a.append(":"); 
    232247        a.append(sanitize(tmsURL.getText())); 
    233248        return a.toString(); 
Note: See TracChangeset for help on using the changeset viewer.