Changeset 6777 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2008-02-04T18:49:57+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 4 added
- 3 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/DownloadWMSTask.java
r6776 r6777 8 8 import org.openstreetmap.josm.actions.DownloadAction; 9 9 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 10 import org.openstreetmap.josm.gui.MapView; 10 11 import org.openstreetmap.josm.data.Bounds; 11 12 import org.openstreetmap.josm.data.coor.LatLon; … … 16 17 private WMSLayer wmsLayer; 17 18 private Bounds bounds; 19 private double pixelPerDegree; 18 20 19 public DownloadWMSTask(WMSLayer wmsLayer, Bounds bounds ) {21 public DownloadWMSTask(WMSLayer wmsLayer, Bounds bounds, double pixelPerDegree) { 20 22 super(tr("Downloading " + wmsLayer.name)); 21 23 22 24 this.wmsLayer = wmsLayer; 23 25 this.bounds = bounds; 26 this.pixelPerDegree = pixelPerDegree; 24 27 } 25 28 26 29 @Override public void realRun() throws IOException { 27 30 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting WMS Server...")); 28 wmsLayer.grab( 29 bounds.min.lat(), bounds.min.lon(), 30 bounds.max.lat(), bounds.max.lon()); 31 wmsLayer.grab(bounds, pixelPerDegree); 31 32 } 32 33 … … 35 36 36 37 public static void download(String name, String wmsurl, 37 double minlat, double minlon, double maxlat, double maxlon) {38 Bounds b, double pixelPerDegree) { 38 39 WMSLayer wmsLayer = null; 39 40 … … 45 46 } 46 47 48 // FIXME: move this to WMSPlugin/WMSInfo/preferences. 47 49 if (wmsLayer == null) { 48 50 if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){ 49 //then we use the OSGBLayer 50 wmsLayer= new OSGBLayer(name, wmsurl); 51 wmsLayer = new WMSLayer(name, new OSGBGrabber(wmsurl)); 51 52 } else { 52 wmsLayer = new WMSLayer(name, wmsurl);53 wmsLayer = new WMSLayer(name, new WMSGrabber(wmsurl)); 53 54 } 54 55 Main.main.addLayer(wmsLayer); 55 56 } 56 57 57 Main.worker.execute(new DownloadWMSTask(wmsLayer, 58 new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon)))); 58 Main.worker.execute(new DownloadWMSTask(wmsLayer, b, pixelPerDegree)); 59 } 60 61 public static void download(String name, String wmsurl) { 62 MapView mv = Main.map.mapView; 63 64 Bounds b = new Bounds( 65 mv.getLatLon(0, mv.getHeight()), 66 mv.getLatLon(mv.getWidth(), 0)); 67 68 download(name, wmsurl, b, mv.getWidth() / (b.max.lon() - b.min.lon())); 59 69 } 60 70 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Map_Rectifier_WMSmenuAction.java
r6776 r6777 7 7 import org.openstreetmap.josm.actions.JosmAction; 8 8 import org.openstreetmap.josm.gui.MapView; 9 10 9 11 10 public class Map_Rectifier_WMSmenuAction extends JosmAction { … … 18 17 public Map_Rectifier_WMSmenuAction() { 19 18 super("Rectified Image ...", "OLmarker", "Download Rectified Image from Metacarta's Map Rectifer WMS", 0, 0, false); 20 21 22 19 } 23 20 24 21 public void actionPerformed(ActionEvent e) { 22 String newid = JOptionPane.showInputDialog(Main.parent, "Metacarta Map Rectifier image id"); 25 23 26 //String newid;27 String newURL = "";28 String newid = "";24 if (newid != null && !newid.equals("")) { 25 String newURL = "http://labs.metacarta.com/rectifier/wms.cgi?id="+newid+ 26 "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png"; 29 27 30 newid = JOptionPane.showInputDialog(Main.parent, "Metacarta Map Rectifier image id "); 31 // System.out.println("newid= " +newid); 32 if (newid != null){ 33 34 35 if (newid.compareTo("") != 0) 36 { 37 newURL = "http://labs.metacarta.com/rectifier/wms.cgi?id="+newid+ 38 "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png"; 39 40 41 //System.out.println(newURL); 42 43 MapView mv = Main.map.mapView; 44 45 DownloadWMSTask.download("rectifier id="+newid, newURL, 46 mv.getLatLon(0, mv.getHeight()).lat(), 47 mv.getLatLon(0, mv.getHeight()).lon(), 48 mv.getLatLon(mv.getWidth(), 0).lat(), 49 mv.getLatLon(mv.getWidth(), 0).lon()); 50 51 52 } 28 DownloadWMSTask.download("rectifier id="+newid, newURL); 53 29 } 54 //else do nuffink55 56 30 } 57 58 59 60 31 } 61 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java
r6775 r6777 19 19 MouseListener, MouseMotionListener{ 20 20 21 WMSImage selectedImage;21 GeorefImage selectedImage; 22 22 boolean mouseDown; 23 23 EastNorth prevEastNorth; … … 46 46 47 47 for(Layer layer:Main.map.mapView.getAllLayers()) { 48 if (layer instanceof WMSLayer) {48 if (layer.visible && layer instanceof WMSLayer) { 49 49 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 50 50 selectedImage = ((WMSLayer)layer).findImage(prevEastNorth); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java
r6776 r6777 21 21 MapView mv = Main.map.mapView; 22 22 23 DownloadWMSTask.download(info.name, info.url, 24 mv.getLatLon(0, mv.getHeight()).lat(), 25 mv.getLatLon(0, mv.getHeight()).lon(), 26 mv.getLatLon(mv.getWidth(), 0).lat(), 27 mv.getLatLon(mv.getWidth(), 0).lon()); 23 DownloadWMSTask.download(info.name, info.url); 28 24 } 29 25 }; -
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.