Example T629598
Visible to All Users

Map for WinForms - Use the OpenStreetMap Search Service

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.

resulting 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.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

OsmSearchSample/MainForm.cs(vb)
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/"; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.