Search in sources :

Example 61 with MapLayer

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

the class MapComposer method loadScatterplot.

public void loadScatterplot(ScatterplotDataDTO data, String lyrName) {
    MapLayer ml = mapSpecies(data.getQuery(), lyrName, StringConstants.SPECIES, 0, LayerUtilitiesImpl.SCATTERPLOT, null, 0, DEFAULT_POINT_SIZE, DEFAULT_POINT_OPACITY, Util.nextColour(), false);
    ml.setDisplayName(lyrName);
    ml.setSubType(LayerUtilitiesImpl.SCATTERPLOT);
    ml.setType(LayerUtilitiesImpl.SCATTERPLOT);
    ml.setScatterplotDataDTO(data);
    addUserDefinedLayerToMenu(ml, true);
    updateLayerControls();
    refreshContextualMenu();
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 62 with MapLayer

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

the class MapComposer method loadUserSession.

public void loadUserSession(String sessionid) {
    onClick$removeAllLayers();
    Scanner scanner = null;
    try {
        String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + sessionid;
        File sessfolder = new File(sfld);
        if (!sessfolder.exists()) {
            showMessage("Session information does not exist. Please provide a valid session id");
            return;
        }
        scanner = new Scanner(new File(sfld + "/details.txt"));
        // first grab the zoom level and bounding box
        String[] mapdetails = scanner.nextLine().split(",");
        BoundingBox bb = new BoundingBox();
        bb.setMinLongitude(Float.parseFloat(mapdetails[1]));
        bb.setMinLatitude(Float.parseFloat(mapdetails[2]));
        bb.setMaxLongitude(Float.parseFloat(mapdetails[3]));
        bb.setMaxLatitude(Float.parseFloat(mapdetails[4]));
        openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true));
        String[] scatterplotNames = null;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.startsWith("scatterplotNames")) {
                scatterplotNames = line.substring(17).split("___");
            }
        }
        ArrayUtils.reverse(scatterplotNames);
        // ignore fields not found
        XStream xstream = new XStream(new DomDriver()) {

            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {

                    public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                        if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName))
                            System.out.println("faled to read: " + definedIn + ", " + fieldName);
                        return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
                    }
                };
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader) {
                Object o = super.unmarshal(reader);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root) {
                Object o = super.unmarshal(reader, root);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
                Object o = super.unmarshal(reader, root, dataHolder);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }
        };
        PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream);
        List list = new XmlArrayList(strategy);
        ListIterator it = list.listIterator(list.size());
        int scatterplotIndex = 0;
        while (it.hasPrevious()) {
            Object o = it.previous();
            MapLayer ml = null;
            if (o instanceof MapLayer) {
                ml = (MapLayer) o;
                LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed());
                addUserDefinedLayerToMenu(ml, false);
            } else if (o instanceof ScatterplotDataDTO) {
                ScatterplotDataDTO spdata = (ScatterplotDataDTO) o;
                loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++);
            }
            if (ml != null) {
                addUserDefinedLayerToMenu(ml, true);
            }
        }
    } catch (Exception e) {
        try {
            File f = new File("/data/sessions/" + sessionid + ".txt");
            PrintWriter pw = new PrintWriter(f);
            e.printStackTrace(pw);
            pw.close();
        } catch (Exception ex) {
        }
        LOGGER.error("Unable to load session data", e);
        showMessage("Unable to load session data");
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        try {
            File f = new File("/data/sessions/ok/" + sessionid + ".txt");
            FileUtils.writeStringToFile(f, "ok");
        } catch (Exception ex) {
        }
    }
}
Also used : ScatterplotDataDTO(au.org.ala.spatial.dto.ScatterplotDataDTO) XStream(com.thoughtworks.xstream.XStream) 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) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) DataHolder(com.thoughtworks.xstream.converters.DataHolder) BoundingBox(au.org.emii.portal.value.BoundingBox) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy)

Example 63 with MapLayer

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

the class MapComposer method mapObjectFromParams.

/**
     * Maps environmental and contextual layers from a "&layers" param. Uses the
     * short name of the layer. e.g. "aspect" or ""
     */
public void mapObjectFromParams() {
    Map<String, String> userParams = getQueryParameterMap(Executions.getCurrent().getDesktop().getQueryString());
    if (userParams != null) {
        String pidsAsString = userParams.get(StringConstants.PID);
        if (StringUtils.trimToNull(pidsAsString) == null) {
            return;
        }
        String[] pids = pidsAsString.trim().split(",");
        List<MapLayer> mapLayers = getMapComposer().getPortalSession().getActiveLayers();
        Map<String, MapLayer> names = new HashMap<String, MapLayer>();
        for (MapLayer ml : mapLayers) {
            names.put(ml.getName(), ml);
        }
        for (String pid : pids) {
            if (names.get("PID:" + pid) == null) {
                MapLayer mapLayer = getMapComposer().addObjectByPid(pid, null, 1);
                if (pids.length == 1) {
                    //zoom to this region
                    getMapComposer().zoomToExtent(mapLayer);
                }
            } else if (pids.length == 1) {
                MapLayer mapLayer = names.get("PID:" + pid);
                getMapComposer().zoomToExtent(mapLayer);
            }
        }
    }
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 64 with MapLayer

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

the class MapComposer method onReloadLayers.

/**
     * Reload all species layers
     */
public void onReloadLayers(Event event) {
    String tbxReloadLayers;
    if (event == null) {
        mapZoomLevel = getLeftmenuSearchComposer().getZoom();
        tbxReloadLayers = (new StringBuffer()).append("z=").append(String.valueOf(mapZoomLevel)).append("&amp;b=").append(getLeftmenuSearchComposer().getViewportBoundingBox().toString()).toString();
    } else {
        tbxReloadLayers = (String) event.getData();
        String s = tbxReloadLayers;
        int s1 = s.indexOf("z=");
        int s2 = s.indexOf('&');
        if (s1 >= 0) {
            if (s2 >= 0) {
                mapZoomLevel = Integer.parseInt(s.substring(s1 + 2, s2));
            } else {
                mapZoomLevel = Integer.parseInt(s.substring(s1 + 2));
            }
        }
    }
    LOGGER.debug("tbxReloadLayers.getValue(): " + tbxReloadLayers);
    // iterate thru' active map layers
    List udl = getPortalSession().getActiveLayers();
    Iterator iudl = udl.iterator();
    List<String> processedLayers = new ArrayList();
    String reloadScript = "";
    while (iudl.hasNext()) {
        MapLayer ml = (MapLayer) iudl.next();
        if (processedLayers.contains(ml.getName())) {
            LOGGER.debug(ml.getName() + " already processed.");
            continue;
        }
        LOGGER.debug("checking reload layer: " + ml.getName() + " - " + ml.getId() + " - " + ml.getNameJS() + " -> type: " + ml.getType() + "," + ml.getGeometryType());
        processedLayers.add(ml.getName());
    }
    if (reloadScript.length() > 0) {
        openLayersJavascript.execute(openLayersJavascript.getIFrameReferences() + reloadScript);
    }
}
Also used : HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List)

Example 65 with MapLayer

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

the class MapComposer method addWMSLayer.

/*
     * Public utility methods to interogate the state of the form controls
     */
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 = null;
    if (safeToPerformMapAction()) {
        if (portalSessionUtilities.getUserDefinedById(getPortalSession(), uri) == null) {
            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("^.*&styles=", "").replaceAll("&.*", "").replaceAll("_style", "");
            String newUri = 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(newUri);
            if (metadata != null && 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);
            }
            addUserDefinedLayerToMenu(mapLayer, true);
        } else {
            // fail
            showMessage(languagePack.getLang("wms_layer_already_exists"));
            LOGGER.debug("refusing to add a new layer with URI " + uri + " because it already exists in the menu");
        }
    }
    return mapLayer;
}
Also used : WMSStyle(au.org.emii.portal.wms.WMSStyle) 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