David & Ted
Thanks for your post and sharing! I appreciate it very much.
I think there are 2 solutions for your requirements.
1) Use Polygons instead of MultiPolygons.
I tried to add the polygons as following instead of adding one MultiPolygon, the overlapping intersections will be painted. And when you want to do Shape.Contains() call, just try to loop each Polygons(polygon1 ~ polygon4) to work around as you said.
//InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
//inMemoryLayer.InternalFeatures.Add("Polygon1", new Feature(polygonShape1));
//inMemoryLayer.InternalFeatures.Add("Polygon2", new Feature(polygonShape2));
//inMemoryLayer.InternalFeatures.Add("Polygon3", new Feature(polygonShape3));
//inMemoryLayer.InternalFeatures.Add("Polygon4", new Feature(polygonShape4));
InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
MultipolygonShape multiPolygonShape = new MultipolygonShape();
multiPolygonShape.Polygons.Add(polygonShape1);
multiPolygonShape.Polygons.Add(polygonShape2);
multiPolygonShape.Polygons.Add(polygonShape3);
multiPolygonShape.Polygons.Add(polygonShape4);
inMemoryLayer.InternalFeatures.Add(new Feature(multiPolygonShape));
2) Override your own InmemoryFeatureLayer and InmemoryFeatureSource to fix the problem of not painting when adding a MultiPolygonShape. Following is some codes you can take a reference.
For the problem of Contains, I think you still need to go around this by loop each PolygonShape.
// Create your own FeatureSource
public class CustomInmemoryFeatureSource : InMemoryFeatureSource
{
private CustomInmemoryFeatureSource()
: this(new FeatureSourceColumn[] { }, new Feature[] { })
{ }
public CustomInmemoryFeatureSource(IEnumerable<FeatureSourceColumn> featureSourceColumns)
: this(featureSourceColumns, new Feature[] { })
{
}
public CustomInmemoryFeatureSource(IEnumerable<FeatureSourceColumn> featureSourceColumns, IEnumerable<Feature> features)
: base(featureSourceColumns,features)
{
}
protected override Collection<Feature> GetFeaturesForDrawingCore(RectangleShape boundingBox, double screenWidth, double screenHeight, IEnumerable<string> returningColumnNames)
{
Collection<Feature> features = base.GetFeaturesForDrawingCore(boundingBox, screenWidth, screenHeight, returningColumnNames);
Collection<Feature> returnFeatures = new Collection<Feature>();
foreach (Feature feature in features)
{
BaseShape baseShape = feature.GetShape();
if (baseShape is MultipolygonShape)
{
MultipolygonShape multiPolygonShape = (MultipolygonShape)baseShape;
foreach (PolygonShape polygonShape in multiPolygonShape.Polygons)
{
Feature polygonFeature = new Feature(polygonShape, feature.ColumnValues);
returnFeatures.Add(polygonFeature);
}
}
else
{
returnFeatures.Add(feature);
}
}
return returnFeatures;
}
}
//Create your own FeatureLayer based on the new FeatureSource
public class CustomInmemoryFeatureLayer : InMemoryFeatureLayer
{
public CustomInmemoryFeatureLayer()
: this(new FeatureSourceColumn[] { }, new Feature[] { })
{ }
public CustomInmemoryFeatureLayer(IEnumerable<FeatureSourceColumn> featureSourceColumns, IEnumerable<Feature> features)
: base()
{
FeatureSource = new CustomInmemoryFeatureSource(featureSourceColumns, features);
}
public CustomInmemoryFeatureLayer(IEnumerable<FeatureSourceColumn> featureSourceColumns, IEnumerable<BaseShape> shapes)
{
Collection<Feature> features = new Collection<Feature>();
foreach (BaseShape shape in shapes)
{
features.Add(new Feature(shape));
}
FeatureSource = new CustomInmemoryFeatureSource(featureSourceColumns, features);
}
}
//Useage
CustomInmemoryFeatureLayer inMemoryLayer = new CustomInmemoryFeatureLayer();
MultipolygonShape multiPolygonShape = new MultipolygonShape();
multiPolygonShape.Polygons.Add(polygonShape1);
multiPolygonShape.Polygons.Add(polygonShape2);
multiPolygonShape.Polygons.Add(polygonShape3);
multiPolygonShape.Polygons.Add(polygonShape4);
inMemoryLayer.InternalFeatures.Add(new Feature(multiPolygonShape));
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.Color = GeoColor.SimpleColors.Red;
inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Any more questions just let me know.
Thanks.
Yale