This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository jmapviewer.
commit 346f2a4261a089fcc2ea7cd90d2e804a3d3cf4eb Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Fri Oct 9 10:37:46 2015 +0200 Imported Upstream version 1.09+dfsg --- .../openstreetmap/gui/jmapviewer/JMapViewer.java | 2 +- .../openstreetmap/gui/jmapviewer/OsmMercator.java | 60 ++++++--- .../gui/jmapviewer/OsmTileLoader.java | 14 +- src/org/openstreetmap/gui/jmapviewer/Tile.java | 50 ++++++- .../gui/jmapviewer/interfaces/TileJob.java | 6 + .../gui/jmapviewer/interfaces/TileSource.java | 25 +++- src/org/openstreetmap/gui/jmapviewer/package.html | 2 +- .../tilesources/AbstractOsmTileSource.java | 6 +- .../tilesources/AbstractTMSTileSource.java | 77 ++++++++--- .../jmapviewer/tilesources/AbstractTileSource.java | 8 +- .../tilesources/BingAerialTileSource.java | 9 +- .../jmapviewer/tilesources/ScanexTileSource.java | 10 +- .../gui/jmapviewer/tilesources/TMSTileSource.java | 14 +- .../tilesources/TemplatedTMSTileSource.java | 22 +--- .../gui/jmapviewer/tilesources/TileSourceInfo.java | 143 +++++++++++++++++++++ 15 files changed, 369 insertions(+), 79 deletions(-) diff --git a/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java b/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java index b1aa19f..e70ca00 100644 --- a/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java +++ b/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java @@ -584,7 +584,7 @@ public class JMapViewer extends JPanel implements TileLoaderListener { tile = tileController.getTile(tilex, tiley, zoom); } if (tile != null) { - tile.paint(g, posx, posy); + tile.paint(g, posx, posy, tilesize, tilesize); if (tileGridVisible) { g.drawRect(posx, posy, tilesize, tilesize); } diff --git a/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java b/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java index f0a7bcd..0556783 100644 --- a/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java +++ b/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java @@ -10,31 +10,59 @@ package org.openstreetmap.gui.jmapviewer; */ public class OsmMercator { - public static int TILE_SIZE = 256; + /** + * default tile size + */ + public static int DEFAUL_TILE_SIZE = 256; + /** maximum latitude (north) for mercator display */ public static final double MAX_LAT = 85.05112877980659; + /** minimum latitude (south) for mercator display */ public static final double MIN_LAT = -85.05112877980659; - private static double EARTH_RADIUS = 6378137; // equatorial earth radius for EPSG:3857 (Mercator) + /** equatorial earth radius for EPSG:3857 (Mercator) */ + private static double EARTH_RADIUS = 6378137; + + /** + * instance with tile size of 256 for easy conversions + */ + public static final OsmMercator MERCATOR_256 = new OsmMercator(); + + /** tile size of the displayed tiles */ + private int tileSize = DEFAUL_TILE_SIZE; + + /** + * Creates instance with default tile size of 256 + */ + public OsmMercator() { + } + + /** + * Creates instance with provided tile size. + * @param tileSize + */ + public OsmMercator(int tileSize) { + this.tileSize = tileSize; + } - public static double radius(int aZoomlevel) { - return (TILE_SIZE * (1 << aZoomlevel)) / (2.0 * Math.PI); + public double radius(int aZoomlevel) { + return (tileSize * (1 << aZoomlevel)) / (2.0 * Math.PI); } /** * Returns the absolut number of pixels in y or x, defined as: 2^Zoomlevel * - * TILE_WIDTH where TILE_WIDTH is the width of a tile in pixels + * tileSize where tileSize is the width of a tile in pixels * * @param aZoomlevel zoom level to request pixel data * @return number of pixels */ - public static int getMaxPixels(int aZoomlevel) { - return TILE_SIZE * (1 << aZoomlevel); + public int getMaxPixels(int aZoomlevel) { + return tileSize * (1 << aZoomlevel); } - public static int falseEasting(int aZoomlevel) { + public int falseEasting(int aZoomlevel) { return getMaxPixels(aZoomlevel) / 2; } - public static int falseNorthing(int aZoomlevel) { + public int falseNorthing(int aZoomlevel) { return (-1 * getMaxPixels(aZoomlevel) / 2); } @@ -50,7 +78,7 @@ public class OsmMercator { * @return the distance * @author Jason Huntley */ - public static double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) { + public double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) { double la1 = YToLat(y1, zoomLevel); double lo1 = XToLon(x1, zoomLevel); double la2 = YToLat(y2, zoomLevel); @@ -69,7 +97,7 @@ public class OsmMercator { * @return the distance * @author Jason Huntley */ - public static double getDistance(double la1, double lo1, double la2, double lo2) { + public double getDistance(double la1, double lo1, double la2, double lo2) { double aStartLat = Math.toRadians(la1); double aStartLong = Math.toRadians(lo1); double aEndLat =Math.toRadians(la2); @@ -100,10 +128,10 @@ public class OsmMercator { * @return [0..2^Zoomlevel*TILE_SIZE[ * @author Jan Peter Stotz */ - public static double LonToX(double aLongitude, int aZoomlevel) { + public double LonToX(double aLongitude, int aZoomlevel) { int mp = getMaxPixels(aZoomlevel); double x = (mp * (aLongitude + 180l)) / 360l; - return Math.min(x, mp - 1); + return Math.min(x, mp); } /** @@ -124,7 +152,7 @@ public class OsmMercator { * @return [0..2^Zoomlevel*TILE_SIZE[ * @author Jan Peter Stotz */ - public static double LatToY(double aLat, int aZoomlevel) { + public double LatToY(double aLat, int aZoomlevel) { if (aLat < MIN_LAT) aLat = MIN_LAT; else if (aLat > MAX_LAT) @@ -154,7 +182,7 @@ public class OsmMercator { * @return ]-180..180[ * @author Jan Peter Stotz */ - public static double XToLon(int aX, int aZoomlevel) { + public double XToLon(int aX, int aZoomlevel) { return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0; } @@ -165,7 +193,7 @@ public class OsmMercator { * [0..2^Zoomlevel*TILE_WIDTH[ * @return [MIN_LAT..MAX_LAT] is about [-85..85] */ - public static double YToLat(int aY, int aZoomlevel) { + public double YToLat(int aY, int aZoomlevel) { aY += falseNorthing(aZoomlevel); double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); return -1 * Math.toDegrees(latitude); diff --git a/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java b/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java index bf93c6e..d138714 100644 --- a/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java +++ b/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java @@ -40,6 +40,7 @@ public class OsmTileLoader implements TileLoader { return new TileJob() { InputStream input = null; + boolean force = false; public void run() { synchronized (tile) { @@ -51,6 +52,9 @@ public class OsmTileLoader implements TileLoader { } try { URLConnection conn = loadTileFromOsm(tile); + if (force) { + conn.setUseCaches(false); + } loadTileMetadata(tile, conn); if ("no-tile".equals(tile.getValue("tile-info"))) { tile.setError("No tile at this zoom level"); @@ -88,9 +92,16 @@ public class OsmTileLoader implements TileLoader { @Override public void submit() { - run(); + submit(false); } + + @Override + public void submit(boolean force) { + this.force = force; + run(); + } + }; } @@ -101,7 +112,6 @@ public class OsmTileLoader implements TileLoader { if (urlConn instanceof HttpURLConnection) { prepareHttpUrlConnection((HttpURLConnection)urlConn); } - urlConn.setReadTimeout(30000); // 30 seconds read timeout return urlConn; } diff --git a/src/org/openstreetmap/gui/jmapviewer/Tile.java b/src/org/openstreetmap/gui/jmapviewer/Tile.java index 895b962..8cd511d 100644 --- a/src/org/openstreetmap/gui/jmapviewer/Tile.java +++ b/src/org/openstreetmap/gui/jmapviewer/Tile.java @@ -48,9 +48,9 @@ public class Tile { protected int zoom; protected BufferedImage image; protected String key; - protected boolean loaded = false; - protected boolean loading = false; - protected boolean error = false; + protected volatile boolean loaded = false; // field accessed by multiple threads without any monitors, needs to be volatile + protected volatile boolean loading = false; + protected volatile boolean error = false; protected String error_message; /** TileLoader-specific tile metadata */ @@ -219,6 +219,23 @@ public class Tile { g.drawImage(image, x, y, null); } + /** + * Paints the tile-image on the {@link Graphics} <code>g</code> at the + * position <code>x</code>/<code>y</code>. + * + * @param g the Graphics object + * @param x x-coordinate in <code>g</code> + * @param y y-coordinate in <code>g</code> + * @param width width that tile should have + * @param height height that tile should have + */ + public void paint(Graphics g, int x, int y, int width, int height) { + if (image == null) + return; + g.drawImage(image, x, y, width, height, null); + } + + @Override public String toString() { return "Tile " + key; @@ -312,23 +329,50 @@ public class Tile { metadata.put(key, value); } + /** + * returns the metadata of the Tile + * + * @param key metadata key that should be returned + * @return null if no such metadata exists, or the value of the metadata + */ public String getValue(String key) { if (metadata == null) return null; return metadata.get(key); } + /** + * + * @return metadata of the tile + */ public Map<String,String> getMetadata() { + if (metadata == null) { + metadata = new HashMap<>(); + } return metadata; } + /** + * indicate that loading process for this tile has started + */ public void initLoading() { loaded = false; error = false; loading = true; } + /** + * indicate that loading process for this tile has ended + */ public void finishLoading() { loading = false; loaded = true; } + + /** + * + * @return TileSource from which this tile comes + */ + public TileSource getTileSource() { + return source; + } } diff --git a/src/org/openstreetmap/gui/jmapviewer/interfaces/TileJob.java b/src/org/openstreetmap/gui/jmapviewer/interfaces/TileJob.java index 3e91f3b..f546b48 100644 --- a/src/org/openstreetmap/gui/jmapviewer/interfaces/TileJob.java +++ b/src/org/openstreetmap/gui/jmapviewer/interfaces/TileJob.java @@ -22,4 +22,10 @@ public interface TileJob extends Runnable { * submits download job to backend. */ void submit(); + + /** + * submits download job to backend. + * @param force true if the load should skip all the caches (local & remote) + */ + void submit(boolean force); } diff --git a/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java b/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java index ab003a6..ec509c0 100644 --- a/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java @@ -2,6 +2,8 @@ package org.openstreetmap.gui.jmapviewer.interfaces; import java.io.IOException; +import java.util.List; +import java.util.Map; import org.openstreetmap.gui.jmapviewer.JMapViewer; @@ -70,10 +72,10 @@ public interface TileSource extends Attributed { /** * A unique id for this tile source. - * + * * Unlike the name it has to be unique and has to consist only of characters * valid for filenames. - * + * * @return the id */ String getId(); @@ -155,4 +157,23 @@ public interface TileSource extends Attributed { * @return [MIN_LAT..MAX_LAT] */ double tileYToLat(int y, int zoom); + + /** + * Determines, if the returned data from TileSource represent "no tile at this zoom level" situation. Detection + * algorithms differ per TileSource, so each TileSource should implement each own specific way. + * + * @param headers HTTP headers from response from TileSource server + * @param statusCode HTTP status code + * @param content byte array representing the data returned from the server + * @return true, if "no tile at this zoom level" situation detected + */ + public boolean isNoTileAtZoom(Map<String, List<String>> headers, int statusCode, byte[] content); + + /** + * Extracts metadata about the tile based on HTTP headers + * + * @param headers HTTP headers from Tile Source server + * @return tile metadata + */ + public Map<String, String> getMetadata(Map<String, List<String>> headers); } diff --git a/src/org/openstreetmap/gui/jmapviewer/package.html b/src/org/openstreetmap/gui/jmapviewer/package.html index 6be7e8e..d9b0584 100644 --- a/src/org/openstreetmap/gui/jmapviewer/package.html +++ b/src/org/openstreetmap/gui/jmapviewer/package.html @@ -7,6 +7,6 @@ component <a href="http://wiki.openstreetmap.org/wiki/JMapViewer">JMapViewer</a> <p>JMapViewer is designed to run as stand-alone component without any further requirements. Therefore <b>please do not add any code that depends on other libraries or applications</b>. Only functions and methods -provided by the runtime library of Java 5 should be used.</p> +provided by the runtime library of Java 7 should be used.</p> </body> </html> \ No newline at end of file diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java index ff8f58a..0fc6c41 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java @@ -6,7 +6,7 @@ import java.awt.Image; import org.openstreetmap.gui.jmapviewer.Coordinate; /** - * Abstract clas for OSM Tile sources + * Abstract class for OSM Tile sources */ public abstract class AbstractOsmTileSource extends AbstractTMSTileSource { @@ -23,9 +23,11 @@ public abstract class AbstractOsmTileSource extends AbstractTMSTileSource { * are safe for file names; can be null */ public AbstractOsmTileSource(String name, String base_url, String id) { - super(name, base_url, id); + super(new TileSourceInfo(name, base_url, id)); + } + @Override public int getMaxZoom() { return 19; } diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java index 2ec140b..50a6a7c 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java @@ -2,6 +2,10 @@ package org.openstreetmap.gui.jmapviewer.tilesources; import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import org.openstreetmap.gui.jmapviewer.OsmMercator; @@ -10,14 +14,22 @@ public abstract class AbstractTMSTileSource extends AbstractTileSource { protected String name; protected String baseUrl; protected String id; - - public AbstractTMSTileSource(String name, String base_url, String id) { - this.name = name; - this.baseUrl = base_url; - if(baseUrl.endsWith("/")) { + private Map<String, String> noTileHeaders; + private Map<String, String> metadataHeaders; + protected int tileSize; + protected OsmMercator osmMercator; + + public AbstractTMSTileSource(TileSourceInfo info) { + this.name = info.getName(); + this.baseUrl = info.getUrl(); + if(baseUrl != null && baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0,baseUrl.length()-1); } - this.id = id; + this.id = info.getUrl(); + this.noTileHeaders = info.getNoTileHeaders(); + this.metadataHeaders = info.getMetadataHeaders(); + this.tileSize = info.getTileSize(); + osmMercator = new OsmMercator(this.tileSize); } @Override @@ -75,51 +87,84 @@ public abstract class AbstractTMSTileSource extends AbstractTileSource { */ @Override public int getTileSize() { - return OsmMercator.TILE_SIZE; + return tileSize; } @Override public double getDistance(double lat1, double lon1, double lat2, double lon2) { - return OsmMercator.getDistance(lat1, lon1, lat2, lon2); + return osmMercator.getDistance(lat1, lon1, lat2, lon2); } @Override public int LonToX(double lon, int zoom) { - return (int )OsmMercator.LonToX(lon, zoom); + return (int )osmMercator.LonToX(lon, zoom); } @Override public int LatToY(double lat, int zoom) { - return (int )OsmMercator.LatToY(lat, zoom); + return (int )osmMercator.LatToY(lat, zoom); } @Override public double XToLon(int x, int zoom) { - return OsmMercator.XToLon(x, zoom); + return osmMercator.XToLon(x, zoom); } @Override public double YToLat(int y, int zoom) { - return OsmMercator.YToLat(y, zoom); + return osmMercator.YToLat(y, zoom); } @Override public double latToTileY(double lat, int zoom) { - return OsmMercator.LatToY(lat, zoom) / OsmMercator.TILE_SIZE; + return osmMercator.LatToY(lat, zoom) / tileSize; } @Override public double lonToTileX(double lon, int zoom) { - return OsmMercator.LonToX(lon, zoom) / OsmMercator.TILE_SIZE; + return osmMercator.LonToX(lon, zoom) / tileSize; } @Override public double tileYToLat(int y, int zoom) { - return OsmMercator.YToLat(y * OsmMercator.TILE_SIZE, zoom); + return osmMercator.YToLat(y * tileSize, zoom); } @Override public double tileXToLon(int x, int zoom) { - return OsmMercator.XToLon(x * OsmMercator.TILE_SIZE, zoom); + return osmMercator.XToLon(x * tileSize, zoom); + } + + @Override + public boolean isNoTileAtZoom(Map<String, List<String>> headers, int statusCode, byte[] content) { + if (noTileHeaders != null && headers != null) { + for (Entry<String, String> searchEntry: noTileHeaders.entrySet()) { + List<String> headerVals = headers.get(searchEntry.getKey()); + if (headerVals != null) { + for (String headerValue: headerVals) { + if (headerValue.matches(searchEntry.getValue())) { + return true; + } + } + } + } + } + return super.isNoTileAtZoom(headers, statusCode, content); + } + + @Override + public Map<String, String> getMetadata(Map<String, List<String>> headers) { + Map<String, String> ret = new HashMap<>(); + if (metadataHeaders != null && headers != null) { + for (Entry<String, String> searchEntry: metadataHeaders.entrySet()) { + List<String> headerVals = headers.get(searchEntry.getKey()); + if (headerVals != null) { + for (String headerValue: headerVals) { + ret.put(searchEntry.getValue(), headerValue); + } + } + } + } + return ret; } } diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java index 9505330..b41e558 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java @@ -2,9 +2,11 @@ package org.openstreetmap.gui.jmapviewer.tilesources; import java.awt.Image; +import java.util.List; +import java.util.Map; -import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; import org.openstreetmap.gui.jmapviewer.Coordinate; +import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; abstract public class AbstractTileSource implements TileSource { @@ -74,4 +76,8 @@ abstract public class AbstractTileSource implements TileSource { this.termsOfUseURL = termsOfUseURL; } + public boolean isNoTileAtZoom(Map<String, List<String>> headers, int statusCode, byte[] content) { + // default handler - when HTTP 404 is returned, then treat this situation as no tile at this zoom level + return statusCode == 404; + } } diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java index e71d093..c5e8169 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java @@ -52,14 +52,11 @@ public class BingAerialTileSource extends AbstractTMSTileSource { * Constructs a new {@code BingAerialTileSource}. */ public BingAerialTileSource() { - this("Bing"); + super(new TileSourceInfo("Bing", null, null)); } - /** - * Constructs a new {@code BingAerialTileSource}. - */ - public BingAerialTileSource(String id) { - super("Bing Aerial Maps", "http://example.com/", id); + public BingAerialTileSource(TileSourceInfo info) { + super(info); } protected class Attribution { diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java index b12b98e..9d0d502 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java @@ -45,8 +45,9 @@ public class ScanexTileSource extends TMSTileSource { /* IRS by default */ private ScanexLayer Layer = ScanexLayer.IRS; - public ScanexTileSource(String name, String url, String id, int maxZoom) { - super(name, url, id, maxZoom); + public ScanexTileSource(TileSourceInfo info) { + super(info); + String url = info.getUrl(); for (ScanexLayer layer : ScanexLayer.values()) { if (url.equalsIgnoreCase(layer.getName())) { @@ -77,6 +78,7 @@ public class ScanexTileSource extends TMSTileSource { return this.Layer.getUri() + "&apikey=" + API_KEY + "&x=" + tilex + "&y=" + tiley + "&z=" + zoom; } + @Override public TileUpdate getTileUpdate() { return TileUpdate.IfNoneMatch; } @@ -91,12 +93,12 @@ public class ScanexTileSource extends TMSTileSource { @Override public int LatToY(double lat, int zoom) { - return (int )(latToTileY(lat, zoom) * OsmMercator.TILE_SIZE); + return (int )(latToTileY(lat, zoom) * tileSize); } @Override public double YToLat(int y, int zoom) { - return tileYToLat((double )y / OsmMercator.TILE_SIZE, zoom); + return tileYToLat((double )y / tileSize, zoom); } @Override diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java index 7f47c6a..66673de 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java @@ -1,20 +1,16 @@ // License: GPL. For details, see Readme.txt file. package org.openstreetmap.gui.jmapviewer.tilesources; + public class TMSTileSource extends AbstractTMSTileSource { protected int maxZoom; protected int minZoom = 0; - public TMSTileSource(String name, String url, String id, int maxZoom) { - super(name, url, id); - this.maxZoom = maxZoom; - } - - public TMSTileSource(String name, String url, String id, int minZoom, int maxZoom) { - super(name, url, id); - this.minZoom = minZoom; - this.maxZoom = maxZoom; + public TMSTileSource(TileSourceInfo info) { + super(info); + minZoom = info.getMinZoom(); + maxZoom = info.getMaxZoom(); } @Override diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java index 98417fb..cf163bf 100644 --- a/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java @@ -1,11 +1,11 @@ // License: GPL. For details, see Readme.txt file. package org.openstreetmap.gui.jmapviewer.tilesources; -import java.util.Map; import java.util.HashMap; +import java.util.Map; import java.util.Random; -import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.regex.Pattern; public class TemplatedTMSTileSource extends TMSTileSource { @@ -27,20 +27,10 @@ public class TemplatedTMSTileSource extends TMSTileSource { PATTERN_SWITCH }; - public TemplatedTMSTileSource(String name, String url, String id, int maxZoom) { - super(name, url, id, maxZoom); - handleTemplate(); - } - - public TemplatedTMSTileSource(String name, String url, String id, int minZoom, int maxZoom) { - super(name, url, id, minZoom, maxZoom); - handleTemplate(); - } - - public TemplatedTMSTileSource(String name, String url, String id, int minZoom, int maxZoom, String cookies) { - super(name, url, id, minZoom, maxZoom); - if (cookies != null) { - headers.put(COOKIE_HEADER, cookies); + public TemplatedTMSTileSource(TileSourceInfo info) { + super(info); + if (info.getCookies() != null) { + headers.put(COOKIE_HEADER, info.getCookies()); } handleTemplate(); } diff --git a/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java b/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java new file mode 100644 index 0000000..49591ec --- /dev/null +++ b/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java @@ -0,0 +1,143 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.gui.jmapviewer.tilesources; + +import java.util.Map; + +import org.openstreetmap.gui.jmapviewer.OsmMercator; + +/** + * Data class that keeps basic information about a tile source. + * + * @since 31122 + */ +public class TileSourceInfo { + /** id for this imagery entry, optional at the moment */ + protected String id; + /** URL of the imagery service */ + protected String url = null; + + /** name of the imagery layer */ + protected String name; + + /** headers meaning, that there is no tile at this zoom level */ + protected Map<String, String> noTileHeaders; + + /** minimum zoom level supported by the tile source */ + protected int minZoom; + + /** maximum zoom level supported by the tile source */ + protected int maxZoom; + + /** cookies that needs to be sent to tile source */ + protected String cookies; + + /** tile size of the displayed tiles */ + private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; + + /** mapping <header key, metadata key> */ + protected Map<String, String> metadataHeaders; + + /** + * Create a TileSourceInfo class + * + * @param name + * @param base_url + * @param id + */ + public TileSourceInfo(String name, String base_url, String id) { + this(name); + this.url = base_url; + this.id = id; + } + + /** + * Create a TileSourceInfo class + * + * @param name + */ + public TileSourceInfo(String name) { + this.name = name; + } + + /** + * Creates empty TileSourceInfo class + */ + public TileSourceInfo() { + } + + /** + * Request name of the tile source + * @return name of the tile source + */ + public String getName() { + return name; + } + + /** + * Request URL of the tile source + * @return url of the tile source + */ + public String getUrl() { + return url; + } + + /** + * Request header information for empty tiles for servers delivering such tile types + * @return map of headers, that when set, means that this is "no tile at this zoom level" situation + */ + public Map<String, String> getNoTileHeaders() { + return noTileHeaders; + } + + /** + * Request supported minimum zoom level + * @return minimum zoom level supported by tile source + */ + public int getMinZoom() { + return minZoom; + } + + /** + * Request supported maximum zoom level + * @return maximum zoom level supported by tile source + */ + public int getMaxZoom() { + return maxZoom; + } + + /** + * Request cookies to be sent together with request + * @return cookies to be sent along with request to tile source + */ + public String getCookies() { + return cookies; + } + + /** + * Request tile size of this tile source + * @return tile size provided by this tile source + */ + public int getTileSize() { + return tileSize; + } + + /** + * Sets the tile size provided by this tile source + * @param tileSize + */ + public void setTileSize(int tileSize) { + if (tileSize <= 0) { + throw new AssertionError("Invalid tile size: " + tileSize); + } + this.tileSize = tileSize; + } + + /** + * + * @return mapping <HTTP header name, Metadata key name> for copying HTTP headers to Tile metadata + * @since 31125 + */ + public Map<String, String> getMetadataHeaders() { + return metadataHeaders; + } +} -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/jmapviewer.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel