Ignore:
Timestamp:
2009-07-03T12:33:32+02:00 (15 years ago)
Author:
stoecker
Message:

Large rework in projection handling - now allows only switching and more specific projections
TODO:

  • allow subprojections (i.e. settings for projections)
  • setup preferences for subprojections
  • better support of the new projection depending world bounds (how to handle valid data outside of world)
  • do not allow to zoom out of the world - zoom should stop when whole world is displayed
  • fix Lambert and SwissGrid to handle new OutOfWorld style and subprojections
  • fix new UTM projection
  • handle layers with fixed projection on projection change
  • allow easier projection switching (e.g. in menu)

NOTE:
This checkin very likely will cause problems. Please report or fix them. Older plugins may have trouble. The SVN plugins
have been fixed but may have problems nevertheless. This is a BIG change, but will make JOSMs internal structure much cleaner
and reduce lots of projection related problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r1689 r1722  
    5555        return Double.parseDouble(map.get("m"+key));
    5656    }
     57
     58    static public int getZoom(Bounds b)
     59    {
     60        // convert to mercator (for calculation of zoom only)
     61        double latMin = Math.log(Math.tan(Math.PI/4.0+b.min.lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
     62        double latMax = Math.log(Math.tan(Math.PI/4.0+b.max.lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
     63        double size = Math.max(Math.abs(latMax-latMin), Math.abs(b.max.lon()-b.min.lon()));
     64        int zoom = 0;
     65        while (zoom <= 20) {
     66            if (size >= 180)
     67                break;
     68            size *= 2;
     69            zoom++;
     70        }
     71        return zoom;
     72    }
     73
     74    static public String getURL(Bounds b)
     75    {
     76        return getURL(b.center(), getZoom(b));
     77    }
     78
     79    static public String getURL(LatLon pos, int zoom)
     80    {
     81        // Truncate lat and lon to something more sensible
     82        int decimals = (int) Math.pow(10, (zoom / 3));
     83        double lat = (Math.round(pos.lat() * decimals))/decimals;
     84        double lon = (Math.round(pos.lon() * decimals))/decimals;
     85        return new String("http://www.openstreetmap.org/?lat="+lat+"&lon="+lon+"&zoom="+zoom);
     86    }
    5787}
Note: See TracChangeset for help on using the changeset viewer.