1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.net.MalformedURLException;
|
---|
10 | import java.nio.file.Files;
|
---|
11 | import java.nio.file.Paths;
|
---|
12 | import java.util.ArrayList;
|
---|
13 | import java.util.Arrays;
|
---|
14 | import java.util.List;
|
---|
15 | import java.util.concurrent.TimeUnit;
|
---|
16 |
|
---|
17 | import org.junit.ClassRule;
|
---|
18 | import org.junit.Ignore;
|
---|
19 | import org.junit.Rule;
|
---|
20 | import org.junit.Test;
|
---|
21 | import org.openstreetmap.gui.jmapviewer.TileXY;
|
---|
22 | import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
|
---|
23 | import org.openstreetmap.josm.Main;
|
---|
24 | import org.openstreetmap.josm.TestUtils;
|
---|
25 | import org.openstreetmap.josm.data.Bounds;
|
---|
26 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
27 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
28 | import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException;
|
---|
29 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
30 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
31 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
32 |
|
---|
33 | import com.github.tomakehurst.wiremock.client.WireMock;
|
---|
34 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
---|
35 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
---|
36 |
|
---|
37 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Unit tests for class {@link WMTSTileSource}.
|
---|
41 | */
|
---|
42 | public class WMTSTileSourceTest {
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Setup test.
|
---|
46 | */
|
---|
47 | @ClassRule
|
---|
48 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
49 | public static JOSMTestRules test = new JOSMTestRules().preferences().platform().projection().timeout((int) TimeUnit.MINUTES.toMillis(5));
|
---|
50 |
|
---|
51 | @Rule
|
---|
52 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
53 | public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
|
---|
54 |
|
---|
55 | private ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
|
---|
56 | private ImageryInfo testImageryPSEUDO_MERCATOR = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-pseudo-mercator.xml");
|
---|
57 | private ImageryInfo testImageryTOPO_PL = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-TOPO.xml");
|
---|
58 | private ImageryInfo testImageryORTO_PL = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-ORTO.xml");
|
---|
59 | private ImageryInfo testImageryWIEN = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-wien.xml");
|
---|
60 | private ImageryInfo testImageryWALLONIE = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Wallonie.xml");
|
---|
61 | private ImageryInfo testImageryOntario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
|
---|
62 | private ImageryInfo testImageryGeoAdminCh = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-GeoAdminCh.xml");
|
---|
63 | private ImageryInfo testImagery12168 = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12168-WMTSCapabilities.xml");
|
---|
64 | private ImageryInfo testLotsOfLayers = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml");
|
---|
65 | private ImageryInfo testDuplicateTags = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12573-wmts-identifier.xml");
|
---|
66 | private ImageryInfo testMissingStyleIdentifer = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12573-wmts-missing-style-identifier.xml");
|
---|
67 | private ImageryInfo testMultipleTileMatrixForLayer = getImagery(TestUtils.getTestDataRoot() +
|
---|
68 | "wmts/bug13975-multiple-tile-matrices-for-one-layer-projection.xml");
|
---|
69 | private ImageryInfo testImageryGisKtnGvAt = getImagery(TestUtils.getTestDataRoot() + "wmts/gis.ktn.gv.at.xml");
|
---|
70 |
|
---|
71 | private static ImageryInfo getImagery(String path) {
|
---|
72 | try {
|
---|
73 | ImageryInfo ret = new ImageryInfo(
|
---|
74 | "test",
|
---|
75 | new File(path).toURI().toURL().toString()
|
---|
76 | );
|
---|
77 | ret.setImageryType(ImageryType.WMTS);
|
---|
78 | return ret;
|
---|
79 | } catch (MalformedURLException e) {
|
---|
80 | e.printStackTrace();
|
---|
81 | return null;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Test
|
---|
86 | public void testPseudoMercator() throws IOException, WMTSGetCapabilitiesException {
|
---|
87 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
88 | WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR);
|
---|
89 | testSource.initProjection(Main.getProjection());
|
---|
90 |
|
---|
91 | verifyMercatorTile(testSource, 0, 0, 1);
|
---|
92 | verifyMercatorTile(testSource, 0, 0, 2);
|
---|
93 | verifyMercatorTile(testSource, 1, 1, 2);
|
---|
94 | for (int x = 0; x < 4; x++) {
|
---|
95 | for (int y = 0; y < 4; y++) {
|
---|
96 | verifyMercatorTile(testSource, x, y, 3);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | for (int x = 0; x < 8; x++) {
|
---|
100 | for (int y = 0; y < 4; y++) {
|
---|
101 | verifyMercatorTile(testSource, x, y, 4);
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 10);
|
---|
106 |
|
---|
107 | assertEquals("TileXMax", 1, testSource.getTileXMax(0));
|
---|
108 | assertEquals("TileYMax", 1, testSource.getTileYMax(0));
|
---|
109 | assertEquals("TileXMax", 2, testSource.getTileXMax(1));
|
---|
110 | assertEquals("TileYMax", 2, testSource.getTileYMax(1));
|
---|
111 | assertEquals("TileXMax", 4, testSource.getTileXMax(2));
|
---|
112 | assertEquals("TileYMax", 4, testSource.getTileYMax(2));
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Test
|
---|
116 | public void testWALLONIE() throws IOException, WMTSGetCapabilitiesException {
|
---|
117 | Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
|
---|
118 | WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
|
---|
119 | testSource.initProjection(Main.getProjection());
|
---|
120 |
|
---|
121 | assertEquals("http://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FOND_PLAN_ANNOTATIONS_2012_RW_NB/"
|
---|
122 | + "MapServer/WMTS/tile/1.0.0/DONNEES_BASE_FOND_PLAN_ANNOTATIONS_2012_RW_NB/default/default028mm/5/1219/1063.png",
|
---|
123 | testSource.getTileUrl(5, 1063, 1219));
|
---|
124 |
|
---|
125 | // +bounds=2.54,49.51,6.4,51.5
|
---|
126 | Bounds wallonieBounds = new Bounds(
|
---|
127 | new LatLon(49.485372459967245, 2.840548314430268),
|
---|
128 | new LatLon(50.820959517561256, 6.427849693016202)
|
---|
129 | );
|
---|
130 | verifyBounds(wallonieBounds, testSource, 5, 1063, 1219);
|
---|
131 | verifyBounds(wallonieBounds, testSource, 10, 17724, 20324);
|
---|
132 | }
|
---|
133 |
|
---|
134 | @Test
|
---|
135 | @Ignore("disable this test, needs further working") // XXX
|
---|
136 | public void testWALLONIENoMatrixDimension() throws IOException, WMTSGetCapabilitiesException {
|
---|
137 | Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
|
---|
138 | WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml"));
|
---|
139 | testSource.initProjection(Main.getProjection());
|
---|
140 |
|
---|
141 | Bounds wallonieBounds = new Bounds(
|
---|
142 | new LatLon(49.485372459967245, 2.840548314430268),
|
---|
143 | new LatLon(50.820959517561256, 6.427849693016202)
|
---|
144 | );
|
---|
145 |
|
---|
146 | verifyBounds(wallonieBounds, testSource, 6, 1063, 1219);
|
---|
147 | verifyBounds(wallonieBounds, testSource, 11, 17724, 20324);
|
---|
148 | }
|
---|
149 |
|
---|
150 | private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) {
|
---|
151 | LatLon ret = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
|
---|
152 | assertTrue(ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));
|
---|
153 | int tileXmax = testSource.getTileXMax(z);
|
---|
154 | int tileYmax = testSource.getTileYMax(z);
|
---|
155 | assertTrue("tile x: " + x + " is greater than allowed max: " + tileXmax, tileXmax >= x);
|
---|
156 | assertTrue("tile y: " + y + " is greater than allowed max: " + tileYmax, tileYmax >= y);
|
---|
157 | }
|
---|
158 |
|
---|
159 | @Test
|
---|
160 | public void testWIEN() throws IOException, WMTSGetCapabilitiesException {
|
---|
161 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
162 | WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
|
---|
163 | testSource.initProjection(Main.getProjection());
|
---|
164 | int zoomOffset = 10;
|
---|
165 |
|
---|
166 | verifyMercatorTile(testSource, 0, 0, 1, zoomOffset);
|
---|
167 | verifyMercatorTile(testSource, 1105, 709, 2, zoomOffset);
|
---|
168 | verifyMercatorTile(testSource, 1, 1, 1, zoomOffset);
|
---|
169 | verifyMercatorTile(testSource, 2, 2, 1, zoomOffset);
|
---|
170 | verifyMercatorTile(testSource, 0, 0, 2, zoomOffset);
|
---|
171 | verifyMercatorTile(testSource, 1, 1, 2, zoomOffset);
|
---|
172 |
|
---|
173 | for (int x = 0; x < 4; x++) {
|
---|
174 | for (int y = 0; y < 4; y++) {
|
---|
175 | verifyMercatorTile(testSource, x, y, 3, zoomOffset);
|
---|
176 | }
|
---|
177 | }
|
---|
178 | for (int x = 0; x < 8; x++) {
|
---|
179 | for (int y = 0; y < 4; y++) {
|
---|
180 | verifyMercatorTile(testSource, x, y, 4, zoomOffset);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 2, zoomOffset);
|
---|
185 |
|
---|
186 | verifyMercatorMax(testSource, 1, zoomOffset);
|
---|
187 | verifyMercatorMax(testSource, 2, zoomOffset);
|
---|
188 | verifyMercatorMax(testSource, 3, zoomOffset);
|
---|
189 | }
|
---|
190 |
|
---|
191 | private void verifyMercatorMax(WMTSTileSource testSource, int zoom, int zoomOffset) {
|
---|
192 | TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
|
---|
193 | int result = testSource.getTileXMax(zoom);
|
---|
194 | int expected = verifier.getTileXMax(zoom + zoomOffset);
|
---|
195 | assertTrue("TileXMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
|
---|
196 | result = testSource.getTileYMax(zoom);
|
---|
197 | expected = verifier.getTileYMax(zoom + zoomOffset);
|
---|
198 | assertTrue("TileYMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);
|
---|
199 | }
|
---|
200 |
|
---|
201 | @Test
|
---|
202 | public void testGeoportalTOPOPL() throws IOException, WMTSGetCapabilitiesException {
|
---|
203 | Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
|
---|
204 | WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL);
|
---|
205 | testSource.initProjection(Main.getProjection());
|
---|
206 | verifyTile(new LatLon(56, 12), testSource, 0, 0, 1);
|
---|
207 | verifyTile(new LatLon(56, 12), testSource, 0, 0, 2);
|
---|
208 | verifyTile(new LatLon(51.13231917844218, 16.867680821557823), testSource, 1, 1, 1);
|
---|
209 |
|
---|
210 | assertEquals("TileXMax", 2, testSource.getTileXMax(0));
|
---|
211 | assertEquals("TileYMax", 1, testSource.getTileYMax(0));
|
---|
212 | assertEquals("TileXMax", 3, testSource.getTileXMax(1));
|
---|
213 | assertEquals("TileYMax", 2, testSource.getTileYMax(1));
|
---|
214 | assertEquals("TileXMax", 6, testSource.getTileXMax(2));
|
---|
215 | assertEquals("TileYMax", 4, testSource.getTileYMax(2));
|
---|
216 | assertEquals(
|
---|
217 | "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&"
|
---|
218 | + "VERSION=1.0.0&LAYER=MAPA TOPOGRAFICZNA&STYLE=default&FORMAT=image/jpeg&tileMatrixSet=EPSG:4326&"
|
---|
219 | + "tileMatrix=EPSG:4326:0&tileRow=1&tileCol=1",
|
---|
220 | testSource.getTileUrl(0, 1, 1));
|
---|
221 | }
|
---|
222 |
|
---|
223 | @Test
|
---|
224 | public void testGeoportalORTOPL4326() throws IOException, WMTSGetCapabilitiesException {
|
---|
225 | Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
|
---|
226 | WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
|
---|
227 | testSource.initProjection(Main.getProjection());
|
---|
228 | verifyTile(new LatLon(53.60205873528009, 19.552206794646956), testSource, 12412, 3941, 13);
|
---|
229 | verifyTile(new LatLon(49.79005619189761, 22.778262259134397), testSource, 17714, 10206, 13);
|
---|
230 | }
|
---|
231 |
|
---|
232 | @Test
|
---|
233 | public void testGeoportalORTOPL2180() throws IOException, WMTSGetCapabilitiesException {
|
---|
234 | Main.setProjection(Projections.getProjectionByCode("EPSG:2180"));
|
---|
235 | WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
|
---|
236 | testSource.initProjection(Main.getProjection());
|
---|
237 |
|
---|
238 | verifyTile(new LatLon(53.59940948387726, 19.560544913270064), testSource, 6453, 3140, 13);
|
---|
239 | verifyTile(new LatLon(49.782984840526055, 22.790064966993445), testSource, 9932, 9305, 13);
|
---|
240 | }
|
---|
241 |
|
---|
242 | @Test
|
---|
243 | public void testTicket12168() throws IOException, WMTSGetCapabilitiesException {
|
---|
244 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
245 | WMTSTileSource testSource = new WMTSTileSource(testImagery12168);
|
---|
246 | testSource.initProjection(Main.getProjection());
|
---|
247 | assertEquals(
|
---|
248 | "http://www.ngi.be/cartoweb/1.0.0/topo/default/3857/7/1/1.png",
|
---|
249 | testSource.getTileUrl(0, 1, 1));
|
---|
250 | }
|
---|
251 |
|
---|
252 | @Test
|
---|
253 | public void testTwoTileSetsForOneProjection() throws Exception {
|
---|
254 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
255 | ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
|
---|
256 | ontario.setDefaultLayers(Arrays.asList(new DefaultLayer[] {
|
---|
257 | new DefaultLayer(ImageryType.WMTS, "Basemap_Imagery_2014", null, "default028mm")
|
---|
258 | }));
|
---|
259 | WMTSTileSource testSource = new WMTSTileSource(ontario);
|
---|
260 | testSource.initProjection(Main.getProjection());
|
---|
261 | assertEquals(
|
---|
262 | "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/"
|
---|
263 | + "default028mm/4/2932/2371.jpg",
|
---|
264 | testSource.getTileUrl(4, 2371, 2932));
|
---|
265 | verifyTile(new LatLon(45.4601306, -75.7617187), testSource, 2372, 2932, 4);
|
---|
266 | verifyTile(new LatLon(45.4602510, -75.7617187), testSource, 607232, 750591, 12);
|
---|
267 | }
|
---|
268 |
|
---|
269 | @Test
|
---|
270 | public void testTwoTileSetsForOneProjectionSecondLayer() throws Exception {
|
---|
271 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
272 | ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
|
---|
273 | ontario.setDefaultLayers(Arrays.asList(new DefaultLayer[] {
|
---|
274 | new DefaultLayer(ImageryType.WMTS, "Basemap_Imagery_2014", null, "GoogleMapsCompatible")
|
---|
275 | }));
|
---|
276 | WMTSTileSource testSource = new WMTSTileSource(ontario);
|
---|
277 | testSource.initProjection(Main.getProjection());
|
---|
278 | assertEquals(
|
---|
279 | "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/"
|
---|
280 | + "GoogleMapsCompatible/4/2932/2371.jpg",
|
---|
281 | testSource.getTileUrl(4, 2371, 2932));
|
---|
282 | verifyMercatorTile(testSource, 74, 91, 8);
|
---|
283 | verifyMercatorTile(testSource, 37952, 46912, 17);
|
---|
284 | }
|
---|
285 |
|
---|
286 | @Test
|
---|
287 | public void testManyLayersScrollbars() throws Exception {
|
---|
288 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
289 | WMTSTileSource testSource = new WMTSTileSource(testLotsOfLayers);
|
---|
290 | testSource.initProjection(Main.getProjection());
|
---|
291 | }
|
---|
292 |
|
---|
293 | @Test
|
---|
294 | public void testParserForDuplicateTags() throws Exception {
|
---|
295 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
296 | WMTSTileSource testSource = new WMTSTileSource(testDuplicateTags);
|
---|
297 | testSource.initProjection(Main.getProjection());
|
---|
298 | assertEquals(
|
---|
299 | "http://tile.informatievlaanderen.be/ws/raadpleegdiensten/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=grb_bsk&"
|
---|
300 | + "STYLE=&FORMAT=image/png&tileMatrixSet=GoogleMapsVL&tileMatrix=1&tileRow=1&tileCol=1",
|
---|
301 | testSource.getTileUrl(1, 1, 1)
|
---|
302 | );
|
---|
303 | }
|
---|
304 |
|
---|
305 | @Test
|
---|
306 | public void testParserForMissingStyleIdentifier() throws Exception {
|
---|
307 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
308 | WMTSTileSource testSource = new WMTSTileSource(testMissingStyleIdentifer);
|
---|
309 | testSource.initProjection(Main.getProjection());
|
---|
310 | }
|
---|
311 |
|
---|
312 | @Test
|
---|
313 | public void testForMultipleTileMatricesForOneLayerProjection() throws Exception {
|
---|
314 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
315 | ImageryInfo copy = new ImageryInfo(testMultipleTileMatrixForLayer);
|
---|
316 | List<DefaultLayer> defaultLayers = new ArrayList<>(1);
|
---|
317 | defaultLayers.add(new DefaultLayer(ImageryType.WMTS, "Mashhad_BaseMap_1", null, "default028mm"));
|
---|
318 | copy.setDefaultLayers(defaultLayers);
|
---|
319 | WMTSTileSource testSource = new WMTSTileSource(copy);
|
---|
320 | testSource.initProjection(Main.getProjection());
|
---|
321 | assertEquals(
|
---|
322 | "http://188.253.0.155:6080/arcgis/rest/services/Mashhad_BaseMap_1/MapServer/WMTS/tile/1.0.0/Mashhad_BaseMap_1"
|
---|
323 | + "/default/default028mm/1/3/2",
|
---|
324 | testSource.getTileUrl(1, 2, 3)
|
---|
325 | );
|
---|
326 | }
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Test WMTS dimension.
|
---|
330 | * @throws IOException if any I/O error occurs
|
---|
331 | * @throws WMTSGetCapabilitiesException if any error occurs
|
---|
332 | */
|
---|
333 | @Test
|
---|
334 | public void testDimension() throws IOException, WMTSGetCapabilitiesException {
|
---|
335 | Main.setProjection(Projections.getProjectionByCode("EPSG:21781"));
|
---|
336 | ImageryInfo info = new ImageryInfo(testImageryGeoAdminCh);
|
---|
337 | List<DefaultLayer> defaultLayers = new ArrayList<>(1);
|
---|
338 | defaultLayers.add(new DefaultLayer(ImageryType.WMTS, "ch.are.agglomerationen_isolierte_staedte", null, "21781_26"));
|
---|
339 | info.setDefaultLayers(defaultLayers);
|
---|
340 | WMTSTileSource testSource = new WMTSTileSource(info);
|
---|
341 | testSource.initProjection(Main.getProjection());
|
---|
342 | assertEquals(
|
---|
343 | "http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte/default/20140101/21781/1/3/2.png",
|
---|
344 | testSource.getTileUrl(1, 2, 3)
|
---|
345 | );
|
---|
346 | }
|
---|
347 |
|
---|
348 | @Test
|
---|
349 | public void testDefaultLayer() throws Exception {
|
---|
350 | // https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml
|
---|
351 | // do not use withFileBody as it needs different directory layout :(
|
---|
352 |
|
---|
353 | tileServer.stubFor(
|
---|
354 | WireMock.get("/getcapabilities.xml")
|
---|
355 | .willReturn(
|
---|
356 | WireMock.aResponse()
|
---|
357 | .withBody(Files.readAllBytes(
|
---|
358 | Paths.get(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml"))
|
---|
359 | )
|
---|
360 | )
|
---|
361 | );
|
---|
362 |
|
---|
363 | tileServer.stubFor(
|
---|
364 | WireMock.get("//maps")
|
---|
365 | .willReturn(
|
---|
366 | WireMock.aResponse().withBody(
|
---|
367 | "<?xml version='1.0' encoding='UTF-8'?>\n" +
|
---|
368 | "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
|
---|
369 | "<entry>\n" +
|
---|
370 | "<name>Landsat</name>\n" +
|
---|
371 | "<id>landsat</id>\n" +
|
---|
372 | "<type>wmts</type>\n" +
|
---|
373 | "<url><![CDATA[" + tileServer.url("/getcapabilities.xml") + "]]></url>\n" +
|
---|
374 | "<default-layers>" +
|
---|
375 | "<layer name=\"GEOGRAPHICALGRIDSYSTEMS.MAPS\" />" +
|
---|
376 | "</default-layers>" +
|
---|
377 | "</entry>\n" +
|
---|
378 | "</imagery>"
|
---|
379 | )));
|
---|
380 |
|
---|
381 | Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
|
---|
382 | ImageryLayerInfo.instance.loadDefaults(true, null, false);
|
---|
383 |
|
---|
384 | assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
|
---|
385 | ImageryInfo wmtsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
|
---|
386 | assertEquals(1, wmtsImageryInfo.getDefaultLayers().size());
|
---|
387 | assertEquals("GEOGRAPHICALGRIDSYSTEMS.MAPS", wmtsImageryInfo.getDefaultLayers().get(0).getLayerName());
|
---|
388 | WMTSTileSource tileSource = new WMTSTileSource(wmtsImageryInfo);
|
---|
389 | tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
390 | assertEquals("http://wxs.ign.fr/61fs25ymczag0c67naqvvmap/geoportail/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&"
|
---|
391 | + "LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS"
|
---|
392 | + "&STYLE=normal&FORMAT=image/jpeg&tileMatrixSet=PM&tileMatrix=1&tileRow=1&tileCol=1", tileSource.getTileUrl(1, 1, 1));
|
---|
393 |
|
---|
394 | }
|
---|
395 |
|
---|
396 | private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) {
|
---|
397 | LatLon ll = CoordinateConversion.coorToLL(source.tileXYToLatLon(x, y, z));
|
---|
398 | assertEquals("Latitude", expected.lat(), ll.lat(), 1e-05);
|
---|
399 | assertEquals("Longitude", expected.lon(), ll.lon(), 1e-05);
|
---|
400 | }
|
---|
401 |
|
---|
402 | private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z) {
|
---|
403 | verifyMercatorTile(testSource, x, y, z, 0);
|
---|
404 | }
|
---|
405 |
|
---|
406 | private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z, int zoomOffset) {
|
---|
407 | TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
|
---|
408 | LatLon result = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
|
---|
409 | LatLon expected = CoordinateConversion.coorToLL(verifier.tileXYToLatLon(x, y, z + zoomOffset));
|
---|
410 | assertEquals("Longitude", LatLon.normalizeLon(expected.lon() - result.lon()), 0.0, 1e-04);
|
---|
411 | assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
|
---|
412 | }
|
---|
413 |
|
---|
414 | @Test
|
---|
415 | public void testGisKtnGvAt() throws IOException, WMTSGetCapabilitiesException {
|
---|
416 | Main.setProjection(Projections.getProjectionByCode("EPSG:31258"));
|
---|
417 | final WMTSTileSource source = new WMTSTileSource(testImageryGisKtnGvAt);
|
---|
418 | source.initProjection(Main.getProjection());
|
---|
419 | final TileXY tile = source.latLonToTileXY(46.6103, 13.8558, 11);
|
---|
420 | assertEquals("https://gis.ktn.gv.at/arcgis/rest/services/tilecache/Ortho_2013_2015" +
|
---|
421 | "/MapServer/WMTS/tile/1.0.0/tilecache_Ortho_2013_2015/default/default028mm/11/6299/7373.jpg",
|
---|
422 | source.getTileUrl(11, tile.getXIndex(), tile.getYIndex()));
|
---|
423 | }
|
---|
424 | }
|
---|