Ryan & Ted,
I think probably I understood wrong way what kinds of requirements need to be.
But if we implement all kinds of Area type shape tick the same way, the Polygon and RectangShape seems OK while the Ellipse and Circle seems too clustered(if you don’t care, I think have your own custom area style is a very good solution) .
Below is the custom style codes, you can try it with the latest build Desktop 3.0.307 RC.
public class CustomAreaStyle : AreaStyle
{
public CustomAreaStyle()
: this(new GeoPen(), new GeoSolidBrush(), PenBrushDrawingOrder.BrushFirst)
{
}
public CustomAreaStyle(GeoSolidBrush fillSolidBrush)
: this(new GeoPen(), fillSolidBrush, PenBrushDrawingOrder.BrushFirst)
{
}
public CustomAreaStyle(GeoPen outlinePen)
: this(outlinePen, new GeoSolidBrush(), PenBrushDrawingOrder.BrushFirst)
{
}
public CustomAreaStyle(GeoPen outlinePen, GeoSolidBrush fillSolidBrush)
: this(outlinePen, fillSolidBrush, PenBrushDrawingOrder.BrushFirst)
{
}
public CustomAreaStyle(GeoPen outlinePen, GeoSolidBrush fillSolidBrush, PenBrushDrawingOrder penBrushDrawingOrder)
: base(outlinePen, fillSolidBrush, penBrushDrawingOrder)
{ }
protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
base.DrawCore(features, canvas, labelsInThisLayer, labelsInAllLayers);
LineStyle lineStyle = new LineStyle(OutlinePen);
Collection<Feature> lineFeatures = new Collection<Feature>();
foreach (Feature feature in features)
{
AreaBaseShape baseShape = (AreaBaseShape)feature.GetShape();
Collection<Feature> lineFeaturesForThisFeature = GetLineFeatures(baseShape);
foreach (Feature lineFeature in lineFeaturesForThisFeature)
{
lineFeatures.Add(lineFeature);
}
}
lineStyle.Draw(lineFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
}
private Collection<Feature> GetLineFeatures(AreaBaseShape areaShape)
{
Collection<Feature> returnFeatures = new Collection<Feature>();
if (areaShape is PolygonShape)
{
PolygonShape polygonShape = (PolygonShape)areaShape;
returnFeatures = GetLineFeaturesForPolygon(polygonShape);
}
return returnFeatures;
}
private Collection<Feature> GetLineFeaturesForPolygon(PolygonShape polygonShape)
{
Collection<Feature> returnFeatures = new Collection<Feature>();
double length = 0.5;
float percentage = 5f;
RingShape ringShape = polygonShape.OuterRing;
for (int i = 0; i < ringShape.Vertices.Count - 1; i++)
{
Vertex vertex1 = ringShape.Vertices[i];
Vertex vertex2 = ringShape.Vertices[i + 1];
for (int k = 1; k < 20; k++)
{
PointShape rootPoint = new LineShape(new Vertex[] { vertex1, vertex2 }).GetPointOnALine(StartingPoint.FirstPoint, percentage * k);
double middleX = rootPoint.X;
double middleY = rootPoint.Y;
double angle = Math.Atan((vertex1.Y - vertex2.Y) / (vertex1.X - vertex2.X));
double x = 0;
double y = 0;
if (vertex1.X > vertex2.X)
{
x = middleX + Math.Sin(angle) * length;
y = middleY - Math.Cos(angle) * length;
}
else
{
x = middleX - Math.Sin(angle) * length;
y = middleY + Math.Cos(angle) * length;
}
if (vertex1.Y == vertex2.Y)
{
if (vertex1.X > vertex2.X)
{
x = middleX - Math.Sin(angle) * length;
y = middleY + Math.Cos(angle) * length;
}
else
{
x = middleX + Math.Sin(angle) * length;
y = middleY - Math.Cos(angle) * length;
}
}
LineShape line = new LineShape(new Vertex[] { new Vertex(middleX, middleY), new Vertex(x, y) });
returnFeatures.Add(new Feature(line));
}
}
return returnFeatures;
}
}
Test codes as below:
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.CurrentExtent = new RectangleShape(0, 100, 100, 0);
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);
RectangleShape rectangleShape = new RectangleShape(65, 30, 95, 15);
EllipseShape ellipseShape = new EllipseShape(new PointShape(30, 30), 20, 5);
EllipseShape circleShape = new EllipseShape(new PointShape(60, 10), 10, 10);
PolygonShape polygonShape = (PolygonShape)BaseShape.CreateShapeFromWellKnownData("POLYGON((10 60,40 70,30 85, 10 60))");
InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
inMemoryLayer.InternalFeatures.Add("Polygon", new Feature(polygonShape));
inMemoryLayer.InternalFeatures.Add("Rectangle", new Feature(rectangleShape));
inMemoryLayer.InternalFeatures.Add("Ellipse", new Feature(ellipseShape));
inMemoryLayer.InternalFeatures.Add("Circle", new Feature(circleShape));
CustomAreaStyle curstomerAreaStyle = new CustomAreaStyle(new GeoPen( GeoColor.SimpleColors.Red,1), new GeoSolidBrush( GeoColor.SimpleColors.LightBlue), PenBrushDrawingOrder.BrushFirst);
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = curstomerAreaStyle;
inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
winformsMap1.Overlays.Add(staticOverlay);
winformsMap1.Refresh();
Any more questions just let me know.
Thanks.
Yale