}
}
@Override
protected void handleRequest() throws RequestHandlerErrorException {
DownloadTask osmTask = new DownloadOsmTask();
try {
boolean newLayer = isLoadInNewLayer();
if (command.equals(myCommand)) {
if (!PermissionPrefWithDefault.LOAD_DATA.isAllowed()) {
Main.info("RemoteControl: download forbidden by preferences");
} 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) {