Changeset 32759 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2016-08-02T22:18:57+02:00 (9 years ago)
Author:
glebius
Message:

Restore proper operation of ScanexTileSource, broken by donvip somewhere
around r31573. The revision made ScanexTileSource equal to TMSTileSource,
not overriding anything, while overriding Y to Latitude calculation and
vice versa is crucial in this layer.

My fix has two remarkable notes:

  • The internal private methods of ScanexTileSource don't use getTileSize(). The size of 256 (28) is hardcoded in to the formulae, and right now I'm too lazy and stupid to get back to understanding them and rewriting them in a pretty way, so that 28 isn't hardcoded in there.
  • latLonToXY() and xyToLatLon() are implemented, but I don't see any real usage of them. They aren't tested. Are they important at all?
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java

    r32602 r32759  
    22package org.openstreetmap.gui.jmapviewer.tilesources;
    33
     4import java.awt.Point;
    45import java.util.Random;
    56
     7import org.openstreetmap.gui.jmapviewer.Coordinate;
    68import org.openstreetmap.gui.jmapviewer.OsmMercator;
     9import org.openstreetmap.gui.jmapviewer.TileXY;
     10import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    711
    812/**
     
    2125    private static final int DEFAULT_MAXZOOM = 14;
    2226    private static final String API_KEY = "4018C5A9AECAD8868ED5DEB2E41D09F7";
    23 
    24     // Latitude to Y and back calculations.
    25 
    26     /** eccentricity of Earth's ellipsoid */
    27     private static double E = 0.0818191908426;
    2827
    2928    private enum ScanexLayer {
     
    8988    }
    9089
     90    // Latitude to Y and back calculations.
     91    private static double RADIUS_E = 6378137;   /* radius of Earth at equator,
     92m */
     93    private static double EQUATOR = 40075016.68557849; /* equator length, m */
     94    private static double E = 0.0818191908426;  /* eccentricity of Earth's ellipsoid */
     95
     96    @Override
     97    public Point latLonToXY(double lat, double lon, int zoom) {
     98        return new Point(
     99                (int) osmMercator.lonToX(lon, zoom),
     100                (int) latToTileY(lat, zoom)
     101                );
     102    }
     103
     104    @Override
     105    public ICoordinate xyToLatLon(int x, int y, int zoom) {
     106        return new Coordinate(
     107                tileYToLat((double) y, zoom),
     108                osmMercator.xToLon(x, zoom)
     109                );
     110    }
     111
     112    @Override
     113    public TileXY latLonToTileXY(double lat, double lon, int zoom) {
     114        return new TileXY(
     115                osmMercator.lonToX(lon, zoom) / getTileSize(),
     116                latToTileY(lat, zoom)
     117                );
     118    }
     119
     120    @Override
     121    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
     122        return new Coordinate(
     123                tileYToLat((double) y, zoom),
     124                osmMercator.xToLon(x * getTileSize(), zoom)
     125                );
     126    }
     127
     128    private double latToTileY(double lat, int zoom) {
     129        double tmp = Math.tan(Math.PI/4 * (1 + lat/90));
     130        double pow = Math.pow(Math.tan(Math.PI/4 + Math.asin(E * Math.sin(Math.toRadians(lat)))/2), E);
     131
     132        return (EQUATOR/2 - (RADIUS_E * Math.log(tmp/pow))) * Math.pow(2.0, zoom) / EQUATOR;
     133    }
     134
    91135    /*
    92136     * To solve inverse formula latitude = f(y) we use
Note: See TracChangeset for help on using the changeset viewer.