I have a TreeView on my form that lists InMemoryFeatureLayer names for the user to choose from. When they pick one and then click the edit button, I am trying to move everything on that selectedLayer to the EditOverlay and clear out the selectedLayer.
I seem to be moving the features to the EditOverlay just fine, but the original stays on the screen.
Similarly, when I exit edit mode, I copy the features back to the selectedLayer and clear out the EditOverlay. In this case, the shape does disappear from the screen, but that original shape is still sitting there in the old position like some sort of toad. If I enter edit mode again without changing layers, the shape re-appears (on the EditOverlay) in the correct position (where it was when I exited edit mode last) so I must be saving the features to a good place.
What am I doing wrong here?
Dave
Note: in my code, there is only one layer per overlay and the layer name, layer key and overlay key are all the same string value
//entering edit mode //move everything in the layer selected in Legend to the EditOverlay InMemoryFeatureLayer selectedLayer = GetSelectedLayer(); foreach (Feature feature in selectedLayer.InternalFeatures) { Map.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature); }
I made a sample according to the description and the code snippets you provided, it worked perfect, please take a look at it and let me know if I am misunderstand anything.
One thing I just want to remind is that we do not need to call the Refresh twice every time, otherwise it will draw twiceJ.
Any more questions please feel free to let me know.
No, you understood well... it sure looks like my code should work, but in fact it may be a red herring.
I figured out that the 'original' shape wasn't the original at all. I was not clearing out the tracking overlay after I promoted it to a InMemoryFeatureLayer, so any other layers I drew would get shapes drawn earlier and still hanging around on the TrackingLayer. SO it was not the original, it was a duplicate.
After resolving that, and adding a Map.Refresh() at the end of that promotion step (Tracking to InMemory) I see that my real issue is that my InMemoryFeatureLayers are not being drawn.
Below is the function that I use to promote from Tracking to a new InMemoryFeatureLayer. Once the Map.Refresh() executes, the shapes on the TrackingLayer disappear, but they do not reappear by way of the InMemoryFeatureLayer. If I use my earlier code to move shapes from any InMemoryFeatureLayer to EditOverlay, the shapes reappear via the EditOverlay.
Again, it is like my InMemoryFeatureLayers are not being rendered... what could I have done (or not done) to cause that?
Dave
/// <summary> /// Moves the contents of the TrackShapeLayer to a new independent in-memory layer /// </summary> /// <param name="layerType"></param> private void MoveTrackToNewLayer(string layerType) { //Exit drawing (tracking) mode Map.TrackOverlay.TrackMode = TrackMode.None;
// This means the user has left this drawing mode // We need to put what they drew on its own layer
InMemoryFeatureLayer newLayer = new InMemoryFeatureLayer(); foreach (Feature f in Map.TrackOverlay.TrackShapeLayer.InternalFeatures) { newLayer.InternalFeatures.Add(f); } // Add the new layer to an Overlay and then add the Overlay to the Map newLayer.Name = NewLayerName(layerType); //returns a string like "Rectangle01" LayerOverlay newOverlay = new LayerOverlay(); newOverlay.Layers.Add(newLayer.Name, newLayer); Map.Overlays.Add(newLayer.Name,newOverlay); AddLayerToLegend(newLayer); Map.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); Map.Refresh(); }