Search in sources :

Example 1 with WebMapServer

use of org.geotools.data.wms.WebMapServer in project spatial-portal by AtlasOfLivingAustralia.

the class AddWMSLayerComposer method onClick$addAllLayersButton.

public void onClick$addAllLayersButton() {
    LOGGER.debug("onClick$addAllLayersButton()");
    // hide (any) previous success message
    resultLabel.setVisible(false);
    // validate - DO NOT SHORT CURCUIT HERE!
    // DO NOT PUT TEST INTO IF STATEMENT (DO NOT SHORT CURCUIT HERE!)
    boolean amc = validateAutomaticModeCommon();
    boolean c = validateCommon();
    if (c && amc) {
        try {
            wmsServer = new WebMapServer(new URL(uri.getValue()));
            discoveredLayer = wmsServer.getCapabilities();
            MapLayer mapLayer = new MapLayer();
            mapLayer.setName(Validate.escapeHtmlAndTrim(label.getValue()));
            String ur = uri.getValue();
            mapLayer.setUri(ur);
            mapLayer.setLayer(layerUtilities.getLayers(ur));
            mapLayer.setOpacity(opacitySlider.getCurpos() / 100.0f);
            mapLayer.setImageFormat(layerUtilities.getImageFormat(ur));
            /* attempt to retrieve bounding box */
            List<Double> bbox = layerUtilities.getBBox(ur);
            if (bbox != null) {
                MapLayerMetadata md = new MapLayerMetadata();
                md.setBbox(bbox);
                md.setMoreInfo(ur);
                mapLayer.setMapLayerMetadata(md);
            }
            /* we don't want our user to have to type loads
                 * when adding a new layer so we just assume/generate
                 * values for the id and description
                 */
            String name = (nameAutomatically.isChecked()) ? "" : Validate.escapeHtmlAndTrim(label.getValue());
            mapLayer.setId(uri + name.replaceAll("\\s+", ""));
            mapLayer.setDescription(name);
            // wms version
            String version = layerUtilities.getVersionValue(ur);
            mapLayer.setType(layerUtilities.internalVersion(version));
            getMapComposer().addUserDefinedLayerToMenu(mapLayer, true);
            updateResult("wms_server_added");
        // addWMSServer handles showing any errors for us
        } catch (Exception e) {
            LOGGER.error("failed to get layer from url", e);
        }
    }
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) WebMapServer(org.geotools.data.wms.WebMapServer) MapLayer(au.org.emii.portal.menu.MapLayer) URL(java.net.URL) MetadataURL(org.geotools.data.wms.xml.MetadataURL)

Example 2 with WebMapServer

use of org.geotools.data.wms.WebMapServer in project spatial-portal by AtlasOfLivingAustralia.

the class AddWMSLayerComposer method onClick$selectLayersButton.

public void onClick$selectLayersButton() {
    LOGGER.debug("onClick$selectLayersButton");
    if (validateAutomaticModeCommon()) {
        try {
            wmsServer = new WebMapServer(new URL(uri.getValue()));
            discoveredLayer = wmsServer.getCapabilities();
            // want list of all
            if (discoveredLayer != null) {
                availableLayers = new ArrayList<String[]>();
                //skip first layer,
                for (int i = 1; i < discoveredLayer.getLayerList().size(); i++) {
                    availableLayers.add(new String[] { String.valueOf(i), discoveredLayer.getLayerList().get(i).getName() + "," + discoveredLayer.getLayerList().get(i).getTitle() });
                }
                updateAvailableLayers();
                selectLayers.setVisible(true);
                selectLayersButton.setDisabled(true);
                addDiscoveredLayerButton.setVisible(true);
            } else {
                // there was an error somewhere..
                getMapComposer().showMessage(CommonData.lang("error_adding_layer"));
            }
        } catch (Exception e) {
            LOGGER.error("map request", e);
        }
    }
}
Also used : WebMapServer(org.geotools.data.wms.WebMapServer) URL(java.net.URL) MetadataURL(org.geotools.data.wms.xml.MetadataURL)

Aggregations

URL (java.net.URL)2 WebMapServer (org.geotools.data.wms.WebMapServer)2 MetadataURL (org.geotools.data.wms.xml.MetadataURL)2 MapLayer (au.org.emii.portal.menu.MapLayer)1 MapLayerMetadata (au.org.emii.portal.menu.MapLayerMetadata)1