Changeset 12224 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r11881 r12224 74 74 // CHECKSTYLE.OFF: SingleSpaceSeparator 75 75 private static final QName QN_CONTENTS = new QName(WMTSTileSource.WMTS_NS_URL, "Contents"); 76 private static final QName QN_DEFAULT = new QName(WMTSTileSource.WMTS_NS_URL, "Default"); 77 private static final QName QN_DIMENSION = new QName(WMTSTileSource.WMTS_NS_URL, "Dimension"); 76 78 private static final QName QN_FORMAT = new QName(WMTSTileSource.WMTS_NS_URL, "Format"); 77 79 private static final QName QN_LAYER = new QName(WMTSTileSource.WMTS_NS_URL, "Layer"); … … 87 89 private static final QName QN_TILE_HEIGHT = new QName(WMTSTileSource.WMTS_NS_URL, "TileHeight"); 88 90 private static final QName QN_TOPLEFT_CORNER = new QName(WMTSTileSource.WMTS_NS_URL, "TopLeftCorner"); 91 private static final QName QN_VALUE = new QName(WMTSTileSource.WMTS_NS_URL, "Value"); 89 92 // CHECKSTYLE.ON: SingleSpaceSeparator 90 93 … … 142 145 identifier = builder.identifier; 143 146 } 144 147 } 148 149 private static class Dimension { 150 private String identifier; 151 private String defaultValue; 152 private final List<String> values = new ArrayList<>(); 145 153 } 146 154 … … 153 161 private String style; 154 162 private final Collection<String> tileMatrixSetLinks = new ArrayList<>(); 163 private final Collection<Dimension> dimensions = new ArrayList<>(); 155 164 156 165 Layer(Layer l) { … … 162 171 style = l.style; 163 172 tileMatrixSet = new TileMatrixSet(l.tileMatrixSet); 173 dimensions.addAll(l.dimensions); 164 174 } 165 175 … … 458 468 tagStack.push(reader.getName()); // keep tagStack in sync 459 469 } 470 } else if (QN_DIMENSION.equals(reader.getName())) { 471 layer.dimensions.add(parseDimension(reader)); 460 472 } else if (QN_TILEMATRIX_SET_LINK.equals(reader.getName())) { 461 layer.tileMatrixSetLinks.add(p raseTileMatrixSetLink(reader));473 layer.tileMatrixSetLinks.add(parseTileMatrixSetLink(reader)); 462 474 } else { 463 475 GetCapabilitiesParseHelper.moveReaderToEndCurrentTag(reader); … … 488 500 489 501 /** 502 * Gets Dimension value. Returns when reader is on Dimension closing tag 503 * 504 * @param reader StAX reader instance 505 * @return dimension 506 * @throws XMLStreamException See {@link XMLStreamReader} 507 */ 508 private static Dimension parseDimension(XMLStreamReader reader) throws XMLStreamException { 509 Dimension ret = new Dimension(); 510 for (int event = reader.getEventType(); 511 reader.hasNext() && !(event == XMLStreamReader.END_ELEMENT && 512 QN_DIMENSION.equals(reader.getName())); 513 event = reader.next()) { 514 if (event == XMLStreamReader.START_ELEMENT) { 515 if (GetCapabilitiesParseHelper.QN_OWS_IDENTIFIER.equals(reader.getName())) { 516 ret.identifier = reader.getElementText(); 517 } else if (QN_DEFAULT.equals(reader.getName())) { 518 ret.defaultValue = reader.getElementText(); 519 } else if (QN_VALUE.equals(reader.getName())) { 520 ret.values.add(reader.getElementText()); 521 } 522 } 523 } 524 return ret; 525 } 526 527 /** 490 528 * Gets TileMatrixSetLink value. Returns when reader is on TileMatrixSetLink closing tag 491 529 * … … 494 532 * @throws XMLStreamException See {@link XMLStreamReader} 495 533 */ 496 private static String p raseTileMatrixSetLink(XMLStreamReader reader) throws XMLStreamException {534 private static String parseTileMatrixSetLink(XMLStreamReader reader) throws XMLStreamException { 497 535 String ret = null; 498 536 for (int event = reader.getEventType(); … … 718 756 } 719 757 720 returnurl.replaceAll("\\{layer\\}", this.currentLayer.identifier)758 url = url.replaceAll("\\{layer\\}", this.currentLayer.identifier) 721 759 .replaceAll("\\{format\\}", this.currentLayer.format) 722 760 .replaceAll("\\{TileMatrixSet\\}", this.currentTileMatrixSet.identifier) … … 725 763 .replaceAll("\\{TileCol\\}", Integer.toString(tilex)) 726 764 .replaceAll("(?i)\\{style\\}", this.currentLayer.style); 765 766 for (Dimension d : currentLayer.dimensions) { 767 url = url.replaceAll("\\{"+d.identifier+"\\}", d.defaultValue); 768 } 769 770 return url; 727 771 } 728 772 … … 935 979 } 936 980 981 /** 982 * Returns the tile projection. 983 * @return the tile projection 984 */ 937 985 public Projection getTileProjection() { 938 986 return tileProjection; -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r11257 r12224 36 36 private ImageryInfo testImageryWALLONIE = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Wallonie.xml"); 37 37 private ImageryInfo testImageryOntario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml"); 38 private ImageryInfo testImageryGeoAdminCh = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-GeoAdminCh.xml"); 38 39 private ImageryInfo testImagery12168 = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12168-WMTSCapabilities.xml"); 39 40 private ImageryInfo testLotsOfLayers = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml"); … … 245 246 WMTSTileSource testSource = new WMTSTileSource(testLotsOfLayers); 246 247 testSource.initProjection(Main.getProjection()); 247 248 248 } 249 249 … … 279 279 "http://188.253.0.155:6080/arcgis/rest/services/Mashhad_BaseMap_1/MapServer/WMTS/tile/1.0.0/Mashhad_BaseMap_1" 280 280 + "/default/default028mm/1/3/2", 281 testSource.getTileUrl(1, 2, 3) 282 ); 283 } 284 285 /** 286 * Test WMTS dimension. 287 * @throws IOException if any I/O error occurs 288 */ 289 @Test 290 public void testDimension() throws IOException { 291 Main.setProjection(Projections.getProjectionByCode("EPSG:21781")); 292 ImageryInfo info = new ImageryInfo(testImageryGeoAdminCh); 293 Collection<DefaultLayer> defaultLayers = new ArrayList<>(1); 294 defaultLayers.add(new WMTSDefaultLayer("ch.are.agglomerationen_isolierte_staedte", "21781_26")); 295 info.setDefaultLayers(defaultLayers); 296 WMTSTileSource testSource = new WMTSTileSource(info); 297 testSource.initProjection(Main.getProjection()); 298 assertEquals( 299 "http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte/default/20140101/21781/1/3/2.png", 281 300 testSource.getTileUrl(1, 2, 3) 282 301 );
Note: See TracChangeset
for help on using the changeset viewer.