Imports AspMap
Imports AspMap.Web
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadStates()
End If
LoadLayer()
End Sub
Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
getAirport(ddlState.SelectedValue)
End Sub
Sub LoadLayer()
Dim layer As AspMap.Layer
Dim MapDir As String = MapPath("MAP/")
' add states layer
layer = Map1.AddLayer(MapDir & "states.shp")
layer.LabelField = "STATE_NAME"
layer.ShowLabels = True
layer.LabelFont.Name = "Verdana"
layer.LabelFont.Size = 12
layer.LabelFont.Bold = True
layer.LabelStyle = LabelStyle.PolygonCenter
' add roads layer
layer = Map1.AddLayer(MapDir & "roads.shp")
End Sub
Sub LoadStates()
Dim cn As New SqlConnection("Data Source=pdi-app-laptop\mobile;Initial Catalog=DbUSA;Trusted_Connection=yes;")
cn.Open()
Dim cmd As New SqlCommand("select distinct [STATE_NAME],STATE_ABBR from [STATES] order by STATE_NAME", cn)
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader
ddlState.Items.Clear()
While rdr.Read
Dim li As New ListItem
li.Text = Trim("" & rdr(0))
li.Value = Trim("" & rdr(1))
ddlState.Items.Add(li)
End While
rdr.Close()
rdr = Nothing
cmd = Nothing
cn.Close()
cn = Nothing
End Sub
Sub getAirport(ByVal strState As String)
Dim cn As New SqlConnection("Data Source=pdi-app-laptop\mobile;Initial Catalog=DbUSA;Trusted_Connection=yes;")
cn.Open()
Dim cmd As New SqlCommand("select [NAME], [Location].STAsText() from [Airports] where STATE ='" & strState & "'", cn)
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader
Map1.Markers.Clear()
lblFound.Text = ""
Dim count As Integer
count = 0
While rdr.Read
Dim symbol As New MarkerSymbol("icon/marker.gif", 19, 31)
Dim x As Double
Dim y As Double
Dim tmp As String
Dim pos As Byte
tmp = Left(Trim("" & rdr(1)), Len(Trim("" & rdr(1))) - 1)
pos = InStr(tmp, "(", CompareMethod.Text)
tmp = Right(tmp, Len(tmp) - pos)
Dim arrXY() As String
arrXY = Split(Trim(tmp), " ", , CompareMethod.Text)
x = arrXY(0)
y = arrXY(1)
Dim marker As New Marker(New AspMap.Point(x, y), symbol, rdr(0))
Map1.Markers.Add(marker)
arrXY = Nothing
count = count + 1
End While
lblFound.Text = count.ToString & " Airports Found "
rdr.Close()
rdr = Nothing
cmd = Nothing
cn.Close()
cn = Nothing
End Sub
End Class