source: josm/trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java@ 8598

Last change on this file since 8598 was 8598, checked in by wiktorn, 9 years ago

TileSource:

  • added method - getTileId that returns unique identifier for the tile, that should not collide with other tile sources
  • added JavaDocs

JCSCacheManager:

  • moved from object count limit to object size limit
  • fixed bug with unnecessary re-creation of auxilary cache, that could result in cache corruption/loss of current cache data

CachedTileLoaderFactory, WMSCachedTileLoader, TMSCachedTileLoader

  • un-abstract CachedTileLoaderFactory, use reflection to create TileLoaders
  • adjust constructors

TMSCachedTileLoader, AbstractCachedTileSourceLayer:

  • move cache related settings to AbstractCachedTileSourceLayer
  • move cache instation to AbstractCachedTileSourceLayer
  • make "flush tile cache" command clear only one tile source

TMSCachedTileLoaderJob:

  • make "flush tile cache" command clear only one tile source
  • reorder methods

TemplatedWMSTileSource:

  • java docs
  • inline of private methods: getTileXMax, getTileYMax
  • fix sonar issues
  • make WMS layer zoom levels closer to TMS (addresses: #11459)

WMTSTileSource:

  • fix Sonar issues
  • use topLeftCorner in X/Y tile max calculations instead of world bounds (fixes issues with WMTS-es, for which topLeftCorner lies outside projection world bounds)

AbstractTileSourceLayer:

  • draw warning, when min-zoom-level is set, and tiles are not loaded due to too many tiles on screen

TMSLayer, WMSLayer, WMTSLayer:

  • expose access to cache object for ImageryPreferences

CacheContentsPanel:

  • add panel for managing cache regions and tile sources within the regions

CommonSettingsPanel, TMSSettingsPanel:

  • move settings common to all imagery layers from TMSSettingsPanel to CommonSettingsPanel
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer;
3
4import java.io.IOException;
5
6import org.apache.commons.jcs.access.CacheAccess;
7import org.openstreetmap.gui.jmapviewer.TileXY;
8import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
9import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
10import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.imagery.ImageryInfo;
15import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
16import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader;
17import org.openstreetmap.josm.data.imagery.WMTSTileSource;
18import org.openstreetmap.josm.data.preferences.BooleanProperty;
19import org.openstreetmap.josm.data.projection.Projection;
20import org.openstreetmap.josm.gui.MapView;
21
22/**
23 * WMTS layer based on AbstractTileSourceLayer. Overrides few methods to align WMTS to Tile based computations
24 * but most magic is done within WMTSTileSource class.
25 *
26 * Full specification of the protocol available at:
27 * http://www.opengeospatial.org/standards/wmts
28 *
29 * @author Wiktor Niesiobędzki
30 *
31 */
32public class WMTSLayer extends AbstractCachedTileSourceLayer {
33 /**
34 * default setting of autozoom per layer
35 */
36 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty("imagery.wmts.default_autozoom", true);
37 private static final String CACHE_REGION_NAME = "WMTS";
38
39
40 /**
41 * Creates WMTS layer from ImageryInfo
42 * @param info Imagery Info describing the layer
43 */
44 public WMTSLayer(ImageryInfo info) {
45 super(info);
46 autoZoom = PROP_DEFAULT_AUTOZOOM.get();
47 }
48
49 @Override
50 protected TileSource getTileSource(ImageryInfo info) {
51 try {
52 if (info.getImageryType() == ImageryType.WMTS && info.getUrl() != null) {
53 WMTSTileSource.checkUrl(info.getUrl());
54 WMTSTileSource tileSource = new WMTSTileSource(info);
55 info.setAttribution(tileSource);
56 return tileSource;
57 }
58 return null;
59 } catch (IOException e) {
60 Main.warn(e);
61 throw new IllegalArgumentException(e);
62 }
63 }
64
65 /**
66 * @param zoom level of the tile
67 * @return how many pixels of the screen occupies one pixel of the tile
68 */
69 private double getTileToScreenRatio(int zoom) {
70 MapView mv = Main.map.mapView;
71 LatLon topLeft = mv.getLatLon(0, 0);
72 LatLon botLeft = mv.getLatLon(0, tileSource.getTileSize());
73
74 TileXY topLeftTile = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom);
75
76 ICoordinate north = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex(), zoom);
77 ICoordinate south = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex() + 1, zoom);
78
79 return Math.abs((north.getLat() - south.getLat()) / (topLeft.lat() - botLeft.lat()));
80 }
81
82 @Override
83 protected int getBestZoom() {
84 if (!Main.isDisplayingMapView()) return 1;
85
86 for (int i = getMinZoomLvl() + 1; i <= getMaxZoomLvl(); i++) {
87 double ret = getTileToScreenRatio(i);
88 if (ret < 1) {
89 return i - 1;
90 }
91 }
92 return getMaxZoomLvl();
93 }
94
95 @Override
96 public boolean isProjectionSupported(Projection proj) {
97 return ((WMTSTileSource) tileSource).getSupportedProjections().contains(proj.toCode());
98 }
99
100 @Override
101 public String nameSupportedProjections() {
102 StringBuilder ret = new StringBuilder();
103 for (String e: ((WMTSTileSource) tileSource).getSupportedProjections()) {
104 ret.append(e).append(", ");
105 }
106 return ret.substring(0, ret.length()-2);
107 }
108
109 @Override
110 public void projectionChanged(Projection oldValue, Projection newValue) {
111 super.projectionChanged(oldValue, newValue);
112 ((WMTSTileSource) tileSource).initProjection(newValue);
113 }
114
115 @Override
116 protected Class<? extends TileLoader> getTileLoaderClass() {
117 return WMSCachedTileLoader.class;
118 }
119
120 @Override
121 protected String getCacheName() {
122 return CACHE_REGION_NAME;
123 }
124
125 /**
126 * @return cache region for WMTS layer
127 */
128 public static CacheAccess<String, BufferedImageCacheEntry> getCache() {
129 return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
130 }
131}
Note: See TracBrowser for help on using the repository browser.