User Tools

Site Tools


source_code_webeditionsample_arcgisserverrestoverlay_cs_110603.zip

Source Code WebEditionSample ArcGISServerRestOverlay CS 110603.zip

Banner.ascx.cs

 using System;  
 using System.IO;  
 
 public partial class Banner : System.Web.UI.UserControl  
 {  
     private const string PreStart = "<body oncontextmenu='return false;'><pre name='code' class='c-sharp:nocontrols'>";  
     private const string PreEnd = "</pre><link type='text/css' rel='stylesheet' href='../Resources/SyntaxHighlighter/SyntaxHighlighter.css'></link><script language='javascript' src='../Resources/SyntaxHighlighter/shCore.js'></script><script language='javascript' src='../Resources/SyntaxHighlighter/shBrushCSharp.js'></script><script language='javascript' src='../Resources/SyntaxHighlighter/shBrushXml.js'></script><script language='javascript'>dp.SyntaxHighlighter.HighlightAll('code');</script></body>";  
     private const string ErrorPageUrl = "~/Source Code Not Available in Beta.html";  
 
     protected void Page_Load(object sender, EventArgs e)  
     {  
         string filename = "Sample.aspx.cs";  
         string htmlFileName = filename.Replace(".cs", ".htm");  
         if (File.Exists(htmlFileName))  
         {  
             return;  
         }  
 
         string text;  
         try  
         {  
             using (StreamReader sr = new StreamReader(Server.MapPath(filename)))  
             {  
                 text = sr.ReadToEnd();  
             }  
             text = PreStart + text + PreEnd;  
 
             using (StreamWriter sw = new StreamWriter(Server.MapPath(htmlFileName)))  
             {  
                 sw.Write(text);  
             }  
         }  
         catch  
         {  
             htmlFileName = ErrorPageUrl;  
         }  
         return;  
     }  
 }  
 

Footer.ascx.cs

using System;  
 
 public partial class Footer : System.Web.UI.UserControl  
 {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
 
     }  
 }  
 

Sample.aspx.cs

 using System;  
 using System.Web.UI;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WebEdition;  
 
 public partial class Sample : System.Web.UI.Page  
 {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
         if (!Page.IsPostBack)  
         {  
             Map1.MapUnit = GeographyUnit.DecimalDegree;  
             Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);  
 
             //use the WorldMapKit as the background overlay.  
             WorldMapKitWmsWebOverlay worldMapKitWmsWebOverlay = new WorldMapKitWmsWebOverlay();  
             Map1.CustomOverlays.Add(worldMapKitWmsWebOverlay);  
 
             //Create a new ArcGISRestServerOverlay.  This will be used to show counties based on population.  
             //documentation for ArcGIS Server REST API can be found at:  http:// resources.esri.com/help/9.3/arcgisserver/apis/rest/  
             ArcGISServerRestOverlay arcGISServerRestOverlay = new ArcGISServerRestOverlay("ArcGIS Overlay");  
 
             //specify the uri of the web service.  
             arcGISServerRestOverlay.ServerUri = new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export");  
             //Set our parameters for image format and transparency.  
             arcGISServerRestOverlay.Parameters.Add("format", "png");  
             arcGISServerRestOverlay.Parameters.Add("transparent", "true");  
             //specify the layerId(s) you wish to display.  LayerId 2 is the county layer.  
             arcGISServerRestOverlay.Parameters.Add("layers", "show:2");  
             //specify the layer and field you wish to query (layerid:field).  in this example, the layerid is 2 and the data field to query is POP1999.  
             arcGISServerRestOverlay.Parameters.Add("layerdefs", "2:POP1999" + txtPopulationFilter.Text);  
             arcGISServerRestOverlay.IsBaseOverlay = false;  
 
             Map1.CustomOverlays.Add(arcGISServerRestOverlay);  
 
             Map1.CurrentExtent = new RectangleShape(-140, 60, -58, 30);  
         }  
     }  
 
     protected void btnSubmitQuery_Click(object sender, EventArgs e)  
     {  
         //get our ArcGIS Overlay and update the layerdefs parameter.  
         ArcGISServerRestOverlay arcGISServerRestOverlay = (ArcGISServerRestOverlay)Map1.CustomOverlays["ArcGIS|Overlay"];  
         arcGISServerRestOverlay.Parameters["layerdefs"] = "2:POP1999" + txtPopulationFilter.Text;  
     }  
 }  
 

InstructionsPanel.cs

using System;  
 using System.ComponentModel;  
 using System.IO;  
 using System.Web.UI.WebControls;  
 
 namespace DisplayASimpleMap  
 {  
     // This class represents the "instructions" floating panel.  
     [ToolboxItem(false)]  
     public class InstructionPanel : Panel  
     {  
         protected override void OnPreRender(System.EventArgs e)  
         {  
             StreamReader reader = File.OpenText(Page.MapPath("~/Resources/InstructionsPanel/InstructionsPanel.js"));  
             string script = reader.ReadToEnd();  
             reader.Close();  
             Page.ClientScript.RegisterClientScriptBlock(GetType(), "PanelScript", script, true);  
             base.OnPreRender(e);  
         }  
 
         protected override void Render(System.Web.UI.HtmlTextWriter writer)  
         {  
             StreamReader reader = File.OpenText(Page.MapPath("~/Resources/InstructionsPanel/InstructionsPanel.htm"));  
             string[] script = reader.ReadToEnd().Split(new string[] { "<!--Split-->" }, StringSplitOptions.RemoveEmptyEntries);  
             reader.Close();  
             writer.WriteLine(script[0].Trim());  
             base.Render(writer);  
             writer.WriteLine(script[1].Trim());  
         }  
     }  
 }  
 

Sample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sample.aspx.cs" Inherits="Sample" %>  
 
 <%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>  
 <%@ Register Src="Footer.ascx" TagName="Footer" TagPrefix="uc1" %>  
 <%@ Register Src="Banner.ascx" TagName="Banner" TagPrefix="uc2" %>  
 <!DOCTYPE html PUBLIC "-W3C//DTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head id="Head1" runat="server">  
     <link href="Resources/css.css" rel="stylesheet" type="text/css" />  
     <title>Display a Simple Map - Map Suite Web Sample application</title>  
 </head>  
 <body onresize="resizeElementHeight()">  
     <form id="form1" runat="server">  
     <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">  
         <tr>  
             <td>  
                 <uc2:Banner ID="Header1" runat="server" />  
             </td>  
         </tr>  
         <tr>  
             <td align="left">  
                 <div id="TabContainer">  
                     <a id="A1" runat="server" class="tab selected" href="#" onclick="this.className='tab selected';document.getElementById('A2').className='tab';document.getElementById('maptoggle').style.display='block';document.getElementById('sourcecode').style.display='none';">  
                         Map View</a> <a id="A2" runat="server" class="tab" href="#" onclick="this.className='tab selected';document.getElementById('A1').className='tab';document.getElementById('sourcecode').style.display='block';document.getElementById('maptoggle').style.display='none';">  
                             Source Code</a>  
                 </div>  
             </td>  
         </tr>  
         <tr> 
             <td align="center">  
                 <div id="MapContainer">  
                     <div id="maptoggle">  
                         <asp:ScriptManager ID="ScriptManager1" runat="server">  
                         </asp:ScriptManager>  
                         <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%">  
                         </cc1:Map>  
 
                         <Instruction:InstructionPanel ID="FunctionPanel" runat="server" Width="292px">  
                             This sample uses the ArcGISServerRestOverlay to show all US counties with a population > 50,000.  This feature is new to MapSuite WebEdition 5.0 and allows you to easily access maps via the ArcGIS Server REST API.  
                             <br /><br />  
                             Use the text box below to filter by county population:<br />  
                             <asp:TextBox ID="txtPopulationFilter" runat="server" Text=" > 50000"></asp:TextBox> &nbsp;&nbsp;  
                             <asp:Button runat="server" Name="btnSubmitQuery" Text="Submit Query"  
                                 onclick="btnSubmitQuery_Click"/>  
                         </Instruction:InstructionPanel>  
                     </div>  
                     <div id="sourcecode" style="display: none;">  
                         <iframe height="100%" width="100%" id="sourcepage" runat="server" src="Sample.aspx.htm">  
                         </iframe>  
                     </div>  
                 </div>  
             </td>  
         </tr>  
         <tr>  
             <td>  
                 <uc1:Footer ID="Footer1" runat="server" />  
             </td>  
         </tr>  
     </table>  
     </form>  
 </body>  
 <script type="text/javascript">  
     function resizeElementHeight() {  
         var height = 0;  
         var body = window.document.body;  
         if (window.innerHeight) {  
             height = window.innerHeight;  
         } else if (body.parentElement.clientHeight) {  
             height = body.parentElement.clientHeight;  
         } else if (body && body.clientHeight) {  
             height = body.clientHeight;  
         }  
         document.getElementById('MapContainer').style.height = ((height - 170) + "px");  
     }  
     var alreadyrun = 0  
     if (document.addEventListener)  
              document.addEventListener("DOMContentLoaded", function () { alreadyrun = 1; resizeElementHeight() }, false)  
     else if (document.all && !window.opera) {  
         document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')  
         var contentloadtag = document.getElementById("contentloadtag")  
         contentloadtag.onreadystatechange = function () {  
             if (this.readyState == "complete") {  
                 alreadyrun = 1  
                 resizeElementHeight()  
             }  
         }  
     }  
     window.onload = function () {  
         setTimeout("if (!alreadyrun) resizeElementHeight()", 0)  
     }  
 </script>  
 </html>  
 
source_code_webeditionsample_arcgisserverrestoverlay_cs_110603.zip.txt · Last modified: 2015/09/09 03:37 by admin