Changeset 806 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2008-08-18T12:12:40+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r769 r806 19 19 20 20 /** 21 22 23 21 * The boundings of the desired map data. 22 */ 23 private final double lat1; 24 24 private final double lon1; 25 25 private final double lat2; … … 31 31 this.lat2 = lat2; 32 32 this.lon2 = lon2; 33 } 33 // store the bounding box in the preferences so it can be 34 // re-used across invocations of josm 35 Main.pref.put("osm-download.bounds", lat1+";"+lon1+";"+lat2+";"+lon2); 36 } 34 37 35 38 /** 36 37 38 *contain only one list, since the server cannot distinguish between39 *ways.40 39 * Retrieve raw gps waypoints from the server API. 40 * @return A list of all primitives retrieved. Currently, the list of lists 41 * contain only one list, since the server cannot distinguish between 42 * ways. 43 */ 41 44 public GpxData parseRawGps() throws IOException, SAXException { 42 45 Main.pleaseWaitDlg.progress.setValue(0); 43 46 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 44 45 47 try { 48 String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 46 49 47 50 boolean done = false; 48 51 GpxData result = null; 49 52 for (int i = 0;!done;++i) { 50 51 52 53 53 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); 54 InputStream in = getInputStream(url+i, Main.pleaseWaitDlg); 55 if (in == null) 56 break; 54 57 GpxData currentGpx = new GpxReader(in, null).data; 55 58 if (result == null) { … … 59 62 } else{ 60 63 done = true; 61 62 63 64 64 } 65 in.close(); 66 activeConnection = null; 67 } 65 68 result.fromServer = true; 66 69 return result; 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 70 } catch (IllegalArgumentException e) { 71 // caused by HttpUrlConnection in case of illegal stuff in the response 72 if (cancel) 73 return null; 74 throw new SAXException("Illegal characters within the HTTP-header response", e); 75 } catch (IOException e) { 76 if (cancel) 77 return null; 78 throw e; 79 } catch (SAXException e) { 80 throw e; 81 } catch (Exception e) { 82 if (cancel) 83 return null; 84 if (e instanceof RuntimeException) 85 throw (RuntimeException)e; 86 throw new RuntimeException(e); 87 } 88 } 86 89 87 90 /** 88 89 90 91 92 91 * Read the data from the osm server address. 92 * @return A data set containing all data retrieved from that url 93 */ 94 public DataSet parseOsm() throws SAXException, IOException { 95 try { 93 96 Main.pleaseWaitDlg.progress.setValue(0); 94 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 95 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg); 96 if (in == null) 97 return null; 98 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 99 final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg); 100 /* 101 * We're not doing this here anymore as the API now properly sets a bounds element 102 * which will get parsed. 103 String origin = Main.pref.get("osm-server.url")+"/"+Main.pref.get("osm-server.version", "0.5"); 104 Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2)); 105 DataSource src = new DataSource(bounds, origin); 106 data.dataSources.add(src); 107 */ 108 in.close(); 109 activeConnection = null; 110 return data; 111 } catch (IOException e) { 112 if (cancel) 113 return null; 114 throw e; 115 } catch (SAXException e) { 116 throw e; 117 } catch (Exception e) { 118 if (cancel) 119 return null; 120 if (e instanceof RuntimeException) 121 throw (RuntimeException)e; 122 throw new RuntimeException(e); 123 } 124 } 97 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 98 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg); 99 if (in == null) 100 return null; 101 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 102 final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg); 103 in.close(); 104 activeConnection = null; 105 return data; 106 } catch (IOException e) { 107 if (cancel) 108 return null; 109 throw e; 110 } catch (SAXException e) { 111 throw e; 112 } catch (Exception e) { 113 if (cancel) 114 return null; 115 if (e instanceof RuntimeException) 116 throw (RuntimeException)e; 117 throw new RuntimeException(e); 118 } 119 } 125 120 }
Note:
See TracChangeset
for help on using the changeset viewer.