Changeset 11830 in josm for trunk


Ignore:
Timestamp:
2017-04-03T15:03:26+02:00 (8 years ago)
Author:
bastiK
Message:

see #7427 - add implementations for new TileSource methods

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r10915 r11830  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
     3
     4import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
    35
    46/**
     
    2022    public EastNorth(double east, double north) {
    2123        super(east, north);
     24    }
     25
     26    /**
     27     * Constructs a new {@code EastNorth} from {@link IProjected}.
     28     * @param p projected coordinates
     29     */
     30    public EastNorth(IProjected p) {
     31        super(p.getEast(), p.getNorth());
    2232    }
    2333
  • trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java

    r11685 r11830  
    44import java.awt.Point;
    55
     6import org.openstreetmap.gui.jmapviewer.Projected;
    67import org.openstreetmap.gui.jmapviewer.Tile;
    78import org.openstreetmap.gui.jmapviewer.TileXY;
    89import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     10import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
    911import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
    1012import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
     
    182184    }
    183185
     186    @Override
     187    public IProjected tileXYtoProjected(int x, int y, int zoom) {
     188        EastNorth en = getTileEastNorth(x, y, zoom);
     189        return new Projected(en.east(), en.north());
     190    }
     191
     192    @Override
     193    public TileXY projectedToTileXY(IProjected p, int zoom) {
     194        return eastNorthToTileXY(new EastNorth(p.getEast(), p.getNorth()), zoom);
     195    }
     196
     197    @Override
     198    public String getServerCRS() {
     199        return Main.getProjection().toCode();
     200    }
    184201}
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r11824 r11830  
    4040
    4141import org.openstreetmap.gui.jmapviewer.Coordinate;
     42import org.openstreetmap.gui.jmapviewer.Projected;
    4243import org.openstreetmap.gui.jmapviewer.Tile;
     44import org.openstreetmap.gui.jmapviewer.TileRange;
    4345import org.openstreetmap.gui.jmapviewer.TileXY;
    4446import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     47import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
    4548import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
    4649import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    4750import org.openstreetmap.josm.Main;
     51import org.openstreetmap.josm.data.ProjectionBounds;
    4852import org.openstreetmap.josm.data.coor.EastNorth;
    4953import org.openstreetmap.josm.data.coor.LatLon;
     
    908912    }
    909913
     914    @Override
     915    public IProjected tileXYtoProjected(int x, int y, int zoom) {
     916        TileMatrix matrix = getTileMatrix(zoom);
     917        if (matrix == null) {
     918            return new Projected(0, 0);
     919        }
     920        double scale = matrix.scaleDenominator * this.crsScale;
     921        return new Projected(
     922                matrix.topLeftCorner.east() + x * scale,
     923                matrix.topLeftCorner.north() - y * scale);
     924    }
     925
     926    @Override
     927    public TileXY projectedToTileXY(IProjected projected, int zoom) {
     928        TileMatrix matrix = getTileMatrix(zoom);
     929        if (matrix == null) {
     930            return new TileXY(0, 0);
     931        }
     932        double scale = matrix.scaleDenominator * this.crsScale;
     933        return new TileXY(
     934                (projected.getEast() - matrix.topLeftCorner.east()) / scale,
     935                -(projected.getNorth() - matrix.topLeftCorner.north()) / scale);
     936    }
     937
     938    private ProjectionBounds getTileProjectionBounds(Tile tile) {
     939        ProjectionBounds pb = new ProjectionBounds(new EastNorth(
     940                this.tileXYtoProjected(tile.getXtile(), tile.getYtile(), tile.getZoom())));
     941        pb.extend(new EastNorth(this.tileXYtoProjected(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom())));
     942        return pb;
     943    }
     944
     945    @Override
     946    public boolean isInside(Tile inner, Tile outer) {
     947        ProjectionBounds pbInner = getTileProjectionBounds(inner);
     948        ProjectionBounds pbOuter = getTileProjectionBounds(outer);
     949        // a little tolerance, for when inner tile touches the border of the
     950        // outer tile
     951        double epsilon = 1e-7 * (pbOuter.maxEast - pbOuter.minEast);
     952        return pbOuter.minEast <= pbInner.minEast + epsilon &&
     953                pbOuter.minNorth <= pbInner.minNorth + epsilon &&
     954                pbOuter.maxEast >= pbInner.maxEast - epsilon &&
     955                pbOuter.maxNorth >= pbInner.maxNorth - epsilon;
     956    }
     957
     958    @Override
     959    public TileRange getCoveringTileRange(Tile tile, int newZoom) {
     960        TileMatrix matrixNew = getTileMatrix(newZoom);
     961        if (matrixNew == null) {
     962            return new TileRange(new TileXY(0, 0), new TileXY(0, 0), newZoom);
     963        }
     964        IProjected p0 = tileXYtoProjected(tile.getXtile(), tile.getYtile(), tile.getZoom());
     965        IProjected p1 = tileXYtoProjected(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom());
     966        TileXY tMin = projectedToTileXY(p0, newZoom);
     967        TileXY tMax = projectedToTileXY(p1, newZoom);
     968        // shrink the target tile a little, so we don't get neighboring tiles, that
     969        // share an edge, but don't actually cover the target tile
     970        double epsilon = 1e-7 * (tMax.getX() - tMin.getX());
     971        int minX = (int) Math.floor(tMin.getX() + epsilon);
     972        int minY = (int) Math.floor(tMin.getY() + epsilon);
     973        int maxX = (int) Math.ceil(tMax.getX() - epsilon) - 1;
     974        int maxY = (int) Math.ceil(tMax.getY() - epsilon) - 1;
     975        return new TileRange(new TileXY(minX, minY), new TileXY(maxX, maxY), newZoom);
     976    }
     977
     978    @Override
     979    public String getServerCRS() {
     980        return Main.getProjection().toCode();
     981    }
    910982}
Note: See TracChangeset for help on using the changeset viewer.