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