I'm currently using MapSuite to display data read in from six shapefiles, including a "road" layer. Users are able to select roads in a variety of ways, once selected these are highlighted by adding them to an InMemoryFeatureLayer.
One way of selecting roads is by using the EditOverlay to capture drawn shapes, then using this to find matching entries in the roads layer and drawing them.
protected void OnAddPolygon(object sender, ImageClickEventArgs e)
{
this.LinkSetMap.EditOverlay.TrackMode = TrackMode.Polygon;
}
protected void OnTrackShapeFinished(object sender, EventArgs e)
{
LayerOverlay roadsOverlay =
(LayerOverlay)this.LinkSetMap.CustomOverlays["Roads"];
ShapeFileFeatureLayer roadsLayer =
ShapeFileFeatureLayer)roadsOverlay.Layers["Roads"];
roadsLayer.Open();
foreach (Feature feature in this.LinkSetMap.EditOverlay.Features)
{
Collection<Feature> spatialQueryResults =
roadsLayer.QueryTools.GetFeaturesWithin(feature, new string[0]);
this.AddFeaturesToSelection(spatialQueryResults);
roadsLayer.Close();
this.LinkSetMap.EditOverlay.TrackMode = TrackMode.None;
this.LinkSetMap.EditOverlay.Features.Clear();
}
}
private void AddFeaturesToSelection(Collection<Feature> features)
{
LayerOverlay staticOverlay =
(LayerOverlay)this.LinkSetMap.CustomOverlays["StaticOverlay"];
InMemoryFeatureLayer selectedLinksLayer =
(InMemoryFeatureLayer)staticOverlay.Layers["SelectedLinksLayer"];
selectedLinksLayer.Open();
foreach (Feature linkFeature in features)
{
if (!selectedLinksLayer.InternalFeatures.Contains(linkFeature.Id))
{
selectedLinksLayer.InternalFeatures.Add(linkFeature.Id, linkFeature);
}
}
selectedLinksLayer.Close();
this.ZoomMapToSelection();
staticOverlay.Redraw();
}
private void ZoomMapToSelection()
{
LayerOverlay staticOverlay =
(LayerOverlay)this.LinkSetMap.CustomOverlays["StaticOverlay"];
InMemoryFeatureLayer selectedLinksLayer =
(InMemoryFeatureLayer)staticOverlay.Layers["SelectedLinksLayer"];
if (selectedLinksLayer.InternalFeatures.Count > 0)
{
this.LinkSetMap.CurrentExtent = staticOverlay.GetBoundingBox();
}
else
{
this.LinkSetMap.CurrentExtent = defaultExtents;
}
staticOverlay.Redraw();
}
This process works fine. When I click on the "draw" button, the map is switched to edit mode and I draw a polygon. When complete, the roads which are inside the drawn shape are located and added to the InMemory layer, which is zoomed and redrawn correctly.
The problem I am having is when I try to add roads which don't involve the editing layer. In this case I have a list of counties which the user selects one then clicks on an add button:
protected void OnAddCounty(object sender, EventArgs e)
{
string selectedCounty = this.CountyDropdown.SelectedValue;
LayerOverlay roadsOverlay =
(LayerOverlay)this.LinkSetMap.CustomOverlays["Roads"];
ShapeFileFeatureLayer roadsLayer =
(ShapeFileFeatureLayer)roadsOverlay.Layers["Roads"];
roadsLayer.Open();
Collection<Feature> featuresInCounty =
roadsLayer.QueryTools.GetFeaturesByColumnValue("County", selectedCounty);
roadsLayer.Close();
this.AddFeaturesToSelection(featuresInCounty);
this.ZoomMapToSelection();
}
When I run this code, the data location process is performed correctly, and a collection of features is retrieved as expected, however upon adding this data to the map no redraw is triggered, nor is the current extent updated. If I zoom the map in or out, then the updated layer is redrawn correctly. What am I missing? I'm guessing that the first case is only working because we're actively switching in and out of edit mode.