Skip to main content

OpenStreetMapDataProvider.TileUriTemplate Property

SECURITY NOTE

Downloading image tiles passed through URLs specified by the TileUriTemplate property may create security issues. Review the following help topic and learn how to spot, analyze, and prohibit unwanted download requests:

Suppress Control Requests to Download Data from External URLs

Gets or sets a pattern to obtain image tiles from the OpenStreetMap provider.

Namespace: DevExpress.XtraMap

Assembly: DevExpress.XtraMap.v24.2.dll

Declaration

public string TileUriTemplate { get; set; }

Property Value

Type Description
String

The pattern.

Remarks

Use the following pattern to specify TileUriTemplate: https://{0}.tile.INSERT_SERVER_NAME.com/{1}/{2}/{3}.png

Template placeholders are replaced with the following values:

  • {0} - A sub-domain of the OSM server.
  • {1} - The current zoom level.
  • {2} - The horizontal (X) index of the requested tile.
  • {3} - The vertical (Y) index of the requested tile.

If the TileUriTemplate property specifies an invalid URI, the layer to which the provider is assigned raises the Error event.

Important

Use of the TileUriTemplate property assumes that an OSM Tile Server is used. This means that all tiles for all zoom levels can be loaded. Design a custom tile provider if not all tiles are available.

Note

Before using map images in the OpenStreetMap format, please review the Copyright and License and Tile usage policy pages.

To control which web resource should be used in your application as an OpenStreetMap data provider, you should assign specific values for the OpenStreetMapDataProvider.TileUriTemplate property. Note that by default, this property is set to obtain data from the OpenStreetMap official web service.

Example

This example uses OpenStreetMapDataProvider to connect Map Control to the OpenStreetMap service.

Follow the steps below to display the OpenStreetMap geodata in the Map Control:

Note

Specify a valid OSM server name in the OpenStreetMapDataProvider.TileUriTemplate property. For instance, you can set your own tile server, use a public OSM server or choose alternative OSM servers. For more information, refer to the following article: Tile Usage Policy.

View Example: How to: Load Image Tiles from OpenStreetMap

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

namespace ConnectToOpenStreet {
    public partial class Form1 : Form {
        public Form1() {
            // Specify the network security protocol. 
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            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 form.
            this.Controls.Add(map);

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

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

            // Specify the TileUriTemplate property to connect the Map Control to an OSM server. 
            provider.TileUriTemplate = "http://{0}.tile.MyCustomOSMProvider.org/{1}/{2}/{3}.png";

            provider.WebRequest += OnWebRequest;
        }
            // Pass the user-agent HTTP header to the OSM server.
        private void OnWebRequest(object sender, MapWebRequestEventArgs e) {
            e.UserAgent = "XtraMap Getting Started - Connect to OpenStreetMap";
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the TileUriTemplate property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also