Changeset 29379 in osm for applications
- Timestamp:
- 2013-03-20T21:28:34+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db
- Files:
-
- 5 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/"); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29377 r29379 1 1 package iodb; 2 2 3 import java.awt.FlowLayout; 4 import java.awt.GridLayout; 5 import java.awt.Insets; 3 import java.awt.*; 6 4 import java.awt.event.ActionEvent; 7 5 import java.awt.event.ActionListener; 8 6 import java.awt.event.KeyEvent; 9 7 import java.util.*; 8 import java.util.List; 10 9 import javax.swing.*; 11 10 import javax.swing.border.CompoundBorder; 12 11 import javax.swing.border.EmptyBorder; 13 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.tools.GBC; 14 14 import static org.openstreetmap.josm.tools.I18n.tr; 15 15 … … 31 31 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL); 32 32 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 33 setResizable(false);33 // setResizable(false); 34 34 this.offsets = offsets; 35 35 … … 41 41 42 42 private void prepareDialog() { 43 Box dialog = new Box(BoxLayout.Y_AXIS);44 43 updateButtonPanel(); 45 44 final JCheckBox calibrationBox = new JCheckBox(tr("Calibration geometries")); … … 66 65 cancelButton.setAlignmentX(CENTER_ALIGNMENT); 67 66 67 Box dialog = new Box(BoxLayout.Y_AXIS); 68 68 dialog.add(buttonPanel); 69 69 dialog.add(checkBoxPanel); … … 92 92 buttonPanel.add(button); 93 93 } 94 // buttonPanel.setMinimumSize(buttonPanel.getPreferredSize());95 94 pack(); 96 95 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29377 r29379 24 24 public OffsetDialogButton( ImageryOffsetBase offset ) { 25 25 super(); 26 // todo: fix layout 27 setMinimumSize(new Dimension(500, 80)); 28 setMaximumSize(new Dimension(500, 140)); 26 setMinimumSize(new Dimension(500, 10)); 27 setMaximumSize(new Dimension(500, 150)); 29 28 setText("<html>" 30 29 + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m: " … … 41 40 } 42 41 43 /*@Override42 @Override 44 43 public Dimension getPreferredSize() { 45 return new Dimension(500, super.getPreferredSize().height); 46 }*/ 44 Dimension size = super.getPreferredSize(); 45 size.width = 500; 46 size.height = 70; 47 return size; 48 } 47 49 48 50 private double[] getLengthAndDirection( ImageryOffset offset ) { 49 51 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 50 52 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()}; 51 return OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);53 return ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 52 54 } 53 55 … … 66 68 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 67 69 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] { layer.getDx(), layer.getDy() }; 68 double[] ld = OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);70 double[] ld = ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 69 71 length = ld[0]; 70 72 direction = ld[1]; -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
r29377 r29379 35 35 StringBuilder sb = new StringBuilder(); 36 36 if( offset instanceof ImageryOffset ) { 37 double[] ld = getLengthAndDirection((ImageryOffset)offset); 38 sb.append(tr("An imagery offset of {0} m to {1}", ld[0], explainDirection(ld[1]))).append('\n'); 39 sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery()); 40 } else 41 sb.append(tr("A calibration {0}", getGeometryType((CalibrationObject)offset))); 42 sb.append("\n\nCreated by ").append(offset.getAuthor()); 43 sb.append(" on ").append(DATE_FORMAT.format(offset.getDate())).append("\n"); 37 double[] ld = ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset); 38 sb.append(ld[0] < 1e-3 ? tr("An imagery offset of 0 mm") : tr("An imagery offset of {0} to {1}", 39 ImageryOffsetTools.formatDistance(ld[0]), explainDirection(ld[1]))).append('\n'); 40 sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery()).append('\n'); 41 } else { 42 sb.append(tr("A calibration {0}", getGeometryType((CalibrationObject)offset))).append('\n'); 43 } 44 45 double dist = ImageryOffsetTools.getMapCenter().greatCircleDistance(offset.getPosition()); 46 double heading = dist < 1 ? 0.0 : ImageryOffsetTools.getMapCenter().heading(offset.getPosition()); 47 sb.append(dist < 10 ? tr("Determined right here") : tr("Determined at a point {0} to the {1}", 48 ImageryOffsetTools.formatDistance(dist), explainDirection(heading))); 49 50 sb.append('\n').append('\n'); 51 sb.append("Created by ").append(offset.getAuthor()); 52 sb.append(" on ").append(DATE_FORMAT.format(offset.getDate())).append('\n'); 44 53 sb.append("Description: ").append(offset.getDescription()); 54 45 55 if( offset.isDeprecated() ) { 46 sb.append("\n\nThis geometry was marked obsolete\n"); 56 sb.append('\n').append('\n'); 57 sb.append("This geometry was marked obsolete").append('\n'); 47 58 sb.append("by ").append(offset.getAbandonAuthor()); 48 sb.append(" on ").append(DATE_FORMAT.format(offset.getAbandonDate())).append( "\n");59 sb.append(" on ").append(DATE_FORMAT.format(offset.getAbandonDate())).append('\n'); 49 60 sb.append("Reason: ").append(offset.getAbandonReason()); 50 61 } … … 66 77 } 67 78 68 public static double[] getLengthAndDirection( ImageryOffset offset ) {69 return getLengthAndDirection(offset, 0.0, 0.0);70 }71 72 public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) {73 double length = 0.0;74 double direction = 0.0;75 // todo: calculate length and angular direction76 return new double[] { length, direction };77 }78 79 79 public static String explainDirection( double dir ) { 80 return "nowhere"; // todo 80 dir = dir * 8 / Math.PI; 81 if( dir < 1 || dir >= 15 ) return tr("north"); 82 if( dir < 3 ) return tr("northeast"); 83 if( dir < 5 ) return tr("east"); 84 if( dir < 7 ) return tr("southeast"); 85 if( dir < 9 ) return tr("south"); 86 if( dir < 11 ) return tr("southwest"); 87 if( dir < 13 ) return tr("west"); 88 if( dir < 15 ) return tr("northwest"); 89 return "nowhere"; 81 90 } 82 91 }
Note:
See TracChangeset
for help on using the changeset viewer.