Ticket #7739: TMSLayer.patch

File TMSLayer.patch, 13.2 KB (added by Locked, 12 years ago)

the patch

  • TMSLayer.java

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: C:\Users\Franz\Documents\NetBeansProjects\JOSM-Plugins\core\src\org\openstreetmap\josm\gui\layer
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    6666import org.openstreetmap.josm.data.preferences.IntegerProperty;
    6767import org.openstreetmap.josm.data.preferences.StringProperty;
    6868import org.openstreetmap.josm.data.projection.Projection;
     69import org.openstreetmap.josm.gui.MapFrame;
    6970import org.openstreetmap.josm.gui.MapView;
    7071import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    7172import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    123124
    124125    HashSet<Tile> tileRequestsOutstanding = new HashSet<Tile>();
    125126    @Override
    126     public synchronized void tileLoadingFinished(Tile tile, boolean success)
    127     {
     127    public synchronized void tileLoadingFinished(Tile tile, boolean success) {
    128128        if (tile.hasError()) {
    129129            success = false;
    130130            tile.setImage(null);
     
    142142    }
    143143   
    144144    @Override
    145     public TileCache getTileCache()
    146     {
     145    public TileCache getTileCache() {
    147146        return tileCache;
    148147    }
    149148   
     
    188187        }
    189188    }
    190189
    191     void clearTileCache(ProgressMonitor monitor)
    192     {
     190    /**
     191     * Clears the tile cache.
     192     *
     193     * If the current tileLoader is an instance of OsmTileLoader, a new
     194     * TmsTileClearController is created and passed to the according clearCache
     195     * method.
     196     *
     197     * @param monitor
     198     * @see MemoryTileCache#clear()
     199     * @see OsmFileCacheTileLoader#clearCache(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader.TileClearController)
     200     */
     201    void clearTileCache(ProgressMonitor monitor) {
    193202        tileCache.clear();
    194203        if (tileLoader instanceof OsmFileCacheTileLoader) {
    195204            ((OsmFileCacheTileLoader)tileLoader).clearCache(tileSource, new TmsTileClearController(monitor));
     
    216225    protected boolean autoLoad;
    217226    protected boolean showErrors;
    218227
    219     void redraw()
    220     {
     228    /**
     229     * Initiates a repaint of Main.map
     230     *
     231     * @see Main#map
     232     * @see MapFrame#repaint()
     233     */
     234    void redraw() {
    221235        needRedraw = true;
    222236        Main.map.repaint();
    223237    }
    224238
    225     static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts)
    226     {
     239    static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) {
    227240        if(maxZoomLvl > MAX_ZOOM) {
    228241            /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/
    229242            maxZoomLvl = MAX_ZOOM;
     
    238251        return maxZoomLvl;
    239252    }
    240253
    241     public static int getMaxZoomLvl(TileSource ts)
    242     {
     254    public static int getMaxZoomLvl(TileSource ts) {
    243255        return checkMaxZoomLvl(PROP_MAX_ZOOM_LVL.get(), ts);
    244256    }
    245257
     
    248260        PROP_MAX_ZOOM_LVL.put(maxZoomLvl);
    249261    }
    250262
    251     static int checkMinZoomLvl(int minZoomLvl, TileSource ts)
    252     {
     263    static int checkMinZoomLvl(int minZoomLvl, TileSource ts) {
    253264        if(minZoomLvl < MIN_ZOOM) {
    254265            /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/
    255266            minZoomLvl = MIN_ZOOM;
     
    265276        return minZoomLvl;
    266277    }
    267278
    268     public static int getMinZoomLvl(TileSource ts)
    269     {
     279    public static int getMinZoomLvl(TileSource ts) {
    270280        return checkMinZoomLvl(PROP_MIN_ZOOM_LVL.get(), ts);
    271281    }
    272282
     
    316326        }
    317327    }
    318328
     329    /**
     330     * Creates and returns a new TileSource instance depending on the {@link ImageryType}
     331     * of the passed ImageryInfo object.
     332     *
     333     * If no appropriate TileSource is found, null is returned.
     334     * Currently supported ImageryType are {@link ImageryType#TMS},
     335     * {@link ImageryType#BING}, {@link ImageryType#SCANEX}.
     336     *
     337     * @param info
     338     * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
     339     * @throws IllegalArgumentException
     340     */
    319341    public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
    320342        if (info.getImageryType() == ImageryType.TMS) {
    321343            checkUrl(info.getUrl());
     
    350372        }
    351373    }
    352374
    353     private void initTileSource(TileSource tileSource)
    354     {
     375    private void initTileSource(TileSource tileSource) {
    355376        this.tileSource = tileSource;
    356377        attribution.initialize(tileSource);
    357378
     
    623644        });
    624645    }
    625646
    626     void zoomChanged()
    627     {
     647    void zoomChanged() {
    628648        /*if (debug) {
    629649            Main.debug("zoomChanged(): " + currentZoomLevel);
    630650        }*/
     
    633653        tileRequestsOutstanding.clear();
    634654    }
    635655
    636     int getMaxZoomLvl()
    637     {
     656    int getMaxZoomLvl() {
    638657        if (info.getMaxZoom() != 0)
    639658            return checkMaxZoomLvl(info.getMaxZoom(), tileSource);
    640659        else
    641660            return getMaxZoomLvl(tileSource);
    642661    }
    643662
    644     int getMinZoomLvl()
    645     {
     663    int getMinZoomLvl() {
    646664        return getMinZoomLvl(tileSource);
    647665    }
    648666
     
    651669     *
    652670     * @return    true, if zoom increasing was successfull, false othervise
    653671     */
    654     public boolean zoomIncreaseAllowed()
    655     {
     672    public boolean zoomIncreaseAllowed() {
    656673        boolean zia = currentZoomLevel < this.getMaxZoomLvl();
    657674        /*if (debug) {
    658675            Main.debug("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() );
    659676        }*/
    660677        return zia;
    661678    }
    662     public boolean increaseZoomLevel()
    663     {
     679   
     680    public boolean increaseZoomLevel() {
    664681        if (zoomIncreaseAllowed()) {
    665682            currentZoomLevel++;
    666683            /*if (debug) {
     
    675692        return true;
    676693    }
    677694
    678     public boolean setZoomLevel(int zoom)
    679     {
     695    public boolean setZoomLevel(int zoom) {
    680696        if (zoom == currentZoomLevel) return true;
    681697        if (zoom > this.getMaxZoomLvl()) return false;
    682698        if (zoom < this.getMinZoomLvl()) return false;
     
    690706     *
    691707     * @return    true, if zoom increasing was successfull, false othervise
    692708     */
    693     public boolean zoomDecreaseAllowed()
    694     {
     709    public boolean zoomDecreaseAllowed() {
    695710        return currentZoomLevel > this.getMinZoomLvl();
    696711    }
     712   
    697713    public boolean decreaseZoomLevel() {
    698714        //int minZoom = this.getMinZoomLvl();
    699715        if (zoomDecreaseAllowed()) {
     
    723739            return tile;
    724740        return new Tile(tileSource, x, y, zoom);
    725741    }
     742   
    726743    synchronized Tile getOrCreateTile(int x, int y, int zoom) {
    727744        Tile tile = getTile(x, y, zoom);
    728745        if (tile == null) {
     
    745762        return tile;
    746763    }
    747764
    748     synchronized boolean loadTile(Tile tile, boolean force)
    749     {
     765    synchronized boolean loadTile(Tile tile, boolean force) {
    750766        if (tile == null)
    751767            return false;
    752768        if (!force && (tile.hasError() || tile.isLoaded()))
     
    802818        Main.map.repaint(done ? 0 : 100);
    803819        return !done;
    804820    }
     821   
    805822    boolean imageLoaded(Image i) {
    806823        if (i == null)
    807824            return false;
     
    810827            return true;
    811828        return false;
    812829    }
    813     Image getLoadedTileImage(Tile tile)
    814     {
     830   
     831    /**
     832     * Returns the image for the given tile if both tile and image are loaded.
     833     * Otherwise returns  null.
     834     *
     835     * @param tile the Tile for which the image should be returned
     836     * @return  the image of the tile or null.
     837     */
     838    Image getLoadedTileImage(Tile tile) {
    815839        if (!tile.isLoaded())
    816840            return null;
    817841        Image img = tile.getImage();
     
    820844        return img;
    821845    }
    822846
    823     LatLon tileLatLon(Tile t)
    824     {
     847    LatLon tileLatLon(Tile t) {
    825848        int zoom = t.getZoom();
    826849        return new LatLon(tileSource.tileYToLat(t.getYtile(), zoom),
    827850                tileSource.tileXToLon(t.getXtile(), zoom));
    828851    }
    829852
    830     Rectangle tileToRect(Tile t1)
    831     {
     853    Rectangle tileToRect(Tile t1) {
    832854        /*
    833855         * We need to get a box in which to draw, so advance by one tile in
    834856         * each direction to find the other corner of the box.
     
    846868    //
    847869    // 'border' is the screen cordinates that need to be drawn.
    848870    //  We must not draw outside of it.
    849     void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border)
    850     {
     871    void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) {
    851872        Rectangle target = source;
    852873
    853874        // If a border is specified, only draw the intersection
     
    898919                    target.width, target.height);
    899920        }
    900921    }
     922   
    901923    // This function is called for several zoom levels, not just
    902924    // the current one.  It should not trigger any tiles to be
    903925    // downloaded.  It should also avoid polluting the tile cache
     
    10171039    private Point pixelPos(LatLon ll) {
    10181040        return Main.map.mapView.getPoint(Main.getProjection().latlon2eastNorth(ll).add(getDx(), getDy()));
    10191041    }
     1042   
    10201043    private Point pixelPos(Tile t) {
    10211044        double lon = tileSource.tileXToLon(t.getXtile(), t.getZoom());
    10221045        LatLon tmpLL = new LatLon(tileSource.tileYToLat(t.getYtile(), t.getZoom()), lon);
    10231046        return pixelPos(tmpLL);
    10241047    }
     1048   
    10251049    private LatLon getShiftedLatLon(EastNorth en) {
    10261050        return Main.getProjection().eastNorth2latlon(en.add(-getDx(), -getDy()));
    10271051    }
     1052   
    10281053    private Coordinate getShiftedCoord(EastNorth en) {
    10291054        LatLon ll = getShiftedLatLon(en);
    10301055        return new Coordinate(ll.lat(),ll.lon());
     
    10791104                y1 = tileMax;
    10801105            }
    10811106        }
     1107       
    10821108        boolean tooSmall() {
    10831109            return this.tilesSpanned() < 2.1;
    10841110        }
     1111       
    10851112        boolean tooLarge() {
    10861113            return this.tilesSpanned() > 10;
    10871114        }
     1115       
    10881116        boolean insane() {
    10891117            return this.tilesSpanned() > 100;
    10901118        }
     1119       
    10911120        double tilesSpanned() {
    10921121            return Math.sqrt(1.0 * this.size());
    10931122        }
     
    11021131         * Get all tiles represented by this TileSet that are
    11031132         * already in the tileCache.
    11041133         */
    1105         List<Tile> allExistingTiles()
    1106         {
     1134        List<Tile> allExistingTiles() {
    11071135            return this.__allTiles(false);
    11081136        }
    1109         List<Tile> allTilesCreate()
    1110         {
     1137       
     1138        List<Tile> allTilesCreate() {
    11111139            return this.__allTiles(true);
    11121140        }
    1113         private List<Tile> __allTiles(boolean create)
    1114         {
     1141       
     1142        private List<Tile> __allTiles(boolean create) {
    11151143            // Tileset is either empty or too large
    11161144            if (zoom == 0 || this.insane())
    11171145                return Collections.emptyList();
     
    11311159            }
    11321160            return ret;
    11331161        }
    1134         private List<Tile> allLoadedTiles()
    1135         {
     1162       
     1163        private List<Tile> allLoadedTiles() {
    11361164            List<Tile> ret = new ArrayList<Tile>();
    11371165            for (Tile t : this.allExistingTiles()) {
    11381166                if (t.isLoaded())
     
    11411169            return ret;
    11421170        }
    11431171
    1144         void loadAllTiles(boolean force)
    1145         {
     1172        void loadAllTiles(boolean force) {
    11461173            if (!autoLoad && !force)
    11471174                return;
    11481175            for (Tile t : this.allTilesCreate()) {
     
    11501177            }
    11511178        }
    11521179
    1153         void loadAllErrorTiles(boolean force)
    1154         {
     1180        void loadAllErrorTiles(boolean force) {
    11551181            if (!autoLoad && !force)
    11561182                return;
    11571183            for (Tile t : this.allTilesCreate()) {
     
    11931219        final int minZoom, maxZoom;
    11941220        private final TileSet[] tileSets;
    11951221        private final TileSetInfo[] tileSetInfos;
     1222       
    11961223        public DeepTileSet(EastNorth topLeft, EastNorth botRight, int minZoom, int maxZoom) {
    11971224            this.topLeft = topLeft;
    11981225            this.botRight = botRight;
     
    12011228            this.tileSets = new TileSet[maxZoom - minZoom + 1];
    12021229            this.tileSetInfos = new TileSetInfo[maxZoom - minZoom + 1];
    12031230        }
     1231       
    12041232        public TileSet getTileSet(int zoom) {
    12051233            if (zoom < minZoom)
    12061234                return nullTileSet;
     
    12111239            }
    12121240            return ts;
    12131241        }
     1242       
    12141243        public TileSetInfo getTileSetInfo(int zoom) {
    12151244            if (zoom < minZoom)
    12161245                return new TileSetInfo();
     
    12231252        }
    12241253    }
    12251254
    1226     /**
    1227      */
    12281255    @Override
    12291256    public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    12301257        //long start = System.currentTimeMillis();