use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class AreaToolComposer method detach.
@Override
public void detach() {
super.detach();
String parentname = (String) winProps.get(StringConstants.PARENTNAME);
String areatype = (String) getMapComposer().getAttribute(StringConstants.ADDAREAWINDOW);
if (areatype == null) {
areatype = "";
} else {
if (areatype.startsWith("ci")) {
areatype = areatype.substring(2);
}
if (areatype.startsWith("Upload")) {
areatype = "Import - Area " + areatype.substring(6);
} else if (areatype.startsWith("WKT")) {
areatype = "Import - Area WKT";
} else {
areatype = "Area - " + areatype;
}
}
//always map the user defined area
MapLayer ml = getMapComposer().getMapLayer(layerName);
if (ok && ml != null) {
String displayName = ml.getDisplayName();
String fromLayer = (String) getMapComposer().getAttribute("mappolygonlayer");
String activeLayerName = (String) getMapComposer().getAttribute("activeLayerName");
if (fromLayer == null) {
fromLayer = "";
} else {
getMapComposer().removeAttribute("mappolygonlayer");
}
if (activeLayerName == null) {
activeLayerName = "";
} else {
getMapComposer().removeAttribute("activeLayerName");
}
remoteLogger.logMapArea(layerName + ((!layerName.equalsIgnoreCase(displayName)) ? " (" + displayName + ")" : ""), areatype, ml.testWKT(), activeLayerName, fromLayer);
//warn user when reduced WKT may be used for analysis
getMapComposer().warnForLargeWKT(ml);
//upload this area and replace with WMS
getMapComposer().replaceWKTwithWMS(ml);
}
if (isAnalysisChild) {
analysisParent.resetWindow(ok ? layerName : null);
try {
remoteLogger.logMapArea(layerName, areatype, getMapComposer().getMapLayer(layerName).testWKT());
} catch (Exception e) {
LOGGER.error("error with remote logging", e);
}
} else if (isFacetChild) {
facetParent.resetWindow(ok ? layerName : null);
try {
remoteLogger.logMapArea(layerName, areatype, getMapComposer().getMapLayer(layerName).testWKT());
} catch (Exception e) {
LOGGER.error("error with remote logging", e);
}
} else if (parentname != null && "AddSpeciesInArea".equals(parentname)) {
//was OK clicked?
if (ok) {
//map
// String wkt = null;
// try {
// wkt = getMapComposer().getMapLayer(layerName).getWKT();
// } catch (Exception e) {
// LOGGER.error("failed to get WKT for layer: " + layerName, e);
// }
MapLayer mapLayer = getMapComposer().getMapLayer(layerName);
Query q = null;
if (winProps.get(StringConstants.QUERY) != null) {
q = ((Query) winProps.get(StringConstants.QUERY));
List<Facet> facets = mapLayer.getFacets();
String wkt = facets == null ? mapLayer.getWKT() : null;
SelectedArea sa = new SelectedArea(getMapComposer().getMapLayer(layerName), wkt);
q = QueryUtil.queryFromSelectedArea(q, sa, true, null);
}
if (winProps.get(StringConstants.QUERY) == null) {
mapSpeciesInArea();
} else if (winProps.get(StringConstants.FILTER) != null && (Boolean) winProps.get(StringConstants.FILTER)) {
ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
} else if (winProps.get("filterGrid") != null && (Boolean) winProps.get("filterGrid")) {
ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
} else if (winProps.get("byLsid") != null && (Boolean) winProps.get("byLsid")) {
ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
} else {
getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.TAXON), (String) winProps.get(StringConstants.RANK), 0, LayerUtilitiesImpl.SPECIES, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
}
if (getMapComposer().getMapLayer(layerName) != null) {
String displayName = getMapComposer().getMapLayer(layerName).getDisplayName();
remoteLogger.logMapArea(layerName + ((!layerName.equalsIgnoreCase(displayName)) ? " (" + displayName + ")" : ""), areatype, null);
}
}
}
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method addListener.
void addListener() {
if (!addedListener) {
addedListener = true;
// register for viewport changes
EventListener el = new EventListener() {
public void onEvent(Event event) throws Exception {
selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
}
};
getMapComposer().getLeftmenuSearchComposer().addViewportEventListener(StringConstants.FILTERING_RESULTS, el);
}
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityListResults method populateListWithProgressBar.
public void populateListWithProgressBar() {
areaPds = new ArrayList<Map<String, String>>();
areaSpeciesMatches = new ArrayList<Map<String, JSONArray>>();
for (SelectedArea sa : selectedAreas) {
queue.add(sa);
}
progress = new ConcurrentHashMap();
progress.put("label", "Starting");
progress.put("percent", 0.0);
Callable backgroundProcess = new Callable<Boolean>() {
@Override
public Boolean call() {
//TODO: setup for multiple threads
try {
while (!queue.isEmpty()) {
SelectedArea sa = queue.take();
progress.put("label", "Processing area: " + (selectedAreas.size() - queue.size()) + " of " + selectedAreas.size());
evalArea(sa);
progress.put("percent", String.valueOf((selectedAreas.size() - queue.size()) / (double) selectedAreas.size()));
}
} catch (InterruptedException e) {
}
return true;
}
};
pool = Executors.newFixedThreadPool(1);
future = pool.submit(backgroundProcess);
getMapComposer().getOpenLayersJavascript().execute("setTimeout('checkProgress()', 2000);");
divProgress.setVisible(true);
divResults.setVisible(false);
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListResults method populateList.
public void populateList() {
if (selectedArea == null) {
selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
}
try {
Query sq = QueryUtil.queryFromSelectedArea(null, selectedArea, extraParams, false, geospatialKosher);
sq = sq.newFacet(new Facet("occurrence_status_s", "absent", false), false);
if (sq.getSpeciesCount() <= 0) {
getMapComposer().showMessage("No species records in the active area.");
results = null;
popupListboxResults.setVisible(false);
resultsLabel.setVisible(false);
this.detach();
return;
}
//remove header
String speciesList = chooseEndemic ? sq.endemicSpeciesList() : sq.speciesList();
results = speciesList.substring(speciesList.indexOf('\n') + 1).split("\n");
java.util.Arrays.sort(results);
// results should already be sorted
String[] tmp = results;
if (results.length > 200) {
tmp = java.util.Arrays.copyOf(results, 200);
resultsLabel.setValue("preview of first 200 of " + results.length + " species found");
} else {
resultsLabel.setValue("preview of all " + results.length + " species found");
}
popupListboxResults.setModel(new ListModelArray(tmp, false));
popupListboxResults.setItemRenderer(new ListitemRenderer() {
public void render(Listitem li, Object data, int itemIdx) {
String s = (String) data;
CSVReader reader = new CSVReader(new StringReader(s));
String[] ss;
try {
ss = reader.readNext();
} catch (Exception e) {
ss = new String[0];
}
if (ss == null || ss.length == 0) {
return;
}
Listcell lc = new Listcell(ss[0]);
lc.setParent(li);
int col = 1;
while (col < ss.length) {
lc = new Listcell(ss[col]);
lc.setParent(li);
col++;
}
try {
reader.close();
} catch (IOException e) {
LOGGER.error("error closing after reading species list", e);
}
}
});
} catch (Exception e) {
LOGGER.error("error reading species list data", e);
}
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListResults method onClick$btnDownload.
public void onClick$btnDownload() {
StringBuilder sb = new StringBuilder();
sb.append("LSID,Scientific Name,Taxon Concept,Taxon Rank,Kingdom,Phylum,Class,Order,Family,Genus,Vernacular Name,Number of records");
for (int i = 0; i < CommonData.getSpeciesListAdditionalColumnsHeader().size(); i++) {
sb.append(",").append(CommonData.getSpeciesListAdditionalColumnsHeader().get(i));
}
sb.append("\r\n");
for (String s : results) {
sb.append(s);
sb.append("\r\n");
}
String spid = pid;
if (spid == null || StringConstants.NONE.equals(spid)) {
spid = String.valueOf(System.currentTimeMillis());
}
SimpleDateFormat date = new SimpleDateFormat(StringConstants.DATE);
String sdate = date.format(new Date());
Filedownload.save(sb.toString(), StringConstants.TEXT_PLAIN, "Species_list_" + sdate + "_" + spid + ".csv");
if (selectedArea == null) {
selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
}
remoteLogger.logMapAnalysis("Species List", "Export - Species List", (selectedArea.getFacets() != null ? selectedArea.getFacets().get(0).toString() : selectedArea.getWkt()), "", "", spid, "Species_list_" + sdate + "_" + spid + ".csv", "");
detach();
}
Aggregations