Changeset 8586 in josm for trunk/src


Ignore:
Timestamp:
2015-07-08T23:06:52+02:00 (9 years ago)
Author:
wiktorn
Message:
  • (WMTS) Added Style support
  • (WMTS) Added MatrixHeight and MatrixWidth support
  • (WMTS) Corrected best zoom calcu

Closes: #10623 - Walonnie WMTS finally works.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r8585 r8586  
    8080        int tileWidth;
    8181        int tileHeight;
     82        public int matrixWidth = -1;
     83        public int matrixHeight = -1;
    8284    }
    8385
     
    99101        Map<String, TileMatrixSet> tileMatrixSetByCRS = new ConcurrentHashMap<>();
    100102        public String baseUrl;
     103        public String style;
    101104    }
    102105
     
    163166    private double crsScale;
    164167    private TransferMode transferMode;
    165     private String style = "";
    166168
    167169    /**
     
    248250            layer.name = getStringByXpath(layerNode, "Identifier");
    249251            layer.baseUrl = getStringByXpath(layerNode, "ResourceURL[@resourceType='tile']/@template");
     252            layer.style = getStringByXpath(layerNode, "Style[@isDefault='true']/Identifier");
     253            if (layer.style == null) {
     254                layer.style = "";
     255            }
    250256            NodeList tileMatrixSetLinks = getByXpath(layerNode, "TileMatrixSetLink");
    251257            for (int tileMatrixId = 0; tileMatrixId < tileMatrixSetLinks.getLength(); tileMatrixId++) {
     
    287293                tileMatrix.tileHeight = Integer.parseInt(getStringByXpath(tileMatrixNode, "TileHeight"));
    288294                tileMatrix.tileWidth = Integer.parseInt(getStringByXpath(tileMatrixNode, "TileHeight"));
     295                tileMatrix.matrixWidth = getOptionalIntegerByXpath(tileMatrixNode, "MatrixWidth");
     296                tileMatrix.matrixHeight = getOptionalIntegerByXpath(tileMatrixNode, "MatrixHeight");
    289297                if (tileMatrix.tileHeight != tileMatrix.tileWidth) {
    290298                    throw new AssertionError(tr("Only square tiles are supported. {0}x{1} returned by server for TileMatrix identifier {2}",
     
    304312        }
    305313        return crsIdentifier;
     314    }
     315
     316    private int getOptionalIntegerByXpath(Node document, String xpathQuery) throws XPathExpressionException {
     317        String ret = getStringByXpath(document, xpathQuery);
     318        if (ret == null || "".equals(ret)) {
     319            return -1;
     320        }
     321        return Integer.parseInt(ret);
    306322    }
    307323
     
    384400                .replaceAll("\\{TileRow\\}", Integer.toString(tiley))
    385401                .replaceAll("\\{TileCol\\}", Integer.toString(tilex))
    386                 .replaceAll("\\{Style\\}", this.style);
     402                .replaceAll("\\{Style\\}", this.currentLayer.style);
    387403    }
    388404
     
    595611            return 0;
    596612        }
     613
     614        if (matrix.matrixHeight != -1) {
     615            return matrix.matrixHeight;
     616        }
     617
    597618        double scale = matrix.scaleDenominator * this.crsScale;
    598         Bounds bounds = Main.getProjection().getWorldBoundsLatLon();
     619        Bounds bounds = proj.getWorldBoundsLatLon();
    599620        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
    600621        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
     
    607628            return 0;
    608629        }
     630        if (matrix.matrixWidth != -1) {
     631            return matrix.matrixWidth;
     632        }
     633
    609634        double scale = matrix.scaleDenominator * this.crsScale;
    610         Bounds bounds = Main.getProjection().getWorldBoundsLatLon();
     635        Bounds bounds = proj.getWorldBoundsLatLon();
    611636        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
    612637        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r8584 r8586  
    55import java.util.Map;
    66
     7import org.openstreetmap.gui.jmapviewer.TileXY;
    78import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    89import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
     
    8182     */
    8283    private double getTileToScreenRatio(int zoom) {
    83          ICoordinate north = tileSource.tileXYToLatLon(0, 0, zoom);
    84          ICoordinate south = tileSource.tileXYToLatLon(0, 1, zoom);
    85 
    8684         MapView mv = Main.map.mapView;
    8785         LatLon topLeft = mv.getLatLon(0, 0);
    8886         LatLon botLeft = mv.getLatLon(0, tileSource.getTileSize());
     87
     88         TileXY topLeftTile = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom);
     89
     90         ICoordinate north = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex(), zoom);
     91         ICoordinate south = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex() + 1, zoom);
    8992
    9093         return Math.abs((north.getLat() - south.getLat()) / (topLeft.lat() - botLeft.lat()));
     
    9598        if (!Main.isDisplayingMapView()) return 1;
    9699
    97         for (int i = getMinZoomLvl(); i <= getMaxZoomLvl(); i++) {
     100        for (int i = getMinZoomLvl() + 1; i <= getMaxZoomLvl(); i++) {
    98101            double ret = getTileToScreenRatio(i);
    99102            if (ret < 1) {
    100                 return i;
     103                return i - 1;
    101104            }
    102105        }
Note: See TracChangeset for help on using the changeset viewer.