Revision 8832
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.googlemaps/org.gvsig.raster.googlemaps.provider/src/main/java/org/gvsig/raster/googlemaps/provider/GoogleMapsImage.java | ||
---|---|---|
1 | 1 |
package org.gvsig.raster.googlemaps.provider; |
2 | 2 |
|
3 | 3 |
import java.awt.image.BufferedImage; |
4 |
import java.util.HashMap; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.Map.Entry; |
|
8 |
import java.util.Set; |
|
4 |
import java.awt.image.WritableRaster; |
|
5 |
import java.io.IOException; |
|
9 | 6 |
|
10 | 7 |
import org.slf4j.Logger; |
11 | 8 |
import org.slf4j.LoggerFactory; |
... | ... | |
30 | 27 |
import org.gvsig.raster.lib.buffer.api.Band; |
31 | 28 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
32 | 29 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
30 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
33 | 31 |
import org.gvsig.raster.lib.buffer.api.TileStruct; |
34 | 32 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
35 | 33 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
39 | 37 |
import org.gvsig.tools.exception.BaseException; |
40 | 38 |
import org.gvsig.tools.locator.LocatorException; |
41 | 39 |
|
42 |
|
|
43 | 40 |
/** |
44 | 41 |
* @author fdiaz |
45 | 42 |
* |
... | ... | |
81 | 78 |
Buffer buffer = null; |
82 | 79 |
if (this.tile != null && this.tile.getKey().equalsIgnoreCase(keyTile) && this.tile.isDownloaded()) { |
83 | 80 |
// Devolver la banda del buffer del tile |
84 |
logger.info("Devolviendo la banda "+bandNumber+" del buffer del tile "+tile.getKey());
|
|
81 |
logger.info("Devolviendo la banda " + bandNumber + " del buffer del tile " + tile.getKey());
|
|
85 | 82 |
try { |
86 | 83 |
buffer = tile.getBuffer(); |
87 | 84 |
Band band = buffer.getBand(bandNumber); |
... | ... | |
93 | 90 |
return null; |
94 | 91 |
} |
95 | 92 |
} else { |
96 |
this.tile=null;
|
|
93 |
this.tile = null;
|
|
97 | 94 |
// Cargar un tile nuevo |
98 | 95 |
Band band = null; |
99 | 96 |
try { |
100 |
while(this.tile==null || !this.tile.isDownloaded()) {
|
|
97 |
while (this.tile == null || !this.tile.isDownloaded()) {
|
|
101 | 98 |
tile = requestTile(zoomLevel, structRow, structCol, keyTile); |
102 | 99 |
} |
103 | 100 |
|
... | ... | |
106 | 103 |
band = buffer.getBand(bandNumber); |
107 | 104 |
ToolsLocator.getDisposableManager().bind(band); |
108 | 105 |
return band; |
109 |
} catch (DataException | BufferException | CreateGeometryException | InterruptedException | URLFormatException | DownloadingException e) { |
|
106 |
} catch (DataException | BufferException | CreateGeometryException | InterruptedException |
|
107 |
| URLFormatException | DownloadingException e) { |
|
110 | 108 |
logger.warn("Can't fetch tile: zoomLevel = " + zoomLevel + ", tileRow = " + structRow |
111 | 109 |
+ ", tileColumn = " + structCol + ", band = " + bandNumber + ".", e); |
112 | 110 |
return null; |
... | ... | |
114 | 112 |
} |
115 | 113 |
} |
116 | 114 |
|
117 |
private DownloadedTile requestTile(int zoomLevel, int structRow, int structCol, String key) throws CreateEnvelopeException, |
|
118 |
CloneNotSupportedException, BufferException, ValidateDataParametersException, DataException, CreateGeometryException, URLFormatException, DownloadingException { |
|
115 |
private DownloadedTile requestTile(int zoomLevel, int structRow, int structCol, String key) |
|
116 |
throws CreateEnvelopeException, CloneNotSupportedException, BufferException, ValidateDataParametersException, |
|
117 |
DataException, CreateGeometryException, URLFormatException, DownloadingException { |
|
119 | 118 |
|
120 | 119 |
Double pixelSize = this.tileStruct.getPixelSizePerZoomLevel().get(zoomLevel); |
121 | 120 |
|
... | ... | |
125 | 124 |
int rowsPerTile = this.tileStruct.getRowsPerTile(); |
126 | 125 |
int columnsPerTile = this.tileStruct.getColumnsPerTile(); |
127 | 126 |
|
128 |
double minX = Math.max(structExtent.getMinimum(DIMENSIONS.X) + (structCol * (pixelSize * columnsPerTile)),structExtent.getMinimum(DIMENSIONS.X)); |
|
129 |
double minY = Math.max(structExtent.getMaximum(DIMENSIONS.Y) - ((structRow + 1) * (pixelSize * rowsPerTile)),structExtent.getMinimum(DIMENSIONS.Y)); |
|
130 |
double maxX = Math.min(structExtent.getMinimum(DIMENSIONS.X) + ((structCol + 1) * (pixelSize * columnsPerTile)),structExtent.getMaximum(DIMENSIONS.X)); |
|
131 |
double maxY = Math.min(structExtent.getMaximum(DIMENSIONS.Y) - (structRow * (pixelSize * rowsPerTile)),structExtent.getMaximum(DIMENSIONS.Y)); |
|
127 |
double minX = |
|
128 |
Math.max(structExtent.getMinimum(DIMENSIONS.X) + (structCol * (pixelSize * columnsPerTile)), |
|
129 |
structExtent.getMinimum(DIMENSIONS.X)); |
|
130 |
double minY = |
|
131 |
Math.max(structExtent.getMaximum(DIMENSIONS.Y) - ((structRow + 1) * (pixelSize * rowsPerTile)), |
|
132 |
structExtent.getMinimum(DIMENSIONS.Y)); |
|
133 |
double maxX = |
|
134 |
Math.min(structExtent.getMinimum(DIMENSIONS.X) + ((structCol + 1) * (pixelSize * columnsPerTile)), |
|
135 |
structExtent.getMaximum(DIMENSIONS.X)); |
|
136 |
double maxY = |
|
137 |
Math.min(structExtent.getMaximum(DIMENSIONS.Y) - (structRow * (pixelSize * rowsPerTile)), |
|
138 |
structExtent.getMaximum(DIMENSIONS.Y)); |
|
132 | 139 |
Envelope envelope = geomManager.createEnvelope(minX, minY, maxX, maxY, SUBTYPES.GEOM2D); |
133 | 140 |
Point center; |
134 | 141 |
|
135 |
center = geomManager.createPoint(envelope.getCenter(DIMENSIONS.X), envelope.getCenter(DIMENSIONS.Y), SUBTYPES.GEOM2D); |
|
142 |
center = |
|
143 |
geomManager |
|
144 |
.createPoint(envelope.getCenter(DIMENSIONS.X), envelope.getCenter(DIMENSIONS.Y), SUBTYPES.GEOM2D); |
|
136 | 145 |
|
137 | 146 |
GoogleMapsManager googleMapsManager = GoogleMapsLocator.getManager(); |
138 | 147 |
GoogleMapsRequestParams requestParams = googleMapsManager.createRequestParams(); |
... | ... | |
146 | 155 |
requestParams.setMapType((String) storeParameters.getDynValue("mapType")); |
147 | 156 |
requestParams.setFormat((String) storeParameters.getDynValue("format")); |
148 | 157 |
|
149 |
GoogleMapsRequest googleRequest=googleMapsManager.createRequest(requestParams);
|
|
158 |
GoogleMapsRequest googleRequest = googleMapsManager.createRequest(requestParams);
|
|
150 | 159 |
DownloadedTile downloadedTile = new DownloadedTile(key, envelope); |
151 |
downloadedTile.setImage(googleRequest.getTile(center, zoomLevel, (int)Math.round(envelope.getLength(DIMENSIONS.X)/pixelSize), (int)Math.round(envelope.getLength(DIMENSIONS.Y)/pixelSize))); |
|
160 |
downloadedTile.setImage(googleRequest.getTile(center, zoomLevel, |
|
161 |
(int) Math.round(envelope.getLength(DIMENSIONS.X) / pixelSize), |
|
162 |
(int) Math.round(envelope.getLength(DIMENSIONS.Y) / pixelSize))); |
|
152 | 163 |
|
153 | 164 |
return downloadedTile; |
154 | 165 |
} |
... | ... | |
163 | 174 |
return builder.toString(); |
164 | 175 |
} |
165 | 176 |
|
166 |
private class DownloadedTile extends AbstractDisposable { //implements GoogleMapsRequestListener { |
|
177 |
private class DownloadedTile extends AbstractDisposable { // implements |
|
178 |
// GoogleMapsRequestListener |
|
179 |
// { |
|
167 | 180 |
|
168 | 181 |
private org.gvsig.raster.lib.buffer.api.Buffer buffer; |
169 | 182 |
long lastAccess; |
... | ... | |
184 | 197 |
|
185 | 198 |
public synchronized org.gvsig.raster.lib.buffer.api.Buffer getBuffer() throws InterruptedException { |
186 | 199 |
lastAccess = System.currentTimeMillis(); |
187 |
while(!isDownloaded()){
|
|
200 |
while (!isDownloaded()) {
|
|
188 | 201 |
this.wait(); |
189 | 202 |
} |
190 | 203 |
return buffer; |
... | ... | |
205 | 218 |
|
206 | 219 |
try { |
207 | 220 |
|
221 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
208 | 222 |
this.buffer = |
209 |
BufferLocator.getBufferManager().createBuffer(img, GoogleMapsRasterProvider.GOOGLE_MAPS_PROJECTION,
|
|
223 |
bufferManager.createRGBABuffer(img, GoogleMapsRasterProvider.GOOGLE_MAPS_PROJECTION,
|
|
210 | 224 |
this.envelope); |
211 | 225 |
|
212 | 226 |
} catch (LocatorException | BufferException e) { |
... | ... | |
223 | 237 |
buffer = null; |
224 | 238 |
} |
225 | 239 |
|
226 |
|
|
227 |
public boolean isDownloaded(){ |
|
240 |
public boolean isDownloaded() { |
|
228 | 241 |
return this.downloaded; |
229 | 242 |
} |
230 | 243 |
} |
231 | 244 |
|
232 | 245 |
@Override |
233 | 246 |
protected void doDispose() throws BaseException { |
234 |
if(this.tile != null) { |
|
247 |
if (this.tile != null) {
|
|
235 | 248 |
DisposeUtils.dispose(this.tile); |
236 | 249 |
} |
237 | 250 |
DisposeUtils.dispose((Disposable) tileStruct); |
Also available in: Unified diff