====== Source Code ServicesEditionSample MultiColumnLabeling CS 090922.zip ======
====Program.cs====
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MultiColumnLabeling
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
}
====TestForm.cs====
using System;
using System.Drawing;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
namespace MultiColumnLabeling
{
public partial class TestForm : Form
{
private MapEngine mapEngine = new MapEngine();
private Bitmap bitmap = null;
ShapeFileFeatureLayer worldLayer = null;
ShapeFileFeatureLayer volcanoLayer = null;
public TestForm()
{
InitializeComponent();
}
private void TestForm_Load(object sender, EventArgs e)
{
// Set the full extent and the background color
mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-133.30,56.94,-129.66,54.50), Map.Width, Map.Height);
mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
// Add the static layers to the MapEngine
worldLayer = new ShapeFileFeatureLayer(@"..\..\Data\Countries02.shp", ShapeFileReadWriteMode.ReadOnly);
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapEngine.StaticLayers.Add("WorldLayer", worldLayer);
volcanoLayer = new ShapeFileFeatureLayer(@"..\..\Data\volcanoes.shp", ShapeFileReadWriteMode.ReadOnly);
volcanoLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleTriangleStyle(GeoColor.StandardColors.Orange, 16, GeoColor.StandardColors.Black);
volcanoLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapEngine.StaticLayers.Add("volcanoLayer", volcanoLayer);
//Adds the volcanoes shapefile for labeling the columns Name, Elevation, Type and State.
ShapeFileFeatureLayer labelVolcanoLayer = new ShapeFileFeatureLayer(@"..\..\Data\volcanoes.shp", ShapeFileReadWriteMode.ReadOnly);
//TextStyle for the first line, Name and Elevation.
labelVolcanoLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add (TextStyles.CreateSimpleTextStyle("MergedColumn", "Arial", 8,
DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 10, 12));
//TextStyle for the second line, Type and State.
labelVolcanoLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("MergedColumn2", "Arial", 8,
DrawingFontStyles.Italic, GeoColor.StandardColors.Black, 10, 0));
labelVolcanoLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapEngine.StaticLayers.Add("labelVolcanoLayer", labelVolcanoLayer);
//Hooks up the event for CustomColumnFetch used to label the different columns.
((ShapeFileFeatureSource)labelVolcanoLayer.FeatureSource).CustomColumnFetch
+= new EventHandler(labelVolcanoLayer_CustomColumnFetch);
DrawImage();
}
//Event used for labeling based on the different columns.
void labelVolcanoLayer_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
{
//For the first TextStyle.
if (e.ColumnName == "MergedColumn")
{
ShapeFileFeatureLayer labelVolcanoLayer = (ShapeFileFeatureLayer)mapEngine.StaticLayers["labelVolcanoLayer"];
Feature currentFeature = labelVolcanoLayer.QueryTools.GetFeatureById(e.Id, ReturningColumnsType.AllColumns);
e.ColumnValue = currentFeature.ColumnValues["Name"] + "," + currentFeature.ColumnValues["Elevation"] + "m";
}
//For the second TextStyle.
else if (e.ColumnName == "MergedColumn2")
{
ShapeFileFeatureLayer labelVolcanoLayer = (ShapeFileFeatureLayer)mapEngine.StaticLayers["labelVolcanoLayer"];
Feature currentFeature = labelVolcanoLayer.QueryTools.GetFeatureById(e.Id, ReturningColumnsType.AllColumns);
e.ColumnValue = currentFeature.ColumnValues["Type"] + "(" + currentFeature.ColumnValues["State"] + ")";
}
}
private void DrawImage()
{
if (bitmap != null) { bitmap.Dispose(); }
bitmap = new Bitmap(Map.Width, Map.Height);
mapEngine.OpenAllLayers();
mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);
mapEngine.CloseAllLayers();
Map.Image = bitmap;
}
private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
switch (e.Button.Tag.ToString())
{
case "Zoom In":
mapEngine.CurrentExtent.ScaleDown(50);
break;
case "Zoom Out":
mapEngine.CurrentExtent.ScaleUp(50);
break;
case "Full Extent":
mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);
break;
case "Pan Left":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);
break;
case "Pan Right":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);
break;
case "Pan Up":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);
break;
case "Pan Down":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);
break;
default:
break;
}
DrawImage();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}