001// License: GPL. For details, see Readme.txt file. 002package org.openstreetmap.gui.jmapviewer.tilesources; 003 004import java.io.IOException; 005 006import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 007 008/** 009 * OSM Tile source. 010 */ 011public class OsmTileSource { 012 013 /** 014 * The default "Mapnik" OSM tile source. 015 */ 016 public static class Mapnik extends AbstractOsmTileSource { 017 018 private static final String PATTERN = "https://%s.tile.openstreetmap.org"; 019 020 private static final String[] SERVER = {"a", "b", "c"}; 021 022 private int serverNum; 023 024 /** 025 * Constructs a new {@code "Mapnik"} tile source. 026 */ 027 public Mapnik() { 028 super("OpenStreetMap Carto", PATTERN, "standard"); 029 modTileFeatures = true; 030 } 031 032 @Override 033 public String getBaseUrl() { 034 String url = String.format(this.baseUrl, new Object[] {SERVER[serverNum]}); 035 serverNum = (serverNum + 1) % SERVER.length; 036 return url; 037 } 038 } 039 040 /** 041 * The "Cycle Map" OSM tile source. 042 */ 043 public abstract static class CycleMap extends AbstractOsmTileSource { 044 045 private static final String PATTERN = "https://%s.tile.thunderforest.com/cycle"; 046 047 private static final String[] SERVER = {"a", "b", "c"}; 048 049 private int serverNum; 050 051 /** 052 * Constructs a new {@code CycleMap} tile source. 053 */ 054 public CycleMap() { 055 super("OpenCycleMap", PATTERN, "opencyclemap"); 056 } 057 058 @Override 059 public String getBaseUrl() { 060 String url = String.format(this.baseUrl, new Object[] {SERVER[serverNum]}); 061 serverNum = (serverNum + 1) % SERVER.length; 062 return url; 063 } 064 065 /** 066 * Get the thunderforest API key. 067 * 068 * Needs to be registered at their web site. 069 * @return the API key 070 */ 071 protected abstract String getApiKey(); 072 073 @Override 074 public int getMaxZoom() { 075 return 18; 076 } 077 078 @Override 079 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException { 080 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley) + "?apikey=" + getApiKey(); 081 } 082 083 @Override 084 public String getTermsOfUseText() { 085 return "Maps © Thunderforest"; 086 } 087 088 @Override 089 public String getTermsOfUseURL() { 090 return "https://thunderforest.com/terms/"; 091 } 092 } 093 094 /** 095 * The "Transport Map" OSM tile source. 096 */ 097 public static class TransportMap extends AbstractOsmTileSource { 098 099 /** 100 * Constructs a new {@code TransportMap} tile source. 101 */ 102 public TransportMap() { 103 super("Public Transport", "https://tile.memomaps.de/tilegen", "public_transport_oepnv"); 104 } 105 106 @Override 107 public int getMaxZoom() { 108 return 18; 109 } 110 111 @Override 112 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 113 return "© OpenStreetMap contributors, CC-BY-SA"; 114 } 115 116 @Override 117 public String getAttributionLinkURL() { 118 return "https://öpnvkarte.de/<"; 119 } 120 } 121}