ThinkGeo.com    |     Blog    |     Wiki    |     Support

Features disappear after editing them

I take some features from an InMemoryFeatureLayer and throw them into the Map’s EditOverlay like so:

foreach (InMemoryFeatureLayer layer in (MyMap.Overlays[DrawingOverlay] as LayerOverlay).Layers)
{
    foreach (Feature feature in layer.InternalFeatures)
    {
        MyMap.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature.Id, feature);
    }
}

MyMap.EditOverlay.CalculateAllControlPoints();

MyMap.Refresh(DrawingOverlay);

After editing the shapes (via dragging a vertex, rotating the shape, moving it, etc.) I do the following to end the edit mode:

private void EditFeatures_Ended()
{

    //Clear any features in the DrawingOverlay
    foreach (InMemoryFeatureLayer layer in (MyMap.Overlays[DrawingOverlay] as LayerOverlay).Layers)
    {
        layer.InternalFeatures.Clear();
    }

    //Add each feature in the EditOverlay to the appropriate layer in DrawingOverlay based on its shape
    foreach (Feature feature in MyMap.EditOverlay.EditShapesLayer.InternalFeatures)
    {
        BaseShape shape = feature.GetShape();
        if (typeof(LineShape) == shape.GetType())
        {
            (MyMap.FindFeatureLayer(LinesLayer) as InMemoryFeatureLayer).InternalFeatures.Add(feature);
        }
        else if (typeof(PolygonShape) == shape.GetType())
        {
            (MyMap.FindFeatureLayer(PolygonsLayer) as InMemoryFeatureLayer).InternalFeatures.Add(feature);
        }
        else if (typeof(PointShape) == shape.GetType())
        {
                (MyMap.FindFeatureLayer(PointsLayer) as InMemoryFeatureLayer).InternalFeatures.Add(feature);
        }
    }

    OnyxMap.EditOverlay.EditShapesLayer.Open();
    OnyxMap.EditOverlay.EditShapesLayer.Clear(); //remove all the features in the edit overlay
    OnyxMap.EditOverlay.EditShapesLayer.Close();
    OnyxMap.Refresh();
}

After this happens, the features disappear off the map until I add another shape to the layer. I’m not sure why this is happening. I can verify the features are in the InMemoryFeatureLayers even though they aren’t showing up on the map.

Hi Dan,

Here is a simple sample which is based on your code, I tested it and found it works well here. Could you please view it and see what’s the different with your code? For simplification problem, I just put a line and only leave line related code.

9488.zip (10.7 KB)

Regards,

Ethan

It looks like maybe my feature is losing its style in the process making it not appear on the map. Here’s a related question: How do you programatically update the shape of a feature? For instance, if you have a polygon feature, normally I get the shape of it, and change the vertices in the OuterRing property of it. After that is done, do you use the EditTools to update that shape or the feature itself? I think there might be an issue related to me updating the feature/shape programatically.

Edit: I’m uploading a modified example of the one you gave me. Instead of a line, I’m using a polygon shape. I added a button click event as well to show how I edit the vertices. You can get it at this link: https://drive.google.com/open?id=1henmZwaBZG1UCw1IZTWxtVGs-eEpaaYC

As you can see, the feature disappears for some reason.

Hi Dan,

It disappear is because when you add the polygon back to InMemoryFeatureLayer, the InMemoryFeatureLayer hadn’t set area style for it.

Please view my modified version, it works.

9488.zip (11.0 KB)

Regards,

Ethan