Search in sources :

Example 6 with MapLayer

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

the class AreaEnvironmentalEnvelope method loadMap.

private MapLayer loadMap(JSONObject layer, int depth, double min, double max, boolean finalLayer) {
    String colour = finalLayer ? "0xFF0000" : FILTER_COLOURS[depth % FILTER_COLOURS.length];
    //correct for data type conversions
    double correction = 0.0000001;
    String filter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\">" + "<NamedLayer><Name>ALA:" + ((JSONObject) layer.get("layer")).get(StringConstants.NAME) + "</Name>" + "<UserStyle><FeatureTypeStyle><Rule><RasterSymbolizer><Geometry></Geometry>" + "<ColorMap>" + "<ColorMapEntry color=\"" + colour + "\" opacity=\"1\" quantity=\"" + (min - correction) + "\"/>" + "<ColorMapEntry color=\"" + colour + "\" opacity=\"0\" quantity=\"" + (min - correction) + "\"/>" + "<ColorMapEntry color=\"" + colour + "\" opacity=\"0\" quantity=\"" + (max + correction) + "\"/>" + "<ColorMapEntry color=\"" + colour + "\" opacity=\"1\" quantity=\"" + (max + correction) + "\"/>" + "</ColorMap></RasterSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>";
    try {
        filter = URLEncoder.encode(filter, StringConstants.UTF_8);
    } catch (Exception e) {
        LOGGER.error("cannot encode filter sld: " + filter, e);
    }
    MapLayer ml = mc.getMapLayer(LAYER_PREFIX + layer.get(StringConstants.ID));
    if (ml == null) {
        ml = getMapComposer().addWMSLayer(LAYER_PREFIX + layer.get(StringConstants.ID), LAYER_PREFIX + layer.get(StringConstants.NAME), ((JSONObject) layer.get("layer")).get("displaypath").toString().replace("/gwc/service", "") + "&sld_body=" + filter, (float) 0.75, CommonData.getLayersServer() + "/layers/view/more/" + layer.get("spid"), CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + ((JSONObject) layer.get("layer")).get(StringConstants.NAME), LayerUtilitiesImpl.WMS_1_3_0, null, null, null);
    } else {
        ml.setUri(((JSONObject) layer.get("layer")).get("displaypath").toString().replace("/gwc/service", "") + "&sld_body=" + filter);
        mc.reloadMapLayerNowAndIndexes(ml);
    }
    return ml;
}
Also used : JSONObject(org.json.simple.JSONObject) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 7 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 8 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 9 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 10 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)

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