use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method getSelectedAreaName.
public String getSelectedAreaName() {
String area = rAreaSelected.getLabel();
List<MapLayer> layers = getMapComposer().getPolygonLayers();
for (MapLayer ml : layers) {
if (area.equals(ml.getDisplayName())) {
area = ml.getName();
break;
}
}
return area;
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method loadAreaLayers.
public void loadAreaLayers(String selectedAreaName) {
try {
// remove all radio buttons that don't have an id
for (int i = rgArea.getItemCount() - 1; i >= 0; i--) {
String id = rgArea.getItems().get(i).getId();
if (id == null || id.length() == 0) {
rgArea.removeItemAt(i);
} else {
rgArea.getItemAtIndex(i).setSelected(false);
}
}
String selectedLayerName = null;
if (params != null && params.containsKey(StringConstants.POLYGON_LAYER_NAME)) {
selectedLayerName = (String) params.get(StringConstants.POLYGON_LAYER_NAME);
}
Radio rSelectedLayer = null;
List<MapLayer> layers = getMapComposer().getPolygonLayers();
for (int i = 0; i < layers.size(); i++) {
MapLayer lyr = layers.get(i);
Radio rAr = new Radio(lyr.getDisplayName());
rAr.setValue(lyr.getName());
rAr.setParent(rgArea);
if (rAreaCurrent != null) {
rgArea.insertBefore(rAr, rAreaCurrent);
} else {
rgArea.appendChild(rAr);
}
if (lyr.getName().equals(selectedLayerName)) {
rSelectedLayer = rAr;
rAreaSelected = rAr;
}
}
if (selectedAreaName != null && !selectedAreaName.isEmpty()) {
for (int i = 0; i < rgArea.getItemCount(); i++) {
if (rgArea.getItemAtIndex(i).isVisible() && rgArea.getItemAtIndex(i).getLabel().equals(selectedAreaName)) {
rAreaSelected = rgArea.getItemAtIndex(i);
rgArea.setSelectedItem(rAreaSelected);
break;
}
}
} else if (rSelectedLayer != null) {
rAreaSelected = rSelectedLayer;
rgArea.setSelectedItem(rAreaSelected);
} else if (StringConstants.NONE.equals(selectedLayerName)) {
rgArea.setSelectedItem(rAreaWorld);
rAreaSelected = rAreaWorld;
rgArea.setSelectedItem(rAreaSelected);
} else {
for (int i = 0; i < rgArea.getItemCount(); i++) {
if (rgArea.getItemAtIndex(i).isVisible()) {
rAreaSelected = rgArea.getItemAtIndex(i);
rgArea.setSelectedItem(rAreaSelected);
break;
}
}
}
Clients.evalJavaScript("jq('#" + rAreaSelected.getUuid() + "-real').attr('checked', true);");
} catch (Exception e) {
LOGGER.error(StringConstants.UNABLE_TO_LOAD_ACTIVE_AREA_LAYERS, e);
}
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityComposer method createMapLayerForObject.
private MapLayer createMapLayerForObject(JSONObject objJson) {
MapLayer mapLayer = new MapLayer();
mapLayer.setPolygonLayer(true);
//TODO: make it work with contextual layers not yet indexed
List<Facet> facets = new ArrayList<Facet>();
facets.add(new Facet((String) objJson.get(StringConstants.FID), "\"" + objJson.get(StringConstants.NAME) + "\"", true));
mapLayer.setFacets(facets);
DecimalFormat df = new DecimalFormat("###,###.##");
try {
mapLayer.setAreaSqKm(String.valueOf(df.format(objJson.get(StringConstants.AREA_KM))));
} catch (Exception e) {
LOGGER.error("bad area for object: " + facets.get(0).toString());
}
mapLayer.setDisplayName((String) objJson.get(StringConstants.NAME));
return mapLayer;
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityComposer method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
this.selectedMethod = "Phylogenetic Diversity";
this.totalSteps = 3;
this.loadAreaLayers(true);
this.loadSpeciesLayers();
this.updateWindowTitle();
rgSpecies.setSelectedItem((Radio) getFellow("rSpeciesAll"));
fillPDTreeList();
Map m = Executions.getCurrent().getArg();
if (m != null) {
for (Object o : m.entrySet()) {
//apply preselected trees
if (((Map.Entry) o).getKey() instanceof String && "selectedTrees".equals(((Map.Entry) o).getKey())) {
String selectedTrees = (String) ((Map.Entry) o).getValue();
for (String tree : selectedTrees.split(",")) {
for (int i = 0; i < trees.length; i++) {
if (((Map<String, String>) trees[i]).containsValue(tree)) {
treesList.getItemAtIndex(i).setSelected(true);
}
}
}
}
//apply preselected areas
if (((Map.Entry) o).getKey() instanceof String && "selectedAreas".equals(((Map.Entry) o).getKey())) {
String selectedAreas = (String) ((Map.Entry) o).getValue();
for (String area : selectedAreas.split(",")) {
List checkboxes = getFellow("vboxArea").getChildren();
for (int i = 0; i < checkboxes.size(); i++) {
if (checkboxes.get(i) instanceof Checkbox && ((Checkbox) checkboxes.get(i)).getLabel().equals(area)) {
((Checkbox) checkboxes.get(i)).setChecked(true);
}
}
}
}
//apply query filter from mapped species occurrences layer
if (((Map.Entry) o).getKey() instanceof String && "query".equals(((Map.Entry) o).getKey())) {
String layerName = (String) ((Map.Entry) o).getValue();
for (MapLayer ml : getMapComposer().getSpeciesLayers()) {
if (ml.getSpeciesQuery() != null) {
//TODO: review matching criteria
if (ml.getName().equals(layerName)) {
break;
}
}
}
}
}
}
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityComposer method getSelectedAreas.
public List<SelectedArea> getSelectedAreas() {
List<SelectedArea> selectedAreas = new ArrayList<SelectedArea>();
Vbox vboxArea = (Vbox) getFellowIfAny("vboxArea");
for (Component c : vboxArea.getChildren()) {
if ((c instanceof Checkbox) && ((Checkbox) c).isChecked()) {
SelectedArea sa = null;
String area = ((Checkbox) c).getValue();
try {
if (StringConstants.CURRENT.equals(area)) {
sa = new SelectedArea(null, getMapComposer().getViewArea());
} else if (StringConstants.AUSTRALIA.equals(area)) {
sa = new SelectedArea(null, CommonData.getSettings().getProperty(CommonData.AUSTRALIA_WKT));
} else if (StringConstants.WORLD.equals(area)) {
sa = new SelectedArea(null, CommonData.WORLD_WKT);
} else {
List<MapLayer> layers = getMapComposer().getPolygonLayers();
for (MapLayer ml : layers) {
if (area.equals(ml.getName())) {
sa = new SelectedArea(ml, null);
break;
}
}
}
} catch (Exception e) {
LOGGER.warn("Unable to retrieve selected area", e);
}
if (sa != null) {
selectedAreas.add(sa);
}
}
}
//add all areas from a selection
if (autoCompleteLayerSelection != null && cAreasFromLayer.isChecked()) {
if (autoCompleteLayerAreas == null) {
String fieldId = CommonData.getLayerFacetNameDefault(autoCompleteLayerSelection);
JSONParser jp = new JSONParser();
JSONObject objJson = null;
try {
objJson = (JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/field/" + fieldId));
} catch (ParseException e) {
LOGGER.error("failed to parse for: " + fieldId);
}
JSONArray objects = (JSONArray) objJson.get("objects");
autoCompleteLayerAreas = new ArrayList();
for (int i = 0; i < objects.size(); i++) {
MapLayer ml = createMapLayerForObject((JSONObject) objects.get(i));
SelectedArea sa = new SelectedArea(ml, null);
autoCompleteLayerAreas.add(sa);
}
}
selectedAreas.addAll(autoCompleteLayerAreas);
}
return selectedAreas;
}
Aggregations