ThinkGeo.com    |     Documentation    |     Premium Support

Vertices and edit controls only appear after multiple clicks on feature to be edited

I create a InMemoryFeatureLayer from a data source in memory that is populated from the database.



I have implemented code that enables a user to click on a feature on the map or in the datagrid that displays the related feature attribute info. On either event a feature object is successfully selected for edit.

 

I then create an EditOverlay by passing the selected feature using this call: wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);



This works fine. However the feature in the map only displays the vertices and other edit controls, such as rotate and resize, after repeatedly clicking on the feature.



My question is, do I have to remove the feature from the original InMemoryFeatureLayer before adding the feature to the  EditShapesLayer? Could this be preventing the object being displayed with all edit controls?



I have looked at various samples on your website but haven’t found anything similar to this scenario.

Hi Mark,



For the issue that only
vertices and edit controls left after repeatedly clicking, we cannot recreate
it on our end. Could you please provide us some code snippet or a complete demo
for us to dig into it?



For the time to
remove feature from original layer. If you get the selected feature by calling
method like GetFeatureById, It’s also OK to remove the layer after added
feature to EditShapesLayer, because the returned feature is a deep cloned
feature.



For the edit controls. We can set some properties of
EditOverlay to prevent some edit controls, please try codes below:


//no rotate control point
 wpfMap1.EditOverlay.CanRotate = false;
 //no resize control point
 wpfMap1.EditOverlay.CanResize = false;
 //no drag control point.
 wpfMap1.EditOverlay.CanDrag = false;
 //…some else.

Any question please feel free to let us know.



Regards and thanks,

Kevin





Hi Kevin,



I would firstly like to clarify that I do not want to prevent some edit controls as you suggest in your code snippet. I have set these to true because I would like the user to be able to edit the feature using the rotate, resize and drag tools, along with modifying the vertices of the shape. The problem is the icons for these tools only appear on the feature after clicking numerous times on the object.



Here is some code:



This is where I actually create the in-memory feature layer from the data source that contains features that might be selected for edit by the user.


private void CreateFeatureObjectLayer()
{
    //Get features from data source
    FeatureObjects = _featureObjectCasheProxy.GetAll().ToList();
    NotifyOfPropertyChange(() => FeatureObjects); 

    FeatureCache featureCache = new FeatureCache();
 
    try
    {
        //Add my feature layer
        myFeatureLayer = new InMemoryFeatureLayer();
        myFeatureLayer.Open();
 
        if (!myFeatureLayer.FeatureSource.IsOpen)
            myFeatureLayer.FeatureSource.Open();
 
        myFeatureLayer.Columns.Add(new FeatureSourceColumn(“FeatureObjectID”));
        myFeatureLayer.Columns.Add(new FeatureSourceColumn(“Code”));
        myFeatureLayer.Columns.Add(new FeatureSourceColumn(“Name”));
        myFeatureLayer.EditTools.BeginTransaction();
        myFeatureDataItems = new BindableCollection<FeatureObject>();
 
        foreach (var featureObject in FeatureObjects)
        {
            var myFeatureObject = new Feature(featureObject.WKBGeom);
 
            //TODO: Assign attribute data here
            myFeatureObject.ColumnValues[“FeatureObjectID”] = featureObject.DestinationID.ToString();
            myFeatureObject.ColumnValues[“Code”] = featureObject.DestinationCode;
            myFeatureObject.ColumnValues[“Name”] = featureObject.DestinationName;
 
            myFeatureLayer.EditTools.Add(myFeatureObject.GetShape(), myFeatureObject.ColumnValues);
 
            //Add to bindable collection for grid
            myFeatureDataItems.Add(featureObject);
        }
 
        myFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.BrightBlue, GeoColor.SimpleColors.PaleRed, 2);
        myFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        myFeatureLayer.FeatureSource.Projection = proj4Projection;
        myFeatureLayer.FeatureSource.GeoCache = featureCache;
        myFeatureLayer.EditTools.CommitTransaction();
        myFeatureLayer.Close();
 
        if (wpfMap1.Overlays.Contains(“FeatureObjectLayerOverlay”))
        {
            myFeatureLayerOverlay = wpfMap1.Overlays[“FeatureObjectLayerOverlay”as LayerOverlay;
            if (myFeatureLayerOverlay != null)
            {
                myFeatureLayerOverlay.Layers.Clear();
                myFeatureLayerOverlay.Layers.Add(myFeatureLayer);
                myFeatureLayerOverlay.Refresh();
            }

        }
        else
        {
            myFeatureLayerOverlay = new LayerOverlay();
            myFeatureLayerOverlay.Layers.Add(myFeatureLayer);
        }     
    }
    catch (Exception ex)
    {

    }
}

The following code snippet is the method that sets up the Edit Layer. I am thinking that perhaps the problem is that the  feature that is selected on the myFeatureLayer needs to be removed from myFeatureLayer because it might be appearing on top of the feature in editOverlay?




private void EditMapFeature(Feature feature, bool zoomToExtent)
       {
           //Create edit layer
           editOverlay = new EditInteractiveOverlay();
           editOverlay.Name = “EditInteractiveOverlay”;
 
           wpfMap1.EditOverlay = editOverlay;
           wpfMap1.EditOverlay.CanAddVertex = true;
           wpfMap1.EditOverlay.CanDrag = true;
           wpfMap1.EditOverlay.CanRemoveVertex = true;
           wpfMap1.EditOverlay.CanReshape = true;
           wpfMap1.EditOverlay.CanResize = true;
           wpfMap1.EditOverlay.CanRotate = true;

           try
           {                            
               if (feature != null)
               {
                   wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);

                   if(!wpfMap1.EditOverlay.EditShapesLayer.IsOpen)
                       wpfMap1.EditOverlay.EditShapesLayer.Open();



                   
//Clear highlighted layer I do this so the highlighted layer doesn’t appear over the edit layer
                   LayerOverlay highlightOverlay = (LayerOverlay)wpfMap1.Overlays[“HighlightOverlay”];
                   InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)highlightOverlay.Layers[“HighlightLayer”];
 
                   if (highlightLayer != null)
                   {
                       highlightLayer.Open();
                       highlightLayer.InternalFeatures.Clear();
                       highlightLayer.Close();
                       highlightOverlay.IsVisible = false;
                       highlightOverlay.Refresh();
                   }
               }
               else
               {
                   wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.Clear();
               }
                
               if (zoomToExtent)
               {
                   extent = wpfMap1.EditOverlay.EditShapesLayer.GetBoundingBox();
                   wpfMap1.CurrentExtent = extent;
               }
 
               ButtonUpdateIsVisible = true;
               NotifyOfPropertyChange(() => ButtonUpdateIsVisible);
 
               ButtonCancelIsVisible = true;
               NotifyOfPropertyChange(() => ButtonCancelIsVisible);
 
               ButtonSaveIsVisible = false;
               NotifyOfPropertyChange(() => ButtonSaveIsVisible);
 
               myFeatureLayerOverlay.Refresh();
               wpfMap1.Refresh();
           }
           catch (Exception ex)
           {
 
           }
 
       }


Hi Mark,


Sorry for my misunderstanding and thanks for your detail explanation.


After we added a feature to EditShapesLayer, we need to call
EditOverlay.CalculateAllControlPoints() method to display tool icons.


Here I create a sample for you like what you are doing.
Please have a check and see if it is what you want. I’m not sure why you create
a new EditOverlay instance for every time call EditMapFeature(), but I modified
sample to always use default EditOverlay of WpfMap.


Hope it would work for your case and any question please feel free to let us
know.


Thanks,


Kevin



Post12546.zip (102 KB)