Mercurial > mxd2map
view src/java/de/intevation/mxd/reader/WMSLayerReader.java @ 317:5a2b5bc066eb
Implement Label Styles and Labels with background
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 20 Sep 2012 12:55:21 +0200 |
parents | 5e3a40a84539 |
children | 2e445968851f |
line wrap: on
line source
/* * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> * * This file is part of MXD2map. * * This program is free software under the LGPL (>=v2.1) * Read the file LICENCE.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. * * MXD2map has been developed on behalf of the * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg * by Intevation GmbH. * * Authors: * Raimund Renkert <raimund.renkert@intevation.de> * Bjoern Schilberg <bjoern.schilberg@intevation.de> * Stephan Holl <stephan.holl@intevation.de> */ package de.intevation.mxd.reader; import java.io.IOException; import org.apache.log4j.Logger; import com.esri.arcgis.carto.ILayer; import com.esri.arcgis.carto.IFeatureRenderer; import com.esri.arcgis.carto.WMSMapLayer; import com.esri.arcgis.carto.WMSGroupLayer; import com.esri.arcgis.carto.WMSLayer; import com.esri.arcgis.gisclient.IWMSServiceDescription; import com.esri.arcgis.gisclient.IWMSLayerDescription; import com.esri.arcgis.geometry.Envelope; import org.w3c.dom.Element; import de.intevation.mxd.utils.MapToXMLUtils; /** * Reads Layer information. * * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> */ public class WMSLayerReader { /** * The logger. */ private static final Logger logger = Logger.getLogger(FeatureLayerReader.class); /** * Privte member. */ private WMSLayer layer; private MapToXMLUtils util; private int invalidLayerCount; /** * Constructor with layer. * * @param layer The ArcGIS layer object. */ public WMSLayerReader(ILayer layer) throws Exception { if(layer instanceof WMSLayer) { this.layer = (WMSLayer)layer; invalidLayerCount = 0; } else { throw new Exception("Not an instance of WMSLayer: " + layer.getClass().toString()); } } /** * Setter for XML document helper. * * @param util The helper for storing map information. */ public void setUtil(MapToXMLUtils util) { this.util = util; } /** * Reads the Layer content. * * @return The layer XML element. */ public Element read() throws IOException{ logger.debug("read()"); Element layerElement = null; try { layerElement = util.addLayer(); } catch(Exception e) { logger.error("Failed to create DOM-Element for Layer."); return null; } try { layerElement.setAttribute("name", layer.getName()); } catch(IOException ioe) { logger.warn( "Could not read layer name." + " Stopped reading layer."); throw new IOException("Error reading layer name."); } try { layerElement.setAttribute("min_scale", String.valueOf(layer.getMinimumScale())); } catch(IOException ioe) { logger.debug("Could not read minimum scale."); layerElement.setAttribute("min_scale", "0"); } try { layerElement.setAttribute("max_scale", String.valueOf(layer.getMaximumScale())); } catch(IOException ioe) { logger.debug( "Could not read maximum scale."); layerElement.setAttribute("max_scale", "0"); } try { if(layer.isVisible()) { layerElement.setAttribute("status", "on"); } else { layerElement.setAttribute("status", "off"); } } catch(IOException ioe) { logger.warn( "Could not read layer status." + " Setting layer status to \"on\"."); layerElement.setAttribute("status", "on"); } layerElement.setAttribute("connection_type", "WMS"); try{ // Set the WMS Connection parameters IWMSServiceDescription wmsconn = layer.getWMSServiceDescription(); String connectionURL = wmsconn.getBaseURL("GetMap", "Get"); if (!connectionURL.endsWith("?")) { connectionURL += "?"; } layerElement.setAttribute("connection", connectionURL); logger.debug(connectionURL); layerElement.setAttribute("imageType", wmsconn.getImageFormat(0)); logger.debug(wmsconn.getImageFormat(0)); if (wmsconn.getSRSCount() > 0) { layerElement.setAttribute("projection", wmsconn.getSRS(0)); logger.debug(wmsconn.getSRS(0)); } layerElement.setAttribute("wms_server_version", wmsconn.getWMSVersion()); logger.debug(wmsconn.getWMSVersion()); } catch(Exception e) { logger.debug(e); logger.error("Error Setting Connection parameters. " + layer.getName()); } try{ // Set the WMS Layer parameters IWMSLayerDescription wmslayer = layer.getWMSLayerDescription(); layerElement.setAttribute("wms_name", wmslayer.getName()); } catch(Exception e) { logger.debug(e); logger.error("Error Setting Layer parameters. " + layer.getName()); } return layerElement; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :