| 1 | package cadastre_fr;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.util.ArrayList;
|
|---|
| 7 |
|
|---|
| 8 | import javax.swing.JOptionPane;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.Main;
|
|---|
| 11 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 12 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 13 |
|
|---|
| 14 | public class WMSDownloadAction extends JosmAction {
|
|---|
| 15 |
|
|---|
| 16 | private static final long serialVersionUID = 1L;
|
|---|
| 17 |
|
|---|
| 18 | public WMSDownloadAction(String layerName) {
|
|---|
| 19 | super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | public void actionPerformed(ActionEvent e) {
|
|---|
| 23 | DownloadWMSTask.download(getLayer());
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | public static WMSLayer getLayer() {
|
|---|
| 27 | // check if we already have a layer created. if not, create; if yes, reuse.
|
|---|
| 28 | if (Main.map != null) {
|
|---|
| 29 | Layer activeLayer = Main.map.mapView.getActiveLayer();
|
|---|
| 30 | if (activeLayer instanceof WMSLayer)
|
|---|
| 31 | return (WMSLayer) activeLayer;
|
|---|
| 32 | ArrayList<WMSLayer> existingWMSlayers = new ArrayList<WMSLayer>();
|
|---|
| 33 | for (Layer l : Main.map.mapView.getAllLayers()) {
|
|---|
| 34 | if (l instanceof WMSLayer) {
|
|---|
| 35 | existingWMSlayers.add((WMSLayer)l);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | if (existingWMSlayers.size() == 1)
|
|---|
| 39 | return existingWMSlayers.get(0);
|
|---|
| 40 | if (existingWMSlayers.size() == 0)
|
|---|
| 41 | return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
|
|---|
| 42 | JOptionPane.showMessageDialog(Main.parent,
|
|---|
| 43 | tr("More than one WMS layer present\nSelect one of them first, then retry"));
|
|---|
| 44 | }
|
|---|
| 45 | return null;
|
|---|
| 46 | }
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|