Back to Devexpress

How to: Connect a Map Control to the OpenStreetMap Search Service

windowsforms-120283-controls-and-libraries-map-control-examples-gis-data-searching-how-to-connect-a-map-control-to-the-openstreetmap-search-service.md

latest2.0 KB
Original Source

How to: Connect a Map Control to the OpenStreetMap Search Service

  • Nov 13, 2018

This example demonstrates how to add an image layer displaying map tiles from the OSM service and an information layer that searches for a place on the map using the OSM search service. It uses the following classes:

ClassDescription
ImageLayerDisplays map images obtained from map image data providers.
OpenStreetMapDataProviderThe class that loads map images from a web resource that provides data in the OpenStreetMap format.
InformationLayerA layer that is used to display additional information above the map.
OsmSearchDataProviderProvides the search options using the Open Street Map service.

View Example

csharp
private void OnFormLoad(object sender, EventArgs e) {
    mapControl.Layers.AddRange(new LayerBase[] {
        new ImageLayer {
            DataProvider = new OpenStreetMapDataProvider {
                TileUriTemplate = "YOUR_WEB_SERVICE.com/{1}/{2}/{3}"
            }
        },
        new InformationLayer {
            DataProvider = new OsmSearchDataProvider { }
        }
    });
}
vb
Private Sub OnFormLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    mapControl.Layers.AddRange(New LayerBase() {
        New ImageLayer With {
            .DataProvider = New OpenStreetMapDataProvider With {
                .TileUriTemplate = "YOUR_WEB_SERVICE.com/{1}/{2}/{3}"
            }
        },
        New InformationLayer With {
            .DataProvider = New OsmSearchDataProvider
        }
    })
End Sub