Search in sources :

Example 46 with MapLayer

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

the class AddFacetController method onClick$btnOk.

public void onClick$btnOk(Event event) {
    if (btnOk.isDisabled()) {
        return;
    }
    try {
        if (!hasCustomArea && (isAreaCustom() || isAreaHighlightCustom())) {
            this.doOverlapped();
            this.setTop("-9999px");
            this.setLeft("-9999px");
            Map<String, Object> winProps = new HashMap<String, Object>();
            winProps.put(StringConstants.PARENT, this);
            winProps.put(StringConstants.PARENTNAME, "Tool");
            winProps.put(StringConstants.SELECTEDMETHOD, selectedMethod);
            List<MapLayer> layers = getMapComposer().getPolygonLayers();
            if (layers != null && !layers.isEmpty()) {
                prevTopArea = layers.get(0);
            } else {
                prevTopArea = null;
            }
            Window window = (Window) Executions.createComponents("WEB-INF/zul/add/AddArea.zul", this, winProps);
            window.setAttribute("winProps", winProps, true);
            window.setParent(this);
            window.doModal();
            return;
        }
        Div currentDiv = (Div) getFellowIfAny(StringConstants.ATSTEP + currentStep);
        Div nextDiv = (Div) getFellowIfAny(StringConstants.ATSTEP + (currentStep + 1));
        if (!currentDiv.getZclass().contains(StringConstants.LAST)) {
            currentDiv.setVisible(false);
            nextDiv.setVisible(true);
            Html previousStepCompletedImg = (Html) getFellowIfAny(StringConstants.IMG_COMPLETED_STEP + (currentStep));
            previousStepCompletedImg.setVisible(true);
            Label previousStepLabel = (Label) getFellowIfAny(StringConstants.LBLSTEP + (currentStep));
            previousStepLabel.setStyle(StringConstants.FONT_WEIGHT_NORMAL);
            Label currentStepLabel = (Label) getFellowIfAny(StringConstants.LBLSTEP + (currentStep + 1));
            currentStepLabel.setStyle(StringConstants.FONT_WEIGHT_BOLD);
            currentStep++;
            updateWindowTitle();
            fixFocus();
            sa = getSelectedArea();
            query = QueryUtil.queryFromSelectedArea(query, sa, false, getGeospatialKosher());
            if (query != null) {
                List<QueryField> fields = query.getFacetFieldList();
                Collections.sort(fields, new QueryField.QueryFieldComparator());
                String lastGroup = null;
                for (QueryField field : fields) {
                    String newGroup = field.getGroup().getName();
                    if (!newGroup.equals(lastGroup)) {
                        Comboitem sep = new Comboitem(StringConstants.SEPERATOR);
                        sep.setLabel("---------------" + StringUtils.center(newGroup, 19) + "---------------");
                        sep.setParent(cbColour);
                        sep.setDisabled(true);
                        lastGroup = newGroup;
                    }
                    Comboitem ci = new Comboitem(field.getDisplayName());
                    ci.setValue(field.getName());
                    ci.setParent(cbColour);
                }
            }
            btnBack.setDisabled(false);
            btnOk.setDisabled(true);
        } else {
            if (selectedList.size() == 0) {
                btnOk.setDisabled(true);
            }
            Facet f = Facet.parseFacet(getSelectionFacet());
            Query querynew = query.newFacet(f, true);
            if (querynew.getOccurrenceCount() <= 0) {
                getMapComposer().showMessage(CommonData.lang(StringConstants.NO_OCCURRENCES_SELECTED));
            } else {
                getMapComposer().mapSpecies(querynew, StringConstants.MY_FACET, StringConstants.SPECIES, -1, LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
                this.detach();
            }
        }
    } catch (Exception ex) {
        LOGGER.error("error adding facet", ex);
    }
    fixFocus();
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) SuspendNotAllowedException(org.zkoss.zk.ui.SuspendNotAllowedException) QueryField(au.org.ala.legend.QueryField) LegendObject(au.org.ala.legend.LegendObject) Facet(au.org.ala.legend.Facet)

Example 47 with MapLayer

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

the class AddFacetController method loadAreaLayers.

public void loadAreaLayers(String selectedAreaName) {
    try {
        Radiogroup rgArealocal = (Radiogroup) getFellowIfAny("rgArea");
        //remove all radio buttons that don't have an id
        for (int i = rgArealocal.getItemCount() - 1; i >= 0; i--) {
            String id = rgArealocal.getItems().get(i).getId();
            if (id == null || id.length() == 0) {
                rgArealocal.removeItemAt(i);
            } else {
                rgArealocal.getItemAtIndex(i).setSelected(false);
            }
        }
        Radio rAreaCurrent = (Radio) getFellowIfAny("rAreaCurrent");
        String 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(rgArealocal);
            rgArealocal.insertBefore(rAr, rAreaCurrent);
            if (lyr.getName().equals(selectedLayerName)) {
                rSelectedLayer = rAr;
                rAreaSelected = rAr;
            }
        }
        if (selectedAreaName != null && !selectedAreaName.isEmpty()) {
            for (int i = 0; i < rgArealocal.getItemCount(); i++) {
                if (rgArealocal.getItemAtIndex(i).isVisible() && rgArealocal.getItemAtIndex(i).getLabel().equals(selectedAreaName)) {
                    rAreaSelected = rgArealocal.getItemAtIndex(i);
                    LOGGER.debug("2.resetting indexToSelect = " + i);
                    rgArealocal.setSelectedItem(rAreaSelected);
                    break;
                }
            }
        } else if (rSelectedLayer != null) {
            rAreaSelected = rSelectedLayer;
            rgArealocal.setSelectedItem(rAreaSelected);
        } else if (StringConstants.NONE.equals(selectedLayerName)) {
            rgArealocal.setSelectedItem(rAreaWorld);
            rAreaSelected = rAreaWorld;
            rgArealocal.setSelectedItem(rAreaSelected);
        } else {
            rAreaSelected = rAreaWorld;
            rgArealocal.setSelectedItem(rAreaSelected);
        }
        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) SuspendNotAllowedException(org.zkoss.zk.ui.SuspendNotAllowedException)

Example 48 with MapLayer

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

the class AddAreaController method onClick$btnOk.

public void onClick$btnOk(Event event) {
    if (btnOk.isDisabled()) {
        return;
    }
    String windowName = "";
    MapComposer mc = getMapComposer();
    String script = "";
    boolean overlapped = true;
    if (cbAreaSelection.getSelectedItem() == ciBoundingBox) {
        windowName = "WEB-INF/zul/add/area/AreaBoundingBox.zul";
        script = mc.getOpenLayersJavascript().addBoxDrawingTool();
    } else if (cbAreaSelection.getSelectedItem() == ciPolygon) {
        windowName = "WEB-INF/zul/add/area/AreaPolygon.zul";
        script = mc.getOpenLayersJavascript().addPolygonDrawingTool();
    } else if (cbAreaSelection.getSelectedItem() == ciPointAndRadius) {
        windowName = "WEB-INF/zul/add/area/AreaPointAndRadius.zul";
        script = mc.getOpenLayersJavascript().addRadiusDrawingTool();
    } else if (cbAreaSelection.getSelectedItem() == ciRegionSelection) {
        overlapped = false;
        windowName = "WEB-INF/zul/add/area/AreaRegionSelection.zul";
    } else if (cbAreaSelection.getSelectedItem() == ciAddressRadiusSelection) {
        overlapped = false;
        windowName = "WEB-INF/zul/add/area/AreaAddressRadiusSelection.zul";
    } else if (cbAreaSelection.getSelectedItem() == ciRadiusManualSelection) {
        overlapped = false;
        windowName = "WEB-INF/zul/add/area/AreaRadiusManualSelection.zul";
    } else if (cbAreaSelection.getSelectedItem() == ciUploadShapefile) {
        windowName = "WEB-INF/zul/add/area/AreaUploadShapefile.zul";
        overlapped = false;
    } else if (cbAreaSelection.getSelectedItem() == ciUploadKML) {
        windowName = "WEB-INF/zul/add/area/AreaUploadKML.zul";
        overlapped = false;
    } else if (cbAreaSelection.getSelectedItem() == ciMapPolygon) {
        List<MapLayer> layers = getMapComposer().getContextualLayers();
        boolean visibleLayers = false;
        for (MapLayer ml : layers) {
            if (ml.isDisplayed()) {
                visibleLayers = true;
                break;
            }
        }
        if (!visibleLayers) {
            //present layer selection window
            windowName = "WEB-INF/zul/layer/ContextualLayerSelection.zul";
            overlapped = false;
        } else {
            windowName = "WEB-INF/zul/add/area/AreaMapPolygon.zul";
            script = mc.getOpenLayersJavascript().addFeatureSelectionTool();
        }
    } else if (cbAreaSelection.getSelectedItem() == ciEnvironmentalEnvelope) {
        windowName = "WEB-INF/zul/add/area/AreaEnvironmentalEnvelope.zul";
    } else if (cbAreaSelection.getSelectedItem() == ciBoxAustralia) {
        String wkt = CommonData.getSettings().getProperty(CommonData.AUSTRALIA_WKT);
        String layerName = mc.getNextAreaLayerName(CommonData.lang(StringConstants.AUSTRALIA_BOUNDING_BOX));
        MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, layerName);
        mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadata(CommonData.lang(StringConstants.AUSTRALIA_BOUNDING_BOX) + " " + wkt));
        remoteLogger.logMapArea(layerName, "Area - BoxAustralia", wkt);
    } else if (cbAreaSelection.getSelectedItem() == ciBoxWorld) {
        String wkt = CommonData.WORLD_WKT;
        String layerName = mc.getNextAreaLayerName(CommonData.lang(StringConstants.WORLD_BOUNDING_BOX));
        MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, layerName);
        mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadata(CommonData.lang(StringConstants.WORLD_BOUNDING_BOX) + " " + wkt));
        remoteLogger.logMapArea(layerName, "Area - BoxWorld", wkt);
    } else if (cbAreaSelection.getSelectedItem() == ciBoxCurrentView) {
        String wkt = mc.getMapComposer().getViewArea();
        String layerName = mc.getNextAreaLayerName(CommonData.lang(StringConstants.CURRENT_VIEW_AREA));
        MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, layerName);
        mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadata(CommonData.lang(StringConstants.CURRENT_VIEW_AREA) + " " + wkt));
        remoteLogger.logMapArea(layerName, "Area - BoxCurrentView", wkt);
    } else if (cbAreaSelection.getSelectedItem() == ciWKT) {
        windowName = "WEB-INF/zul/add/area/AreaWKT.zul";
    } else if (cbAreaSelection.getSelectedItem() == ciMergeAreas) {
        windowName = "WEB-INF/zul/add/area/AreaMerge.zul";
        overlapped = false;
    }
    if (!windowName.isEmpty()) {
        mc.getOpenLayersJavascript().execute(mc.getOpenLayersJavascript().getIFrameReferences() + script);
        Window window = (Window) Executions.createComponents(windowName, this.getParent(), args);
        try {
            if (overlapped) {
                window.doOverlapped();
            } else {
                window.setParent(this.getParent());
                window.doModal();
            }
        } catch (Exception e) {
            LOGGER.error("error opening window: " + windowName, e);
        }
    } else if (StringConstants.ADDTOOLWINDOW.equals(getParent().getId())) {
        ToolComposer analysisParent = (ToolComposer) this.getParent();
        analysisParent.resetWindow(getMapComposer().getNextAreaLayerName(StringConstants.MY_AREA));
    } else if (StringConstants.ADDFACETWINDOW.equals(getParent().getId())) {
        AddFacetController analysisParent = (AddFacetController) this.getParent();
        analysisParent.resetWindow(getMapComposer().getNextAreaLayerName(StringConstants.MY_AREA));
    }
    if (cbAreaSelection.getSelectedItem() != null) {
        mc.setAttribute(StringConstants.ADDAREAWINDOW, cbAreaSelection.getSelectedItem().getId());
    }
    this.detach();
}
Also used : Window(org.zkoss.zul.Window) MapComposer(au.org.emii.portal.composer.MapComposer) ToolComposer(au.org.ala.spatial.composer.tool.ToolComposer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 49 with MapLayer

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

the class AreaEnvironmentalEnvelope method onClick$filterDone.

public void onClick$filterDone(Event event) {
    ok = true;
    try {
        //create the layer
        StringBuilder sbProcessUrl = new StringBuilder();
        sbProcessUrl.append(CommonData.getSatServer()).append("/ws/envelope?area=").append(getWkt());
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(sbProcessUrl.toString());
        LOGGER.debug(sbProcessUrl.toString());
        post.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        client.executeMethod(post);
        String slist = post.getResponseBodyAsString();
        String[] list = slist.split("\n");
        String pid = list[0];
        String url = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:envelope_" + pid + "&FORMAT=image%2Fpng";
        String activeAreaExtent = list[1];
        activeAreaSize = list[2];
        //load the layer
        layerName = txtLayerName.getText();
        MapLayer ml = mc.addWMSLayer(pid, layerName, url, 0.75f, null, null, LayerUtilitiesImpl.ENVIRONMENTAL_ENVELOPE, null, null);
        //add colour!
        int colour = Util.nextColour();
        int r = (colour >> 16) & 0x000000ff;
        int g = (colour >> 8) & 0x000000ff;
        int b = (colour) & 0x000000ff;
        ml.setRedVal(r);
        ml.setGreenVal(g);
        ml.setBlueVal(b);
        ml.setDynamicStyle(true);
        ml.setPolygonLayer(true);
        getMapComposer().applyChange(ml);
        getMapComposer().updateLayerControls();
        //make the metadata?
        StringBuilder sb = new StringBuilder();
        StringBuilder sbLayerList = new StringBuilder();
        sb.append("Environmental Envelope<br>");
        for (int i = 0; i < selectedLayers.size(); i++) {
            JSONObject layer = selectedLayers.get(i);
            SPLFilter f = getSPLFilter(layer);
            sb.append(f.getLayername()).append(": ").append(f.getFilterString()).append("<br>");
            sbLayerList.append(f.getLayername());
            if (i < selectedLayers.size() - 1) {
                sbLayerList.append(":");
            }
        }
        String activeAreaMetadata = LayersUtil.getMetadata(sb.toString());
        getMapComposer().setAttribute("activeLayerName", sbLayerList.toString());
        getMapComposer().setAttribute("mappolygonlayer", sb.toString());
        String finalWkt = null;
        try {
            finalWkt = getWkt();
        } catch (Exception e) {
            LOGGER.error("failed to get WKT", e);
        }
        this.layerName = ml.getName();
        List<Double> bb = new ArrayList<Double>(4);
        String[] bs = activeAreaExtent.split(",");
        for (int i = 0; i < 4; i++) {
            bb.add(Double.parseDouble(bs[i]));
        }
        ml.getMapLayerMetadata().setBbox(bb);
        ml.getMapLayerMetadata().setMoreInfo(activeAreaMetadata);
        ml.setWKT(StringConstants.ENVELOPE + "(" + finalWkt + ")");
        //not the actual WKT
        ml.setEnvelope(finalWkt);
        try {
            double area = Double.parseDouble(activeAreaSize.replace(",", ""));
            activeAreaSize = String.format("%,.2f", area);
        } catch (NumberFormatException e) {
            LOGGER.error("failed to parse environmental envelope area for: " + activeAreaSize);
        }
        ml.setAreaSqKm(activeAreaSize);
        ml.setFacets(getFacets());
        //this also shows active area
        removeAllSelectedLayers(true);
    } catch (Exception e) {
        LOGGER.error("unable to create envelope layer: ", e);
    }
    //do detach after adding the new layer
    mc.updateLayerControls();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) MapLayer(au.org.emii.portal.menu.MapLayer) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 50 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)

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