- double lat, lng;
- int zoom;
- double scale_x, scale_y;
- Point2D.Double coord_pt;
- Point2D.Double last_pt;
-
- Graphics2D g2d;
-
- private void setLocation(double new_lat, double new_lng) {
- int new_zoom = 15;
- lat = new_lat;
- lng = new_lng;
- zoom = new_zoom;
- scale_x = 256/360.0 * Math.pow(2, zoom);
- scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom);
- coord_pt = pt(lat, lng, new Point2D.Double(0,0));
- coord_pt.x = 320-coord_pt.x;
- coord_pt.y = 320-coord_pt.y;
- last_pt = null;
-
- try {
- File pngfile = new File(AltosPreferences.logdir(),
- FileCoord(lat, lng, zoom));
- System.out.printf("Trying file %s\n", pngfile);
- BufferedImage myPicture = ImageIO.read(pngfile);
- picLabel.setIcon(new ImageIcon( myPicture ));
- g2d = myPicture.createGraphics();
- } catch (Exception e) {
- throw new RuntimeException(e);
- };
- }
-
- private static double limit(double v, double lo, double hi) {
- if (v < lo)
- return lo;
- if (hi < v)
- return hi;
- return v;
- }
-
- private static String FileCoord(double lat, double lng, int zoom) {
- char chlat = lat < 0 ? 'S' : 'N';
- char chlng = lng < 0 ? 'E' : 'W';
- if (lat < 0) lat = -lat;
- if (lng < 0) lng = -lng;
- return String.format("map-%c%.3f,%c%.3f-%d.png",
- chlat, lat, chlng, lng, zoom);
- }
-
-
- // based on google js
- // http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js
- // search for fromLatLngToPoint and fromPointToLatLng
- private Point2D.Double pt(double lat, double lng) {
- return pt(lat, lng, coord_pt);
- }
-
- private Point2D.Double pt(double lat, double lng, Point2D.Double centre) {
- Point2D.Double res = new Point2D.Double();
- double e;
-
- res.x = centre.x + lng*scale_x;
- e = limit(Math.sin(Math.toRadians(lat)),-(1-1.0E-15),1-1.0E-15);
- res.y = centre.y + 0.5*Math.log((1+e)/(1-e))*-scale_y;
- return res;
- }
-
-