Search in sources :

Example 36 with MapLayer

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

the class MapComposer method onClick$removeAllLayers.

public void onClick$removeAllLayers() {
    if (safeToPerformMapAction()) {
        List<MapLayer> activeLayers = getPortalSession().getActiveLayers();
        StringBuilder script = new StringBuilder();
        while (activeLayers.size() > 1) {
            MapLayer mapLayer = activeLayers.get(0);
            if (mapLayer.getType() != LayerUtilitiesImpl.MAP) {
                script.append(openLayersJavascript.removeMapLayer(mapLayer));
                // skip executing JS and reseting the layer controls - do
                // them at the end
                deactiveLayer(mapLayer, false, false);
            }
        }
        updateLayerControls();
        refreshContextualMenu();
        openLayersJavascript.execute(openLayersJavascript.getIFrameReferences() + script.toString());
    }
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 37 with MapLayer

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

the class MapComposer method loadUrlParameters.

/**
     * Parsing of "q" and "fq" params
     *
     * @return
     */
private MapLayer loadUrlParameters() {
    MapLayer mapLayer = null;
    String params = null;
    try {
        String analysisLayerSelections = getCookieValue("analysis_layer_selections");
        if (analysisLayerSelections != null) {
            String[] s = URLDecoder.decode(analysisLayerSelections, StringConstants.UTF_8).split("\n");
            for (int i = 0; i < s.length; i++) {
                String[] ls = s[i].split(" // ");
                if (ls.length > 1) {
                    selectedLayers.add(new LayerSelection(ls[0], ls[1]));
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("error loading url parameters", e);
    }
    String tool = null;
    String toolParameters = null;
    try {
        params = Executions.getCurrent().getDesktop().getQueryString();
        LOGGER.debug("User params: " + params);
        List<Entry<String, String>> userParams = Util.getQueryParameters(params);
        StringBuilder sb = new StringBuilder();
        String qc = null;
        String bs = null;
        String ws = null;
        String wkt = null;
        int size = 4;
        float opacity = 0.6f;
        int colour = 0xff0000;
        String pointtype = "auto";
        String bb = null;
        Double lat = null;
        Double lon = null;
        Double radius = null;
        String colourBy = null;
        String savedsession = "";
        String s = null;
        boolean[] geospatialKosher = null;
        boolean supportDynamic = false;
        String qname = null;
        Boolean includeDistributions = true;
        for (int i = 0; i < userParams.size(); i++) {
            String key = userParams.get(i).getKey();
            String value = userParams.get(i).getValue();
            if ("wmscache".equals(key)) {
                useSpeciesWMSCache = value;
            }
            if ("tool".equals(key)) {
                tool = value;
            }
            if ("toolParameters".equals(key)) {
                toolParameters = value;
            }
            if ("species_lsid".equals(key)) {
                sb.append("lsid:").append(value);
            } else if ("q".equals(key)) {
                //relies on spitonparams (biocachequery)
                s = value;
                //remove brackets to make it work
                if (value.startsWith("(") && value.endsWith(")") && !value.contains(" ")) {
                    s = value.substring(1, value.length() - 2);
                }
            } else if ("qname".equals(key)) {
                qname = value;
            } else if ("fq".equals(key)) {
                //flag geospatialKosher filters separately
                boolean[] gk;
                if ((gk = BiocacheQuery.parseGeospatialKosher(value)) != null) {
                    geospatialKosher = gk;
                } else {
                    //use as-is
                    //spitonparams (biocachequery) splits these
                    sb.append("&").append(key).append("=").append(value);
                }
            } else if ("qc".equals(key)) {
                if (StringUtils.isNotEmpty(qc)) {
                    qc = "&qc=" + URLEncoder.encode(value, StringConstants.UTF_8);
                }
            } else if ("bs".equals(key)) {
                bs = value;
            } else if ("ws".equals(key)) {
                ws = value;
            } else if (StringConstants.WKT.equals(key)) {
                wkt = value;
            } else if ("psize".equals(key)) {
                size = Integer.parseInt(value);
            } else if ("popacity".equals(key)) {
                opacity = Float.parseFloat(value);
            } else if ("pcolour".equals(key)) {
                colour = Integer.parseInt(value, 16);
            } else if ("ptype".equals(key)) {
                pointtype = value;
            } else if (StringConstants.BBOX.equals(key)) {
                bb = value;
            } else if ("lat".equals(key)) {
                lat = Double.parseDouble(value);
            } else if ("lon".equals(key)) {
                lon = Double.parseDouble(value);
            } else if ("radius".equals(key)) {
                radius = Double.parseDouble(value);
            } else if ("ss".equals(key)) {
                savedsession = value.trim();
            } else if ("dynamic".equals(key)) {
                supportDynamic = Boolean.parseBoolean(value);
            } else if ("cm".equals(key)) {
                colourBy = value.trim();
            } else if ("includeDistributions".equals(key)) {
                try {
                    includeDistributions = Boolean.parseBoolean(value.trim());
                } catch (Exception e) {
                }
            }
        }
        if (lat != null && lon != null && radius != null) {
            //m to km
            wkt = Util.createCircleJs(lon, lat, radius * 1000);
        }
        if (StringUtils.isNotBlank(savedsession)) {
            loadUserSession(savedsession);
        } else {
            LOGGER.debug("No saved session to load");
        }
        LOGGER.debug("url query: " + sb.toString());
        if (sb.length() > 0 || (s != null && s.length() > 0)) {
            if (s != null) {
                s += sb.toString();
            } else {
                s = sb.toString();
            }
            BiocacheQuery q = new BiocacheQuery(null, wkt, s, null, true, geospatialKosher, bs, ws, supportDynamic);
            if (qc != null) {
                q.setQc(qc);
            }
            if (getMapLayerDisplayName(q.getSolrName()) == null) {
                if (bb == null) {
                    List<Double> bbox = q.getBBox();
                    String script = "map.zoomToExtent(new OpenLayers.Bounds(" + bbox.get(0) + "," + bbox.get(1) + "," + bbox.get(2) + "," + bbox.get(3) + ")" + ".transform(" + "  new OpenLayers.Projection('EPSG:4326')," + "  map.getProjectionObject()));";
                    openLayersJavascript.setAdditionalScript(script);
                }
                //mappable attributes
                int setGrid = -1;
                if (pointtype.equals(StringConstants.GRID)) {
                    setGrid = 1;
                } else if ("point".equals(pointtype)) {
                    setGrid = 0;
                }
                mapLayer = mapSpecies(q, qname != null ? qname : q.getSolrName(), StringConstants.SPECIES, q.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, setGrid, size, opacity, colour, colourBy, includeDistributions);
            }
        }
        mapMultiQueryLayers(geospatialKosher, bs, ws, supportDynamic);
    } catch (Exception e) {
        LOGGER.debug("Error loading url parameters: " + params, e);
    }
    //load any deep linked layers
    mapLayerFromParams();
    //load any deep linked objects
    mapObjectFromParams();
    if (tool != null) {
        //open this tool
        try {
            JSONParser jp = new JSONParser();
            Map map = new HashMap<String, Object>();
            if (toolParameters != null) {
                JSONObject jo = (JSONObject) jp.parse(toolParameters);
                for (Object key : jo.keySet()) {
                    map.put(key.toString(), jo.get(key));
                }
            }
            if ("phylogeneticdiversity".equals(tool)) {
                openModal("WEB-INF/zul/tool/PhylogeneticDiversity.zul", map, StringConstants.ADDTOOLWINDOW);
            } else if ("exportspeciesexternal".equals(tool)) {
                //assume bccvl is logged in at this stage
                openModal("WEB-INF/zul/output/ExportSpeciesExternal.zul", null, StringConstants.ADDTOOLWINDOW);
            }
        } catch (Exception e) {
            LOGGER.error("failed to open tool: " + tool, e);
        }
    }
    return mapLayer;
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) ParseException(org.json.simple.parser.ParseException) Entry(java.util.Map.Entry) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject) RemoteMap(au.org.emii.portal.util.RemoteMap)

Example 38 with MapLayer

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

the class MapComposer method mapLoaded.

public void mapLoaded(String text) {
    boolean loaded = Boolean.parseBoolean(text);
    getPortalSession().setMapLoaded(loaded);
    BoundingBox bb = getPortalSession().getDefaultBoundingBox();
    if (loaded) {
        LOGGER.debug("map is now loaded. let's try mapping.");
        MapLayer ml = loadUrlParameters();
        if (ml == null) {
            openLayersJavascript.useAdditionalScript();
        }
    }
    openLayersJavascript.zoomToBoundingBox(bb, false);
}
Also used : BoundingBox(au.org.emii.portal.value.BoundingBox) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 39 with MapLayer

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

the class MapComposer method getMapLayerDisplayName.

public MapLayer getMapLayerDisplayName(String label) {
    // check if layer already present
    List udl = getPortalSession().getActiveLayers();
    Iterator iudl = udl.iterator();
    LOGGER.debug("session active layers: " + udl.size() + " looking for: " + label);
    while (iudl.hasNext()) {
        MapLayer ml = (MapLayer) iudl.next();
        LOGGER.debug("layer: " + ml.getName() + " - " + ml.getId() + " - " + ml.getNameJS());
        if (ml.getDisplayName().equals(label)) {
            return ml;
        }
    }
    return null;
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List)

Example 40 with MapLayer

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

the class LayerLegendScatterplotController method onSelect$cbHighlightArea.

public void onSelect$cbHighlightArea(Event event) {
    if (cbHighlightArea.getSelectedItem() != null) {
        if (cbHighlightArea.getSelectedItem().getValue() instanceof MapLayer) {
            MapLayer ml = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(ml, ml.getFacets() == null ? ml.getWKT() : null);
            data.setHighlightSa(sa);
        } else {
            String wkt = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(null, wkt);
            data.setHighlightSa(sa);
        }
    } else {
        data.setHighlightSa(null);
    }
    try {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplot/style/" + data.getId());
        //add style parameters (highlight area)
        if (data.getHighlightSa() != null) {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, data.getHighlightSa().getWkt());
        } else {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, "");
        }
        post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
        client.executeMethod(post);
    } catch (Exception e) {
        LOGGER.error("error getting a new scatterplot id", e);
    }
    data.setImagePath(null);
    redraw();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient)

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