# OpenLayers.Control.CacheWrite

A control for caching image tiles in the browser’s local storage. The OpenLayers.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

- OpenLayers.Control

Summary

OpenLayers.Control.CacheWrite | A control for caching image tiles in the browser’s local storage.
Properties |
events | {OpenLayers.Events} Events instance for listeners and triggering control specific events.
eventListeners | {Object} Object with event listeners, keyed by event name.
layers | {Array(OpenLayers.Layer.Grid)}.
imageFormat | {String} The image format used for caching.
quotaRegEx | {RegExp}
Constructor |
OpenLayers.Control.CacheWrite |
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 OpenLayers.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.
OpenLayers.Control.CacheWrite.clearCache | Clears all tiles cached with OpenLayers.Control.CacheWrite from the cache.
Properties |
OpenLayers.Control.CacheWrite.urlMap | {Object} Mapping of same origin urls to cache url keys.

### Properties

### events

{OpenLayers.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 OpenLayers.Control.events)

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.

### 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(OpenLayers.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

### OpenLayers.Control.CacheWrite

#### Parameters

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

### Functions

### setMap

> setMap: function( | map | )

Set the map property for the control.

#### Parameters

map | {OpenLayers.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 OpenLayers.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 OpenLayers.Layer instance

### makeSameOrigin

> makeSameOrigin: function( | evt | )

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

#### Parameters

evt | {OpenLayers.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 OpenLayers.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.

### OpenLayers.Control.CacheWrite.clearCache

> OpenLayers.Control.CacheWrite.clearCache = function()

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

### Properties

### OpenLayers.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 OpenLayers.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.

> OpenLayers.Control.CacheWrite.clearCache = function()

Clears all tiles cached with OpenLayers.Control.CacheWrite from the cache.
A control for using image tiles cached with OpenLayers.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.
{OpenLayers.Events} Events instance for listeners and triggering control specific events.
{String} The image format used for caching.
Instances of OpenLayers.Map are interactive maps embedded in a web page.
Utility functions for event handling.
Instances of OpenLayers.Tile.Image are used to manage the image tiles used by various layers.
Close