use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportPDF method addObjectByPid.
public MapLayer addObjectByPid(String pid, int red, int green, int blue, float opacity) {
JSONParser jp = new JSONParser();
JSONObject obj = null;
try {
obj = (JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/object/" + pid));
} catch (ParseException e) {
LOGGER.error("failed to parse for object: " + pid);
}
//add feature to the map as a new layer
MapLayer mapLayer = addWMSLayer("PID:" + pid, "", obj.get(StringConstants.WMSURL).toString(), opacity, null, null, LayerUtilitiesImpl.WKT, null, null, null);
mapLayer.setPolygonLayer(true);
//if the layer is a point create a radius
String bbox = obj.get(StringConstants.BBOX).toString();
MapLayerMetadata md = mapLayer.getMapLayerMetadata();
try {
List<Double> dbb = Util.getBoundingBox(bbox);
md.setBbox(dbb);
} catch (Exception e) {
LOGGER.debug("failed to parse: " + bbox, e);
}
mapLayer.setRedVal(red);
mapLayer.setGreenVal(green);
mapLayer.setBlueVal(blue);
mapLayer.setOpacity(opacity);
mapLayer.setDynamicStyle(true);
return mapLayer;
}
use of au.org.emii.portal.menu.MapLayerMetadata in project spatial-portal by AtlasOfLivingAustralia.
the class RemoteMapImpl method createWKTLayer.
public MapLayer createWKTLayer(String wkt, String label) {
MapLayer wktLayer = new MapLayer();
wktLayer.setPolygonLayer(true);
LOGGER.debug("adding WKT feature layer " + label);
wktLayer.setName(label);
wktLayer.setLayer(label);
wktLayer.setId(label);
wktLayer.setEnvColour(StringConstants.RED);
int colour = Util.nextColour();
int r = (colour >> 16) & 0x000000ff;
int g = (colour >> 8) & 0x000000ff;
int b = (colour) & 0x000000ff;
wktLayer.setRedVal(r);
wktLayer.setGreenVal(g);
wktLayer.setBlueVal(b);
wktLayer.setType(LayerUtilitiesImpl.WKT);
wktLayer.setWKT(wkt);
if (wktLayer.getMapLayerMetadata() == null) {
wktLayer.setMapLayerMetadata(new MapLayerMetadata());
}
wkt = wkt.replace(" (", "(").replace(", ", ",");
List<Double> bb = Util.getBoundingBox(wkt);
wktLayer.getMapLayerMetadata().setBbox(bb);
wktLayer.setAreaSqKm(String.format("%,.2f", SpatialUtil.calculateArea(wkt) / 1000000.0));
return wktLayer;
}
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();
}
Aggregations