* @param layer
*/
private void addGroundOverlay(Folder folder, Layer layer) {
int mapLayerOrder = context.getMapContent().layers().indexOf(layer);
GroundOverlay go = folder.createAndAddGroundOverlay();
go.setName(layer.getTitle());
go.setDrawOrder(mapLayerOrder);
Icon icon = go.createAndSetIcon();
icon.setHref(getGroundOverlayHRef(layer));
icon.setViewRefreshMode(ViewRefreshMode.NEVER);
icon.setViewBoundScale(0.75);
ReferencedEnvelope box = new ReferencedEnvelope(context.getMapContent()
.getRenderingArea());
boolean reprojectBBox = (box.getCoordinateReferenceSystem() != null)
&& !CRS.equalsIgnoreMetadata(box.getCoordinateReferenceSystem(),
DefaultGeographicCRS.WGS84);
if (reprojectBBox) {
try {
box = box.transform(DefaultGeographicCRS.WGS84, true);
} catch (Exception e) {
throw new ServiceException("Could not transform bbox to WGS84", e,
"ReprojectionError", "");
}
}
LatLonBox gobox = go.createAndSetLatLonBox();
gobox.setEast(box.getMinX());
gobox.setWest(box.getMaxX());
gobox.setNorth(box.getMaxY());
gobox.setSouth(box.getMinY());
}