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

Last change on this file since 12620 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer;
3
4import java.io.IOException;
5import java.util.Collection;
6
7import org.apache.commons.jcs.access.CacheAccess;
8import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
11import org.openstreetmap.josm.data.imagery.ImageryInfo;
12import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
13import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader;
14import org.openstreetmap.josm.data.imagery.WMTSTileSource;
15import org.openstreetmap.josm.data.projection.Projection;
16import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
17import org.openstreetmap.josm.tools.Logging;
18import org.openstreetmap.josm.tools.Utils;
19
20/**
21 * WMTS layer based on AbstractTileSourceLayer. Overrides few methods to align WMTS to Tile based computations
22 * but most magic is done within WMTSTileSource class.
23 *
24 * Full specification of the protocol available at:
25 * http://www.opengeospatial.org/standards/wmts
26 *
27 * @author Wiktor Niesiobędzki
28 *
29 */
30public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> implements NativeScaleLayer {
31 private static final String PREFERENCE_PREFIX = "imagery.wmts";
32
33 /**
34 * Registers all setting properties
35 */
36 static {
37 new TileSourceDisplaySettings(PREFERENCE_PREFIX);
38 }
39
40 private static final String CACHE_REGION_NAME = "WMTS";
41
42 /**
43 * Creates WMTS layer from ImageryInfo
44 * @param info Imagery Info describing the layer
45 */
46 public WMTSLayer(ImageryInfo info) {
47 super(info);
48 }
49
50 @Override
51 protected TileSourceDisplaySettings createDisplaySettings() {
52 return new TileSourceDisplaySettings(PREFERENCE_PREFIX);
53 }
54
55 @Override
56 protected WMTSTileSource getTileSource() {
57 try {
58 if (info.getImageryType() == ImageryType.WMTS && info.getUrl() != null) {
59 WMTSTileSource.checkUrl(info.getUrl());
60 WMTSTileSource tileSource = new WMTSTileSource(info);
61 info.setAttribution(tileSource);
62 return tileSource;
63 }
64 return null;
65 } catch (IOException e) {
66 Logging.warn(e);
67 throw new IllegalArgumentException(e);
68 }
69 }
70
71 @Override
72 public int getBestZoom() {
73 if (!Main.isDisplayingMapView())
74 return 0;
75 ScaleList scaleList = getNativeScales();
76 if (scaleList == null) {
77 return getMaxZoomLvl();
78 }
79 double displayScale = Main.map.mapView.getScale();
80 if (coordinateConverter.requiresReprojection()) {
81 displayScale *= Main.getProjection().getMetersPerUnit();
82 }
83 Scale snap = scaleList.getSnapScale(displayScale, false);
84 return Utils.clamp(snap != null ? snap.getIndex() : getMaxZoomLvl(),
85 getMinZoomLvl(), getMaxZoomLvl());
86 }
87
88 @Override
89 protected int getMinZoomLvl() {
90 return 0;
91 }
92
93 @Override
94 public Collection<String> getNativeProjections() {
95 return tileSource.getSupportedProjections();
96 }
97
98 @Override
99 public void projectionChanged(Projection oldValue, Projection newValue) {
100 super.projectionChanged(oldValue, newValue);
101 tileSource.initProjection(newValue);
102 }
103
104 @Override
105 protected Class<? extends TileLoader> getTileLoaderClass() {
106 return WMSCachedTileLoader.class;
107 }
108
109 @Override
110 protected String getCacheName() {
111 return CACHE_REGION_NAME;
112 }
113
114 /**
115 * @return cache region for WMTS layer
116 */
117 public static CacheAccess<String, BufferedImageCacheEntry> getCache() {
118 return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
119 }
120
121 @Override
122 public ScaleList getNativeScales() {
123 return tileSource.getNativeScales();
124 }
125}
Note: See TracBrowser for help on using the repository browser.