Source Code WpfDesktopEditionSample MultiLineLabeling CS 110316.zip
App.xaml.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace MultiLineLabeling
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
MultiLineTextStyle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
namespace MultiLineLabeling
{
class MultiLineTextStyle : TextStyle
{
public MultiLineTextStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)
: base(textColumnName, textFont, textSolidBrush)
{
base.SplineType = SplineType.StandardSplining;
}
//The strategy for displaying the label at each LineShape making upo the MultilineShape is to treat each LineShape as its own feature.
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
Collection<Feature> featuresForDrawing = new Collection<Feature>();
foreach (Feature feature in features)
{
if (feature.GetWellKnownType() == WellKnownType.Multiline)
{
MultilineShape multiline = (MultilineShape)(feature.GetShape());
foreach (LineShape line in multiline.Lines)
{
Feature newFeature = new Feature(line);
CopyColumnValues(newFeature, feature);
featuresForDrawing.Add(newFeature);
}
}
else
{
featuresForDrawing.Add(feature);
}
}
base.DrawCore(featuresForDrawing, canvas, labelsInThisLayer, labelsInAllLayers);
}
private static void CopyColumnValues(Feature targetFeature, Feature sourceFeature)
{
targetFeature.ColumnValues.Clear();
foreach (KeyValuePair<string, string> item in sourceFeature.ColumnValues)
{
targetFeature.ColumnValues.Add(item.Key, item.Value);
}
}
}
}
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 MultiLineLabeling
{
/// <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(-96.8442,33.115,-96.8114,33.0876);
wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243));
WorldMapKitWmsWpfOverlay worldMapKitWmsWpfOverlay = new WorldMapKitWmsWpfOverlay();
wpfMap1.Overlays.Add(worldMapKitWmsWpfOverlay);
StreamReader streamReader = new StreamReader(@"../../Data/MultilineShape.txt");
String WKT = streamReader.ReadLine();
MultilineShape multilineShape = (MultilineShape)BaseShape.CreateShapeFromWellKnownData(WKT);
Feature feature = new Feature(multilineShape);
feature.ColumnValues.Add("Name", "My Label");
InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
inMemoryFeatureLayer.Open();
inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Name"));
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 4, true);
//Adds the custom TextStyle for displaying the text at each LineShape making up the MultilineShape for the feature to label.
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new MultiLineTextStyle("Name", new GeoFont("Arial", 12), new GeoSolidBrush(GeoColor.StandardColors.Navy));
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
inMemoryFeatureLayer.InternalFeatures.Add(feature);
LayerOverlay dynamicOverlay = new LayerOverlay();
dynamicOverlay.TileType = TileType.SingleTile;
dynamicOverlay.Layers.Add(inMemoryFeatureLayer);
wpfMap1.Overlays.Add(dynamicOverlay);
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);
}
}
}