source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java@ 25045

Last change on this file since 25045 was 25045, checked in by pieren, 14 years ago

Move the grabber single instance from CadastrePlugin singleton to each WMSLayer instance to allow several municipalities grabbing in parallel.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
2package cadastre_fr;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7
8import javax.swing.JOptionPane;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.Bounds;
12import org.openstreetmap.josm.gui.MapView;
13import org.openstreetmap.josm.gui.PleaseWaitRunnable;
14
15public class DownloadWMSVectorImage extends PleaseWaitRunnable {
16
17 private WMSLayer wmsLayer;
18 private Bounds bounds;
19 private static String errorMessage;
20
21 public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds) {
22 super(tr("Downloading {0}", wmsLayer.getName()));
23
24 this.wmsLayer = wmsLayer;
25 this.bounds = bounds;
26 }
27
28 @Override
29 public void realRun() throws IOException {
30 progressMonitor.indeterminateSubTask(tr("Contacting WMS Server..."));
31 errorMessage = null;
32 try {
33 if (wmsLayer.grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
34 if (wmsLayer.getImages().isEmpty()) {
35 // first time we grab an image for this layer
36 if (CacheControl.cacheEnabled) {
37 if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) {
38 Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds());
39 //Main.map.mapView.repaint();
40 return;
41 }
42 }
43 if (wmsLayer.isRaster()) {
44 // set raster image commune bounding box based on current view (before adjustment)
45 JOptionPane.showMessageDialog(Main.parent,tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\""));
46 Main.main.removeLayer(wmsLayer);
47 wmsLayer = null;
48 return;
49 } else {
50 // set vectorized commune bounding box by opening the standard web window
51 wmsLayer.grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer);
52 }
53 }
54 // grab new images from wms server into active layer
55 wmsLayer.grab(bounds);
56 }
57 } catch (DuplicateLayerException e) {
58 // we tried to grab onto a duplicated layer (removed)
59 System.err.println("removed a duplicated layer");
60 } catch (WMSException e) {
61 errorMessage = e.getMessage();
62 wmsLayer.grabber.getWmsInterface().resetCookie();
63 }
64 }
65
66 @Override
67 protected void cancel() {
68 wmsLayer.grabber.getWmsInterface().cancel();
69 if (wmsLayer != null)
70 wmsLayer.grabThread.setCancelled(true);
71 }
72
73 @Override
74 protected void finish() {
75 }
76
77 public static void download(WMSLayer wmsLayer) {
78 MapView mv = Main.map.mapView;
79 Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
80
81 Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds));
82 if (errorMessage != null)
83 JOptionPane.showMessageDialog(Main.parent, errorMessage);
84 }
85}
Note: See TracBrowser for help on using the repository browser.