/** * @param placeNameServiceSet the set of PlaceNameService objects that PlaceNameLayer will render. * @throws IllegalArgumentException if {@link * gov.nasa.worldwind.layers.placename.PlaceNameServiceSet} is null */ public PlaceNameLayer(PlaceNameServiceSet placeNameServiceSet) { if (placeNameServiceSet == null) { String message = Logging.getMessage("nullValue.PlaceNameServiceSetIsNull"); Logging.logger().fine(message); throw new IllegalArgumentException(message); } // this.placeNameServiceSet = placeNameServiceSet.deepCopy(); for (int i = 0; i < this.placeNameServiceSet.getServiceCount(); i++) { // todo do this for long as well and pick min int calc1 = (int) (PlaceNameService.TILING_SECTOR.getDeltaLatDegrees() / this.placeNameServiceSet .getService(i) .getTileDelta() .getLatitude() .getDegrees()); int numLevels = (int) Math.log(calc1); navTiles.add( new NavigationTile( this.placeNameServiceSet.getService(i), PlaceNameService.TILING_SECTOR, numLevels, "top")); } if (!WorldWind.getMemoryCacheSet().containsCache(Tile.class.getName())) { long size = Configuration.getLongValue(AVKey.PLACENAME_LAYER_CACHE_SIZE, 2000000L); MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size); cache.setName("Placename Tiles"); WorldWind.getMemoryCacheSet().addCache(Tile.class.getName(), cache); } }
protected void sendRequests() { Runnable task = this.requestQ.poll(); while (task != null) { if (!WorldWind.getTaskService().isFull()) { WorldWind.getTaskService().addTask(task); } task = this.requestQ.poll(); } }
protected boolean loadTile(Tile tile, java.net.URL url) { if (WWIO.isFileOutOfDate(url, this.placeNameServiceSet.getExpiryTime())) { // The file has expired. Delete it then request download of newer. this.getDataFileStore().removeFile(url); String message = Logging.getMessage("generic.DataFileExpired", url); Logging.logger().fine(message); return false; } PlaceNameChunk tileData; synchronized (this.fileLock) { tileData = readTileData(tile, url); } if (tileData == null) { // Assume that something's wrong with the file and delete it. this.getDataFileStore().removeFile(url); tile.getPlaceNameService() .markResourceAbsent(tile.getPlaceNameService().getTileNumber(tile.row, tile.column)); String message = Logging.getMessage("generic.DeletedCorruptDataFile", url); Logging.logger().fine(message); return false; } tile.setDataChunk(tileData); WorldWind.getMemoryCache(Tile.class.getName()).add(tile.getFileCachePath(), tile); return true; }
public List<Tile> getTiles() { if (tileKeys.isEmpty()) { Tile[] tiles = buildTiles(this.placeNameService, this); // load tileKeys for (Tile t : tiles) { tileKeys.add(t.getFileCachePath()); WorldWind.getMemoryCache(Tile.class.getName()).add(t.getFileCachePath(), t); } return Arrays.asList(tiles); } else { List<Tile> dataTiles = new ArrayList<Tile>(); for (String s : tileKeys) { Tile t = (Tile) WorldWind.getMemoryCache(Tile.class.getName()).getObject(s); if (t != null) { dataTiles.add(t); } } return dataTiles; } }
protected void downloadTile(final Tile tile, DownloadPostProcessor postProcessor) { if (!this.isNetworkRetrievalEnabled()) return; if (!WorldWind.getRetrievalService().isAvailable()) return; java.net.URL url; try { url = tile.getRequestURL(); if (WorldWind.getNetworkStatus().isHostUnavailable(url)) return; } catch (java.net.MalformedURLException e) { Logging.logger() .log( java.util.logging.Level.SEVERE, Logging.getMessage("layers.PlaceNameLayer.ExceptionCreatingUrl", tile), e); return; } Retriever retriever; if ("http".equalsIgnoreCase(url.getProtocol()) || "https".equalsIgnoreCase(url.getProtocol())) { if (postProcessor == null) postProcessor = new DownloadPostProcessor(this, tile); retriever = new HTTPRetriever(url, postProcessor); } else { Logging.logger() .severe( Logging.getMessage("layers.PlaceNameLayer.UnknownRetrievalProtocol", url.toString())); return; } // Apply any overridden timeouts. Integer cto = AVListImpl.getIntegerValue(this, AVKey.URL_CONNECT_TIMEOUT); if (cto != null && cto > 0) retriever.setConnectTimeout(cto); Integer cro = AVListImpl.getIntegerValue(this, AVKey.URL_READ_TIMEOUT); if (cro != null && cro > 0) retriever.setReadTimeout(cro); Integer srl = AVListImpl.getIntegerValue(this, AVKey.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT); if (srl != null && srl > 0) retriever.setStaleRequestLimit(srl); WorldWind.getRetrievalService().runRetriever(retriever, tile.getPriority()); }
/** * Create a layer described by an XML layer description. * * @param domElement the XML element describing the layer to create. * @param params any parameters to apply when creating the layer. * @return a new layer * @throws WWUnrecognizedException if the layer type or service type given in the describing * element is unrecognized. * @see #createTiledImageLayer(org.w3c.dom.Element, gov.nasa.worldwind.avlist.AVList). */ protected Layer createFromLayerDocument(Element domElement, AVList params) { String className = WWXML.getText(domElement, "@className"); if (className != null && className.length() > 0) { Layer layer = (Layer) WorldWind.createComponent(className); String actuate = WWXML.getText(domElement, "@actuate"); layer.setEnabled(WWUtil.isEmpty(actuate) || actuate.equals("onLoad")); WWXML.invokePropertySetters(layer, domElement); return layer; } AVList props = WWXML.copyProperties(domElement, null); if (props != null) { // Copy params and add any properties for this layer to the copy if (params != null) props.setValues(params); params = props; } Layer layer; String href = WWXML.getText(domElement, "@href"); if (href != null && href.length() > 0) { Object o = this.createFromConfigSource(href, params); if (o == null) return null; if (!(o instanceof Layer)) { String msg = Logging.getMessage("LayerFactory.UnexpectedTypeForLayer", o.getClass().getName()); throw new WWRuntimeException(msg); } layer = (Layer) o; } else { String layerType = WWXML.getText(domElement, "@layerType"); if (layerType != null && layerType.equals("TiledImageLayer")) { layer = this.createTiledImageLayer(domElement, params); } else { String msg = Logging.getMessage("generic.UnrecognizedLayerType", layerType); throw new WWUnrecognizedException(msg); } } if (layer != null) { String actuate = WWXML.getText(domElement, "@actuate"); layer.setEnabled(actuate != null && actuate.equals("onLoad")); WWXML.invokePropertySetters(layer, domElement); } return layer; }
protected boolean isTileInMemoryWithData() { Tile t = (Tile) WorldWind.getMemoryCache(Tile.class.getName()).getObject(this.getFileCachePath()); return !(t == null || t.getDataChunk() == null); }