svn-gvsig-desktop / tmp / trunk / cliente / WorkSpace_WPSClient / extWPSCallejero / src / es / logex / gvsig / fmap / layers / FLyrWPS.java @ 26601
History | View | Annotate | Download (9.94 KB)
1 |
package es.logex.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.Graphics2D; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.awt.image.BufferedImage; |
6 |
import java.io.IOException; |
7 |
import java.net.MalformedURLException; |
8 |
import java.net.URL; |
9 |
import java.util.HashMap; |
10 |
|
11 |
|
12 |
import javax.swing.ImageIcon; |
13 |
|
14 |
import org.apache.commons.logging.Log; |
15 |
import org.apache.commons.logging.LogFactory; |
16 |
import org.cresques.cts.IProjection; |
17 |
|
18 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
19 |
import com.iver.andami.PluginServices; |
20 |
import com.iver.cit.gvsig.fmap.DriverException; |
21 |
import com.iver.cit.gvsig.fmap.MapContext; |
22 |
import com.iver.cit.gvsig.fmap.ViewPort; |
23 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
24 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
25 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
27 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
28 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
29 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
30 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
31 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
32 |
import com.iver.utiles.StringUtilities; |
33 |
import com.iver.utiles.XMLEntity; |
34 |
|
35 |
import com.iver.utiles.swing.threads.Cancellable; |
36 |
|
37 |
import es.logex.gvsig.fmap.drivers.wps.FMapWPSDriver; |
38 |
import es.logex.gvsig.fmap.drivers.wps.FMapWPSDriverFactory; |
39 |
|
40 |
|
41 |
public class FLyrWPS extends FLyrVect implements WithDefaultLegend { |
42 |
|
43 |
private URL host = null; // va incluido el nombre de la operación. |
44 |
private String processName = null; /* |
45 |
* Proceso wps a partir del cual se
|
46 |
* obtiene la capa
|
47 |
*/
|
48 |
private String layerId = null; |
49 |
private String name = null; |
50 |
private FMapWPSDriver wpsDriver = null; |
51 |
private String srs = null; |
52 |
private Log logger = LogFactory.getLog(this.getClass()); |
53 |
|
54 |
private Rectangle2D fullExtent; |
55 |
private boolean firstLoad = false; |
56 |
private String defaultLegendPath = null; |
57 |
|
58 |
// WPSAdapter adapter = null;
|
59 |
/**
|
60 |
* Constructor
|
61 |
*/
|
62 |
public FLyrWPS(){
|
63 |
super();
|
64 |
} |
65 |
|
66 |
public FLyrWPS(String layerId, String name, String srs, URL host, double minScale, double maxScale) { |
67 |
this();
|
68 |
|
69 |
this.layerId = layerId;
|
70 |
this.name = name;
|
71 |
this.srs = srs;
|
72 |
this.host = host;
|
73 |
this.setMinScale(minScale);
|
74 |
this.setMaxScale(maxScale);
|
75 |
} |
76 |
// public FLyrWPS() {
|
77 |
// super();
|
78 |
//
|
79 |
// this.layerId = layerId;
|
80 |
// this.name = smlInfo.getName();
|
81 |
// this.srs = smlInfo.getDefaultSRS();
|
82 |
// this.host = smlInfo.getHost();
|
83 |
// this.smlInfo = smlInfo;
|
84 |
// this.setMinScale(smlInfo.getMinScale());
|
85 |
// this.setMaxScale(smlInfo.getMaxScale());
|
86 |
// }
|
87 |
public void setDefaultLegendPath(String defaultLegendPath) { |
88 |
this.defaultLegendPath = defaultLegendPath;
|
89 |
} |
90 |
|
91 |
public void setSrs(String srs) { |
92 |
this.srs = srs;
|
93 |
} |
94 |
|
95 |
public void setName(String layerName) { |
96 |
this.name = layerName;
|
97 |
} |
98 |
public void setHost(URL operationsUrl) { |
99 |
this.host = operationsUrl;
|
100 |
|
101 |
} |
102 |
|
103 |
public ImageIcon getTocImageIcon() { |
104 |
return new ImageIcon(PluginServices.getPluginServices("es.logex.gvsig.wps").getClassLoader().getResource("images/icoLayer.gif")); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Método llamado para la carga con su this.fullExtent y su this.getProjection.
|
109 |
*/
|
110 |
public void load() { |
111 |
load(this.fullExtent, this.getProjection(), "0"); |
112 |
} |
113 |
|
114 |
public void load(Rectangle2D extent, IProjection projection, String detailLevel) { |
115 |
|
116 |
try {
|
117 |
if (logger.isTraceEnabled()) {
|
118 |
logger.trace(this);
|
119 |
} |
120 |
|
121 |
if (firstLoad) {
|
122 |
firstLoad = false;
|
123 |
} else {
|
124 |
|
125 |
wpsDriver.loadGeometries(extent, projection, this.layerId, detailLevel);
|
126 |
if (!detailLevel.equalsIgnoreCase("SAMPLE")) |
127 |
this.fullExtent = extent;
|
128 |
|
129 |
if (getLegend() == null) { |
130 |
if (wpsDriver.getFieldCount() > 0) |
131 |
setDefaultLegend(); |
132 |
} else {
|
133 |
this.setLegend((VectorialLegend)this.getLegend()); |
134 |
} |
135 |
} |
136 |
|
137 |
} catch (FieldNotFoundException e) {
|
138 |
// TODO Auto-generated catch block
|
139 |
e.printStackTrace(); |
140 |
} catch (DriverException e) {
|
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace(); |
143 |
|
144 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
145 |
// TODO Auto-generated catch block
|
146 |
e.printStackTrace(); |
147 |
} catch (Exception e) { |
148 |
e.printStackTrace(); |
149 |
} |
150 |
} |
151 |
|
152 |
public String getSrs() { |
153 |
return srs;
|
154 |
} |
155 |
|
156 |
public void setWpsDriver(FMapWPSDriver driver) { |
157 |
this.wpsDriver = driver;
|
158 |
} |
159 |
|
160 |
public FMapWPSDriver getWpsDriver() {
|
161 |
// TODO Auto-generated method stub
|
162 |
return wpsDriver;
|
163 |
} |
164 |
|
165 |
@SuppressWarnings("unchecked") |
166 |
public HashMap getProperties() { |
167 |
HashMap info = new HashMap(); |
168 |
info.put("name", getName());
|
169 |
info.put("layerName", getName());
|
170 |
info.put("layerText", getLayerText());
|
171 |
info.put("processName", getProcessName());
|
172 |
// info.put("attributes", getFields());
|
173 |
info.put("host", getHost());
|
174 |
|
175 |
// info.put("wfsLayerNode", getWfsLayerNode());
|
176 |
/*
|
177 |
* WFSStatus status = new WFSStatus(getLayerName());
|
178 |
* status.setBuffer(getNumfeatures()); status.setTimeout(getTimeout());
|
179 |
* status.setUserName(getUserName()); status.setPassword(getPassword());
|
180 |
* status.setFilterQuery(getFieldsQuery());
|
181 |
* status.setFilterVisualText(getVisualFilterQuery());
|
182 |
* info.put("status",status);
|
183 |
*/
|
184 |
return info;
|
185 |
} |
186 |
|
187 |
private Object getHost() { |
188 |
return host;
|
189 |
} |
190 |
|
191 |
private Object getProcessName() { |
192 |
return processName;
|
193 |
} |
194 |
|
195 |
public String getName() { |
196 |
return name;
|
197 |
} |
198 |
|
199 |
public String getAbstract() throws Exception { |
200 |
// TODO Implementar
|
201 |
throw new Exception("Not implemented"); |
202 |
} |
203 |
|
204 |
public String getTitle() throws Exception { |
205 |
// TODO Implementar
|
206 |
throw new Exception("Not implemented"); |
207 |
} |
208 |
|
209 |
public String getLayerId() { |
210 |
return this.layerId; |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
215 |
Cancellable cancel, double scale) throws DriverException { |
216 |
if(logger.isDebugEnabled())
|
217 |
{ |
218 |
logger.debug("Dibujar escala: ".concat(String.valueOf(scale)). |
219 |
concat(" minScale:").concat(String.valueOf(getMinScale())) |
220 |
.concat(" maxScale:").concat(String.valueOf(getMaxScale()))); |
221 |
} |
222 |
|
223 |
Rectangle2D newExtent = viewPort.getAdjustedExtent();// .getExtent(); |
224 |
if(isWithinScale(scale))
|
225 |
{ |
226 |
//if(driver.getFullExtent() == null || !driver.getFullExtent().contains(newExtent))
|
227 |
if (this.fullExtent == null || !this.fullExtent.contains(newExtent)) |
228 |
load(newExtent, viewPort.getProjection(), "0");
|
229 |
//this.smlInfo.setLastExtent(newExtent);
|
230 |
|
231 |
} |
232 |
|
233 |
super.draw(image, g, viewPort, cancel, scale);
|
234 |
} |
235 |
|
236 |
private void setDefaultLegend() { |
237 |
LegendManager lm = new LegendManager();
|
238 |
|
239 |
try {
|
240 |
if (defaultLegendPath != null ) { |
241 |
lm.setLegend((FLyrVect) this, defaultLegendPath);
|
242 |
} else {
|
243 |
setLegend(LegendFactory.createSingleSymbolLegend( |
244 |
getShapeType())); |
245 |
} |
246 |
|
247 |
} catch (FieldNotFoundException e) {
|
248 |
// TODO Auto-generated catch block
|
249 |
e.printStackTrace(); |
250 |
} catch (DriverException e) {
|
251 |
// TODO Auto-generated catch block
|
252 |
e.printStackTrace(); |
253 |
} |
254 |
} |
255 |
|
256 |
public void reload() { |
257 |
MapContext mapContext = ((View) PluginServices.getMDIManager().getActiveWindow())
|
258 |
.getMapControl().getMapContext(); |
259 |
|
260 |
this.load(mapContext.getViewPort().getAdjustedExtent(),
|
261 |
mapContext.getViewPort().getProjection(),"0");
|
262 |
} |
263 |
|
264 |
public Legend getDefaultLegend() {
|
265 |
// TODO Auto-generated method stub
|
266 |
return null; |
267 |
} |
268 |
|
269 |
/**
|
270 |
* Devuelve el XMLEntity con la informaci�n necesaria para reproducir la
|
271 |
* capa.
|
272 |
*
|
273 |
* @return XMLEntity.
|
274 |
* @throws XMLException
|
275 |
*/
|
276 |
public XMLEntity getXMLEntity() throws XMLException { |
277 |
XMLEntity xml = super.getXMLEntity();
|
278 |
|
279 |
//name
|
280 |
xml.putProperty("name", this.name); |
281 |
|
282 |
//layerId
|
283 |
xml.putProperty("layerId", layerId);
|
284 |
|
285 |
// Full extent
|
286 |
try {
|
287 |
xml.putProperty("fullExtent", StringUtilities.rect2String(this.wpsDriver.getFullExtent())); |
288 |
} catch (IOException e) { |
289 |
// TODO Auto-generated catch block
|
290 |
e.printStackTrace(); |
291 |
} |
292 |
|
293 |
// Host
|
294 |
xml.putProperty("host", host.toExternalForm());
|
295 |
|
296 |
//Projection
|
297 |
xml.putProperty("projection",getProjection().getAbrev());
|
298 |
|
299 |
// SRS
|
300 |
xml.putProperty("srs", getSrs());
|
301 |
xml.putProperty("geometryType", this.wpsDriver.getShapeType()); |
302 |
//
|
303 |
// SRS
|
304 |
/*xml.putProperty("srs", m_SRS);
|
305 |
if (status!=null)
|
306 |
status.getXMLEntity(xml, true, this);
|
307 |
else{
|
308 |
status = new StatusLayerRaster();
|
309 |
status.getXMLEntity(xml, true, this);
|
310 |
}*/
|
311 |
|
312 |
return xml;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* @param xml XMLEntity
|
317 |
*
|
318 |
* @throws XMLException
|
319 |
* @throws DriverException
|
320 |
* @throws DriverI OException
|
321 |
*/
|
322 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
323 |
|
324 |
//fullExtent
|
325 |
fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
326 |
"fullExtent"));
|
327 |
// Host
|
328 |
try {
|
329 |
host = new URL(xml.getStringProperty("host")); |
330 |
} catch (MalformedURLException e) { |
331 |
throw new XMLException(e); |
332 |
} |
333 |
|
334 |
// Layer name
|
335 |
this.layerId = (xml.getStringProperty("layerId")); |
336 |
setName(xml.getStringProperty("name"));
|
337 |
|
338 |
// SRS
|
339 |
if (xml.contains("srs")){ |
340 |
setSrs(xml.getStringProperty("srs"));
|
341 |
} |
342 |
|
343 |
//Projection
|
344 |
if (xml.contains("projection")){ |
345 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
|
346 |
} |
347 |
|
348 |
|
349 |
try {
|
350 |
wpsDriver = FMapWPSDriverFactory.getFMapDriverForWPSOperation(host); |
351 |
this.setWpsDriver(wpsDriver);
|
352 |
if(xml.contains("geometryType")) |
353 |
{ |
354 |
this.wpsDriver.setShapeType(xml.getIntProperty("geometryType")); |
355 |
} |
356 |
|
357 |
WPSAdapter adapter = new WPSAdapter();
|
358 |
adapter.setDriver((VectorialDriver) wpsDriver); |
359 |
setSource(adapter); |
360 |
//si no cargamos las geometrías no se entera del número de campos que tiene y no puede etiquetar,
|
361 |
//ya que hasta ahora lo único que hemos hecho ha sido conectarnos al servidor
|
362 |
wpsDriver.loadGeometries(fullExtent, getProjection(), this.layerId, "0"); |
363 |
super.setXMLEntity(xml);
|
364 |
setLegend(LegendFactory.createFromXML(xml.getChild(0)));
|
365 |
|
366 |
firstLoad = true;
|
367 |
} catch (Exception e) { |
368 |
throw new XMLException(e); |
369 |
} |
370 |
|
371 |
//TODO: Instanciar su smlInfo
|
372 |
/*WFSLayerNode layer = driver.getLayerInfo(getLayerName());
|
373 |
XMLElement[] atts = null;
|
374 |
*/
|
375 |
|
376 |
|
377 |
//setWfsLayerNode(layer);
|
378 |
//setFields(atts);
|
379 |
setAvailable(true);
|
380 |
} |
381 |
|
382 |
@Override
|
383 |
public int getShapeType() |
384 |
{ |
385 |
return wpsDriver.getShapeType();
|
386 |
} |
387 |
} |