Revision 6050 trunk/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java

View differences:

FLyrWMS.java
105 105
*
106 106
* @author Jaume Dominguez Faus
107 107
* 		  Nacho Brodin
108
* 
108
*
109 109
*/
110 110
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
111 111
	private boolean 					isPrinting = false;
......
115 115
	private final int 					maxTileDrawHeight = 1023;
116 116
	private final int 					maxTilePrintWidth = 1023;
117 117
	private final int 					maxTilePrintHeight = 1023;
118
    
118

  
119 119
    public URL 							host;
120 120
    public String 						m_Format;
121
    
121

  
122 122
	private String 						m_SRS;
123 123
	private String 						layerQuery;
124 124
	private String 						infoLayerQuery;
......
143 143
	private Dimension 					fixedSize;
144 144
	private boolean 					queryable = true;
145 145
	private VisualStatusWMS				visualStatus = new VisualStatusWMS();
146
	
147
	
146

  
147

  
148 148
	private class MyCancellable implements ICancellable
149 149
	{
150 150

  
......
156 156
		public boolean isCanceled() {
157 157
			return original.isCanceled();
158 158
		}
159
		
159

  
160 160
	}
161
	
161

  
162 162
	public FLyrWMS(){
163 163
		super();
164 164
	}
165
	
165

  
166 166
	public FLyrWMS(Map args) throws DriverIOException{
167 167
		FMapWMSDriver drv = null;
168 168
		String host = (String)args.get("host");
......
171 171
		String sSRS = (String)args.get("SRS");
172 172
		String sFormat = (String)args.get("Format");
173 173
		String[] sLayers = sLayer.split(",");
174
		
174

  
175 175
		try {
176 176
			this.setHost(new URL(host));
177 177
		} catch (MalformedURLException e) {
178 178
			//e.printStackTrace();
179
			throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");			
179
			throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");
180 180
		}
181 181
		try {
182 182
			drv = this.getDriver();
183 183
		} catch (Exception e) {
184 184
			// e.printStackTrace();
185
			throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");			
185
			throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");
186 186
		}
187 187
		if( sFormat == null || sSRS == null || fullExtent == null ) {
188 188
			if (!drv.connect(null))
189
				throw new DriverIOException("Can't connect to host '" + host + "'."); 
190
			
189
				throw new DriverIOException("Can't connect to host '" + host + "'.");
190

  
191 191
			WMSLayerNode wmsNode = drv.getLayer(sLayer);
192
							
192

  
193 193
			if (wmsNode == null){
194 194
				throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'.");
195
			}		
195
			}
196 196
			if( sFormat == null ) {
197 197
				sFormat = this.getGreatFormat(drv.getFormats());
198 198
			}
......
203 203
				fullExtent = drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0));
204 204
			}
205 205
		}
206
		
207
				
206

  
207

  
208 208
		this.setFullExtent(fullExtent);
209 209
		this.setFormat(sFormat);
210 210
		this.setLayerQuery(sLayer);
......
212 212
		this.setSRS(sSRS);
213 213
		this.setName(sLayer);
214 214
	}
215
	
215

  
216 216
	/**
217
	 * It choose the best format to load different maps if the server 
218
	 * supports it. This format could be png, because it supports 
217
	 * It choose the best format to load different maps if the server
218
	 * supports it. This format could be png, because it supports
219 219
	 * transparency.
220 220
	 * @param formats
221 221
	 * Arraywith all the formats supported by the server
222 222
	 * @return
223
	 */	
223
	 */
224 224
	private String getGreatFormat(Vector formats){
225 225
	    for (int i=0 ; i<formats.size() ; i++){
226 226
	        String format = (String) formats.get(i);
......
231 231
	            return format;
232 232
	    	}
233 233
	    }
234
		    
234

  
235 235
	    return (String)formats.get(0);
236 236
	}
237
	
237

  
238 238
	/**
239 239
	 * Clase que contiene los datos de visualizaci?n de WMS.
240 240
	 * @author Nacho Brodin (brodin_ign@gva.es)
241 241
	 */
242 242
	private class VisualStatusWMS{
243 243
		/**
244
		 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con 
244
		 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
245 245
		 * el ancho y alto del viewPort
246 246
		 */
247 247
		private	int							width = 0, height = 0;
......
249 249
		private int 						bandCount = 0;
250 250
		private int							dataType = DataBuffer.TYPE_UNDEFINED;
251 251
	}
252
	 
253 252

  
253

  
254 254
	/**
255 255
	 * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
256 256
	 * capa.
......
263 263

  
264 264
		// Full extent
265 265
		xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
266
		
266

  
267 267
		// Host
268 268
		xml.putProperty("host", host.toExternalForm());
269
		
269

  
270 270
		// Part of the query that is not the host, or the
271 271
		// layer names, or other not listed bellow
272 272
		xml.putProperty("infoLayerQuery", infoLayerQuery);
273
		
273

  
274 274
		// Part of the query containing the layer names
275 275
		xml.putProperty("layerQuery", layerQuery);
276
		
276

  
277 277
		// Format
278 278
		xml.putProperty("format", m_Format);
279
		
279

  
280 280
		// SRS
281 281
		xml.putProperty("srs", m_SRS);
282 282
		if (status!=null)
......
285 285
			status = new StatusLayerRaster();
286 286
			status.getXMLEntity(xml, true, this);
287 287
		}
288
		
288

  
289 289
        // Transparency
290 290
        xml.putProperty("wms_transparency", wmsTransparency);
291
        
291

  
292 292
        // Styles
293 293
        if (styles!=null){
294 294
            String stylePr = "";
......
301 301
            	stylePr += " ";
302 302
            xml.putProperty("styles", stylePr);
303 303
        }
304
        
305
        // Dimensions 
304

  
305
        // Dimensions
306 306
        if (dimensions!=null){
307 307
            String dim = "";
308 308
            for (int i = 0; i < dimensions.size(); i++) {
......
314 314
            	dim += " ";
315 315
            xml.putProperty("dimensions", dim);
316 316
        }
317
        
317

  
318 318
        // OnlineResources
319 319
        Iterator it = onlineResources.keySet().iterator();
320 320
        String strOnlines = "";
......
326 326
        		strOnlines += "~##SEP1##~";
327 327
        }
328 328
        xml.putProperty("onlineResources", strOnlines);
329
        
329

  
330 330
        // Queryable
331 331
        xml.putProperty("queryable", queryable);
332
        
332

  
333 333
        // fixedSize
334 334
        if (isSizeFixed()) {
335 335
        	xml.putProperty("fixedSize", true);
......
380 380
		super.setXMLEntity(xml);
381 381
		fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
382 382
					"fullExtent"));
383
		
383

  
384 384
		// Host
385 385
		try {
386 386
			host = new URL(xml.getStringProperty("host"));
......
394 394

  
395 395
		// Part of the query containing the layer names
396 396
		layerQuery = xml.getStringProperty("layerQuery");
397
		
397

  
398 398
		// Format
399 399
		m_Format = xml.getStringProperty("format");
400
		
400

  
401 401
		// SRS
402 402
		m_SRS = xml.getStringProperty("srs");
403
		
403

  
404 404
		String claseStr = StatusLayerRaster.defaultClass;
405 405
		if (xml.contains("raster.class")) {
406 406
			claseStr = xml.getStringProperty("raster.class");
407 407
		}
408
		
408

  
409 409
		// Transparency
410 410
        if (xml.contains("wms_transparency"))
411 411
            wmsTransparency = xml.getBooleanProperty("wms_transparency");
412
        
412

  
413 413
        // Styles
414 414
        if (xml.contains("styles")){
415 415
            styles = new Vector();
416 416
            String[] stl = xml.getStringProperty("styles").split(",");
417
            
417

  
418 418
            for (int i = 0; i < stl.length; i++) {
419 419
            	if (stl[i].equals(" "))
420 420
            		stl[i]="";
421 421
                styles.add(stl[i]);
422 422
            }
423 423
        }
424
        
424

  
425 425
        // Dimensions
426 426
        if (xml.contains("dimensions")){
427 427
            dimensions = new Vector();
......
429 429
            for (int i = 0; i < dims.length; i++){
430 430
            	if (dims[i].equals(" "))
431 431
            		dims[i]="";
432
                
432

  
433 433
                dimensions.add(dims[i]);
434 434
            }
435 435
        }
436
        
436

  
437 437
        // OnlineResources
438 438
        if (xml.contains("onlineResources")) {
439 439
        	String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~");
......
443 443
					onlineResources.put(resources[0], resources[1]);
444 444
			}
445 445
        }
446
        
446

  
447 447
        // Queryable
448 448
        queryable = true; // let's assume that the layer is queryable by default
449 449
        if (xml.contains("queryable"))
450 450
        	queryable = xml.getBooleanProperty("queryable");
451
        
451

  
452 452
        // fixedSize
453 453
        if (xml.contains("fixedSize")) {
454
        	fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), 
454
        	fixedSize = new Dimension(xml.getIntProperty("fixedWidth"),
455 455
        			                  xml.getIntProperty("fixedHeight"));
456 456
        }
457
        
457

  
458 458
		if(status!=null)
459 459
			status.setXMLEntity(xml, this);
460 460
		else{
......
475 475
					exc.printStackTrace();
476 476
				}catch(InvocationTargetException exc){
477 477
					exc.printStackTrace();
478
				}					
478
				}
479 479
			}
480 480
		}
481 481
		firstLoad = true;
......
486 486
	 */
487 487
	public XMLItem[] getInfo(Point p, double tolerance) throws DriverException {
488 488
		XMLItem[] item =  new XMLItem[1];
489
		try {			
489
		try {
490 490
			if (queryable)
491 491
			{
492 492
				//TODO
......
502 502
				int col = (int) p.getX() / maxTilePrintWidth;
503 503
				int row = (int) p.getY() / maxTilePrintHeight;
504 504
				int tileIndex = (row*nCols) + col;
505
				
505

  
506 506
				ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex);
507 507
				wmsStatus.setExtent(vp.getExtent());
508 508
				wmsStatus.setHeight(vp.getImageHeight());
509 509
				wmsStatus.setWidth(vp.getImageWidth());
510 510
				wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo"));
511 511
				item[0] = new StringXMLItem(new String(getDriver()
512
						.getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE)),this); 
512
						.getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE)),this);
513 513
				return item;
514 514
			}
515 515
			else
......
543 543
	}
544 544

  
545 545
	/**
546
	 * 
546
	 *
547 547
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
548 548
	 * 		java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
549 549
	 * 		com.iver.cit.gvsig.fmap.operations.Cancellable)
550 550
	 */
551 551
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
552 552
			Cancellable cancel,double scale) throws DriverException {
553
		
553

  
554 554
		if (isWithinScale(scale)){
555 555
			Point2D p = viewPort.getOffset();
556 556
			// p will be (0, 0) when drawing a view or other when painting onto
......
589 589
//		long mem = r.totalMemory() - r.freeMemory();
590 590
//		System.err.println("Memoria total: " + (mem / 1024) +"KB");
591 591
	}
592
	
592

  
593 593
	private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
594 594
		// This is the extent that will be requested
595 595
		Rectangle2D bBox = getFullExtent();
596 596
		MyCancellable c = new MyCancellable(cancel);
597
		
598
		try {			
597

  
598
		try {
599 599
			wmsStatus.setExtent( bBox );
600 600
			wmsStatus.setFormat( m_Format );
601 601
			wmsStatus.setHeight( fixedSize.height );
......
611 611
				return;
612 612
			String nameWorldFile = f.getPath() + getExtensionWorldFile();
613 613
			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
614
			
614

  
615 615
			if(status!=null && firstLoad){
616 616
				status.applyStatus(this);
617 617
				firstLoad = false;
618 618
			}
619
			
619

  
620 620
			// And finally, obtain the extent intersecting the view and the BBox
621 621
			// to draw to.
622 622
			Rectangle2D extent = new Rectangle2D.Double();
623 623
			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
624
			
624

  
625 625
			ViewPortData vpData = new ViewPortData(
626 626
				vp.getProjection(), new Extent(extent), fixedSize );
627 627
			vpData.setMat(vp.getAffineTransform());
628 628

  
629 629
			rasterProcess(g, vpData, f);
630
			
630

  
631 631
		} catch (ValidationException e) {
632 632
			if (!c.isCanceled())
633 633
				throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
......
643 643
				this.setVisible(false);
644 644
			}
645 645
		}
646
		
647
		
646

  
647

  
648 648
	}
649
	
649

  
650 650
	/**
651 651
	 * This is the method used to draw a tile in a WMS mosaic layer.
652 652
	 */
653 653
	private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException {
654 654

  
655
		// Compute the query geometry 
655
		// Compute the query geometry
656 656
		// 1. Check if it is within borders
657 657
		Rectangle2D extent = getFullExtent();
658 658
        if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
......
661 661
                (vp.getExtent().getMaxY() < extent.getMinY())) {
662 662
            return;
663 663
        }
664
        
664

  
665 665
        // 2. Compute extent to be requested.
666 666
        Rectangle2D bBox = new Rectangle2D.Double();
667 667
        Rectangle2D.intersect(vp.getExtent(), extent, bBox);
668
        
668

  
669 669
        // 3. Compute size in pixels
670
        double scalex = vp.getAffineTransform().getScaleX(); 
671
        double scaley = vp.getAffineTransform().getScaleY(); 
670
        double scalex = vp.getAffineTransform().getScaleX();
671
        double scaley = vp.getAffineTransform().getScaleY();
672 672
        int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
673 673
        int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
674
        
674

  
675 675
        Dimension sz = new Dimension(wImg, hImg);
676 676

  
677 677
        if ((wImg <= 0) || (hImg <= 0)) {
678 678
            return;
679 679
        }
680 680
        MyCancellable c = new MyCancellable(cancel);
681
		
681

  
682 682
		try {
683
			wImg = vp.getImageWidth();
684
			hImg = vp.getImageHeight();
685
			sz = new Dimension(vp.getImageWidth(), vp.getImageHeight());
686
			bBox = vp.getAdjustedExtent();
687
			
683
//			wImg = vp.getImageWidth();
684
//			hImg = vp.getImageHeight();
685
//			sz = new Dimension(vp.getImageWidth(), vp.getImageHeight());
686
//			bBox = vp.getAdjustedExtent();
687

  
688 688
			wmsStatus.setExtent( bBox );
689 689
			wmsStatus.setFormat(m_Format);
690 690
			wmsStatus.setHeight( hImg );
......
695 695
			wmsStatus.setDimensions(dimensions);
696 696
			wmsStatus.setTransparency(wmsTransparency);
697 697
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
698
			
698

  
699 699
			File f = getDriver().getMap(wmsStatus, c);
700 700
			if (f == null)
701 701
				return;
702 702
			String nameWordFile = f.getPath() + getExtensionWorldFile();
703 703
			com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
704
			
704

  
705 705
			if(status!=null && firstLoad){
706 706
				status.applyStatus(this);
707 707
				firstLoad = false;
......
711 711
			vpData.setMat(vp.getAffineTransform());
712 712

  
713 713
			rasterProcess(g, vpData, f);
714
			
714

  
715 715
		} catch (ValidationException e) {
716 716
			if (!c.isCanceled())
717 717
				throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
......
727 727
				this.setVisible(false);
728 728
			}
729 729
		}
730
		
730

  
731 731
	}
732 732

  
733 733
	/**
734 734
	 * Obtiene la extensi?n del fichero de georreferenciaci?n
735 735
	 * @return String con la extensi�n del fichero de georreferenciaci�n dependiendo
736
	 * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld 
736
	 * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
737 737
	 */
738 738
	private String getExtensionWorldFile(){
739 739
		String extWorldFile = ".wld";
......
743 743
    		extWorldFile = ".jpgw";
744 744
    	return extWorldFile;
745 745
	}
746
	
746

  
747 747
	/**
748 748
	 * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
749 749
	 * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
......
761 761
    	data.append(""+bBox.getMinY()+"\n");
762 762
    	return data.toString();
763 763
	}
764
		
764

  
765 765
	/**
766 766
	 * Dibuja una imagen usando PxRaster
767 767
	 * @param g	Graphics2D en el que hay que dibujar.
......
769 769
	 * @param file La imagen en cuesti?n.
770 770
	 */
771 771
	private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) {
772
		
773
		//Creamos el PxRaster	
772

  
773
		//Creamos el PxRaster
774 774
		rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
775 775
		raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
776
		
776

  
777 777
		//Recuperamos la pila de filtros si ya hubiese sido cargado antes
778 778
		if(this.filterStack!=null)
779 779
			raster.filterStack = this.filterStack;
780
		
780

  
781 781
		raster.setTransparency(false);
782
						
782

  
783 783
		//Asignamos transparencia y orden de bandas
784 784
		if(this.transparency==-1 && !firstLoad);
785 785
		else
786 786
			raster.setTransparency(this.transparency);
787
		
787

  
788 788
		raster.setBand(GeoRasterFile.RED_BAND,rband);
789 789
		raster.setBand(GeoRasterFile.GREEN_BAND, gband);
790 790
		raster.setBand(GeoRasterFile.BLUE_BAND, bband);
791
	
791

  
792 792
		//Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
793
		//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de 
793
		//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
794 794
		//propiedades cuando creamos un nuevo pxRaster
795 795
		if(this.stackManager != null)
796
			raster.setStackManager(this.stackManager); 
797
		
796
			raster.setStackManager(this.stackManager);
797

  
798 798
		if(visualStatus != null){
799 799
			visualStatus.bandCount = raster.getBandCount();
800 800
			visualStatus.dataType = raster.getDataType();
801 801
		}
802 802

  
803 803
		raster.draw(g, vpData);
804
		
804

  
805 805
		//En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
806 806
		//si queremos desde las propiedades
807
		
807

  
808 808
		if(this.stackManager == null)
809
			this.stackManager = raster.getStackManager(); 
810
		
809
			this.stackManager = raster.getStackManager();
810

  
811 811
		if(this.filterStack == null)
812 812
			this.filterStack = raster.filterStack;
813
		
813

  
814 814
		//rasterFile.close();
815 815
	}
816
	
816

  
817 817
	/**
818 818
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
819 819
	 * 		com.iver.cit.gvsig.fmap.ViewPort,
......
821 821
	 */
822 822
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
823 823
		throws DriverException {
824
		if (isVisible() && isWithinScale(scale)){	
824
		if (isVisible() && isWithinScale(scale)){
825 825
		isPrinting = true;
826 826
		if (!mustTilePrint) {
827 827
			draw(null, g, viewPort, cancel,scale);
......
830 830
	        // a hacer lo mismo que hace EcwFile: chunkear.
831 831
	        // Llamamos a drawView con cuadraditos m�s peque�os
832 832
	        // del BufferedImage ni caso, cuando se imprime viene con null
833
			
833

  
834 834
			Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
835 835
			tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
836 836
			for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
......
846 846
	    isPrinting = false;
847 847
		}
848 848
	}
849
	
849

  
850 850
	public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
851 851
		throws DriverException {
852 852
		draw(null, g, viewPort, cancel,scale);
......
863 863
	 * @throws IOException
864 864
	 */
865 865
	private FMapWMSDriver getDriver()
866
		throws IllegalStateException, ValidationException, 
866
		throws IllegalStateException, ValidationException,
867 867
			UnsupportedVersionException, IOException {
868 868
		return FMapWMSDriverFactory.getFMapDriverForURL(host);
869 869
	}
870
	
870

  
871 871
	/**
872 872
	 * Devuelve el FMapWMSDriver.
873 873
	 *
......
980 980
	public void setFullExtent(Rectangle2D fullExtent) {
981 981
		this.fullExtent = fullExtent;
982 982
	}
983
	
983

  
984 984
	public HashMap getProperties() {
985 985
		HashMap info = new HashMap();
986 986
        String[] layerNames = getLayerQuery().split(",");
......
1006 1006
        }
1007 1007
        return null;
1008 1008
	}
1009
	
1009

  
1010 1010
	/**
1011 1011
	 * Asignar el estado del raster
1012 1012
	 * @param status
......
1014 1014
	public void setStatus(StatusRasterInterface status){
1015 1015
		this.status = status;
1016 1016
	}
1017
	
1017

  
1018 1018
	/**
1019 1019
	 * Obtiene el estado del raster
1020 1020
	 * @return
......
1022 1022
	public StatusRasterInterface getStatus(){
1023 1023
		return this.status;
1024 1024
	}
1025
	
1025

  
1026 1026
	/* (non-Javadoc)
1027 1027
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
1028 1028
	 */
......
1059 1059
		}
1060 1060
		return  null;
1061 1061
	}
1062
	
1062

  
1063 1063
	/* (non-Javadoc)
1064 1064
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
1065 1065
	 */
......
1074 1074
	public double getHeight() {
1075 1075
		return visualStatus.height;
1076 1076
	}
1077
	
1077

  
1078 1078
	/* (non-Javadoc)
1079 1079
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
1080 1080
	 */
1081 1081
	public double getMaxX() {
1082 1082
		return visualStatus.maxX;
1083 1083
	}
1084
	
1084

  
1085 1085
	/* (non-Javadoc)
1086 1086
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
1087 1087
	 */
1088 1088
	public double getMaxY() {
1089 1089
		return visualStatus.maxY;
1090 1090
	}
1091
	
1091

  
1092 1092
	/* (non-Javadoc)
1093 1093
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
1094 1094
	 */
1095 1095
	public double getMinX() {
1096 1096
		return visualStatus.minX;
1097 1097
	}
1098
	
1098

  
1099 1099
	/* (non-Javadoc)
1100 1100
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
1101 1101
	 */
......
1145 1145
		this.posX = x;
1146 1146
		this.posY = y;
1147 1147
	}
1148
	
1148

  
1149 1149
	/* (non-Javadoc)
1150 1150
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
1151 1151
	 */
......
1153 1153
		this.posXWC = x;
1154 1154
		this.posYWC = y;
1155 1155
	}
1156
	
1156

  
1157 1157
	/* (non-Javadoc)
1158 1158
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
1159 1159
	 */
......
1179 1179
	public GeoRasterFile getGeoRasterFile() {
1180 1180
		return rasterFile;
1181 1181
	}
1182
	
1182

  
1183 1183
	public void setTransparency(int trans) {
1184 1184
		this.transparency = trans;
1185 1185
	}
1186
	
1186

  
1187 1187
	/**
1188 1188
	 * Sets the R-band.
1189
	 * 
1189
	 *
1190 1190
	 * Asigna la banda R.
1191 1191
	 * @param r
1192 1192
	 */
1193 1193
	public void setBandR(int r){
1194 1194
		this.rband = r;
1195 1195
	}
1196
	
1196

  
1197 1197
	/**
1198 1198
	 * Sets the G-band.
1199
	 * 
1199
	 *
1200 1200
	 * Asigna la banda G
1201 1201
	 * @param g
1202 1202
	 */
1203 1203
	public void setBandG(int g){
1204 1204
		this.gband = g;
1205 1205
	}
1206
	
1206

  
1207 1207
	/**
1208 1208
	 * Sets the B-band.
1209
	 * 
1209
	 *
1210 1210
	 * Asigna la banda B
1211 1211
	 * @param b
1212 1212
	 */
......
1244 1244
    		}
1245 1245
    	}
1246 1246
    }
1247
    
1247

  
1248 1248
    /**
1249 1249
     * Sets the dimension vector that is a list of key-value pairs containing
1250 1250
     * the name of the dimension and the value for it
......
1257 1257
    /**
1258 1258
     * Sets the set of URLs that should be accessed for each operation performed
1259 1259
     * to the server.
1260
     * 
1260
     *
1261 1261
     * @param onlineResources
1262 1262
     */
1263 1263
	public void setOnlineResources(Hashtable onlineResources) {
1264 1264
		this.onlineResources = onlineResources;
1265 1265
	}
1266
	
1266

  
1267 1267
	/**
1268 1268
	 * When a server is not fully featured and it only can serve constant map
1269 1269
	 * sizes this value must be set. It expresses the size in pixels (width, height)
......
1273 1273
	public void setFixedSize(Dimension sz) {
1274 1274
		fixedSize = sz;
1275 1275
	}
1276
	
1276

  
1277 1277
	/**
1278 1278
	 * Tells whether if this layer must deal with the server with the constant-size
1279 1279
	 * limitations or not.
......
1297 1297
	 * layer(s).
1298 1298
	 * @param version, The desired version of the resulting document. (1.1.0)
1299 1299
	 * @return String containing the xml.
1300
	 * @throws UnsupportedVersionException 
1300
	 * @throws UnsupportedVersionException
1301 1301
	 */
1302 1302
	public String toMapContext(String mapContextVersion) {
1303 1303
		XmlBuilder xml = new XmlBuilder();
......
1306 1306
			drv = getDriver();
1307 1307
		} catch (Exception e) {
1308 1308
			return xml.toString();
1309
		} 
1309
		}
1310 1310
		String[] layerNames = getLayerQuery().split(",");
1311
		String[] styleNames = (String[]) styles.toArray(new String[0]); 
1311
		String[] styleNames = (String[]) styles.toArray(new String[0]);
1312 1312
		for (int i = 0; i < layerNames.length; i++) {
1313 1313
			WMSLayerNode layer = drv.getLayer(layerNames[i]);
1314 1314
			HashMap xmlAttrs = new HashMap();
1315
			
1315

  
1316 1316
			// <Layer>
1317 1317
			xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible()+"");
1318 1318
			xmlAttrs.put(WebMapContextTags.QUERYABLE, queryable+"");
......
1325 1325
				xmlAttrs.put(WebMapContextTags.SERVER_TITLE, drv.getServiceTitle());
1326 1326
				xml.openTag(WebMapContextTags.SERVER, xmlAttrs);
1327 1327
				xmlAttrs.clear();
1328
				
1328

  
1329 1329
					// <OnlineResource>
1330 1330
					xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
1331 1331
					xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString());
1332 1332
					xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs);
1333 1333
					xmlAttrs.clear();
1334 1334
					// </OnlineResource>
1335
					
1335

  
1336 1336
				xml.closeTag();
1337 1337
				// </Server>
1338
				
1338

  
1339 1339
				// <Name>
1340 1340
				xml.writeTag(WebMapContextTags.NAME, layer.getName().trim());
1341 1341
				// </Name>
1342
				
1342

  
1343 1343
				// <Title>
1344 1344
				xml.writeTag(WebMapContextTags.TITLE, getName().trim());
1345 1345
				// </Title>
1346
				
1346

  
1347 1347
				// <Abstract>
1348 1348
				if (layer.getAbstract() != null)
1349 1349
					xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract());
1350 1350
				// </Abstract>
1351
				
1351

  
1352 1352
				// <SRS> (a list of available SRS for the enclosing layer)
1353 1353
				String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]);
1354 1354
				String mySRS = strings[0];
......
1357 1357
				}
1358 1358
				xml.writeTag(WebMapContextTags.SRS, mySRS);
1359 1359
				// </SRS>
1360
				
1360

  
1361 1361
				// <FormatList>
1362 1362
				xml.openTag(WebMapContextTags.FORMAT_LIST);
1363 1363
					strings = (String[]) drv.getFormats().toArray(new String[0]);
......
1368 1368
							xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
1369 1369
						else
1370 1370
							xml.writeTag(WebMapContextTags.FORMAT, str);
1371
                    // </Format>	
1371
                    // </Format>
1372 1372
					}
1373 1373
				xml.closeTag();
1374 1374
				// </FormatList>
1375
				
1375

  
1376 1376
				// <StyleList>
1377 1377
				xml.openTag(WebMapContextTags.STYLE_LIST);
1378
				
1378

  
1379 1379
					if (layer.getStyles().size()>0) {
1380 1380
						for (int j = 0; j < layer.getStyles().size(); j++) {
1381 1381
							// <Style>
......
1384 1384
								xmlAttrs.put(WebMapContextTags.CURRENT, "1");
1385 1385
							xml.openTag(WebMapContextTags.STYLE, xmlAttrs);
1386 1386
							xmlAttrs.clear();
1387
							
1387

  
1388 1388
								// <Name>
1389 1389
								xml.writeTag(WebMapContextTags.NAME, st.name);
1390 1390
								// </Name>
1391
								
1391

  
1392 1392
								// <Title>
1393 1393
								xml.writeTag(WebMapContextTags.TITLE, st.title);
1394 1394
								// </Title>
1395
								
1395

  
1396 1396
								// <LegendURL width="180" format="image/gif" height="50">
1397 1397
									// <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
1398 1398
									// </OnlineResource>
1399 1399
								// </LegendURL>
1400 1400
							xml.closeTag();
1401 1401
							// </Style>
1402
							
1402

  
1403 1403
						}
1404
						
1404

  
1405 1405
					} else {
1406 1406
						// Create fake style (for compatibility issues)
1407 1407
						xmlAttrs.put(WebMapContextTags.CURRENT, "1");
......
1411 1411
							// <Name>
1412 1412
							xml.writeTag(WebMapContextTags.NAME, "default");
1413 1413
							// </Name>
1414
							
1414

  
1415 1415
							// <Title>
1416 1416
							xml.writeTag(WebMapContextTags.TITLE, "default");
1417 1417
							// </Title>
1418
							
1418

  
1419 1419
//							// <LegendURL width="180" format="image/gif" height="50">
1420 1420
//							xmlAttrs.put(WebMapContextTags.WIDTH, "0");
1421 1421
//							xmlAttrs.put(WebMapContextTags.HEIGHT, "0");
......
1450 1450
		}
1451 1451
		return xml.getXML();
1452 1452
	}
1453
	
1454
	public ImageIcon getTocImageIcon() {			
1453

  
1454
	public ImageIcon getTocImageIcon() {
1455 1455
		return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wms").getClassLoader().getResource("images/icoLayer.png"));
1456 1456
	}
1457 1457

  
......
1460 1460
	 * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
1461 1461
	 */
1462 1462
	public int[] getTileSize() {
1463
		int[] size = {maxTileDrawWidth, maxTileDrawHeight}; 
1463
		int[] size = {maxTileDrawWidth, maxTileDrawHeight};
1464 1464
		return size;
1465 1465
	}
1466 1466

  
......
1471 1471
	public boolean isTiled() {
1472 1472
		return mustTileDraw;
1473 1473
	}
1474
	
1475
	
1474

  
1475

  
1476 1476
}

Also available in: Unified diff