Ignore:
Timestamp:
2015-06-24T20:57:27+02:00 (10 years ago)
Author:
wiktorn
Message:

Introduce WMS layer based on TMS. (closes: #josm11255)

HEADS UP: After this patch you need to manually remove JAX-B generated file/class: org/w3/_2001/xmlschema/Adapter1.java to compile the tree again.

  • create AbstractTileSourceLayer based on TMSLayer as a base for TMS, WMS and (future) WMTS layers, (addresses #josm11459)
  • WMS layer now uses JCS Caching (closes: #josm7363)
  • introduce new conversion methods in TileSource, that convert both X and Y (lat and lon) in one call. This is necessary for other than PseudoMercator projections
    • introduce TileXY class that represents X and Y indexes of tile in tile matrix/space
    • mark old conversion methods as deprecated
    • refactor JMapViewer and JOSM to new methods
    • change use of Coordinate class to ICoordinate where appropiate
  • extract CachedAttributionBingAerialTileSource to separate file
  • create TemplatedWMSTileSource that provides the WMS Layer with square (according to current projection) tiles (closes: #josm11572, closes: #josm7682, addresses: #josm5454)
  • implemented precaching imagery along GPX track for AbstractTileSourceLayer, so now it work for both - WMS and TMS (closes: #josm9154)
  • implemented common righ-click menu on map view, as well on layer list (closes #josm3591)
  • create separate build commands for JMapViewer classes to easily spot, when josm classes are used within JMapViewer
  • remove unnecessary classes of previous WMS implementation - GeorefImage, wms-cache.xsd (and JAXB task from build), WMSCache, WMSRequest, WMSGrabber, HTMLGrabber, WMSException

After this patch you need to manually remove JAX-B generated file/class: org/w3/_2001/xmlschema/Adapter1.java

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

Legend:

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

    r30426 r31301  
    1616
    1717import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
     18import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    1819
    1920public class AttributionSupport {
     
    5354    }
    5455
    55     public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) {
     56    public void paintAttribution(Graphics g, int width, int height, ICoordinate topLeft, ICoordinate bottomRight, int zoom, ImageObserver observer) {
    5657        if (source == null || !source.requiresAttribution()) {
    5758            attrToUBounds = null;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r31293 r31301  
    191191     *            {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM}
    192192     */
    193     public void setDisplayPosition(Coordinate to, int zoom) {
     193    public void setDisplayPosition(ICoordinate to, int zoom) {
    194194        setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), to, zoom);
    195195    }
     
    209209     *            {@link TileSource#getMaxZoom()}
    210210     */
    211     public void setDisplayPosition(Point mapPoint, Coordinate to, int zoom) {
    212         int x = tileSource.LonToX(to.getLon(), zoom);
    213         int y = tileSource.LatToY(to.getLat(), zoom);
    214         setDisplayPosition(mapPoint, x, y, zoom);
     211    public void setDisplayPosition(Point mapPoint, ICoordinate to, int zoom) {
     212        Point p = tileSource.latLonToXY(to, zoom);
     213        setDisplayPosition(mapPoint, p.x, p.y, zoom);
    215214    }
    216215
     
    268267                for (MapMarker marker : mapMarkerList) {
    269268                    if (marker.isVisible()) {
    270                         int x = tileSource.LonToX(marker.getLon(), mapZoomMax);
    271                         int y = tileSource.LatToY(marker.getLat(), mapZoomMax);
    272                         x_max = Math.max(x_max, x);
    273                         y_max = Math.max(y_max, y);
    274                         x_min = Math.min(x_min, x);
    275                         y_min = Math.min(y_min, y);
     269                        Point p = tileSource.latLonToXY(marker.getCoordinate(), mapZoomMax);
     270                        x_max = Math.max(x_max, p.x);
     271                        y_max = Math.max(y_max, p.y);
     272                        x_min = Math.min(x_min, p.x);
     273                        y_min = Math.min(y_min, p.y);
    276274                    }
    277275                }
     
    283281                for (MapRectangle rectangle : mapRectangleList) {
    284282                    if (rectangle.isVisible()) {
    285                         x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax));
    286                         y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax));
    287                         x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax));
    288                         y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax));
     283                        Point bottomRight = tileSource.latLonToXY(rectangle.getBottomRight(), mapZoomMax);
     284                        Point topLeft = tileSource.latLonToXY(rectangle.getTopLeft(), mapZoomMax);
     285                        x_max = Math.max(x_max, bottomRight.x);
     286                        y_max = Math.max(y_max, topLeft.y);
     287                        x_min = Math.min(x_min, topLeft.x);
     288                        y_min = Math.min(y_min, bottomRight.y);
    289289                    }
    290290                }
     
    297297                    if (polygon.isVisible()) {
    298298                        for (ICoordinate c : polygon.getPoints()) {
    299                             int x = tileSource.LonToX(c.getLon(), mapZoomMax);
    300                             int y = tileSource.LatToY(c.getLat(), mapZoomMax);
    301                             x_max = Math.max(x_max, x);
    302                             y_max = Math.max(y_max, y);
    303                             x_min = Math.min(x_min, x);
    304                             y_min = Math.min(y_min, y);
     299                            Point p = tileSource.latLonToXY(c, mapZoomMax);
     300                            x_max = Math.max(x_max, p.x);
     301                            y_max = Math.max(y_max, p.y);
     302                            x_min = Math.min(x_min, p.x);
     303                            y_min = Math.min(y_min, p.y);
    305304                        }
    306305                    }
     
    368367     * @return latitude / longitude
    369368     */
    370     public Coordinate getPosition() {
    371         double lon = tileSource.XToLon(center.x, zoom);
    372         double lat = tileSource.YToLat(center.y, zoom);
    373         return new Coordinate(lat, lon);
     369    public ICoordinate getPosition() {
     370        return tileSource.XYToLatLon(center, zoom);
    374371    }
    375372
     
    383380     * @return latitude / longitude
    384381     */
    385     public Coordinate getPosition(Point mapPoint) {
     382    public ICoordinate getPosition(Point mapPoint) {
    386383        return getPosition(mapPoint.x, mapPoint.y);
    387384    }
     
    395392     * @return latitude / longitude
    396393     */
    397     public Coordinate getPosition(int mapPointX, int mapPointY) {
     394    public ICoordinate getPosition(int mapPointX, int mapPointY) {
    398395        int x = center.x + mapPointX - getWidth() / 2;
    399396        int y = center.y + mapPointY - getHeight() / 2;
    400         double lon = tileSource.XToLon(x, zoom);
    401         double lat = tileSource.YToLat(y, zoom);
    402         return new Coordinate(lat, lon);
     397        return tileSource.XYToLatLon(x, y, zoom);
    403398    }
    404399
     
    413408     */
    414409    public Point getMapPosition(double lat, double lon, boolean checkOutside) {
    415         int x = tileSource.LonToX(lon, zoom);
    416         int y = tileSource.LatToY(lat, zoom);
    417         x -= center.x - getWidth() / 2;
    418         y -= center.y - getHeight() / 2;
     410        Point p = tileSource.latLonToXY(lat, lon, zoom);
     411        p.translate(-(center.x - getWidth() / 2), -(center.y - getHeight() /2));
     412
    419413        if (checkOutside) {
    420             if (x < 0 || y < 0 || x > getWidth() || y > getHeight())
     414            if (p.x < 0 || p.y < 0 || p.x > getWidth() || p.y > getHeight())
    421415                return null;
    422416        }
    423         return new Point(x, y);
     417        return p;
     418    }
     419
     420    /**
     421     * Calculates the position on the map of a given coordinate
     422     *
     423     * @param lat Latitude
     424     * @param lon longitude
     425     * @param offset Offset respect Latitude
     426     * @param checkOutside
     427     * @return Integer the radius in pixels
     428     */
     429    public Integer getLatOffset(double lat, double lon, double offset, boolean checkOutside) {
     430        Point p = tileSource.latLonToXY(lat, lon, zoom);
     431        int y = p.y - center.y - getHeight() / 2;
     432        if (checkOutside) {
     433            if (y < 0 || y > getHeight())
     434                return null;
     435        }
     436        return y;
    424437    }
    425438
     
    432445     * @return Integer the radius in pixels
    433446     */
     447    @Deprecated
    434448    public Integer getLatOffset(double lat, double offset, boolean checkOutside) {
    435449        int y = tileSource.LatToY(lat + offset, zoom);
     
    463477            return (int) marker.getRadius();
    464478        else if (p != null) {
    465             Integer radius = getLatOffset(marker.getLat(), marker.getRadius(), false);
     479            Integer radius = getLatOffset(marker.getLat(), marker.getLon(), marker.getRadius(), false);
    466480            radius = radius == null ? null : p.y - radius.intValue();
    467481            return radius;
     
    509523        double pDistance = center.distance(origin);
    510524
    511         Coordinate originCoord = getPosition(origin);
    512         Coordinate centerCoord = getPosition(center);
     525        ICoordinate originCoord = getPosition(origin);
     526        ICoordinate centerCoord = getPosition(center);
    513527
    514528        double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(),
     
    826840                || zoom == this.zoom)
    827841            return;
    828         Coordinate zoomPos = getPosition(mapPoint);
     842        ICoordinate zoomPos = getPosition(mapPoint);
    829843        tileController.cancelOutstandingJobs(); // Clearing outstanding load
    830844        // requests
     
    971985        if (tileSource.getMinZoom() < MIN_ZOOM)
    972986            throw new RuntimeException("Minimum zoom level too low");
    973         Coordinate position = getPosition();
     987        ICoordinate position = getPosition();
    974988        this.tileSource = tileSource;
    975989        tileController.setTileSource(tileSource);
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java

    r30223 r31301  
    33
    44import java.awt.Image;
    5 
    6 import org.openstreetmap.gui.jmapviewer.Coordinate;
    75
    86public interface Attributed {
     
    1816     * @return Attribution text for the image source.
    1917     */
    20     String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight);
     18    String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight);
    2119
    2220    /**
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r31293 r31301  
    22package org.openstreetmap.gui.jmapviewer.interfaces;
    33
     4import java.awt.Point;
    45import java.io.IOException;
    56import java.util.List;
     
    78
    89import org.openstreetmap.gui.jmapviewer.JMapViewer;
     10import org.openstreetmap.gui.jmapviewer.Tile;
     11import org.openstreetmap.gui.jmapviewer.TileXY;
    912
    1013/**
     
    3639     *
    3740     */
     41    @Deprecated //not used anymore
    3842    public enum TileUpdate {
    3943        IfNoneMatch, ETag, IfModifiedSince, LastModified, None
     
    9397
    9498    /**
    95      * Specifies the tile image type. For tiles rendered by Mapnik or
    96      * Osmarenderer this is usually <code>"png"</code>.
    97      *
    98      * @return file extension of the tile image type
    99      */
    100     String getTileType();
    101 
    102     /**
    10399     * Specifies how large each tile is.
    104      * @return The size of a single tile in pixels.
     100     * @return The size of a single tile in pixels. -1 if default size should be used
    105101     */
    106102    int getTileSize();
    107103
    108104    /**
     105     * @return default tile size, for this tile source
     106     * TODO: @since
     107     */
     108    public int getDefaultTileSize();
     109
     110    /**
    109111     * Gets the distance using Spherical law of cosines.
    110      *  @return the distance, m.
     112     * @param la1 latitude of first point
     113     * @param lo1 longitude of first point
     114     * @param la2 latitude of second point
     115     * @param lo2 longitude of second point
     116     * @return the distance betwen first and second point, in m.
    111117     */
    112118    double getDistance(double la1, double lo1, double la2, double lo2);
     
    114120    /**
    115121     * Transform longitude to pixelspace.
     122     * @param aLongitude
     123     * @param aZoomlevel
    116124     * @return [0..2^Zoomlevel*TILE_SIZE[
    117125     */
     126    @Deprecated
    118127    int LonToX(double aLongitude, int aZoomlevel);
    119128
    120129    /**
    121130     * Transforms latitude to pixelspace.
     131     * @param aLat
     132     * @param aZoomlevel
    122133     * @return [0..2^Zoomlevel*TILE_SIZE[
    123      */
     134     * @deprecated use lonLatToXY instead
     135     */
     136    @Deprecated
    124137    int LatToY(double aLat, int aZoomlevel);
    125138
    126139    /**
     140     * @param lon
     141     * @param lat
     142     * @param zoom
     143     * @return transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined)
     144     */
     145    public Point latLonToXY(double lat, double lon, int zoom);
     146
     147    public Point latLonToXY(ICoordinate point, int zoom);
     148
     149    /**
    127150     * Transforms pixel coordinate X to longitude
     151     * @param aX
     152     * @param aZoomlevel
    128153     * @return ]-180..180[
    129154     */
     155    @Deprecated
    130156    double XToLon(int aX, int aZoomlevel);
    131157
    132158    /**
    133159     * Transforms pixel coordinate Y to latitude.
     160     * @param aY
     161     * @param aZoomlevel
    134162     * @return [MIN_LAT..MAX_LAT]
    135163     */
     164    @Deprecated
    136165    double YToLat(int aY, int aZoomlevel);
    137166
    138167    /**
     168     * @param point
     169     * @param zoom
     170     * @return WGS84 Coordinates of given point
     171     */
     172    public ICoordinate XYToLatLon(Point point, int zoom);
     173
     174    public ICoordinate XYToLatLon(int x, int y, int zoom);
     175
     176    /**
    139177     * Transforms longitude to X tile coordinate.
     178     * @param lon
     179     * @param zoom
    140180     * @return [0..2^Zoomlevel[
    141181     */
     182    @Deprecated
    142183    double lonToTileX(double lon, int zoom);
    143184
    144185    /**
    145186     * Transforms latitude to Y tile coordinate.
     187     * @param lat
     188     * @param zoom
    146189     * @return [0..2^Zoomlevel[
    147190     */
     191    @Deprecated
    148192    double latToTileY(double lat, int zoom);
    149193
    150194    /**
     195     * @param lon
     196     * @param lat
     197     * @param zoom
     198     * @return x and y tile indices
     199     */
     200    public TileXY latLonToTileXY(double lat, double lon, int zoom);
     201
     202    public TileXY latLonToTileXY(ICoordinate point, int zoom);
     203
     204    /**
    151205     * Transforms tile X coordinate to longitude.
     206     * @param x
     207     * @param zoom
    152208     * @return ]-180..180[
    153209     */
     210    @Deprecated
    154211    double tileXToLon(int x, int zoom);
    155212
    156213    /**
    157214     * Transforms tile Y coordinate to latitude.
     215     * @param y
     216     * @param zoom
    158217     * @return [MIN_LAT..MAX_LAT]
    159218     */
     219    @Deprecated
    160220    double tileYToLat(int y, int zoom);
     221
     222    /**
     223     * @param xy
     224     * @param zoom
     225     * @return WGS84 coordinates of given tile
     226     */
     227    public ICoordinate tileXYToLatLon(TileXY xy, int zoom);
     228
     229    public ICoordinate tileXYToLatLon(Tile tile);
     230
     231    public ICoordinate tileXYToLatLon(int x, int y, int zoom);
     232
     233    /**
     234     * @param zoom
     235     * @return maximum X index of tile for specified zoom level
     236     */
     237    public int getTileXMax(int zoom);
     238
     239    /**
     240     *
     241     * @param zoom
     242     * @return minimum X index of tile for specified zoom level
     243     */
     244    public int getTileXMin(int zoom);
     245
     246    /**
     247     *
     248     * @param zoom
     249     * @return maximum Y index of tile for specified zoom level
     250     */
     251    public int getTileYMax(int zoom);
     252
     253    /**
     254     * @param zoom
     255     * @return minimum Y index of tile for specified zoom level
     256     */
     257    public int getTileYMin(int zoom);
    161258
    162259    /**
     
    178275     */
    179276    public Map<String, String> getMetadata(Map<String, List<String>> headers);
     277
     278
    180279}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java

    r31122 r31301  
    44import java.awt.Image;
    55
    6 import org.openstreetmap.gui.jmapviewer.Coordinate;
     6import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    77
    88/**
     
    3939
    4040    @Override
    41     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     41    public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
    4242        return DEFAULT_OSM_ATTRIBUTION;
    4343    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java

    r31142 r31301  
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
     4import java.awt.Point;
    45import java.io.IOException;
    56import java.util.HashMap;
     
    89import java.util.Map.Entry;
    910
     11import org.openstreetmap.gui.jmapviewer.Coordinate;
    1012import org.openstreetmap.gui.jmapviewer.OsmMercator;
    11 
     13import org.openstreetmap.gui.jmapviewer.Tile;
     14import org.openstreetmap.gui.jmapviewer.TileXY;
     15import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     16
     17/**
     18 * Class generalizing all tile based tile sources
     19 *
     20 * @author Wiktor Niesiobędzki
     21 *
     22 */
    1223public abstract class AbstractTMSTileSource extends AbstractTileSource {
    1324
     
    2031    protected OsmMercator osmMercator;
    2132
     33    /**
     34     * Creates an instance based on TileSource information
     35     *
     36     * @param info description of the Tile Source
     37     */
    2238    public AbstractTMSTileSource(TileSourceInfo info) {
    2339        this.name = info.getName();
     
    3349    }
    3450
     51    /**
     52     * @return default tile size to use, when not set in Imagery Preferences
     53     */
     54    public int getDefaultTileSize() {
     55        return OsmMercator.DEFAUL_TILE_SIZE;
     56    }
     57
    3558    @Override
    3659    public String getName() {
     
    5376    }
    5477
     78    /**
     79     * @return image extension, used for URL creation
     80     */
    5581    public String getExtension() {
    5682        return "png";
     
    5884
    5985    /**
     86     * @param zoom level of the tile
     87     * @param tilex tile number in x axis
     88     * @param tiley tile number in y axis
     89     * @return String containg path part of URL of the tile
    6090     * @throws IOException when subclass cannot return the tile URL
    6191     */
     
    6494    }
    6595
     96    /**
     97     * @return Base part of the URL of the tile source
     98     */
    6699    public String getBaseUrl() {
    67100        return this.baseUrl;
     
    78111    }
    79112
    80     @Override
    81     public String getTileType() {
    82         return "png";
    83     }
    84 
    85113    /*
    86114     * Most tilesources use OsmMercator projection.
     
    88116    @Override
    89117    public int getTileSize() {
     118        if (tileSize <= 0) {
     119            return getDefaultTileSize();
     120        }
    90121        return tileSize;
    91122    }
     
    107138
    108139    @Override
     140    public Point latLonToXY(double lat, double lon, int zoom) {
     141        return new Point(
     142                (int)osmMercator.LonToX(lon, zoom),
     143                (int)osmMercator.LatToY(lat, zoom)
     144                );
     145    }
     146
     147    @Override
     148    public Point latLonToXY(ICoordinate point, int zoom) {
     149        return latLonToXY(point.getLat(), point.getLon(), zoom);
     150    }
     151
     152    @Override
    109153    public double XToLon(int x, int zoom) {
    110154        return osmMercator.XToLon(x, zoom);
     
    117161
    118162    @Override
     163    public Coordinate XYToLatLon(Point point, int zoom) {
     164        return XYToLatLon(point.x, point.y, zoom);
     165    }
     166
     167    @Override
     168    public Coordinate XYToLatLon(int x, int y, int zoom) {
     169        return new Coordinate(
     170                osmMercator.YToLat(y, zoom),
     171                osmMercator.XToLon(x, zoom)
     172                );
     173    }
     174
     175    @Override
    119176    public double latToTileY(double lat, int zoom) {
    120177        return osmMercator.LatToY(lat, zoom) / tileSize;
     
    127184
    128185    @Override
     186    public TileXY latLonToTileXY(double lat, double lon, int zoom) {
     187        return new TileXY(
     188                osmMercator.LonToX(lon, zoom) / tileSize,
     189                osmMercator.LatToY(lat, zoom) / tileSize
     190                );
     191    }
     192
     193    @Override
     194    public TileXY latLonToTileXY(ICoordinate point, int zoom) {
     195        return latLonToTileXY(point.getLat(), point.getLon(), zoom);
     196    }
     197
     198    @Override
    129199    public double tileYToLat(int y, int zoom) {
    130200        return osmMercator.YToLat(y * tileSize, zoom);
     
    135205        return osmMercator.XToLon(x * tileSize, zoom);
    136206    }
     207
     208    @Override
     209    public Coordinate tileXYToLatLon(TileXY xy, int zoom) {
     210        return tileXYToLatLon(xy.getXIndex(), xy.getYIndex(), zoom);
     211    }
     212
     213    @Override
     214    public Coordinate tileXYToLatLon(Tile tile) {
     215        return tileXYToLatLon(tile.getXtile(), tile.getYtile(), tile.getZoom());
     216    }
     217
     218    @Override
     219    public Coordinate tileXYToLatLon(int x, int y, int zoom) {
     220        return new Coordinate(
     221                osmMercator.YToLat(y * tileSize, zoom),
     222                osmMercator.XToLon(x * tileSize, zoom)
     223                );
     224    }
     225
     226    @Override
     227    public int getTileXMax(int zoom) {
     228        return getTileMax(zoom);
     229    }
     230
     231    @Override
     232    public int getTileXMin(int zoom) {
     233        return 0;
     234    }
     235
     236    @Override
     237    public int getTileYMax(int zoom) {
     238        return getTileMax(zoom);
     239    }
     240
     241    @Override
     242    public int getTileYMin(int zoom) {
     243        return 0;
     244    }
     245
    137246
    138247    @Override
     
    168277        return ret;
    169278    }
     279
     280    private int getTileMax(int zoom) {
     281        return (int)Math.pow(2.0, zoom) - 1;
     282    }
    170283}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java

    r31122 r31301  
    66import java.util.Map;
    77
    8 import org.openstreetmap.gui.jmapviewer.Coordinate;
     8import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    99import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    1010
     
    2424
    2525    @Override
    26     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     26    public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
    2727        return attributionText;
    2828    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r31122 r31301  
    3030import org.openstreetmap.gui.jmapviewer.Coordinate;
    3131import org.openstreetmap.gui.jmapviewer.JMapViewer;
     32import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    3233import org.w3c.dom.Document;
    3334import org.w3c.dom.Node;
     
    263264
    264265    @Override
    265     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     266    public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
    266267        try {
    267268            final List<Attribution> data = getAttribution();
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/MapQuestOpenAerialTileSource.java

    r30900 r31301  
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
    4 import org.openstreetmap.gui.jmapviewer.Coordinate;
     4import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    55
    66public class MapQuestOpenAerialTileSource extends AbstractMapQuestTileSource {
     
    1313
    1414    @Override
    15     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     15    public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) {
    1616        return "Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency - "+MAPQUEST_ATTRIBUTION;
    1717    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/MapQuestOsmTileSource.java

    r30900 r31301  
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
    4 import org.openstreetmap.gui.jmapviewer.Coordinate;
     4import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    55
    66public class MapQuestOsmTileSource extends AbstractMapQuestTileSource {
     
    1313   
    1414    @Override
    15     public String getAttributionText(int zoom, Coordinate topLeft,
    16             Coordinate botRight) {
     15    public String getAttributionText(int zoom, ICoordinate topLeft,
     16            ICoordinate botRight) {
    1717        return super.getAttributionText(zoom, topLeft, botRight)+" - "+MAPQUEST_ATTRIBUTION;
    1818    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

    r31122 r31301  
    88import java.util.regex.Pattern;
    99
    10 public class TemplatedTMSTileSource extends TMSTileSource {
     10import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
     11
     12/**
     13 * Handles templated TMS Tile Source. Templated means, that some patterns within
     14 * URL gets substituted.
     15 *
     16 * Supported parameters
     17 * {zoom} - substituted with zoom level
     18 * {z} - as above
     19 * {NUMBER-zoom} - substituted with result of equation "NUMBER - zoom",
     20 *                  eg. {20-zoom} for zoom level 15 will result in 5 in this place
     21 * {zoom+number} - substituted with result of equation "zoom + number",
     22 *                 eg. {zoom+5} for zoom level 15 will result in 20.
     23 * {x} - substituted with X tile number
     24 * {y} - substituted with Y tile number
     25 * {!y} - substituted with Yahoo Y tile number
     26 * {-y} - substituted with reversed Y tile number
     27 * {switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually
     28 *                                  used to specify many tile servers
     29 * {header:(HEADER_NAME,HEADER_VALUE)} - sets the headers to be sent to tile server
     30 */
     31
     32public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTileSource {
    1133
    1234    private Random rand = null;
     
    1436    private Map<String, String> headers = new HashMap<>();
    1537
    16     public static final String COOKIE_HEADER   = "Cookie";
    17     public static final String PATTERN_ZOOM    = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}";
    18     public static final String PATTERN_X       = "\\{x\\}";
    19     public static final String PATTERN_Y       = "\\{y\\}";
    20     public static final String PATTERN_Y_YAHOO = "\\{!y\\}";
    21     public static final String PATTERN_NEG_Y   = "\\{-y\\}";
    22     public static final String PATTERN_SWITCH  = "\\{switch:([^}]+)\\}";
    23     public static final String PATTERN_HEADER  = "\\{header\\(([^,]+),([^}]+)\\)\\}";
     38    private static final String COOKIE_HEADER   = "Cookie";
     39    private static final String PATTERN_ZOOM    = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}";
     40    private static final String PATTERN_X       = "\\{x\\}";
     41    private static final String PATTERN_Y       = "\\{y\\}";
     42    private static final String PATTERN_Y_YAHOO = "\\{!y\\}";
     43    private static final String PATTERN_NEG_Y   = "\\{-y\\}";
     44    private static final String PATTERN_SWITCH  = "\\{switch:([^}]+)\\}";
     45    private static final String PATTERN_HEADER  = "\\{header\\(([^,]+),([^}]+)\\)\\}";
    2446
    25     public static final String[] ALL_PATTERNS = {
     47    private static final String[] ALL_PATTERNS = {
    2648        PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y,
    2749        PATTERN_SWITCH
    2850    };
    2951
     52    /**
     53     * Creates Templated TMS Tile Source based on ImageryInfo
     54     * @param info
     55     */
    3056    public TemplatedTMSTileSource(TileSourceInfo info) {
    3157        super(info);
     
    84110        return r;
    85111    }
     112
     113    /**
     114     * Checks if url is acceptable by this Tile Source
     115     * @param url
     116     */
     117    public static void checkUrl(String url) {
     118        assert url != null && !"".equals(url): "URL cannot be null or empty";
     119        Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
     120        while (m.find()) {
     121            boolean isSupportedPattern = false;
     122            for (String pattern : ALL_PATTERNS) {
     123                if (m.group().matches(pattern)) {
     124                    isSupportedPattern = true;
     125                    break;
     126                }
     127            }
     128            if (!isSupportedPattern) {
     129                throw new IllegalArgumentException(
     130                        m.group() + " is not a valid TMS argument. Please check this server URL:\n" + url);
     131            }
     132        }
     133    }
    86134}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java

    r31293 r31301  
    3333
    3434    /** tile size of the displayed tiles */
    35     private int tileSize = OsmMercator.DEFAUL_TILE_SIZE;
     35    private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; // FIXME: set to -1 for next release
    3636
    3737    /** mapping &lt;header key, metadata key&gt; */
     
    116116    /**
    117117     * Request tile size of this tile source
    118      * @return tile size provided by this tile source
     118     * @return tile size provided by this tile source, or -1 when default value should be used
    119119     */
    120120    public int getTileSize() {
     
    127127     */
    128128    public void setTileSize(int tileSize) {
    129         if (tileSize <= 0) {
     129        if (tileSize == 0 || tileSize < -1) {
    130130            throw new AssertionError("Invalid tile size: " + tileSize);
    131131        }
Note: See TracChangeset for help on using the changeset viewer.