User Tools

Site Tools


source_code_wpfdesktopeditionsample_graticulewithgoogleprojection_101005.zip

Source Code WpfDesktopEditionSample GraticuleWithGoogleProjection 101005.zip

App.xaml.cs

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

TestWindow.xaml.cs

using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
namespace GraticuleWithGoogleProjection
{
    /// <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 unit of the map to meters because it is in the Google projection (Spherical Mercator)
            wpfMap1.MapUnit = GeographyUnit.Meter;
            //Loads the Sherical Mercator version of the World Map Kit by setting the projection property
            WorldMapKitWmsWpfOverlay worldMapKitOverlay = new WorldMapKitWmsWpfOverlay();
            worldMapKitOverlay.Projection = WorldMapKitProjection.SphericalMercator;
            wpfMap1.Overlays.Add("WorldOverlay", worldMapKitOverlay);
            //Creates the propection object with the internal and external properties.
            //We need to have Geodetic as internal projection and Google map  as external projection
            //because GraticuleAdornmentLayer is natively in Geodetic and we need to have it displayed
            //with WorldMapKit Spherical Mercartor (Google Map projection).
            ManagedProj4Projection proj4 = new ManagedProj4Projection();
            proj4.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);
            proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();
            proj4.Open();
            //Creates the GraticuleAdornmentLayer with the Projection property.
            //(Other AdormentLayer that would be added to GraticuleAdornmentLayer are:
            //LogoAdormentLayer, ScaleBarAdornmentLayer and ScaleLineAdornmentLayer)
            GraticuleAdornmentLayer graticuleAdornmentLayer = new GraticuleAdornmentLayer();
            graticuleAdornmentLayer.Projection = proj4;
            //Set the styles of the GraticuleAdornmentLayer.
            LineStyle graticuleLineStyle = new LineStyle(new GeoPen(GeoColor.FromArgb(150,GeoColor.StandardColors.Navy),1));
            graticuleAdornmentLayer.GraticuleLineStyle = graticuleLineStyle;
            graticuleAdornmentLayer.GraticuleTextFont = new GeoFont("Times", 12, DrawingFontStyles.Bold);
            //Adds the GraticuleAdormentLayer to the Layers collection of the AdornmentOverlay.
            wpfMap1.AdornmentOverlay.Layers.Add("graticule", graticuleAdornmentLayer);
            wpfMap1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
            wpfMap1.Refresh();
        }
        //Function for getting the extent based on a collection of layers.
        //It gets the overall extent of all the layers.
        private RectangleShape GetFullExtent(GeoCollection<Layer> Layers)
        {
            Collection<BaseShape> rectangleShapes = new Collection<BaseShape>();
            foreach (Layer layer in Layers)
            {
                layer.Open();
                if (layer.HasBoundingBox == true) rectangleShapes.Add(layer.GetBoundingBox());
            }
            return ExtentHelper.GetBoundingBoxOfItems(rectangleShapes);
        }
        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);
            textBox1.Text = "X: " + Math.Round(pointShape.X) +
                          "  Y: " + Math.Round(pointShape.Y);
           }
        }
}
source_code_wpfdesktopeditionsample_graticulewithgoogleprojection_101005.zip.txt · Last modified: 2015/09/09 03:38 by admin