Changeset 27519 in osm for applications
- Timestamp:
- 2012-01-21T10:57:57+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
r27507 r27519 11 11 import java.util.Locale; 12 12 import java.util.concurrent.Callable; 13 import java.util.concurrent.ExecutionException; 13 14 import java.util.concurrent.Executors; 14 15 import java.util.concurrent.Future; … … 36 37 public class BingAerialTileSource extends AbstractTMSTileSource { 37 38 private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU"; 38 private static Future<List<Attribution>> attributions;39 private static volatile Future<List<Attribution>> attributions; // volatile is required for getAttribution(), see below. 39 40 private static String imageUrlTemplate; 40 41 private static Integer imageryZoomMax; … … 59 60 @Override 60 61 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException { 62 // make sure that attribution is loaded. otherwise subdomains is null. 63 getAttribution(); 64 61 65 int t = (zoom + tilex + tiley) % subdomains.length; 62 66 String subdomain = subdomains[t]; … … 212 216 } 213 217 218 protected List<Attribution> getAttribution() { 219 if (attributions == null) { 220 // see http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html 221 synchronized (BingAerialTileSource.class) { 222 if (attributions == null) { 223 attributions = Executors.newSingleThreadExecutor().submit(getAttributionLoaderCallable()); 224 } 225 } 226 } 227 try { 228 return attributions.get(1000, TimeUnit.MILLISECONDS); 229 } catch (TimeoutException ex) { 230 System.err.println("Bing: attribution data is not yet loaded."); 231 } catch (ExecutionException ex) { 232 throw new RuntimeException(ex.getCause()); 233 } catch (InterruptedException ign) { 234 } 235 return null; 236 } 237 214 238 @Override 215 239 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) { 216 if (attributions == null) { 217 attributions = Executors.newSingleThreadExecutor().submit(getAttributionLoaderCallable()); 218 } 219 try { 220 final List<Attribution> data; 221 try { 222 data = attributions.get(1000, TimeUnit.MILLISECONDS); 223 } catch (TimeoutException ex) { 224 return "Loading Bing attribution data..."; 225 } 240 try { 241 final List<Attribution> data = getAttribution(); 226 242 if (data == null) { 227 243 return "Error loading Bing attribution data";
Note:
See TracChangeset
for help on using the changeset viewer.