Changeset 29379 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
- Timestamp:
- 2013-03-20T21:28:34+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r29377 r29379 1 1 package iodb; 2 2 3 import java.text.SimpleDateFormat;4 3 import java.util.*; 5 4 import org.openstreetmap.josm.Main; … … 40 39 public static LatLon getLayerOffset( ImageryLayer layer, LatLon center ) { 41 40 Projection proj = Main.getProjection(); 42 EastNorth offsetCenter = proj.latlon2eastNorth(center);41 EastNorth offsetCenter = Main.map.mapView.getCenter(); 43 42 EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy()); 44 43 LatLon offsetLL = proj.eastNorth2latlon(centerOffset); … … 79 78 boolean isWMS = layer.getInfo().getImageryType().equals(ImageryInfo.ImageryType.WMS); 80 79 81 System.out.println(url); 80 // System.out.println(url); 82 81 83 82 // Remove protocol … … 94 93 95 94 // 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 })); 96 98 Map<String, String> qparams = new TreeMap<String, String>(); 97 99 String[] qparamsStr = query.length() > 1 ? query.substring(1).split("&") : new String[0]; … … 100 102 kv[0] = kv[0].toLowerCase(); 101 103 // 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]) ) 103 105 continue; 104 106 // TMS: skip parameters with variable values … … 128 130 url = url.substring(1); 129 131 130 System.out.println("-> " + url + query); 132 // System.out.println("-> " + url + query); 131 133 return url + query; 132 134 } … … 166 168 } 167 169 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 168 197 public static String getServerURL() { 169 198 return Main.pref.get("iodb.server.url", "http://offsets.textual.ru/");
Note:
See TracChangeset
for help on using the changeset viewer.
