| 1 | package wmsplugin;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 |
|
|---|
| 7 | import org.openstreetmap.josm.Main;
|
|---|
| 8 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 9 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 10 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 11 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 12 |
|
|---|
| 13 | public 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 |
|
|---|