ArcIMS_BlueViewer_VBNet\MakeMap.aspx.vb
' Copyright 2010 ESRI ' ' All rights reserved under the copyright laws of the United States ' and applicable international laws, treaties, and conventions. ' ' You may freely redistribute and use this sample code, with or ' without modification, provided you include the original copyright ' notice and use restrictions. ' ' See the use restrictions. ' Namespace BlueViewer Partial Class MakeMap Inherits System.Web.UI.Page Dim imageURL As String #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim bRequestFailed As Boolean Dim sError As String = "" ' Test for the VALID_USER ' key in the session (which will be there if the ' browser session has visited default.aspx already). If Not Session("VALID_USER") = True Then sError = AddCRs("Error: Either your user session had timed out or this is an unauthorized client... Please close your browser and try again.") SendErrorScreen(sError, _ CLng(Request.QueryString("WIDTH")), _ CLng(Request.QueryString("HEIGHT")) _ ) Exit Sub End If ' Get the map. Trap for failure. Try bRequestFailed = False Dim sServer As String = ConfigurationManager.AppSettings("DEFAULT_MAPSERVER") Dim iPort As Integer = CInt(ConfigurationManager.AppSettings("DEFAULT_MAPPORT")) Dim sService As String = ConfigurationManager.AppSettings("DEFAULT_MAPSERVICE") Dim iWidth As Integer = CInt(Request.QueryString("WIDTH")) Dim iHeight As Integer = CInt(Request.QueryString("HEIGHT")) Dim conArcIMS As New ESRI.ArcGIS.ADF.Connection.IMS.TCPConnection(sServer, iPort) Dim axlRequest As New ESRI.ArcGIS.ADF.Connection.IMS.XML.AxlRequests Dim axlResponse As New System.Xml.XmlDocument conArcIMS.ServiceName = sService Dim sAXLText As String sAXLText = "<?xml version=""1.0"" encoding=""UTF-8""?><ARCXML version=""1.1"">" sAXLText = sAXLText & "<REQUEST><GET_IMAGE><PROPERTIES>" sAXLText = sAXLText & "<IMAGESIZE width=""" & iWidth & """ height=""" & iHeight & """/>" sAXLText = sAXLText & "<ENVELOPE minx=""" & Request.QueryString("XMIN") & """ miny=""" & Request.QueryString("YMIN") & """ maxx=""" & Request.QueryString("XMAX") & """ maxy=""" & Request.QueryString("YMAX") & """ />" sAXLText = sAXLText & "<LEGEND display=""false"" />" sAXLText = sAXLText & "</PROPERTIES></GET_IMAGE></REQUEST></ARCXML>" axlResponse.LoadXml(conArcIMS.Send(sAXLText)) If axlResponse.GetElementsByTagName("OUTPUT").Count = 1 Then Dim nodeOutput As System.Xml.XmlNodeList = axlResponse.GetElementsByTagName("OUTPUT") imageURL = nodeOutput(0).Attributes("url").Value End If Catch ex As System.Exception bRequestFailed = True sError = ex.Message End Try ' If map request failed, generate an image that reports ' the failure. Otherwise, redirect the client to the ' map. If bRequestFailed Then Dim sFullMessage As String = "An error occurred while processing your map request:" & _ vbCrLf & AddCRs(sError) SendErrorScreen(sFullMessage, _ CLng(Request.QueryString("WIDTH")), _ CLng(Request.QueryString("HEIGHT"))) Else Response.Redirect(imageURL) End If End Sub Private Sub SendErrorScreen(ByVal sMsg As String, _ ByVal lWidth As Long, _ ByVal lHeight As Long) ' Purpose: Creates an on-the-fly GIF with a text message. Dim bmpMap As New Bitmap(lWidth, _ lHeight, _ System.Drawing.Imaging.PixelFormat.Format32bppArgb) Dim graMap As Graphics = Graphics.FromImage(bmpMap) graMap.DrawString(sMsg, New Font("Verdana", 8), Brushes.White, 10, 10) bmpMap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif) End Sub Private Function AddCRs(ByVal sIn) As String ' Purpose: Adds a carriage return at a given ' interval. Const INTERVAL = 60 Dim sOut As String = "" Dim i As Integer Dim j As Integer = 0 For i = 1 To Len(sIn) j = j + 1 If j = INTERVAL Then sOut = sOut & vbCrLf j = 0 End If sOut = sOut & Mid(sIn, i, 1) Next i Return sOut End Function End Class End Namespace