Changeset 12669 in josm


Ignore:
Timestamp:
2017-08-27T00:17:49+02:00 (4 weeks ago)
Author:
Don-vip
Message:

see #15182 - remove dependence on JMapViewer for package data.coor (only useful for imagery)

Location:
trunk
Files:
1 added
9 edited

Legend:

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

    r12375 r12669  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
    3 
    4 import org.openstreetmap.gui.jmapviewer.JMapViewer;
    5 import org.openstreetmap.gui.jmapviewer.Projected;
    6 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
    73
    84/**
     
    2925    public EastNorth(double east, double north) {
    3026        super(east, north);
    31     }
    32 
    33     /**
    34      * Constructs a new {@code EastNorth} from {@link IProjected}.
    35      * @param p projected coordinates
    36      */
    37     public EastNorth(IProjected p) {
    38         super(p.getEast(), p.getNorth());
    3927    }
    4028
     
    188176    }
    189177
    190     /**
    191      * Converts this to a {@link IProjected} instance to be used in the {@link JMapViewer}
    192      * @return The projected
    193      */
    194     public IProjected toProjected() {
    195         return new Projected(east(), north());
    196     }
    197 
    198178    @Override
    199179    public String toString() {
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r12620 r12669  
    2323import java.util.regex.Pattern;
    2424
    25 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    2625import org.openstreetmap.josm.Main;
    2726import org.openstreetmap.josm.data.Bounds;
     
    294293    }
    295294
    296     /**
    297      * Constructs a new object for the given coordinate
    298      * @param coor the coordinate
    299      */
    300     public LatLon(ICoordinate coor) {
    301         this(coor.getLat(), coor.getLon());
    302     }
    303 
    304295    @Override
    305296    public double lat() {
     
    566557        return Double.compare(that.x, x) == 0 &&
    567558               Double.compare(that.y, y) == 0;
    568     }
    569 
    570     /**
    571      * Converts this latitude/longitude to an instance of {@link ICoordinate}.
    572      * @return a {@link ICoordinate} instance of this latitude/longitude
    573      */
    574     public ICoordinate toCoordinate() {
    575         return new org.openstreetmap.gui.jmapviewer.Coordinate(lat(), lon());
    576559    }
    577560
  • trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java

    r11858 r12669  
    110110    @Override
    111111    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
    112         return tileProjection.eastNorth2latlon(getTileEastNorth(x, y, zoom)).toCoordinate();
     112        return CoordinateConversion.llToCoor(tileProjection.eastNorth2latlon(getTileEastNorth(x, y, zoom)));
    113113    }
    114114
     
    179179                anchorPosition.north() - y * scale
    180180                );
    181         return tileProjection.eastNorth2latlon(ret).toCoordinate();
     181        return CoordinateConversion.llToCoor(tileProjection.eastNorth2latlon(ret));
    182182    }
    183183
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r12620 r12669  
    808808        TileMatrix matrix = getTileMatrix(zoom);
    809809        if (matrix == null) {
    810             return tileProjection.getWorldBoundsLatLon().getCenter().toCoordinate();
     810            return CoordinateConversion.llToCoor(tileProjection.getWorldBoundsLatLon().getCenter());
    811811        }
    812812        double scale = matrix.scaleDenominator * this.crsScale;
    813813        EastNorth ret = new EastNorth(matrix.topLeftCorner.east() + x * scale, matrix.topLeftCorner.north() - y * scale);
    814         return tileProjection.eastNorth2latlon(ret).toCoordinate();
     814        return CoordinateConversion.llToCoor(tileProjection.eastNorth2latlon(ret));
    815815    }
    816816
     
    10141014    }
    10151015
     1016    private EastNorth tileToEastNorth(int x, int y, int z) {
     1017        return CoordinateConversion.projToEn(this.tileXYtoProjected(x, y, z));
     1018    }
     1019
    10161020    private ProjectionBounds getTileProjectionBounds(Tile tile) {
    1017         ProjectionBounds pb = new ProjectionBounds(new EastNorth(
    1018                 this.tileXYtoProjected(tile.getXtile(), tile.getYtile(), tile.getZoom())));
    1019         pb.extend(new EastNorth(this.tileXYtoProjected(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom())));
     1021        ProjectionBounds pb = new ProjectionBounds(tileToEastNorth(tile.getXtile(), tile.getYtile(), tile.getZoom()));
     1022        pb.extend(tileToEastNorth(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom()));
    10201023        return pb;
    10211024    }
     
    10251028        ProjectionBounds pbInner = getTileProjectionBounds(inner);
    10261029        ProjectionBounds pbOuter = getTileProjectionBounds(outer);
    1027         // a little tolerance, for when inner tile touches the border of the
    1028         // outer tile
     1030        // a little tolerance, for when inner tile touches the border of the outer tile
    10291031        double epsilon = 1e-7 * (pbOuter.maxEast - pbOuter.minEast);
    10301032        return pbOuter.minEast <= pbInner.minEast + epsilon &&
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r12630 r12669  
    8080import org.openstreetmap.josm.data.coor.EastNorth;
    8181import org.openstreetmap.josm.data.coor.LatLon;
     82import org.openstreetmap.josm.data.imagery.CoordinateConversion;
    8283import org.openstreetmap.josm.data.imagery.ImageryInfo;
    8384import org.openstreetmap.josm.data.imagery.OffsetBookmark;
     
    11351136
    11361137    private ICoordinate getShiftedCoord(EastNorth en) {
    1137         return getShiftedLatLon(en).toCoordinate();
     1138        return CoordinateConversion.llToCoor(getShiftedLatLon(en));
    11381139    }
    11391140
     
    12841285            return new TileSet();
    12851286        TileXY t1, t2;
     1287        IProjected topLeftUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMin());
     1288        IProjected botRightUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMax());
    12861289        if (coordinateConverter.requiresReprojection()) {
    12871290            Projection projServer = Projections.getProjectionByCode(tileSource.getServerCRS());
    12881291            ProjectionBounds projBounds = new ProjectionBounds(
    1289                     new EastNorth(coordinateConverter.shiftDisplayToServer(bounds.getMin())),
    1290                     new EastNorth(coordinateConverter.shiftDisplayToServer(bounds.getMax())));
     1292                    CoordinateConversion.projToEn(topLeftUnshifted),
     1293                    CoordinateConversion.projToEn(botRightUnshifted));
    12911294            ProjectionBounds bbox = projServer.getEastNorthBoundsBox(projBounds, Main.getProjection());
    1292             t1 = tileSource.projectedToTileXY(bbox.getMin().toProjected(), zoom);
    1293             t2 = tileSource.projectedToTileXY(bbox.getMax().toProjected(), zoom);
     1295            t1 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(bbox.getMin()), zoom);
     1296            t2 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(bbox.getMax()), zoom);
    12941297        } else {
    1295             IProjected topLeftUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMin());
    1296             IProjected botRightUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMax());
    12971298            t1 = tileSource.projectedToTileXY(topLeftUnshifted, zoom);
    12981299            t2 = tileSource.projectedToTileXY(botRightUnshifted, zoom);
     
    17451746        for (LatLon point: points) {
    17461747            TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel);
    1747             TileXY curTile = tileSource.latLonToTileXY(point.toCoordinate(), currentZoomLevel);
     1748            TileXY curTile = tileSource.latLonToTileXY(CoordinateConversion.llToCoor(point), currentZoomLevel);
    17481749            TileXY maxTile = tileSource.latLonToTileXY(point.lat() + bufferY, point.lon() + bufferX, currentZoomLevel);
    17491750
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ReprojectionTile.java

    r12630 r12669  
    1111import org.openstreetmap.josm.data.ProjectionBounds;
    1212import org.openstreetmap.josm.data.coor.EastNorth;
     13import org.openstreetmap.josm.data.imagery.CoordinateConversion;
    1314import org.openstreetmap.josm.data.projection.Projection;
    1415import org.openstreetmap.josm.data.projection.Projections;
     
    9596        this.anchor = null;
    9697        this.maxZoomReached = false;
     98    }
     99
     100    private EastNorth tileToEastNorth(int x, int y, int z) {
     101        return CoordinateConversion.projToEn(source.tileXYtoProjected(x, y, z));
    97102    }
    98103
     
    118123        Projection projCurrent = Main.getProjection();
    119124        Projection projServer = Projections.getProjectionByCode(source.getServerCRS());
    120         EastNorth en00Server = new EastNorth(source.tileXYtoProjected(xtile, ytile, zoom));
    121         EastNorth en11Server = new EastNorth(source.tileXYtoProjected(xtile + 1, ytile + 1, zoom));
     125        EastNorth en00Server = tileToEastNorth(xtile, ytile, zoom);
     126        EastNorth en11Server = tileToEastNorth(xtile + 1, ytile + 1, zoom);
    122127        ProjectionBounds pbServer = new ProjectionBounds(en00Server);
    123128        pbServer.extend(en11Server);
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileCoordinateConverter.java

    r11961 r12669  
    1717import org.openstreetmap.josm.data.coor.EastNorth;
    1818import org.openstreetmap.josm.data.coor.LatLon;
     19import org.openstreetmap.josm.data.imagery.CoordinateConversion;
    1920import org.openstreetmap.josm.data.projection.Projecting;
    2021import org.openstreetmap.josm.data.projection.ShiftedProjecting;
     
    4647
    4748    private MapViewPoint pos(ICoordinate ll) {
    48         return mapView.getState().getPointFor(new LatLon(ll)).add(settings.getDisplacement());
     49        return mapView.getState().getPointFor(CoordinateConversion.coorToLL(ll)).add(settings.getDisplacement());
    4950    }
    5051
    5152    private MapViewPoint pos(IProjected p) {
    52         return mapView.getState().getPointFor(new EastNorth(p)).add(settings.getDisplacement());
     53        return mapView.getState().getPointFor(CoordinateConversion.projToEn(p)).add(settings.getDisplacement());
    5354    }
    5455
     
    6061     */
    6162    public IProjected shiftDisplayToServer(EastNorth en) {
    62         return en.subtract(settings.getDisplacement()).toProjected();
     63        return CoordinateConversion.enToProj(en.subtract(settings.getDisplacement()));
    6364    }
    6465
     
    102103        if (requiresReprojection()) {
    103104            LatLon ll = getProjecting().eastNorth2latlonClamped(mapView.getEastNorth(sx, sy));
    104             return tileSource.latLonToTileXY(ll.toCoordinate(), zoom);
     105            return tileSource.latLonToTileXY(CoordinateConversion.llToCoor(ll), zoom);
    105106        } else {
    106107            IProjected p = shiftDisplayToServer(mapView.getEastNorth(sx, sy));
     
    165166            LatLon topLeft = mapView.getLatLon(0, 0);
    166167            LatLon botRight = mapView.getLatLon(mapView.getWidth(), mapView.getHeight());
    167             t1 = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom);
    168             t2 = tileSource.latLonToTileXY(botRight.toCoordinate(), zoom);
     168            t1 = tileSource.latLonToTileXY(CoordinateConversion.llToCoor(topLeft), zoom);
     169            t2 = tileSource.latLonToTileXY(CoordinateConversion.llToCoor(botRight), zoom);
    169170        } else {
    170171            EastNorth topLeftEN = mapView.getEastNorth(0, 0);
    171172            EastNorth botRightEN = mapView.getEastNorth(mapView.getWidth(), mapView.getHeight());
    172             t1 = tileSource.projectedToTileXY(topLeftEN.toProjected(), zoom);
    173             t2 = tileSource.projectedToTileXY(botRightEN.toProjected(), zoom);
     173            t1 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(topLeftEN), zoom);
     174            t2 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(botRightEN), zoom);
    174175        }
    175176        int screenPixels = mapView.getWidth()*mapView.getHeight();
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java

    r11859 r12669  
    159159        assertEquals(LatLon.normalizeLon(expected.getLon() - result.lon()), 0.0, 1e-4);
    160160        LatLon tileCenter = new Bounds(result, getTileLatLon(source, x+1, y+1, z)).getCenter();
    161         TileXY backwardsResult = source.latLonToTileXY(tileCenter.toCoordinate(), z);
     161        TileXY backwardsResult = source.latLonToTileXY(CoordinateConversion.llToCoor(tileCenter), z);
    162162        assertEquals(x, backwardsResult.getXIndex());
    163163        assertEquals(y, backwardsResult.getYIndex());
     
    179179                );
    180180
    181         TileXY tileIndex = source.latLonToTileXY(location.toCoordinate(), z);
     181        TileXY tileIndex = source.latLonToTileXY(CoordinateConversion.llToCoor(location), z);
    182182
    183183        assertTrue("X index: " + tileIndex.getXIndex() + " greater than tileXmax: " + source.getTileXMax(z) + " at zoom: " + z,
     
    213213
    214214    private LatLon getTileLatLon(TemplatedWMSTileSource source, int x, int y, int z) {
    215         return new LatLon(source.tileXYToLatLon(x, y, z));
     215        return CoordinateConversion.coorToLL(source.tileXYToLatLon(x, y, z));
    216216    }
    217217
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r12224 r12669  
    129129
    130130    private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) {
    131         LatLon ret = new LatLon(testSource.tileXYToLatLon(x, y, z));
     131        LatLon ret = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
    132132        assertTrue(ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));
    133133        int tileXmax = testSource.getTileXMax(z);
     
    303303
    304304    private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) {
    305         LatLon ll = new LatLon(source.tileXYToLatLon(x, y, z));
     305        LatLon ll = CoordinateConversion.coorToLL(source.tileXYToLatLon(x, y, z));
    306306        assertEquals("Latitude", expected.lat(), ll.lat(), 1e-05);
    307307        assertEquals("Longitude", expected.lon(), ll.lon(), 1e-05);
     
    314314    private void verifyMercatorTile(WMTSTileSource testSource, int x, int y, int z, int zoomOffset) {
    315315        TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
    316         LatLon result = new LatLon(testSource.tileXYToLatLon(x, y, z));
    317         LatLon expected = new LatLon(verifier.tileXYToLatLon(x, y, z + zoomOffset));
     316        LatLon result = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z));
     317        LatLon expected = CoordinateConversion.coorToLL(verifier.tileXYToLatLon(x, y, z + zoomOffset));
    318318        assertEquals("Longitude", LatLon.normalizeLon(expected.lon() - result.lon()), 0.0, 1e-04);
    319319        assertEquals("Latitude", expected.lat(), result.lat(), 1e-04);
Note: See TracChangeset for help on using the changeset viewer.