Changeset 27231 in osm for applications
- Timestamp:
- 2011-12-14T11:35:33+01:00 (13 years ago)
- 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 22 22 --> 23 23 <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"/> 25 25 <property name="plugin.main.version" value="4549"/> 26 26 <!-- -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/newlayer/NewLayerFromFileAction.java
r27191 r27231 26 26 import java.io.File; 27 27 import java.io.IOException; 28 import java.util.ArrayList; 29 import java.util.List; 28 30 29 31 import javax.imageio.ImageIO; … … 36 38 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 37 39 import org.openstreetmap.josm.gui.layer.Layer; 40 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 38 41 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromFile; 42 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromKML; 43 import org.openstreetmap.josm.plugins.piclayer.layer.kml.KMLGroundOverlay; 44 import org.openstreetmap.josm.plugins.piclayer.layer.kml.KMLReader; 39 45 40 46 /** … … 51 57 private class ImageFileFilter extends FileFilter { 52 58 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 53 70 @Override 54 71 public boolean accept(File f) { … … 56 73 return true; 57 74 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); 62 76 63 if ("zip".equalsIgnoreCase(fileExtension)) return true;64 77 // Unfortunately, getReaderFormatNames does not always return ALL extensions in 65 78 // both lower and upper case, so we can not do a search in the array … … 75 88 @Override 76 89 public String getDescription() { 77 return tr("Supported image files + *.zip");90 return tr("Supported image files, *.zip, *.kml"); 78 91 } 79 92 80 }81 82 private class AllFilesFilter extends FileFilter {83 @Override84 public String getDescription() {85 return tr("All Files");86 }87 88 @Override89 public boolean accept(File f) {90 return true;91 }92 93 } 93 94 … … 119 120 // The next layers we load will be placed one after the other after this first layer 120 121 int newLayerPos = Main.map.mapView.getAllLayers().size(); 121 for(Layer l : Main.map.mapView.getLayersOfType(PicLayer FromFile.class)) {122 for(Layer l : Main.map.mapView.getLayersOfType(PicLayerAbstract.class)) { 122 123 int pos = Main.map.mapView.getLayerPos(l); 123 124 if (pos < newLayerPos) newLayerPos = pos; … … 127 128 // TODO: we need a progress bar here, it can take quite some time 128 129 129 // Create layer from file130 PicLayerFromFile layer = new PicLayerFromFile( file );131 // Add layer only if successfully initialized132 try {133 layer.initialize();134 }135 catch (IOException e) {136 // Failed137 System.out.println( "NewLayerFromFileAction::actionPerformed - " + e.getMessage() );138 JOptionPane.showMessageDialog(null, e.getMessage() );139 return;140 }141 130 Main.pref.put(m_lastdirprefname, file.getParent()); 142 131 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 } 145 141 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); 152 144 153 145 } … … 155 147 } 156 148 } 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 65 65 // Counter - just for naming of layers 66 66 private static int imageCounter = 0; 67 67 68 // 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 70 73 // Initial position of the image in the real world 71 private EastNorth initialImagePosition; 74 protected EastNorth initialImagePosition; 75 72 76 // Position of the image in the real world 73 private EastNorth imagePosition; 77 protected EastNorth imagePosition; 78 74 79 // The scale that was set on the map during image creation 75 private double initialImageScale = 1.0; 80 protected double initialImageScale = 1.0; 81 76 82 // Layer icon 77 83 private Icon layerIcon = null; … … 83 89 } 84 90 85 pr ivatePictureTransform transformer;91 protected PictureTransform transformer; 86 92 87 93 public PictureTransform getTransformer() { … … 89 95 } 90 96 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; 109 124 110 125 /** … … 120 135 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png"))); 121 136 122 if (pin Image == null) {137 if (pinTiledImage == null) { 123 138 // allow system to load the image and use it in future 124 pin Image = 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(); 125 140 } 126 141 } … … 256 271 tr.concatenate(transformer.getTransform()); 257 272 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); 260 275 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); 263 280 } 264 281 } … … 276 293 * next (a couple of kilometers). 277 294 */ 278 pr ivatedouble getMetersPerEasting(EastNorth en) {295 protected double getMetersPerEasting(EastNorth en) { 279 296 /* Natural scale in east/north units per pixel. 280 297 * This means, the projection should be able to handle
Note:
See TracChangeset
for help on using the changeset viewer.