Ticket #18122: 18122-v1.patch

File 18122-v1.patch, 6.9 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

     
    467467                if (remark != null && !remark.isEmpty()) {
    468468                    rememberErrorMessage(remark);
    469469                }
    470                 // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work
    471                 dataSet.addDataSource(new DataSource(currentBounds != null ? currentBounds :
    472                     new Bounds(LatLon.ZERO), "OpenStreetMap server"));
     470                if (!(reader instanceof BoundingBoxDownloader)
     471                        || ((BoundingBoxDownloader) reader).considerAsFullDownload()) {
     472                    // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work
     473                    dataSet.addDataSource(new DataSource(
     474                            currentBounds != null ? currentBounds : new Bounds(LatLon.ZERO), "OpenStreetMap server"));
     475                }
    473476            }
    474477
    475478            rememberDownloadedData(dataSet);
  • src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

     
    5151 * @since 12652
    5252 */
    5353public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> {
     54    /** Overpass query to retrieve all nodes and related parent objects, */
     55    public static final String FULL_DOWNLOAD_QUERY = "[out:xml]; \n"
     56            + "(\n"
     57            + "    node({{bbox}});\n"
     58            + "<;\n"
     59            + ");\n"
     60            + "(._;>;);"
     61            + "out meta;";
    5462
    5563    @Override
    5664    public AbstractDownloadSourcePanel<OverpassDownloadData> createPanel(DownloadDialog dialog) {
     
    248256                        JOptionPane.QUESTION_MESSAGE,
    249257                        JOptionPane.YES_OPTION);
    250258                if (doFix) {
    251                     String repairedQuery = "[out:xml]; \n"
    252                             + query + "\n"
    253                             + "(\n"
    254                             + "    node({{bbox}});\n"
    255                             + "<;\n"
    256                             + ");\n"
    257                             + "(._;>;);"
    258                             + "out meta;";
    259                     this.overpassQuery.setText(repairedQuery);
     259                    this.overpassQuery.setText(FULL_DOWNLOAD_QUERY);
    260260                } else {
    261261                    return false;
    262262                }
  • src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

     
    255255            this.limit = limit;
    256256        }
    257257    }
     258
     259    /**
     260     * @return true if download is complete for the given bounding box (not filtered)
     261     */
     262    public boolean considerAsFullDownload() {
     263        return true;
     264    }
     265
    258266}
  • src/org/openstreetmap/josm/io/OverpassDownloadReader.java

     
    3030import org.openstreetmap.josm.data.coor.LatLon;
    3131import org.openstreetmap.josm.data.osm.BBox;
    3232import org.openstreetmap.josm.data.osm.DataSet;
     33import org.openstreetmap.josm.data.osm.DataSetMerger;
    3334import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3435import org.openstreetmap.josm.data.osm.PrimitiveId;
    3536import org.openstreetmap.josm.data.preferences.BooleanProperty;
    3637import org.openstreetmap.josm.data.preferences.ListProperty;
    3738import org.openstreetmap.josm.data.preferences.StringProperty;
     39import org.openstreetmap.josm.gui.download.OverpassDownloadSource;
    3840import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3941import org.openstreetmap.josm.io.NameFinder.SearchResult;
    4042import org.openstreetmap.josm.tools.HttpClient;
     
    384386    public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
    385387
    386388        DataSet ds = super.parseOsm(progressMonitor);
     389        if (!considerAsFullDownload()) {
     390            DataSet noBounds = new DataSet();
     391            DataSetMerger dsm = new DataSetMerger(noBounds, ds);
     392            dsm.merge(null, false);
     393            return dsm.getTargetDataSet();
     394        } else {
     395            // add bounds if necessary (note that Overpass API does not return bounds in the response XML)
     396            if (ds != null && ds.getDataSources().isEmpty() && overpassQuery.contains("{{bbox}}")) {
     397                if (crosses180th) {
     398                    Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
     399                    DataSource src = new DataSource(bounds, getBaseUrl());
     400                    ds.addDataSource(src);
    387401
    388         // add bounds if necessary (note that Overpass API does not return bounds in the response XML)
    389         if (ds != null && ds.getDataSources().isEmpty() && overpassQuery.contains("{{bbox}}")) {
    390             if (crosses180th) {
    391                 Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
    392                 DataSource src = new DataSource(bounds, getBaseUrl());
    393                 ds.addDataSource(src);
    394 
    395                 bounds = new Bounds(lat1, -180.0, lat2, lon2);
    396                 src = new DataSource(bounds, getBaseUrl());
    397                 ds.addDataSource(src);
    398             } else {
    399                 Bounds bounds = new Bounds(lat1, lon1, lat2, lon2);
    400                 DataSource src = new DataSource(bounds, getBaseUrl());
    401                 ds.addDataSource(src);
     402                    bounds = new Bounds(lat1, -180.0, lat2, lon2);
     403                    src = new DataSource(bounds, getBaseUrl());
     404                    ds.addDataSource(src);
     405                } else {
     406                    Bounds bounds = new Bounds(lat1, lon1, lat2, lon2);
     407                    DataSource src = new DataSource(bounds, getBaseUrl());
     408                    ds.addDataSource(src);
     409                }
    402410            }
     411            return ds;
    403412        }
    404 
    405         return ds;
    406413    }
    407414
    408415    /**
     
    416423                .replaceAll("out( body| skel| ids)?( id| qt)?;", "out meta$2;")
    417424                .replaceAll("(?s)\\[out:(csv)[^\\]]*\\]", "[out:xml]");
    418425    }
     426
     427    @Override
     428    public boolean considerAsFullDownload() {
     429        return overpassQuery.equals(OverpassDownloadSource.FULL_DOWNLOAD_QUERY);
     430    }
    419431}