User Tools

Site Tools


source_code_wpfdesktopeditionsample_draggablelabels_cs_101013.zip

Source Code WpfDesktopEditionSample DraggableLabels CS 101013.zip

App.xaml.cs

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

TestWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
namespace DraggableLabels
{
    /// <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 and the extent of the map.
            wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
            wpfMap1.CurrentExtent = new RectangleShape(-128,51,-65,19);
            wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243));
           //Adds the countries shapefile
            ShapeFileFeatureLayer shapeFileFeatureLayer1 = new ShapeFileFeatureLayer(@"..\..\Data\Countries02.shp");
            shapeFileFeatureLayer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            shapeFileFeatureLayer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            //Adds the Shapefile MajorCities as a ShapeFileFeatureLayer between zoom levels 01 and 04.
            ShapeFileFeatureLayer shapeFileFeatureLayer2 = new ShapeFileFeatureLayer(@"..\..\Data\MajorCities.shp");
            shapeFileFeatureLayer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Turquoise, 8, GeoColor.StandardColors.Black);
            shapeFileFeatureLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            //Adds the ShapeFileFeatureLayer to an LayerOverlay.
            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.Layers.Add(shapeFileFeatureLayer1);
            layerOverlay.Layers.Add(shapeFileFeatureLayer2);
            wpfMap1.Overlays.Add(layerOverlay);
            //SimpleMarkerOverlay for dragging labels.
            SimpleMarkerOverlay simpleMarkerOverlay = new SimpleMarkerOverlay();
            simpleMarkerOverlay.DragMode = DragMode.Drag;
            wpfMap1.Overlays.Add("SimpleMarkerOverlay", simpleMarkerOverlay);
            //Gets all the features of the cities shapefile and loops thru them to add the label as a Marker of the SimpleMarkerOverlay.
            shapeFileFeatureLayer2.Open();
            Collection<Feature> features = shapeFileFeatureLayer2.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
            shapeFileFeatureLayer2.Close();
            foreach (Feature feature in features)
            {
                PointShape pointShape = (PointShape)feature.GetShape();
                Marker marker = new Marker(pointShape.X, pointShape.Y);
                marker.ImageSource = null;
                marker.Content = feature.ColumnValues["AREANAME"];
                marker.FontSize = 14;
                marker.FontStyle = FontStyles.Oblique;
                simpleMarkerOverlay.Markers.Add(marker);
            }
            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);
            textBox1.Text = "X: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.X) +
                          "  Y: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.Y);
           }
    }
}
source_code_wpfdesktopeditionsample_draggablelabels_cs_101013.zip.txt · Last modified: 2015/09/09 03:38 by admin