This example demonstrates how to add an image layer with map tiles from the OpenStreetMap service, and an information layer uses the OpenStreetMap search service to locate a place on the map.
The example uses the following classes:
ImageLayer
- A layer that displays map images obtained from map image data providers.OpenStreetMapDataProvider
- A provider that loads map images in the OpenStreetMap format from a web resource.
IMPORTANT: Before you use OpenStreetMap tiles in your app, read the following articles: Copyright and License and Tile Usage Policy.
InformationLayer
- A layer that displays additional geo information over the map.OsmSearchDataProvider
- Allows you to use the OpenStreetMap search service.
Files to Review
- MainForm.cs (VB: MainForm.vb)
Documentation
More Examples
- Map for WinForms - Connect to the OpenStreetMap Service
- How to: Use the OpenStreetMap Geocode Service Via the Map Control
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace OsmSearchSample {
public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
}
private void OnFormLoad(object sender, EventArgs e) {
ImageLayer imageLayer = new ImageLayer();
OpenStreetMapDataProvider dataProvider = new OpenStreetMapDataProvider();
dataProvider.TileUriTemplate = "https://{0}.tile.openstreetmap.org/{1}/{2}/{3}.png";
imageLayer.DataProvider = dataProvider;
dataProvider.WebRequest += DataProvider_WebRequest;
InformationLayer infoLayer = new InformationLayer();
OsmSearchDataProvider osmSearchDataProvider = new OsmSearchDataProvider();
osmSearchDataProvider.ResultsCount = 5;
infoLayer.DataProvider = osmSearchDataProvider;
mapControl.SearchPanelOptions.Width = 400;
mapControl.Layers.AddRange(new LayerBase[] { imageLayer, infoLayer });
}
private void DataProvider_WebRequest(object sender, MapWebRequestEventArgs e) {
e.UserAgent = "Sample app with OSM tiles and search";
e.Referer = "https://www.mycompanysite.com/";
}
}
}