Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/WMSLayerReader.java @ 301:2cb2d8eb56ed
Add WMS Support in the Reader classes and
add new Reader classes for WMS Layers
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 05 Sep 2012 16:19:18 +0200 |
parents | |
children | 5e3a40a84539 |
comparison
equal
deleted
inserted
replaced
300:215ae6199b95 | 301:2cb2d8eb56ed |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> | |
3 * | |
4 * This file is part of MXD2map. | |
5 * | |
6 * This program is free software under the LGPL (>=v2.1) | |
7 * Read the file LICENCE.txt coming with the software for details | |
8 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
9 * | |
10 * MXD2map has been developed on behalf of the | |
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg | |
12 * by Intevation GmbH. | |
13 * | |
14 * Authors: | |
15 * Raimund Renkert <raimund.renkert@intevation.de> | |
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de> | |
17 * Stephan Holl <stephan.holl@intevation.de> | |
18 */ | |
19 | |
20 package de.intevation.mxd.reader; | |
21 | |
22 import java.io.IOException; | |
23 | |
24 import org.apache.log4j.Logger; | |
25 | |
26 import com.esri.arcgis.carto.ILayer; | |
27 import com.esri.arcgis.carto.IFeatureRenderer; | |
28 import com.esri.arcgis.carto.WMSMapLayer; | |
29 import com.esri.arcgis.carto.WMSGroupLayer; | |
30 import com.esri.arcgis.carto.WMSLayer; | |
31 import com.esri.arcgis.gisclient.IWMSServiceDescription; | |
32 import com.esri.arcgis.gisclient.IWMSLayerDescription; | |
33 import com.esri.arcgis.geometry.Envelope; | |
34 | |
35 import org.w3c.dom.Element; | |
36 | |
37 import de.intevation.mxd.utils.MapToXMLUtils; | |
38 | |
39 | |
40 /** | |
41 * Reads Layer information. | |
42 * | |
43 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> | |
44 */ | |
45 public class WMSLayerReader { | |
46 | |
47 /** | |
48 * The logger. | |
49 */ | |
50 private static final Logger logger = | |
51 Logger.getLogger(FeatureLayerReader.class); | |
52 | |
53 /** | |
54 * Privte member. | |
55 */ | |
56 private WMSLayer layer; | |
57 private MapToXMLUtils util; | |
58 private int invalidLayerCount; | |
59 | |
60 /** | |
61 * Constructor with layer. | |
62 * | |
63 * @param layer The ArcGIS layer object. | |
64 */ | |
65 public WMSLayerReader(ILayer layer) | |
66 throws Exception { | |
67 if(layer instanceof WMSLayer) { | |
68 this.layer = (WMSLayer)layer; | |
69 invalidLayerCount = 0; | |
70 } | |
71 else { | |
72 throw new Exception("Not an instance of WMSLayer: " + | |
73 layer.getClass().toString()); | |
74 } | |
75 } | |
76 | |
77 /** | |
78 * Setter for XML document helper. | |
79 * | |
80 * @param util The helper for storing map information. | |
81 */ | |
82 public void setUtil(MapToXMLUtils util) { | |
83 this.util = util; | |
84 } | |
85 | |
86 /** | |
87 * Reads the Layer content. | |
88 * | |
89 * @return The layer XML element. | |
90 */ | |
91 public Element read() | |
92 throws IOException{ | |
93 logger.debug("read()"); | |
94 Element layerElement = null; | |
95 try { | |
96 layerElement = util.addLayer(); | |
97 } | |
98 catch(Exception e) { | |
99 logger.error("Failed to create DOM-Element for Layer."); | |
100 return null; | |
101 } | |
102 try { | |
103 layerElement.setAttribute("name", layer.getName()); | |
104 } | |
105 catch(IOException ioe) { | |
106 logger.warn( | |
107 "Could not read layer name." + | |
108 " Stopped reading layer."); | |
109 throw new IOException("Error reading layer name."); | |
110 } | |
111 | |
112 try { | |
113 layerElement.setAttribute("min_scale", | |
114 String.valueOf(layer.getMinimumScale())); | |
115 } | |
116 catch(IOException ioe) { | |
117 logger.warn("Could not read minimum scale."); | |
118 } | |
119 | |
120 try { | |
121 layerElement.setAttribute("max_scale", | |
122 String.valueOf(layer.getMaximumScale())); | |
123 } | |
124 catch(IOException ioe) { | |
125 logger.warn( | |
126 "Could not read maximum scale."); | |
127 } | |
128 | |
129 try { | |
130 if(layer.isVisible()) { | |
131 layerElement.setAttribute("status", "on"); | |
132 } | |
133 else { | |
134 layerElement.setAttribute("status", "off"); | |
135 } | |
136 } | |
137 catch(IOException ioe) { | |
138 logger.warn( | |
139 "Could not read layer status." + | |
140 " Setting layer status to \"on\"."); | |
141 layerElement.setAttribute("status", "on"); | |
142 } | |
143 | |
144 layerElement.setAttribute("connection_type", "WMS"); | |
145 | |
146 try{ | |
147 // Set the WMS Connection parameters | |
148 IWMSServiceDescription wmsconn = layer.getWMSServiceDescription(); | |
149 | |
150 String connectionURL = wmsconn.getBaseURL("GetMap", "Get"); | |
151 if (!connectionURL.endsWith("?")) { | |
152 connectionURL += "?"; | |
153 } | |
154 layerElement.setAttribute("connection", connectionURL); | |
155 logger.debug(connectionURL); | |
156 layerElement.setAttribute("imageType", wmsconn.getImageFormat(0)); | |
157 logger.debug(wmsconn.getImageFormat(0)); | |
158 if (wmsconn.getSRSCount() > 0) { | |
159 layerElement.setAttribute("projection", wmsconn.getSRS(0)); | |
160 logger.debug(wmsconn.getSRS(0)); | |
161 } | |
162 layerElement.setAttribute("wms_server_version", wmsconn.getWMSVersion()); | |
163 logger.debug(wmsconn.getWMSVersion()); | |
164 } | |
165 catch(Exception e) { | |
166 logger.debug(e); | |
167 logger.error("Error Setting Connection parameters. " + layer.getName()); | |
168 } | |
169 | |
170 try{ | |
171 // Set the WMS Layer parameters | |
172 IWMSLayerDescription wmslayer = layer.getWMSLayerDescription(); | |
173 layerElement.setAttribute("wms_name", wmslayer.getName()); | |
174 } | |
175 catch(Exception e) { | |
176 logger.debug(e); | |
177 logger.error("Error Setting Layer parameters. " + layer.getName()); | |
178 } | |
179 return layerElement; | |
180 } | |
181 } | |
182 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |