Revision 4272 org.gvsig.raster.wmts/trunk/org.gvsig.raster.wmts/org.gvsig.raster.wmts.app.wmtsclient/src/main/java/org/gvsig/raster/wmts/app/wmtsclient/layer/FLyrWMTS.java

View differences:

FLyrWMTS.java
8 8
import java.awt.geom.Rectangle2D;
9 9
import java.awt.image.BufferedImage;
10 10
import java.lang.ref.WeakReference;
11
import java.net.URI;
12
import java.net.URISyntaxException;
11 13
import java.util.ArrayList;
12 14
import java.util.HashMap;
13 15
import java.util.Iterator;
......
17 19

  
18 20
import org.cresques.cts.ICoordTrans;
19 21
import org.cresques.cts.IProjection;
22

  
20 23
import org.gvsig.fmap.dal.DALLocator;
21 24
import org.gvsig.fmap.dal.DataManager;
22 25
import org.gvsig.fmap.dal.DataParameters;
......
70 73
import org.gvsig.tools.task.Cancellable;
71 74
import org.gvsig.tools.task.SimpleTaskStatus;
72 75
import org.gvsig.tools.task.TaskStatusManager;
76

  
73 77
import org.slf4j.Logger;
74 78
import org.slf4j.LoggerFactory;
75 79

  
......
102 106
					FLyrWMTS.class,
103 107
					"FLyrWMTS_Persistent",
104 108
					"FLyrWMTS Persistent Definition",
105
					null, 
109
					null,
106 110
					null
107 111
			);
108
			
112

  
109 113
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME);
110 114
		}
111 115

  
112 116
		DefaultFLyrRaster.registerPersistence(definition);
113 117
	}
114
	
118

  
115 119
	public FLyrWMTS() {
116 120
		super();
117 121
		this.updateDrawVersion();
......
121 125
			logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
122 126
		}
123 127
	}
124
	
128

  
125 129
	public static DataStore createDataStore(String host, IProjection srs) throws InitializeException {
126 130
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
127 131
		RasterDataParameters params = null;
......
132 136
		} catch (ProviderNotRegisteredException e) {
133 137
			return null;
134 138
		}
135
		params.setURI(host);
139
		URI hostURI;
140
        try {
141
            hostURI = new URI(host);
142
        } catch (URISyntaxException e1) {
143
            logger.warn("Can't create URI from "+host, e1);
144
            throw new InitializeException(e1);
145
        }
146
		params.setURI(hostURI);
136 147
		params.setSRS(srs);
137
		
148

  
138 149
		try {
139 150
			return dataman.openStore(params.getDataStoreName(), params);
140 151
		} catch (ValidateDataParametersException e) {
......
143 154
			throw new InitializeException(e);
144 155
		}
145 156
	}
146
	
157

  
147 158
	public void loadFromState(PersistentState state)
148 159
			throws PersistenceException {
149 160
		try {
150 161
			super.loadFromState(state);
151
			
162

  
152 163
			/*
153
			 * Needs to initialize variables using methods on setDataStore method of this class 
164
			 * Needs to initialize variables using methods on setDataStore method of this class
154 165
			 */
155 166
			this.setDataStore(getDataStore());
156 167
			//this.setParameters(getDataStore().getParameters());
......
193 204
			zoomLevel = dataStore.getNearestLevel(pixelSize);
194 205
		}
195 206
		recalcLevel = true;
196
		
207

  
197 208
		if(!firstLoad) {
198 209
			try {
199 210
				initFilters();
......
208 219
			}
209 220
			firstLoad = true;
210 221
		}
211
		
222

  
212 223
		enableStopped();
213 224

  
214 225
		if (isWithinScale(scale)) {
......
217 228
			Envelope adjustedExtent = viewPort.getAdjustedEnvelope();
218 229
			Extent ext = rManager.getDataStructFactory().createExtent(
219 230
					adjustedExtent.getLowerCorner().getX(),
220
					adjustedExtent.getUpperCorner().getY(), 
231
					adjustedExtent.getUpperCorner().getY(),
221 232
					adjustedExtent.getUpperCorner().getX(),
222 233
					adjustedExtent.getLowerCorner().getY());
223 234
			Dimension imgSz = viewPort.getImageSize();
224 235
			ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(viewPort.getProjection(), ext, imgSz );
225 236
			vp2.setMat(viewPort.getAffineTransform());
226 237
			vp2.setDPI((int)viewPort.getDPI());
227
			
238

  
228 239
			TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
229 240
			SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel);
230 241
			manager.add(taskStatus);
......
235 246
				//getParameters().setExtent(ext.toRectangle2D());
236 247
				par.setWidth((int)viewPort.getImageSize().getWidth());
237 248
				par.setHeight((int)viewPort.getImageSize().getHeight());
238
				
249

  
239 250
				getRender().drawTiledService(g, vp2, viewPort.getImageSize(), taskStatus);
240 251
			} catch (ProcessInterruptedException e) {
241 252
				throw new ReadException("Problems drawing this layer: " + e.getMessage(), e);
......
247 258
		}
248 259
		disableStopped();
249 260
	}
250
	
251 261

  
262

  
252 263
	/**
253 264
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
254 265
	 * 		com.iver.cit.gvsig.fmap.ViewPort,
......
256 267
	 */
257 268
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties)
258 269
	throws ReadException {
259
		
270

  
260 271
	}
261 272

  
262 273
	public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
......
418 429
		}
419 430
		return null;
420 431
	}
421
	
432

  
422 433
	@Override
423 434
	public String getFileFormat() {
424 435
		return "WMTS";
425 436
	}
426
	
427 437

  
438

  
428 439
	/**
429 440
	 * Devuelve el envelope en la proyeccion de la vista
430 441
	 */
......
462 473
		return rAux;
463 474

  
464 475
	}
465
	
476

  
466 477
	public Extent getFullRasterExtent() {
467 478
		Envelope env = getFullEnvelope();
468 479
		double minx = env.getMinimum(0);
......
478 489

  
479 490
    public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel)
480 491
		throws LoadLayerException, DataException {
481
		
492

  
482 493
		return null;
483 494
	}
484
    
495

  
485 496
    public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, boolean fast)
486 497
    throws LoadLayerException, DataException {
487 498

  
......
503 514
    	}
504 515
    	return new DynObjectSetWMTSInfo(fInfo, type);
505 516
    }
506
    
517

  
507 518
    /**
508 519
     * Sets the data store parameters
509 520
     * @param params
......
515 526
		if(params instanceof TileDataParameters) {
516 527
			((TileDataParameters)params).deleteCache(deleteCache);
517 528
		}
518
		
529

  
519 530
    	DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
520 531
		try {
521 532
			DataStore dStore = dataman.openStore(params.getDataStoreName(), params);
522 533
			this.setDataStore(dStore);
523
			
534

  
524 535
			if(params instanceof WMTSDataParameters) {
525
				this.setName(((WMTSDataParameters) params).getURI());
536
				this.setName(((WMTSDataParameters) params).getURI().getPath());
526 537
			}
527
			
538

  
528 539
			if(params instanceof TileDataParameters) {
529 540
				DataParameters p = ((TileDataParameters) params).getDataParameters();
530 541
				if(p instanceof WMTSDataParameters) {
531
					this.setName(((WMTSDataParameters) p).getURI());
542
					this.setName(((WMTSDataParameters) p).getURI().getPath());
532 543
				}
533 544
			}
534
			
545

  
535 546
		} catch (ValidateDataParametersException e) {
536 547
			throw new InitializeException(e);
537 548
		} catch (ProviderNotRegisteredException e) {
......
542 553
			throw new InitializeException(e);
543 554
		}
544 555
    }
545
    
556

  
546 557
    @SuppressWarnings("deprecation")
547 558
	public DataStoreParameters getParameters() {
548 559
    	if(params == null) {
......
560 571
    	}
561 572
    	return getWMTSParameters(params);
562 573
    }
563
    
574

  
564 575
    /**
565 576
     * Gets <code>WMTSDataParameters</code>
566 577
     * @param parameters
......
571 582
    	if(parameters instanceof WMTSDataParameters) {
572 583
			params = (WMTSDataParameters) parameters;
573 584
		}
574
		
585

  
575 586
		if(parameters instanceof TileDataParameters) {
576 587
			DataParameters p = ((TileDataParameters) parameters).getDataParameters();
577 588
			if(p instanceof WMTSDataParameters) {
......
580 591
		}
581 592
		return params;
582 593
    }
583
    
594

  
584 595
    /**
585 596
     * Sets the explorer
586 597
     * @param explorer
......
588 599
    public void setExplorer(WMTSServerExplorer explorer) {
589 600
    	this.wmtsExplorer = explorer;
590 601
    }
591
    
602

  
592 603
    /**
593 604
     * Gets the explorer
594 605
     * @return
......
604 615
	public String getPathImage() {
605 616
		return null;
606 617
	}
607
	
618

  
608 619
	public FLayer cloneLayer() throws Exception {
609 620
		RasterDataStore  ds = dataStore.cloneDataStore();
610 621
		FLyrWMTS newLayer = new FLyrWMTS();
......
614 625
		newLayer.params = params;
615 626
		newLayer.firstLoad = firstLoad;
616 627
		newLayer.wmtsExplorer = wmtsExplorer;
617
		
628

  
618 629
		List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
619 630

  
620 631
		//Hacemos una copia de las bandas a renderizar
......
633 644
		NoData nd = (NoData)getNoDataValue().clone();
634 645
		newLayer.setNoDataValue(nd);
635 646
		newLayer.enableOpen();
636
		
647

  
637 648
		return newLayer;
638 649
	}
639 650

  

Also available in: Unified diff