Search in sources :

Example 81 with MapLayer

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;
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer)

Example 82 with MapLayer

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);
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) IOException(java.io.IOException)

Example 83 with MapLayer

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;
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ParseException(org.json.simple.parser.ParseException) Facet(au.org.ala.legend.Facet)

Example 84 with 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;
                        }
                    }
                }
            }
        }
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 85 with MapLayer

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;
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ParseException(org.json.simple.parser.ParseException) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) Component(org.zkoss.zk.ui.Component)

Aggregations

MapLayer (au.org.emii.portal.menu.MapLayer)131 HasMapLayer (au.org.emii.portal.menu.HasMapLayer)34 JSONObject (org.json.simple.JSONObject)24 MapComposer (au.org.emii.portal.composer.MapComposer)20 ParseException (org.json.simple.parser.ParseException)18 IOException (java.io.IOException)16 MapLayerMetadata (au.org.emii.portal.menu.MapLayerMetadata)15 SelectedArea (au.org.emii.portal.menu.SelectedArea)14 Facet (au.org.ala.legend.Facet)12 List (java.util.List)10 XmlArrayList (com.thoughtworks.xstream.persistence.XmlArrayList)9 JSONParser (org.json.simple.parser.JSONParser)9 JSONArray (org.json.simple.JSONArray)8 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 SuspendNotAllowedException (org.zkoss.zk.ui.SuspendNotAllowedException)7 LegendObject (au.org.ala.legend.LegendObject)6 Component (org.zkoss.zk.ui.Component)6 Geometry (com.vividsolutions.jts.geom.Geometry)5 ParseException (com.vividsolutions.jts.io.ParseException)5