Ignore:
Timestamp:
2013-03-20T21:28:34+01:00 (13 years ago)
Author:
zverik
Message:

alpha version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java

    r29377 r29379  
    11package iodb;
    22
    3 import java.text.SimpleDateFormat;
    43import java.util.*;
    54import org.openstreetmap.josm.Main;
     
    4039    public static LatLon getLayerOffset( ImageryLayer layer, LatLon center ) {
    4140        Projection proj = Main.getProjection();
    42         EastNorth offsetCenter = proj.latlon2eastNorth(center);
     41        EastNorth offsetCenter = Main.map.mapView.getCenter();
    4342        EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy());
    4443        LatLon offsetLL = proj.eastNorth2latlon(centerOffset);
     
    7978        boolean isWMS = layer.getInfo().getImageryType().equals(ImageryInfo.ImageryType.WMS);
    8079
    81         System.out.println(url);
     80//        System.out.println(url);
    8281
    8382        // Remove protocol
     
    9493
    9594        // Parse query parameters into a sorted map
     95        final Set<String> removeWMSParams = new TreeSet<String>(Arrays.asList(new String[] {
     96            "srs", "width", "height", "bbox", "service", "request", "version", "format", "styles", "transparent"
     97        }));
    9698        Map<String, String> qparams = new TreeMap<String, String>();
    9799        String[] qparamsStr = query.length() > 1 ? query.substring(1).split("&") : new String[0];
     
    100102            kv[0] = kv[0].toLowerCase();
    101103            // WMS: if this is WMS, remove all parameters except map and layers
    102             if( isWMS && !(kv[0].equals("map") || kv[0].equals("layers")) )
     104            if( isWMS && removeWMSParams.contains(kv[0]) )
    103105                continue;
    104106            // TMS: skip parameters with variable values
     
    128130            url = url.substring(1);
    129131
    130         System.out.println("-> " + url + query);
     132//        System.out.println("-> " + url + query);
    131133        return url + query;
    132134    }
     
    166168    }
    167169
     170    public static double[] getLengthAndDirection( ImageryOffset offset ) {
     171        return getLengthAndDirection(offset, 0.0, 0.0);
     172    }
     173
     174    public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) {
     175        Projection proj = Main.getProjection();
     176        EastNorth pos = proj.latlon2eastNorth(offset.getPosition());
     177        LatLon correctedCenterLL = proj.eastNorth2latlon(pos.add(dx, dy));
     178        double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos());
     179        double direction = length < 1e-3 ? 0.0 : correctedCenterLL.heading(offset.getImageryPos());
     180        // todo: north vs south. Meanwhile, let's fix this dirty:
     181        direction = Math.PI - direction;
     182        if( direction < 0 )
     183            direction += Math.PI * 2;
     184        return new double[] {length, direction};
     185    }
     186
     187    public static String formatDistance( double d ) {
     188        if( d < 0.0095 ) return tr("{0,number,0} mm", d * 1000);
     189        if( d < 0.095 ) return tr("{0,number,0.0} cm", d * 100);
     190        if( d < 0.95) return tr("{0,number,0} cm", d * 100);
     191        if( d < 9.5 ) return tr("{0,number,0.0} m", d);
     192        if( d < 950 ) return tr("{0,number,0} m", d);
     193        if( d < 9500 ) return tr("{0,number,0.0} km", d / 1000);
     194        return tr("{0,number,0} km", d / 1000);
     195    }
     196
    168197    public static String getServerURL() {
    169198        return Main.pref.get("iodb.server.url", "http://offsets.textual.ru/");
Note: See TracChangeset for help on using the changeset viewer.