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