ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
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 SilverlightApplication { 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) { } } } }
using System; using System.Windows; using System.Windows.Browser; using System.Windows.Controls; using System.Windows.Media; using SilverlightApplication.GetDataService; using ThinkGeo.MapSuite.SilverlightCore; using ThinkGeo.MapSuite.SilverlightEdition; namespace SilverlightApplication { [ScriptableTypeAttribute] public partial class MainPage : UserControl { private PointShape currentPoint; public MainPage() { InitializeComponent(); UpdateSize(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); Map1.Click += new EventHandler<MapClickEventArgs>(Map1_Click); } [ScriptableMemberAttribute] public void UpdateSize() { Map1.Width = (double)HtmlPage.Document.Body.GetProperty("scrollWidth"); Map1.Height = (double)HtmlPage.Document.Body.GetProperty("scrollHeight") - 135; double width = Map1.Width - 260; DescInfo.SetValue(Canvas.LeftProperty, width); DescInfo.SetValue(Canvas.TopProperty, 6.0); } void Map1_Click(object sender, MapClickEventArgs e) { currentPoint = e.WorldPointShape; GetGeoDataServiceClient client = new GetGeoDataServiceClient(); client.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(client_GetDataCompleted); client.GetDataAsync(e.WorldPointShape.X, e.WorldPointShape.Y); } void client_GetDataCompleted(object sender, GetDataCompletedEventArgs e) { string[] results = e.Result.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries); Map1.Popups.Clear(); if (results.Length == 2) { GeoPopup popup = new GeoPopup(currentPoint); popup.Width = 180; popup.Height = 50; TextBlock tb = new TextBlock(); tb.Text = "Name: " + results[0] + "\r\nPopulation: " + results[1]; popup.Content = tb; tb.Margin = new Thickness(5); Map1.Popups.Add(popup); Map1.Refresh(); } } void MainPage_Loaded(object sender, RoutedEventArgs e) { HtmlPage.RegisterScriptableObject("MainPage", this); Map1.Background = new SolidColorBrush(Color.FromArgb(255, 156, 187, 216)); Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.MapTools.MouseCoordinate.IsEnabled = true; Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude; WorldMapKitWmsSilverlightOverlay wmsOverlay = new WorldMapKitWmsSilverlightOverlay(); Map1.Overlays.Add(wmsOverlay); ServerLayerOverlay serverLayerOverlay = new ServerLayerOverlay("NativeServer", "SilverlightMapConnector1"); Map1.Overlays.Add(serverLayerOverlay); Map1.CurrentExtent = new RectangleShape(-80.88515625, 73.659375, 143.06015625, -46.39921875); } private void Button_Click(object sender, RoutedEventArgs e) { Button button = (Button)e.OriginalSource; if (button.Name.Equals("Button1")) { Map1.ZoomTo(Map1.MaxExtent); } else { Map1.ZoomTo(new RectangleShape(-80.88515625, 73.659375, 143.06015625, -46.39921875)); } Map1.Refresh(); } } }
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ // // This code was auto-generated by Microsoft.Silverlight.ServiceReference, version 3.0.40624.0 // namespace SilverlightApplication.GetDataService { [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel",|"3.0.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="GetDataService.IGetGeoDataService")] public interface IGetGeoDataService { [System.ServiceModel.OperationContractAttribute(AsyncPattern=true,|Action="http://tempuri.org/IGetGeoDataService/GetData", ReplyAction="http://tempuri.org/IGetGeoDataService/GetDataResponse")] System.IAsyncResult BeginGetData(double lon, double lat, System.AsyncCallback callback, object asyncState); string EndGetData(System.IAsyncResult result); } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel",|"3.0.0.0")] public interface IGetGeoDataServiceChannel : SilverlightApplication.GetDataService.IGetGeoDataService, System.ServiceModel.IClientChannel { } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel",|"3.0.0.0")] public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { private object[] results; public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : base(exception, cancelled, userState) { this.results = results; } public string Result { get { base.RaiseExceptionIfNecessary(); return ((string)(this.results[0])); } } } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel",|"3.0.0.0")] public partial class GetGeoDataServiceClient : System.ServiceModel.ClientBase<SilverlightApplication.GetDataService.IGetGeoDataService>, SilverlightApplication.GetDataService.IGetGeoDataService { private BeginOperationDelegate onBeginGetDataDelegate; private EndOperationDelegate onEndGetDataDelegate; private System.Threading.SendOrPostCallback onGetDataCompletedDelegate; private BeginOperationDelegate onBeginOpenDelegate; private EndOperationDelegate onEndOpenDelegate; private System.Threading.SendOrPostCallback onOpenCompletedDelegate; private BeginOperationDelegate onBeginCloseDelegate; private EndOperationDelegate onEndCloseDelegate; private System.Threading.SendOrPostCallback onCloseCompletedDelegate; public GetGeoDataServiceClient() { } public GetGeoDataServiceClient(string endpointConfigurationName) : base(endpointConfigurationName) { } public GetGeoDataServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public GetGeoDataServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public GetGeoDataServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } public System.Net.CookieContainer CookieContainer { get { System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>(); if ((httpCookieContainerManager != null)) { return httpCookieContainerManager.CookieContainer; } else { return null; } } set { System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>(); if ((httpCookieContainerManager != null)) { httpCookieContainerManager.CookieContainer = value; } else { throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" + "ookieContainerBindingElement."); } } } public event System.EventHandler<GetDataCompletedEventArgs> GetDataCompleted; public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted; public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted; [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] System.IAsyncResult SilverlightApplication.GetDataService.IGetGeoDataService.BeginGetData(double lon, double lat, System.AsyncCallback callback, object asyncState) { return base.Channel.BeginGetData(lon, lat, callback, asyncState); } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] string SilverlightApplication.GetDataService.IGetGeoDataService.EndGetData(System.IAsyncResult result) { return base.Channel.EndGetData(result); } private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState) { double lon = ((double)(inValues[0])); double lat = ((double)(inValues[1])); return ((SilverlightApplication.GetDataService.IGetGeoDataService)(this)).BeginGetData(lon, lat, callback, asyncState); } private object[] OnEndGetData(System.IAsyncResult result) { string retVal = ((SilverlightApplication.GetDataService.IGetGeoDataService)(this)).EndGetData(result); return new object[] { retVal}; } private void OnGetDataCompleted(object state) { if ((this.GetDataCompleted != null)) { InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state)); this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState)); } } public void GetDataAsync(double lon, double lat) { this.GetDataAsync(lon, lat, null); } public void GetDataAsync(double lon, double lat, object userState) { if ((this.onBeginGetDataDelegate == null)) { this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData); } if ((this.onEndGetDataDelegate == null)) { this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData); } if ((this.onGetDataCompletedDelegate == null)) { this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted); } base.InvokeAsync(this.onBeginGetDataDelegate, new object[] { lon, lat}, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, userState); } private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) { return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState); } private object[] OnEndOpen(System.IAsyncResult result) { ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result); return null; } private void OnOpenCompleted(object state) { if ((this.OpenCompleted != null)) { InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state)); this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState)); } } public void OpenAsync() { this.OpenAsync(null); } public void OpenAsync(object userState) { if ((this.onBeginOpenDelegate == null)) { this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen); } if ((this.onEndOpenDelegate == null)) { this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen); } if ((this.onOpenCompletedDelegate == null)) { this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted); } base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState); } private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) { return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState); } private object[] OnEndClose(System.IAsyncResult result) { ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result); return null; } private void OnCloseCompleted(object state) { if ((this.CloseCompleted != null)) { InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state)); this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState)); } } public void CloseAsync() { this.CloseAsync(null); } public void CloseAsync(object userState) { if ((this.onBeginCloseDelegate == null)) { this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose); } if ((this.onEndCloseDelegate == null)) { this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose); } if ((this.onCloseCompletedDelegate == null)) { this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted); } base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState); } protected override SilverlightApplication.GetDataService.IGetGeoDataService CreateChannel() { return new GetGeoDataServiceClientChannel(this); } private class GetGeoDataServiceClientChannel : ChannelBase<SilverlightApplication.GetDataService.IGetGeoDataService>, SilverlightApplication.GetDataService.IGetGeoDataService { public GetGeoDataServiceClientChannel(System.ServiceModel.ClientBase<SilverlightApplication.GetDataService.IGetGeoDataService> client) : base(client) { } public System.IAsyncResult BeginGetData(double lon, double lat, System.AsyncCallback callback, object asyncState) { object[] _args = new object[2]; _args[0] = lon; _args[1] = lat; System.IAsyncResult _result = base.BeginInvoke("GetData", _args, callback, asyncState); return _result; } public string EndGetData(System.IAsyncResult result) { object[] _args = new object[0]; string _result = ((string)(base.EndInvoke("GetData", _args, result))); return _result; } } } }
using System; using System.Web.UI; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.SilverlightEdition; namespace SilverlightApplication { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP_CNTRY"); classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, AreaStyles.Grass1)); classBreakStyle.ClassBreaks.Add(new ClassBreak(1000000, AreaStyles.Evergreen2)); classBreakStyle.ClassBreaks.Add(new ClassBreak(10000000, AreaStyles.Evergreen1)); classBreakStyle.ClassBreaks.Add(new ClassBreak(50000000, AreaStyles.Crop1)); classBreakStyle.ClassBreaks.Add(new ClassBreak(100000000, AreaStyles.Forest1)); ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/app_data/cntry02.shp")); worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer"); layerOverlay.Layers.Add(worldLayer); SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using ThinkGeo.MapSuite.Core; using System.Reflection; using System.IO; using System.Collections.ObjectModel; namespace SilverlightApplication { // NOTE: If you change the class name "GetGeoDataService" here, you must also update the reference to "GetGeoDataService" in Web.config. public class GetGeoDataService : IGetGeoDataService { private static ShapeFileFeatureSource featureSource; public GetGeoDataService() { string excutePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(GetGeoDataService)).CodeBase); string appPath = excutePath.Substring(excutePath.IndexOf(' ') + 1, excutePath.LastIndexOf(' ') - excutePath.IndexOf(' ') - 1); featureSource = new ShapeFileFeatureSource(appPath + @"\app_data\cntry02.shp"); } public string GetData(double lon, double lat) { featureSource.Open(); Collection<Feature> features = featureSource.SpatialQuery(new PointShape(lon, lat), QueryType.Contains, new string[] { "CNTRY_NAME", "POP_CNTRY", "COLOR_MAP" }); featureSource.Close(); StringBuilder stringBuilder = new StringBuilder(); if (features.Count != 0) { stringBuilder.AppendFormat("{0}^{1}", features[0].ColumnValues["CNTRY_NAME"], features[0].ColumnValues["POP_CNTRY"]); } return stringBuilder.ToString(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using ThinkGeo.MapSuite.Core; namespace SilverlightApplication { // NOTE: If you change the interface name "IGetGeoDataService" here, you must also update the reference to "IGetGeoDataService" in Web.config. [ServiceContract] public interface IGetGeoDataService { [OperationContract] string GetData(double lon, double lat); } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CenterMapBasedOnLatLong.UC { public partial class Footer : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CenterMapBasedOnLatLong.UC { public partial class Header : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SilverlightApplication._Default" %> <%@ Register Assembly="SilverlightMapConnector" Namespace="ThinkGeo.MapSuite.SilverlightEdition" TagPrefix="cc1" %> <%@ Register Src="UC/Footer.ascx" TagName="Footer" TagPrefix="uc1" %> <%@ Register Src="UC/Header.ascx" TagName="Header" TagPrefix="uc2" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <link href="Theme/css.css" rel="stylesheet" type="text/css" /> <title>CSharp Silverlight HowDoISamples For Debug</title> <style type="text/css"> html, body, form { height: 100%; } body { margin: 0px; overflow: hidden; } </style> <script type="text/javascript"> var updateSize = function(withTree) { var sw = parseInt(document.body.scrollWidth); var sh = parseInt(document.body.scrollHeight); var sourceDiv = $get('SilverlightMapConnector1'); if (withTree) { sh -= 160; } if (!IsIE()) { sourceDiv.style.width = sw + 'px'; sourceDiv.style.height = sh + 'px'; } } var hide = function() { var sourceDiv = $get('sourceDiv'); sourceDiv.style.display = 'none'; } var show = function(srcUri) { var div = $get('sourceDiv'); var iframe = $get('sourceFrame'); iframe.src = srcUri; div.style.display = 'block'; } </script> <script type="text/javascript" src="Silverlight.js"></script> <script type="text/javascript"> function onSilverlightError(sender, args) { var appSource = ""; if (sender != null && sender != 0) { appSource = sender.getHost().Source; } var errorType = args.ErrorType; var iErrorCode = args.ErrorCode; if (errorType == "ImageError" || errorType == "MediaError") { return; } var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n"; errMsg += "Code: " + iErrorCode + " \n"; errMsg += "Category: " + errorType + " \n"; errMsg += "Message: " + args.ErrorMessage + " \n"; if (errorType == "ParserError") { errMsg += "File: " + args.xamlFile + " \n"; errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } else if (errorType == "RuntimeError") { if (args.lineNumber != 0) { errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } errMsg += "MethodName: " + args.methodName + " \n"; } throw new Error(errMsg); } function IsIE() { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { return true; } else //Firefox { if (window.navigator.userAgent.indexOf("Firefox") >= 1) { return false; } } } function resize() { var control = document.getElementById('SilverlightMapConnector1'); control.Content.MainPage.UpdateSize(); } </script> </head> <body onload="updateSize(true)" onresize="resize()"> <form id="form1" runat="server" style="height: 100%"> <table border="0px" width="100%" cellpadding="0px" cellspacing="0px" style="height: 100%;"> <tr> <td style="height: 82px;"> <uc2:Header ID="Header1" runat="server" /> </td> </tr> <tr> <td style="height: 100%; border-top: solid 1px #ece9d8;"> <div id="silverlightControlHost"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <cc1:SilverlightMapConnector ID="SilverlightMapConnector1" runat="server" Windowless="true" Width="100%" Height="100%" Source="~/ClientBin/SilverlightApplication.xap"> </cc1:SilverlightMapConnector> <div id="sourceDiv" style="position: absolute; left: 253px; top: 119px; display: none;"> <iframe id="sourceFrame" width="100%" height="100%"></iframe> </div> </div> </td> </tr> <tr> <td style="height: 50px; border-top: outset 0px #666666; background-color: #ece9d8;"> <uc1:Footer ID="Footer1" runat="server" /> </td> </tr> </table> </form> </body> </html>