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