Mercurial > mxd2map
view src/java/de/intevation/mxd/reader/WMSLayerReader.java @ 346:ab4e4c4b83c9
Add Install_Linux.txt with all my notes from the installtion
this file should be cleaned for publishing
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 16 Nov 2012 17:02:07 +0100 |
parents | 2e445968851f |
children |
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)); } String wms_version = wmsconn.getWMSVersion(); if (wms_version != "1.0.0" && wms_version != "1.0.7" && wms_version != "1.1.0" && wms_version != "1.1.1") { logger.warn("WMS Version " + wms_version + " not supported by" + "Mapserver. Falling back to Version 1.1.1"); wms_version = "1.1.1"; } layerElement.setAttribute("wms_server_version", wms_version); } 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 :