using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using ThinkGeo.MapSuite.Core;
namespace FeatureCentricStyle
{
class FeatureCentricAreaStyle : AreaStyle
{
private Feature selectedFeature;
private AreaStyle withinRangeStyle;
private AreaStyle outsideRangeStyle;
private AreaStyle selectedStyle;
private string columnName;
private double range;
public FeatureCentricAreaStyle()
{
this.range = 100000;
this.columnName = "Pop_cntry";
this.selectedStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Red));
this.withinRangeStyle =new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Yellow));
this.outsideRangeStyle = new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow));
}
public FeatureCentricAreaStyle(double Range, string ColumnName, AreaStyle SelectedStyle, AreaStyle WithinRangeStyle, AreaStyle OutsideRangeStyle)
{
this.range = Range;
this.columnName = ColumnName;
this.selectedStyle = SelectedStyle;
this.withinRangeStyle = WithinRangeStyle;
this.outsideRangeStyle = OutsideRangeStyle;
}
public Feature SelectedFeature
{
get { return selectedFeature; }
set { selectedFeature = value; }
}
public double Range
{
get { return range; }
set { range = value; }
}
public string ColumnName
{
get { return columnName; }
set { columnName = value; }
}
public AreaStyle SelectedStyle
{
get { return selectedStyle; }
set { selectedStyle = value; }
}
public AreaStyle WithinRangeStyle
{
get { return withinRangeStyle; }
set { withinRangeStyle = value; }
}
public AreaStyle OutsideRangeStyle
{
get { return outsideRangeStyle; }
set { outsideRangeStyle = value; }
}
protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
Collection<Feature> selectedFeatures = new Collection<Feature>();
Collection<Feature> featuresWithinRange = new Collection<Feature>();
Collection<Feature> featuresOutsideRange = new Collection<Feature>();
selectedFeatures.Add(selectedFeature);
double currentValue = System.Convert.ToDouble(selectedFeature.ColumnValues[columnName]);
double lowEnd = currentValue - range;
double highEnd = currentValue + range;
foreach (Feature feature in features)
{
if (feature.Id != selectedFeature.Id)
{
double value = System.Convert.ToDouble(feature.ColumnValues[columnName]);
if (value >= lowEnd && value <= highEnd)
{
featuresWithinRange.Add(feature);
}
else
{
featuresOutsideRange.Add(feature);
}
}
}
withinRangeStyle.Draw(featuresWithinRange, canvas, labelsInThisLayer, labelsInAllLayers);
outsideRangeStyle.Draw(featuresOutsideRange, canvas, labelsInThisLayer, labelsInAllLayers);
selectedStyle.Draw(selectedFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
}
protected override Collection<string> GetRequiredColumnNamesCore()
{
Collection<string> requiredColumns = new Collection<string>();
requiredColumns.Add(columnName);
return requiredColumns;
}
}
}
using System;
using System.Drawing;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
namespace FeatureCentricStyle
{
public partial class TestForm : Form
{
private MapEngine mapEngine = new MapEngine();
private Bitmap bitmap = null;
private FeatureCentricAreaStyle featureCentricAreaStyle;
public TestForm()
{
InitializeComponent();
}
private void TestForm_Load(object sender, EventArgs e)
{
mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.DeepOcean);
ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp");
ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\countries02.shp", BuildIndexMode.DoNotRebuild);
AreaStyle selectedAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Red));
AreaStyle withinRangeAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Yellow));
AreaStyle outsideRangeAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow));
featureCentricAreaStyle = new FeatureCentricAreaStyle(10000000, "Pop_cntry", selectedAreaStyle, withinRangeAreaStyle, outsideRangeAreaStyle);
Layer1.Open();
Feature selectedFeature = Layer1.QueryTools.GetFeatureById("15", ReturningColumnsType.AllColumns);
featureCentricAreaStyle.SelectedFeature = selectedFeature;
Layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(featureCentricAreaStyle);
Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapEngine.StaticLayers.Add("WorldLayer", Layer1);
mapEngine.CurrentExtent = Layer1.GetBoundingBox();
Layer1.Close();
DrawImage();
}
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 Map_MouseDown(object sender, MouseEventArgs e)
{
PointShape worldPoint = ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, e.X, e.Y, Map.Width, Map.Height);
FeatureLayer worldLayer = mapEngine.FindStaticFeatureLayer("WorldLayer");
worldLayer.Open();
Collection<Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(worldPoint, ReturningColumnsType.AllColumns); //new string[1] { "CNTRY_NAME" });
worldLayer.Close();
if (selectedFeatures.Count > 0)
{
featureCentricAreaStyle.SelectedFeature = selectedFeatures[0];
DrawImage();
}
}
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();
}
}
}