Search in sources :

Example 66 with MapLayer

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

the class MapComposer method saveSession.

private String saveSession() {
    String jsessionid = getCookieValue("JSESSIONID");
    if (jsessionid == null) {
        jsessionid = "test";
    }
    PrintWriter out = null;
    try {
        String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + jsessionid;
        // if the session dir exists, then clear it,
        // if not let's create it.
        File sessfolder = new File(sfld + "/");
        if (!sessfolder.exists()) {
            sessfolder.mkdirs();
        } else {
            FileUtils.deleteDirectory(sessfolder);
            sessfolder.mkdirs();
        }
        StringBuilder sbSession = new StringBuilder();
        sbSession.append(String.valueOf(mapZoomLevel)).append(",").append(getLeftmenuSearchComposer().getViewportBoundingBox().toString());
        sbSession.append(System.getProperty("line.separator"));
        PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld));
        List list = new XmlArrayList(strategy);
        String scatterplotNames = "";
        List udl = getPortalSession().getActiveLayers();
        Iterator iudl = udl.iterator();
        while (iudl.hasNext()) {
            MapLayer ml = (MapLayer) iudl.next();
            if (ml.getType() != LayerUtilitiesImpl.MAP) {
                if (ml.getSubType() == LayerUtilitiesImpl.SCATTERPLOT) {
                    list.add(ml.getScatterplotDataDTO());
                    scatterplotNames += ((scatterplotNames.length() > 1) ? "___" + ml.getName() : ml.getName());
                } else {
                    list.add(ml);
                }
            }
        }
        sbSession.append("scatterplotNames=").append(scatterplotNames);
        sbSession.append(System.getProperty("line.separator"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(sfld + "/details.txt")));
        out.write(sbSession.toString());
        out.close();
    } catch (Exception e) {
        LOGGER.error("failed to save session", e);
    } finally {
        if (out != null) {
            out.close();
        }
    }
    return CommonData.getWebportalServer() + "?ss=" + jsessionid;
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) ParseException(org.json.simple.parser.ParseException) PersistenceStrategy(com.thoughtworks.xstream.persistence.PersistenceStrategy) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy)

Example 67 with MapLayer

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

the class MapComposer method mapSpecies.

public MapLayer mapSpecies(Query sq, String species, String rank, int count, int subType, String wkt, int setGrid, int size, float opacity, int colour, String colourBy, boolean mapExpertDistribution) {
    String newSpecies = species;
    String newRank = rank;
    if (newSpecies == null) {
        newSpecies = sq.getName();
        newRank = sq.getRank();
    }
    int newCount = count;
    if (newCount < 0) {
        newCount = sq.getOccurrenceCount();
    }
    //use # of points cutoff
    boolean grid;
    if (setGrid == 0) {
        grid = false;
    } else {
        grid = setGrid == 1 || sq.getOccurrenceCount() > Integer.parseInt(getSettingsSupplementary().getProperty("points_cluster_threshold"));
    }
    MapLayer ml = mapSpeciesFilter(sq, newSpecies, newRank, newCount, subType, wkt, grid, size, opacity, colour, mapExpertDistribution);
    if (ml != null) {
        if (colourBy != null) {
            ml.setColourMode(colourBy);
        }
        //for Active Area mapping
        ml.getMapLayerMetadata().setOccurrencesCount(newCount);
        String layerType = "Species - Search";
        if (newSpecies.startsWith("Occurrences in ")) {
            layerType = "Species - Occurrences";
        } else if (StringConstants.SPECIES_ASSEMBLAGE.equals(newSpecies)) {
            layerType = "Species - Assemblage";
        } else if (newSpecies.contains(StringConstants.MY_FACET)) {
            layerType = "Species - Facet";
        }
        if (subType == LayerUtilitiesImpl.SPECIES_UPLOAD) {
            layerType = "Import - Species";
        }
        if (subType == LayerUtilitiesImpl.SPECIES && "user".equals(newRank)) {
            layerType = "Import - LSID";
        }
        if (sq instanceof BiocacheQuery) {
            BiocacheQuery bq = (BiocacheQuery) sq;
            String extra = bq.getWS() + "|" + bq.getBS() + "|" + bq.getFullQ(false);
            remoteLogger.logMapSpecies(ml.getDisplayName(), bq.getLsids(), wkt, layerType, extra);
        } else if (sq instanceof UserDataQuery) {
            remoteLogger.logMapSpecies(ml.getDisplayName(), "user-" + sq.getSpeciesCount() + " records", wkt, layerType, sq.getMetadataHtml());
        } else {
            remoteLogger.logMapSpecies(ml.getDisplayName(), newSpecies, wkt, layerType, sq.getMetadataHtml());
        }
        updateLayerControls();
        refreshContextualMenu();
        // reflect the correct facet
        if (colourBy != null) {
            applyChange(ml);
        }
    }
    return ml;
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 68 with MapLayer

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

the class MapComposer method getMapLayerIdxInLegend.

public int getMapLayerIdxInLegend(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);
    int pos = -1;
    while (iudl.hasNext()) {
        pos++;
        MapLayer ml = (MapLayer) iudl.next();
        LOGGER.debug("layer: " + ml.getName() + " - " + ml.getId() + " - " + ml.getNameJS());
        if (ml.getName().equals(label)) {
            return pos;
        }
    }
    // now check if we can find it using the display name
    return 0;
}
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 69 with MapLayer

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

the class MapComposer method openChecklistSpecies.

void openChecklistSpecies(String lsids, String wkt, boolean mapIfOnlyOne) {
    try {
        //species checklists
        String[] finallist = Util.getDistributionsOrChecklists(StringConstants.CHECKLISTS, wkt, lsids, null);
        //open for optional mapping of areas
        if (finallist.length > 1) {
            if (mapIfOnlyOne && finallist.length == 2) {
                try {
                    String[] row;
                    CSVReader csv = new CSVReader(new StringReader(finallist[1]));
                    row = csv.readNext();
                    csv.close();
                    if (getMapLayerWMS(CommonData.getSpeciesChecklistWMSFromSpcode(row[0])[1]) == null) {
                        //map it
                        String[] mapping = CommonData.getSpeciesChecklistWMSFromSpcode(row[0]);
                        String displayName = mapping[0] + " area";
                        if (row[11] != null && row[11].length() > 0) {
                            displayName = row[11];
                        }
                        String layerName = getNextAreaLayerName(row[0] + " area");
                        String html = Util.getMetadataHtmlForDistributionOrChecklist(row[0], row, layerName);
                        MapLayer ml = getMapComposer().addWMSLayer(layerName, displayName, mapping[1], 0.6f, html, null, LayerUtilitiesImpl.WKT, null, null);
                        ml.setSPCode(row[0]);
                        setupMapLayerAsDistributionArea(ml);
                    }
                } catch (Exception e) {
                    LOGGER.error("error opening checklist species", e);
                }
            } else {
                if (hasFellow(StringConstants.DISTRIBUTION_RESULTS)) {
                    getFellowIfAny(StringConstants.DISTRIBUTION_RESULTS).detach();
                }
                Map params = new HashMap();
                params.put(StringConstants.TITLE, "Checklist species");
                params.put(StringConstants.SIZE, String.valueOf(finallist.length - 1));
                params.put(StringConstants.TABLE, finallist);
                Window window = (Window) Executions.createComponents("WEB-INF/zul/results/AnalysisDistributionResults.zul", this, params);
                try {
                    window.setParent(this);
                    window.doModal();
                } catch (Exception e) {
                    LOGGER.error("error opening checklist species dialog", e);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("error opening distribution area dialog", e);
    }
}
Also used : Window(org.zkoss.zul.Window) CSVReader(au.com.bytecode.opencsv.CSVReader) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) RemoteMap(au.org.emii.portal.util.RemoteMap) ParseException(org.json.simple.parser.ParseException)

Example 70 with MapLayer

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

the class MapComposer method getActiveLayersSelection.

/**
     * Return the MapLayer instance associated with the item currently selected
     * in the active layers listbox or null if no item is currently selected.
     * <p/>
     * If nothing is selected and alertOnNoSelection is set true, show the user
     * a message and return null
     *
     * @return selected MapLayer instance or null if there is nothing selected
     */
public MapLayer getActiveLayersSelection(boolean alertOnNoSelection) {
    MapLayer mapLayer = null;
    // only one item can be selected at a time
    Listitem selected = activeLayersList.getSelectedItem();
    if (selected != null) {
        mapLayer = selected.getValue();
    } else if (alertOnNoSelection) {
        showMessage(languagePack.getLang("active_layer_not_selected"));
    }
    return mapLayer;
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) 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