Skip to content

Commit ce4a427

Browse files
author
Don Dietrick
committed
Adding saveCache property to MapTileLayer, refining cache location in default openmap.properties
1 parent 20d470f commit ce4a427

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

openmap.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ tiles.rootDir=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
10321032

10331033
# For remote server, you can also store tiles locally, to reduce load on server.
10341034
# You should update this with a valid path local to your machine.
1035-
#tiles.localCacheRootDir=/data/tiles/osmtiles
1035+
#tiles.localCacheRootDir=./share/data/tiles/osmtiles
10361036

10371037
# What to do about empty tiles for bottom-most layer? Set
10381038
# up an EmptyTileHandler. Saves disk space for tile storage. Usually

src/openmap/com/bbn/openmap/layer/imageTile/MapTileLayer.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
* tiles.rootDir=URL root directory of tiles
8282
* # a local location to cache tiles, to reduce load on server.
8383
* tiles.localCacheRootDir=/data/tiles/osmtiles
84+
* # save cache when layer is done (true by default)
85+
* tiles.saveCache=true
8486
*
8587
* # other properties are the same.
8688
* tiles.fileExt=.png
@@ -161,9 +163,10 @@ public class MapTileLayer extends OMGraphicHandlerLayer implements MapTileReques
161163
public final static String DATA_ATTRIBUTION_PROPERTY = "attribution";
162164

163165
/**
164-
* A property to disable tile factory reset on layer being removed.
166+
* A property to save or destroy the tile factory cache when the layer is
167+
* removed.
165168
*/
166-
public final static String DISABLE_TILE_FACTORY_RESET = "disableTileFactoryReset";
169+
public final static String SAVE_CACHE_PROPERTY = "saveCache";
167170
/**
168171
* The MapTileFactory that knows how to fetch image files and create
169172
* OMRasters for them.
@@ -189,9 +192,9 @@ public class MapTileLayer extends OMGraphicHandlerLayer implements MapTileReques
189192
protected String attribution = null;
190193

191194
/**
192-
* Flag to disable tile factory reset on layer being removed.
195+
* Flag to save tile factory cache when the layer is no longer used.
193196
*/
194-
protected boolean disableTileFactoryReset = false;
197+
protected boolean saveCache = true;
195198

196199
/**
197200
* Rendering parameters for attribution string.
@@ -310,8 +313,7 @@ public void setProperties(String prefix, Properties props) {
310313

311314
setZoomLevel(PropUtils.intFromProperties(props, prefix + ZOOM_LEVEL_PROPERTY, zoomLevel));
312315

313-
disableTileFactoryReset = PropUtils.booleanFromProperties(props, prefix
314-
+ DISABLE_TILE_FACTORY_RESET, disableTileFactoryReset);
316+
saveCache = PropUtils.booleanFromProperties(props, prefix + SAVE_CACHE_PROPERTY, saveCache);
315317
}
316318

317319
public Properties getProperties(Properties props) {
@@ -328,7 +330,7 @@ public Properties getProperties(Properties props) {
328330
props.put(prefix + INCREMENTAL_UPDATES_PROPERTY, Boolean.toString(incrementalUpdates));
329331
props.put(prefix + ZOOM_LEVEL_PROPERTY, Integer.toString(zoomLevel));
330332
props.put(prefix + DATA_ATTRIBUTION_PROPERTY, PropUtils.unnull(attribution));
331-
props.put(prefix + DISABLE_TILE_FACTORY_RESET, Boolean.toString(disableTileFactoryReset));
333+
props.put(prefix + SAVE_CACHE_PROPERTY, Boolean.toString(saveCache));
332334

333335
attributionAttributes.getProperties(props);
334336

@@ -342,16 +344,16 @@ public Properties getPropertyInfo(Properties props) {
342344
"Force zoom level for queries (-1 is no forcing)", null);
343345
PropUtils.setI18NPropertyInfo(i18n, props, this.getClass(), DATA_ATTRIBUTION_PROPERTY, "Attribution",
344346
"Attribution for data source", null);
345-
PropUtils.setI18NPropertyInfo(i18n, props, this.getClass(), DISABLE_TILE_FACTORY_RESET, "Disable Tile Factory Reset", "Disable tile factory reset on layer remove", null);
347+
PropUtils.setI18NPropertyInfo(i18n, props, this.getClass(), SAVE_CACHE_PROPERTY, "Disable Tile Factory Reset", "Disable tile factory reset on layer remove", null);
346348
if (tileFactory instanceof StandardMapTileFactory) {
347349
((StandardMapTileFactory) tileFactory).getPropertyInfo(props);
348350
props.put(initPropertiesProperty, ((StandardMapTileFactory) tileFactory).getInitPropertiesOrder()
349351
+ " " + ZOOM_LEVEL_PROPERTY + " " + DATA_ATTRIBUTION_PROPERTY + " "
350-
+ DISABLE_TILE_FACTORY_RESET);
352+
+ SAVE_CACHE_PROPERTY);
351353
} else {
352354
props.put(initPropertiesProperty, StandardMapTileFactory.ROOT_DIR_PROPERTY + " "
353355
+ StandardMapTileFactory.FILE_EXT_PROPERTY + " " + ZOOM_LEVEL_PROPERTY + " "
354-
+ DATA_ATTRIBUTION_PROPERTY + " " + DISABLE_TILE_FACTORY_RESET);
356+
+ DATA_ATTRIBUTION_PROPERTY + " " + SAVE_CACHE_PROPERTY);
355357
}
356358

357359
return props;
@@ -363,7 +365,7 @@ public Properties getPropertyInfo(Properties props) {
363365
*/
364366
public void removed(Container cont) {
365367
MapTileFactory tileFactory = getTileFactory();
366-
if (tileFactory != null && !disableTileFactoryReset) {
368+
if (tileFactory != null && !saveCache) {
367369
tileFactory.reset();
368370
}
369371
}

0 commit comments

Comments
 (0)