- Timestamp:
- 2017-04-03T15:03:26+02:00 (8 years ago)
- 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 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.coor; 3 4 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected; 3 5 4 6 /** … … 20 22 public EastNorth(double east, double north) { 21 23 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()); 22 32 } 23 33 -
trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java
r11685 r11830 4 4 import java.awt.Point; 5 5 6 import org.openstreetmap.gui.jmapviewer.Projected; 6 7 import org.openstreetmap.gui.jmapviewer.Tile; 7 8 import org.openstreetmap.gui.jmapviewer.TileXY; 8 9 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 10 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected; 9 11 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 10 12 import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; … … 182 184 } 183 185 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 } 184 201 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r11824 r11830 40 40 41 41 import org.openstreetmap.gui.jmapviewer.Coordinate; 42 import org.openstreetmap.gui.jmapviewer.Projected; 42 43 import org.openstreetmap.gui.jmapviewer.Tile; 44 import org.openstreetmap.gui.jmapviewer.TileRange; 43 45 import org.openstreetmap.gui.jmapviewer.TileXY; 44 46 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 47 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected; 45 48 import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource; 46 49 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource; 47 50 import org.openstreetmap.josm.Main; 51 import org.openstreetmap.josm.data.ProjectionBounds; 48 52 import org.openstreetmap.josm.data.coor.EastNorth; 49 53 import org.openstreetmap.josm.data.coor.LatLon; … … 908 912 } 909 913 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 } 910 982 }
Note:
See TracChangeset
for help on using the changeset viewer.