User Tools

Site Tools


source_code_silverlighteditionsample_outofbrowser_cs_111128.zip

Source Code SilverlightEditionSample OutOfBrowser CS 111128.zip

App.xaml.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Net;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Documents;  
 using System.Windows.Input;  
 using System.Windows.Media;  
 using System.Windows.Media.Animation;  
 using System.Windows.Shapes;  
 
 namespace HelloWorld  
 {  
     public partial class App : Application  
     {  
 
         public App()  
         {  
             this.Startup += this.Application_Startup;  
             this.Exit += this.Application_Exit;  
             this.UnhandledException += this.Application_UnhandledException;  
 
             InitializeComponent();  
         }  
 
         private void Application_Startup(object sender, StartupEventArgs e)  
         {  
             this.RootVisual = new MainPage();  
         }  
 
         private void Application_Exit(object sender, EventArgs e)  
         {  
 
         }  
         private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)  
         {  
             // If the app is running outside of the debugger then report the exception using  
             // the browser's exception mechanism. On IE this will display it a yellow alert  
             // icon in the status bar and Firefox will display a script error.  
             if (!System.Diagnostics.Debugger.IsAttached)  
             {  
 
                 // NOTE: This will allow the application to continue running after an exception has been thrown  
                 // but not handled.  
                 // For production applications this error handling should be replaced with something that will  
                 // report the error to the website and stop the application.  
                 e.Handled = true;  
                 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });  
             }  
         }  
         private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)  
         {  
             try  
             {  
                 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;  
                 errorMsg = errorMsg.Replace('"', '\//).Replace("\r\n", @"\n");  
 
                 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");  
             }  
             catch (Exception)  
             {  
             }  
         }  
     }  
 }  
 

MainPage.xaml.cs

 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Media;  
 using ThinkGeo.MapSuite.SilverlightCore;  
 using ThinkGeo.MapSuite.SilverlightEdition;  
 
 namespace HelloWorld  
 {  
     public partial class MainPage : UserControl  
     {  
         public MainPage()  
         {  
             InitializeComponent();  
             Loaded += new RoutedEventHandler(MainPage_Loaded);  
         }  
 
         void MainPage_Loaded(object sender, RoutedEventArgs e)  
         {  
             Map1.MapUnit = GeographyUnit.DecimalDegree;  
             Map1.Background = new SolidColorBrush(Color.FromArgb(255, 156, 187, 216));  
 
             WorldMapKitWmsSilverlightOverlay wmk = new WorldMapKitWmsSilverlightOverlay();  
             Map1.Overlays.Add(wmk);  
 
             // Here shows how to enable the serverOverlay work in out-of-browser  
             ServerLayerOverlay serverOverlay = new ServerLayerOverlay("NativeServer", "SilverlightMapConnector1");  
             serverOverlay.ConnectorHost = new System.Uri("http://localhost:65452/Default.aspx");  
             Map1.Overlays.Add(serverOverlay);  
 
             Map1.ZoomTo(new PointShape(-100, 35), 4);  
         }  
     }  
 }  
 

Banner.ascx.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 
 namespace HelloWorld.Web  
 {  
     public partial class Banner : System.Web.UI.UserControl  
     {  
         protected void Page_Load(object sender, EventArgs e)  
         {  
 
         }  
     }  
 }

Default.aspx.cs

 using System;  
 using System.Web.UI;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.SilverlightEdition;  
 
 namespace HelloWorld.Web  
 {  
     public partial class _Default : System.Web.UI.Page  
     {  
         protected void Page_Load(object sender, EventArgs e)  
         {  
             if (!Page.IsPostBack)  
             {  
                 ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/app_data/cntry02.shp"));  
                 worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, 243, 239, 228), GeoColor.SimpleColors.Red, 1);  
                 worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
                 ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer");  
                 layerOverlay.Layers.Add(worldLayer);  
 
                 SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay);  
             }  
         }  
     }  
 }

Footer.ascx.cs

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

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());  
         }  
     }  
 }  
 

Default.aspx

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HelloWorld.Web._Default" %>  
 
 <%@ Register Src="Footer.ascx" TagName="Footer" TagPrefix="uc1" %>  
 <%@ Register Src="Banner.ascx" TagName="Banner" TagPrefix="uc2" %>  
 <%@ Register Assembly="SilverlightMapConnector" Namespace="ThinkGeo.MapSuite.SilverlightEdition"  
     TagPrefix="cc1" %>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
     <link href="Resources/css.css" rel="stylesheet" type="text/css" />  
     <title></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:SilverlightMapConnector runat="server" ID="SilverlightMapConnector1" Source="~/ClientBin/HelloWorld.xap"  
                             Height="700px" Width="1200px">  
                         </cc1:SilverlightMapConnector>  
                     </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_silverlighteditionsample_outofbrowser_cs_111128.zip.txt · Last modified: 2015/09/09 03:37 by admin