Statistics
| Revision:

svn-gvsig-desktop / branches / MULTITHREADING_DEVELOPMENT / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / FLyrWMS.java @ 5230

History | View | Annotate | Download (81 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Component;
44
import java.awt.Dimension;
45
import java.awt.Graphics2D;
46
import java.awt.Point;
47
import java.awt.Rectangle;
48
import java.awt.geom.AffineTransform;
49
import java.awt.geom.NoninvertibleTransformException;
50
import java.awt.geom.Point2D;
51
import java.awt.geom.Rectangle2D;
52
import java.awt.image.BufferedImage;
53
import java.awt.image.DataBuffer;
54
import java.io.File;
55
import java.io.IOException;
56
import java.lang.reflect.Constructor;
57
import java.lang.reflect.InvocationTargetException;
58
import java.net.MalformedURLException;
59
import java.net.URL;
60
import java.util.ArrayList;
61
import java.util.HashMap;
62
import java.util.Hashtable;
63
import java.util.Iterator;
64
import java.util.Map;
65
import java.util.TimerTask;
66
import java.util.Vector;
67

    
68
import javax.swing.JOptionPane;
69

    
70
import org.cresques.geo.ViewPortData;
71
import org.cresques.io.GdalFile;
72
import org.cresques.io.GeoRasterFile;
73
import org.cresques.io.raster.RasterFilterStack;
74
import org.cresques.io.raster.RasterFilterStackManager;
75
import org.cresques.px.Extent;
76
import org.cresques.px.PxRaster;
77
import org.exolab.castor.xml.ValidationException;
78
import org.gvsig.remoteClient.utils.Utilities;
79
import org.gvsig.remoteClient.wms.WMSStatus;
80

    
81
import com.iver.andami.PluginServices;
82
import com.iver.andami.messages.NotificationManager;
83
import com.iver.cit.gvsig.fmap.DriverException;
84
import com.iver.cit.gvsig.fmap.ViewPort;
85
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
86
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
87
import com.iver.cit.gvsig.fmap.drivers.WMSException;
88
import com.iver.cit.gvsig.fmap.drivers.WMSListener;
89
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
90
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle;
91
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
92
import com.iver.cit.gvsig.fmap.operations.Cancellable;
93
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
94
import com.iver.cit.gvsig.wmc.WebMapContextTags;
95
import com.iver.utiles.StringUtilities;
96
import com.iver.utiles.XMLEntity;
97

    
98
/**
99
* FMap's WMS Layer class.
100
*
101
* @author Jaume Dominguez Faus
102
*                   Nacho Brodin
103
* 
104
*/
105
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
106
        private boolean                                         isPrinting = false;
107
        private boolean                                         mustTileDraw = false;
108
        private boolean                                         mustTilePrint = true;
109
        private final int                                         maxTileDrawWidth = -1;
110
        private final int                                         maxTileDrawHeight = -1;
111
        private final int                                         maxTilePrintWidth = 1200;
112
        private final int                                         maxTilePrintHeight = 1200;
113
    
114
    public URL                                                         host;
115
    public String                                                 m_Format;
116
    
117
        private String                                                 m_SRS;
118
        private String                                                 layerQuery;
119
        private String                                                 infoLayerQuery;
120
        private FMapWMSDriver                                 wms;
121
        private WMSStatus                                         wmsStatus = new WMSStatus();
122
        private EventMonitor                                monitor = new EventMonitor(); 
123
        private Rectangle2D                                 fullExtent;
124
        private boolean                                                wmsTransparency;
125
    private Vector                                                 styles;
126
    private Vector                                                 dimensions;
127
        private StatusRasterInterface                status = null;
128
        private int                                                 posX = 0, posY = 0;
129
        private double                                                 posXWC = 0, posYWC = 0;
130
        private int                                                 r = 0, g = 0, b = 0;
131
        private GeoRasterFile                                 rasterFile = null;
132
        private PxRaster                                         raster = null;
133
        private RasterFilterStack                         filterStack = null;
134
        private boolean                                                firstLoad = false;
135
        private int                                                 transparency = -1;
136
        private int                                                 rband = 0, gband = 1, bband = 2;
137
        private RasterFilterStackManager        stackManager = null;
138
        private Hashtable                                         onlineResources = new Hashtable();
139
        private Dimension                                         fixedSize;
140
        private boolean                                         queryable = true;
141
        private VisualStatusWMS                                visualStatus = new VisualStatusWMS();
142
        
143
        public FLyrWMS(){
144
                super();
145
        }
146
        
147
        public FLyrWMS(Map args) throws DriverIOException{
148
                FMapWMSDriver drv = null;
149
                String host = (String)args.get("host");
150
                String sLayer = (String)args.get("layer");
151
                Rectangle2D fullExtent = (Rectangle2D)args.get("FullExtent");
152
                String sSRS = (String)args.get("SRS");
153
                String sFormat = (String)args.get("Format");
154
                String[] sLayers = sLayer.split(",");
155
                
156
                try {
157
                        this.setHost(new URL(host));
158
                } catch (MalformedURLException e) {
159
                        //e.printStackTrace();
160
                        throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");                        
161
                }
162
                try {
163
                        drv = this.getDriver();
164
                } catch (Exception e) {
165
                        // e.printStackTrace();
166
                        throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");                        
167
                }
168
                if( sFormat == null || sSRS == null || fullExtent == null ) {
169
                        if (!drv.connect())
170
                                throw new DriverIOException("Can't connect to host '" + host + "'."); 
171
                        
172
                        WMSLayerNode wmsNode = drv.getLayer(sLayer);
173
                                                        
174
                        if (wmsNode == null){
175
                                throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'.");
176
                        }                
177
                        if( sFormat == null ) {
178
                                sFormat = this.getGreatFormat(drv.getFormats());
179
                        }
180
                     if( sSRS == null ) {
181
                             sSRS = (String)wmsNode.getAllSrs().get(0);
182
                     }
183
                        if( fullExtent == null ) {
184
                                fullExtent = drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0));
185
                        }
186
                }
187
                
188
                                
189
                this.setFullExtent(fullExtent);
190
                this.setFormat(sFormat);
191
                this.setLayerQuery(sLayer);
192
                this.setInfoLayerQuery("");
193
                this.setSRS(sSRS);
194
                this.setName(sLayer);
195
        }
196
        
197
        /**
198
         * It choose the best format to load different maps if the server 
199
         * supports it. This format could be png, because it supports 
200
         * transparency.
201
         * @param formats
202
         * Arraywith all the formats supported by the server
203
         * @return
204
         * @author jorge piera llodra
205
         */        
206
        private String getGreatFormat(Vector formats){
207
            for (int i=0 ; i<formats.size() ; i++){
208
                String format = (String) formats.get(i);
209
                    if (format.equals("image/jpg")){
210
                    return format;
211
                    }
212
                    if (format.equals("image/jpeg")){
213
                    return format;
214
                    }
215
            }
216
                    
217
            return (String)formats.get(0);
218
        }
219
        
220
        /**
221
         * Clase que contiene los datos de visualizaci?n de WMS.
222
         * @author Nacho Brodin (brodin_ign@gva.es)
223
         */
224
        private class VisualStatusWMS{
225
                /**
226
                 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con 
227
                 * el ancho y alto del viewPort
228
                 */
229
                private        int                                                        width = 0, height = 0;
230
                private double                                                minX = 0D, minY = 0D, maxX = 0D, maxY = 0D;
231
                private int                                                 bandCount = 0;
232
                private int                                                        dataType = DataBuffer.TYPE_UNDEFINED;
233
        }
234
         
235

    
236
        /**
237
         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
238
         * capa.
239
         *
240
         * @return XMLEntity.
241
         * @throws XMLException
242
         */
243
        public XMLEntity getXMLEntity() throws XMLException {
244
                XMLEntity xml = super.getXMLEntity();
245

    
246
                // Full extent
247
                xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
248
                
249
                // Host
250
                xml.putProperty("host", host.toExternalForm());
251
                
252
                // Part of the query that is not the host, or the
253
                // layer names, or other not listed bellow
254
                xml.putProperty("infoLayerQuery", infoLayerQuery);
255
                
256
                // Part of the query containing the layer names
257
                xml.putProperty("layerQuery", layerQuery);
258
                
259
                // Format
260
                xml.putProperty("format", m_Format);
261
                
262
                // SRS
263
                xml.putProperty("srs", m_SRS);
264
                if (status!=null)
265
                        status.getXMLEntity(xml, true, this);
266
                else{
267
                        status = new StatusLayerRaster();
268
                        status.getXMLEntity(xml, true, this);
269
                }
270
                
271
        // Transparency
272
        xml.putProperty("wms_transparency", wmsTransparency);
273
        
274
        // Styles
275
        if (styles!=null){
276
            String stylePr = "";
277
            for (int i = 0; i < styles.size(); i++) {
278
                stylePr += (String) styles.get(i);
279
                if (i<styles.size()-1)
280
                    stylePr += ",";
281
            }
282
            if (stylePr.endsWith(","))
283
                    stylePr += " ";
284
            xml.putProperty("styles", stylePr);
285
        }
286
        
287
        // Dimensions 
288
        if (dimensions!=null){
289
            String dim = "";
290
            for (int i = 0; i < dimensions.size(); i++) {
291
                dim += (String) dimensions.get(i);
292
                if (i<dimensions.size()-1)
293
                    dim += ",";
294
            }
295
            if (dim.endsWith(","))
296
                    dim += " ";
297
            xml.putProperty("dimensions", dim);
298
        }
299
        
300
        // OnlineResources
301
        Iterator it = onlineResources.keySet().iterator();
302
        String strOnlines = "";
303
        while (it.hasNext()) {
304
                String key = (String) it.next();
305
                String value = (String) onlineResources.get(key);
306
                strOnlines = key+"~##SEP2##~"+value;
307
                if (it.hasNext())
308
                        strOnlines += "~##SEP1##~";
309
        }
310
        xml.putProperty("onlineResources", strOnlines);
311
        
312
        // Queryable
313
        xml.putProperty("queryable", queryable);
314
        
315
        // fixedSize
316
        if (isSizeFixed()) {
317
                xml.putProperty("fixedSize", true);
318
                xml.putProperty("fixedWidth", fixedSize.width);
319
                xml.putProperty("fixedHeight", fixedSize.height);
320
        }
321
        return xml;
322
        }
323

    
324
        /**
325
         * A partir del XMLEntity reproduce la capa.
326
         *
327
         * @param xml XMLEntity
328
         *
329
         * @throws XMLException
330
         * @throws DriverException
331
         * @throws DriverIOException
332
         */
333
        public void setXMLEntity03(XMLEntity xml)
334
                throws XMLException {
335
                super.setXMLEntity(xml);
336
                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
337
                                        "fullExtent"));
338

    
339
                try {
340
                        host = new URL(xml.getStringProperty("host"));
341
                } catch (MalformedURLException e) {
342
                        throw new XMLException(e);
343
                }
344

    
345
                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
346
                layerQuery = xml.getStringProperty("layerQuery");
347
                m_Format = xml.getStringProperty("format");
348
                m_SRS = xml.getStringProperty("srs");
349
        }
350

    
351
        /**
352
         * A partir del XMLEntity reproduce la capa.
353
         *
354
         * @param xml XMLEntity
355
         *
356
         * @throws XMLException
357
         * @throws DriverException
358
         * @throws DriverIOException
359
         */
360
        public void setXMLEntity(XMLEntity xml)
361
                throws XMLException {
362
                super.setXMLEntity(xml);
363
                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
364
                                        "fullExtent"));
365
                
366
                // Host
367
                try {
368
                        host = new URL(xml.getStringProperty("host"));
369
                } catch (MalformedURLException e) {
370
                        throw new XMLException(e);
371
                }
372

    
373
                // Part of the query that is not the host, or the
374
                // layer names, or other not listed bellow
375
                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
376

    
377
                // Part of the query containing the layer names
378
                layerQuery = xml.getStringProperty("layerQuery");
379
                
380
                // Format
381
                m_Format = xml.getStringProperty("format");
382
                
383
                // SRS
384
                m_SRS = xml.getStringProperty("srs");
385
                
386
                String claseStr = StatusLayerRaster.defaultClass;
387
                if (xml.contains("raster.class")) {
388
                        claseStr = xml.getStringProperty("raster.class");
389
                }
390
                
391
                // Transparency
392
        if (xml.contains("wms_transparency"))
393
            wmsTransparency = xml.getBooleanProperty("wms_transparency");
394
        
395
        // Styles
396
        if (xml.contains("styles")){
397
            styles = new Vector();
398
            String[] stl = xml.getStringProperty("styles").split(",");
399
            
400
            for (int i = 0; i < stl.length; i++) {
401
                    if (stl[i].equals(" "))
402
                            stl[i]="";
403
                styles.add(stl[i]);
404
            }
405
        }
406
        
407
        // Dimensions
408
        if (xml.contains("dimensions")){
409
            dimensions = new Vector();
410
            String[] dims = xml.getStringProperty("dimensions").split(",");
411
            for (int i = 0; i < dims.length; i++){
412
                    if (dims[i].equals(" "))
413
                            dims[i]="";
414
                
415
                dimensions.add(dims[i]);
416
            }
417
        }
418
        
419
        // OnlineResources
420
        if (xml.contains("onlineResources")) {
421
                String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~");
422
                for (int i = 0; i < operations.length; i++) {
423
                                String[] resources = operations[i].split("~##SEP2##~");
424
                                if (resources.length==2 && resources[1]!="")
425
                                        onlineResources.put(resources[0], resources[1]);
426
                        }
427
        }
428
        
429
        // Queryable
430
        queryable = true; // let's assume that the layer is queryable by default
431
        if (xml.contains("queryable"))
432
                queryable = xml.getBooleanProperty("queryable");
433
        
434
        // fixedSize
435
        if (xml.contains("fixedSize")) {
436
                fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), 
437
                                                  xml.getIntProperty("fixedHeight"));
438
        }
439
        
440
                if(status!=null)
441
                        status.setXMLEntity(xml, this);
442
                else{
443
                        if(claseStr!=null && !claseStr.equals("")){
444
                                try{
445
                                        Class clase = Class.forName(claseStr);
446
                                        Constructor constr = clase.getConstructor(null);
447
                                        status = (StatusRasterInterface)constr.newInstance(null);
448
                                        if(status!=null)
449
                                                status.setXMLEntity(xml, this);
450
                                }catch(ClassNotFoundException exc){
451
                                        exc.printStackTrace();
452
                                }catch(InstantiationException exc){
453
                                        exc.printStackTrace();
454
                                }catch(IllegalAccessException exc){
455
                                        exc.printStackTrace();
456
                                }catch(NoSuchMethodException exc){
457
                                        exc.printStackTrace();
458
                                }catch(InvocationTargetException exc){
459
                                        exc.printStackTrace();
460
                                }                                        
461
                        }
462
                }
463
                firstLoad = true;
464
        }
465

    
466
        /**
467
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
468
         */
469
        public String queryByPoint(Point p) throws DriverException {
470
                try {
471
                        if (queryable)
472
                        {
473
                                //TODO
474
                                // check if there are layers which are not queryable
475
                                ViewPort viewPort = getFMap().getViewPort();
476

    
477
                                Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight);
478
                                Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
479
                                Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
480
                                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
481
                                int nCols = tiles.getNumCols();
482

    
483
                                int col = (int) p.getX() / maxTilePrintWidth;
484
                                int row = (int) p.getY() / maxTilePrintHeight;
485
                                int tileIndex = (row*nCols) + col;
486
                                
487
                                ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex);
488
                                wmsStatus.setExtent(vp.getExtent());
489
                                wmsStatus.setHeight(vp.getImageHeight());
490
                                wmsStatus.setWidth(vp.getImageWidth());
491
                                wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo"));
492
                                return new String(getDriver()
493
                                                .getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE));
494
                        }
495
                        else
496
                        {
497
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
498
                                                PluginServices.getText(this, "wms_not_queryable"));
499
                                return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>";
500
                        }
501
                } catch (WMSException  e) {
502
                        return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" +
503
                        e.getMessage() + "</exception>";
504
                } catch (ValidationException e) {
505
                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
506
                } catch (UnsupportedVersionException e) {
507
                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
508
                } catch (IOException e) {
509
                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
510
                } catch (NoninvertibleTransformException e) {
511
                        NotificationManager.addError("NotinvertibleTransform", e);
512
                }
513
                return null;
514
        }
515

    
516
        /**
517
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
518
         */
519
        public Rectangle2D getFullExtent() {
520
                return fullExtent;
521
        }
522

    
523
        /**
524
         * 
525
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
526
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
527
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
528
         */
529
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
530
                        Cancellable cancel,double scale) throws DriverException {
531
                
532
                if (isWithinScale(scale)){
533
                        Point2D p = viewPort.getOffset();
534
                        // p will be (0, 0) when drawing a view or other when painting onto
535
                        // the Layout.
536
                        visualStatus.width =  viewPort.getImageWidth();
537
                        visualStatus.height =  viewPort.getImageHeight();
538
                        visualStatus.minX = viewPort.getAdjustedExtent().getMinX();
539
                        visualStatus.minY = viewPort.getAdjustedExtent().getMinY();
540
                        visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX();
541
                        visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY();
542
                        if (isSizeFixed()) {
543
                                // This condition handles those situations in which the server can
544
                                // only give static extent and resolution maps despite we need
545
                                // a specific BBOX and pixel WIDTH and HEIGHT
546
                                drawFixedSize(g, viewPort, cancel);
547

    
548
                        } else {
549
                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
550
                                Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
551
                                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
552
                                for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
553
                                        // drawing part
554
                                        try {
555
                                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
556
                                                drawTile(g, vp, cancel);
557
                                        } catch (NoninvertibleTransformException e) {
558
                                                e.printStackTrace();
559
                                        }
560
                                }
561
                        }
562
                }
563
        }
564
        
565
        private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
566
                // This is the extent that will be requested
567
                Rectangle2D bBox = getFullExtent();
568
                
569
                try {                        
570
                        wmsStatus.setExtent( bBox );
571
                        wmsStatus.setFormat( m_Format );
572
                        wmsStatus.setHeight( fixedSize.height );
573
                        wmsStatus.setWidth( fixedSize.width );
574
                        wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
575
                        wmsStatus.setSrs(m_SRS);
576
                        wmsStatus.setStyles(styles);
577
                        wmsStatus.setDimensions(dimensions);
578
                        wmsStatus.setTransparency(wmsTransparency);
579
                        wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
580
                        
581
                        File f = getDriver().getMap(wmsStatus);
582
                        String nameWorldFile = f.getPath() + getExtensionWorldFile();
583
                        com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
584
                        
585
                        if(status!=null && firstLoad){
586
                                status.applyStatus(this);
587
                                firstLoad = false;
588
                        }
589
                        
590
                        // And finally, obtain the extent intersecting the view and the BBox
591
                        // to draw to.
592
                        Rectangle2D extent = new Rectangle2D.Double();
593
                        Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
594
                        
595
                        ViewPortData vpData = new ViewPortData(
596
                                vp.getProjection(), new Extent(extent), fixedSize );
597
                        vpData.setMat(vp.getAffineTransform());
598

    
599
                        rasterProcess(g, vpData, f);
600
                        
601
                } catch (ValidationException e) {
602
                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
603
                } catch (UnsupportedVersionException e) {
604
                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
605
                } catch (IOException e) {
606
                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
607
                } catch (WMSException e) {
608
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
609
                        this.setVisible(false);
610
                }
611
                
612
                
613
        }
614
        
615
        /**
616
         * This is the method used to draw a tile in a WMS mosaic layer.
617
         */
618
        private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
619

    
620
                // Compute the query geometry 
621
                // 1. Check if it is within borders
622
                Rectangle2D extent = getFullExtent();
623
        if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
624
                (vp.getExtent().getMinY() > extent.getMaxY()) ||
625
                (vp.getExtent().getMaxX() < extent.getMinX()) ||
626
                (vp.getExtent().getMaxY() < extent.getMinY())) {
627
            return;
628
        }
629
        
630
        // 2. Compute extent to be requested.
631
        Rectangle2D bBox = new Rectangle2D.Double();
632
        Rectangle2D.intersect(vp.getExtent(), extent, bBox);
633
        
634
        // 3. Compute size in pixels
635
        double scalex = vp.getAffineTransform().getScaleX(); 
636
        double scaley = vp.getAffineTransform().getScaleY(); 
637
        int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
638
        int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
639
        Dimension sz = new Dimension(wImg, hImg);
640

    
641
        if ((wImg <= 0) || (hImg <= 0)) {
642
            return;
643
        }
644
                
645
                try {                        
646
                        wmsStatus.setExtent( bBox );
647
                        wmsStatus.setFormat(m_Format);
648
                        wmsStatus.setHeight( hImg );
649
                        wmsStatus.setWidth( wImg );
650
                        wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
651
                        wmsStatus.setSrs(m_SRS);
652
                        wmsStatus.setStyles(styles);
653
                        wmsStatus.setDimensions(dimensions);
654
                        wmsStatus.setTransparency(wmsTransparency);
655
                        wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
656
                        
657
                        File f = getDriver().getMap(wmsStatus);
658
                        String nameWordFile = f.getPath() + getExtensionWorldFile();
659
                        com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
660
                        
661
                        if(status!=null && firstLoad){
662
                                status.applyStatus(this);
663
                                firstLoad = false;
664
                        }
665
                        ViewPortData vpData = new ViewPortData(
666
                                vp.getProjection(), new Extent(bBox), sz );
667
                        vpData.setMat(vp.getAffineTransform());
668

    
669
                        rasterProcess(g, vpData, f);
670
                        
671
                } catch (ValidationException e) {
672
                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
673
                } catch (UnsupportedVersionException e) {
674
                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
675
                } catch (IOException e) {
676
                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
677
                } catch (WMSException e) {
678
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
679
                        this.setVisible(false);
680
                }
681
                
682
        }
683

    
684
        /**
685
         * Obtiene la extensi?n del fichero de georreferenciaci?n
686
         * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
687
         * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld 
688
         */
689
        private String getExtensionWorldFile(){
690
                String extWorldFile = ".wld";
691
            if(m_Format.equals("image/tif") || m_Format.equals("image/tiff"))
692
                    extWorldFile = ".tfw";
693
            if(m_Format.equals("image/jpeg"))
694
                    extWorldFile = ".jpgw";
695
            return extWorldFile;
696
        }
697
        
698
        /**
699
         * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
700
         * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
701
         * @param sz Tama?o de la imagen en pixeles.
702
         * @return el 'WorldFile', como String.
703
         * @throws IOException
704
         */
705
        public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException {
706
                StringBuffer data = new StringBuffer();
707
            data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n");
708
            data.append("0.0\n");
709
            data.append("0.0\n");
710
            data.append((bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n");
711
            data.append(""+bBox.getMinX()+"\n");
712
            data.append(""+bBox.getMinY()+"\n");
713
            return data.toString();
714
        }
715
                
716
        /**
717
         * Dibuja una imagen usando PxRaster
718
         * @param g        Graphics2D en el que hay que dibujar.
719
         * @param vpData Par?metros de visualizaci?n
720
         * @param file La imagen en cuesti?n.
721
         */
722
        private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) {
723
                
724
                //Creamos el PxRaster        
725
                rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
726
                raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
727
                
728
                //Recuperamos la pila de filtros si ya hubiese sido cargado antes
729
                if(this.filterStack!=null)
730
                        raster.filterStack = this.filterStack;
731
                
732
                raster.setTransparency(false);
733
                                                
734
                //Asignamos transparencia y orden de bandas
735
                if(this.transparency==-1 && !firstLoad);
736
                else
737
                        raster.setTransparency(this.transparency);
738
                
739
                raster.setBand(GeoRasterFile.RED_BAND,rband);
740
                raster.setBand(GeoRasterFile.GREEN_BAND, gband);
741
                raster.setBand(GeoRasterFile.BLUE_BAND, bband);
742
        
743
                //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
744
                //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de 
745
                //propiedades cuando creamos un nuevo pxRaster
746
                if(this.stackManager != null)
747
                        raster.setStackManager(this.stackManager); 
748
                
749
                if(visualStatus != null){
750
                        visualStatus.bandCount = raster.getBandCount();
751
                        visualStatus.dataType = raster.getDataType();
752
                }
753

    
754
                raster.draw(g, vpData);
755
                
756
                //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
757
                //si queremos desde las propiedades
758
                
759
                if(this.stackManager == null)
760
                        this.stackManager = raster.getStackManager(); 
761
                
762
                if(this.filterStack == null)
763
                        this.filterStack = raster.filterStack;
764
                
765
                //rasterFile.close();
766
        }
767
        
768
        /**
769
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
770
         *                 com.iver.cit.gvsig.fmap.ViewPort,
771
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
772
         */
773
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
774
                throws DriverException {
775
                if (isVisible() && isWithinScale(scale)){        
776
                isPrinting = true;
777
                if (!mustTilePrint) {
778
                        draw(null, g, viewPort, cancel,scale);
779
                } else {
780
                // Para no pedir imagenes demasiado grandes, vamos
781
                // a hacer lo mismo que hace EcwFile: chunkear.
782
                // Llamamos a drawView con cuadraditos m?s peque?os
783
                // del BufferedImage ni caso, cuando se imprime viene con null
784
                        
785
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
786
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
787
                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
788
                            // Parte que dibuja
789
                            try {
790
                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
791
                                drawTile(g, vp, cancel);
792
                                } catch (NoninvertibleTransformException e) {
793
                                        e.printStackTrace();
794
                                }
795
                }
796
                }
797
            isPrinting = false;
798
                }
799
        }
800
        
801
        public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
802
                throws DriverException {
803
                draw(null, g, viewPort, cancel,scale);
804
        }
805

    
806
        /**
807
         * Devuelve el FMapWMSDriver.
808
         *
809
         * @return FMapWMSDriver
810
         *
811
         * @throws IllegalStateException
812
         * @throws ValidationException
813
         * @throws UnsupportedVersionException
814
         * @throws IOException
815
         */
816
        private FMapWMSDriver getDriver()
817
                throws IllegalStateException, ValidationException, 
818
                        UnsupportedVersionException, IOException {
819
                if (wms == null) {
820
                        //wmsClient = WMSClientFactory.getClient(host);
821
                        wms = new FMapWMSDriver(monitor);
822
                        
823
            wms.createClient(host);
824
            
825
                }
826

    
827
                return wms;
828
        }
829
        
830
        /**
831
         * Devuelve el FMapWMSDriver.
832
         *
833
         * @return FMapWMSDriver
834
         *
835
         * @throws IllegalStateException
836
         * @throws ValidationException
837
         * @throws UnsupportedVersionException
838
         * @throws IOException
839
         */
840
        public void setDriver(FMapWMSDriver drv) {
841
                wms = drv;
842
        }
843

    
844
        /**
845
         * Devuelve el URL.
846
         *
847
         * @return URL.
848
         */
849
        public URL getHost() {
850
                return host;
851
        }
852

    
853
        /**
854
         * Inserta el URL.
855
         *
856
         * @param host URL.
857
         */
858
        public void setHost(URL host) {
859
                this.host = host;
860
        }
861

    
862
        /**
863
         * Devuelve la informaci?n de la consulta.
864
         *
865
         * @return String.
866
         */
867
        public String getInfoLayerQuery() {
868
                return infoLayerQuery;
869
        }
870

    
871
        /**
872
         * Inserta la informaci?n de la consulta.
873
         *
874
         * @param infoLayerQuery String.
875
         */
876
        public void setInfoLayerQuery(String infoLayerQuery) {
877
                this.infoLayerQuery = infoLayerQuery;
878
        }
879

    
880
        /**
881
         * Devuelve la consulta.
882
         *
883
         * @return String.
884
         */
885
        public String getLayerQuery() {
886
                return layerQuery;
887
        }
888

    
889
        /**
890
         * Inserta la consulta.
891
         *
892
         * @param layerQuery consulta.
893
         */
894
        public void setLayerQuery(String layerQuery) {
895
                this.layerQuery = layerQuery;
896
        }
897

    
898
        /**
899
         * Devuelve el formato.
900
         *
901
         * @return Formato.
902
         */
903
        public String getFormat() {
904
                return m_Format;
905
        }
906

    
907
        /**
908
         * Inserta el formato.
909
         *
910
         * @param format Formato.
911
         */
912
        public void setFormat(String format) {
913
                m_Format = format;
914
        }
915

    
916
        /**
917
         * Devuelve el SRS.
918
         *
919
         * @return SRS.
920
         */
921
        public String getSRS() {
922
                return m_SRS;
923
        }
924

    
925
        /**
926
         * Inserta el SRS.
927
         *
928
         * @param m_srs SRS.
929
         */
930
        public void setSRS(String m_srs) {
931
                m_SRS = m_srs;
932
        }
933

    
934
        /**
935
         * Inserta la extensi?n total de la capa.
936
         *
937
         * @param fullExtent Rect?ngulo.
938
         */
939
        public void setFullExtent(Rectangle2D fullExtent) {
940
                this.fullExtent = fullExtent;
941
        }
942
        
943
        public HashMap getProperties() {
944
                HashMap info = new HashMap();
945
        String[] layerNames = getLayerQuery().split(",");
946
        Vector layers = new Vector(layerNames.length);
947
        try {
948
            if(getDriver().connect()){
949
                for (int i = 0; i < layerNames.length; i++) {
950
                    layers.add(i, wms.getLayer(layerNames[i]));
951
                }
952
                info.put("name", getName());
953
                info.put("selectedLayers", layers);
954
                info.put("host", getHost());
955
                info.put("srs", getSRS());
956
                info.put("format", getFormat());
957
                info.put("wmsTransparency", new Boolean(wmsTransparency));
958
                info.put("styles", styles);
959
                info.put("dimensions", dimensions);
960
                info.put("fixedSize", fixedSize);
961
                return info;
962
            }
963
        } catch (Exception e) {
964
            e.printStackTrace();
965
        }
966
        return null;
967
        }
968
        
969
        /**
970
         * Asignar el estado del raster
971
         * @param status
972
         */
973
        public void setStatus(StatusRasterInterface status){
974
                this.status = status;
975
        }
976
        
977
        /**
978
         * Obtiene el estado del raster
979
         * @return
980
         */
981
        public StatusRasterInterface getStatus(){
982
                return this.status;
983
        }
984
        
985
        /* (non-Javadoc)
986
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
987
         */
988
        public ArrayList getAttributes() {
989
                if(rasterFile != null){
990
                        ArrayList attr = new ArrayList();
991
                        String dataType = "Byte";
992
                        if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte";
993
                        else if (visualStatus.dataType == DataBuffer.TYPE_SHORT)
994
                                dataType = "Short";
995
                        else if (visualStatus.dataType == DataBuffer.TYPE_USHORT)
996
                                dataType = "Unsigned Short";
997
                        else if (visualStatus.dataType == DataBuffer.TYPE_INT)
998
                                dataType = "Integer";
999
                        else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT)
1000
                                dataType = "Float";
1001
                        else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE)
1002
                                dataType = "Double";
1003
                        else
1004
                                dataType = "Unknown";
1005

    
1006
                        Object [][] a = {
1007
                                {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())},
1008
                                {"Filesize",new Long(0)},
1009
                                {"Width",new Integer((int)this.getWidth())},
1010
                                {"Height", new Integer((int)this.getHeight())},
1011
                                {"Bands", new Integer(visualStatus.bandCount)},
1012
                                {"BandDataType", dataType}
1013
                        };
1014
                        for (int i=0; i<a.length; i++)
1015
                                attr.add(a[i]);
1016

    
1017
                        return attr;
1018
                }
1019
                return  null;
1020
        }
1021
        
1022
        /* (non-Javadoc)
1023
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
1024
         */
1025
        public RasterFilterStack getFilterStack() {
1026
                if(raster!=null)
1027
                        return raster.filterStack;
1028
                return null;
1029
        }
1030
        /* (non-Javadoc)
1031
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
1032
         */
1033
        public double getHeight() {
1034
                return visualStatus.height;
1035
        }
1036
        
1037
        /* (non-Javadoc)
1038
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
1039
         */
1040
        public double getMaxX() {
1041
                return visualStatus.maxX;
1042
        }
1043
        
1044
        /* (non-Javadoc)
1045
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
1046
         */
1047
        public double getMaxY() {
1048
                return visualStatus.maxY;
1049
        }
1050
        
1051
        /* (non-Javadoc)
1052
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
1053
         */
1054
        public double getMinX() {
1055
                return visualStatus.minX;
1056
        }
1057
        
1058
        /* (non-Javadoc)
1059
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
1060
         */
1061
        public double getMinY() {
1062
                return visualStatus.minY;
1063
        }
1064
        /* (non-Javadoc)
1065
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
1066
         */
1067
        public int[] getPixel(double wcx, double wcy) {
1068
                if(getPxRaster() != null)
1069
                        return getPxRaster().getPixel(wcx, wcy);
1070
        return null;
1071
        }
1072
        /* (non-Javadoc)
1073
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
1074
         */
1075
        public RasterAdapter getSource() {
1076
                return null;
1077
        }
1078
        /* (non-Javadoc)
1079
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
1080
         */
1081
        public double getWidth() {
1082
                return visualStatus.width;
1083
        }
1084
        /* (non-Javadoc)
1085
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
1086
         */
1087
        public void setBand(int flag, int nBand) {
1088
                switch(flag){
1089
                case GeoRasterFile.RED_BAND:setBandR(nBand);break;
1090
                case GeoRasterFile.GREEN_BAND:setBandG(nBand);break;
1091
                case GeoRasterFile.BLUE_BAND:setBandB(nBand);break;
1092
                }
1093
        }
1094
        /* (non-Javadoc)
1095
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
1096
         */
1097
        public void setFilterStack(RasterFilterStack stack) {
1098
                this.filterStack = stack;
1099
        }
1100
        /* (non-Javadoc)
1101
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
1102
         */
1103
        public void setPos(int x, int y) {
1104
                this.posX = x;
1105
                this.posY = y;
1106
        }
1107
        
1108
        /* (non-Javadoc)
1109
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
1110
         */
1111
        public void setPosWC(double x, double y) {
1112
                this.posXWC = x;
1113
                this.posYWC = y;
1114
        }
1115
        
1116
        /* (non-Javadoc)
1117
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
1118
         */
1119
        public void setRGB(int r, int g, int b) {
1120
                this.r = r;
1121
                this.g = g;
1122
                this.b = b;
1123
        }
1124
        /* (non-Javadoc)
1125
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
1126
         */
1127
        public void setSource(RasterAdapter ra) {
1128
        }
1129
        /**
1130
         * @return Returns the raster.
1131
         */
1132
        public PxRaster getPxRaster() {
1133
                return raster;
1134
        }
1135
        /**
1136
         * @return Returns the rasterFile.
1137
         */
1138
        public GeoRasterFile getGeoRasterFile() {
1139
                return rasterFile;
1140
        }
1141
        
1142
        public void setTransparency(int trans) {
1143
                this.transparency = trans;
1144
        }
1145
        
1146
        /**
1147
         * Sets the R-band.
1148
         * 
1149
         * Asigna la banda R.
1150
         * @param r
1151
         */
1152
        public void setBandR(int r){
1153
                this.rband = r;
1154
        }
1155
        
1156
        /**
1157
         * Sets the G-band.
1158
         * 
1159
         * Asigna la banda G
1160
         * @param g
1161
         */
1162
        public void setBandG(int g){
1163
                this.gband = g;
1164
        }
1165
        
1166
        /**
1167
         * Sets the B-band.
1168
         * 
1169
         * Asigna la banda B
1170
         * @param b
1171
         */
1172
        public void setBandB(int b){
1173
                this.bband = b;
1174
        }
1175

    
1176
    /**
1177
     * @return Returns the wmsTransparency.
1178
     */
1179
    public boolean isWmsTransparent() {
1180
        return wmsTransparency;
1181
    }
1182

    
1183
    /**
1184
     * @param wmsTransparency The wmsTransparency to set.
1185
     */
1186
    public void setWmsTransparency(boolean wmsTransparency) {
1187
        this.wmsTransparency = wmsTransparency;
1188
    }
1189

    
1190
     /**
1191
     * @param styles
1192
     */
1193
    public void setStyles(Vector styles) {
1194
            //laura:
1195
            //layer query is built with the layer in reverse order
1196
            // so here we build the styles upside-down.
1197
            if (styles != null)
1198
            {
1199
                    this.styles = new Vector();
1200
                    for(int i = styles.size()-1; i>=0; i--)
1201
                    {
1202
                            this.styles.add(styles.elementAt(i));
1203
                    }
1204
            }
1205
    }
1206
    
1207
    /**
1208
     * Sets the dimension vector that is a list of key-value pairs containing
1209
     * the name of the dimension and the value for it
1210
     * @param dimensions
1211
     */
1212
    public void setDimensions(Vector dimensions) {
1213
        this.dimensions = dimensions;
1214
    }
1215

    
1216
    /**
1217
     * Sets the set of URLs that should be accessed for each operation performed
1218
     * to the server.
1219
     * 
1220
     * @param onlineResources
1221
     */
1222
        public void setOnlineResources(Hashtable onlineResources) {
1223
                this.onlineResources = onlineResources;
1224
        }
1225
        
1226
        /**
1227
         * When a server is not fully featured and it only can serve constant map
1228
         * sizes this value must be set. It expresses the size in pixels (width, height)
1229
         * that the map will be requested.
1230
         * @param Dimension sz
1231
         */
1232
        public void setFixedSize(Dimension sz) {
1233
                fixedSize = sz;
1234
        }
1235
        
1236
        /**
1237
         * Tells whether if this layer must deal with the server with the constant-size
1238
         * limitations or not.
1239
         * @return boolean.
1240
         */
1241
        private boolean isSizeFixed() {
1242
                return fixedSize != null && fixedSize.getWidth() > 0 && fixedSize.getHeight() > 0;
1243
        }
1244

    
1245
        /**
1246
         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
1247
         * maps to FMap's infoByPoint(p) operation.
1248
         * @param b
1249
         */
1250
        public void setQueryable(boolean b) {
1251
                queryable = b;
1252
        }
1253

    
1254
        /**
1255
         * Creates the part of a OGC's MapContext document that would describe this
1256
         * layer(s).
1257
         * @param version, The desired version of the resulting document. (1.1.0)
1258
         * @return String containing the xml.
1259
         * @throws UnsupportedVersionException 
1260
         */
1261
        public String toMapContext(String mapContextVersion) {
1262
                XmlBuilder xml = new XmlBuilder();
1263
                FMapWMSDriver drv;
1264
                try {
1265
                        drv = getDriver();
1266
                        drv.connect();
1267
                } catch (Exception e) {
1268
                        return xml.toString();
1269
                } 
1270
                String[] layerNames = getLayerQuery().split(",");
1271
                for (int i = 0; i < layerNames.length; i++) {
1272
                        WMSLayerNode layer = drv.getLayer(layerNames[i]);
1273
                        HashMap xmlAttrs = new HashMap();
1274
                        
1275
                        // <Layer>
1276
                        xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible()+"");
1277
                        xmlAttrs.put(WebMapContextTags.QUERYABLE, queryable+"");
1278
                        xml.openTag(WebMapContextTags.LAYER);
1279
                        if (mapContextVersion.equals("1.1.0") || mapContextVersion.equals("1.0.0")) {
1280
                                // <Server>
1281
                                xmlAttrs.put(WebMapContextTags.SERVICE, WebMapContextTags.WMS);
1282
                                xmlAttrs.put(WebMapContextTags.VERSION, drv.getVersion());
1283
                                xmlAttrs.put(WebMapContextTags.SERVER_TITLE, drv.getServiceTitle());
1284
                                xml.openTag(WebMapContextTags.SERVER, xmlAttrs);
1285
                                xmlAttrs.clear();
1286
                                
1287
                                        // <OnlineResource>
1288
                                        xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
1289
                                        xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString());
1290
                                        xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs);
1291
                                        xmlAttrs.clear();
1292
                                        // </OnlineResource>
1293
                                        
1294
                                xml.closeTag();
1295
                                // </Server>
1296
                                
1297
                                // <Name>
1298
                                xml.writeTag(WebMapContextTags.NAME, layer.getName().trim());
1299
                                // </Name>
1300
                                
1301
                                // <Title>
1302
                                xml.writeTag(WebMapContextTags.TITLE, getName().trim());
1303
                                // </Title>
1304
                                
1305
                                // <Abstract>
1306
                                if (layer.getAbstract() != null)
1307
                                        xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract());
1308
                                // </Abstract>
1309
                                
1310
                                // <SRS> (a list of available SRS for the enclosing layer)
1311
                                String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]);
1312
                                String mySRS = strings[0];
1313
                                for (int j = 1; j < strings.length; j++) {
1314
                                        mySRS += ","+strings[j];
1315
                                }
1316
                                xml.writeTag(WebMapContextTags.SRS, mySRS);
1317
                                // </SRS>
1318
                                
1319
                                // <FormatList>
1320
                                xml.openTag(WebMapContextTags.FORMAT_LIST);
1321
                                        strings = (String[]) drv.getFormats().toArray(new String[0]);
1322
                                        for (int j = 0; j < strings.length; j++) {
1323
                    // <Format>
1324
                                                String str = strings[j].trim();
1325
                                                if (str.equals(getFormat()))
1326
                                                        xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
1327
                                                else
1328
                                                        xml.writeTag(WebMapContextTags.FORMAT, str);
1329
                    // </Format>        
1330
                                        }
1331
                                xml.closeTag();
1332
                                // </FormatList>
1333
                                
1334
                                // <StyleList>
1335
                                if (layer.getStyles().size()>0) {
1336
                                        xml.openTag(WebMapContextTags.STYLE_LIST);
1337
                                        for (int j = 0; j < layer.getStyles().size(); j++) {
1338
                                                // <Style>
1339
                                                FMapWMSStyle st = (FMapWMSStyle) layer.getStyles().get(i);
1340
                                                if (st.equals(layer.getSelectedStyle()))
1341
                                                        xmlAttrs.put(WebMapContextTags.CURRENT, "1");
1342
                                                xml.openTag(WebMapContextTags.STYLE, xmlAttrs);
1343
                                                
1344
                                                        // <Name>
1345
                                                        xml.writeTag(WebMapContextTags.NAME, st.name);
1346
                                                        // </Name>
1347
                                                        
1348
                                                        // <Title>
1349
                                                        xml.writeTag(WebMapContextTags.TITLE, st.title);
1350
                                                        // </Title>
1351
                                                        
1352
                                                        // <LegendURL width="180" format="image/gif" height="50">
1353
                                                                // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
1354
                                                                // </OnlineResource>
1355
                                                        // </LegendURL>
1356
                                                xml.closeTag();
1357
                                                // </Style>
1358
                                                
1359
                                        }
1360
                                        xml.closeTag();
1361
                                }
1362
                                // </StyleList>
1363
                                if (mapContextVersion.compareTo("1.0.0") > 0) {
1364
                                // <DimensionList>
1365
                                        xml.openTag(WebMapContextTags.DIMENSION_LIST);
1366
                                        // <Dimension>
1367
                                        // </Dimension>
1368
                                        xml.closeTag();
1369
                                // </DimensionList>
1370
                                }
1371
                        } else {
1372
                                xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version"));
1373
                        }
1374
                        // </Layer>
1375
                        xml.closeTag();
1376
                }
1377
                return xml.getXML();
1378
        }
1379
        
1380
        private class MyTimerTask extends TimerTask {
1381
                private Cancellable cancel;
1382
                
1383
                public MyTimerTask(Cancellable cancel) {
1384
                        super();
1385
                        this.cancel = cancel;
1386
                }
1387
                
1388
                public void run() {
1389
                        while (!cancel.isCanceled()) {}
1390
                        try {
1391
                                getDriver();//.cancelTransfer();
1392
                        } catch (IllegalStateException e) {
1393
                                // TODO Auto-generated catch block
1394
                                e.printStackTrace();
1395
                        } catch (ValidationException e) {
1396
                                // TODO Auto-generated catch block
1397
                                e.printStackTrace();
1398
                        } catch (UnsupportedVersionException e) {
1399
                                // TODO Auto-generated catch block
1400
                                e.printStackTrace();
1401
                        } catch (IOException e) {
1402
                                // TODO Auto-generated catch block
1403
                                e.printStackTrace();
1404
                        }
1405
                }
1406
        }
1407
        
1408
        private class EventMonitor implements WMSListener {
1409
                public void newEvent(int idRequest, int eventType) {
1410
                        // TODO Auto-generated method stub
1411
                        
1412
                }
1413
        }
1414
}
1415

    
1416

    
1417
///**
1418
//* FMap's WMS Layer class.
1419
//*
1420
//* @author Jaume Dominguez Faus
1421
//*                   Nacho Brodin
1422
//* 
1423
//*/
1424
//public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
1425
//        private boolean                                         isPrinting = false;
1426
//        private boolean                                         mustTileDraw = false;
1427
//        private boolean                                         mustTilePrint = true;
1428
//        private final int                                         maxTileDrawWidth = -1;
1429
//        private final int                                         maxTileDrawHeight = -1;
1430
//        private final int                                         maxTilePrintWidth = 1200;
1431
//        private final int                                         maxTilePrintHeight = 1200;
1432
//    
1433
//    public URL                                                         host;
1434
//    public String                                                 m_Format;
1435
//    
1436
//        private String                                                 m_SRS;
1437
//        private String                                                 layerQuery;
1438
//        private String                                                 infoLayerQuery;
1439
//        private FMapWMSDriver                                 wms;
1440
//        private WMSStatus                                         wmsStatus = new WMSStatus();
1441
//        private Rectangle2D                                 fullExtent;
1442
//        private boolean                                                wmsTransparency;
1443
//    private Vector                                                 styles;
1444
//    private Vector                                                 dimensions;
1445
//        private StatusRasterInterface                status = null;
1446
//        private int                                                 posX = 0, posY = 0;
1447
//        private double                                                 posXWC = 0, posYWC = 0;
1448
//        private int                                                 r = 0, g = 0, b = 0;
1449
//        private GeoRasterFile                                 rasterFile = null;
1450
//        private PxRaster                                         raster = null;
1451
//        private RasterFilterStack                         filterStack = null;
1452
//        private boolean                                                firstLoad = false;
1453
//        private int                                                 transparency = -1;
1454
//        private int                                                 rband = 0, gband = 1, bband = 2;
1455
//        private RasterFilterStackManager        stackManager = null;
1456
//        private Hashtable                                         onlineResources = new Hashtable();
1457
//        private Dimension                                         fixedSize;
1458
//        private boolean                                         queryable = true;
1459
//        private VisualStatusWMS                                visualStatus = new VisualStatusWMS();
1460
//        
1461
//        public FLyrWMS(){
1462
//                super();
1463
//        }
1464
//        
1465
//        public FLyrWMS(Map args) throws DriverIOException{
1466
//                FMapWMSDriver drv = null;
1467
//                String host = (String)args.get("host");
1468
//                String sLayer = (String)args.get("layer");
1469
//                Rectangle2D fullExtent = (Rectangle2D)args.get("FullExtent");
1470
//                String sSRS = (String)args.get("SRS");
1471
//                String sFormat = (String)args.get("Format");
1472
//                String[] sLayers = sLayer.split(",");
1473
//                
1474
//                try {
1475
//                        this.setHost(new URL(host));
1476
//                } catch (MalformedURLException e) {
1477
//                        //e.printStackTrace();
1478
//                        throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");                        
1479
//                }
1480
//                try {
1481
//                        drv = this.getDriver();
1482
//                } catch (Exception e) {
1483
//                        // e.printStackTrace();
1484
//                        throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");                        
1485
//                }
1486
//                if( sFormat == null || sSRS == null || fullExtent == null ) {
1487
//                        if (!drv.connect())
1488
//                                throw new DriverIOException("Can't connect to host '" + host + "'."); 
1489
//                        
1490
//                        WMSLayerNode wmsNode = drv.getLayer(sLayer);
1491
//                                                        
1492
//                        if (wmsNode == null){
1493
//                                throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'.");
1494
//                        }                
1495
//                        if( sFormat == null ) {
1496
//                                sFormat = this.getGreatFormat(drv.getFormats());
1497
//                        }
1498
//                     if( sSRS == null ) {
1499
//                             sSRS = (String)wmsNode.getAllSrs().get(0);
1500
//                     }
1501
//                        if( fullExtent == null ) {
1502
//                                fullExtent = drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0));
1503
//                        }
1504
//                }
1505
//                
1506
//                                
1507
//                this.setFullExtent(fullExtent);
1508
//                this.setFormat(sFormat);
1509
//                this.setLayerQuery(sLayer);
1510
//                this.setInfoLayerQuery("");
1511
//                this.setSRS(sSRS);
1512
//                this.setName(sLayer);
1513
//        }
1514
//        
1515
//        /**
1516
//         * It choose the best format to load different maps if the server 
1517
//         * supports it. This format could be png, because it supports 
1518
//         * transparency.
1519
//         * @param formats
1520
//         * Arraywith all the formats supported by the server
1521
//         * @return
1522
//         */        
1523
//        private String getGreatFormat(Vector formats){
1524
//            for (int i=0 ; i<formats.size() ; i++){
1525
//                String format = (String) formats.get(i);
1526
//                    if (format.equals("image/jpg")){
1527
//                    return format;
1528
//                    }
1529
//                    if (format.equals("image/jpeg")){
1530
//                    return format;
1531
//                    }
1532
//            }
1533
//                    
1534
//            return (String)formats.get(0);
1535
//        }
1536
//        
1537
//        /**
1538
//         * Clase que contiene los datos de visualizaci?n de WMS.
1539
//         * @author Nacho Brodin (brodin_ign@gva.es)
1540
//         */
1541
//        private class VisualStatusWMS{
1542
//                /**
1543
//                 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con 
1544
//                 * el ancho y alto del viewPort
1545
//                 */
1546
//                private        int                                                        width = 0, height = 0;
1547
//                private double                                                minX = 0D, minY = 0D, maxX = 0D, maxY = 0D;
1548
//                private int                                                 bandCount = 0;
1549
//                private int                                                        dataType = DataBuffer.TYPE_UNDEFINED;
1550
//        }
1551
//         
1552
//
1553
//        /**
1554
//         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
1555
//         * capa.
1556
//         *
1557
//         * @return XMLEntity.
1558
//         * @throws XMLException
1559
//         */
1560
//        public XMLEntity getXMLEntity() throws XMLException {
1561
//                XMLEntity xml = super.getXMLEntity();
1562
//
1563
//                // Full extent
1564
//                xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
1565
//                
1566
//                // Host
1567
//                xml.putProperty("host", host.toExternalForm());
1568
//                
1569
//                // Part of the query that is not the host, or the
1570
//                // layer names, or other not listed bellow
1571
//                xml.putProperty("infoLayerQuery", infoLayerQuery);
1572
//                
1573
//                // Part of the query containing the layer names
1574
//                xml.putProperty("layerQuery", layerQuery);
1575
//                
1576
//                // Format
1577
//                xml.putProperty("format", m_Format);
1578
//                
1579
//                // SRS
1580
//                xml.putProperty("srs", m_SRS);
1581
//                if (status!=null)
1582
//                        status.getXMLEntity(xml, true, this);
1583
//                else{
1584
//                        status = new StatusLayerRaster();
1585
//                        status.getXMLEntity(xml, true, this);
1586
//                }
1587
//                
1588
//        // Transparency
1589
//        xml.putProperty("wms_transparency", wmsTransparency);
1590
//        
1591
//        // Styles
1592
//        if (styles!=null){
1593
//            String stylePr = "";
1594
//            for (int i = 0; i < styles.size(); i++) {
1595
//                stylePr += (String) styles.get(i);
1596
//                if (i<styles.size()-1)
1597
//                    stylePr += ",";
1598
//            }
1599
//            if (stylePr.endsWith(","))
1600
//                    stylePr += " ";
1601
//            xml.putProperty("styles", stylePr);
1602
//        }
1603
//        
1604
//        // Dimensions 
1605
//        if (dimensions!=null){
1606
//            String dim = "";
1607
//            for (int i = 0; i < dimensions.size(); i++) {
1608
//                dim += (String) dimensions.get(i);
1609
//                if (i<dimensions.size()-1)
1610
//                    dim += ",";
1611
//            }
1612
//            if (dim.endsWith(","))
1613
//                    dim += " ";
1614
//            xml.putProperty("dimensions", dim);
1615
//        }
1616
//        
1617
//        // OnlineResources
1618
//        Iterator it = onlineResources.keySet().iterator();
1619
//        String strOnlines = "";
1620
//        while (it.hasNext()) {
1621
//                String key = (String) it.next();
1622
//                String value = (String) onlineResources.get(key);
1623
//                strOnlines = key+"~##SEP2##~"+value;
1624
//                if (it.hasNext())
1625
//                        strOnlines += "~##SEP1##~";
1626
//        }
1627
//        xml.putProperty("onlineResources", strOnlines);
1628
//        
1629
//        // Queryable
1630
//        xml.putProperty("queryable", queryable);
1631
//        
1632
//        // fixedSize
1633
//        if (isSizeFixed()) {
1634
//                xml.putProperty("fixedSize", true);
1635
//                xml.putProperty("fixedWidth", fixedSize.width);
1636
//                xml.putProperty("fixedHeight", fixedSize.height);
1637
//        }
1638
//        return xml;
1639
//        }
1640
//
1641
//        /**
1642
//         * A partir del XMLEntity reproduce la capa.
1643
//         *
1644
//         * @param xml XMLEntity
1645
//         *
1646
//         * @throws XMLException
1647
//         * @throws DriverException
1648
//         * @throws DriverIOException
1649
//         */
1650
//        public void setXMLEntity03(XMLEntity xml)
1651
//                throws XMLException {
1652
//                super.setXMLEntity(xml);
1653
//                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
1654
//                                        "fullExtent"));
1655
//
1656
//                try {
1657
//                        host = new URL(xml.getStringProperty("host"));
1658
//                } catch (MalformedURLException e) {
1659
//                        throw new XMLException(e);
1660
//                }
1661
//
1662
//                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
1663
//                layerQuery = xml.getStringProperty("layerQuery");
1664
//                m_Format = xml.getStringProperty("format");
1665
//                m_SRS = xml.getStringProperty("srs");
1666
//        }
1667
//
1668
//        /**
1669
//         * A partir del XMLEntity reproduce la capa.
1670
//         *
1671
//         * @param xml XMLEntity
1672
//         *
1673
//         * @throws XMLException
1674
//         * @throws DriverException
1675
//         * @throws DriverIOException
1676
//         */
1677
//        public void setXMLEntity(XMLEntity xml)
1678
//                throws XMLException {
1679
//                super.setXMLEntity(xml);
1680
//                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
1681
//                                        "fullExtent"));
1682
//                
1683
//                // Host
1684
//                try {
1685
//                        host = new URL(xml.getStringProperty("host"));
1686
//                } catch (MalformedURLException e) {
1687
//                        throw new XMLException(e);
1688
//                }
1689
//
1690
//                // Part of the query that is not the host, or the
1691
//                // layer names, or other not listed bellow
1692
//                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
1693
//
1694
//                // Part of the query containing the layer names
1695
//                layerQuery = xml.getStringProperty("layerQuery");
1696
//                
1697
//                // Format
1698
//                m_Format = xml.getStringProperty("format");
1699
//                
1700
//                // SRS
1701
//                m_SRS = xml.getStringProperty("srs");
1702
//                
1703
//                String claseStr = StatusLayerRaster.defaultClass;
1704
//                if (xml.contains("raster.class")) {
1705
//                        claseStr = xml.getStringProperty("raster.class");
1706
//                }
1707
//                
1708
//                // Transparency
1709
//        if (xml.contains("wms_transparency"))
1710
//            wmsTransparency = xml.getBooleanProperty("wms_transparency");
1711
//        
1712
//        // Styles
1713
//        if (xml.contains("styles")){
1714
//            styles = new Vector();
1715
//            String[] stl = xml.getStringProperty("styles").split(",");
1716
//            
1717
//            for (int i = 0; i < stl.length; i++) {
1718
//                    if (stl[i].equals(" "))
1719
//                            stl[i]="";
1720
//                styles.add(stl[i]);
1721
//            }
1722
//        }
1723
//        
1724
//        // Dimensions
1725
//        if (xml.contains("dimensions")){
1726
//            dimensions = new Vector();
1727
//            String[] dims = xml.getStringProperty("dimensions").split(",");
1728
//            for (int i = 0; i < dims.length; i++){
1729
//                    if (dims[i].equals(" "))
1730
//                            dims[i]="";
1731
//                
1732
//                dimensions.add(dims[i]);
1733
//            }
1734
//        }
1735
//        
1736
//        // OnlineResources
1737
//        if (xml.contains("onlineResources")) {
1738
//                String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~");
1739
//                for (int i = 0; i < operations.length; i++) {
1740
//                                String[] resources = operations[i].split("~##SEP2##~");
1741
//                                if (resources.length==2 && resources[1]!="")
1742
//                                        onlineResources.put(resources[0], resources[1]);
1743
//                        }
1744
//        }
1745
//        
1746
//        // Queryable
1747
//        queryable = true; // let's assume that the layer is queryable by default
1748
//        if (xml.contains("queryable"))
1749
//                queryable = xml.getBooleanProperty("queryable");
1750
//        
1751
//        // fixedSize
1752
//        if (xml.contains("fixedSize")) {
1753
//                fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), 
1754
//                                                  xml.getIntProperty("fixedHeight"));
1755
//        }
1756
//        
1757
//                if(status!=null)
1758
//                        status.setXMLEntity(xml, this);
1759
//                else{
1760
//                        if(claseStr!=null && !claseStr.equals("")){
1761
//                                try{
1762
//                                        Class clase = Class.forName(claseStr);
1763
//                                        Constructor constr = clase.getConstructor(null);
1764
//                                        status = (StatusRasterInterface)constr.newInstance(null);
1765
//                                        if(status!=null)
1766
//                                                status.setXMLEntity(xml, this);
1767
//                                }catch(ClassNotFoundException exc){
1768
//                                        exc.printStackTrace();
1769
//                                }catch(InstantiationException exc){
1770
//                                        exc.printStackTrace();
1771
//                                }catch(IllegalAccessException exc){
1772
//                                        exc.printStackTrace();
1773
//                                }catch(NoSuchMethodException exc){
1774
//                                        exc.printStackTrace();
1775
//                                }catch(InvocationTargetException exc){
1776
//                                        exc.printStackTrace();
1777
//                                }                                        
1778
//                        }
1779
//                }
1780
//                firstLoad = true;
1781
//        }
1782
//
1783
//        /**
1784
//         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
1785
//         */
1786
//        public String queryByPoint(Point p) throws DriverException {
1787
//                try {
1788
//                        if (queryable)
1789
//                        {
1790
//                                //TODO
1791
//                                // check if there are layers which are not queryable
1792
//                                ViewPort viewPort = getFMap().getViewPort();
1793
//
1794
//                                Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight);
1795
//                                Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
1796
//                                Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
1797
//                                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
1798
//                                int nCols = tiles.getNumCols();
1799
//
1800
//                                int col = (int) p.getX() / maxTilePrintWidth;
1801
//                                int row = (int) p.getY() / maxTilePrintHeight;
1802
//                                int tileIndex = (row*nCols) + col;
1803
//                                
1804
//                                ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex);
1805
//                                wmsStatus.setExtent(vp.getExtent());
1806
//                                wmsStatus.setHeight(vp.getImageHeight());
1807
//                                wmsStatus.setWidth(vp.getImageWidth());
1808
//                                wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo"));
1809
//                                return new String(getDriver()
1810
//                                                .getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE));
1811
//                        }
1812
//                        else
1813
//                        {
1814
//                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
1815
//                                                PluginServices.getText(this, "wms_not_queryable"));
1816
//                                return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>";
1817
//                        }
1818
//                } catch (WMSException  e) {
1819
//                        return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" +
1820
//                        e.getMessage() + "</exception>";
1821
//                } catch (ValidationException e) {
1822
//                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
1823
//                } catch (UnsupportedVersionException e) {
1824
//                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
1825
//                } catch (IOException e) {
1826
//                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
1827
//                } catch (NoninvertibleTransformException e) {
1828
//                        NotificationManager.addError("NotinvertibleTransform", e);
1829
//                }
1830
//                return null;
1831
//        }
1832
//
1833
//        /**
1834
//         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
1835
//         */
1836
//        public Rectangle2D getFullExtent() {
1837
//                return fullExtent;
1838
//        }
1839
//
1840
//        /**
1841
//         * 
1842
//         * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
1843
//         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
1844
//         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
1845
//         */
1846
//        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
1847
//                        Cancellable cancel,double scale) throws DriverException {
1848
//                
1849
//                if (isWithinScale(scale)){
1850
//                        Point2D p = viewPort.getOffset();
1851
//                        // p will be (0, 0) when drawing a view or other when painting onto
1852
//                        // the Layout.
1853
//                        visualStatus.width =  viewPort.getImageWidth();
1854
//                        visualStatus.height =  viewPort.getImageHeight();
1855
//                        visualStatus.minX = viewPort.getAdjustedExtent().getMinX();
1856
//                        visualStatus.minY = viewPort.getAdjustedExtent().getMinY();
1857
//                        visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX();
1858
//                        visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY();
1859
//                        if (isSizeFixed()) {
1860
//                                // This condition handles those situations in which the server can
1861
//                                // only give static extent and resolution maps despite we need
1862
//                                // a specific BBOX and pixel WIDTH and HEIGHT
1863
//                                drawFixedSize(g, viewPort, cancel);
1864
//
1865
//                        } else {
1866
//                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
1867
//                                Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
1868
//                                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
1869
//                                for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
1870
//                                        // drawing part
1871
//                                        try {
1872
//                                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
1873
//                                                drawTile(g, vp, cancel);
1874
//                                        } catch (NoninvertibleTransformException e) {
1875
//                                                e.printStackTrace();
1876
//                                        }
1877
//                                }
1878
//                        }
1879
//                }
1880
//        }
1881
//        
1882
//        private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
1883
//                // This is the extent that will be requested
1884
//                Rectangle2D bBox = getFullExtent();
1885
//                
1886
//                try {                        
1887
//                        wmsStatus.setExtent( bBox );
1888
//                        wmsStatus.setFormat( m_Format );
1889
//                        wmsStatus.setHeight( fixedSize.height );
1890
//                        wmsStatus.setWidth( fixedSize.width );
1891
//                        wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
1892
//                        wmsStatus.setSrs(m_SRS);
1893
//                        wmsStatus.setStyles(styles);
1894
//                        wmsStatus.setDimensions(dimensions);
1895
//                        wmsStatus.setTransparency(wmsTransparency);
1896
//                        wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
1897
//                        
1898
//                        File f = getDriver().getMap(wmsStatus);
1899
//                        String nameWorldFile = f.getPath() + getExtensionWorldFile();
1900
//                        com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
1901
//                        
1902
//                        if(status!=null && firstLoad){
1903
//                                status.applyStatus(this);
1904
//                                firstLoad = false;
1905
//                        }
1906
//                        
1907
//                        // And finally, obtain the extent intersecting the view and the BBox
1908
//                        // to draw to.
1909
//                        Rectangle2D extent = new Rectangle2D.Double();
1910
//                        Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
1911
//                        
1912
//                        ViewPortData vpData = new ViewPortData(
1913
//                                vp.getProjection(), new Extent(extent), fixedSize );
1914
//                        vpData.setMat(vp.getAffineTransform());
1915
//
1916
//                        rasterProcess(g, vpData, f);
1917
//                        
1918
//                } catch (ValidationException e) {
1919
//                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
1920
//                } catch (UnsupportedVersionException e) {
1921
//                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
1922
//                } catch (IOException e) {
1923
//                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
1924
//                } catch (WMSException e) {
1925
//            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
1926
//                        this.setVisible(false);
1927
//                }
1928
//                
1929
//                
1930
//        }
1931
//        
1932
//        /**
1933
//         * This is the method used to draw a tile in a WMS mosaic layer.
1934
//         */
1935
//        private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
1936
//
1937
//                // Compute the query geometry 
1938
//                // 1. Check if it is within borders
1939
//                Rectangle2D extent = getFullExtent();
1940
//        if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
1941
//                (vp.getExtent().getMinY() > extent.getMaxY()) ||
1942
//                (vp.getExtent().getMaxX() < extent.getMinX()) ||
1943
//                (vp.getExtent().getMaxY() < extent.getMinY())) {
1944
//            return;
1945
//        }
1946
//        
1947
//        // 2. Compute extent to be requested.
1948
//        Rectangle2D bBox = new Rectangle2D.Double();
1949
//        Rectangle2D.intersect(vp.getExtent(), extent, bBox);
1950
//        
1951
//        // 3. Compute size in pixels
1952
//        double scalex = vp.getAffineTransform().getScaleX(); 
1953
//        double scaley = vp.getAffineTransform().getScaleY(); 
1954
//        int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
1955
//        int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
1956
//        Dimension sz = new Dimension(wImg, hImg);
1957
//
1958
//        if ((wImg <= 0) || (hImg <= 0)) {
1959
//            return;
1960
//        }
1961
//                
1962
//                try {                        
1963
//                        wmsStatus.setExtent( bBox );
1964
//                        wmsStatus.setFormat(m_Format);
1965
//                        wmsStatus.setHeight( hImg );
1966
//                        wmsStatus.setWidth( wImg );
1967
//                        wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
1968
//                        wmsStatus.setSrs(m_SRS);
1969
//                        wmsStatus.setStyles(styles);
1970
//                        wmsStatus.setDimensions(dimensions);
1971
//                        wmsStatus.setTransparency(wmsTransparency);
1972
//                        wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
1973
//                        
1974
//                        File f = getDriver().getMap(wmsStatus);
1975
//                        String nameWordFile = f.getPath() + getExtensionWorldFile();
1976
//                        com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
1977
//                        
1978
//                        if(status!=null && firstLoad){
1979
//                                status.applyStatus(this);
1980
//                                firstLoad = false;
1981
//                        }
1982
//                        ViewPortData vpData = new ViewPortData(
1983
//                                vp.getProjection(), new Extent(bBox), sz );
1984
//                        vpData.setMat(vp.getAffineTransform());
1985
//
1986
//                        rasterProcess(g, vpData, f);
1987
//                        
1988
//                } catch (ValidationException e) {
1989
//                        throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
1990
//                } catch (UnsupportedVersionException e) {
1991
//                        throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
1992
//                } catch (IOException e) {
1993
//                        throw new DriverException(PluginServices.getText(this, "connect_error"), e);
1994
//                } catch (WMSException e) {
1995
//            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
1996
//                        this.setVisible(false);
1997
//                }
1998
//                
1999
//        }
2000
//
2001
//        /**
2002
//         * Obtiene la extensi?n del fichero de georreferenciaci?n
2003
//         * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
2004
//         * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld 
2005
//         */
2006
//        private String getExtensionWorldFile(){
2007
//                String extWorldFile = ".wld";
2008
//            if(m_Format.equals("image/tif") || m_Format.equals("image/tiff"))
2009
//                    extWorldFile = ".tfw";
2010
//            if(m_Format.equals("image/jpeg"))
2011
//                    extWorldFile = ".jpgw";
2012
//            return extWorldFile;
2013
//        }
2014
//        
2015
//        /**
2016
//         * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
2017
//         * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
2018
//         * @param sz Tama?o de la imagen en pixeles.
2019
//         * @return el 'WorldFile', como String.
2020
//         * @throws IOException
2021
//         */
2022
//        public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException {
2023
//                StringBuffer data = new StringBuffer();
2024
//            data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n");
2025
//            data.append("0.0\n");
2026
//            data.append("0.0\n");
2027
//            data.append((bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n");
2028
//            data.append(""+bBox.getMinX()+"\n");
2029
//            data.append(""+bBox.getMinY()+"\n");
2030
//            return data.toString();
2031
//        }
2032
//                
2033
//        /**
2034
//         * Dibuja una imagen usando PxRaster
2035
//         * @param g        Graphics2D en el que hay que dibujar.
2036
//         * @param vpData Par?metros de visualizaci?n
2037
//         * @param file La imagen en cuesti?n.
2038
//         */
2039
//        private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) {
2040
//                
2041
//                //Creamos el PxRaster        
2042
//                rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
2043
//                raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
2044
//                
2045
//                //Recuperamos la pila de filtros si ya hubiese sido cargado antes
2046
//                if(this.filterStack!=null)
2047
//                        raster.filterStack = this.filterStack;
2048
//                
2049
//                raster.setTransparency(false);
2050
//                                                
2051
//                //Asignamos transparencia y orden de bandas
2052
//                if(this.transparency==-1 && !firstLoad);
2053
//                else
2054
//                        raster.setTransparency(this.transparency);
2055
//                
2056
//                raster.setBand(GeoRasterFile.RED_BAND,rband);
2057
//                raster.setBand(GeoRasterFile.GREEN_BAND, gband);
2058
//                raster.setBand(GeoRasterFile.BLUE_BAND, bband);
2059
//        
2060
//                //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
2061
//                //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de 
2062
//                //propiedades cuando creamos un nuevo pxRaster
2063
//                if(this.stackManager != null)
2064
//                        raster.setStackManager(this.stackManager); 
2065
//                
2066
//                if(visualStatus != null){
2067
//                        visualStatus.bandCount = raster.getBandCount();
2068
//                        visualStatus.dataType = raster.getDataType();
2069
//                }
2070
//
2071
//                raster.draw(g, vpData);
2072
//                
2073
//                //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
2074
//                //si queremos desde las propiedades
2075
//                
2076
//                if(this.stackManager == null)
2077
//                        this.stackManager = raster.getStackManager(); 
2078
//                
2079
//                if(this.filterStack == null)
2080
//                        this.filterStack = raster.filterStack;
2081
//                
2082
//                //rasterFile.close();
2083
//        }
2084
//        
2085
//        /**
2086
//         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
2087
//         *                 com.iver.cit.gvsig.fmap.ViewPort,
2088
//         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
2089
//         */
2090
//        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
2091
//                throws DriverException {
2092
//                if (isVisible() && isWithinScale(scale)){        
2093
//                isPrinting = true;
2094
//                if (!mustTilePrint) {
2095
//                        draw(null, g, viewPort, cancel,scale);
2096
//                } else {
2097
//                // Para no pedir imagenes demasiado grandes, vamos
2098
//                // a hacer lo mismo que hace EcwFile: chunkear.
2099
//                // Llamamos a drawView con cuadraditos m?s peque?os
2100
//                // del BufferedImage ni caso, cuando se imprime viene con null
2101
//                        
2102
//                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
2103
//                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
2104
//                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
2105
//                            // Parte que dibuja
2106
//                            try {
2107
//                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
2108
//                                drawTile(g, vp, cancel);
2109
//                                } catch (NoninvertibleTransformException e) {
2110
//                                        e.printStackTrace();
2111
//                                }
2112
//                }
2113
//                }
2114
//            isPrinting = false;
2115
//                }
2116
//        }
2117
//        
2118
//        public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
2119
//                throws DriverException {
2120
//                draw(null, g, viewPort, cancel,scale);
2121
//        }
2122
//
2123
//        /**
2124
//         * Devuelve el FMapWMSDriver.
2125
//         *
2126
//         * @return FMapWMSDriver
2127
//         *
2128
//         * @throws IllegalStateException
2129
//         * @throws ValidationException
2130
//         * @throws UnsupportedVersionException
2131
//         * @throws IOException
2132
//         */
2133
//        private FMapWMSDriver getDriver()
2134
//                throws IllegalStateException, ValidationException, 
2135
//                        UnsupportedVersionException, IOException {
2136
//                if (wms == null) {
2137
//                        //wmsClient = WMSClientFactory.getClient(host);
2138
//                        wms = new FMapWMSDriver();
2139
//            wms.createClient(host);
2140
//            
2141
//                }
2142
//
2143
//                return wms;
2144
//        }
2145
//        
2146
//        /**
2147
//         * Devuelve el FMapWMSDriver.
2148
//         *
2149
//         * @return FMapWMSDriver
2150
//         *
2151
//         * @throws IllegalStateException
2152
//         * @throws ValidationException
2153
//         * @throws UnsupportedVersionException
2154
//         * @throws IOException
2155
//         */
2156
//        public void setDriver(FMapWMSDriver drv) {
2157
//                wms = drv;
2158
//        }
2159
//
2160
//        /**
2161
//         * Devuelve el URL.
2162
//         *
2163
//         * @return URL.
2164
//         */
2165
//        public URL getHost() {
2166
//                return host;
2167
//        }
2168
//
2169
//        /**
2170
//         * Inserta el URL.
2171
//         *
2172
//         * @param host URL.
2173
//         */
2174
//        public void setHost(URL host) {
2175
//                this.host = host;
2176
//        }
2177
//
2178
//        /**
2179
//         * Devuelve la informaci?n de la consulta.
2180
//         *
2181
//         * @return String.
2182
//         */
2183
//        public String getInfoLayerQuery() {
2184
//                return infoLayerQuery;
2185
//        }
2186
//
2187
//        /**
2188
//         * Inserta la informaci?n de la consulta.
2189
//         *
2190
//         * @param infoLayerQuery String.
2191
//         */
2192
//        public void setInfoLayerQuery(String infoLayerQuery) {
2193
//                this.infoLayerQuery = infoLayerQuery;
2194
//        }
2195
//
2196
//        /**
2197
//         * Devuelve la consulta.
2198
//         *
2199
//         * @return String.
2200
//         */
2201
//        public String getLayerQuery() {
2202
//                return layerQuery;
2203
//        }
2204
//
2205
//        /**
2206
//         * Inserta la consulta.
2207
//         *
2208
//         * @param layerQuery consulta.
2209
//         */
2210
//        public void setLayerQuery(String layerQuery) {
2211
//                this.layerQuery = layerQuery;
2212
//        }
2213
//
2214
//        /**
2215
//         * Devuelve el formato.
2216
//         *
2217
//         * @return Formato.
2218
//         */
2219
//        public String getFormat() {
2220
//                return m_Format;
2221
//        }
2222
//
2223
//        /**
2224
//         * Inserta el formato.
2225
//         *
2226
//         * @param format Formato.
2227
//         */
2228
//        public void setFormat(String format) {
2229
//                m_Format = format;
2230
//        }
2231
//
2232
//        /**
2233
//         * Devuelve el SRS.
2234
//         *
2235
//         * @return SRS.
2236
//         */
2237
//        public String getSRS() {
2238
//                return m_SRS;
2239
//        }
2240
//
2241
//        /**
2242
//         * Inserta el SRS.
2243
//         *
2244
//         * @param m_srs SRS.
2245
//         */
2246
//        public void setSRS(String m_srs) {
2247
//                m_SRS = m_srs;
2248
//        }
2249
//
2250
//        /**
2251
//         * Inserta la extensi?n total de la capa.
2252
//         *
2253
//         * @param fullExtent Rect?ngulo.
2254
//         */
2255
//        public void setFullExtent(Rectangle2D fullExtent) {
2256
//                this.fullExtent = fullExtent;
2257
//        }
2258
//        
2259
//        public HashMap getProperties() {
2260
//                HashMap info = new HashMap();
2261
//        String[] layerNames = getLayerQuery().split(",");
2262
//        Vector layers = new Vector(layerNames.length);
2263
//        try {
2264
//            if(getDriver().connect()){
2265
//                for (int i = 0; i < layerNames.length; i++) {
2266
//                    layers.add(i, wms.getLayer(layerNames[i]));
2267
//                }
2268
//                info.put("name", getName());
2269
//                info.put("selectedLayers", layers);
2270
//                info.put("host", getHost());
2271
//                info.put("srs", getSRS());
2272
//                info.put("format", getFormat());
2273
//                info.put("wmsTransparency", new Boolean(wmsTransparency));
2274
//                info.put("styles", styles);
2275
//                info.put("dimensions", dimensions);
2276
//                info.put("fixedSize", fixedSize);
2277
//                return info;
2278
//            }
2279
//        } catch (Exception e) {
2280
//            e.printStackTrace();
2281
//        }
2282
//        return null;
2283
//        }
2284
//        
2285
//        /**
2286
//         * Asignar el estado del raster
2287
//         * @param status
2288
//         */
2289
//        public void setStatus(StatusRasterInterface status){
2290
//                this.status = status;
2291
//        }
2292
//        
2293
//        /**
2294
//         * Obtiene el estado del raster
2295
//         * @return
2296
//         */
2297
//        public StatusRasterInterface getStatus(){
2298
//                return this.status;
2299
//        }
2300
//        
2301
//        /* (non-Javadoc)
2302
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
2303
//         */
2304
//        public ArrayList getAttributes() {
2305
//                if(rasterFile != null){
2306
//                        ArrayList attr = new ArrayList();
2307
//                        String dataType = "Byte";
2308
//                        if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte";
2309
//                        else if (visualStatus.dataType == DataBuffer.TYPE_SHORT)
2310
//                                dataType = "Short";
2311
//                        else if (visualStatus.dataType == DataBuffer.TYPE_USHORT)
2312
//                                dataType = "Unsigned Short";
2313
//                        else if (visualStatus.dataType == DataBuffer.TYPE_INT)
2314
//                                dataType = "Integer";
2315
//                        else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT)
2316
//                                dataType = "Float";
2317
//                        else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE)
2318
//                                dataType = "Double";
2319
//                        else
2320
//                                dataType = "Unknown";
2321
//
2322
//                        Object [][] a = {
2323
//                                {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())},
2324
//                                {"Filesize",new Long(0)},
2325
//                                {"Width",new Integer((int)this.getWidth())},
2326
//                                {"Height", new Integer((int)this.getHeight())},
2327
//                                {"Bands", new Integer(visualStatus.bandCount)},
2328
//                                {"BandDataType", dataType}
2329
//                        };
2330
//                        for (int i=0; i<a.length; i++)
2331
//                                attr.add(a[i]);
2332
//
2333
//                        return attr;
2334
//                }
2335
//                return  null;
2336
//        }
2337
//        
2338
//        /* (non-Javadoc)
2339
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
2340
//         */
2341
//        public RasterFilterStack getFilterStack() {
2342
//                if(raster!=null)
2343
//                        return raster.filterStack;
2344
//                return null;
2345
//        }
2346
//        /* (non-Javadoc)
2347
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
2348
//         */
2349
//        public double getHeight() {
2350
//                return visualStatus.height;
2351
//        }
2352
//        
2353
//        /* (non-Javadoc)
2354
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
2355
//         */
2356
//        public double getMaxX() {
2357
//                return visualStatus.maxX;
2358
//        }
2359
//        
2360
//        /* (non-Javadoc)
2361
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
2362
//         */
2363
//        public double getMaxY() {
2364
//                return visualStatus.maxY;
2365
//        }
2366
//        
2367
//        /* (non-Javadoc)
2368
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
2369
//         */
2370
//        public double getMinX() {
2371
//                return visualStatus.minX;
2372
//        }
2373
//        
2374
//        /* (non-Javadoc)
2375
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
2376
//         */
2377
//        public double getMinY() {
2378
//                return visualStatus.minY;
2379
//        }
2380
//        /* (non-Javadoc)
2381
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
2382
//         */
2383
//        public int[] getPixel(double wcx, double wcy) {
2384
//                if(getPxRaster() != null)
2385
//                        return getPxRaster().getPixel(wcx, wcy);
2386
//        return null;
2387
//        }
2388
//        /* (non-Javadoc)
2389
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
2390
//         */
2391
//        public RasterAdapter getSource() {
2392
//                return null;
2393
//        }
2394
//        /* (non-Javadoc)
2395
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
2396
//         */
2397
//        public double getWidth() {
2398
//                return visualStatus.width;
2399
//        }
2400
//        /* (non-Javadoc)
2401
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
2402
//         */
2403
//        public void setBand(int flag, int nBand) {
2404
//                switch(flag){
2405
//                case GeoRasterFile.RED_BAND:setBandR(nBand);break;
2406
//                case GeoRasterFile.GREEN_BAND:setBandG(nBand);break;
2407
//                case GeoRasterFile.BLUE_BAND:setBandB(nBand);break;
2408
//                }
2409
//        }
2410
//        /* (non-Javadoc)
2411
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
2412
//         */
2413
//        public void setFilterStack(RasterFilterStack stack) {
2414
//                this.filterStack = stack;
2415
//        }
2416
//        /* (non-Javadoc)
2417
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
2418
//         */
2419
//        public void setPos(int x, int y) {
2420
//                this.posX = x;
2421
//                this.posY = y;
2422
//        }
2423
//        
2424
//        /* (non-Javadoc)
2425
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
2426
//         */
2427
//        public void setPosWC(double x, double y) {
2428
//                this.posXWC = x;
2429
//                this.posYWC = y;
2430
//        }
2431
//        
2432
//        /* (non-Javadoc)
2433
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
2434
//         */
2435
//        public void setRGB(int r, int g, int b) {
2436
//                this.r = r;
2437
//                this.g = g;
2438
//                this.b = b;
2439
//        }
2440
//        /* (non-Javadoc)
2441
//         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
2442
//         */
2443
//        public void setSource(RasterAdapter ra) {
2444
//        }
2445
//        /**
2446
//         * @return Returns the raster.
2447
//         */
2448
//        public PxRaster getPxRaster() {
2449
//                return raster;
2450
//        }
2451
//        /**
2452
//         * @return Returns the rasterFile.
2453
//         */
2454
//        public GeoRasterFile getGeoRasterFile() {
2455
//                return rasterFile;
2456
//        }
2457
//        
2458
//        public void setTransparency(int trans) {
2459
//                this.transparency = trans;
2460
//        }
2461
//        
2462
//        /**
2463
//         * Sets the R-band.
2464
//         * 
2465
//         * Asigna la banda R.
2466
//         * @param r
2467
//         */
2468
//        public void setBandR(int r){
2469
//                this.rband = r;
2470
//        }
2471
//        
2472
//        /**
2473
//         * Sets the G-band.
2474
//         * 
2475
//         * Asigna la banda G
2476
//         * @param g
2477
//         */
2478
//        public void setBandG(int g){
2479
//                this.gband = g;
2480
//        }
2481
//        
2482
//        /**
2483
//         * Sets the B-band.
2484
//         * 
2485
//         * Asigna la banda B
2486
//         * @param b
2487
//         */
2488
//        public void setBandB(int b){
2489
//                this.bband = b;
2490
//        }
2491
//
2492
//    /**
2493
//     * @return Returns the wmsTransparency.
2494
//     */
2495
//    public boolean isWmsTransparent() {
2496
//        return wmsTransparency;
2497
//    }
2498
//
2499
//    /**
2500
//     * @param wmsTransparency The wmsTransparency to set.
2501
//     */
2502
//    public void setWmsTransparency(boolean wmsTransparency) {
2503
//        this.wmsTransparency = wmsTransparency;
2504
//    }
2505
//
2506
//     /**
2507
//     * @param styles
2508
//     */
2509
//    public void setStyles(Vector styles) {
2510
//            //laura:
2511
//            //layer query is built with the layer in reverse order
2512
//            // so here we build the styles upside-down.
2513
//            if (styles != null)
2514
//            {
2515
//                    this.styles = new Vector();
2516
//                    for(int i = styles.size()-1; i>=0; i--)
2517
//                    {
2518
//                            this.styles.add(styles.elementAt(i));
2519
//                    }
2520
//            }
2521
//    }
2522
//    
2523
//    /**
2524
//     * Sets the dimension vector that is a list of key-value pairs containing
2525
//     * the name of the dimension and the value for it
2526
//     * @param dimensions
2527
//     */
2528
//    public void setDimensions(Vector dimensions) {
2529
//        this.dimensions = dimensions;
2530
//    }
2531
//
2532
//    /**
2533
//     * Sets the set of URLs that should be accessed for each operation performed
2534
//     * to the server.
2535
//     * 
2536
//     * @param onlineResources
2537
//     */
2538
//        public void setOnlineResources(Hashtable onlineResources) {
2539
//                this.onlineResources = onlineResources;
2540
//        }
2541
//        
2542
//        /**
2543
//         * When a server is not fully featured and it only can serve constant map
2544
//         * sizes this value must be set. It expresses the size in pixels (width, height)
2545
//         * that the map will be requested.
2546
//         * @param Dimension sz
2547
//         */
2548
//        public void setFixedSize(Dimension sz) {
2549
//                fixedSize = sz;
2550
//        }
2551
//        
2552
//        /**
2553
//         * Tells whether if this layer must deal with the server with the constant-size
2554
//         * limitations or not.
2555
//         * @return boolean.
2556
//         */
2557
//        private boolean isSizeFixed() {
2558
//                return fixedSize != null && fixedSize.getWidth() > 0 && fixedSize.getHeight() > 0;
2559
//        }
2560
//
2561
//        /**
2562
//         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
2563
//         * maps to FMap's infoByPoint(p) operation.
2564
//         * @param b
2565
//         */
2566
//        public void setQueryable(boolean b) {
2567
//                queryable = b;
2568
//        }
2569
//
2570
//        /**
2571
//         * Creates the part of a OGC's MapContext document that would describe this
2572
//         * layer(s).
2573
//         * @param version, The desired version of the resulting document. (1.1.0)
2574
//         * @return String containing the xml.
2575
//         * @throws UnsupportedVersionException 
2576
//         */
2577
//        public String toMapContext(String mapContextVersion) {
2578
//                XmlBuilder xml = new XmlBuilder();
2579
//                FMapWMSDriver drv;
2580
//                try {
2581
//                        drv = getDriver();
2582
//                        drv.connect();
2583
//                } catch (Exception e) {
2584
//                        return xml.toString();
2585
//                } 
2586
//                String[] layerNames = getLayerQuery().split(",");
2587
//                for (int i = 0; i < layerNames.length; i++) {
2588
//                        WMSLayerNode layer = drv.getLayer(layerNames[i]);
2589
//                        HashMap xmlAttrs = new HashMap();
2590
//                        
2591
//                        // <Layer>
2592
//                        xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible()+"");
2593
//                        xmlAttrs.put(WebMapContextTags.QUERYABLE, queryable+"");
2594
//                        xml.openTag(WebMapContextTags.LAYER);
2595
//                        if (mapContextVersion.equals("1.1.0") || mapContextVersion.equals("1.0.0")) {
2596
//                                // <Server>
2597
//                                xmlAttrs.put(WebMapContextTags.SERVICE, WebMapContextTags.WMS);
2598
//                                xmlAttrs.put(WebMapContextTags.VERSION, drv.getVersion());
2599
//                                xmlAttrs.put(WebMapContextTags.SERVER_TITLE, drv.getServiceTitle());
2600
//                                xml.openTag(WebMapContextTags.SERVER, xmlAttrs);
2601
//                                xmlAttrs.clear();
2602
//                                
2603
//                                        // <OnlineResource>
2604
//                                        xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
2605
//                                        xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString());
2606
//                                        xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs);
2607
//                                        xmlAttrs.clear();
2608
//                                        // </OnlineResource>
2609
//                                        
2610
//                                xml.closeTag();
2611
//                                // </Server>
2612
//                                
2613
//                                // <Name>
2614
//                                xml.writeTag(WebMapContextTags.NAME, layer.getName().trim());
2615
//                                // </Name>
2616
//                                
2617
//                                // <Title>
2618
//                                xml.writeTag(WebMapContextTags.TITLE, getName().trim());
2619
//                                // </Title>
2620
//                                
2621
//                                // <Abstract>
2622
//                                if (layer.getAbstract() != null)
2623
//                                        xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract());
2624
//                                // </Abstract>
2625
//                                
2626
//                                // <SRS> (a list of available SRS for the enclosing layer)
2627
//                                String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]);
2628
//                                String mySRS = strings[0];
2629
//                                for (int j = 1; j < strings.length; j++) {
2630
//                                        mySRS += ","+strings[j];
2631
//                                }
2632
//                                xml.writeTag(WebMapContextTags.SRS, mySRS);
2633
//                                // </SRS>
2634
//                                
2635
//                                // <FormatList>
2636
//                                xml.openTag(WebMapContextTags.FORMAT_LIST);
2637
//                                        strings = (String[]) drv.getFormats().toArray(new String[0]);
2638
//                                        for (int j = 0; j < strings.length; j++) {
2639
//                    // <Format>
2640
//                                                String str = strings[j].trim();
2641
//                                                if (str.equals(getFormat()))
2642
//                                                        xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
2643
//                                                else
2644
//                                                        xml.writeTag(WebMapContextTags.FORMAT, str);
2645
//                    // </Format>        
2646
//                                        }
2647
//                                xml.closeTag();
2648
//                                // </FormatList>
2649
//                                
2650
//                                // <StyleList>
2651
//                                if (layer.getStyles().size()>0) {
2652
//                                        xml.openTag(WebMapContextTags.STYLE_LIST);
2653
//                                        for (int j = 0; j < layer.getStyles().size(); j++) {
2654
//                                                // <Style>
2655
//                                                FMapWMSStyle st = (FMapWMSStyle) layer.getStyles().get(i);
2656
//                                                if (st.equals(layer.getSelectedStyle()))
2657
//                                                        xmlAttrs.put(WebMapContextTags.CURRENT, "1");
2658
//                                                xml.openTag(WebMapContextTags.STYLE, xmlAttrs);
2659
//                                                
2660
//                                                        // <Name>
2661
//                                                        xml.writeTag(WebMapContextTags.NAME, st.name);
2662
//                                                        // </Name>
2663
//                                                        
2664
//                                                        // <Title>
2665
//                                                        xml.writeTag(WebMapContextTags.TITLE, st.title);
2666
//                                                        // </Title>
2667
//                                                        
2668
//                                                        // <LegendURL width="180" format="image/gif" height="50">
2669
//                                                                // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
2670
//                                                                // </OnlineResource>
2671
//                                                        // </LegendURL>
2672
//                                                xml.closeTag();
2673
//                                                // </Style>
2674
//                                                
2675
//                                        }
2676
//                                        xml.closeTag();
2677
//                                }
2678
//                                // </StyleList>
2679
//                                if (mapContextVersion.compareTo("1.0.0") > 0) {
2680
//                                // <DimensionList>
2681
//                                        xml.openTag(WebMapContextTags.DIMENSION_LIST);
2682
//                                        // <Dimension>
2683
//                                        // </Dimension>
2684
//                                        xml.closeTag();
2685
//                                // </DimensionList>
2686
//                                }
2687
//                        } else {
2688
//                                xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version"));
2689
//                        }
2690
//                        // </Layer>
2691
//                        xml.closeTag();
2692
//                }
2693
//                return xml.getXML();
2694
//        }
2695
//}