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

Last change on this file since 32212 was 32212, checked in by donvip, 9 years ago

see #josm12878 - update plugin to work with new cadastre version

  • Property svn:eol-style set to native
File size: 27.4 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.awt.GridBagLayout;
7import java.io.BufferedReader;
8import java.io.IOException;
9import java.io.InputStreamReader;
10import java.io.OutputStream;
11import java.net.CookieHandler;
12import java.net.HttpURLConnection;
13import java.net.MalformedURLException;
14import java.net.URISyntaxException;
15import java.net.URL;
16import java.nio.charset.StandardCharsets;
17import java.util.ArrayList;
18import java.util.Date;
19import java.util.HashMap;
20import java.util.List;
21
22import javax.swing.JComboBox;
23import javax.swing.JDialog;
24import javax.swing.JOptionPane;
25import javax.swing.JPanel;
26
27import org.openstreetmap.josm.Main;
28import org.openstreetmap.josm.data.coor.EastNorth;
29import org.openstreetmap.josm.data.validation.util.Entities;
30import org.openstreetmap.josm.gui.layer.Layer;
31import org.openstreetmap.josm.tools.GBC;
32
33public class CadastreInterface {
34 public boolean downloadCanceled;
35 public HttpURLConnection urlConn;
36
37 private String cookie;
38 private String interfaceRef;
39 private String lastWMSLayerName;
40 private URL searchFormURL;
41 private List<String> listOfCommunes = new ArrayList<>();
42 private List<String> listOfTA = new ArrayList<>();
43 static class PlanImage {
44 String name;
45 String ref;
46 PlanImage(String name, String ref) {
47 this.name = name;
48 this.ref = ref;
49 }
50 }
51 private List<PlanImage> listOfFeuilles = new ArrayList<>();
52 private long cookieTimestamp;
53
54 static final String BASE_URL = "http://www.cadastre.gouv.fr";
55 static final String C_IMAGE_FORMAT = "Cette commune est au format ";
56 static final String C_COMMUNE_LIST_START = "<select name=\"codeCommune\"";
57 static final String C_COMMUNE_LIST_END = "</select>";
58 static final String C_OPTION_LIST_START = "<option value=\"";
59 static final String C_OPTION_LIST_END = "</option>";
60 static final String C_BBOX_COMMUN_START = "new GeoBox(";
61 static final String C_BBOX_COMMUN_END = ")";
62
63 static final String C_INTERFACE_VECTOR = "afficherCarteCommune.do";
64 static final String C_INTERFACE_RASTER_TA = "afficherCarteTa.do";
65 static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do";
66 static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteFeuille.do?f=";
67 static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?f=";
68 static final String C_IMAGE_NAME_START = ">Feuille ";
69 static final String C_TA_IMAGE_NAME_START = "Tableau d'assemblage <strong>";
70
71 static final long COOKIE_EXPIRATION = 30 * 60 * 1000L; // 30 minutes expressed in milliseconds
72
73 static final int RETRIES_GET_COOKIE = 10; // 10 times every 3 seconds means 30 seconds trying to get a cookie
74
75 public boolean retrieveInterface(WMSLayer wmsLayer) throws DuplicateLayerException, WMSException {
76 if (wmsLayer.getName().isEmpty())
77 return false;
78 boolean isCookieExpired = isCookieExpired();
79 if (wmsLayer.getName().equals(lastWMSLayerName) && !isCookieExpired)
80 return true;
81 if (!wmsLayer.getName().equals(lastWMSLayerName))
82 interfaceRef = null;
83 // open the session with the French Cadastre web front end
84 downloadCanceled = false;
85 try {
86 if (cookie == null || isCookieExpired) {
87 getCookie();
88 interfaceRef = null;
89 }
90 if (cookie == null)
91 throw new WMSException(tr("Cannot open a new client session.\nServer in maintenance or temporary overloaded."));
92 if (interfaceRef == null) {
93 getInterface(wmsLayer);
94 this.lastWMSLayerName = wmsLayer.getName();
95 }
96 openInterface();
97 } catch (IOException e) {
98 Main.error(e);
99 JOptionPane.showMessageDialog(Main.parent,
100 tr("Town/city {0} not found or not available\n" +
101 "or action canceled", wmsLayer.getLocation()));
102 return false;
103 }
104 return true;
105 }
106
107 /**
108 *
109 * @return true if a cookie is delivered by WMS and false is WMS is not opening a client session
110 * (too many clients or in maintenance)
111 * @throws IOException
112 */
113 private void getCookie() throws IOException {
114 boolean success = false;
115 int retries = RETRIES_GET_COOKIE;
116 try {
117 searchFormURL = new URL(BASE_URL + "/scpc/accueil.do");
118 while (!success && retries > 0) {
119 urlConn = (HttpURLConnection)searchFormURL.openConnection();
120 urlConn.setRequestProperty("Connection", "close");
121 urlConn.setRequestMethod("GET");
122 urlConn.connect();
123 if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
124 Main.info("GET "+searchFormURL);
125 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8));
126 while(in.readLine() != null) {
127 // read the buffer otherwise we sent POST too early
128 }
129 success = true;
130 // See https://bugs.openjdk.java.net/browse/JDK-8036017
131 // When a cookie handler is setup, "Set-Cookie" header returns empty values
132 CookieHandler cookieHandler = CookieHandler.getDefault();
133 if (cookieHandler != null) {
134 if (handleCookie(cookieHandler.get(searchFormURL.toURI(), new HashMap<String,List<String>>()).get("Cookie").get(0))) {
135 break;
136 }
137 } else {
138 String headerName;
139 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) {
140 if ("Set-Cookie".equals(headerName) && handleCookie(urlConn.getHeaderField(i))) {
141 break;
142 }
143 }
144 }
145 } else {
146 Main.warn("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times");
147 CadastrePlugin.safeSleep(3000);
148 retries --;
149 }
150 }
151 } catch (MalformedURLException | URISyntaxException e) {
152 throw new IOException("Illegal url.", e);
153 }
154 }
155
156 private boolean handleCookie(String pCookie) {
157 cookie = pCookie;
158 if (cookie == null || cookie.isEmpty()) {
159 Main.warn("received empty cookie");
160 cookie = null;
161 } else {
162 int index = cookie.indexOf(';');
163 if (index > -1) {
164 cookie = cookie.substring(0, index);
165 }
166 cookieTimestamp = new Date().getTime();
167 Main.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp));
168 }
169 return cookie != null;
170 }
171
172 public void resetCookie() {
173 lastWMSLayerName = null;
174 cookie = null;
175 }
176
177 public boolean isCookieExpired() {
178 long now = new Date().getTime();
179 if ((now - cookieTimestamp) > COOKIE_EXPIRATION) {
180 Main.info("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")");
181 return true;
182 }
183 return false;
184 }
185
186 public void resetInterfaceRefIfNewLayer(String newWMSLayerName) {
187 if (!newWMSLayerName.equals(lastWMSLayerName)) {
188 interfaceRef = null;
189 cookie = null; // new since WMS server requires that we come back to the main form
190 }
191 }
192
193 public void setCookie() {
194 this.urlConn.setRequestProperty("Cookie", this.cookie);
195 }
196
197 public void setCookie(HttpURLConnection urlConn) {
198 urlConn.setRequestProperty("Cookie", this.cookie);
199 }
200
201 private void getInterface(WMSLayer wmsLayer) throws IOException, DuplicateLayerException {
202 // first attempt : search for given name without codeCommune
203 interfaceRef = postForm(wmsLayer, "");
204 // second attempt either from known codeCommune (e.g. from cache) or from ComboBox
205 if (interfaceRef == null) {
206 if (!wmsLayer.getCodeCommune().isEmpty()) {
207 // codeCommune is already known (from previous request or from cache on disk)
208 interfaceRef = postForm(wmsLayer, wmsLayer.getCodeCommune());
209 } else {
210 if (listOfCommunes.size() > 1) {
211 // commune unknown, prompt the list of communes from server and try with codeCommune
212 String selected = selectMunicipalityDialog();
213 if (selected != null) {
214 String newCodeCommune = selected.substring(1, selected.indexOf('>') - 2);
215 String newLocation = selected.substring(selected.indexOf('>') + 1, selected.lastIndexOf(" - "));
216 wmsLayer.setCodeCommune(newCodeCommune);
217 wmsLayer.setLocation(newLocation);
218 Main.pref.put("cadastrewms.codeCommune", newCodeCommune);
219 Main.pref.put("cadastrewms.location", newLocation);
220 }
221 checkLayerDuplicates(wmsLayer);
222 interfaceRef = postForm(wmsLayer, wmsLayer.getCodeCommune());
223 }
224 if (listOfCommunes.size() == 1 && wmsLayer.isRaster()) {
225 // commune known but raster format. Select "Feuille" (non-georeferenced image) from list.
226 int res = selectFeuilleDialog();
227 if (res != -1) {
228 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name);
229 checkLayerDuplicates(wmsLayer);
230 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
231 }
232 }
233 }
234 }
235
236 if (interfaceRef == null)
237 throw new IOException("Town/city " + wmsLayer.getLocation() + " not found.");
238 }
239
240 private void openInterface() throws IOException {
241 try {
242 // finally, open the interface on server side giving access to the wms server
243 URL interfaceURL = new URL(BASE_URL + "/scpc/"+interfaceRef);
244 urlConn = (HttpURLConnection)interfaceURL.openConnection();
245 urlConn.setRequestMethod("GET");
246 setCookie();
247 urlConn.connect();
248 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
249 throw new IOException("Cannot open Cadastre interface. GET response:"+urlConn.getResponseCode());
250 }
251 Main.info("GET "+interfaceURL);
252 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8));
253 // read the buffer otherwise we sent POST too early
254 StringBuilder lines = new StringBuilder();
255 String ln;
256 while ((ln = in.readLine()) != null) {
257 if (Main.isDebugEnabled()) {
258 lines.append(ln);
259 }
260 }
261 if (Main.isDebugEnabled()) {
262 Main.debug(lines.toString());
263 }
264 } catch (MalformedURLException e) {
265 throw (IOException) new IOException(
266 "CadastreGrabber: Illegal url.").initCause(e);
267 }
268 }
269
270 /**
271 * Post the form with the commune name and check the returned answer which is embedded
272 * in HTTP XML packets. This function doesn't use an XML parser yet but that would be a good idea
273 * for the next releases.
274 * Two possibilities :
275 * - either the commune name matches and we receive an URL starting with "afficherCarteCommune.do" or
276 * - we don't receive a single answer but a list of possible values. This answer looks like:
277 * <select name="codeCommune" class="long erreur" id="codeCommune">
278 * <option value="">Choisir</option>
279 * <option value="50061" >COLMARS - 04370</option>
280 * <option value="QK066" >COLMAR - 68000</option>
281 * </select>
282 * The returned string is the interface name used in further requests, e.g. "afficherCarteCommune.do?c=QP224"
283 * where QP224 is the code commune known by the WMS (or "afficherCarteTa.do?c=..." for raster images).
284 *
285 * @param location
286 * @param codeCommune
287 * @return retURL url to available code commune in the cadastre; "" if not found
288 * @throws IOException
289 */
290 private String postForm(WMSLayer wmsLayer, String codeCommune) throws IOException {
291 try {
292 listOfCommunes.clear();
293 listOfTA.clear();
294 // send a POST request with a city/town/village name
295 String content = "numerovoie=";
296 content += "&indiceRepetition=";
297 content += "&nomvoie=";
298 content += "&lieuDit=";
299 if (codeCommune.isEmpty()) {
300 content += "&ville=" + java.net.URLEncoder.encode(wmsLayer.getLocation(), "UTF-8");
301 content += "&codePostal=";
302 } else {
303 content += "&codeCommune=" + codeCommune;
304 }
305 content += "&codeDepartement=";
306 content += wmsLayer.getDepartement();
307 content += "&nbResultatParPage=10";
308 content += "&x=0&y=0";
309 searchFormURL = new URL(BASE_URL + "/scpc/rechercherPlan.do");
310 urlConn = (HttpURLConnection)searchFormURL.openConnection();
311 urlConn.setRequestMethod("POST");
312 urlConn.setDoOutput(true);
313 urlConn.setDoInput(true);
314 setCookie();
315 try (OutputStream wr = urlConn.getOutputStream()) {
316 wr.write(content.getBytes(StandardCharsets.UTF_8));
317 Main.info("POST "+content);
318 wr.flush();
319 }
320 String ln;
321 StringBuilder sb = new StringBuilder();
322 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8))) {
323 while ((ln = rd.readLine()) != null) {
324 sb.append(ln);
325 }
326 }
327 String lines = sb.toString();
328 urlConn.disconnect();
329 if (lines != null) {
330 if (lines.indexOf(C_IMAGE_FORMAT) != -1) {
331 int i = lines.indexOf(C_IMAGE_FORMAT);
332 int j = lines.indexOf('.', i);
333 wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), j)));
334 }
335 if (!wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_VECTOR) != -1) { // "afficherCarteCommune.do"
336 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269";
337 lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR),lines.length());
338 lines = lines.substring(0, lines.indexOf('\''));
339 lines = Entities.unescape(lines);
340 Main.info("interface ref.:"+lines);
341 return lines;
342 } else if (wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_RASTER_TA) != -1) { // "afficherCarteTa.do"
343 // list of values parsed in listOfFeuilles (list all non-georeferenced images)
344 lines = getFeuillesList();
345 if (!downloadCanceled) {
346 parseFeuillesList(lines);
347 if (!listOfFeuilles.isEmpty()) {
348 int res = selectFeuilleDialog();
349 if (res != -1) {
350 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name);
351 checkLayerDuplicates(wmsLayer);
352 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
353 wmsLayer.setCodeCommune(listOfFeuilles.get(res).ref);
354 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref);
355 lines = Entities.unescape(lines);
356 Main.info("interface ref.:"+lines);
357 return lines;
358 }
359 }
360 }
361 return null;
362 } else if (lines.indexOf(C_COMMUNE_LIST_START) != -1 && lines.indexOf(C_COMMUNE_LIST_END) != -1) {
363 // list of values parsed in listOfCommunes
364 int i = lines.indexOf(C_COMMUNE_LIST_START);
365 int j = lines.indexOf(C_COMMUNE_LIST_END, i);
366 parseCommuneList(lines.substring(i, j));
367 }
368 }
369 } catch (MalformedURLException e) {
370 throw (IOException) new IOException("Illegal url.").initCause(e);
371 } catch (DuplicateLayerException e){
372 Main.error(e);
373 }
374 return null;
375 }
376
377 private void parseCommuneList(String input) {
378 if (input.indexOf(C_OPTION_LIST_START) != -1) {
379 while (input.indexOf("<option value=\"") != -1) {
380 int i = input.indexOf(C_OPTION_LIST_START);
381 int j = input.indexOf(C_OPTION_LIST_END, i+C_OPTION_LIST_START.length());
382 int k = input.indexOf('"', i+C_OPTION_LIST_START.length());
383 if (j != -1 && k > (i + C_OPTION_LIST_START.length())) {
384 String lov = input.substring(i+C_OPTION_LIST_START.length()-1, j);
385 if (lov.indexOf('>') != -1) {
386 Main.info("parse "+lov);
387 listOfCommunes.add(lov);
388 } else
389 Main.error("unable to parse commune string:"+lov);
390 }
391 input = input.substring(j+C_OPTION_LIST_END.length());
392 }
393 }
394 }
395
396 private String getFeuillesList() {
397 // get all images in one html page
398 String ln = null;
399 StringBuilder lines = new StringBuilder();
400 HttpURLConnection urlConn2 = null;
401 try {
402 URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000");
403 urlConn2 = (HttpURLConnection)getAllImagesURL.openConnection();
404 setCookie(urlConn2);
405 urlConn2.connect();
406 Main.info("GET "+getAllImagesURL);
407 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream(), StandardCharsets.UTF_8))) {
408 while ((ln = rd.readLine()) != null) {
409 lines.append(ln);
410 }
411 }
412 urlConn2.disconnect();
413 } catch (IOException e) {
414 listOfFeuilles.clear();
415 Main.error(e);
416 }
417 return lines.toString();
418 }
419
420 private void parseFeuillesList(String input) {
421 listOfFeuilles.clear();
422 // get "Tableau d'assemblage"
423 String inputTA = input;
424 if (Main.pref.getBoolean("cadastrewms.useTA", false)) {
425 while (inputTA.indexOf(C_TA_IMAGE_LINK_START) != -1) {
426 inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length());
427 String refTA = inputTA.substring(0, inputTA.indexOf('\''));
428 String nameTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_NAME_START) + C_TA_IMAGE_NAME_START.length());
429 nameTA = nameTA.substring(0, nameTA.indexOf('<'));
430 listOfFeuilles.add(new PlanImage(nameTA, refTA));
431 }
432 }
433 // get "Feuilles"
434 while (input.indexOf(C_IMAGE_LINK_START) != -1) {
435 input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length());
436 String refFeuille = input.substring(0, input.indexOf('\''));
437 String nameFeuille = input.substring(
438 input.indexOf(C_IMAGE_NAME_START)+C_IMAGE_NAME_START.length(),
439 input.indexOf(" -"));
440 listOfFeuilles.add(new PlanImage(nameFeuille, refFeuille));
441 }
442 }
443
444 private String selectMunicipalityDialog() {
445 JPanel p = new JPanel(new GridBagLayout());
446 String[] communeList = new String[listOfCommunes.size() + 1];
447 communeList[0] = tr("Choose from...");
448 for (int i = 0; i < listOfCommunes.size(); i++) {
449 communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1);
450 }
451 JComboBox<String> inputCommuneList = new JComboBox<>(communeList);
452 p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
453 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
454 // this below is a temporary workaround to fix the "always on top" issue
455 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune"));
456 CadastrePlugin.prepareDialog(dialog);
457 dialog.setVisible(true);
458 // till here
459 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
460 return null;
461 return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1);
462 }
463
464 private int selectFeuilleDialog() {
465 JPanel p = new JPanel(new GridBagLayout());
466 List<String> imageNames = new ArrayList<>();
467 for (PlanImage src : listOfFeuilles) {
468 imageNames.add(src.name);
469 }
470 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{}));
471 p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
472 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
473 // this below is a temporary workaround to fix the "always on top" issue
474 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
475 CadastrePlugin.prepareDialog(dialog);
476 dialog.setVisible(true);
477 // till here
478 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
479 return -1;
480 return inputFeuilleList.getSelectedIndex();
481 }
482
483 private static String buildRasterFeuilleInterfaceRef(String codeCommune) {
484 return C_INTERFACE_RASTER_FEUILLE + "?f=" + codeCommune;
485 }
486
487 /**
488 * Retrieve the bounding box size in pixels of the whole commune (point 0,0 at top, left corner)
489 * and store it in given wmsLayer
490 * In case of raster image, we also check in the same http request if the image is already georeferenced
491 * and store the result in the wmsLayer as well.
492 * @param wmsLayer the WMSLayer where the commune data and images are stored
493 * @throws IOException
494 */
495 public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException {
496 if (interfaceRef == null)
497 return;
498 // send GET opening normally the small window with the commune overview
499 String content = BASE_URL + "/scpc/" + interfaceRef;
500 content += "&dontSaveLastForward&keepVolatileSession=";
501 searchFormURL = new URL(content);
502 urlConn = (HttpURLConnection)searchFormURL.openConnection();
503 urlConn.setRequestMethod("GET");
504 setCookie();
505 urlConn.connect();
506 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
507 throw new IOException("Cannot get Cadastre response.");
508 }
509 Main.info("GET "+searchFormURL);
510 String ln;
511 StringBuilder sb = new StringBuilder();
512 try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8))) {
513 while ((ln = in.readLine()) != null) {
514 sb.append(ln);
515 }
516 }
517 urlConn.disconnect();
518 String line = sb.toString();
519 parseBBoxCommune(wmsLayer, line);
520 if (wmsLayer.isRaster() && !wmsLayer.isAlreadyGeoreferenced()) {
521 parseGeoreferences(wmsLayer, line);
522 }
523 }
524
525 private static void parseBBoxCommune(WMSLayer wmsLayer, String input) {
526 if (input.indexOf(C_BBOX_COMMUN_START) != -1) {
527 input = input.substring(input.indexOf(C_BBOX_COMMUN_START));
528 int i = input.indexOf(',');
529 double minx = Double.parseDouble(input.substring(C_BBOX_COMMUN_START.length(), i));
530 int j = input.indexOf(',', i+1);
531 double miny = Double.parseDouble(input.substring(i+1, j));
532 int k = input.indexOf(',', j+1);
533 double maxx = Double.parseDouble(input.substring(j+1, k));
534 int l = input.indexOf(C_BBOX_COMMUN_END, k+1);
535 double maxy = Double.parseDouble(input.substring(k+1, l));
536 wmsLayer.setCommuneBBox( new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy)));
537 }
538 }
539
540 private static void parseGeoreferences(WMSLayer wmsLayer, String input) {
541 /* commented since cadastre WMS changes mid july 2013
542 * until new GeoBox coordinates parsing is solved */
543// if (input.lastIndexOf(cBBoxCommunStart) != -1) {
544// input = input.substring(input.lastIndexOf(cBBoxCommunStart));
545// input = input.substring(input.indexOf(cBBoxCommunEnd)+cBBoxCommunEnd.length());
546// int i = input.indexOf(",");
547// int j = input.indexOf(",", i+1);
548// String str = input.substring(i+1, j);
549// double unknown_yet = tryParseDouble(str);
550// int j_ = input.indexOf(",", j+1);
551// double angle = Double.parseDouble(input.substring(j+1, j_));
552// int k = input.indexOf(",", j_+1);
553// double scale_origin = Double.parseDouble(input.substring(j_+1, k));
554// int l = input.indexOf(",", k+1);
555// double dpi = Double.parseDouble(input.substring(k+1, l));
556// int m = input.indexOf(",", l+1);
557// double fX = Double.parseDouble(input.substring(l+1, m));
558// int n = input.indexOf(",", m+1);
559// double fY = Double.parseDouble(input.substring(m+1, n));
560// int o = input.indexOf(",", n+1);
561// double X0 = Double.parseDouble(input.substring(n+1, o));
562// int p = input.indexOf(",", o+1);
563// double Y0 = Double.parseDouble(input.substring(o+1, p));
564// if (X0 != 0.0 && Y0 != 0) {
565// wmsLayer.setAlreadyGeoreferenced(true);
566// wmsLayer.fX = fX;
567// wmsLayer.fY = fY;
568// wmsLayer.angle = angle;
569// wmsLayer.X0 = X0;
570// wmsLayer.Y0 = Y0;
571// }
572// Main.info("parse georef:"+unknown_yet+","+angle+","+scale_origin+","+dpi+","+fX+","+fY+","+X0+","+Y0);
573// }
574 }
575
576 private static void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException {
577 if (Main.map != null) {
578 for (Layer l : Main.map.mapView.getAllLayers()) {
579 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (!l.equals(wmsLayer))) {
580 Main.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened.");
581 // remove the duplicated layer
582 Main.main.removeLayer(wmsLayer);
583 throw new DuplicateLayerException();
584 }
585 }
586 }
587 }
588
589 public void cancel() {
590 if (urlConn != null) {
591 urlConn.setConnectTimeout(1);
592 urlConn.setReadTimeout(1);
593 }
594 downloadCanceled = true;
595 lastWMSLayerName = null;
596 }
597}
Note: See TracBrowser for help on using the repository browser.