Hello,
I have the following methods in a MVC application, which both gets called periodically by ajax (first RefreshVesselMarkers then AddVesselTrails):
public IEnumerable<VesselPosition> RefreshVesselMarkers(RectangleShape currentExtent = null)
{
var featureLayer = _map.DynamicOverlay.Layers[VesselMarkersOverlayName] as InMemoryFeatureLayer;
lock (_syncObject)
{
featureLayer.FeatureSource.Open();
featureLayer.FeatureSource.BeginTransaction();
featureLayer.InternalFeatures.Clear();
_map.Projection.Open();
var extent = _map.Projection.ConvertToInternalProjection(currentExtent ?? _map.RestrictedExtent ?? _defaultRestrictedExtent);
var positions = new List<VesselPosition>();
foreach (var vesselPosition in _positionService.GetVesselPositions(extent, _customerGroupId))
{
var feature = _map.Projection.ConvertToExternalProjection(CreateFeatureFromVesselPosition(vesselPosition));
featureLayer.FeatureSource.AddFeature(feature);
var point = feature.GetShape() as PointShape;
if (point != null)
{
vesselPosition.Lon = point.X;
vesselPosition.Lat = point.Y;
positions.Add(vesselPosition);
}
}
featureLayer.FeatureSource.CommitTransaction();
_map.Projection.Close();
featureLayer.FeatureSource.Close();
return positions;
}
}
public void AddVesselTrails(IEnumerable<int> vesselIds, TimeSpan? ageLimit)
{
AssertMapIsInitialized();
var layer = _map.DynamicOverlay.Layers[VesselTrailsOverlayName] as InMemoryFeatureLayer;
lock (_syncObject)
{
layer.FeatureSource.Open();
layer.FeatureSource.BeginTransaction();
layer.InternalFeatures.Clear();
_map.Projection.Open();
Action<IEnumerable<VesselPosition>> addFeature = positions =>
{
var feature = new Feature(new LineShape(positions.Select(o => new Vertex(o.Lon, o.Lat))));
layer.FeatureSource.AddFeature(_map.Projection.ConvertToExternalProjection(feature));
};
if (vesselIds.Count() > 1)
{
var positions = _positionService.GetHistoricalPositionsForVessels(vesselIds);
foreach (var position in positions)
addFeature(position.Value);
}
else
{
var positions = _positionService.GetHistoricalPositionsForVessel(vesselIds.First()).ToList();
if (positions.Count > 1)
addFeature(positions);
}
_map.Projection.Close();
layer.FeatureSource.CommitTransaction();
layer.FeatureSource.Close();
}
}
From time to time, I get this exception:
System.InvalidOperationException: The FeatureSource is not open. Please call the Open method before calling this method. at ThinkGeo.MapSuite.Core.FeatureSource.AddFeature(Feature feature)
This does not make any sense to me, as you can see I am opening and closing the FeatureSource in each method. I even added a lock in case there was some problem with concurrency.
Does anyone have an idea what can be wrong?