User Tools

Site Tools


source_code_wpfeditionsample_wrapdatelinemode_cs_110110.zip

Source Code WpfEditionSample WrapDatelineMode CS 110110.zip

App.xaml.cs

 using System;  
 using System.Collections.Generic;  
 using System.Configuration;  
 using System.Data;  
 using System.Linq;  
 using System.Windows;  
 
 namespace WrapDatelineMode  
 {  
     /// <summary>  
     /// Interaction logic for App.xaml  
     /// </summary>  
     public partial class App : Application  
     {  
     }  
 }  
 

TestWindow.xaml.cs

 using System.Windows;  
 using System.Windows.Input;  
 using System.Windows.Media;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace WrapDatelineMode  
 {  
     /// <summary>  
     /// Interaction logic for TestWindow.xaml  
     /// </summary>  
     public partial class TestWindow : Window  
     {  
         public TestWindow()  
         {  
             InitializeComponent();  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             //Sets the correct map unit  
             wpfMap1.MapUnit = GeographyUnit.DecimalDegree;  
             //Sets the map extent in real coordinates.  
             wpfMap1.CurrentExtent = new RectangleShape(-326,82,-58,-91);  
             wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243));  
 
             WorldMapKitWmsWpfOverlay worldMapKitWmsWpfOverlay = new WorldMapKitWmsWpfOverlay();  
             //Sets the WrapDatelineMode to WrapDateline for the overlay.  
             worldMapKitWmsWpfOverlay.WrapDatelineMode = ThinkGeo.MapSuite.WpfDesktopEdition.WrapDatelineMode.WrapDateline;  
             wpfMap1.Overlays.Add(worldMapKitWmsWpfOverlay);  
 
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle  
                                                          (GeoColor.FromArgb(120, GeoColor.StandardColors.Red),12);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             inMemoryFeatureLayer.Open();  
             inMemoryFeatureLayer.InternalFeatures.Add(new Feature(new PointShape(-96.83,33.08)));  
             inMemoryFeatureLayer.InternalFeatures.Add(new Feature(new PointShape(104.07,30.63)));  
             inMemoryFeatureLayer.Close();  
 
             LayerOverlay layerOverlay = new LayerOverlay();  
             //Sets the WrapDatelineMode to WrapDateline for the overlay.  
             layerOverlay.WrapDatelineMode = ThinkGeo.MapSuite.WpfDesktopEdition.WrapDatelineMode.WrapDateline;  
             layerOverlay.Layers.Add(inMemoryFeatureLayer);  
             wpfMap1.Overlays.Add(layerOverlay);  
 
             wpfMap1.Refresh();  
         }  
 
 
         private void wpfMap1_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Gets the PointShape in world coordinates from screen coordinates.  
             Point point = e.MouseDevice.GetPosition(null);  
 
             ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y);  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, screenPointF, (float)wpfMap1.Width, (float)wpfMap1.Height);  
 
             //Uses the WrapDatelineProjection to get the proper decimal degree value on the virtual maps to the right and left of the central map.  
             WrapDatelineProjection wrapDatelineProjection = new WrapDatelineProjection();  
             //Sets the HalfExtentWidth of the wrapdateline overlay we want to apply the projection on.  
             //Here it is 180 because, the full extent width is 360.  
             wrapDatelineProjection.HalfExtentWidth = 180;  
 
             wrapDatelineProjection.Open();  
             Vertex projVertex = wrapDatelineProjection.ConvertToExternalProjection(pointShape.X, pointShape.Y);  
             wrapDatelineProjection.Close();  
 
             //Shows the real coordinates.  
             textBox1.Text = "real X: " + string.Format("{0:0.00}",System.Math.Round(pointShape.X, 2)) +  
                          "  real Y: " + string.Format("{0:0.00}",System.Math.Round(pointShape.Y, 2));  
             //Shows the decimal degrees after the WrapDatelineProjection  
             textBox2.Text = "Decimal Degree X: " + string.Format("{0:0.00}",System.Math.Round(projVertex.X, 2)) +  
                          " Decimal Degree Y: " + string.Format("{0:0.00}",System.Math.Round(projVertex.Y, 2));  
             //Shows the Decimal Minutes Seconds format after the WrapDatelineProjection  
             textBox3.Text = "Long.: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(projVertex.X) +  
                           "  Lat.: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(projVertex.Y);  
 
             }  
     }  
 }  
 

WrapDatelineProjection.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace WrapDatelineMode  
 {  
     class WrapDatelineProjection : Projection, IDisposable  
     {  
         private double nHalfExtentWidth;  
         private double [] an = new double[100];  
         private double[] an_minus = new double[100];  
 
         //Property for half the extent of the central map.  
         //For example:  
         //If the map is in decimal degree, the value will be 180 (worldMapKitWmsWpfOverlay.GetBoundingBox().Width / 2).  
         //If the map is using Google map, the value will be 14000955.5 (googleMapsOverlay.GetBoundingBox().Width / 2)  
         public double HalfExtentWidth  
         {  
             get { return nHalfExtentWidth; }  
             set  
             {  
                 nHalfExtentWidth = value;  
 
                 double sum = 0;  
                 for (int i = 0; i <= an.Length - 1; i += 1)  
                 {  
                     an[i] = nHalfExtentWidth + sum;  
                     sum = sum + (nHalfExtentWidth * 2);  
                 }  
 
                 sum = 0;  
                 for (int i = 0; i <= an_minus.Length - 1; i += 1)  
                 {  
                     an_minus[i] = -nHalfExtentWidth - sum;  
                     sum = sum + (nHalfExtentWidth * 2);  
                 }  
             }  
         }  
 
         protected override Vertex[] ConvertToExternalProjectionCore(double[] x, double[] y)  
         {  
             Vertex[] vertices = new Vertex[x.Length];  
 
             for (int i = 0; i < vertices.Length; i++)  
             {  
                 if ((x[i] > HalfExtentWidth)|| (x[i] < (-HalfExtentWidth)))  
                 {  
                 double realx = GetAp(x[i]);  
                 vertices[i] = new Vertex(realx, y[i]);  
                 }  
                 else  
                 {  
                     vertices[i] = new Vertex(x[i], y[i]);  
                 }  
             }  
             return vertices;  
         }  
 
         private double GetAp(double Xp)  
         {  
             double result = 0;  
             if (Xp > 0)  
             {  
                 for (int i = 0; i < an.Length - 2; i++)  
                 {  
                     if ((Xp >= an[i]) && (Xp < an[i|+ 1]))  
                     {  
                         result = Xp - (an[i] + HalfExtentWidth);  
                         break;  
                     }  
                 }  
             }  
             else  
             {  
                 for (int i = 0; i < an_minus.Length - 2; i++)  
                 {  
                     if ((Xp <= an_minus[i]) && (Xp > an_minus[i|+ 1]))  
                     {  
                         result = Xp + (an[i] + HalfExtentWidth);  
                         break;  
                     }  
                 }  
             }  
             return result;  
         }  
 
         protected override Vertex[] ConvertToInternalProjectionCore(double[] x, double[] y)  
         {  
             throw new NotImplementedException();  
         }  
 
         public void Dispose()  
         {  
             Dispose(true);  
             GC.SuppressFinalize(this);  
         }  
 
         private void Dispose(bool disposing)  
         {  
             Close();  
         }  
     }  
 }  
 
source_code_wpfeditionsample_wrapdatelinemode_cs_110110.zip.txt · Last modified: 2015/09/08 05:24 by admin