From: Frédéric Perrin Date: Sun, 30 Dec 2018 14:23:02 +0000 (+0000) Subject: Allow to use maps with custom format X-Git-Tag: v19.2.fp1^2~1 X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=commitdiff_plain;h=ab86483ebe9379c497e3b7005251d69c5caae2f2 Allow to use maps with custom format --- diff --git a/src/tim/prune/gui/map/MapSource.java b/src/tim/prune/gui/map/MapSource.java index c4e2946..177ad67 100644 --- a/src/tim/prune/gui/map/MapSource.java +++ b/src/tim/prune/gui/map/MapSource.java @@ -104,7 +104,7 @@ public abstract class MapSource urlstr = "http://" + urlstr; } // check trailing / - if (!urlstr.endsWith("/")) { + if (!urlstr.endsWith("/") && !urlstr.contains("?")) { urlstr = urlstr + "/"; } // Validate current url, return null if not ok diff --git a/src/tim/prune/gui/map/OsmMapSource.java b/src/tim/prune/gui/map/OsmMapSource.java index 925fcf6..e3fe589 100644 --- a/src/tim/prune/gui/map/OsmMapSource.java +++ b/src/tim/prune/gui/map/OsmMapSource.java @@ -152,12 +152,31 @@ public class OsmMapSource extends MapSource /** * Make the URL to get the specified tile + * @param inLayerNum layer number + * @param inZoom zoom level + * @param inX x coordinate + * @param inY y coordinate + * @return relative file path as String */ public String makeURL(int inLayerNum, int inZoom, int inX, int inY) { // Check if the base url has a [1234], if so replace at random - StringBuffer url = new StringBuffer(); - url.append(pickServerUrl(_baseUrls[inLayerNum])); + String baseUrl = pickServerUrl(_baseUrls[inLayerNum]); + return makeUrl(baseUrl, inLayerNum, inZoom, inX, inY); + } + + public String makeUrl(String baseUrl, int inLayerNum, int inZoom, int inX, int inY) + { + // If the base URL has {x}/{y} placeholders, use them + if (baseUrl.contains("{x}")) { + baseUrl = baseUrl.replace("{z}", Integer.toString(inZoom)) + .replace("{x}", Integer.toString(inX)) + .replace("{y}", Integer.toString(inY)); + return baseUrl; + } + + // Else simply append the tile indices and file extension + StringBuffer url = new StringBuffer(baseUrl); url.append(inZoom).append('/').append(inX).append('/').append(inY); url.append('.').append(getFileExtension(inLayerNum)); if (_apiKey != null) @@ -167,6 +186,26 @@ public class OsmMapSource extends MapSource return url.toString(); } + /** + * Make a relative file path from the base directory including site name + * @param inLayerNum layer number + * @param inZoom zoom level + * @param inX x coordinate + * @param inY y coordinate + * @return relative file path as String + */ + public String makeFilePath(int inLayerNum, int inZoom, int inX, int inY) + { + String siteName = getSiteName(inLayerNum); + String filePath = makeUrl(siteName, inLayerNum, inZoom, inX, inY); + int indexParam = filePath.indexOf("?"); + if (indexParam > 0) + { + filePath = filePath.substring(0, indexParam); + } + return filePath; + } + /** * @return maximum zoom level */