Changeset 31301 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2015-06-24T20:57:27+02:00 (9 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java
r30426 r31301 16 16 17 17 import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; 18 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 18 19 19 20 public class AttributionSupport { … … 53 54 } 54 55 55 public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft,Coordinate bottomRight, int zoom, ImageObserver observer) {56 public void paintAttribution(Graphics g, int width, int height, ICoordinate topLeft, ICoordinate bottomRight, int zoom, ImageObserver observer) { 56 57 if (source == null || !source.requiresAttribution()) { 57 58 attrToUBounds = null; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r31293 r31301 191 191 * {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM} 192 192 */ 193 public void setDisplayPosition( Coordinate to, int zoom) {193 public void setDisplayPosition(ICoordinate to, int zoom) { 194 194 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), to, zoom); 195 195 } … … 209 209 * {@link TileSource#getMaxZoom()} 210 210 */ 211 public void setDisplayPosition(Point mapPoint, Coordinate to, int zoom) { 212 int x = tileSource.LonToX(to.getLon(), zoom); 213 int y = tileSource.LatToY(to.getLat(), zoom); 214 setDisplayPosition(mapPoint, x, y, zoom); 211 public void setDisplayPosition(Point mapPoint, ICoordinate to, int zoom) { 212 Point p = tileSource.latLonToXY(to, zoom); 213 setDisplayPosition(mapPoint, p.x, p.y, zoom); 215 214 } 216 215 … … 268 267 for (MapMarker marker : mapMarkerList) { 269 268 if (marker.isVisible()) { 270 int x = tileSource.LonToX(marker.getLon(), mapZoomMax); 271 int y = tileSource.LatToY(marker.getLat(), mapZoomMax); 272 x_max = Math.max(x_max, x); 273 y_max = Math.max(y_max, y); 274 x_min = Math.min(x_min, x); 275 y_min = Math.min(y_min, y); 269 Point p = tileSource.latLonToXY(marker.getCoordinate(), mapZoomMax); 270 x_max = Math.max(x_max, p.x); 271 y_max = Math.max(y_max, p.y); 272 x_min = Math.min(x_min, p.x); 273 y_min = Math.min(y_min, p.y); 276 274 } 277 275 } … … 283 281 for (MapRectangle rectangle : mapRectangleList) { 284 282 if (rectangle.isVisible()) { 285 x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 286 y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 287 x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 288 y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 283 Point bottomRight = tileSource.latLonToXY(rectangle.getBottomRight(), mapZoomMax); 284 Point topLeft = tileSource.latLonToXY(rectangle.getTopLeft(), mapZoomMax); 285 x_max = Math.max(x_max, bottomRight.x); 286 y_max = Math.max(y_max, topLeft.y); 287 x_min = Math.min(x_min, topLeft.x); 288 y_min = Math.min(y_min, bottomRight.y); 289 289 } 290 290 } … … 297 297 if (polygon.isVisible()) { 298 298 for (ICoordinate c : polygon.getPoints()) { 299 int x = tileSource.LonToX(c.getLon(), mapZoomMax); 300 int y = tileSource.LatToY(c.getLat(), mapZoomMax); 301 x_max = Math.max(x_max, x); 302 y_max = Math.max(y_max, y); 303 x_min = Math.min(x_min, x); 304 y_min = Math.min(y_min, y); 299 Point p = tileSource.latLonToXY(c, mapZoomMax); 300 x_max = Math.max(x_max, p.x); 301 y_max = Math.max(y_max, p.y); 302 x_min = Math.min(x_min, p.x); 303 y_min = Math.min(y_min, p.y); 305 304 } 306 305 } … … 368 367 * @return latitude / longitude 369 368 */ 370 public Coordinate getPosition() { 371 double lon = tileSource.XToLon(center.x, zoom); 372 double lat = tileSource.YToLat(center.y, zoom); 373 return new Coordinate(lat, lon); 369 public ICoordinate getPosition() { 370 return tileSource.XYToLatLon(center, zoom); 374 371 } 375 372 … … 383 380 * @return latitude / longitude 384 381 */ 385 public Coordinate getPosition(Point mapPoint) {382 public ICoordinate getPosition(Point mapPoint) { 386 383 return getPosition(mapPoint.x, mapPoint.y); 387 384 } … … 395 392 * @return latitude / longitude 396 393 */ 397 public Coordinate getPosition(int mapPointX, int mapPointY) {394 public ICoordinate getPosition(int mapPointX, int mapPointY) { 398 395 int x = center.x + mapPointX - getWidth() / 2; 399 396 int y = center.y + mapPointY - getHeight() / 2; 400 double lon = tileSource.XToLon(x, zoom); 401 double lat = tileSource.YToLat(y, zoom); 402 return new Coordinate(lat, lon); 397 return tileSource.XYToLatLon(x, y, zoom); 403 398 } 404 399 … … 413 408 */ 414 409 public Point getMapPosition(double lat, double lon, boolean checkOutside) { 415 int x = tileSource.LonToX(lon, zoom); 416 int y = tileSource.LatToY(lat, zoom); 417 x -= center.x - getWidth() / 2; 418 y -= center.y - getHeight() / 2; 410 Point p = tileSource.latLonToXY(lat, lon, zoom); 411 p.translate(-(center.x - getWidth() / 2), -(center.y - getHeight() /2)); 412 419 413 if (checkOutside) { 420 if ( x < 0 || y < 0 || x > getWidth() ||y > getHeight())414 if (p.x < 0 || p.y < 0 || p.x > getWidth() || p.y > getHeight()) 421 415 return null; 422 416 } 423 return new Point(x, y); 417 return p; 418 } 419 420 /** 421 * Calculates the position on the map of a given coordinate 422 * 423 * @param lat Latitude 424 * @param lon longitude 425 * @param offset Offset respect Latitude 426 * @param checkOutside 427 * @return Integer the radius in pixels 428 */ 429 public Integer getLatOffset(double lat, double lon, double offset, boolean checkOutside) { 430 Point p = tileSource.latLonToXY(lat, lon, zoom); 431 int y = p.y - center.y - getHeight() / 2; 432 if (checkOutside) { 433 if (y < 0 || y > getHeight()) 434 return null; 435 } 436 return y; 424 437 } 425 438 … … 432 445 * @return Integer the radius in pixels 433 446 */ 447 @Deprecated 434 448 public Integer getLatOffset(double lat, double offset, boolean checkOutside) { 435 449 int y = tileSource.LatToY(lat + offset, zoom); … … 463 477 return (int) marker.getRadius(); 464 478 else if (p != null) { 465 Integer radius = getLatOffset(marker.getLat(), marker.get Radius(), false);479 Integer radius = getLatOffset(marker.getLat(), marker.getLon(), marker.getRadius(), false); 466 480 radius = radius == null ? null : p.y - radius.intValue(); 467 481 return radius; … … 509 523 double pDistance = center.distance(origin); 510 524 511 Coordinate originCoord = getPosition(origin);512 Coordinate centerCoord = getPosition(center);525 ICoordinate originCoord = getPosition(origin); 526 ICoordinate centerCoord = getPosition(center); 513 527 514 528 double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(), … … 826 840 || zoom == this.zoom) 827 841 return; 828 Coordinate zoomPos = getPosition(mapPoint);842 ICoordinate zoomPos = getPosition(mapPoint); 829 843 tileController.cancelOutstandingJobs(); // Clearing outstanding load 830 844 // requests … … 971 985 if (tileSource.getMinZoom() < MIN_ZOOM) 972 986 throw new RuntimeException("Minimum zoom level too low"); 973 Coordinate position = getPosition();987 ICoordinate position = getPosition(); 974 988 this.tileSource = tileSource; 975 989 tileController.setTileSource(tileSource); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/Attributed.java
r30223 r31301 3 3 4 4 import java.awt.Image; 5 6 import org.openstreetmap.gui.jmapviewer.Coordinate;7 5 8 6 public interface Attributed { … … 18 16 * @return Attribution text for the image source. 19 17 */ 20 String getAttributionText(int zoom, Coordinate topLeft,Coordinate botRight);18 String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight); 21 19 22 20 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r31293 r31301 2 2 package org.openstreetmap.gui.jmapviewer.interfaces; 3 3 4 import java.awt.Point; 4 5 import java.io.IOException; 5 6 import java.util.List; … … 7 8 8 9 import org.openstreetmap.gui.jmapviewer.JMapViewer; 10 import org.openstreetmap.gui.jmapviewer.Tile; 11 import org.openstreetmap.gui.jmapviewer.TileXY; 9 12 10 13 /** … … 36 39 * 37 40 */ 41 @Deprecated //not used anymore 38 42 public enum TileUpdate { 39 43 IfNoneMatch, ETag, IfModifiedSince, LastModified, None … … 93 97 94 98 /** 95 * Specifies the tile image type. For tiles rendered by Mapnik or96 * Osmarenderer this is usually <code>"png"</code>.97 *98 * @return file extension of the tile image type99 */100 String getTileType();101 102 /**103 99 * Specifies how large each tile is. 104 * @return The size of a single tile in pixels. 100 * @return The size of a single tile in pixels. -1 if default size should be used 105 101 */ 106 102 int getTileSize(); 107 103 108 104 /** 105 * @return default tile size, for this tile source 106 * TODO: @since 107 */ 108 public int getDefaultTileSize(); 109 110 /** 109 111 * Gets the distance using Spherical law of cosines. 110 * @return the distance, m. 112 * @param la1 latitude of first point 113 * @param lo1 longitude of first point 114 * @param la2 latitude of second point 115 * @param lo2 longitude of second point 116 * @return the distance betwen first and second point, in m. 111 117 */ 112 118 double getDistance(double la1, double lo1, double la2, double lo2); … … 114 120 /** 115 121 * Transform longitude to pixelspace. 122 * @param aLongitude 123 * @param aZoomlevel 116 124 * @return [0..2^Zoomlevel*TILE_SIZE[ 117 125 */ 126 @Deprecated 118 127 int LonToX(double aLongitude, int aZoomlevel); 119 128 120 129 /** 121 130 * Transforms latitude to pixelspace. 131 * @param aLat 132 * @param aZoomlevel 122 133 * @return [0..2^Zoomlevel*TILE_SIZE[ 123 */ 134 * @deprecated use lonLatToXY instead 135 */ 136 @Deprecated 124 137 int LatToY(double aLat, int aZoomlevel); 125 138 126 139 /** 140 * @param lon 141 * @param lat 142 * @param zoom 143 * @return transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined) 144 */ 145 public Point latLonToXY(double lat, double lon, int zoom); 146 147 public Point latLonToXY(ICoordinate point, int zoom); 148 149 /** 127 150 * Transforms pixel coordinate X to longitude 151 * @param aX 152 * @param aZoomlevel 128 153 * @return ]-180..180[ 129 154 */ 155 @Deprecated 130 156 double XToLon(int aX, int aZoomlevel); 131 157 132 158 /** 133 159 * Transforms pixel coordinate Y to latitude. 160 * @param aY 161 * @param aZoomlevel 134 162 * @return [MIN_LAT..MAX_LAT] 135 163 */ 164 @Deprecated 136 165 double YToLat(int aY, int aZoomlevel); 137 166 138 167 /** 168 * @param point 169 * @param zoom 170 * @return WGS84 Coordinates of given point 171 */ 172 public ICoordinate XYToLatLon(Point point, int zoom); 173 174 public ICoordinate XYToLatLon(int x, int y, int zoom); 175 176 /** 139 177 * Transforms longitude to X tile coordinate. 178 * @param lon 179 * @param zoom 140 180 * @return [0..2^Zoomlevel[ 141 181 */ 182 @Deprecated 142 183 double lonToTileX(double lon, int zoom); 143 184 144 185 /** 145 186 * Transforms latitude to Y tile coordinate. 187 * @param lat 188 * @param zoom 146 189 * @return [0..2^Zoomlevel[ 147 190 */ 191 @Deprecated 148 192 double latToTileY(double lat, int zoom); 149 193 150 194 /** 195 * @param lon 196 * @param lat 197 * @param zoom 198 * @return x and y tile indices 199 */ 200 public TileXY latLonToTileXY(double lat, double lon, int zoom); 201 202 public TileXY latLonToTileXY(ICoordinate point, int zoom); 203 204 /** 151 205 * Transforms tile X coordinate to longitude. 206 * @param x 207 * @param zoom 152 208 * @return ]-180..180[ 153 209 */ 210 @Deprecated 154 211 double tileXToLon(int x, int zoom); 155 212 156 213 /** 157 214 * Transforms tile Y coordinate to latitude. 215 * @param y 216 * @param zoom 158 217 * @return [MIN_LAT..MAX_LAT] 159 218 */ 219 @Deprecated 160 220 double tileYToLat(int y, int zoom); 221 222 /** 223 * @param xy 224 * @param zoom 225 * @return WGS84 coordinates of given tile 226 */ 227 public ICoordinate tileXYToLatLon(TileXY xy, int zoom); 228 229 public ICoordinate tileXYToLatLon(Tile tile); 230 231 public ICoordinate tileXYToLatLon(int x, int y, int zoom); 232 233 /** 234 * @param zoom 235 * @return maximum X index of tile for specified zoom level 236 */ 237 public int getTileXMax(int zoom); 238 239 /** 240 * 241 * @param zoom 242 * @return minimum X index of tile for specified zoom level 243 */ 244 public int getTileXMin(int zoom); 245 246 /** 247 * 248 * @param zoom 249 * @return maximum Y index of tile for specified zoom level 250 */ 251 public int getTileYMax(int zoom); 252 253 /** 254 * @param zoom 255 * @return minimum Y index of tile for specified zoom level 256 */ 257 public int getTileYMin(int zoom); 161 258 162 259 /** … … 178 275 */ 179 276 public Map<String, String> getMetadata(Map<String, List<String>> headers); 277 278 180 279 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java
r31122 r31301 4 4 import java.awt.Image; 5 5 6 import org.openstreetmap.gui.jmapviewer. Coordinate;6 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 7 7 8 8 /** … … 39 39 40 40 @Override 41 public String getAttributionText(int zoom, Coordinate topLeft,Coordinate botRight) {41 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 42 42 return DEFAULT_OSM_ATTRIBUTION; 43 43 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java
r31142 r31301 2 2 package org.openstreetmap.gui.jmapviewer.tilesources; 3 3 4 import java.awt.Point; 4 5 import java.io.IOException; 5 6 import java.util.HashMap; … … 8 9 import java.util.Map.Entry; 9 10 11 import org.openstreetmap.gui.jmapviewer.Coordinate; 10 12 import org.openstreetmap.gui.jmapviewer.OsmMercator; 11 13 import org.openstreetmap.gui.jmapviewer.Tile; 14 import org.openstreetmap.gui.jmapviewer.TileXY; 15 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 16 17 /** 18 * Class generalizing all tile based tile sources 19 * 20 * @author Wiktor Niesiobędzki 21 * 22 */ 12 23 public abstract class AbstractTMSTileSource extends AbstractTileSource { 13 24 … … 20 31 protected OsmMercator osmMercator; 21 32 33 /** 34 * Creates an instance based on TileSource information 35 * 36 * @param info description of the Tile Source 37 */ 22 38 public AbstractTMSTileSource(TileSourceInfo info) { 23 39 this.name = info.getName(); … … 33 49 } 34 50 51 /** 52 * @return default tile size to use, when not set in Imagery Preferences 53 */ 54 public int getDefaultTileSize() { 55 return OsmMercator.DEFAUL_TILE_SIZE; 56 } 57 35 58 @Override 36 59 public String getName() { … … 53 76 } 54 77 78 /** 79 * @return image extension, used for URL creation 80 */ 55 81 public String getExtension() { 56 82 return "png"; … … 58 84 59 85 /** 86 * @param zoom level of the tile 87 * @param tilex tile number in x axis 88 * @param tiley tile number in y axis 89 * @return String containg path part of URL of the tile 60 90 * @throws IOException when subclass cannot return the tile URL 61 91 */ … … 64 94 } 65 95 96 /** 97 * @return Base part of the URL of the tile source 98 */ 66 99 public String getBaseUrl() { 67 100 return this.baseUrl; … … 78 111 } 79 112 80 @Override81 public String getTileType() {82 return "png";83 }84 85 113 /* 86 114 * Most tilesources use OsmMercator projection. … … 88 116 @Override 89 117 public int getTileSize() { 118 if (tileSize <= 0) { 119 return getDefaultTileSize(); 120 } 90 121 return tileSize; 91 122 } … … 107 138 108 139 @Override 140 public Point latLonToXY(double lat, double lon, int zoom) { 141 return new Point( 142 (int)osmMercator.LonToX(lon, zoom), 143 (int)osmMercator.LatToY(lat, zoom) 144 ); 145 } 146 147 @Override 148 public Point latLonToXY(ICoordinate point, int zoom) { 149 return latLonToXY(point.getLat(), point.getLon(), zoom); 150 } 151 152 @Override 109 153 public double XToLon(int x, int zoom) { 110 154 return osmMercator.XToLon(x, zoom); … … 117 161 118 162 @Override 163 public Coordinate XYToLatLon(Point point, int zoom) { 164 return XYToLatLon(point.x, point.y, zoom); 165 } 166 167 @Override 168 public Coordinate XYToLatLon(int x, int y, int zoom) { 169 return new Coordinate( 170 osmMercator.YToLat(y, zoom), 171 osmMercator.XToLon(x, zoom) 172 ); 173 } 174 175 @Override 119 176 public double latToTileY(double lat, int zoom) { 120 177 return osmMercator.LatToY(lat, zoom) / tileSize; … … 127 184 128 185 @Override 186 public TileXY latLonToTileXY(double lat, double lon, int zoom) { 187 return new TileXY( 188 osmMercator.LonToX(lon, zoom) / tileSize, 189 osmMercator.LatToY(lat, zoom) / tileSize 190 ); 191 } 192 193 @Override 194 public TileXY latLonToTileXY(ICoordinate point, int zoom) { 195 return latLonToTileXY(point.getLat(), point.getLon(), zoom); 196 } 197 198 @Override 129 199 public double tileYToLat(int y, int zoom) { 130 200 return osmMercator.YToLat(y * tileSize, zoom); … … 135 205 return osmMercator.XToLon(x * tileSize, zoom); 136 206 } 207 208 @Override 209 public Coordinate tileXYToLatLon(TileXY xy, int zoom) { 210 return tileXYToLatLon(xy.getXIndex(), xy.getYIndex(), zoom); 211 } 212 213 @Override 214 public Coordinate tileXYToLatLon(Tile tile) { 215 return tileXYToLatLon(tile.getXtile(), tile.getYtile(), tile.getZoom()); 216 } 217 218 @Override 219 public Coordinate tileXYToLatLon(int x, int y, int zoom) { 220 return new Coordinate( 221 osmMercator.YToLat(y * tileSize, zoom), 222 osmMercator.XToLon(x * tileSize, zoom) 223 ); 224 } 225 226 @Override 227 public int getTileXMax(int zoom) { 228 return getTileMax(zoom); 229 } 230 231 @Override 232 public int getTileXMin(int zoom) { 233 return 0; 234 } 235 236 @Override 237 public int getTileYMax(int zoom) { 238 return getTileMax(zoom); 239 } 240 241 @Override 242 public int getTileYMin(int zoom) { 243 return 0; 244 } 245 137 246 138 247 @Override … … 168 277 return ret; 169 278 } 279 280 private int getTileMax(int zoom) { 281 return (int)Math.pow(2.0, zoom) - 1; 282 } 170 283 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTileSource.java
r31122 r31301 6 6 import java.util.Map; 7 7 8 import org.openstreetmap.gui.jmapviewer. Coordinate;8 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 9 9 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 10 10 … … 24 24 25 25 @Override 26 public String getAttributionText(int zoom, Coordinate topLeft,Coordinate botRight) {26 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 27 27 return attributionText; 28 28 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
r31122 r31301 30 30 import org.openstreetmap.gui.jmapviewer.Coordinate; 31 31 import org.openstreetmap.gui.jmapviewer.JMapViewer; 32 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 32 33 import org.w3c.dom.Document; 33 34 import org.w3c.dom.Node; … … 263 264 264 265 @Override 265 public String getAttributionText(int zoom, Coordinate topLeft,Coordinate botRight) {266 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 266 267 try { 267 268 final List<Attribution> data = getAttribution(); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/MapQuestOpenAerialTileSource.java
r30900 r31301 2 2 package org.openstreetmap.gui.jmapviewer.tilesources; 3 3 4 import org.openstreetmap.gui.jmapviewer. Coordinate;4 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 5 5 6 6 public class MapQuestOpenAerialTileSource extends AbstractMapQuestTileSource { … … 13 13 14 14 @Override 15 public String getAttributionText(int zoom, Coordinate topLeft,Coordinate botRight) {15 public String getAttributionText(int zoom, ICoordinate topLeft, ICoordinate botRight) { 16 16 return "Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency - "+MAPQUEST_ATTRIBUTION; 17 17 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/MapQuestOsmTileSource.java
r30900 r31301 2 2 package org.openstreetmap.gui.jmapviewer.tilesources; 3 3 4 import org.openstreetmap.gui.jmapviewer. Coordinate;4 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 5 5 6 6 public class MapQuestOsmTileSource extends AbstractMapQuestTileSource { … … 13 13 14 14 @Override 15 public String getAttributionText(int zoom, Coordinate topLeft,16 Coordinate botRight) {15 public String getAttributionText(int zoom, ICoordinate topLeft, 16 ICoordinate botRight) { 17 17 return super.getAttributionText(zoom, topLeft, botRight)+" - "+MAPQUEST_ATTRIBUTION; 18 18 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
r31122 r31301 8 8 import java.util.regex.Pattern; 9 9 10 public class TemplatedTMSTileSource extends TMSTileSource { 10 import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource; 11 12 /** 13 * Handles templated TMS Tile Source. Templated means, that some patterns within 14 * URL gets substituted. 15 * 16 * Supported parameters 17 * {zoom} - substituted with zoom level 18 * {z} - as above 19 * {NUMBER-zoom} - substituted with result of equation "NUMBER - zoom", 20 * eg. {20-zoom} for zoom level 15 will result in 5 in this place 21 * {zoom+number} - substituted with result of equation "zoom + number", 22 * eg. {zoom+5} for zoom level 15 will result in 20. 23 * {x} - substituted with X tile number 24 * {y} - substituted with Y tile number 25 * {!y} - substituted with Yahoo Y tile number 26 * {-y} - substituted with reversed Y tile number 27 * {switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually 28 * used to specify many tile servers 29 * {header:(HEADER_NAME,HEADER_VALUE)} - sets the headers to be sent to tile server 30 */ 31 32 public class TemplatedTMSTileSource extends TMSTileSource implements TemplatedTileSource { 11 33 12 34 private Random rand = null; … … 14 36 private Map<String, String> headers = new HashMap<>(); 15 37 16 p ublicstatic final String COOKIE_HEADER = "Cookie";17 p ublicstatic final String PATTERN_ZOOM = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}";18 p ublicstatic final String PATTERN_X = "\\{x\\}";19 p ublicstatic final String PATTERN_Y = "\\{y\\}";20 p ublicstatic final String PATTERN_Y_YAHOO = "\\{!y\\}";21 p ublicstatic final String PATTERN_NEG_Y = "\\{-y\\}";22 p ublicstatic final String PATTERN_SWITCH = "\\{switch:([^}]+)\\}";23 p ublicstatic final String PATTERN_HEADER = "\\{header\\(([^,]+),([^}]+)\\)\\}";38 private static final String COOKIE_HEADER = "Cookie"; 39 private static final String PATTERN_ZOOM = "\\{(?:(\\d+)-)?z(?:oom)?([+-]\\d+)?\\}"; 40 private static final String PATTERN_X = "\\{x\\}"; 41 private static final String PATTERN_Y = "\\{y\\}"; 42 private static final String PATTERN_Y_YAHOO = "\\{!y\\}"; 43 private static final String PATTERN_NEG_Y = "\\{-y\\}"; 44 private static final String PATTERN_SWITCH = "\\{switch:([^}]+)\\}"; 45 private static final String PATTERN_HEADER = "\\{header\\(([^,]+),([^}]+)\\)\\}"; 24 46 25 p ublicstatic final String[] ALL_PATTERNS = {47 private static final String[] ALL_PATTERNS = { 26 48 PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, 27 49 PATTERN_SWITCH 28 50 }; 29 51 52 /** 53 * Creates Templated TMS Tile Source based on ImageryInfo 54 * @param info 55 */ 30 56 public TemplatedTMSTileSource(TileSourceInfo info) { 31 57 super(info); … … 84 110 return r; 85 111 } 112 113 /** 114 * Checks if url is acceptable by this Tile Source 115 * @param url 116 */ 117 public static void checkUrl(String url) { 118 assert url != null && !"".equals(url): "URL cannot be null or empty"; 119 Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url); 120 while (m.find()) { 121 boolean isSupportedPattern = false; 122 for (String pattern : ALL_PATTERNS) { 123 if (m.group().matches(pattern)) { 124 isSupportedPattern = true; 125 break; 126 } 127 } 128 if (!isSupportedPattern) { 129 throw new IllegalArgumentException( 130 m.group() + " is not a valid TMS argument. Please check this server URL:\n" + url); 131 } 132 } 133 } 86 134 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java
r31293 r31301 33 33 34 34 /** tile size of the displayed tiles */ 35 private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; 35 private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; // FIXME: set to -1 for next release 36 36 37 37 /** mapping <header key, metadata key> */ … … 116 116 /** 117 117 * Request tile size of this tile source 118 * @return tile size provided by this tile source 118 * @return tile size provided by this tile source, or -1 when default value should be used 119 119 */ 120 120 public int getTileSize() { … … 127 127 */ 128 128 public void setTileSize(int tileSize) { 129 if (tileSize <= 0) {129 if (tileSize == 0 || tileSize < -1) { 130 130 throw new AssertionError("Invalid tile size: " + tileSize); 131 131 }
Note:
See TracChangeset
for help on using the changeset viewer.