Search in sources :

Example 51 with MapLayer

use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaPointAndRadius method onSelectionGeom.

/**
     * @param event
     */
public void onSelectionGeom(Event event) {
    String selectionGeom = (String) event.getData();
    try {
        String wkt = "";
        if (selectionGeom.contains(StringConstants.NAN_NAN)) {
            displayGeom.setValue("");
        } else if (selectionGeom.startsWith("LAYER(")) {
            //get WKT from this feature
            String v = selectionGeom.replace("LAYER(", "");
            v = v.substring(0, v.length() - 1);
            //for display
            wkt = Util.wktFromJSON(getMapComposer().getMapLayer(v).getGeoJSON());
            displayGeom.setValue(wkt);
        } else {
            wkt = selectionGeom;
            displayGeom.setValue(wkt);
        }
        //get the current MapComposer instance
        MapComposer mc = getMapComposer();
        //add feature to the map as a new layer
        if (wkt.length() > 0) {
            layerName = (mc.getMapLayer(txtLayerName.getValue()) == null) ? txtLayerName.getValue() : mc.getNextAreaLayerName(txtLayerName.getValue());
            MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, txtLayerName.getValue());
            mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadataForWKT(CommonData.lang(StringConstants.METADATA_POINT_AND_RADIUS), wkt));
        }
        btnNext.setDisabled(false);
        btnClear.setDisabled(false);
    } catch (Exception e) {
        LOGGER.error("error mapping point and radius", e);
    }
}
Also used : MapComposer(au.org.emii.portal.composer.MapComposer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 52 with MapLayer

use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaMapPolygon method loadLayerSelection.

public void loadLayerSelection() {
    try {
        Radio rSelectedLayer = (Radio) getFellowIfAny("rSelectedLayer");
        List<MapLayer> layers = getMapComposer().getContextualLayers();
        if (!layers.isEmpty()) {
            for (int i = 0; i < layers.size(); i++) {
                MapLayer lyr = layers.get(i);
                Radio rAr = new Radio(lyr.getDisplayName());
                rAr.setId(lyr.getDisplayName().replaceAll(" ", ""));
                rAr.setValue(lyr.getDisplayName());
                rAr.setParent(rgPolygonLayers);
                if (i == 0) {
                    rAr.setSelected(true);
                }
                rgPolygonLayers.insertBefore(rAr, rSelectedLayer);
            }
            rSelectedLayer.setSelected(true);
        }
    } catch (Exception e) {
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) Radio(org.zkoss.zul.Radio)

Example 53 with MapLayer

use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaMapPolygon method onSearchPoint.

/**
     * Searches the gazetter at a given point and then maps the polygon feature
     * found at the location (for the current top contextual layer).
     *
     * @param event
     */
public void onSearchPoint(Event event) {
    String searchPoint = (String) event.getData();
    String lon = searchPoint.split(",")[0];
    String lat = searchPoint.split(",")[1];
    LOGGER.debug("*************************************");
    LOGGER.debug("CommonData.getLayerList");
    LOGGER.debug("*************************************");
    JSONArray layerlist = CommonData.getLayerListJSONArray();
    MapComposer mc = getMapComposer();
    List<MapLayer> activeLayers = getPortalSession().getActiveLayers();
    Boolean searchComplete = false;
    for (int i = 0; i < activeLayers.size(); i++) {
        MapLayer ml = activeLayers.get(i);
        String activeLayerName = StringConstants.NONE;
        if (ml.getUri() != null) {
            activeLayerName = ml.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
        }
        LOGGER.debug("ACTIVE LAYER: " + activeLayerName);
        if (ml.isDisplayed() && ml.isContextualLayer()) {
            for (int j = 0; j < layerlist.size() && !searchComplete; j++) {
                JSONObject field = (JSONObject) layerlist.get(j);
                JSONObject layer = (JSONObject) field.get("layer");
                if (layer.get(StringConstants.TYPE) != null && layer.get(StringConstants.TYPE).toString().length() > 0 && StringConstants.CONTEXTUAL.equalsIgnoreCase(layer.get(StringConstants.TYPE).toString()) && field.get(StringConstants.ID).toString().equalsIgnoreCase(activeLayerName)) {
                    LOGGER.debug(ml.getName());
                    Map<String, String> feature = GazetteerPointSearch.pointSearch(lon, lat, activeLayerName, CommonData.getGeoServer());
                    if (feature == null || !feature.containsKey(StringConstants.PID)) {
                        continue;
                    }
                    layerName = (mc.getMapLayer(txtLayerName.getValue()) == null) ? txtLayerName.getValue() : mc.getNextAreaLayerName(txtLayerName.getValue());
                    getMapComposer().addObjectByPid(feature.get(StringConstants.PID), layerName, 1);
                    //found the object on the layer
                    btnOk.setDisabled(false);
                    btnClear.setDisabled(false);
                    mc.updateLayerControls();
                    searchComplete = true;
                    displayGeom.setValue("layer: " + feature.get(StringConstants.LAYERNAME) + "\r\n" + "area: " + feature.get(StringConstants.VALUE));
                    return;
                }
            }
        }
    }
}
Also used : MapComposer(au.org.emii.portal.composer.MapComposer) JSONObject(org.json.simple.JSONObject) MapLayer(au.org.emii.portal.menu.MapLayer) JSONArray(org.json.simple.JSONArray)

Example 54 with MapLayer

use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaMapPolygon method onClick$btnOk.

public void onClick$btnOk(Event event) {
    MapLayer ml = getMapComposer().getMapLayer(layerName);
    ml.setDisplayName(txtLayerName.getValue());
    getMapComposer().redrawLayersList();
    ok = true;
    Clients.evalJavaScript("mapFrame.toggleClickHandler(true);");
    String activeLayerName = StringConstants.NONE;
    if (ml.getUri() != null) {
        activeLayerName = ml.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
    }
    getMapComposer().setAttribute("activeLayerName", activeLayerName);
    try {
        if (rgPolygonLayers.getSelectedItem() == null) {
            if (rgPolygonLayers.getItemCount() > 0) {
                getMapComposer().setAttribute("mappolygonlayer", rgPolygonLayers.getItemAtIndex(0).getValue());
            }
        } else {
            getMapComposer().setAttribute("mappolygonlayer", rgPolygonLayers.getSelectedItem().getValue());
        }
    } catch (Exception e) {
        LOGGER.error("failed to set map area polygon selected by the radio button selection", e);
    }
    this.detach();
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer)

Example 55 with MapLayer

use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.

the class AddSpeciesInArea method onFinish.

public void onFinish() {
    try {
        SelectedArea sa = getSelectedArea();
        boolean setupMetadata = true;
        MapLayer ml = null;
        Query q = QueryUtil.queryFromSelectedArea(query, sa, true, geospatialKosher);
        if (byLsid) {
            ml = getMapComposer().mapSpecies(q, name, s, featureCount, type, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), expertDistributions);
        } else if (filter) {
            ml = getMapComposer().mapSpecies(q, name, s, featureCount, type, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), expertDistributions);
        } else if (filterGrid) {
            ml = getMapComposer().mapSpecies(q, name, s, featureCount, type, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), expertDistributions);
        } else if (rank != null && taxon != null && q != null) {
            ml = getMapComposer().mapSpecies(q, taxon, rank, -1, LayerUtilitiesImpl.SPECIES, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), expertDistributions);
            setupMetadata = false;
        } else {
            int resultsCountOccurrences = q.getOccurrenceCount();
            //test limit
            if (resultsCountOccurrences > 0 && resultsCountOccurrences <= Integer.parseInt(CommonData.getSettings().getProperty(StringConstants.MAX_RECORD_COUNT_MAP))) {
                String activeAreaLayerName = getSelectedAreaDisplayName();
                String layerName = CommonData.lang("occurrences_in_area_prefix") + " " + activeAreaLayerName;
                if (multipleSpeciesUploadName != null) {
                    layerName = multipleSpeciesUploadName;
                } else {
                    if (q instanceof BiocacheQuery) {
                        String lsids = ((BiocacheQuery) q).getLsids();
                        if (lsids != null && lsids.length() > 0 && lsids.split(",").length > 1) {
                            layerName = CommonData.lang("species_assemblage_layer_name");
                        }
                    }
                }
                ml = getMapComposer().mapSpecies(q, layerName, StringConstants.SPECIES, resultsCountOccurrences, LayerUtilitiesImpl.SPECIES, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), expertDistributions);
            } else {
                getMapComposer().showMessage(CommonData.lang("error_too_many_occurrences_for_mapping").replace("<counted_occurrences>", resultsCountOccurrences + "").replace("<max_occurrences>", CommonData.getSettings().getProperty(StringConstants.MAX_RECORD_COUNT_MAP)));
            }
            setupMetadata = false;
        }
        if (setupMetadata) {
            ml.getMapLayerMetadata().setMoreInfo(metadata);
        }
        LOGGER.debug("metadata: " + metadata);
    } catch (Exception e) {
        LOGGER.error("error adding species in area to map", e);
    }
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer)

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