private GpxData downloadRawGps(String url, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException { boolean done = false; GpxData result = null; for (int i = 0; !done; ++i) { progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); InputStream in = getInputStream(url + i, progressMonitor.createSubTaskMonitor(1, true)); if (in == null) { break; } progressMonitor.setTicks(0); GpxReader reader = new GpxReader(in); gpxParsedProperly = reader.parse(false); GpxData currentGpx = reader.data; if (result == null) { result = currentGpx; } else if (currentGpx.hasTrackPoints()) { result.mergeFrom(currentGpx); } else { done = true; } in.close(); activeConnection = null; } result.fromServer = true; return result; }
private GpxData downloadRawGps(Bounds b, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException { boolean done = false; GpxData result = null; String url = "trackpoints?bbox=" + b.getMinLon() + ',' + b.getMinLat() + ',' + b.getMaxLon() + ',' + b.getMaxLat() + "&page="; for (int i = 0; !done; ++i) { progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, (i + 1) * 5000)); try (InputStream in = getInputStream(url + i, progressMonitor.createSubTaskMonitor(1, true))) { if (in == null) { break; } progressMonitor.setTicks(0); GpxReader reader = new GpxReader(in); gpxParsedProperly = reader.parse(false); GpxData currentGpx = reader.getGpxData(); if (result == null) { result = currentGpx; } else if (currentGpx.hasTrackPoints()) { result.mergeFrom(currentGpx); } else { done = true; } } activeConnection = null; } if (result != null) { result.fromServer = true; result.dataSources.add(new DataSource(b, "OpenStreetMap server")); } return result; }
/** * Replies the new GPX and marker layers corresponding to the specified GPX data. * * @param data The GPX data * @param parsedProperly True if GPX data has been properly parsed by {@link GpxReader#parse} * @param gpxLayerName The GPX layer name * @param markerLayerName The marker layer name * @return the new GPX and marker layers corresponding to the specified GPX data, to be used with * {@link #addLayers} * @see #addLayers */ public static GpxImporterData loadLayers( final GpxData data, final boolean parsedProperly, final String gpxLayerName, String markerLayerName) { GpxLayer gpxLayer = null; MarkerLayer markerLayer = null; if (data.hasRoutePoints() || data.hasTrackPoints()) { gpxLayer = new GpxLayer(data, gpxLayerName, data.storageFile != null); } if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) { markerLayer = new MarkerLayer(data, markerLayerName, data.storageFile, gpxLayer); if (markerLayer.data.isEmpty()) { markerLayer = null; } } Runnable postLayerTask = () -> { if (!parsedProperly) { String msg; if (data.storageFile == null) { msg = tr( "Error occurred while parsing gpx data for layer ''{0}''. Only a part of the file will be available.", gpxLayerName); } else { msg = tr( "Error occurred while parsing gpx file ''{0}''. Only a part of the file will be available.", data.storageFile.getPath()); } JOptionPane.showMessageDialog(null, msg); } }; return new GpxImporterData(gpxLayer, markerLayer, postLayerTask); }