Adding a Database Table as a Layer


Objective: In this lesson, you will learn how to add a database table that contains coordinates of locations as a map layer.

 

We will use the Airports.mdb database that contains the Airports table which stores locations of airports as latitude/longitude coordinates:

 

ID

DESCRIP

STATE

LONGITUDE

LATITUDE

1958

STEVENSON

AL

-85.803

34.8862

1956

CHAMBERS MUNI

AL

-85.2296

32.812

1583

ROY WILCOX

AL

-88.1945

31.4518

935

GROVE HILL MUNI

AL

-87.7614

31.6893

 

More information is available in the Accessing Spatial Data Stored in Databases topic.

 

1. Add the AddDatabase() method. The locations of airports will be rendered as silver circles.

Imports AspMap.Data
Private Sub AddDatabase()
        Dim dataFile As String = MapPath("DATA/airports.mdb")
        Dim connectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dataFile

        Dim pointData As AspMap.Data.PointDataLayer 
        pointData = New AspMap.Data.PointDataLayer("System.Data.OleDb", connectionString, "airports", "LONGITUDE", "LATITUDE")

        Dim dbLayer As AspMap.Layer = Map1.AddLayer(pointData)

        If dbLayer Is Nothing Then
                Response.Write("Cannot add airports.mdb database.")
                Response.End()
        End If

        dbLayer.Name = "Airports"
        dbLayer.Symbol.PointStyle = PointStyle.Circle
        dbLayer.Symbol.FillColor = Color.Silver

        dbLayer.LabelField = "DESCRIP"
        dbLayer.LabelFont.Name = "Arial"
        dbLayer.LabelFont.Size = 12
        dbLayer.ShowLabels = true
        ' dislpay the labels when MapScale is less than 15000000
        dbLayer.LabelMaxScale = 15000000 
End Sub

2. Replace the code in the OnLoad event handler as follows (new code is in RED):

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddMapLayers()
        AddDatabase()
End Sub

3. Compile and run the application, your map should look similar to the image below:

 

 

 

 

 

© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)