ALKMaps.Control.CacheWrite

A control for caching image tiles in the browser’s local storage.  The ALKMaps.Control.CacheRead control is used to fetch and use the cached tile images.

Note: Before using this control on any layer that is not your own, make sure that the terms of service of the tile provider allow local storage of tiles.

Inherits from

Summary
ALKMaps.Control.CacheWriteA control for caching image tiles in the browser’s local storage.
Properties
events{ALKMaps.Events} Events instance for listeners and triggering control specific events.
eventListeners{Object} Object with event listeners, keyed by event name.
layers{Array(ALKMaps.Layer.Grid)}.
imageFormat{String} The image format used for caching.
quotaRegEx{RegExp}
Constructor
ALKMaps.Control.CacheWrite
Properties
cacheBlackImage{Boolean} Cache black tile image if true else do not cache black tile image.
Functions
setMapSet the map property for the control.
addLayerAdds a layer to the control.
removeLayerRemoves a layer from the control.
makeSameOriginIf the tile does not have CORS image loading enabled and is from a different origin, use ALKMaps.ProxyHost to make it a same origin url.
cacheAdds a tile to the cache.
destroyThe destroy method is used to perform any clean up before the control is dereferenced.
ALKMaps.Control.CacheWrite.clearCacheClears all tiles cached with ALKMaps.Control.CacheWrite from the cache.
Properties
ALKMaps.Control.CacheWrite.urlMap{Object} Mapping of same origin urls to cache url keys.

Properties

events

{ALKMaps.Events} Events instance for listeners and triggering control specific events.

To register events in the constructor, configure eventListeners.

Register a listener for a particular event with the following syntax

control.events.register(type, obj, listener);

Supported event types (in addition to those from <ALKMaps.Control.events>)

cachefullTriggered when the cache is full.  Listeners receive an object with a tile property as first argument.  The tile references the tile that couldn’t be cached.

eventListeners

{Object} Object with event listeners, keyed by event name.  An optional scope property defines the scope that listeners will be executed in.

layers

{Array(ALKMaps.Layer.Grid)}.  Optional.  If provided, caching will be enabled for these layers only, otherwise for all cacheable layers.

imageFormat

{String} The image format used for caching.  The default is “image/png”.  Supported formats depend on the user agent.  If an unsupported imageFormat is provided, “image/png” will be used.  For aerial imagery, “image/jpeg” is recommended.

quotaRegEx

{RegExp}

Constructor

ALKMaps.Control.CacheWrite

Parameters

options{Object} Object with API properties for this control.

Properties

cacheBlackImage

{Boolean} Cache black tile image if true else do not cache black tile image.

Functions

setMap

setMap: function(map)

Set the map property for the control.

Parameters

map{ALKMaps.Map}

addLayer

addLayer: function(evt)

Adds a layer to the control.  Once added, tiles requested for this layer will be cached.

Parameters

evt{Object} Object with a layer property referencing an ALKMaps.Layer instance

removeLayer

removeLayer: function(evt)

Removes a layer from the control.  Once removed, tiles requested for this layer will no longer be cached.

Parameters

evt{Object} Object with a layer property referencing an ALKMaps.Layer instance

makeSameOrigin

makeSameOrigin: function(evt)

If the tile does not have CORS image loading enabled and is from a different origin, use ALKMaps.ProxyHost to make it a same origin url.

Parameters

evt{ALKMaps.Event}

cache

cache: function(obj)

Adds a tile to the cache.  When the cache is full, the “cachefull” event is triggered.

Parameters

obj{Object} Object with a tile property, tile being the ALKMaps.Tile.Image with the data to add to the cache

destroy

destroy: function()

The destroy method is used to perform any clean up before the control is dereferenced.  Typically this is where event listeners are removed to prevent memory leaks.

ALKMaps.Control.CacheWrite.clearCache

ALKMaps.Control.CacheWrite.clearCache = function()

Clears all tiles cached with ALKMaps.Control.CacheWrite from the cache.

Properties

ALKMaps.Control.CacheWrite.urlMap

{Object} Mapping of same origin urls to cache url keys.  Entries will be deleted as soon as a tile was cached.

Base class for layers that use a lattice of tiles.
setMap: function(map)
Set the map property for the control.
addLayer: function(evt)
Adds a layer to the control.
removeLayer: function(evt)
Removes a layer from the control.
makeSameOrigin: function(evt)
If the tile does not have CORS image loading enabled and is from a different origin, use ALKMaps.ProxyHost to make it a same origin url.
cache: function(obj)
Adds a tile to the cache.
destroy: function()
The destroy method is used to perform any clean up before the control is dereferenced.
ALKMaps.Control.CacheWrite.clearCache = function()
Clears all tiles cached with ALKMaps.Control.CacheWrite from the cache.
A control for using image tiles cached with ALKMaps.Control.CacheWrite from the browser’s local storage.
Controls affect the display or behavior of the map.
{Object} Object with event listeners, keyed by event name.
{String} The image format used for caching.
Instances of ALKMaps.Map are interactive maps embedded in a web page.
Utility functions for event handling.
Instances of ALKMaps.Tile.Image are used to manage the image tiles used by various layers.
Close