Changeset 33313 in osm for applications


Ignore:
Timestamp:
2017-05-16T19:00:23+02:00 (7 years ago)
Author:
bastik
Message:

see #josm14796 - various improvements for JMapViewer (patch by Chris Tipper)

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
4 edited

Legend:

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

    r32723 r33313  
    4444 */
    4545public class JMapViewer extends JPanel implements TileLoaderListener {
     46
     47    private static final long serialVersionUID = 1L;
    4648
    4749    /** whether debug mode is enabled or not */
     
    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
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java

    r31790 r33313  
    11// License: GPL. For details, see Readme.txt file.
    22package org.openstreetmap.gui.jmapviewer.tilesources;
     3
     4import java.io.IOException;
     5
     6import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    37
    48/**
     
    6367        }
    6468    }
     69
     70    /**
     71     * The "Transport Map" OSM tile source.
     72     *
     73     * Template for thunderforest.com
     74     */
     75    public static class TransportMap extends AbstractOsmTileSource {
     76
     77        private static final String API_KEY = "API_KEY_HERE";
     78
     79        private static final String PATTERN = "https://%s.tile.thunderforest.com/transport";
     80
     81        private static final String[] SERVER = { "a", "b", "c" };
     82
     83        private int serverNum;
     84
     85        /**
     86         * Constructs a new {@code TransportMap} tile source.
     87         */
     88        public TransportMap() {
     89            super("OSM Transport Map", PATTERN, "osmtransportmap");
     90        }
     91
     92        @Override
     93        public String getBaseUrl() {
     94            String url = String.format(this.baseUrl, new Object[] {SERVER[serverNum]});
     95            serverNum = (serverNum + 1) % SERVER.length;
     96            return url;
     97        }
     98
     99        @Override
     100        public int getMaxZoom() {
     101            return 18;
     102        }
     103
     104        @Override
     105        public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
     106            return this.getBaseUrl() + getTilePath(zoom, tilex, tiley); // + "?apikey=" + API_KEY;
     107        }
     108
     109        @Override
     110        public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
     111            return "Maps © Thunderforest, Data © OpenStreetMap contributors";
     112        }
     113
     114        @Override
     115        public String getAttributionLinkURL() {
     116            return "http://www.thunderforest.com/";
     117        }
     118    }
     119
    65120}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java

    r33128 r33313  
    110110
    111111    // Latitude to Y and back calculations.
    112     private static double RADIUS_E = 6378137;   /* radius of Earth at equator, m */
    113     private static double EQUATOR = 40075016.68557849; /* equator length, m */
    114     private static double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
     112    private static final double RADIUS_E = 6378137;   /* radius of Earth at equator, m */
     113    private static final double EQUATOR = 40075016.68557849; /* equator length, m */
     114    private static final double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
    115115
    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    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

    r33286 r33313  
    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    }
Note: See TracChangeset for help on using the changeset viewer.