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.
ALKMaps. | A 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. | |
Properties | |
cacheBlackImage | {Boolean} Cache black tile image if true else do not cache black tile image. |
Functions | |
setMap | Set the map property for the control. |
addLayer | Adds a layer to the control. |
removeLayer | Removes a layer from the control. |
makeSameOrigin | 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 | Adds a tile to the cache. |
destroy | The destroy method is used to perform any clean up before the control is dereferenced. |
ALKMaps. | Clears all tiles cached with ALKMaps.Control.CacheWrite from the cache. |
Properties | |
ALKMaps. | {Object} Mapping of same origin urls to cache url keys. |
{ALKMaps.Events} Events instance for listeners and triggering control specific events.
To register events in the constructor, configure eventListeners.
control.events.register(type, obj, listener);
cachefull | Triggered 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. |
{Array(ALKMaps.Layer.Grid)}. Optional. If provided, caching will be enabled for these layers only, otherwise for all cacheable layers.
{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.
addLayer: function( evt )
Adds a layer to the control. Once added, tiles requested for this layer will be cached.
evt | {Object} Object with a layer property referencing an ALKMaps.Layer instance |
removeLayer: function( evt )
Removes a layer from the control. Once removed, tiles requested for this layer will no longer be cached.
evt | {Object} Object with a layer property referencing an ALKMaps.Layer instance |
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.
evt | {ALKMaps.Event} |
cache: function( obj )
Adds a tile to the cache. When the cache is full, the “cachefull” event is triggered.
obj | {Object} Object with a tile property, tile being the ALKMaps.Tile.Image with the data to add to the cache |
ALKMaps.Control.CacheWrite.clearCache = function()
Clears all tiles cached with ALKMaps.Control.CacheWrite from the cache.
Set the map property for the control.
setMap: function( map )
Adds a layer to the control.
addLayer: function( evt )
Removes a layer from the control.
removeLayer: 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.
makeSameOrigin: function( evt )
Adds a tile to the cache.
cache: function( obj )
The destroy method is used to perform any clean up before the control is dereferenced.
destroy: function()
Clears all tiles cached with ALKMaps.Control.CacheWrite from the cache.
ALKMaps.Control.CacheWrite.clearCache = function()