ThinkGeo.com    |     Documentation    |     Premium Support

Clearing features question/confusion

I'm confused about something.


Why does this work to get rid of the features on the track layer?



public Feature? GetTrackedFeature()
{
map.TrackOverlay.Lock.EnterWriteLock();
Feature? feature = null;
try
{
if (map.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)
{
feature = map.TrackOverlay.TrackShapeLayer.InternalFeatures[0];
RemoveFeatureListFromLayer(map.TrackOverlay.TrackShapeLayer, new Collection<Feature> { feature.Value });
}
}
finally
{
map.TrackOverlay.Lock.ExitWriteLock();
}
return feature;
}


 



And this doesn't work to get rid of the features off the track layer?




public void ClearTrackedFeature()
{
map.TrackOverlay.Lock.EnterWriteLock();
try
{
RemoveAllFeaturesFromLayer(map.TrackOverlay.TrackShapeLayer);
}
finally
{
map.TrackOverlay.Lock.ExitWriteLock();
}
}


Here are the supporting methods: 




private void RemoveAllFeaturesFromLayer(InMemoryFeatureLayer layer)
{
layer.Open();
Collection<Feature> features = layer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
layer.Close();
RemoveFeatureListFromLayer(layer, features);
}


private void RemoveFeatureListFromLayer(InMemoryFeatureLayer layer, Collection<Feature> featureList)
{
layer.Open();
layer.EditTools.BeginTransaction();

try
{
foreach (Feature feature in featureList)
{
layer.EditTools.Delete(feature.Id);
}
}
finally
{
layer.EditTools.CommitTransaction();
layer.Close();
}
}



I answered my own question. Trying to clear the features before the track ended event fires does not have any effect. When you get the features using query tools, I do get the tracked feature returned, but deleting it seems to have no effect.


Kimberly



Kimberly. 
  
   When I saw your post I was intrigued so I debugged my way though it to find the same thing you found.  My results came at that both methods do the same thing, sometimes succeed and sometimes fail, depending on if the track shape is finished or not.  Here is the full scoop… 
  
   When we are drawing a track shape we store that feature in the InternalFeatures under the key “InTrackingFeature” which is different from the feature’s ID.  The Id is on the feature, which is a random guid, and the hard coded string is the key into the collection.  We name it that so we can get to it internally but what we should also do is to set the feature Id to the same thing.  With the key in the collection and the feature Id being different it causes some issues down the line with our transaction system.  When we overrode the CommitTransactionCore on the InMemoryFeatureSource we implemented the delete with a assumption.  We assumed that the feature Id would match the key used in the InternalFeatures.  This way we can find the item to delete by using the key look up and not looping to find the right feature Id. 
  
   I think we can clean this up by making sure the FeatureId for the shape being tracked always matches the key we use to store it in the collection.  I will write this up to be modified. 
  
 David

Thanks for the explanation. I didn’t need it, but was curious. I appreciate you taking the time to look it up.  
  
 Kimberly

Glad we were able to help. 
  
 Thanks!