Changeset 8696 in josm for trunk/src/org


Ignore:
Timestamp:
2015-08-27T21:19:44+02:00 (5 years ago)
Author:
wiktorn
Message:

Glue WMS zoom levels to TMS zoom levels.

Based on WMTS well known scale set (in OGC spec: http://www.opengeospatial.org/standards/wmts) GoogleMapsCompatibile
implement same zoom levels for WMS in JOSM. This change makes WMS zoom levels corresponding (identical?) to TMS zoom
levels and independent of current projection (as it was till now).

Addresses: #11808

File:
1 edited

Legend:

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

    r8659 r8696  
    6262    };
    6363
     64    /*
     65     * Constant taken from OGC WMTS Implementation Specification (http://www.opengeospatial.org/standards/wmts)
     66     * From table E.4 - Definition of Well-known scale set GoogleMapsCompatibile
     67     *
     68     *  As higher zoom levels have denominator divided by 2, we keep only zoom level 1 in the code
     69     */
     70    private static final float SCALE_DENOMINATOR_ZOOM_LEVEL_1 = 559082264.0287178f;
     71
    6472    /**
    6573     * Creates a tile source based on imagery info
     
    7280        initProjection();
    7381        // FIXME: remove in September 2015, when ImageryPreferenceEntry.tileSize will be initialized to -1 instead to 256
    74         // need to leave it as it is to keep compatiblity between tested and latest JOSM versions
     82        // need to leave it as it is to keep compatibility between tested and latest JOSM versions
    7583        tileSize = WMSLayer.PROP_IMAGE_SIZE.get();
    7684    }
     
    94102
    95103        LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon());
     104
     105        // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection
     106        double crsScale = 256 * 0.28e-03 / proj.getMetersPerUnit();
    96107        tileXMax = new int[getMaxZoom() + 1];
    97108        tileYMax = new int[getMaxZoom() + 1];
    98         degreesPerTile = new double[getMaxZoom() +1];
     109        degreesPerTile = new double[getMaxZoom() + 1];
     110
    99111        for (int zoom = getMinZoom(); zoom <= getMaxZoom(); zoom++) {
    100112            TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom);
    101113            tileXMax[zoom] = maxTileIndex.getXIndex();
    102114            tileYMax[zoom] = maxTileIndex.getYIndex();
    103             int tilesPerZoom = (int) Math.pow(2d, zoom - 1);
    104             degreesPerTile[zoom] = Math.max(
    105                     Math.abs(max.getY() - min.getY()) / tilesPerZoom,
    106                     Math.abs(max.getX() - min.getX()) / tilesPerZoom
    107                     );
    108 
     115            // use well known scale set "GoogleCompatibile" from OGC WMTS spec to calculate number of tiles per zoom level
     116            // this makes the zoom levels "glued" to standard TMS zoom levels
     117            degreesPerTile[zoom] = (SCALE_DENOMINATOR_ZOOM_LEVEL_1 / Math.pow(2, zoom - 1)) * crsScale;
    109118        }
    110119
Note: See TracChangeset for help on using the changeset viewer.