Search in sources :

Example 86 with MapLayer

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

the class PointComparison method afterCompose.

@Override
public void afterCompose() {
    super.afterCompose();
    lbPoints.setModel(new SimpleListModel<String[]>(points));
    lbPoints.setItemRenderer(new ListitemRenderer<String[]>() {

        @Override
        public void render(Listitem item, String[] data, int index) throws Exception {
            items.set(index, item);
            Listcell lc = new Listcell(String.valueOf(index + 1));
            lc.setParent(item);
            lc = new Listcell();
            Textbox txt1 = new Textbox(data[0] != null ? data[0] : "");
            lc.setSclass("txtCoordinate");
            txt1.setParent(lc);
            if (index != currentPoint)
                txt1.setDisabled(true);
            lc.setParent(item);
            lc = new Listcell();
            Textbox txt2 = new Textbox(data[1] != null ? data[1] : "");
            lc.setSclass("txtCoordinate");
            txt2.setParent(lc);
            if (index != currentPoint)
                txt2.setDisabled(true);
            lc.setParent(item);
            lc = new Listcell();
            Button b = new Button("edit");
            b.setSclass("btn-mini");
            b.setParent(lc);
            lc.setParent(item);
            b.addEventListener("onClick", new EventListener<Event>() {

                @Override
                public void onEvent(Event event) throws Exception {
                    enablePointClick();
                    disableEdit();
                    ((Textbox) event.getTarget().getParent().getPreviousSibling().getFirstChild()).setDisabled(false);
                    ((Textbox) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getFirstChild()).setDisabled(false);
                    ((Button) event.getTarget().getParent().getNextSibling().getFirstChild()).setDisabled(false);
                    currentPoint = Integer.parseInt(((Listcell) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getPreviousSibling()).getLabel());
                    currentPoint--;
                }
            });
            lc = new Listcell();
            b = new Button("save");
            b.setParent(lc);
            b.setSclass("btn-mini");
            lc.setParent(item);
            if (index != currentPoint)
                b.setDisabled(true);
            b.addEventListener("onClick", new EventListener<Event>() {

                @Override
                public void onEvent(Event event) throws Exception {
                    disableEdit();
                    currentPoint = Integer.parseInt(((Listcell) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getPreviousSibling().getPreviousSibling()).getLabel());
                    currentPoint--;
                    points.get(currentPoint)[1] = ((Textbox) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getFirstChild()).getValue();
                    points.get(currentPoint)[0] = ((Textbox) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getPreviousSibling().getFirstChild()).getValue();
                    MapComposer mc = getMapComposer();
                    layerName = mc.getNextAreaLayerName("Point");
                    mc.deactiveLayer(layers.get(currentPoint), true, false);
                    String pointGeom = "POINT(" + points.get(currentPoint)[0] + " " + points.get(currentPoint)[1] + ")";
                    MapLayer mapLayer = mc.addWKTLayer(pointGeom, layerName, "Point");
                    mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadataForWKT(CommonData.lang(StringConstants.METADATA_USER_BOUNDING_BOX), pointGeom));
                    layers.set(currentPoint, mapLayer);
                }
            });
            lc = new Listcell();
            b = new Button("remove");
            b.setParent(lc);
            b.setSclass("btn-mini");
            lc.setParent(item);
            b.addEventListener("onClick", new EventListener<Event>() {

                @Override
                public void onEvent(Event event) throws Exception {
                    int point = Integer.parseInt(((Listcell) event.getTarget().getParent().getPreviousSibling().getPreviousSibling().getPreviousSibling().getPreviousSibling().getPreviousSibling()).getLabel());
                    ;
                    point--;
                    getMapComposer().deactiveLayer(layers.get(point), true, false);
                    if (currentPoint == point) {
                        currentPoint = -1;
                    }
                    points.remove(point);
                    layers.remove(point);
                    items.remove(point);
                    lbPoints.setModel(new SimpleListModel<Object>(points));
                }
            });
        }
    });
    lbResults.setItemRenderer(new ListitemRenderer<String[]>() {

        @Override
        public void render(Listitem item, String[] data, int index) throws Exception {
            for (int i = 0; i < data.length; i++) {
                Listcell lc = new Listcell(data[i]);
                lc.setParent(item);
            }
        }
    });
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) MapComposer(au.org.emii.portal.composer.MapComposer) Event(org.zkoss.zk.ui.event.Event) JSONObject(org.json.simple.JSONObject) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 87 with MapLayer

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

the class AreaReportPDF method createWKTLayer.

MapLayer createWKTLayer(String wkt, int red, int green, int blue, float opacity) {
    String pid = UserShapes.upload(wkt, "", "", "area_report", CommonData.getSettings().getProperty("api_key"));
    areaPid = pid;
    if (pid != null) {
        //1. create new layer
        MapLayer newml = addObjectByPid(pid, red, green, blue, opacity);
        newml.setDisplayed(true);
        return newml;
    } else {
        LOGGER.error("failed to upload wkt to layers-service");
    }
    return null;
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer)

Example 88 with MapLayer

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

the class AreaReportPDF method addWMSLayer.

public MapLayer addWMSLayer(String name, String displayName, String uri, float opacity, String metadata, String legendUri, int subType, String cqlfilter, String envParams, Query q) {
    MapLayer mapLayer = remoteMap.createAndTestWMSLayer(name, uri, opacity);
    mapLayer.setDisplayName(displayName);
    if (q != null) {
        mapLayer.setSpeciesQuery(q);
    }
    //ok
    mapLayer.setSubType(subType);
    mapLayer.setCql(cqlfilter);
    mapLayer.setEnvParams(envParams);
    String fieldId = mapLayer.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
    String uriActual = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + mapLayer.getLayer() + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
    mapLayer.setDefaultStyleLegendUri(uriActual);
    if (metadata != null) {
        if (metadata.startsWith("http")) {
            mapLayer.getMapLayerMetadata().setMoreInfo(metadata + "\n" + displayName);
        } else {
            mapLayer.getMapLayerMetadata().setMoreInfo(metadata);
        }
    }
    if (legendUri != null) {
        WMSStyle style = new WMSStyle();
        style.setName(StringConstants.DEFAULT);
        style.setDescription("Default style");
        style.setTitle(StringConstants.DEFAULT);
        style.setLegendUri(legendUri);
        mapLayer.addStyle(style);
        mapLayer.setSelectedStyleIndex(1);
        LOGGER.debug("adding WMSStyle with legendUri: " + legendUri);
        mapLayer.setDefaultStyleLegendUriSet(true);
    }
    mapLayer.setDisplayed(true);
    return mapLayer;
}
Also used : WMSStyle(au.org.emii.portal.wms.WMSStyle) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 89 with MapLayer

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

the class AreaReportPDF method initImages.

private void initImages() {
    double aspectRatio = 1.6;
    String type = "png";
    int resolution = 0;
    String basemap = "Minimal";
    mlArea.setColourMode("hatching");
    List<Double> bbox = mlArea.getMapLayerMetadata().getBbox();
    //30% width buffer in decimal degrees
    double step = (bbox.get(2) - bbox.get(0)) * 0.3;
    double[] extents = new double[] { bbox.get(0) - step, bbox.get(1) - step, bbox.get(2) + step, bbox.get(3) + step };
    step = (bbox.get(2) - bbox.get(0)) * 0.05;
    double[] extentsSmall = new double[] { bbox.get(0) - step, bbox.get(1) - step, bbox.get(2) + step, bbox.get(3) + step };
    step = (bbox.get(2) - bbox.get(0)) * 10;
    double[] extentsLarge = new double[] { bbox.get(0) - step, bbox.get(1) - step, bbox.get(2) + step, bbox.get(3) + step };
    if (extentsLarge[2] > 180) {
        extentsLarge[2] = 180;
    }
    if (extentsLarge[0] < -180) {
        extentsLarge[0] = -180;
    }
    if (extentsLarge[1] < -85) {
        extentsLarge[1] = -85;
    }
    if (extentsLarge[3] > 85) {
        extentsLarge[3] = 85;
    }
    setProgress("Getting information: images for map of map", 0);
    if (isCancelled())
        return;
    MapLayer mlSpecies = createSpeciesLayer(query, 0, 0, 255, .6f, false, 9, false);
    List<MapLayer> lifeforms = new ArrayList<MapLayer>();
    for (int i = 0; i < StringConstants.SPECIES_GROUPS.length; i++) {
        String s = StringConstants.SPECIES_GROUPS[i];
        setProgress("Getting information: images for map of lifeform " + s, 0);
        if (isCancelled())
            return;
        lifeforms.add(createSpeciesLayer(query.newFacet(new Facet("species_group", s, true), true), 0, 0, 255, .6f, false, 9, false));
    }
    setProgress("Getting information: images for map of threatened species", 0);
    if (isCancelled())
        return;
    MapLayer threatenedSpecies = createSpeciesLayer(query.newFacet(Facet.parseFacet(CommonData.speciesListThreatened), true), 0, 0, 255, .6f, false, 9, false);
    setProgress("Getting information: images for map of iconic species", 0);
    if (isCancelled())
        return;
    MapLayer iconicSpecies = createSpeciesLayer(query.newFacet(new Facet("species_list_uid", "dr781", true), true), 0, 0, 255, .6f, false, 9, false);
    setProgress("Getting information: images for map of migratory species", 0);
    if (isCancelled())
        return;
    MapLayer migratorySpecies = createSpeciesLayer(query.newFacet(new Facet("species_list_uid", "dr1005", true), true), 0, 0, 255, .6f, false, 9, false);
    setProgress("Getting information: images for map of invasive species", 0);
    if (isCancelled())
        return;
    MapLayer invasiveSpecies = createSpeciesLayer(query.newFacet(Facet.parseFacet(CommonData.speciesListInvasive), true), 0, 0, 255, .6f, false, 9, false);
    String[] layers = CommonData.getSettings().getProperty("detailed_area_report_layers").split("\n");
    for (String layer : layers) {
        if (!layer.isEmpty()) {
            String[] split = layer.trim().split("\\|");
            String shortname = split[0];
            String displayname = split[1];
            String geoserver_url = split[2];
            String canSetColourMode = split[3];
            String description = split[4];
            setProgress("Getting information: images for map of layer " + shortname, 0);
            if (isCancelled())
                return;
            MapLayer ml = createLayer(shortname, 1.0f);
            if ("Y".equalsIgnoreCase(canSetColourMode)) {
                ml.setColourMode("&styles=" + shortname + "&format_options=dpi:600");
            }
            setProgress("Getting information: making map of " + shortname, 0);
            if (isCancelled())
                return;
            saveImage(shortname, new PrintMapComposer(extents, basemap, new MapLayer[] { mlArea, ml }, aspectRatio, "", type, resolution).get());
        }
    }
    setProgress("Getting information: making map of area", 0);
    if (isCancelled())
        return;
    saveImage("base_area", new PrintMapComposer(extents, basemap, new MapLayer[] { mlArea }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making map of area overview", 0);
    if (isCancelled())
        return;
    saveImage("base_area_zoomed_out", new PrintMapComposer(extentsLarge, basemap, new MapLayer[] { mlArea }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making occurrences", 0);
    if (isCancelled())
        return;
    saveImage(StringConstants.OCCURRENCES, new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, mlSpecies }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making threatened species", 0);
    if (isCancelled())
        return;
    saveImage("Threatened_Species", new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, threatenedSpecies }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making iconic species", 0);
    if (isCancelled())
        return;
    saveImage("Iconic_Species", new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, iconicSpecies }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making migratory species", 0);
    if (isCancelled())
        return;
    saveImage("Migratory_Species", new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, migratorySpecies }, aspectRatio, "", type, resolution).get());
    setProgress("Getting information: making invasive species", 0);
    if (isCancelled())
        return;
    saveImage("Invasive_Species", new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, invasiveSpecies }, aspectRatio, "", type, resolution).get());
    for (int i = 0; i < StringConstants.SPECIES_GROUPS.length; i++) {
        setProgress("Getting information: making map of lifeform " + StringConstants.SPECIES_GROUPS[i], 0);
        if (isCancelled())
            return;
        saveImage("lifeform - " + StringConstants.SPECIES_GROUPS[i], new PrintMapComposer(extentsSmall, basemap, new MapLayer[] { mlArea, lifeforms.get(i) }, aspectRatio, "", type, resolution).get());
    }
    //save images
    setProgress("Getting information: saving maps", 0);
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) Facet(au.org.ala.legend.Facet)

Example 90 with MapLayer

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

the class AreaReportPDF method addObjectByPid.

public MapLayer addObjectByPid(String pid, int red, int green, int blue, float opacity) {
    JSONParser jp = new JSONParser();
    JSONObject obj = null;
    try {
        obj = (JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/object/" + pid));
    } catch (ParseException e) {
        LOGGER.error("failed to parse for object: " + pid);
    }
    //add feature to the map as a new layer
    MapLayer mapLayer = addWMSLayer("PID:" + pid, "", obj.get(StringConstants.WMSURL).toString(), opacity, null, null, LayerUtilitiesImpl.WKT, null, null, null);
    mapLayer.setPolygonLayer(true);
    //if the layer is a point create a radius
    String bbox = obj.get(StringConstants.BBOX).toString();
    MapLayerMetadata md = mapLayer.getMapLayerMetadata();
    try {
        List<Double> dbb = Util.getBoundingBox(bbox);
        md.setBbox(dbb);
    } catch (Exception e) {
        LOGGER.debug("failed to parse: " + bbox, e);
    }
    mapLayer.setRedVal(red);
    mapLayer.setGreenVal(green);
    mapLayer.setBlueVal(blue);
    mapLayer.setOpacity(opacity);
    mapLayer.setDynamicStyle(true);
    return mapLayer;
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) JSONObject(org.json.simple.JSONObject) MapLayer(au.org.emii.portal.menu.MapLayer) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException)

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