Ryan, you are welcome.
Try the following update one:
public class StyledFeatureLayer : FeatureLayer
{
private Dictionary<Feature, Style> features;
public StyledFeatureLayer()
:this(new Dictionary<Feature,Style>())
{ }
public StyledFeatureLayer(Dictionary<Feature, Style> features)
:base()
{
this.features = features;
FeatureSource = new InMemoryFeatureSource(new Collection<FeatureSourceColumn>(), features.Keys);
}
public Dictionary<Feature, Style> Features
{
get { return features; }
}
protected override bool IsOpenCore
{
get
{
return true;
}
}
protected override void SetupToolsCore()
{
base.SetupToolsCore();
FeatureSource = new InMemoryFeatureSource(new Collection<FeatureSourceColumn>(), features.Keys);
}
protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
{
Collection<SimpleCandidate> labelInThisLayer = new Collection<SimpleCandidate>();
Collection<SimpleCandidate> labelInAllLayers = new Collection<SimpleCandidate>();
foreach (Feature feature in features.Keys)
{
Style style = features[feature];
style.Draw(new Feature[] { feature }, canvas, labelInThisLayer, labelInAllLayers);
}
}
}
Test codes:
private void Form1_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.Meter;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
winformsMap1.ZoomLevelSnapping = ZoomLevelSnappingMode.Default;
StyledFeatureLayer styledFeatureLayer = new StyledFeatureLayer();
BaseShape rectangle1 = new RectangleShape(0, 45, 45, 0);
Feature feature1 = new Feature(rectangle1);
BaseShape rectangle2 = new EllipseShape(new PointShape(45, 45), 5);
Feature feature2 = new Feature(rectangle2);
LineShape line1 = new LineShape();
line1.Vertices.Add(new Vertex(0, 0));
line1.Vertices.Add(new Vertex(45, 0));
line1.Vertices.Add(new Vertex(0, 45));
Feature feature3 = new Feature(line1);
styledFeatureLayer.Features.Add(feature1, AreaStyles.Country1);
styledFeatureLayer.Features.Add(feature2, AreaStyles.Grass1);
styledFeatureLayer.Features.Add(feature3, LineStyles.Canal1);
InMemoryFeatureLayer rectangleLayer = new InMemoryFeatureLayer();
rectangleLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(new GeoColor(50, 100, 100, 200)));
rectangleLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.DarkBlue;
rectangleLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
rectangleLayer.InternalFeatures.Add("Rectangle", new Feature("POLYGON((-100 -20,-100 200,50 200,50 -20,-100 -20))", "Rectangle"));
InMemoryFeatureLayer spatialQueryResultLayer = new InMemoryFeatureLayer();
spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(200, GeoColor.SimpleColors.PastelRed)));
spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Red;
spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldLayer", styledFeatureLayer);
staticOverlay.Layers.Add("RectangleLayer", rectangleLayer);
LayerOverlay spatialQueryResultOverlay = new LayerOverlay();
spatialQueryResultOverlay.Layers.Add("SpatialQueryResultLayer", spatialQueryResultLayer);
winformsMap1.Overlays.Add(staticOverlay);
winformsMap1.Overlays.Add("SpatialQueryResultOverlay", spatialQueryResultOverlay);
winformsMap1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
StyledFeatureLayer worldLayer = (StyledFeatureLayer)winformsMap1.FindFeatureLayer("WorldLayer");
InMemoryFeatureLayer rectangleLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("RectangleLayer");
InMemoryFeatureLayer spatialQueryResultLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SpatialQueryResultLayer");
Feature rectangleFeature = rectangleLayer.InternalFeatures["Rectangle"];
Collection<Feature> spatialQueryResults;
worldLayer.Open();
string text = "Intersecting";
switch (text)
{
case "Within":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesWithin(rectangleFeature, new string[0]);
break;
case "Containing":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesContaining(rectangleFeature, new string[0]);
break;
case "Disjointed":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesDisjointed(rectangleFeature, new string[0]);
break;
case "Intersecting":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesIntersecting(rectangleFeature, new string[0]);
break;
case "Overlapping":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesOverlapping(rectangleFeature, new string[0]);
break;
case "TopologicalEqual":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesTopologicalEqual(rectangleFeature, new string[0]);
break;
case "Touching":
spatialQueryResults = worldLayer.QueryTools.GetFeaturesTouching(rectangleFeature, new string[0]);
break;
default:
spatialQueryResults = worldLayer.QueryTools.GetFeaturesWithin(rectangleFeature, new string[0]);
break;
}
worldLayer.Close();
winformsMap1.Overlays["SpatialQueryResultOverlay"].Lock.EnterWriteLock();
try
{
spatialQueryResultLayer.InternalFeatures.Clear();
foreach (Feature feature in spatialQueryResults)
{
spatialQueryResultLayer.InternalFeatures.Add(feature.Id, feature);
}
}
finally
{
winformsMap1.Overlays["SpatialQueryResultOverlay"].Lock.ExitWriteLock();
}
winformsMap1.Refresh();
}
Hope this can gives you any help. Let me know if any more queries.
Thanks.
Yale