Ignore:
Timestamp:
2011-12-14T11:35:33+01:00 (13 years ago)
Author:
larry0ua
Message:

'PicLayer - changed marker icon to make it more visible; #5451; #7124 - first stage'

Location:
applications/editors/josm/plugins/piclayer
Files:
5 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer/build.xml

    r27220 r27231  
    2222-->
    2323<project name="PicLayer" default="dist" basedir=".">
    24     <property name="commit.message" value="PicLayer - changed marker icon to make it more visible"/>
     24    <property name="commit.message" value="PicLayer - changed marker icon to make it more visible; #5451; #7124 - first stage"/>
    2525    <property name="plugin.main.version" value="4549"/>
    2626    <!--
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java

    r27191 r27231  
    2626import java.io.File;
    2727import java.io.IOException;
     28import java.util.ArrayList;
     29import java.util.List;
    2830
    2931import javax.imageio.ImageIO;
     
    3638import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    3739import org.openstreetmap.josm.gui.layer.Layer;
     40import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    3841import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromFile;
     42import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromKML;
     43import org.openstreetmap.josm.plugins.piclayer.layer.kml.KMLGroundOverlay;
     44import org.openstreetmap.josm.plugins.piclayer.layer.kml.KMLReader;
    3945
    4046/**
     
    5157    private class ImageFileFilter extends FileFilter {
    5258
     59        private String[] supportedExtensions;
     60
     61        public ImageFileFilter() {
     62            List<String> extensions = new ArrayList<String>();
     63            extensions.add("zip");
     64            extensions.add("kml");
     65            for (String ext : ImageIO.getReaderFormatNames())
     66                extensions.add(ext);
     67            supportedExtensions = extensions.toArray(new String[0]);
     68        }
     69
    5370        @Override
    5471        public boolean accept(File f) {
     
    5673                return true;
    5774
    58             int dotIdx = f.getName().lastIndexOf('.');
    59             if (dotIdx == -1) return false;
    60             String fileExtension = f.getName().substring(dotIdx+1);
    61             String[] supportedExtensions = ImageIO.getReaderFormatNames();
     75            String fileExtension = PicLayerFromFile.getFileExtension(f);
    6276
    63             if ("zip".equalsIgnoreCase(fileExtension)) return true;
    6477            // Unfortunately, getReaderFormatNames does not always return ALL extensions in
    6578            // both lower and upper case, so we can not do a search in the array
     
    7588        @Override
    7689        public String getDescription() {
    77             return tr("Supported image files + *.zip");
     90            return tr("Supported image files, *.zip, *.kml");
    7891        }
    7992
    80     }
    81 
    82     private class AllFilesFilter extends FileFilter {
    83         @Override
    84         public String getDescription() {
    85             return tr("All Files");
    86         }
    87 
    88         @Override
    89         public boolean accept(File f) {
    90             return true;
    91         }
    9293    }
    9394
     
    119120            // The next layers we load will be placed one after the other after this first layer
    120121            int newLayerPos = Main.map.mapView.getAllLayers().size();
    121             for(Layer l : Main.map.mapView.getLayersOfType(PicLayerFromFile.class)) {
     122            for(Layer l : Main.map.mapView.getLayersOfType(PicLayerAbstract.class)) {
    122123                int pos = Main.map.mapView.getLayerPos(l);
    123124                if (pos < newLayerPos) newLayerPos = pos;
     
    127128                // TODO: we need a progress bar here, it can take quite some time
    128129
    129                 // Create layer from file
    130                 PicLayerFromFile layer = new PicLayerFromFile( file );
    131                 // Add layer only if successfully initialized
    132                 try {
    133                     layer.initialize();
    134                 }
    135                 catch (IOException e) {
    136                     // Failed
    137                     System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() );
    138                     JOptionPane.showMessageDialog(null, e.getMessage() );
    139                     return;
    140                 }
    141130                Main.pref.put(m_lastdirprefname, file.getParent());
    142131
    143                 Main.main.addLayer( layer );
    144                 Main.map.mapView.moveLayer(layer, newLayerPos++);
     132                // Create layer from file
     133                if ("kml".equalsIgnoreCase(PicLayerFromFile.getFileExtension(file))) {
     134                    KMLReader kml = new KMLReader(file);
     135                    kml.process();
     136                    JOptionPane.showMessageDialog(null, tr("KML calibration is in beta stage and may produce incorrectly calibrated layers!\nPlease use http://josm.openstreetmap.de/ticket/5451 to upload your KMLs that were calibrated incorrectly."));
     137                    for (KMLGroundOverlay overlay : kml.getGroundOverlays()) {
     138                        //TODO: zoom to whole picture, not only the last
     139                        addNewLayerFromKML(file, overlay, newLayerPos);
     140                    }
    145141
    146                 if ( fc.getSelectedFiles().length == 1 && Main.pref.getInteger("piclayer.zoom-on-load", 1) != 0 ) {
    147                     // if we are loading a single picture file, zoom on it, so that the user can see something
    148                     BoundingXYVisitor v = new BoundingXYVisitor();
    149                     layer.visitBoundingBox(v);
    150                     Main.map.mapView.recalculateCenterScale(v);
    151                 }
     142                } else {
     143                addNewLayerFromFile(file, newLayerPos, fc.getSelectedFiles().length == 1);
    152144
    153145            }
     
    155147    }
    156148}
     149
     150    private void addNewLayerFromFile(File file, int newLayerPos, boolean isZoomToLayer) {
     151        try {
     152            PicLayerFromFile layer = new PicLayerFromFile( file );
     153            layer.initialize();
     154
     155            placeLayer(layer, newLayerPos, isZoomToLayer);
     156        }
     157        catch (IOException e) {
     158            // Failed
     159            System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() );
     160            JOptionPane.showMessageDialog(null, e.getMessage() );
     161        }
     162    }
     163
     164    private void placeLayer(PicLayerAbstract layer, int newLayerPos, boolean isZoomToLayer) throws IOException {
     165        // Add layer only if successfully initialized
     166
     167        Main.main.addLayer( layer );
     168        Main.map.mapView.moveLayer(layer, newLayerPos++);
     169
     170        if ( isZoomToLayer && Main.pref.getInteger("piclayer.zoom-on-load", 1) != 0 ) {
     171            // if we are loading a single picture file, zoom on it, so that the user can see something
     172            BoundingXYVisitor v = new BoundingXYVisitor();
     173            layer.visitBoundingBox(v);
     174            Main.map.mapView.recalculateCenterScale(v);
     175        }
     176    }
     177    private void addNewLayerFromKML(File root, KMLGroundOverlay overlay, int newLayerPos) {
     178        try {
     179            PicLayerFromKML layer = new PicLayerFromKML(root, overlay);
     180            layer.initialize();
     181
     182            placeLayer(layer, newLayerPos, true);
     183        } catch (IOException e) {
     184            // Failed
     185            System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() );
     186            JOptionPane.showMessageDialog(null, e.getMessage() );
     187        }
     188    }
     189}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java

    r27220 r27231  
    6565    // Counter - just for naming of layers
    6666    private static int imageCounter = 0;
     67
    6768    // This is the main image to be displayed
    68     private Image image = null;
    69     private static Image pinImage;
     69    protected Image image = null;
     70    // Tiles of pin images
     71    private static Image pinTiledImage;
     72
    7073    // Initial position of the image in the real world
    71     private EastNorth initialImagePosition;
     74    protected EastNorth initialImagePosition;
     75
    7276    // Position of the image in the real world
    73     private EastNorth imagePosition;
     77    protected EastNorth imagePosition;
     78
    7479    // The scale that was set on the map during image creation
    75     private double initialImageScale = 1.0;
     80    protected double initialImageScale = 1.0;
     81
    7682    // Layer icon
    7783    private Icon layerIcon = null;
     
    8389    }
    8490
    85     private PictureTransform transformer;
     91    protected PictureTransform transformer;
    8692
    8793    public PictureTransform getTransformer() {
     
    8995    }
    9096
    91     // Keys for saving in Properties
    92     private final String INITIAL_POS_X = "INITIAL_POS_X";
    93     private final String INITIAL_POS_Y = "INITIAL_POS_y";
    94     private final String POSITION_X = "POSITION_X";
    95     private final String POSITION_Y = "POSITION_Y";
    96     private final String ANGLE = "ANGLE";
    97     private final String INITIAL_SCALE = "INITIAL_SCALE";
    98     private final String SCALEX = "SCALEX";
    99     private final String SCALEY = "SCALEY";
    100     private final String SHEARX = "SHEARX";
    101     private final String SHEARY = "SHEARY";
    102 
    103     private final String MATRIXm00 = "M00";
    104     private final String MATRIXm01 = "M01";
    105     private final String MATRIXm10 = "M10";
    106     private final String MATRIXm11 = "M11";
    107     private final String MATRIXm02 = "M02";
    108     private final String MATRIXm12 = "M12";
     97    // Keys for loading from old/new Properties
     98    private static final String INITIAL_POS_X = "INITIAL_POS_X";
     99    private static final String INITIAL_POS_Y = "INITIAL_POS_y";
     100    private static final String POSITION_X = "POSITION_X";
     101    private static final String POSITION_Y = "POSITION_Y";
     102    private static final String ANGLE = "ANGLE";
     103    private static final String INITIAL_SCALE = "INITIAL_SCALE";
     104    private static final String SCALEX = "SCALEX";
     105    private static final String SCALEY = "SCALEY";
     106    private static final String SHEARX = "SHEARX";
     107    private static final String SHEARY = "SHEARY";
     108    // new properties
     109    private static final String MATRIXm00 = "M00";
     110    private static final String MATRIXm01 = "M01";
     111    private static final String MATRIXm10 = "M10";
     112    private static final String MATRIXm11 = "M11";
     113    private static final String MATRIXm02 = "M02";
     114    private static final String MATRIXm12 = "M12";
     115
     116    // pin images properties - tile anchors, width and offset
     117    // TODO: load these from properties file in images folder...
     118    private static final int pinAnchorX = 31;
     119    private static final int pinAnchorY = 31;
     120    private static final int[] pinTileOffsetX = {74, 0, 74, 0};
     121    private static final int[] pinTileOffsetY = {0, 74, 74, 0};
     122    private static final int pinWidth = 64;
     123    private static final int pinHeight = 64;
    109124
    110125    /**
     
    120135        layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));
    121136
    122         if (pinImage == null) {
     137        if (pinTiledImage == null) {
    123138            // allow system to load the image and use it in future
    124             pinImage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/marker.png"))).getImage();
     139            pinTiledImage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/v6_64.png"))).getImage();
    125140        }
    126141    }
     
    256271                tr.concatenate(transformer.getTransform());
    257272
    258                 for (Point2D p : transformer.getOriginPoints()) {
    259                    Point2D trP = tr.transform(p, null);
     273                for (int i = 0; i < transformer.getOriginPoints().size(); i++) {
     274                   Point2D trP = tr.transform(transformer.getOriginPoints().get(i), null);
    260275                   int x = (int)trP.getX(), y = (int)trP.getY();
    261                    //gPoints.drawOval(x-2, y-2, 5, 5);
    262                    gPoints.drawImage(pinImage, x-15, y-15, null);
     276
     277                   int dstx = x-pinAnchorX;
     278                   int dsty = y-pinAnchorY;
     279                   gPoints.drawImage(pinTiledImage, dstx, dsty, dstx+pinWidth, dsty+pinHeight, pinTileOffsetX[i], pinTileOffsetY[i], pinTileOffsetX[i]+pinWidth, pinTileOffsetY[i]+pinHeight, null);
    263280                }
    264281            }
     
    276293     * next (a couple of kilometers).
    277294     */
    278     private double getMetersPerEasting(EastNorth en) {
     295    protected double getMetersPerEasting(EastNorth en) {
    279296        /* Natural scale in east/north units per pixel.
    280297         * This means, the projection should be able to handle
Note: See TracChangeset for help on using the changeset viewer.