source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.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: 9.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.File;
8import java.io.IOException;
9import java.net.MalformedURLException;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.Bounds;
17import org.openstreetmap.josm.data.coor.LatLon;
18import org.openstreetmap.josm.data.projection.Projections;
19
20public class WMTSTileSourceTest {
21
22 private ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
23 private ImageryInfo testImageryPSEUDO_MERCATOR = getImagery("test/data/wmts/getcapabilities-pseudo-mercator.xml");
24 private ImageryInfo testImageryTOPO_PL = getImagery("test/data/wmts/getcapabilities-TOPO.xml");
25 private ImageryInfo testImageryORTO_PL = getImagery("test/data/wmts/getcapabilities-ORTO.xml");
26 private ImageryInfo testImageryWIEN = getImagery("test/data/wmts/getCapabilities-wien.xml");
27 private ImageryInfo testImageryWALLONIE = getImagery("test/data/wmts/WMTSCapabilities-Wallonie.xml");
28
29 @BeforeClass
30 public static void setUp() {
31 JOSMFixture.createUnitTestFixture().init();
32 }
33
34 private static ImageryInfo getImagery(String path) {
35 try {
36 return new ImageryInfo(
37 "test",
38 new File(path).toURI().toURL().toString()
39 );
40 } catch (MalformedURLException e) {
41 e.printStackTrace();
42 return null;
43 }
44 }
45
46 @Test
47 public void testPseudoMercator() throws MalformedURLException, IOException {
48 Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
49 WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR);
50
51 verifyMercatorTile(testSource, 0, 0, 1);
52 verifyMercatorTile(testSource, 0, 0, 2);
53 verifyMercatorTile(testSource, 1, 1, 2);
54 for (int x = 0; x < 4; x++) {
55 for (int y = 0; y < 4; y++) {
56 verifyMercatorTile(testSource, x, y, 3);
57 }
58 }
59 for (int x = 0; x < 8; x++) {
60 for (int y = 0; y < 4; y++) {
61 verifyMercatorTile(testSource, x, y, 4);
62 }
63 }
64
65 verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 10);
66
67 assertEquals("TileXMax", 1, testSource.getTileXMax(1));
68 assertEquals("TileYMax", 1, testSource.getTileYMax(1));
69 assertEquals("TileXMax", 2, testSource.getTileXMax(2));
70 assertEquals("TileYMax", 2, testSource.getTileYMax(2));
71 assertEquals("TileXMax", 4, testSource.getTileXMax(3));
72 assertEquals("TileYMax", 4, testSource.getTileYMax(3));
73
74 }
75
76 @Test
77 public void testWALLONIE() throws MalformedURLException, IOException {
78 Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
79 WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
80 assertEquals("http://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FOND_PLAN_ANNOTATIONS_2012_RW_NB/"
81 + "MapServer/WMTS/tile/1.0.0/DONNEES_BASE_FOND_PLAN_ANNOTATIONS_2012_RW_NB/default/default028mm/5/1219/1063.png",
82 testSource.getTileUrl(6, 1063, 1219));
83
84 // +bounds=2.54,49.51,6.4,51.5
85 Bounds wallonieBounds = new Bounds(
86 new LatLon(49.485372459967245, 2.840548314430268),
87 new LatLon(50.820959517561256, 6.427849693016202)
88 );
89 verifyBounds(wallonieBounds, testSource, 6, 1063, 1219);
90 verifyBounds(wallonieBounds, testSource, 11, 17724, 20324);
91 }
92
93 @Test
94 public void testWALLONIENoMatrixDimension() throws MalformedURLException, IOException {
95 Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
96 WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml"));
97 Bounds wallonieBounds = new Bounds(
98 new LatLon(49.485372459967245, 2.840548314430268),
99 new LatLon(50.820959517561256, 6.427849693016202)
100 );
101
102 verifyBounds(wallonieBounds, testSource, 6, 1063, 1219);
103 verifyBounds(wallonieBounds, testSource, 11, 17724, 20324);
104 }
105
106 private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) {
107 LatLon ret = new LatLon(testSource.tileXYToLatLon(x, y, z));
108 assertTrue(ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));
109 int tileXmax = testSource.getTileXMax(z);
110 int tileYmax = testSource.getTileYMax(z);
111 assertTrue("tile x: " + x + " is greater than allowed max: " + tileXmax, tileXmax >= x);
112 assertTrue("tile y: " + y + " is greater than allowed max: " + tileYmax, tileYmax >= y);
113 }
114
115 @Test
116 public void testWIEN() throws MalformedURLException, IOException {
117 Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
118 WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
119 int zoomOffset = 9;
120
121 verifyMercatorTile(testSource, 0, 0, 1, zoomOffset);
122 verifyMercatorTile(testSource, 1105, 709, 2, zoomOffset);
123 verifyMercatorTile(testSource, 1, 1, 1, zoomOffset);
124 verifyMercatorTile(testSource, 2, 2, 1, zoomOffset);
125 verifyMercatorTile(testSource, 0, 0, 2, zoomOffset);
126 verifyMercatorTile(testSource, 1, 1, 2, zoomOffset);
127
128 for (int x = 0; x < 4; x++) {
129 for (int y = 0; y < 4; y++) {
130 verifyMercatorTile(testSource, x, y, 3, zoomOffset);
131 }
132 }
133 for (int x = 0; x < 8; x++) {
134 for (int y = 0; y < 4; y++) {
135 verifyMercatorTile(testSource, x, y, 4, zoomOffset);
136 }
137 }
138
139 verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 2, zoomOffset);
140
141 verifyMercatorMax(testSource, 1, zoomOffset);
142 verifyMercatorMax(testSource, 2, zoomOffset);
143 verifyMercatorMax(testSource, 3, zoomOffset);
144 }
145
146 private void verifyMercatorMax(WMTSTileSource testSource, int zoom, int zoomOffset) {
147 TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
148 int result = testSource.getTileXMax(zoom);
149 int expected = verifier.getTileXMax(zoom + zoomOffset);
150 assertTrue("TileXMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
151 result = testSource.getTileYMax(zoom);
152 expected = verifier.getTileYMax(zoom + zoomOffset);
153 assertTrue("TileYMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
154 }
155
156 @Test
157 public void testGeoportalTOPOPL() throws IOException {
158 Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
159 WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL);
160 verifyTile(new LatLon(56, 12), testSource, 0, 0, 1);
161 verifyTile(new LatLon(56, 12), testSource, 0, 0, 2);
162 verifyTile(new LatLon(51.1268639, 16.8731360), testSource, 1, 1, 2);
163
164 assertEquals("TileXMax", 2, testSource.getTileXMax(1));
165 assertEquals("TileYMax", 1, testSource.getTileYMax(1));
166 assertEquals("TileXMax", 3, testSource.getTileXMax(2));
167 assertEquals("TileYMax", 2, testSource.getTileYMax(2));
168 assertEquals("TileXMax", 6, testSource.getTileXMax(3));
169 assertEquals("TileYMax", 4, testSource.getTileYMax(3));
170 assertEquals(
171 "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&"
172 + "VERSION=1.0.0&LAYER=MAPA TOPOGRAFICZNA&STYLE=default&FORMAT=image/jpeg&tileMatrixSet=EPSG:4326&"
173 + "tileMatrix=EPSG:4326:0&tileRow=1&tileCol=1",
174 testSource.getTileUrl(1, 1, 1));
175 }
176
177 @Test
178 public void testGeoportalORTOPL4326() throws IOException {
179 Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
180 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
181 verifyTile(new LatLon(53.5993712684958, 19.560669777688176), testSource, 12412, 3941, 14);
182 verifyTile(new LatLon(49.783096954497786, 22.79034127751704), testSource, 17714, 10206, 14);
183 }
184
185 @Test
186 public void testGeoportalORTOPL2180() throws IOException {
187 Main.setProjection(Projections.getProjectionByCode("EPSG:2180"));
188 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
189
190 verifyTile(new LatLon(53.59940948387726, 19.560544913270064), testSource, 6453, 3140, 14);
191 verifyTile(new LatLon(49.782984840526055, 22.790064966993445), testSource, 9932, 9305, 14);
192 }
193
194 private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) {
195 LatLon ll = new LatLon(source.tileXYToLatLon(x, y, z));
196 assertEquals("Latitude", expected.lat(), ll.lat(), 1e-05);
197 assertEquals("Longitude", expected.lon(), ll.lon(), 1e-05);
198
199 }
200
201 private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z) {
202 verifyMercatorTile(testSource, x, y, z, -1);
203 }
204
205 private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z, int zoomOffset) {
206 TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
207 LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z));
208 LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z + zoomOffset));
209 //System.out.println(z + "/" + x + "/" + y + " - result: " + result.toDisplayString() + " osmMercator: " + expected.toDisplayString());
210 assertEquals("Longitude" , expected.lon(), result.lon(), 1e-04);
211 assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
212 }
213}
Note: See TracBrowser for help on using the repository browser.