Hi Kaori,
Thanks for your sample, that helps to figure out what the problem is. Basically that error you got is about index. We have the in memory RTree index in InmemoryFeatureLayer to enhance the performance if there are thousands of features.
There are 2 ways to add / remove features in InMemoryFeatureLayer,
1# is:
inMemoryFeatureLayer.InternalFeatures.Add(newFeature)
inMemoryFeatureLayer.InternalFeatures.Clear()
In this way, the index is disabled unless call inMemoryFeatureLayer.BuildIndex() method.
2# is:
inMemoryFeatureLayer.FeatureSource.BeginTransaction()
inMemoryFeatureLayer.AddFeature(newFeature)
inMemoryFeatureLayer.FeatureSource.CommitTransaction()
This way the in memory index will be built automatically, so after you add / remove the features, have to call inMemoryFeatureLayer.BuildIndex() to refresh the in memory index.
In your code, using 2# but didn’t call BuildIndex() method after Clear internal features.
So, 2 way to fix that.
1. Do NOT use BeginTransaction() / CommitTransaction() to dynamically adding features if you have only a few features in the layer.
2. Call pointLayer.BuildIndex() in ClearMarkers method after clear InternalFeatures.
Please feel free to let us know if you have any questions.
Thanks,
Lee