use of au.org.emii.portal.wms.WMSStyle in project spatial-portal by AtlasOfLivingAustralia.
the class ALOCComposer method loadMap.
public void loadMap(Event event) {
//get job inputs
try {
for (String s : getJob().split(";")) {
if (s.startsWith("gc")) {
layerLabel = tToolName.getValue();
generationCount++;
break;
}
}
} catch (Exception e) {
LOGGER.error("error getting ALOC job info", e);
}
if (layerLabel == null) {
layerLabel = "My Classification " + generationCount;
generationCount++;
}
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);
legendPath = legendurl;
getMapComposer().addWMSLayer("aloc_" + pid, layerLabel, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ALOC, null, null);
MapLayer mapLayer = getMapComposer().getMapLayer("aloc_" + pid);
if (mapLayer != null) {
mapLayer.setPid(pid);
WMSStyle style = new WMSStyle();
style.setName(StringConstants.DEFAULT);
style.setDescription("Default style");
style.setTitle(StringConstants.DEFAULT);
style.setLegendUri(legendurl);
LOGGER.debug("legend:" + legendPath);
mapLayer.addStyle(style);
mapLayer.setSelectedStyleIndex(1);
MapLayerMetadata md = mapLayer.getMapLayerMetadata();
String infoUrl = CommonData.getSatServer() + "/output/aloc/" + pid + "/classification.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", tToolName.getValue().replaceAll(" ", "_") + ".zip");
} catch (Exception ex) {
LOGGER.error("Error generating download for classification model:", ex);
}
}
this.detach();
}
use of au.org.emii.portal.wms.WMSStyle in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportPDF method addWMSLayer.
public MapLayer addWMSLayer(String name, String displayName, String uri, float opacity, String metadata, String legendUri, int subType, String cqlfilter, String envParams, Query q) {
MapLayer mapLayer = remoteMap.createAndTestWMSLayer(name, uri, opacity);
mapLayer.setDisplayName(displayName);
if (q != null) {
mapLayer.setSpeciesQuery(q);
}
//ok
mapLayer.setSubType(subType);
mapLayer.setCql(cqlfilter);
mapLayer.setEnvParams(envParams);
String fieldId = mapLayer.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
String uriActual = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + mapLayer.getLayer() + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
mapLayer.setDefaultStyleLegendUri(uriActual);
if (metadata != null) {
if (metadata.startsWith("http")) {
mapLayer.getMapLayerMetadata().setMoreInfo(metadata + "\n" + displayName);
} else {
mapLayer.getMapLayerMetadata().setMoreInfo(metadata);
}
}
if (legendUri != null) {
WMSStyle style = new WMSStyle();
style.setName(StringConstants.DEFAULT);
style.setDescription("Default style");
style.setTitle(StringConstants.DEFAULT);
style.setLegendUri(legendUri);
mapLayer.addStyle(style);
mapLayer.setSelectedStyleIndex(1);
LOGGER.debug("adding WMSStyle with legendUri: " + legendUri);
mapLayer.setDefaultStyleLegendUriSet(true);
}
mapLayer.setDisplayed(true);
return mapLayer;
}
use of au.org.emii.portal.wms.WMSStyle in project spatial-portal by AtlasOfLivingAustralia.
the class MapLayer method clone.
/**
* Provide a deep copy of the object - equivalent to clone() only not
* broken. This is to allow us to maintain a single list of layers obtained
* from the map servers and then provide a copy of this list to clients
* rather than rerequesting it for each session/page access
*
* @return
*/
public Object clone() throws CloneNotSupportedException {
MapLayer mapLayer = (MapLayer) super.clone();
mapLayer.children = new ArrayList<MapLayer>();
mapLayer.styles = new ArrayList<WMSStyle>();
if (mapLayerId > 0) {
mapLayer.mapLayerId = mapLayerId;
}
// copy any styles
if (styles != null) {
for (WMSStyle style : styles) {
mapLayer.addStyle((WMSStyle) style.copy());
}
}
// copy any children.. - when we use add child, the parent is correctly set
if (children != null) {
for (MapLayer child : children) {
MapLayer clonedChild = (MapLayer) child.clone();
mapLayer.addChild(clonedChild);
}
}
// we can COPY instead of CLONEing
if (mapLayerMetadata != null) {
mapLayer.mapLayerMetadata = mapLayerMetadata;
}
return mapLayer;
}
use of au.org.emii.portal.wms.WMSStyle in project spatial-portal by AtlasOfLivingAustralia.
the class MapComposer method addWMSLayer.
/*
* Public utility methods to interogate the state of the form controls
*/
public MapLayer addWMSLayer(String name, String displayName, String uri, float opacity, String metadata, String legendUri, int subType, String cqlfilter, String envParams, Query q) {
MapLayer mapLayer = null;
if (safeToPerformMapAction()) {
if (portalSessionUtilities.getUserDefinedById(getPortalSession(), uri) == null) {
mapLayer = remoteMap.createAndTestWMSLayer(name, uri, opacity);
mapLayer.setDisplayName(displayName);
if (q != null) {
mapLayer.setSpeciesQuery(q);
}
//ok
mapLayer.setSubType(subType);
mapLayer.setCql(cqlfilter);
mapLayer.setEnvParams(envParams);
String fieldId = mapLayer.getUri().replaceAll("^.*&styles=", "").replaceAll("&.*", "").replaceAll("_style", "");
String newUri = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + mapLayer.getLayer() + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
mapLayer.setDefaultStyleLegendUri(newUri);
if (metadata != null && metadata.startsWith("http")) {
mapLayer.getMapLayerMetadata().setMoreInfo(metadata + "\n" + displayName);
} else {
mapLayer.getMapLayerMetadata().setMoreInfo(metadata);
}
if (legendUri != null) {
WMSStyle style = new WMSStyle();
style.setName(StringConstants.DEFAULT);
style.setDescription("Default style");
style.setTitle(StringConstants.DEFAULT);
style.setLegendUri(legendUri);
mapLayer.addStyle(style);
mapLayer.setSelectedStyleIndex(1);
LOGGER.debug("adding WMSStyle with legendUri: " + legendUri);
mapLayer.setDefaultStyleLegendUriSet(true);
}
addUserDefinedLayerToMenu(mapLayer, true);
} else {
// fail
showMessage(languagePack.getLang("wms_layer_already_exists"));
LOGGER.debug("refusing to add a new layer with URI " + uri + " because it already exists in the menu");
}
}
return mapLayer;
}
use of au.org.emii.portal.wms.WMSStyle 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