<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
'Declare the global script variables
Dim Output As String = "" 'The JavaScript response sent back to the Map API
Dim MapType As String = context.Request.Params("maptype") 'API to use (VE/GM)
'Declare the variables used to create each feature
Dim WKT As String = "" 'The WKT representation provided by the stored proc
Dim VEGM As String = "" 'The VE/GMaps equivalent representation
Dim Shape As String = "" 'The unique name of each shape
Dim ShapeTitle As String = "" 'The title to display for each shape
Dim ShapeDescription As String = "" 'The description attached to the shape
Dim id As Integer = 0 'Shape counter
Dim LineStyle As String = "" 'The line style
Dim FillStyle As String = "" 'The fill style
'Set up a connection to SQL server
Dim myConn As SqlConnection = New SqlConnection("server=PDI-APP-LAPTOP\Mobile;" & _
"Trusted_Connection=yes;" & _
"database=GEMPA")
'Open the connection
myConn.Open()
'Define the stored procedure to execute
Dim myQuery As String = "dbo.LokasiGempa"
Dim cmd As New SqlCommand(myQuery, myConn)
cmd.CommandType = Data.CommandType.StoredProcedure
'Send the point the user clicked on to the stored proc
cmd.Parameters.Add("@Latitude", Data.SqlDbType.Float)
cmd.Parameters("@Latitude").Value = context.Request.Params("lat")
cmd.Parameters.Add("@Longitude", Data.SqlDbType.Float)
cmd.Parameters("@Longitude").Value = context.Request.Params("long")
'Create a reader for the result set
Dim rdr As SqlDataReader = cmd.ExecuteReader()
'Go through the results
While rdr.Read()
'Set a unique variable name for this shape
Shape = "shape" + id.ToString
'Set the title for the shape
ShapeTitle = rdr("Title").ToString
'Set the description for the shape
ShapeDescription = rdr("Description").ToString
'Set the appropriate styling options for each shape
'Set the color and opacity for fills
FillStyle = 'new VEColor(0, 0, 255, 0.5)'
'Set the color and opacity for lines
LineStyle = 'new VEColor(255, 255, 255, 0.7)"
'Convert from WKT to the relevant API constructor for the type of geometry
Select Case rdr("GeometryType").ToString
Case "Point"
'Get the WKT representation of the object
WKT = rdr("WKT").ToString
'Replace the double brackets that surround the coordinate point pair
WKT = Replace(WKT, "POINT (", "")
'Remove the closing double brackets
WKT = Replace(WKT, ")", "")
'Build the appropriate Pushpin/GMarker object from the coordinates
VEGM = ""
Dim Coords() As String = Split(Trim(WKT), " ")
VEGM = VEGM + "new VELatLong(" + Coords(1) + "," + Coords(0) + ")"
Output += "var " + Shape + _
"=new VEShape(VEShapeType.Pushpin, " + VEGM + ");"
'Display descriptive airport information when mouse hovers over point
'Set the shape title
Output += Shape + ".SetTitle('" + ShapeTitle + "');"
'Set the shape description
Output += Shape + ".SetDescription('" + ShapeDescription + "');"
Case "Polygon"
'Get the WKT representation of the object
WKT = rdr("WKT").ToString
'Replace the double brackets that surround the coordinate point pairs
WKT = Replace(WKT, "POLYGON ((", "")
'Remove the closing double brackets
WKT = Replace(WKT, "))", "")
'Create an array of each point in the Polygon
Dim PointArray() As String = Split(WKT, ",")
'Build the appropriate VE/GMaps Polygon object from the coordinates
VEGM = ""
Dim i As Integer = 0
While i <= PointArray.Length - 1
Dim Coords() As String = Split(Trim(PointArray(i)), " ")
VEGM = VEGM + "new VELatLong(" + Coords(1) + "," + Coords(0) + "),"
i = i + 1
End While
'Remove the last trailing comma
VEGM = Left(VEGM, VEGM.Length - 1)
'Add the constructor for the Polygon, and apply styling options
Output += "var " + Shape + _
"=new VEShape(VEShapeType.Polygon, [" + VEGM + "]);"
Output += Shape + ".SetLineColor(" + LineStyle + ");"
Output += Shape + ".SetFillColor(" + FillStyle + ");"
Output += Shape + ".HideIcon();"
End Select
'Add the shape to the map
Output += "map.AddShape(" + Shape + ");"
'Increment the shape counter
id = id + 1
End While
'Close the reader
rdr.Close()
'Close the connection
myConn.Close()
'Tell the browser to handle the response as JavaScript
context.Response.ContentType = "text/JavaScript"
'Do not cache the results, so always load new data
context.Response.CacheControl = "no-cache"
'Make the response expire immediately
context.Response.Expires = -1
'Return the constructed JavaScript
context.Response.Write(Output)
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class