use of org.geotools.data.wms.request.GetMapRequest in project spatial-portal by AtlasOfLivingAustralia.
the class AddWMSLayerComposer method onClick$addDiscoveredLayerButton.
/**
* User selected a map layer after doing "select layers" and clicked "add to
* map"
*/
public void onClick$addDiscoveredLayerButton() {
LOGGER.debug("onAddDiscoveredLayer()");
// DO NOT PUT TEST INTO IF STATEMENT (DO NOT SHORT CURCUIT HERE!)
boolean acm = validateAutomaticModeCommon();
boolean ams = validiateAutomaticModeSelectLayer();
boolean c = validateCommon();
if (acm && ams && c) {
String discoveredLayerId = ((String[]) layerName.getSelectedItem().getValue())[0];
/*
* we've already interogated the WMS server to find the available
* layers - we don't need to do this again, all we need to do is
* select the layer they user chose by looking for the layer name
*/
Layer targetLayer = discoveredLayer.getLayerList().get(Integer.parseInt(discoveredLayerId));
if (targetLayer != null) {
MapLayer mapLayer = new MapLayer();
mapLayer.setName(targetLayer.getName());
GetMapRequest mapRequest = wmsServer.createGetMapRequest();
mapRequest.addLayer(targetLayer);
LOGGER.debug(mapRequest.getFinalURL());
mapRequest.setFormat(StringConstants.IMAGE_PNG);
String url = mapRequest.getFinalURL().toString();
mapLayer.setUri(url);
mapLayer.setLayer(targetLayer.getName());
mapLayer.setOpacity(opacitySlider.getCurpos() / 100.0f);
mapLayer.setImageFormat(layerUtilities.getImageFormat(url));
/* attempt to retrieve bounding box */
List<Double> bbox = layerUtilities.getBBox(url);
if (bbox != null) {
CRSEnvelope e = targetLayer.getLatLonBoundingBox();
bbox.set(0, e.getMinX());
bbox.set(1, e.getMinY());
bbox.set(2, e.getMaxX());
bbox.set(3, e.getMaxY());
MapLayerMetadata md = new MapLayerMetadata();
md.setBbox(bbox);
md.setMoreInfo(targetLayer.getName() + "\n" + makeMetadataHtml(targetLayer));
mapLayer.setMapLayerMetadata(md);
}
/* we don't want our user to have to type loads
* when adding a new layer so we just assume/generate
* values for the id and description
*/
String name = (nameAutomatically.isChecked()) ? targetLayer.getName() + ", " + targetLayer.getTitle() : Validate.escapeHtmlAndTrim(label.getValue());
mapLayer.setId(url + name.replaceAll("\\s+", ""));
mapLayer.setDescription(name);
// wms version
String version = layerUtilities.getVersionValue(url);
mapLayer.setType(layerUtilities.internalVersion(version));
getMapComposer().addUserDefinedLayerToMenu(mapLayer, true);
// all sweet
updateResult(StringConstants.WMS_LAYER_ADDED);
// remove the layer from available layers to stop it being
// added twice
removeLayer(discoveredLayerId);
updateAvailableLayers();
} else {
getMapComposer().showMessage(CommonData.lang("error_selecting_layer") + ": '" + discoveredLayerId + "'");
}
}
}
Aggregations