Changeset 6777 in osm for applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
- Timestamp:
- 2008-02-04T18:49:57+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r6775 r6777 29 29 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 30 30 import org.openstreetmap.josm.data.projection.Projection; 31 import org.openstreetmap.josm.data.Bounds; 31 32 import org.openstreetmap.josm.gui.MapView; 32 33 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 42 43 public class WMSLayer extends Layer { 43 44 44 protected static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png"))); 45 protected final ArrayList<WMSImage> wmsImages; 46 protected final String url; 47 protected final int serializeFormatVersion = 1; 48 45 protected static final Icon icon = 46 new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png"))); 47 48 protected ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(); 49 protected Grabber grabber; 50 protected final int serializeFormatVersion = 2; 51 49 52 public WMSLayer() { 50 super("Blank Layer"); 51 wmsImages = new ArrayList<WMSImage>(); 52 url = ""; 53 } 54 public WMSLayer(String name, String url) { 53 this("Blank Layer", null); 54 } 55 56 public WMSLayer(String name, Grabber grabber) { 55 57 super(name); 56 // to calculate the world dimension, we assume that the projection does 57 // not have problems with translating longitude to a correct scale. 58 // Next to that, the projection must be linear dependend on the lat/lon 59 // unprojected scale. 60 if (Projection.MAX_LON != 180) 61 throw new IllegalArgumentException(tr 62 ("Wrong longitude transformation for tile manager. "+ 63 "Can't operate on {0}",Main.proj)); 64 65 this.url = url; 66 //wmsImage = new WMSImage(url); 67 wmsImages = new ArrayList<WMSImage>(); 68 } 69 70 public void grab() throws IOException 71 { 72 MapView mv = Main.map.mapView; 73 WMSImage wmsImage = new WMSImage(url); 74 wmsImage.grab(mv); 75 wmsImages.add(wmsImage); 76 } 77 78 public void grab(double minlat,double minlon,double maxlat,double maxlon) 79 throws IOException 80 { 81 MapView mv = Main.map.mapView; 82 WMSImage wmsImage = new WMSImage(url); 83 wmsImage.grab(mv,minlat,minlon,maxlat,maxlon); 84 wmsImages.add(wmsImage); 58 this.grabber = grabber; 59 } 60 61 public void grab(Bounds b, double pixelPerDegree) throws IOException { 62 if (grabber == null) return; 63 images.add(grabber.grab(b, Main.main.proj, pixelPerDegree)); 64 Main.map.mapView.repaint(); 85 65 } 86 66 … … 90 70 91 71 @Override public String getToolTipText() { 92 return tr("WMS layer ({0}), {1} tile(s) loaded", name, wmsImages.size());72 return tr("WMS layer ({0}), {1} tile(s) loaded", name, images.size()); 93 73 } 94 74 … … 101 81 102 82 @Override public void paint(Graphics g, final MapView mv) { 103 for(WMSImage wmsImage : wmsImages) { 104 wmsImage.paint(g,mv); 105 } 83 for (GeorefImage img : images) img.paint(g, mv); 106 84 } 107 85 108 86 @Override public void visitBoundingBox(BoundingXYVisitor v) { 109 // doesn't have a bounding box 87 for (GeorefImage img : images) { 88 v.visit(img.min); 89 v.visit(img.max); 90 } 110 91 } 111 92 … … 124 105 } 125 106 126 public WMSImage findImage(EastNorth eastNorth) 127 { 128 for(WMSImage wmsImage : wmsImages) { 129 if (wmsImage.contains(eastNorth)) { 130 return wmsImage; 107 public GeorefImage findImage(EastNorth eastNorth) { 108 // Iterate in reverse, so we return the image which is painted last. 109 // (i.e. the topmost one) 110 for (int i = images.size() - 1; i >= 0; i--) { 111 if (images.get(i).contains(eastNorth)) { 112 return images.get(i); 131 113 } 132 114 } … … 134 116 } 135 117 136 //to enable the removal of the images when the layer is removed.137 public void destroy() {138 wmsImages.clear();139 }140 141 118 public class SaveWmsAction extends AbstractAction { 142 119 public SaveWmsAction() { … … 149 126 ObjectOutputStream oos = new ObjectOutputStream(fos); 150 127 oos.writeInt(serializeFormatVersion); 151 oos.writeInt( wmsImages.size());152 for ( WMSImage w : wmsImages) {153 oos.writeObject( w);128 oos.writeInt(images.size()); 129 for (GeorefImage img : images) { 130 oos.writeObject(img); 154 131 } 155 132 oos.close(); … … 181 158 int numImg = ois.readInt(); 182 159 for (int i=0; i< numImg; i++) { 183 WMSImage img = (WMSImage) ois.readObject();184 wmsImages.add(img);160 GeorefImage img = (GeorefImage) ois.readObject(); 161 images.add(img); 185 162 } 186 163 ois.close();
Note:
See TracChangeset
for help on using the changeset viewer.