1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.Bounds;
|
---|
7 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
8 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Implement Mercator Projection code, coded after documentation
|
---|
12 | * from wikipedia.
|
---|
13 | *
|
---|
14 | * The center of the mercator projection is always the 0 grad
|
---|
15 | * coordinate.
|
---|
16 | *
|
---|
17 | * See also USGS Bulletin 1532
|
---|
18 | * (http://egsc.usgs.gov/isb/pubs/factsheets/fs08799.html)
|
---|
19 | *
|
---|
20 | * @author imi
|
---|
21 | */
|
---|
22 | public class Mercator implements Projection {
|
---|
23 |
|
---|
24 | public EastNorth latlon2eastNorth(LatLon p) {
|
---|
25 | return new EastNorth(
|
---|
26 | p.lon()*Math.PI/180,
|
---|
27 | Math.log(Math.tan(Math.PI/4+p.lat()*Math.PI/360)));
|
---|
28 | }
|
---|
29 |
|
---|
30 | public LatLon eastNorth2latlon(EastNorth p) {
|
---|
31 | return new LatLon(
|
---|
32 | Math.atan(Math.sinh(p.north()))*180/Math.PI,
|
---|
33 | p.east()*180/Math.PI);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override public String toString() {
|
---|
37 | return tr("Mercator");
|
---|
38 | }
|
---|
39 |
|
---|
40 | public String toCode() {
|
---|
41 | return "EPSG:3857"; /* initially they used 3785 but that has been superseded, see http://www.epsg-registry.org/ */
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public int hashCode() {
|
---|
46 | return getClass().getName().hashCode(); // we have no variables
|
---|
47 | }
|
---|
48 |
|
---|
49 | public String getCacheDirectoryName() {
|
---|
50 | return "mercator";
|
---|
51 | }
|
---|
52 |
|
---|
53 | public Bounds getWorldBoundsLatLon()
|
---|
54 | {
|
---|
55 | return new Bounds(
|
---|
56 | new LatLon(-85.05112877980659, -180.0),
|
---|
57 | new LatLon(85.05112877980659, 180.0));
|
---|
58 | }
|
---|
59 |
|
---|
60 | public double getDefaultZoomInPPD() {
|
---|
61 | // This will set the scale bar to about 100 km
|
---|
62 | return 0.000158;
|
---|
63 | }
|
---|
64 | }
|
---|