Changeset 29379 in osm


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

alpha version

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  
    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/");
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java

    r29377 r29379  
    11package iodb;
    22
    3 import java.awt.FlowLayout;
    4 import java.awt.GridLayout;
    5 import java.awt.Insets;
     3import java.awt.*;
    64import java.awt.event.ActionEvent;
    75import java.awt.event.ActionListener;
    86import java.awt.event.KeyEvent;
    97import java.util.*;
     8import java.util.List;
    109import javax.swing.*;
    1110import javax.swing.border.CompoundBorder;
    1211import javax.swing.border.EmptyBorder;
    1312import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.tools.GBC;
    1414import static org.openstreetmap.josm.tools.I18n.tr;
    1515
     
    3131        super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL);
    3232        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    33         setResizable(false);
     33//        setResizable(false);
    3434        this.offsets = offsets;
    3535
     
    4141   
    4242    private void prepareDialog() {
    43         Box dialog = new Box(BoxLayout.Y_AXIS);
    4443        updateButtonPanel();
    4544        final JCheckBox calibrationBox = new JCheckBox(tr("Calibration geometries"));
     
    6665        cancelButton.setAlignmentX(CENTER_ALIGNMENT);
    6766
     67        Box dialog = new Box(BoxLayout.Y_AXIS);
    6868        dialog.add(buttonPanel);
    6969        dialog.add(checkBoxPanel);
     
    9292            buttonPanel.add(button);
    9393        }
    94 //        buttonPanel.setMinimumSize(buttonPanel.getPreferredSize());
    9594        pack();
    9695    }
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java

    r29377 r29379  
    2424    public OffsetDialogButton( ImageryOffsetBase offset ) {
    2525        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));
    2928        setText("<html>"
    3029                + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m: "
     
    4140    }
    4241
    43 /*    @Override
     42    @Override
    4443    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    }
    4749
    4850    private double[] getLengthAndDirection( ImageryOffset offset ) {
    4951        ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
    5052        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]);
    5254    }
    5355
     
    6668                ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
    6769                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]);
    6971                length = ld[0];
    7072                direction = ld[1];
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java

    r29377 r29379  
    3535        StringBuilder sb = new StringBuilder();
    3636        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');
    4453        sb.append("Description: ").append(offset.getDescription());
     54       
    4555        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');
    4758            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');
    4960            sb.append("Reason: ").append(offset.getAbandonReason());
    5061        }
     
    6677    }
    6778
    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 direction
    76         return new double[] { length, direction };
    77     }
    78 
    7979    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";
    8190    }
    8291}
Note: See TracChangeset for help on using the changeset viewer.