Revision 3840

View differences:

trunk/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java
43 43
import java.awt.Component;
44 44
import java.awt.Graphics2D;
45 45
import java.awt.Point;
46
import java.awt.Rectangle;
46 47
import java.awt.geom.AffineTransform;
47 48
import java.awt.geom.NoninvertibleTransformException;
48 49
import java.awt.geom.Point2D;
......
61 62
import java.net.URL;
62 63
import java.util.ArrayList;
63 64
import java.util.HashMap;
64
import java.util.Hashtable;
65 65
import java.util.Vector;
66 66

  
67 67
import javax.swing.JOptionPane;
......
322 322
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
323 323
			Cancellable cancel,double scale) throws DriverException {
324 324
		if (isWithinScale(scale)){	
325
			try {
325
			
326
			Rectangle r = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
327
			Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
328
			tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
329
			for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
330
	    		// Parte que dibuja
331
	    		try {
332
	        		ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
333
	        		_draw(null, g, vp, cancel,scale);
334
				} catch (NoninvertibleTransformException e) {
335
					e.printStackTrace();
336
				}
337
	        }
338
			
339
		}
340
	}
341
	
342
	/**
343
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
344
	 * 		java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
345
	 * 		com.iver.cit.gvsig.fmap.operations.Cancellable)
346
	 */
347
	public void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
348
			Cancellable cancel,double scale) throws DriverException {
349
			
350
		try {
326 351
							
327
				if (wmsStatus == null)
328
				{
352
			if (wmsStatus == null)
329 353
					wmsStatus = new WMSStatus();
330
				}
331
				wmsStatus.setExtent(viewPort.getAdjustedExtent());
332
				wmsStatus.setFormat(m_Format);
333
				wmsStatus.setHeight( viewPort.getImageHeight());
334
                wmsStatus.setWidth( viewPort.getImageWidth());
335
				wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
336
				wmsStatus.setSrs(m_SRS);
337
				wmsStatus.setStyles(styles);
338
                wmsStatus.setDimensions(dimensions);
339
                wmsStatus.setTransparency(wmsTransparency);
340
				if (wmsPreviousStatus == null || !wmsPreviousStatus.equals(wmsStatus)){
341
                    wmsPreviousStatus = wmsStatus;
342
				    byte[] bytes;
343
				    bytes = getDriver().getMap(wmsStatus);
354
				
355
			wmsStatus.setExtent(viewPort.getAdjustedExtent());
356
			wmsStatus.setFormat(m_Format);
357
			wmsStatus.setHeight( viewPort.getImageHeight());
358
            wmsStatus.setWidth( viewPort.getImageWidth());
359
			wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
360
			wmsStatus.setSrs(m_SRS);
361
			wmsStatus.setStyles(styles);
362
            wmsStatus.setDimensions(dimensions);
363
            wmsStatus.setTransparency(wmsTransparency);
364
			if (wmsPreviousStatus == null || !wmsPreviousStatus.equals(wmsStatus)){
365
                wmsPreviousStatus = wmsStatus;
366
			    byte[] bytes;
367
			    bytes = getDriver().getMap(wmsStatus);
344 368
				    
345
				    ByteArrayInputStream inbytes = new ByteArrayInputStream(bytes);
346
				    //BufferedImage tempImg = ImageIO.read(inbytes);
347
				    // LWS Cambio de estrategia en el posicionado para la impresi?n.
348
				    Point2D p2=new Point2D.Double(viewPort.getAdjustedExtent().getX(), viewPort.getAdjustedExtent().getMaxY()); //viewPort.getOffset();
349
				    viewPort.getAffineTransform().transform(p2, p2);
369
			    ByteArrayInputStream inbytes = new ByteArrayInputStream(bytes);
370
			    //BufferedImage tempImg = ImageIO.read(inbytes);
371
			    // LWS Cambio de estrategia en el posicionado para la impresi?n.
372
			    Point2D p2=new Point2D.Double(viewPort.getAdjustedExtent().getX(), viewPort.getAdjustedExtent().getMaxY()); //viewPort.getOffset();
373
			    viewPort.getAffineTransform().transform(p2, p2);
350 374
				    
351
				    rasterProcess(g, viewPort, createTemp(inbytes, "wms_Query", viewPort));
352
				    if(status!=null && firstLoad){
353
				        status.applyStatus(this);
354
				        firstLoad = false;
355
				    }
375
			    rasterProcess(g, viewPort, createTemp(inbytes, "wms_Query", viewPort));
376
			    if(status!=null && firstLoad){
377
			        status.applyStatus(this);
378
			        firstLoad = false;
379
			    }
356 380
                    
357
				}
381
			}
358 382
				//g.drawImage(tempImg,(int)p2.getX(),(int)p2.getY(), null);
359
			} catch (ValidationException e) {
360
				throw new DriverException("No se reconoce el formato de la respuesta",
361
						e);
362
			} catch (UnsupportedVersionException e) {
363
				throw new DriverException("Conflicto de versiones", e);
364
			} catch (IOException e) {
365
				throw new DriverException("Error en la conexi?n", e);
366
			} catch (WMSException e) {
367
                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
368
				this.setVisible(false);
369
                wmsPreviousStatus = null;
370
			}
383
		} catch (ValidationException e) {
384
			throw new DriverException("No se reconoce el formato de la respuesta",
385
					e);
386
		} catch (UnsupportedVersionException e) {
387
			throw new DriverException("Conflicto de versiones", e);
388
		} catch (IOException e) {
389
			throw new DriverException("Error en la conexi?n", e);
390
		} catch (WMSException e) {
391
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
392
			this.setVisible(false);
393
            wmsPreviousStatus = null;
371 394
		}
395
		
372 396
	}
373 397
	
374 398
	/**
......
399 423
	 
400 424
	    //Generamos un world file para gdal
401 425
	    DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(tfw)) );
402
	    dos.writeBytes((vp.getAdjustedExtent().getMaxX() - vp.getAdjustedExtent().getMinX())/vp.getImageWidth()+"\n");
426
	    dos.writeBytes((vp.getAdjustedExtent().getMaxX() - vp.getAdjustedExtent().getMinX())/(vp.getImageWidth() - 1)+"\n");
403 427
	    dos.writeBytes("0.0\n");
404 428
	    dos.writeBytes("0.0\n");
405
	    dos.writeBytes((vp.getAdjustedExtent().getMaxY() - vp.getAdjustedExtent().getMinY())/vp.getImageHeight()+"\n");
429
	    dos.writeBytes((vp.getAdjustedExtent().getMaxY() - vp.getAdjustedExtent().getMinY())/(vp.getImageHeight() - 1)+"\n");
406 430
	    dos.writeBytes(""+vp.getAdjustedExtent().getMinX()+"\n");
407 431
	    dos.writeBytes(""+vp.getAdjustedExtent().getMinY()+"\n");
408 432
	    dos.close();

Also available in: Unified diff