User Tools

Site Tools


source_code_wpfeditionsample_defaultvaluestyle_cs_110218.zip

Source Code WpfEditionSample DefaultValueStyle CS 110218.zip

App.xaml.cs

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

CustomDefaultValueStyle.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThinkGeo.MapSuite.Core;
namespace DefaultValueStyle
{
    class CustomDefaultValueStyle : ValueStyle
    {
        private Style defaultStyle = null;
        public Style DefaultStyle
        {
            get
            {
                return defaultStyle;
            }
            set
            {
                defaultStyle = value;
            }
        }
        protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            foreach (Feature feature in features)
            {
                string fieldValue = feature.ColumnValues[this.ColumnName].Trim();
                ValueItem valueItem = GetValueItem(fieldValue);
                Feature[] tmpFeatures = new Feature[1] { feature };
                if (valueItem.CustomStyles.Count == 0)
                {
                    if (!string.IsNullOrEmpty(valueItem.Value))
                    {
                        valueItem.DefaultAreaStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                        valueItem.DefaultLineStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                        valueItem.DefaultPointStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                    }
                    else
                    {
                        defaultStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                    }
                    valueItem.DefaultTextStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                }
                else
                {
                    foreach (Style style in valueItem.CustomStyles)
                    {
                        style.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
                    }
                }
            }
        }
        private ValueItem GetValueItem(string columnValue)
        {
            ValueItem result = null;
            foreach (ValueItem valueItem in ValueItems)
            {
                if (string.Compare(columnValue, valueItem.Value, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    result = valueItem;
                    break;
                }
            }
            if (result == null)
            {
                result = new ValueItem();
            }
            return result;
        }
    }
}

TestWindow.xaml.cs

using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
namespace DefaultValueStyle
{
    /// <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(-121, 69, 142, -69);
            wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243));
            WorldMapKitWmsWpfOverlay worldMapKitWmsWpfOverlay = new WorldMapKitWmsWpfOverlay();
            wpfMap1.Overlays.Add(worldMapKitWmsWpfOverlay);
            ShapeFileFeatureLayer worldCapitalsLayer = new ShapeFileFeatureLayer(@"..\..\Data\WorldCapitals.shp");
            worldCapitalsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            // Draw features based on values.
            CustomDefaultValueStyle customDefaultValueStyle = new CustomDefaultValueStyle();
            customDefaultValueStyle.ColumnName = "POP_RANK";
            //Default style if no value found.
            customDefaultValueStyle.DefaultStyle = PointStyles.CreateSimpleSquareStyle(GeoColor.StandardColors.Navy, 4);
            customDefaultValueStyle.ValueItems.Add(new ValueItem("1", PointStyles.Capital1));
            customDefaultValueStyle.ValueItems.Add(new ValueItem("2", PointStyles.Capital2));
            worldCapitalsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(customDefaultValueStyle);
            LayerOverlay worldOverlay = new LayerOverlay();
            worldOverlay.Layers.Add("WorldCaptials", worldCapitalsLayer);
            wpfMap1.Overlays.Add(worldOverlay);
            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_wpfeditionsample_defaultvaluestyle_cs_110218.zip.txt · Last modified: 2015/09/09 03:39 by admin