source: osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java@ 10382

Last change on this file since 10382 was 10382, checked in by petrdlouhy, 16 years ago

Added automatic tiles downloading and Yahoo support.

File size: 1.3 KB
Line 
1package wmsplugin;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.event.ActionEvent;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.actions.JosmAction;
9import org.openstreetmap.josm.gui.MapView;
10import org.openstreetmap.josm.gui.layer.Layer;
11import org.openstreetmap.josm.data.Bounds;
12
13public class WMSDownloadAction extends JosmAction {
14
15 private WMSInfo info;
16
17 public WMSDownloadAction(WMSInfo info) {
18 super(info.name, "wmsmenu", tr("Download WMS tile from {0}",info.name), 0, 0, false);
19 this.info = info;
20 }
21
22 public void actionPerformed(ActionEvent e) {
23 System.out.println(info.url);
24
25 WMSLayer wmsLayer = getLayer(info);
26 MapView mv = Main.map.mapView;
27
28 Bounds b = new Bounds(
29 mv.getLatLon(0, mv.getHeight()),
30 mv.getLatLon(mv.getWidth(), 0));
31 double pixelPerDegree = mv.getWidth() / (b.max.lon() - b.min.lon());
32
33 wmsLayer.grab(b, pixelPerDegree);
34 }
35
36 public static WMSLayer getLayer(WMSInfo info) {
37 // simply check if we already have a layer created. if not, create; if yes, reuse.
38 for (Layer l : Main.main.map.mapView.getAllLayers()) {
39 if (l instanceof WMSLayer && l.name.equals(info.name)) {
40 return (WMSLayer) l;
41 }
42 }
43
44 // FIXME: move this to WMSPlugin/WMSInfo/preferences.
45 WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
46 Main.main.addLayer(wmsLayer);
47 return wmsLayer;
48 }
49};
50
Note: See TracBrowser for help on using the repository browser.