Changeset 32025 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2016-01-24T23:10:45+01:00 (9 years ago)
Author:
wiktorn
Message:

Refactor structure of TMS based classes.

Move OsmMercator initialization to TMSTileSource and switch all TMS
based TileSource so they extend TMSTileSource.

Now WMTSTileSource will not create OsmMercator object that it will not
use anyhow.

AbstractTMSTileSource could be named now AbstractTileBasedTileSource,
but I did not the name change, to maintain history.

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

Legend:

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

    r31791 r32025  
    99 * Abstract class for OSM Tile sources
    1010 */
    11 public abstract class AbstractOsmTileSource extends AbstractTMSTileSource {
    12    
     11public abstract class AbstractOsmTileSource extends TMSTileSource {
     12
    1313    /**
    14      * The OSM attribution. Must be always in line with 
     14     * The OSM attribution. Must be always in line with
    1515     * <a href="https://www.openstreetmap.org/copyright/en">https://www.openstreetmap.org/copyright/en</a>
    1616     */
    1717    public static final String DEFAULT_OSM_ATTRIBUTION = "\u00a9 OpenStreetMap contributors";
    18    
     18
    1919    /**
    2020     * Constructs a new OSM tile source
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r32024 r32025  
    1111import java.util.Map.Entry;
    1212
    13 import org.openstreetmap.gui.jmapviewer.Coordinate;
    1413import org.openstreetmap.gui.jmapviewer.OsmMercator;
    1514import org.openstreetmap.gui.jmapviewer.Tile;
     
    3231    private final Map<String, String> metadataHeaders;
    3332    protected int tileSize;
    34     protected OsmMercator osmMercator;
    3533
    3634    /**
     
    5048        this.metadataHeaders = info.getMetadataHeaders();
    5149        this.tileSize = info.getTileSize();
    52         this.osmMercator = new OsmMercator(this.getTileSize());
    5350    }
    5451
     
    128125
    129126    @Override
    130     public double getDistance(double lat1, double lon1, double lat2, double lon2) {
    131         return osmMercator.getDistance(lat1, lon1, lat2, lon2);
    132     }
    133 
    134     @Override
    135     public Point latLonToXY(double lat, double lon, int zoom) {
    136         return new Point(
    137                 (int) osmMercator.lonToX(lon, zoom),
    138                 (int) osmMercator.latToY(lat, zoom)
    139                 );
    140     }
    141 
    142     @Override
    143127    public Point latLonToXY(ICoordinate point, int zoom) {
    144128        return latLonToXY(point.getLat(), point.getLon(), zoom);
     
    151135
    152136    @Override
    153     public ICoordinate xyToLatLon(int x, int y, int zoom) {
    154         return new Coordinate(
    155                 osmMercator.yToLat(y, zoom),
    156                 osmMercator.xToLon(x, zoom)
    157                 );
    158     }
    159 
    160     @Override
    161     public TileXY latLonToTileXY(double lat, double lon, int zoom) {
    162         return new TileXY(
    163                 osmMercator.lonToX(lon, zoom) / getTileSize(),
    164                 osmMercator.latToY(lat, zoom) / getTileSize()
    165                 );
    166     }
    167 
    168     @Override
    169137    public TileXY latLonToTileXY(ICoordinate point, int zoom) {
    170138        return latLonToTileXY(point.getLat(), point.getLon(), zoom);
     
    179147    public ICoordinate tileXYToLatLon(Tile tile) {
    180148        return tileXYToLatLon(tile.getXtile(), tile.getYtile(), tile.getZoom());
    181     }
    182 
    183     @Override
    184     public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
    185         return new Coordinate(
    186                 osmMercator.yToLat(y * getTileSize(), zoom),
    187                 osmMercator.xToLon(x * getTileSize(), zoom)
    188                 );
    189149    }
    190150
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r31855 r32025  
    3737import org.xml.sax.SAXException;
    3838
    39 public class BingAerialTileSource extends AbstractTMSTileSource {
     39public class BingAerialTileSource extends TMSTileSource {
    4040
    4141    private static final String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU";
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

    r31790 r32025  
    11// License: GPL. For details, see Readme.txt file.
    22package org.openstreetmap.gui.jmapviewer.tilesources;
     3
     4import java.awt.Point;
     5
     6import org.openstreetmap.gui.jmapviewer.Coordinate;
     7import org.openstreetmap.gui.jmapviewer.OsmMercator;
     8import org.openstreetmap.gui.jmapviewer.TileXY;
     9import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    310
    411public class TMSTileSource extends AbstractTMSTileSource {
     
    613    protected int maxZoom;
    714    protected int minZoom;
     15    protected OsmMercator osmMercator;
    816
    917    public TMSTileSource(TileSourceInfo info) {
     
    1119        minZoom = info.getMinZoom();
    1220        maxZoom = info.getMaxZoom();
     21        this.osmMercator = new OsmMercator(this.getTileSize());
    1322    }
    1423
     
    2231        return (maxZoom == 0) ? super.getMaxZoom() : maxZoom;
    2332    }
     33    @Override
     34    public double getDistance(double lat1, double lon1, double lat2, double lon2) {
     35        return osmMercator.getDistance(lat1, lon1, lat2, lon2);
     36    }
     37
     38    @Override
     39    public Point latLonToXY(double lat, double lon, int zoom) {
     40        return new Point(
     41                (int) osmMercator.lonToX(lon, zoom),
     42                (int) osmMercator.latToY(lat, zoom)
     43                );
     44    }
     45
     46    @Override
     47    public ICoordinate xyToLatLon(int x, int y, int zoom) {
     48        return new Coordinate(
     49                osmMercator.yToLat(y, zoom),
     50                osmMercator.xToLon(x, zoom)
     51                );
     52    }
     53
     54    @Override
     55    public TileXY latLonToTileXY(double lat, double lon, int zoom) {
     56        return new TileXY(
     57                osmMercator.lonToX(lon, zoom) / getTileSize(),
     58                osmMercator.latToY(lat, zoom) / getTileSize()
     59                );
     60    }
     61
     62    @Override
     63    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
     64        return new Coordinate(
     65                osmMercator.yToLat(y * getTileSize(), zoom),
     66                osmMercator.xToLon(x * getTileSize(), zoom)
     67                );
     68    }
    2469}
Note: See TracChangeset for help on using the changeset viewer.