Ignore:
Timestamp:
2009-01-28T21:44:10+01:00 (17 years ago)
Author:
pieren
Message:

add municipality bbox in grab and cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java

    r13382 r13426  
    1818
    1919import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.data.coor.EastNorth;
    2021import org.openstreetmap.josm.gui.layer.Layer;
    2122import org.openstreetmap.josm.tools.GBC;
     
    3839    final String c0ptionListStart = "<option value=\"";
    3940    final String cOptionListEnd = "</option>";
     41    final String cBBoxCommunStart = "new GeoBox(";
     42    final String cBBoxCommunEnd = ")";
    4043   
    4144    final String cInterfaceVector = "afficherCarteCommune.do";
     
    310313    }
    311314   
     315    public EastNorthBound retrieveCommuneBBox() throws IOException {
     316        if (interfaceRef == null)
     317            return null;
     318        String ln = null;
     319        String line = null;
     320        // send GET opening normally the small window with the commune overview
     321        String content = baseURL + "/scpc/" + interfaceRef;
     322        content += "&dontSaveLastForward&keepVolatileSession=";
     323        searchFormURL = new URL(content);
     324        System.out.println("HEAD:"+content);
     325        urlConn = (HttpURLConnection)searchFormURL.openConnection();
     326        urlConn.setRequestMethod("GET");
     327        setCookie();
     328        urlConn.connect();
     329        if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
     330            throw (IOException) new IOException("Cannot get Cadastre response.");
     331        }
     332        BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
     333        while ((ln = in.readLine()) != null) {
     334            line += ln;
     335        }
     336        in.close();
     337        urlConn.disconnect();
     338        return parseBBoxCommune(line);
     339    }
     340   
     341    private EastNorthBound parseBBoxCommune(String input) {
     342        if (input.indexOf(cBBoxCommunStart) != -1) {
     343            input = input.substring(input.indexOf(cBBoxCommunStart));
     344            int i = input.indexOf(",");
     345            double minx = Double.parseDouble(input.substring(cBBoxCommunStart.length(), i));
     346            int j = input.indexOf(",", i+1);
     347            double miny = Double.parseDouble(input.substring(i+1, j));
     348            int k = input.indexOf(",", j+1);
     349            double maxx = Double.parseDouble(input.substring(j+1, k));
     350            int l = input.indexOf(cBBoxCommunEnd, k+1);
     351            double maxy = Double.parseDouble(input.substring(k+1, l));
     352            return new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy));
     353        }
     354        return null;
     355    }
     356   
    312357    private void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException {
    313358        if (Main.map != null) {
Note: See TracChangeset for help on using the changeset viewer.