Hi guys,
I'm trying to remove lines from a multilineshape (starting from the end of the multilineshape and until it crosses the passed in point) and refresh the line layer overlay and the map. The multilineshape is a feature in the layers collection of the line layer overlay. My code is as follows:
public void RemoveLinesFromMultilineShapeLine(string lineLayerKey, string lineKey, Position intersectingPosition)
{
LayerOverlay lineLayerOverlay = (LayerOverlay)Map1.Overlays[DEFAULT_LINE_LAYER_OVERLAY_KEY];
InMemoryFeatureLayer lineLayer = null;
if (lineLayerOverlay.Layers.Contains(lineLayerKey))
{
if (lineLayerOverlay.Layers[lineLayerKey] is InMemoryFeatureLayer)
{
lineLayer = (InMemoryFeatureLayer)lineLayerOverlay.Layers[lineLayerKey];
if (lineLayer.InternalFeatures.Contains(lineKey))
{
MultilineShape existingMultiLineShape = (MultilineShape)lineLayer.InternalFeatures[lineKey].GetShape();
int index = existingMultiLineShape.Lines.Count - 1;
RectangleShape rectShape = GenerateMiniBoundingBox(new PointShape(intersectingPosition.Longitude, intersectingPosition.Latitude));
while (!existingMultiLineShape.Lines[index].Crosses(rectShape))
{
existingMultiLineShape.Lines.RemoveAt(index);
index--;
};
existingMultiLineShape.Lines.RemoveAt(index);
lineLayer.InternalFeatures[lineKey] = new Feature(existingMultiLineShape);
lineLayerOverlay.Refresh();
Map1.Refresh();
}
}
else
{
throw new Exception("Another type of overlay with the same key already exists.");
}
}
}
However, I get the following error when I refresh the line layer overlay using lineLayerOverlay.Refresh():
The given key was not present in the dictionary.
Stack trace:
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ThinkGeo.MapSuite.SilverlightCore.InMemoryFeatureSource.GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox, IEnumerable`1 returningColumnNames)
at ThinkGeo.MapSuite.SilverlightCore.FeatureSource.GetFeaturesForDrawingCore(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)
at ThinkGeo.MapSuite.SilverlightCore.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)
at ThinkGeo.MapSuite.SilverlightCore.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.SilverlightCore.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.SilverlightEdition.LayerOverlay.DrawCore(RectangleShape worldExtent)
at ThinkGeo.MapSuite.SilverlightEdition.Overlay.Draw(RectangleShape worldExtent, OverlayDrawType overlayDrawType)
at ThinkGeo.MapSuite.SilverlightEdition.Overlay.Refresh()
at MapControl.RemoveLinesFromMultilineShape(String lineLayerKey, String lineKey, Position intersectingPosition)
What am I doing wrong?
Thanks,
Nirish