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

Last change on this file since 16929 was 16581, checked in by jttt, 16 years ago

Made work with JOSM new ProgressMonitor

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1package cadastre_fr;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.io.IOException;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.data.Bounds;
9import org.openstreetmap.josm.gui.MapView;
10import org.openstreetmap.josm.gui.PleaseWaitRunnable;
11
12public class DownloadWMSTask extends PleaseWaitRunnable {
13
14 private WMSLayer wmsLayer;
15
16 private Bounds bounds;
17
18 private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
19
20 public DownloadWMSTask(WMSLayer wmsLayer, Bounds bounds) {
21 super(tr("Downloading {0}", wmsLayer.name));
22
23 this.wmsLayer = wmsLayer;
24 this.bounds = bounds;
25 }
26
27 @Override
28 public void realRun() throws IOException {
29 progressMonitor.indeterminateSubTask(tr("Contacting WMS Server..."));
30 try {
31 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
32 if (wmsLayer.images.isEmpty()) {
33 // first time we grab an image for this layer
34 if (CacheControl.cacheEnabled) {
35 if (wmsLayer.getCacheControl().loadCacheIfExist()) {
36 Main.map.mapView.repaint();
37 return;
38 }
39 }
40 if (wmsLayer.isRaster())
41 // set raster image commune bounding box based on current view (before adjustment)
42 wmsLayer.setRasterBounds(bounds);
43 else
44 // set vectorized commune bounding box by opening the standard web window
45 wmsLayer.setCommuneBBox( grabber.getWmsInterface().retrieveCommuneBBox());
46 }
47 // grab new images from wms server into active layer
48 wmsLayer.grab(grabber, bounds);
49 }
50 } catch (DuplicateLayerException e) {
51 // we tried to grab onto a duplicated layer (removed)
52 System.err.println("removed a duplicated layer");
53 }
54 }
55
56 @Override
57 protected void cancel() {
58 grabber.getWmsInterface().cancel();
59 }
60
61 @Override
62 protected void finish() {
63 }
64
65 public static void download(WMSLayer wmsLayer) {
66 MapView mv = Main.map.mapView;
67 Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
68
69 Main.worker.execute(new DownloadWMSTask(wmsLayer, bounds));
70
71 }
72}
Note: See TracBrowser for help on using the repository browser.