Search in sources :

Example 21 with MapComposer

use of au.org.emii.portal.composer.MapComposer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaMapPolygon method onClick$btnCancel.

public void onClick$btnCancel(Event event) {
    MapComposer mc = getMapComposer();
    if (layerName != null && mc.getMapLayer(layerName) != null) {
        mc.removeLayer(layerName);
    }
    Clients.evalJavaScript("mapFrame.toggleClickHandler(true);");
    this.detach();
}
Also used : MapComposer(au.org.emii.portal.composer.MapComposer)

Example 22 with MapComposer

use of au.org.emii.portal.composer.MapComposer 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 23 with MapComposer

use of au.org.emii.portal.composer.MapComposer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaAddressRadiusSelection method createRadiusFromAddress.

public void createRadiusFromAddress() {
    String wkt = radiusFromAddress(addressBox.getText());
    if (!StringConstants.NONE.equalsIgnoreCase(wkt)) {
        try {
            MapComposer mc = getMapComposer();
            layerName = (mc.getMapLayer(txtLayerName.getValue()) == null) ? txtLayerName.getValue() : mc.getNextAreaLayerName(txtLayerName.getValue());
            MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, txtLayerName.getValue());
            mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadata(dRadius.getText() + "km radius around " + addressLabel.getValue() + " (" + longitude + ", " + latitude + ")"));
            displayGeom.setText(wkt);
        } catch (Exception e) {
            LOGGER.error("Error adding WKT layer");
        }
    }
}
Also used : MapComposer(au.org.emii.portal.composer.MapComposer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 24 with MapComposer

use of au.org.emii.portal.composer.MapComposer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaBoundingBox method onBoxGeom.

public void onBoxGeom(Event event) {
    String boxGeom = (String) event.getData();
    try {
        if (boxGeom.contains(StringConstants.NAN_NAN)) {
            displayGeom.setValue("");
        } else {
            displayGeom.setValue(boxGeom);
        }
        //get the current MapComposer instance
        MapComposer mc = getMapComposer();
        //add feature to the map as a new layer
        layerName = (mc.getMapLayer(txtLayerName.getValue()) == null) ? txtLayerName.getValue() : mc.getNextAreaLayerName(txtLayerName.getValue());
        MapLayer mapLayer = mc.addWKTLayer(boxGeom, layerName, txtLayerName.getValue());
        mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadataForWKT(CommonData.lang(StringConstants.METADATA_USER_BOUNDING_BOX), boxGeom));
        btnNext.setDisabled(false);
        btnClear.setDisabled(false);
    } catch (Exception e) {
        LOGGER.error("Error adding user bounding box area", e);
    }
}
Also used : MapComposer(au.org.emii.portal.composer.MapComposer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 25 with MapComposer

use of au.org.emii.portal.composer.MapComposer in project spatial-portal by AtlasOfLivingAustralia.

the class AreaUploadShapefile method loadUserLayerKML.

public void loadUserLayerKML(String name, byte[] kmldata, UserDataDTO ud) {
    try {
        String id = String.valueOf(System.currentTimeMillis());
        String kmlpath = "/data/ala/runtime/output/layers/" + id + "/";
        File kmlfilepath = new File(kmlpath);
        kmlfilepath.mkdirs();
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(kmlfilepath.getAbsolutePath() + "/" + name)));
        String kmlstr = new String(kmldata);
        out.write(kmlstr);
        out.close();
        MapComposer mc = getMapComposer();
        layerName = (mc.getMapLayer(txtLayerName.getValue()) == null) ? txtLayerName.getValue() : mc.getNextAreaLayerName(txtLayerName.getValue());
        String wkt = getKMLPolygonAsWKT(kmlstr);
        if (wkt != null && wkt.length() == 0) {
            getMapComposer().showMessage("Failed to find the area in this KML file. \r\n\r\n" + "KML file must have a single placemark within no more than 1 folder.");
            return;
        } else if (wkt == null) {
            getMapComposer().showMessage("Failed to parse this KML file. \r\n\r\n" + "Try importing a Shapefile or WKT instead.");
            return;
        }
        boolean invalid = false;
        String msg = "";
        try {
            WKTReader wktReader = new WKTReader();
            com.vividsolutions.jts.geom.Geometry g = wktReader.read(wkt);
            //NC 20130319: Ensure that the WKT is valid according to the WKT standards.
            IsValidOp op = new IsValidOp(g);
            if (!op.isValid()) {
                //this will fix some issues
                g = g.buffer(0);
                op = new IsValidOp(g);
            }
            if (!op.isValid()) {
                invalid = true;
                LOGGER.warn(CommonData.lang(StringConstants.ERROR_WKT_INVALID) + " " + op.getValidationError().getMessage());
                msg = op.getValidationError().getMessage();
            //TODO Fix invalid WKT text using https://github.com/tudelft-gist/prepair maybe???
            } else if (g.isRectangle()) {
                //NC 20130319: When the shape is a rectangle ensure that the points a specified in the correct order.
                //get the new WKT for the rectangle will possibly need to change the order.
                com.vividsolutions.jts.geom.Envelope envelope = g.getEnvelopeInternal();
                String wkt2 = StringConstants.POLYGON + "((" + envelope.getMinX() + " " + envelope.getMinY() + "," + envelope.getMaxX() + " " + envelope.getMinY() + "," + envelope.getMaxX() + " " + envelope.getMaxY() + "," + envelope.getMinX() + " " + envelope.getMaxY() + "," + envelope.getMinX() + " " + envelope.getMinY() + "))";
                if (!wkt.equals(wkt2)) {
                    LOGGER.debug("NEW WKT for Rectangle: " + wkt);
                    msg = CommonData.lang("error_wkt_anticlockwise");
                    invalid = true;
                }
            }
            if (!invalid) {
                invalid = !op.isValid();
            }
        } catch (ParseException parseException) {
            LOGGER.error(CommonData.lang(StringConstants.ERROR_WKT_INVALID), parseException);
        }
        if (invalid) {
            ok = false;
            getMapComposer().showMessage(CommonData.lang(StringConstants.ERROR_WKT_INVALID) + " " + msg);
        } else {
            MapLayer mapLayer = mc.addWKTLayer(wkt, layerName, txtLayerName.getValue());
            ud.setUploadedTimeInMs(Long.parseLong(id));
            ud.setType("kml");
            String metadata = "";
            metadata += "User uploaded KML area \n";
            metadata += "Name: " + ud.getName() + " <br />\n";
            metadata += "Filename: " + ud.getFilename() + " <br />\n";
            metadata += "Date: " + ud.getDisplayTime() + " <br />\n";
            mapLayer.getMapLayerMetadata().setMoreInfo(metadata);
            if (mapLayer == null) {
                LOGGER.debug("The layer " + name + " couldnt be created");
                mc.showMessage(mc.getLanguagePack().getLang("ext_layer_creation_failure"));
            } else {
                ok = true;
                mc.addUserDefinedLayerToMenu(mapLayer, true);
            }
        }
    } catch (IOException e) {
        getMapComposer().showMessage(CommonData.lang("error_upload_failed"));
        LOGGER.debug("unable to load user kml: ", e);
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) WKTReader(com.vividsolutions.jts.io.WKTReader) MapComposer(au.org.emii.portal.composer.MapComposer) IsValidOp(com.vividsolutions.jts.operation.valid.IsValidOp) Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(com.vividsolutions.jts.io.ParseException)

Aggregations

MapComposer (au.org.emii.portal.composer.MapComposer)38 MapLayer (au.org.emii.portal.menu.MapLayer)20 Listitem (org.zkoss.zul.Listitem)6 HashMap (java.util.HashMap)5 Component (org.zkoss.zk.ui.Component)5 ParseException (com.vividsolutions.jts.io.ParseException)3 JSONObject (org.json.simple.JSONObject)3 ScatterplotDataDTO (au.org.ala.spatial.dto.ScatterplotDataDTO)2 Query (au.org.ala.spatial.util.Query)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Checkbox (org.zkoss.zul.Checkbox)2 Facet (au.org.ala.legend.Facet)1 ToolComposer (au.org.ala.spatial.composer.tool.ToolComposer)1 PortalSession (au.org.emii.portal.session.PortalSession)1 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1