1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.apache.commons.jcs.access.CacheAccess;
|
---|
7 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
|
---|
8 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
|
---|
9 | import org.openstreetmap.gui.jmapviewer.tilesources.ScanexTileSource;
|
---|
10 | import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
|
---|
11 | import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
|
---|
12 | import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
|
---|
13 | import org.openstreetmap.josm.data.imagery.CachedAttributionBingAerialTileSource;
|
---|
14 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
15 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
16 | import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
|
---|
17 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
18 | import org.openstreetmap.josm.data.preferences.IntegerProperty;
|
---|
19 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Class that displays a slippy map layer.
|
---|
23 | *
|
---|
24 | * @author Frederik Ramm
|
---|
25 | * @author LuVar <lubomir.varga@freemap.sk>
|
---|
26 | * @author Dave Hansen <dave@sr71.net>
|
---|
27 | * @author Upliner <upliner@gmail.com>
|
---|
28 | *
|
---|
29 | */
|
---|
30 | public class TMSLayer extends AbstractCachedTileSourceLayer {
|
---|
31 | private static final String CACHE_REGION_NAME = "TMS";
|
---|
32 |
|
---|
33 | private static final String PREFERENCE_PREFIX = "imagery.tms";
|
---|
34 |
|
---|
35 | /** minimum zoom level for TMS layer */
|
---|
36 | public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl",
|
---|
37 | AbstractTileSourceLayer.PROP_MIN_ZOOM_LVL.get());
|
---|
38 | /** maximum zoom level for TMS layer */
|
---|
39 | public static final IntegerProperty PROP_MAX_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".max_zoom_lvl",
|
---|
40 | AbstractTileSourceLayer.PROP_MAX_ZOOM_LVL.get());
|
---|
41 | /** shall TMS layers be added to download dialog */
|
---|
42 | public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER = new BooleanProperty(PREFERENCE_PREFIX + ".add_to_slippymap_chooser",
|
---|
43 | true);
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Create a layer based on ImageryInfo
|
---|
47 | * @param info description of the layer
|
---|
48 | */
|
---|
49 | public TMSLayer(ImageryInfo info) {
|
---|
50 | super(info);
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Creates and returns a new TileSource instance depending on the {@link ImageryType}
|
---|
56 | * of the passed ImageryInfo object.
|
---|
57 | *
|
---|
58 | * If no appropriate TileSource is found, null is returned.
|
---|
59 | * Currently supported ImageryType are {@link ImageryType#TMS},
|
---|
60 | * {@link ImageryType#BING}, {@link ImageryType#SCANEX}.
|
---|
61 | *
|
---|
62 | *
|
---|
63 | * @param info imagery info
|
---|
64 | * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
|
---|
65 | * @throws IllegalArgumentException if url from imagery info is null or invalid
|
---|
66 | */
|
---|
67 | @Override
|
---|
68 | protected TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
|
---|
69 | return getTileSourceStatic(info);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Adds a context menu to the mapView.
|
---|
74 | */
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public final boolean isProjectionSupported(Projection proj) {
|
---|
78 | return "EPSG:3857".equals(proj.toCode()) || "EPSG:4326".equals(proj.toCode());
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public final String nameSupportedProjections() {
|
---|
83 | return tr("EPSG:4326 and Mercator projection are supported");
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Creates and returns a new TileSource instance depending on the {@link ImageryType}
|
---|
88 | * of the passed ImageryInfo object.
|
---|
89 | *
|
---|
90 | * If no appropriate TileSource is found, null is returned.
|
---|
91 | * Currently supported ImageryType are {@link ImageryType#TMS},
|
---|
92 | * {@link ImageryType#BING}, {@link ImageryType#SCANEX}.
|
---|
93 | *
|
---|
94 | * @param info imagery info
|
---|
95 | * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
|
---|
96 | * @throws IllegalArgumentException if url from imagery info is null or invalid
|
---|
97 | */
|
---|
98 | public static TileSource getTileSourceStatic(ImageryInfo info) throws IllegalArgumentException {
|
---|
99 | if (info.getImageryType() == ImageryType.TMS) {
|
---|
100 | TemplatedTMSTileSource.checkUrl(info.getUrl());
|
---|
101 | TMSTileSource t = new TemplatedTMSTileSource(info);
|
---|
102 | info.setAttribution(t);
|
---|
103 | return t;
|
---|
104 | } else if (info.getImageryType() == ImageryType.BING)
|
---|
105 | return new CachedAttributionBingAerialTileSource(info);
|
---|
106 | else if (info.getImageryType() == ImageryType.SCANEX) {
|
---|
107 | return new ScanexTileSource(info);
|
---|
108 | }
|
---|
109 | return null;
|
---|
110 | }
|
---|
111 |
|
---|
112 | @Override
|
---|
113 | protected Class<? extends TileLoader> getTileLoaderClass() {
|
---|
114 | return TMSCachedTileLoader.class;
|
---|
115 | }
|
---|
116 |
|
---|
117 | @Override
|
---|
118 | protected String getCacheName() {
|
---|
119 | return CACHE_REGION_NAME;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * @return cache for TMS region
|
---|
124 | */
|
---|
125 | public static CacheAccess<String, BufferedImageCacheEntry> getCache() {
|
---|
126 | return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
|
---|
127 | }
|
---|
128 |
|
---|
129 | }
|
---|