Search in sources :

Example 1 with WmsCapabilities

use of com.revolsys.gis.wms.capabilities.WmsCapabilities in project com.revolsys.open by revolsys.

the class WmsClient method getMapUrl.

public UrlResource getMapUrl(final List<String> layers, final List<String> styles, final String srid, final BoundingBox envelope, final String format, final int width, final int height) {
    final WmsCapabilities capabilities = getCapabilities();
    final String version = capabilities.getVersion();
    final Map<String, Object> parameters = new LinkedHashMap<>();
    parameters.put("SERVICE", "WMS");
    if (version.equals("1.0.0")) {
        parameters.put(WmsParameters.WMTVER, version);
        parameters.put(WmsParameters.REQUEST, WmsParameterValues.MAP);
    } else {
        parameters.put(WmsParameters.VERSION, version);
        parameters.put(WmsParameters.REQUEST, WmsParameterValues.GET_MAP);
    }
    parameters.put(WmsParameters.LAYERS, Strings.toString(layers));
    String style;
    if (styles == null) {
        style = "";
    } else {
        style = Strings.toString(styles);
        for (int i = styles.size(); i < layers.size(); i++) {
            style += ",";
        }
    }
    parameters.put(WmsParameters.STYLES, style);
    if (version.equals("1.3.0")) {
        parameters.put(WmsParameters.CRS, srid);
    } else {
        parameters.put(WmsParameters.SRS, srid);
    }
    final String bbox = envelope.getMinX() + "," + envelope.getMinY() + "," + envelope.getMaxX() + "," + envelope.getMaxY();
    parameters.put(WmsParameters.BBOX, bbox);
    parameters.put(WmsParameters.WIDTH, width);
    parameters.put(WmsParameters.HEIGHT, height);
    parameters.put(WmsParameters.FORMAT, format);
    final String exceptionFormat = capabilities.getExceptionFormat();
    parameters.put(WmsParameters.EXCEPTIONS, exceptionFormat);
    parameters.put(WmsParameters.TRANSPARENT, "TRUE");
    // = getCapabilities().getRequestUrl("GetMap",
    UrlResource requestUrl = null;
    // "GET");
    if (requestUrl == null) {
        requestUrl = getServiceUrl();
    }
    return requestUrl.newUrlResource(parameters);
}
Also used : UrlResource(com.revolsys.spring.resource.UrlResource) WmsCapabilities(com.revolsys.gis.wms.capabilities.WmsCapabilities) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with WmsCapabilities

use of com.revolsys.gis.wms.capabilities.WmsCapabilities in project com.revolsys.open by revolsys.

the class WmsClient method loadCapabilities.

public WmsCapabilities loadCapabilities() {
    final Map<String, Object> parameters = new LinkedHashMap<>();
    parameters.put(WmsParameters.SERVICE, WmsParameterValues.WMS);
    parameters.put(WmsParameters.REQUEST, WmsParameterValues.GET_CAPABILITIES);
    final UrlResource capabilitiesUrl = newServiceUrlResource(parameters);
    try (InputStream in = capabilitiesUrl.getInputStream()) {
        final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setValidating(false);
        documentBuilderFactory.setNamespaceAware(true);
        final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        final Document document = documentBuilder.parse(in);
        this.capabilities = new WmsCapabilities(this, document.getDocumentElement());
        return this.capabilities;
    } catch (final Throwable e) {
        throw Exceptions.wrap("Unable to read capabilities: " + capabilitiesUrl, e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) UrlResource(com.revolsys.spring.resource.UrlResource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) WmsCapabilities(com.revolsys.gis.wms.capabilities.WmsCapabilities)

Aggregations

WmsCapabilities (com.revolsys.gis.wms.capabilities.WmsCapabilities)2 UrlResource (com.revolsys.spring.resource.UrlResource)2 LinkedHashMap (java.util.LinkedHashMap)2 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1