001// License: GPL. For details, see Readme.txt file. 002package org.openstreetmap.gui.jmapviewer.tilesources; 003 004import java.util.Map; 005 006import org.openstreetmap.gui.jmapviewer.OsmMercator; 007 008/** 009 * Data class that keeps basic information about a tile source. 010 * 011 * @since 31122 012 */ 013public class TileSourceInfo { 014 /** id for this imagery entry, optional at the moment */ 015 protected String id; 016 017 /** URL of the imagery service */ 018 protected String url; 019 020 /** name of the imagery layer */ 021 protected String name; 022 023 /** headers meaning, that there is no tile at this zoom level */ 024 protected Map<String, String> noTileHeaders; 025 026 /** minimum zoom level supported by the tile source */ 027 protected int minZoom; 028 029 /** maximum zoom level supported by the tile source */ 030 protected int maxZoom; 031 032 /** cookies that needs to be sent to tile source */ 033 protected String cookies = ""; 034 035 /** tile size of the displayed tiles */ 036 private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; // FIXME: set to -1 for next release 037 038 /** mapping <header key, metadata key> */ 039 protected Map<String, String> metadataHeaders; 040 041 /** 042 * Create a TileSourceInfo class 043 * 044 * @param name name 045 * @param baseUrl base URL 046 * @param id unique id 047 */ 048 public TileSourceInfo(String name, String baseUrl, String id) { 049 this.name = name; 050 this.url = baseUrl; 051 this.id = id; 052 } 053 054 /** 055 * Create a TileSourceInfo class 056 * 057 * @param name name 058 */ 059 public TileSourceInfo(String name) { 060 this(name, null, null); 061 } 062 063 /** 064 * Creates empty TileSourceInfo class 065 */ 066 public TileSourceInfo() { 067 this(null, null, null); 068 } 069 070 /** 071 * Request name of the tile source 072 * @return name of the tile source 073 */ 074 public final String getName() { 075 return name; 076 } 077 078 /** 079 * Request URL of the tile source 080 * @return url of the tile source 081 */ 082 public final String getUrl() { 083 return url; 084 } 085 086 /** 087 * Request ID of the tile source. Id can be null. This gets the configured id as is. 088 * Due to a user error, this may not be unique. 089 * @return id of the tile source 090 */ 091 public final String getId() { 092 return id; 093 } 094 095 /** 096 * Request header information for empty tiles for servers delivering such tile types 097 * @return map of headers, that when set, means that this is "no tile at this zoom level" situation 098 */ 099 public Map<String, String> getNoTileHeaders() { 100 return noTileHeaders; 101 } 102 103 /** 104 * Request supported minimum zoom level 105 * @return minimum zoom level supported by tile source 106 */ 107 public int getMinZoom() { 108 return minZoom; 109 } 110 111 /** 112 * Request supported maximum zoom level 113 * @return maximum zoom level supported by tile source 114 */ 115 public int getMaxZoom() { 116 return maxZoom; 117 } 118 119 /** 120 * Request cookies to be sent together with request 121 * @return cookies to be sent along with request to tile source 122 */ 123 public String getCookies() { 124 return cookies; 125 } 126 127 /** 128 * Request tile size of this tile source 129 * @return tile size provided by this tile source, or -1 when default value should be used 130 */ 131 public int getTileSize() { 132 return tileSize; 133 } 134 135 /** 136 * Request metadata headers 137 * @return mapping <HTTP header name, Metadata key name> for copying HTTP headers to Tile metadata 138 * @since 31125 139 */ 140 public Map<String, String> getMetadataHeaders() { 141 return metadataHeaders; 142 } 143 144 /** 145 * Sets the tile size provided by this tile source 146 * @param tileSize tile size in pixels 147 */ 148 public final void setTileSize(int tileSize) { 149 if (tileSize == 0 || tileSize < -1) { 150 throw new AssertionError("Invalid tile size: " + tileSize); 151 } 152 this.tileSize = tileSize; 153 } 154 155 /** 156 * Sets the tile URL. 157 * @param url tile URL 158 */ 159 public final void setUrl(String url) { 160 this.url = url; 161 } 162 163 /** 164 * Sets the tile name. 165 * @param name tile name 166 */ 167 public final void setName(String name) { 168 this.name = name; 169 } 170 171 /** 172 * Sets the tile id. 173 * @param id tile id 174 */ 175 public final void setId(String id) { 176 this.id = id; 177 } 178}