Back to Devexpress

CacheOptions Class

windowsforms-devexpress-dot-xtramap-d9bb7559.md

latest5.9 KB
Original Source

CacheOptions Class

Contains settings that define the parameters of a local cache for storing image tiles.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public class CacheOptions :
    INotifyPropertyChanged
vb
Public Class CacheOptions
    Implements INotifyPropertyChanged

The following members return CacheOptions objects:

Remarks

The local cache stores map tiles loaded from the GIS data provider. So, when you navigate to the same geographical locations, the map tiles are loaded from your local directory, saving internet resources.

A local cache is represented by the CacheOptions object and can be accessed via the MapTileDataProviderBase.CacheOptions property.

To customize the local cache, specify the disk folder (CacheOptions.DiskFolder), the time interval after which the loaded map tiles should be updated (CacheOptions.DiskExpireTime) and other parameters (CacheOptions.MemoryLimit, CacheOptions.DiskLimit).

Note

CacheOptions is not supported for vector-based tile providers.

Example

This example illustrates what is required to customize the local cache of a map control.

The local cache allows you to save internet resources and significantly increase map performance by loading saved map tiles from the local directory.

To enable map cache, specify the directory to which the loaded map tiles will be saved using the CacheOptions.DiskFolder property and the time interval after which the loaded map tiles should be updated using the CacheOptions.DiskExpireTime property. To access the CacheOptions object, use the MapTileDataProviderBase.CacheOptions property.

In addition, you can specify the amount of memory on the computer and disk space (in megabytes) for storing tile images via CacheOptions.MemoryLimit and CacheOptions.DiskLimit properties, respectively.

In this example tile images of a map are loaded from the OpenStreetMap resource.

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraMap;

namespace CacheImageTiles {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create a map control.
            MapControl map = new MapControl();

            // Specify the map position on the form.           
            map.Dock = DockStyle.Fill;

            // Add the map control to the window.
            this.Controls.Add(map);

            // Create an image tiles layer and add it to the map.
            ImageLayer tilesLayer = new ImageLayer();
            map.Layers.Add(tilesLayer);

            // Create an Open Street data provider.
            OpenStreetMapDataProvider provider = new OpenStreetMapDataProvider();
            tilesLayer.DataProvider = provider;

            // Customize a local cache for storing image tiles obtained from the Open Street provider.
            provider.CacheOptions.DiskFolder = "C://MapTiles"; 
            provider.CacheOptions.DiskExpireTime = new TimeSpan(01,00,00);
            provider.CacheOptions.MemoryLimit = 64;           
            provider.CacheOptions.DiskLimit = 200;
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraMap

Namespace CacheImageTiles
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create a map control.
            Dim map As New MapControl()

            ' Specify the map position on the form.           
            map.Dock = DockStyle.Fill

            ' Add the map control to the window.
            Me.Controls.Add(map)

            ' Create an image tiles layer and add it to the map.
            Dim tilesLayer As New ImageLayer()
            map.Layers.Add(tilesLayer)

            ' Create an Open Street data provider.
            Dim provider As New OpenStreetMapDataProvider()
            tilesLayer.DataProvider = provider

            ' Customize a local cache for storing image tiles obtained from the Open Street provider.
            provider.CacheOptions.DiskFolder = "C://MapTiles"
            provider.CacheOptions.DiskExpireTime = New TimeSpan(01,00,00)
            provider.CacheOptions.MemoryLimit = 64
            provider.CacheOptions.DiskLimit = 200
        End Sub
    End Class
End Namespace

Inheritance

Object CacheOptions

See Also

CacheOptions Members

DevExpress.XtraMap Namespace