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 | // public WMSDownloadAction(String layerName) {
|
---|
18 | // super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);
|
---|
19 | // }
|
---|
20 | //
|
---|
21 | // public void actionPerformed(ActionEvent e) {
|
---|
22 | // DownloadWMSVectorImage.download(getLayer());
|
---|
23 | // }
|
---|
24 |
|
---|
25 | public static WMSLayer getLayer() {
|
---|
26 | // check if we already have a layer created. if not, create; if yes, reuse.
|
---|
27 | ArrayList<WMSLayer> existingWMSlayers = new ArrayList<>();
|
---|
28 | if (Main.map != null) {
|
---|
29 | Layer activeLayer = Main.getLayerManager().getActiveLayer();
|
---|
30 | if (activeLayer instanceof WMSLayer)
|
---|
31 | return (WMSLayer) activeLayer;
|
---|
32 | for (Layer l : Main.getLayerManager().getLayers()) {
|
---|
33 | if (l instanceof WMSLayer) {
|
---|
34 | existingWMSlayers.add((WMSLayer)l);
|
---|
35 | }
|
---|
36 | }
|
---|
37 | if (existingWMSlayers.size() == 1)
|
---|
38 | return existingWMSlayers.get(0);
|
---|
39 | if (existingWMSlayers.size() == 0)
|
---|
40 | return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
|
---|
41 | if (Main.pref.getBoolean("cadastrewms.autoFirstLayer", false)) {
|
---|
42 | return existingWMSlayers.get(0);
|
---|
43 | } else {
|
---|
44 | JOptionPane.showMessageDialog(Main.parent,
|
---|
45 | tr("More than one WMS layer present\nSelect one of them first, then retry"));
|
---|
46 | }
|
---|
47 | } else {
|
---|
48 | return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
|
---|
49 | }
|
---|
50 | return null;
|
---|
51 | }
|
---|
52 | };
|
---|
53 |
|
---|