| 1 | Index: WMSLayer.java
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- WMSLayer.java (revision 17300)
|
|---|
| 4 | +++ WMSLayer.java (working copy)
|
|---|
| 5 | @@ -34,12 +34,14 @@
|
|---|
| 6 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
|---|
| 7 | import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
|
|---|
| 8 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 9 | +import org.openstreetmap.josm.io.CacheFiles;
|
|---|
| 10 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 11 |
|
|---|
| 12 | /**
|
|---|
| 13 | * This is a layer that grabs the current screen from an WMS server. The data
|
|---|
| 14 | - * fetched this way is tiled and managerd to the disc to reduce server load.
|
|---|
| 15 | + * fetched this way is tiled and managed to the disc to reduce server load.
|
|---|
| 16 | */
|
|---|
| 17 | +@SuppressWarnings("serial")
|
|---|
| 18 | public class WMSLayer extends Layer {
|
|---|
| 19 | protected static final Icon icon =
|
|---|
| 20 | new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
|
|---|
| 21 | @@ -70,33 +72,39 @@
|
|---|
| 22 | mv = Main.map.mapView;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | - public WMSLayer(String name, String baseURL, String cookies) {
|
|---|
| 26 | - super(name);
|
|---|
| 27 | - alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel"));
|
|---|
| 28 | - background = true; /* set global background variable */
|
|---|
| 29 | - initializeImages();
|
|---|
| 30 | - this.baseURL = baseURL;
|
|---|
| 31 | - this.cookies = cookies;
|
|---|
| 32 | - WMSGrabber.getProjection(baseURL, true);
|
|---|
| 33 | - mv = Main.map.mapView;
|
|---|
| 34 | - resolution = mv.getDist100PixelText();
|
|---|
| 35 | - pixelPerDegree = getPPD();
|
|---|
| 36 | -
|
|---|
| 37 | + public WMSLayer(String name, String baseURL, String cookies) {
|
|---|
| 38 | + super(name);
|
|---|
| 39 | + alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel"));
|
|---|
| 40 | + background = true; /* set global background variable */
|
|---|
| 41 | + initializeImages();
|
|---|
| 42 | + this.baseURL = baseURL;
|
|---|
| 43 | + this.cookies = cookies;
|
|---|
| 44 | + WMSGrabber.getProjection(baseURL, true);
|
|---|
| 45 | + mv = Main.map.mapView;
|
|---|
| 46 | + resolution = "PixelPerDegree: " + Double.toString(getPPD()) + " (add #PPD= to layer name to restore)";
|
|---|
| 47 | + pixelPerDegree = getPPD();
|
|---|
| 48 | executor = Executors.newFixedThreadPool(3);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | - @Override
|
|---|
| 52 | - public void destroy() {
|
|---|
| 53 | - try {
|
|---|
| 54 | - executor.shutdown();
|
|---|
| 55 | - // Might not be initalized, so catch NullPointer as well
|
|---|
| 56 | - } catch(Exception x) {}
|
|---|
| 57 | - }
|
|---|
| 58 | + @Override
|
|---|
| 59 | + public void destroy() {
|
|---|
| 60 | + try {
|
|---|
| 61 | + executor.shutdown();
|
|---|
| 62 | + // Might not be initialized, so catch NullPointer as well
|
|---|
| 63 | + } catch(Exception x) {}
|
|---|
| 64 | + }
|
|---|
| 65 |
|
|---|
| 66 | - public double getPPD(){
|
|---|
| 67 | - ProjectionBounds bounds = mv.getProjectionBounds();
|
|---|
| 68 | - return mv.getWidth() / (bounds.max.east() - bounds.min.east());
|
|---|
| 69 | - }
|
|---|
| 70 | + public double getPPD(){
|
|---|
| 71 | + // quick hack to predefine the PixelDensity to reuse the cache
|
|---|
| 72 | + int codeIndex = getName().indexOf("#PPD=");
|
|---|
| 73 | + if (codeIndex != -1) {
|
|---|
| 74 | + double f = Double.valueOf(getName().substring(codeIndex+5));
|
|---|
| 75 | + return f;
|
|---|
| 76 | + }
|
|---|
| 77 | +
|
|---|
| 78 | + ProjectionBounds bounds = mv.getProjectionBounds();
|
|---|
| 79 | + return mv.getWidth() / (bounds.max.east() - bounds.min.east());
|
|---|
| 80 | + }
|
|---|
| 81 |
|
|---|
| 82 | public void initializeImages() {
|
|---|
| 83 | images = new GeorefImage[dax][day];
|
|---|
| 84 | @@ -200,23 +208,24 @@
|
|---|
| 85 | return getToolTipText();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | - @Override public Component[] getMenuEntries() {
|
|---|
| 89 | - return new Component[]{
|
|---|
| 90 | - new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
|
|---|
| 91 | - new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
|
|---|
| 92 | - new JSeparator(),
|
|---|
| 93 | - new JMenuItem(new LoadWmsAction()),
|
|---|
| 94 | - new JMenuItem(new SaveWmsAction()),
|
|---|
| 95 | - new JSeparator(),
|
|---|
| 96 | - startstop,
|
|---|
| 97 | - alphaChannel,
|
|---|
| 98 | - new JMenuItem(new changeResolutionAction()),
|
|---|
| 99 | - new JMenuItem(new reloadErrorTilesAction()),
|
|---|
| 100 | - new JMenuItem(new downloadAction()),
|
|---|
| 101 | - new JSeparator(),
|
|---|
| 102 | - new JMenuItem(new LayerListPopup.InfoAction(this))
|
|---|
| 103 | - };
|
|---|
| 104 | - }
|
|---|
| 105 | + @Override public Component[] getMenuEntries() {
|
|---|
| 106 | + return new Component[]{
|
|---|
| 107 | + new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
|
|---|
| 108 | + new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
|
|---|
| 109 | + new JSeparator(),
|
|---|
| 110 | + new JMenuItem(new LoadWmsAction()),
|
|---|
| 111 | + new JMenuItem(new SaveWmsAction()),
|
|---|
| 112 | + new JMenuItem(new BookmarkWmsAction()),
|
|---|
| 113 | + new JSeparator(),
|
|---|
| 114 | + startstop,
|
|---|
| 115 | + alphaChannel,
|
|---|
| 116 | + new JMenuItem(new changeResolutionAction()),
|
|---|
| 117 | + new JMenuItem(new reloadErrorTilesAction()),
|
|---|
| 118 | + new JMenuItem(new downloadAction()),
|
|---|
| 119 | + new JSeparator(),
|
|---|
| 120 | + new JMenuItem(new LayerListPopup.InfoAction(this))
|
|---|
| 121 | + };
|
|---|
| 122 | + }
|
|---|
| 123 |
|
|---|
| 124 | public GeorefImage findImage(EastNorth eastNorth) {
|
|---|
| 125 | for(int x = 0; x<dax; ++x) {
|
|---|
| 126 | @@ -250,13 +259,13 @@
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | public class reloadErrorTilesAction extends AbstractAction {
|
|---|
| 130 | - public reloadErrorTilesAction() {
|
|---|
| 131 | - super(tr("Reload erroneous tiles"));
|
|---|
| 132 | - }
|
|---|
| 133 | - public void actionPerformed(ActionEvent ev) {
|
|---|
| 134 | - // Delete small files, because they're probably blank tiles.
|
|---|
| 135 | - // See https://josm.openstreetmap.de/ticket/2307
|
|---|
| 136 | - WMSPlugin.cache.customCleanUp(WMSPlugin.cache.CLEAN_SMALL_FILES, 2048);
|
|---|
| 137 | + public reloadErrorTilesAction() {
|
|---|
| 138 | + super(tr("Reload erroneous tiles"));
|
|---|
| 139 | + }
|
|---|
| 140 | + public void actionPerformed(ActionEvent ev) {
|
|---|
| 141 | + // Delete small files, because they're probably blank tiles.
|
|---|
| 142 | + // See https://josm.openstreetmap.de/ticket/2307
|
|---|
| 143 | + WMSPlugin.cache.customCleanUp(CacheFiles.CLEAN_SMALL_FILES, 4096);
|
|---|
| 144 |
|
|---|
| 145 | for (int x = 0; x < dax; ++x) {
|
|---|
| 146 | for (int y = 0; y < day; ++y) {
|
|---|
| 147 | @@ -364,4 +373,35 @@
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | +
|
|---|
| 152 | + /**
|
|---|
| 153 | + * This action will add a WMS layer menu entry with the current WMS layer URL and name extended by the current resolution.
|
|---|
| 154 | + * When using the menu entry again, the WMS cache will be used properly.
|
|---|
| 155 | + *
|
|---|
| 156 | + * @author <alex@addismap.com>
|
|---|
| 157 | + */
|
|---|
| 158 | + public class BookmarkWmsAction extends AbstractAction {
|
|---|
| 159 | + public BookmarkWmsAction() {
|
|---|
| 160 | + super(tr("Set WMS Bookmark"));
|
|---|
| 161 | + }
|
|---|
| 162 | + public void actionPerformed(ActionEvent ev) {
|
|---|
| 163 | + int i = 0;
|
|---|
| 164 | + while (Main.pref.hasKey("wmsplugin.url."+i+".url")) {
|
|---|
| 165 | + i++;
|
|---|
| 166 | + }
|
|---|
| 167 | + String baseName;
|
|---|
| 168 | + // cut old parameter
|
|---|
| 169 | + int parameterIndex = getName().indexOf("#PPD=");
|
|---|
| 170 | + if (parameterIndex != -1) {
|
|---|
| 171 | + baseName = getName().substring(0,parameterIndex);
|
|---|
| 172 | + }
|
|---|
| 173 | + else {
|
|---|
| 174 | + baseName = getName();
|
|---|
| 175 | + }
|
|---|
| 176 | + Main.pref.put("wmsplugin.url."+ i +".url",baseURL );
|
|---|
| 177 | + Main.pref.put("wmsplugin.url."+String.valueOf(i)+".name", baseName + "#" + getPPD() );
|
|---|
| 178 | + WMSPlugin.refreshMenu();
|
|---|
| 179 | + }
|
|---|
| 180 | + }
|
|---|
| 181 | +
|
|---|
| 182 | }
|
|---|