Changeset 12224 in josm


Ignore:
Timestamp:
2017-05-21T17:56:42+02:00 (7 months ago)
Author:
Don-vip
Message:

fix #14825 - Support WMTS Dimensions

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r11881 r12224  
    7474    // CHECKSTYLE.OFF: SingleSpaceSeparator
    7575    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");
    7678    private static final QName QN_FORMAT              = new QName(WMTSTileSource.WMTS_NS_URL, "Format");
    7779    private static final QName QN_LAYER               = new QName(WMTSTileSource.WMTS_NS_URL, "Layer");
     
    8789    private static final QName QN_TILE_HEIGHT         = new QName(WMTSTileSource.WMTS_NS_URL, "TileHeight");
    8890    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");
    8992    // CHECKSTYLE.ON: SingleSpaceSeparator
    9093
     
    142145            identifier = builder.identifier;
    143146        }
    144 
     147    }
     148
     149    private static class Dimension {
     150        private String identifier;
     151        private String defaultValue;
     152        private final List<String> values = new ArrayList<>();
    145153    }
    146154
     
    153161        private String style;
    154162        private final Collection<String> tileMatrixSetLinks = new ArrayList<>();
     163        private final Collection<Dimension> dimensions = new ArrayList<>();
    155164
    156165        Layer(Layer l) {
     
    162171            style = l.style;
    163172            tileMatrixSet = new TileMatrixSet(l.tileMatrixSet);
     173            dimensions.addAll(l.dimensions);
    164174        }
    165175
     
    458468                            tagStack.push(reader.getName()); // keep tagStack in sync
    459469                        }
     470                    } else if (QN_DIMENSION.equals(reader.getName())) {
     471                        layer.dimensions.add(parseDimension(reader));
    460472                    } else if (QN_TILEMATRIX_SET_LINK.equals(reader.getName())) {
    461                         layer.tileMatrixSetLinks.add(praseTileMatrixSetLink(reader));
     473                        layer.tileMatrixSetLinks.add(parseTileMatrixSetLink(reader));
    462474                    } else {
    463475                        GetCapabilitiesParseHelper.moveReaderToEndCurrentTag(reader);
     
    488500
    489501    /**
     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    /**
    490528     * Gets TileMatrixSetLink value. Returns when reader is on TileMatrixSetLink closing tag
    491529     *
     
    494532     * @throws XMLStreamException See {@link XMLStreamReader}
    495533     */
    496     private static String praseTileMatrixSetLink(XMLStreamReader reader) throws XMLStreamException {
     534    private static String parseTileMatrixSetLink(XMLStreamReader reader) throws XMLStreamException {
    497535        String ret = null;
    498536        for (int event = reader.getEventType();
     
    718756        }
    719757
    720         return url.replaceAll("\\{layer\\}", this.currentLayer.identifier)
     758        url = url.replaceAll("\\{layer\\}", this.currentLayer.identifier)
    721759                .replaceAll("\\{format\\}", this.currentLayer.format)
    722760                .replaceAll("\\{TileMatrixSet\\}", this.currentTileMatrixSet.identifier)
     
    725763                .replaceAll("\\{TileCol\\}", Integer.toString(tilex))
    726764                .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;
    727771    }
    728772
     
    935979    }
    936980
     981    /**
     982     * Returns the tile projection.
     983     * @return the tile projection
     984     */
    937985    public Projection getTileProjection() {
    938986        return tileProjection;
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r11257 r12224  
    3636    private ImageryInfo testImageryWALLONIE = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Wallonie.xml");
    3737    private ImageryInfo testImageryOntario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
     38    private ImageryInfo testImageryGeoAdminCh = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-GeoAdminCh.xml");
    3839    private ImageryInfo testImagery12168 = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12168-WMTSCapabilities.xml");
    3940    private ImageryInfo testLotsOfLayers = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml");
     
    245246        WMTSTileSource testSource = new WMTSTileSource(testLotsOfLayers);
    246247        testSource.initProjection(Main.getProjection());
    247 
    248248    }
    249249
     
    279279                "http://188.253.0.155:6080/arcgis/rest/services/Mashhad_BaseMap_1/MapServer/WMTS/tile/1.0.0/Mashhad_BaseMap_1"
    280280                        + "/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",
    281300                testSource.getTileUrl(1, 2, 3)
    282301                );
Note: See TracChangeset for help on using the changeset viewer.