Displaying Map Layers


Objective: In this lesson, you will add a Map control in your new application, add several map layers and display them.

 

1. In Visual Studio, create a new ASP.NET Web Application. The application will contain several files including a web.config file and a Web Form called Default.aspx.

 

2. Add the AspMap controls to the Visual Studio Toolbox as described in the Adding AspMap Controls to the Visual Studio Toolbox topic.

 

AspMap supports ASP.NET AJAX as described in the AJAX Support topic. While it is possible to use the AspMap controls in classic ASP.NET applications, it is recommended to add the AspMap controls to UpdatePanel controls.

 

3. Expand the 'AJAX Extensions' tab in the Toolbox and put the UpdatePanel and ScrptManager controls on the form.

 

4. Add the Map control to the UpdatePanel control by clicking on the Map control and then dragging and dropping it on the UpdatePanel control.

 

5. Add references to the AspMap namespace:

Imports AspMap
Imports AspMap.Data
Imports AspMap.Web

6. Add the AddMapLayers() method to load the States.shp, Roads.shp, Capitals.shp shapefiles:

Private Sub AddMapLayers()
        Dim layer As AspMap.Layer
        Dim MapDir As String = MapPath("MAPS/USA/")

        ' add States layer
        layer = Map1.AddLayer(MapDir & "States.shp")

        ' add Roads layer
        layer = Map1.AddLayer(MapDir & "Roads.shp")

        ' add Capitals layer
        layer = Map1.AddLayer(MapDir & "Capitals.shp")                  
End Sub
7. Call the AddMapLayers() method inside the Page_Load event handler:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddMapLayers()
End Sub
Ê AspMap processes many requests from many clients. A new image may be created for each postback, unless Map Caching is used. AspMap saves map images into the ASP.NET Cache object or a temporary folder. Read more about image generation and map caching.

 

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