Recently I had the challenge of building a DOT Transportation Compliance System and one of the challenges was generating a pop up map of the United States indicating A State's DOT compliance status based on system settings. In other words a system administrator sets a states DOT status in the application and the popup map will dynamically reflect these changes.
The above popup map clearly indicates DOT and NON-DOT states. The squares colors are set based on data from a database. I am basically toggling between two images and setting their absolute position with in the page.
The first thing that I did was found a suitable map from the Internet and set the page background attribute to this image. The next thing that I had to do was dynamically build the image string for the above indicator images in the VB code behind.
Partial Class usmap Inherits System.Web.UI.Page Dim myData As New clsData Dim myTable As Data.DataTable Dim myUtil As New clsUtility Dim myHash As New Hashtable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load BuildHashTable() GetStates() End Sub
Private Sub GetStates() Dim strSQL As String = "Select * From DOT_STATE order by 1" Dim i As Integer = 0 Dim TempImage As String = ""
myTable = myData.GetDataTable_SQLString(strSQL) ‘My data class
For i = 0 To myTable.Rows.Count - 1 If myTable.Rows(i)(2) = 0 Then TempImage = " Else TempImage = " End If TempImage += "style='" & myHash(CType(myTable.Rows(i)(1), String).ToLower) & "' alt='" & CType(myTable.Rows(i)(1), String).ToUpper & "' / />" Response.Write(TempImage) Next End Sub End Class
This class is basically composed of two procedures.
BuildHashtbale: I used an image-mapping program to find the image placement position for all the states and placed this information in a hash table. Note…this information is not in the database because this map was created after the fact. The state abbreviation denotes the row in the hash table paired with it’s Top and Left information.
GetStates: Here I query the database to get the state long name, abbreviation and DOT status information.
The Data
Long Name Abbreviation DOT Status Georgia GA 1 Florida FL 0 Texas TX 0 Kentucky KY 1
I then loop thru the data table and dynamically build the HTML image tag. Based on the DOT status column I start building a black or orange square image. I use the abbreviation fields to attach the image style to the appropriate row in the hash table, which sets the image positioning to absolute and sets a top and left position values.
As an added bonus I placed the state abbreviation in the images ALT tag using the abbreviation column data.
This article shows one creative way of dynamically placing images on a page and placing them in predetermined positions.
Items can be positioned based on data in a database by dynamically building a style string from database information.
Mr.surat keadnaimongkol
Non-training enquiries should be directed, initially, to our UK national office in Bradford (West Yorkshire), even if the enquiry concerns services delivered in London or South/East England. Clients in London and the South East will typically be handled by staff working in the London or Cambridge areas.
No comments:
Post a Comment