addDynamic(offsetMenuItem);
addDynamicSeparator();
// for each configured ImageryInfo, add a menu entry.
for (final ImageryInfo u : ImageryLayerInfo.instance.getLayers()) {
addDynamic(new AddImageryLayerAction(u));
}
// list all imagery entries where the current map location
// is within the imagery bounds
if (Main.isDisplayingMapView()) {
MapView mv = Main.map.mapView;
LatLon pos = mv.getProjection().eastNorth2latlon(mv.getCenter());
final Set<ImageryInfo> inViewLayers = new TreeSet<>();
for (ImageryInfo i : ImageryLayerInfo.instance.getDefaultLayers()) {
if (i.getBounds() != null && i.getBounds().contains(pos)) {
inViewLayers.add(i);
}
}
// Do not suggest layers already in use
inViewLayers.removeAll(ImageryLayerInfo.instance.getLayers());
// For layers containing complex shapes, check that center is in one
// of its shapes (fix #7910)
for (Iterator<ImageryInfo> iti = inViewLayers.iterator(); iti.hasNext(); ) {
List<Shape> shapes = iti.next().getBounds().getShapes();
if (shapes != null && !shapes.isEmpty()) {
boolean found = false;
for (Iterator<Shape> its = shapes.iterator(); its.hasNext() && !found; ) {
found = its.next().contains(pos);
}
if (!found) {
iti.remove();
}
}
}
if (!inViewLayers.isEmpty()) {
addDynamicSeparator();
for (ImageryInfo i : inViewLayers) {
addDynamic(new AddImageryLayerAction(i));
}
}
}
addDynamicSeparator();