use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class AddWMSLayerComposer method onClick$addAllLayersButton.
public void onClick$addAllLayersButton() {
LOGGER.debug("onClick$addAllLayersButton()");
// hide (any) previous success message
resultLabel.setVisible(false);
// validate - DO NOT SHORT CURCUIT HERE!
// DO NOT PUT TEST INTO IF STATEMENT (DO NOT SHORT CURCUIT HERE!)
boolean amc = validateAutomaticModeCommon();
boolean c = validateCommon();
if (c && amc) {
try {
wmsServer = new WebMapServer(new URL(uri.getValue()));
discoveredLayer = wmsServer.getCapabilities();
MapLayer mapLayer = new MapLayer();
mapLayer.setName(Validate.escapeHtmlAndTrim(label.getValue()));
String ur = uri.getValue();
mapLayer.setUri(ur);
mapLayer.setLayer(layerUtilities.getLayers(ur));
mapLayer.setOpacity(opacitySlider.getCurpos() / 100.0f);
mapLayer.setImageFormat(layerUtilities.getImageFormat(ur));
/* attempt to retrieve bounding box */
List<Double> bbox = layerUtilities.getBBox(ur);
if (bbox != null) {
MapLayerMetadata md = new MapLayerMetadata();
md.setBbox(bbox);
md.setMoreInfo(ur);
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()) ? "" : Validate.escapeHtmlAndTrim(label.getValue());
mapLayer.setId(uri + name.replaceAll("\\s+", ""));
mapLayer.setDescription(name);
// wms version
String version = layerUtilities.getVersionValue(ur);
mapLayer.setType(layerUtilities.internalVersion(version));
getMapComposer().addUserDefinedLayerToMenu(mapLayer, true);
updateResult("wms_server_added");
// addWMSServer handles showing any errors for us
} catch (Exception e) {
LOGGER.error("failed to get layer from url", e);
}
}
}
use of au.org.emii.portal.menu.MapLayerMetadata 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 + "'");
}
}
}
use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class ImportAnalysisController method loadMapMaxent.
public void loadMapMaxent(Event event) {
String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:species_" + pid + "&styles=alastyles&FORMAT=image%2Fpng";
String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:species_" + pid + "&STYLE=alastyles";
LOGGER.debug(legendurl);
//get job inputs
String layername = "Maxent - " + pid;
getMapComposer().addWMSLayer("species_" + pid, layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.MAXENT, null, null);
MapLayer ml = getMapComposer().getMapLayer("species_" + pid);
ml.setPid(pid);
String infoUrl = CommonData.getSatServer() + "/output/maxent/" + pid + "/species.html";
MapLayerMetadata md = ml.getMapLayerMetadata();
md.setMoreInfo(infoUrl + "\nMaxent Output\npid:" + pid);
md.setId(Long.valueOf(pid));
try {
// set off the download as well
String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
Filedownload.save(new URL(fileUrl).openStream(), "application/zip", layername.replaceAll(" ", "_") + ".zip");
} catch (Exception ex) {
LOGGER.error("Error generating download for prediction model pid=" + pid, ex);
}
this.detach();
}
use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class ImportAnalysisController method loadMapSxS.
private void loadMapSxS() {
try {
if (sxsOccurrenceDensity) {
String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:odensity_" + pid + "&styles=odensity_" + pid + "&FORMAT=image%2Fpng";
String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:odensity_" + pid + "&STYLE=odensity_" + pid;
LOGGER.debug(legendurl);
String layername = getMapComposer().getNextAreaLayerName(StringConstants.OCCURRENCE_DENSITY);
getMapComposer().addWMSLayer(pid + "_odensity", layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ODENSITY, null, null);
MapLayer ml = getMapComposer().getMapLayer(pid + "_odensity");
ml.setPid(pid + "_odensity");
String infoUrl = CommonData.getSatServer() + "/output/sitesbyspecies/" + pid + "/odensity_metadata.html";
MapLayerMetadata md = ml.getMapLayerMetadata();
md.setMoreInfo(infoUrl + "\nOccurrence Density\npid:" + pid);
md.setId(Long.valueOf(pid));
}
if (sxsSpeciesDensity) {
String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:srichness_" + pid + "&styles=srichness_" + pid + "&FORMAT=image%2Fpng";
String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:srichness_" + pid + "&STYLE=srichness_" + pid;
LOGGER.debug(legendurl);
String layername = getMapComposer().getNextAreaLayerName(StringConstants.SPECIES_RICHNESS);
getMapComposer().addWMSLayer(pid + "_srichness", layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.SRICHNESS, null, null);
MapLayer ml = getMapComposer().getMapLayer(pid + "_srichness");
ml.setPid(pid + "_srichness");
String infoUrl = CommonData.getSatServer() + "/output/sitesbyspecies/" + pid + "/srichness_metadata.html";
MapLayerMetadata md = ml.getMapLayerMetadata();
md.setMoreInfo(infoUrl + "\nSpecies Richness\npid:" + pid);
md.setId(Long.valueOf(pid));
}
// set off the download as well
String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
Filedownload.save(new URL(fileUrl).openStream(), "application/zip", "sites_by_species.zip");
} catch (Exception ex) {
LOGGER.error("Error generating download for sites by species pid=" + pid, ex);
}
this.detach();
}
use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class ImportAnalysisController method loadMapAloc.
public void loadMapAloc(Event event) {
String layerLabel = "Classification - " + pid;
String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:aloc_" + pid + "&FORMAT=image%2Fpng";
String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:aloc_" + pid;
LOGGER.debug(legendurl);
getMapComposer().addWMSLayer("aloc_" + pid, layerLabel, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ALOC, null, null);
MapLayer mapLayer = getMapComposer().getMapLayer("aloc_" + pid);
mapLayer.setPid(pid);
if (mapLayer != null) {
WMSStyle style = new WMSStyle();
style.setName(StringConstants.DEFAULT);
style.setDescription("Default style");
style.setTitle(StringConstants.DEFAULT);
style.setLegendUri(legendurl);
LOGGER.debug("legend:" + legendurl);
mapLayer.addStyle(style);
mapLayer.setSelectedStyleIndex(1);
MapLayerMetadata md = mapLayer.getMapLayerMetadata();
String infoUrl = CommonData.getSatServer() + "/output/layers/" + pid + "/metadata.html" + "\nClassification output\npid:" + pid;
md.setMoreInfo(infoUrl);
md.setId(Long.valueOf(pid));
getMapComposer().updateLayerControls();
try {
// set off the download as well
String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
Filedownload.save(new URL(fileUrl).openStream(), "application/zip", layerLabel.replaceAll(" ", "_") + ".zip");
} catch (Exception ex) {
LOGGER.error("Error generating download for classification model pid=" + pid, ex);
}
}
this.detach();
}
Aggregations