This example uses OpenStreetMapDataProvider
to connect Map Control to the OpenStreetMap service.
IMPORTANT: 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.
Follow the steps below to display the OpenStreetMap geodata in the Map Control:
-
Use the
ServicePointManager.SecurityProtocol
property to specify the network security protocol before theInitializeComponent
method call. -
Create a
MapControl
object. Set theMapControl.Dock
property to the DockStyle.Fill value to fit the Map Control to the form. Call the Add method to add the Map Control to the form's control collection. -
Create
ImageLayer
and use theMapControl.Layers.Add
method to add this layer to the map. -
Create an
OpenStreetMapDataProvider
object and assign it to theImageLayer.DataProvider
property. Specify theOpenStreetMapDataProvider.TileUriTemplate
property to load data from an OSM server. Our example contains a sample template string that does not connect to an existing OSM server. -
Handle the
OpenStreetMapDataProvider.WebRequest
event and specify thee.UserAgent
ande.Referer
properties in the event handler.