Changeset 36138 in osm


Ignore:
Timestamp:
2023-09-15T16:54:54+02:00 (16 months ago)
Author:
taylor.smock
Message:

Fix #23113: Add default methods to JMapViewer TileSource interface

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

Legend:

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

    r34765 r36138  
    1313
    1414/**
     15 * Used for generating tiles
    1516 *
    1617 * @author Jan Peter Stotz
     
    4546    /**
    4647     * A unique id for this tile source.
    47      *
     48     * <p>
    4849     * Unlike the name it has to be unique and has to consist only of characters
    4950     * valid for filenames.
     
    111112     * @return the pixel coordinates
    112113     */
    113     Point latLonToXY(ICoordinate point, int zoom);
     114    default Point latLonToXY(ICoordinate point, int zoom) {
     115        return latLonToXY(point.getLat(), point.getLon(), zoom);
     116    }
    114117
    115118    /**
     
    119122     * @return WGS84 Coordinates of given point
    120123     */
    121     ICoordinate xyToLatLon(Point point, int zoom);
     124    default ICoordinate xyToLatLon(Point point, int zoom) {
     125        return xyToLatLon(point.x, point.y, zoom);
     126    }
    122127
    123128    /**
     
    145150     * @return x and y tile indices
    146151     */
    147     TileXY latLonToTileXY(ICoordinate point, int zoom);
     152    default TileXY latLonToTileXY(ICoordinate point, int zoom) {
     153        return latLonToTileXY(point.getLat(), point.getLon(), zoom);
     154    }
    148155
    149156    /**
     
    153160     * @return WGS84 coordinates of given tile
    154161     */
    155     ICoordinate tileXYToLatLon(TileXY xy, int zoom);
     162    default ICoordinate tileXYToLatLon(TileXY xy, int zoom) {
     163        return tileXYToLatLon(xy.getXIndex(), xy.getYIndex(), zoom);
     164    }
    156165
    157166    /**
     
    161170     * @return WGS84 coordinates of given tile
    162171     */
    163     ICoordinate tileXYToLatLon(Tile tile);
     172    default ICoordinate tileXYToLatLon(Tile tile) {
     173        return tileXYToLatLon(tile.getXtile(), tile.getYtile(), tile.getZoom());
     174    }
    164175
    165176    /**
     
    249260     * Returns a range of tiles, that cover a given tile, which is
    250261     * usually at a different zoom level.
    251      *
     262     * <p>
    252263     * In standard tile layout, 4 tiles cover a tile one zoom lower, 16 tiles
    253264     * cover a tile 2 zoom levels below etc.
     
    263274    /**
    264275     * Get coordinate reference system for this tile source.
    265      *
     276     * <p>
    266277     * E.g. "EPSG:3857" for Google-Mercator.
    267278     * @return code for the coordinate reference system in use
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r35190 r36138  
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
    4 import java.awt.Point;
    54import java.io.IOException;
    65import java.security.MessageDigest;
     
    1110import java.util.Map.Entry;
    1211import java.util.Set;
    13 
     12import java.util.logging.Level;
     13
     14import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    1415import org.openstreetmap.gui.jmapviewer.JMapViewer;
    1516import org.openstreetmap.gui.jmapviewer.OsmMercator;
    16 import org.openstreetmap.gui.jmapviewer.Tile;
    17 import org.openstreetmap.gui.jmapviewer.TileXY;
    18 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    1917
    2018/**
     
    4038     * @param info description of the Tile Source
    4139     */
    42     public AbstractTMSTileSource(TileSourceInfo info) {
     40    protected AbstractTMSTileSource(TileSourceInfo info) {
    4341        this.name = info.getName();
    4442        this.baseUrl = info.getUrl();
     
    9088
    9189    /**
     90     * Get the tile path after the URL
    9291     * @param zoom level of the tile
    9392     * @param tilex tile number in x axis
    9493     * @param tiley tile number in y axis
    95      * @return String containg path part of URL of the tile
     94     * @return String containing path part of URL of the tile
    9695     * @throws IOException when subclass cannot return the tile URL
    9796     */
     
    126125        }
    127126        return tileSize;
    128     }
    129 
    130     @Override
    131     public Point latLonToXY(ICoordinate point, int zoom) {
    132         return latLonToXY(point.getLat(), point.getLon(), zoom);
    133     }
    134 
    135     @Override
    136     public ICoordinate xyToLatLon(Point point, int zoom) {
    137         return xyToLatLon(point.x, point.y, zoom);
    138     }
    139 
    140     @Override
    141     public TileXY latLonToTileXY(ICoordinate point, int zoom) {
    142         return latLonToTileXY(point.getLat(), point.getLon(), zoom);
    143     }
    144 
    145     @Override
    146     public ICoordinate tileXYToLatLon(TileXY xy, int zoom) {
    147         return tileXYToLatLon(xy.getXIndex(), xy.getYIndex(), zoom);
    148     }
    149 
    150     @Override
    151     public ICoordinate tileXYToLatLon(Tile tile) {
    152         return tileXYToLatLon(tile.getXtile(), tile.getYtile(), tile.getZoom());
    153127    }
    154128
     
    191165        if (noTileChecksums != null && content != null) {
    192166            for (Entry<String, Set<String>> searchEntry: noTileChecksums.entrySet()) {
    193                 MessageDigest md = null;
     167                MessageDigest md;
    194168                try {
    195169                    md = MessageDigest.getInstance(searchEntry.getKey());
    196170                } catch (NoSuchAlgorithmException e) {
     171                    FeatureAdapter.getLogger(this.getClass()).log(Level.FINER, searchEntry.getKey() + " algorithm was not found", e);
    197172                    break;
    198173                }
     
    201176
    202177                char[] hexChars = new char[len * 2];
    203                 for (int i = 0, j = 0; i < len; i++) {
    204                     final int v = byteDigest[i];
     178                int j = 0;
     179                for (final int v : byteDigest) {
    205180                    int vn = (v & 0xf0) >> 4;
    206                     hexChars[j++] = (char) (vn + (vn >= 10 ? 'a'-10 : '0'));
     181                    hexChars[j++] = (char) (vn + (vn >= 10 ? 'a' - 10 : '0'));
    207182                    vn = (v & 0xf);
    208                     hexChars[j++] = (char) (vn + (vn >= 10 ? 'a'-10 : '0'));
     183                    hexChars[j++] = (char) (vn + (vn >= 10 ? 'a' - 10 : '0'));
    209184                }
    210185                for (String val: searchEntry.getValue()) {
Note: See TracChangeset for help on using the changeset viewer.