Ticket #14796: JMapViewer-2.patch

File JMapViewer-2.patch, 6.3 KB (added by chris.tipper@…, 9 years ago)

revised patch based off today's svn repo, removed the changes objected, inserted a 1500ms timeout for Bing based on local machine perf, eliminated redundant whitespace

  • src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

     
    4444 */
    4545public class JMapViewer extends JPanel implements TileLoaderListener {
    4646
     47    private static final long serialVersionUID = 1L;
     48
    4749    /** whether debug mode is enabled or not */
    4850    public static boolean debug;
    4951
     
    502504            return (int) marker.getRadius();
    503505        else if (p != null) {
    504506            Integer radius = getLatOffset(marker.getLat(), marker.getLon(), marker.getRadius(), false);
    505             radius = radius == null ? null : p.y - radius.intValue();
     507            radius = radius == null ? null : p.y - radius;
    506508            return radius;
    507509        } else
    508510            return null;
  • src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

     
    99import java.util.HashMap;
    1010import java.util.Map;
    1111import java.util.Map.Entry;
    12 import java.util.concurrent.Executors;
     12import java.util.concurrent.LinkedBlockingQueue;
    1313import java.util.concurrent.ThreadPoolExecutor;
     14import java.util.concurrent.TimeUnit;
    1415
    1516import org.openstreetmap.gui.jmapviewer.interfaces.TileJob;
    1617import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
     
    2223 * @author Jan Peter Stotz
    2324 */
    2425public class OsmTileLoader implements TileLoader {
    25     private static final ThreadPoolExecutor jobDispatcher = (ThreadPoolExecutor) Executors.newFixedThreadPool(3);
     26   
     27    private static final ThreadPoolExecutor jobDispatcher = new ThreadPoolExecutor(8, 24, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(2_000));
    2628
    2729    private final class OsmTileJob implements TileJob {
    2830        private final Tile tile;
     
    178180
    179181    @Override
    180182    public void cancelOutstandingTasks() {
    181         jobDispatcher.getQueue().clear();
     183        for (Runnable item : jobDispatcher.getQueue()) {
     184            jobDispatcher.remove(item);
     185        }
    182186    }
    183187
    184188    /**
  • src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

     
    263263            }
    264264        }
    265265        try {
    266             return attributions.get(0, TimeUnit.MILLISECONDS);
     266            return attributions.get(1500, TimeUnit.MILLISECONDS);
    267267        } catch (TimeoutException ex) {
    268268            System.err.println("Bing: attribution data is not yet loaded.");
    269269        } catch (ExecutionException ex) {
  • src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java

     
    11// License: GPL. For details, see Readme.txt file.
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
     4import java.io.IOException;
     5import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     6
    47/**
    58 * OSM Tile source.
    69 */
     
    3740     */
    3841    public static class CycleMap extends AbstractOsmTileSource {
    3942
    40         private static final String PATTERN = "http://%s.tile.opencyclemap.org/cycle";
     43        private static final String API_KEY = "API_KEY";
    4144
    42         private static final String[] SERVER = {"a", "b", "c"};
     45        private static final String PATTERN = "https://%s.tile.thunderforest.com/cycle";
    4346
     47        private static final String[] SERVER = { "a", "b", "c" };
     48
    4449        private int serverNum;
    4550
    4651        /**
     
    4752         * Constructs a new {@code CycleMap} tile source.
    4853         */
    4954        public CycleMap() {
    50             super("Cyclemap", PATTERN, "opencyclemap");
     55            super("OSM Cycle Map", PATTERN, "opencyclemap");
    5156        }
    5257
    5358        @Override
     
    6166        public int getMaxZoom() {
    6267            return 18;
    6368        }
     69
     70        @Override
     71        public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
     72            return this.getBaseUrl() + getTilePath(zoom, tilex, tiley); // + "?apikey=" + API_KEY;
     73        }
     74
     75        @Override
     76        public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
     77            return "Maps © Thunderforest, Data © OpenStreetMap contributors";
     78        }
     79
     80        @Override
     81        public String getAttributionLinkURL() {
     82            return "http://www.thunderforest.com/";
     83        }
    6484    }
     85
    6586}
  • src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java

     
    116116    @Override
    117117    public Point latLonToXY(double lat, double lon, int zoom) {
    118118        return new Point(
    119                 (int) osmMercator.lonToX(lon, zoom),
    120                 (int) latToTileY(lat, zoom)
     119                (int) Math.round(osmMercator.lonToX(lon, zoom)),
     120                (int) Math.round(latToTileY(lat, zoom))
    121121                );
    122122    }
    123123
  • src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

     
    5050    @Override
    5151    public Point latLonToXY(double lat, double lon, int zoom) {
    5252        return new Point(
    53                 (int) osmMercator.lonToX(lon, zoom),
    54                 (int) osmMercator.latToY(lat, zoom)
     53                (int) Math.round(osmMercator.lonToX(lon, zoom)),
     54                (int) Math.round(osmMercator.latToY(lat, zoom))
    5555                );
    5656    }
    5757