Hi,
I was wondering if I can create my own Overlay type by inheriting from the Overlay class? I have built support for my own data type and would like to make a custom Overlay to match this.
Do you have any samples of this?
Thanks!
Hi,
I was wondering if I can create my own Overlay type by inheriting from the Overlay class? I have built support for my own data type and would like to make a custom Overlay to match this.
Do you have any samples of this?
Thanks!
Clint,
Sure you can. Here is a simple sample how to create my own Overlay. This Overlay will draw a point and a line on the map.
public class MyOverlay: Overlay
{
private Collection<Feature> features;
public MyOverlay()
:base()
{
features = new Collection<Feature>();
}
public Collection<Feature> InmemoryFeatures
{
get
{
return features;
}
}
protected override void DrawCore(GeoCanvas canvas)
{
PointStyle pointStyle = PointStyles.Capital1;
LineStyle lineShape = LineStyles.Canal1;
pointStyle.Draw(features, canvas, new Collection<SimpleCandidate>(), new Collection<SimpleCandidate>());
lineShape.Draw(features, canvas, new Collection<SimpleCandidate>(), new Collection<SimpleCandidate>());
}
}
Here is how to use it as well as the result.
private void DisplayMap_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.Layers.Add("WorldLayer", worldLayer);
//winformsMap1.StaticOverlay.Layers.Add("WorldLayer", worldLayer);
winformsMap1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);
LineShape lineShape = new LineShape();
lineShape.Vertices.Add(new Vertex(winformsMap1.CurrentExtent.UpperLeftPoint.X, winformsMap1.CurrentExtent.UpperLeftPoint.Y));
lineShape.Vertices.Add(new Vertex(winformsMap1.CurrentExtent.LowerRightPoint.X, winformsMap1.CurrentExtent.LowerRightPoint.Y));
MyOverlay myOverlay = new MyOverlay();
myOverlay.InmemoryFeatures.Add(new Feature( new PointShape(-128.0, 108)));
myOverlay.InmemoryFeatures.Add(new Feature(lineShape));
winformsMap1.CustomOverlays.Add(layerOverlay);
winformsMap1.CustomOverlays.Add(myOverlay);
winformsMap1.Refresh();
}
Thanks,
Ben