if (layers.isEmpty()) return null;
return layers.get(0);
}
private BoundingXYVisitor getBoundingBox() {
BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();
switch(mode) {
case "problem":
TestError error = Main.map.validatorDialog.getSelectedError();
if (error == null) return null;
((ValidatorBoundingXYVisitor) v).visit(error);
if (v.getBounds() == null) return null;
v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));
break;
case "data":
for (Layer l : Main.map.mapView.getAllLayers()) {
l.visitBoundingBox(v);
}
break;
case "layer":
if (Main.main.getActiveLayer() == null)
return null;
// try to zoom to the first selected layer
Layer l = getFirstSelectedLayer();
if (l == null) return null;
l.visitBoundingBox(v);
break;
case "selection":
case "conflict":
Collection<OsmPrimitive> sel = new HashSet<>();
if ("selection".equals(mode)) {
sel = getCurrentDataSet().getSelected();
} else {
Conflict<? extends OsmPrimitive> c = Main.map.conflictDialog.getSelectedConflict();
if (c != null) {
sel.add(c.getMy());
} else if (Main.map.conflictDialog.getConflicts() != null) {
sel = Main.map.conflictDialog.getConflicts().getMyConflictParties();
}
}
if (sel.isEmpty()) {
JOptionPane.showMessageDialog(
Main.parent,
("selection".equals(mode) ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")),
tr("Information"),
JOptionPane.INFORMATION_MESSAGE
);
return null;
}
for (OsmPrimitive osm : sel) {
osm.accept(v);
}
// Increase the bounding box by up to 100% to give more context.
v.enlargeBoundingBoxLogarithmically(100);
// Make the bounding box at least 100 meter wide to
// ensure reasonable zoom level when zooming onto single nodes.
v.enlargeToMinSize(Main.pref.getDouble("zoom_to_selection_min_size_in_meter", 100));
break;
case "download":
Bounds bounds = DownloadDialog.getSavedDownloadBounds();
if (bounds != null) {
try {
v.visit(bounds);
} catch (Exception e) {
Main.warn(e);
}
}
break;