} else {
Area toDownload = null;
if (!newLayer) {
// find out whether some data has already been downloaded
Area present = null;
DataSet ds = Main.main.getCurrentDataSet();
if (ds != null) {
present = ds.getDataSourceArea();
}
if (present != null && !present.isEmpty()) {
toDownload = new Area(new Rectangle2D.Double(minlon,minlat,maxlon-minlon,maxlat-minlat));
toDownload.subtract(present);
if (!toDownload.isEmpty()) {
// the result might not be a rectangle (L shaped etc)
Rectangle2D downloadBounds = toDownload.getBounds2D();
minlat = downloadBounds.getMinY();
minlon = downloadBounds.getMinX();
maxlat = downloadBounds.getMaxY();
maxlon = downloadBounds.getMaxX();
}
}
}
if (toDownload != null && toDownload.isEmpty()) {
Main.info("RemoteControl: no download necessary");
} else {
Future<?> future = osmTask.download(newLayer, new Bounds(minlat,minlon,maxlat,maxlon), null /* let the task manage the progress monitor */);
Main.worker.submit(new PostDownloadHandler(osmTask, future));
}
}
}
} catch (Exception ex) {
Main.warn("RemoteControl: Error parsing load_and_zoom remote control request:");
Main.error(ex);
throw new RequestHandlerErrorException(ex);
}
/**
* deselect objects if parameter addtags given
*/
if (args.containsKey("addtags")) {
GuiHelper.executeByMainWorkerInEDT(new Runnable() {
@Override
public void run() {
DataSet ds = Main.main.getCurrentDataSet();
if(ds == null) // e.g. download failed
return;
ds.clearSelection();
}
});
}
final Bounds bbox = new Bounds(minlat, minlon, maxlat, maxlon);
if (args.containsKey("select") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
// select objects after downloading, zoom to selection.
GuiHelper.executeByMainWorkerInEDT(new Runnable() {
@Override
public void run() {
Set<OsmPrimitive> newSel = new HashSet<>();
DataSet ds = Main.main.getCurrentDataSet();
if (ds == null) // e.g. download failed
return;
for (SimplePrimitiveId id : toSelect) {
final OsmPrimitive p = ds.getPrimitiveById(id);
if (p != null) {
newSel.add(p);
}
}
toSelect.clear();
ds.setSelected(newSel);
zoom(newSel, bbox);
if (Main.isDisplayingMapView() && Main.map.relationListDialog != null) {
Main.map.relationListDialog.selectRelations(null); // unselect all relations to fix #7342
Main.map.relationListDialog.dataChanged(null);
Main.map.relationListDialog.selectRelations(Utils.filteredCollection(newSel, Relation.class));
}
}
});
} else if (args.containsKey("search") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
try {
final DataSet ds = Main.main.getCurrentDataSet();
final SearchCompiler.Match search = SearchCompiler.compile(args.get("search"), false, false);
final Collection<OsmPrimitive> filteredPrimitives = Utils.filter(ds.allPrimitives(), search);
ds.setSelected(filteredPrimitives);
zoom(filteredPrimitives, bbox);
} catch (SearchCompiler.ParseError ex) {
Main.error(ex);
throw new RequestHandlerErrorException(ex);
}