Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -red62f6b66a9884ae4ac854f0bc1131425567b0af -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision ed62f6b66a9884ae4ac854f0bc1131425567b0af) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -223,33 +223,33 @@ var drawnMapDataLookup = drawnMapDataList.ToDictionary(dmd => dmd.FeatureBasedMapData, dmd => dmd); DrawMissingMapDataOnCollectionChange(mapDataThatShouldBeDrawn, drawnMapDataLookup); - RemoveRedundantMapDataOnCollectionChange(drawnMapDataLookup, mapDataThatShouldBeDrawn); + RemoveRedundantMapDataOnCollectionChange(mapDataThatShouldBeDrawn, drawnMapDataLookup); - drawnMapDataLookup = drawnMapDataList.ToDictionary(le => le.FeatureBasedMapData, le => le); + drawnMapDataLookup = drawnMapDataList.ToDictionary(dmd => dmd.FeatureBasedMapData, dmd => dmd); MoveMapDataOnCollectionChange(mapDataThatShouldBeDrawn, drawnMapDataLookup); } - private void DrawMissingMapDataOnCollectionChange(List mapDataThatShouldBeDrawn, Dictionary drawnMapDataLookup) + private void DrawMissingMapDataOnCollectionChange(IEnumerable mapDataThatShouldBeDrawn, + IDictionary drawnMapDataLookup) { - foreach (var mapDataToDraw in mapDataThatShouldBeDrawn) + foreach (var mapDataToDraw in mapDataThatShouldBeDrawn.Where(mapDataToDraw => !drawnMapDataLookup.ContainsKey(mapDataToDraw))) { - if (!drawnMapDataLookup.ContainsKey(mapDataToDraw)) - { - DrawMapData(mapDataToDraw); - } + DrawMapData(mapDataToDraw); } } - private void RemoveRedundantMapDataOnCollectionChange(Dictionary drawnMapDataLookup, List mapDataThatShouldBeDrawn) + private void RemoveRedundantMapDataOnCollectionChange(IEnumerable mapDataThatShouldBeDrawn, + IDictionary drawnMapDataLookup) { foreach (var featureBasedMapData in drawnMapDataLookup.Keys.Except(mapDataThatShouldBeDrawn)) { RemoveMapData(drawnMapDataLookup[featureBasedMapData]); } } - private void MoveMapDataOnCollectionChange(List mapDataThatShouldBeDrawn, Dictionary drawnMapDataLookup) + private void MoveMapDataOnCollectionChange(IList mapDataThatShouldBeDrawn, + IDictionary drawnMapDataLookup) { for (var i = 0; i < mapDataThatShouldBeDrawn.Count; i++) { Index: Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs =================================================================== diff -u -rbefc1a0f0bbc89550ee9a96fcf554487c004400a -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision befc1a0f0bbc89550ee9a96fcf554487c004400a) +++ Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -54,7 +54,7 @@ ValidateParameters(data, layer); ClearLayerData(layer); - SetDataTableColumns(data, layer); + SetDataTableColumns(data.MetaData, layer); var attributeMapping = GetAttributeMapping(data); @@ -64,18 +64,9 @@ foreach (var feature in features) { - layer.DataSet.Features.Add(feature); - - foreach (var attribute in mapFeature.MetaData) - { - feature.DataRow[attributeMapping[attribute.Key].ToString()] = attribute.Value; - } + AddFeatureToLayer(layer, feature, mapFeature, attributeMapping); } } - - layer.DataSet.InitializeVertices(); - layer.DataSet.UpdateExtent(); - layer.AssignFastDrawnStates(); } /// @@ -141,14 +132,31 @@ layer.DataSet.DataTable.Reset(); } - private static void SetDataTableColumns(TFeatureBasedMapData data, IFeatureLayer layer) + private static void SetDataTableColumns(IEnumerable metaData, IFeatureLayer layer) { - for (var i = 1; i <= data.MetaData.Count(); i++) + var count = metaData.Count(); + + for (var i = 1; i <= count; i++) { layer.DataSet.DataTable.Columns.Add(i.ToString(), typeof(string)); } } + private static void AddFeatureToLayer(TMapFeatureLayer layer, IFeature feature, MapFeature mapFeature, Dictionary attributeMapping) + { + layer.DataSet.Features.Add(feature); + + AddMetaDataToFeature(feature, mapFeature, attributeMapping); + } + + private static void AddMetaDataToFeature(IFeature feature, MapFeature mapFeature, Dictionary attributeMapping) + { + foreach (var attribute in mapFeature.MetaData) + { + feature.DataRow[attributeMapping[attribute.Key].ToString()] = attribute.Value; + } + } + /// /// This method is used for obtaining a mapping between map data attribute names and DotSpatial /// attribute names. This mapping is needed because DotSpatial can't handle special characters. Index: Core/Components/src/Core.Components.DotSpatial/Layer/MapLineDataLayer.cs =================================================================== diff -u -racf1c815d99af1ce78dfd0b04b1949203c731803 -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/src/Core.Components.DotSpatial/Layer/MapLineDataLayer.cs (.../MapLineDataLayer.cs) (revision acf1c815d99af1ce78dfd0b04b1949203c731803) +++ Core/Components/src/Core.Components.DotSpatial/Layer/MapLineDataLayer.cs (.../MapLineDataLayer.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -41,6 +41,7 @@ /// Creates a new instance of . /// /// The which the map line data layer is based upon. + /// Thrown when is null. public MapLineDataLayer(MapLineData mapLineData) { if (mapLineData == null) @@ -59,6 +60,10 @@ { converter.ConvertLayerFeatures(mapLineData, this); + DataSet.InitializeVertices(); + DataSet.UpdateExtent(); + AssignFastDrawnStates(); + drawnFeatures = mapLineData.Features; } Index: Core/Components/src/Core.Components.DotSpatial/Layer/MapPointDataLayer.cs =================================================================== diff -u -racf1c815d99af1ce78dfd0b04b1949203c731803 -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/src/Core.Components.DotSpatial/Layer/MapPointDataLayer.cs (.../MapPointDataLayer.cs) (revision acf1c815d99af1ce78dfd0b04b1949203c731803) +++ Core/Components/src/Core.Components.DotSpatial/Layer/MapPointDataLayer.cs (.../MapPointDataLayer.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -20,6 +20,7 @@ /// Creates a new instance of . /// /// The which the map point data layer is based upon. + /// Thrown when is null. public MapPointDataLayer(MapPointData mapPointData) { if (mapPointData == null) @@ -38,6 +39,10 @@ { converter.ConvertLayerFeatures(mapPointData, this); + DataSet.InitializeVertices(); + DataSet.UpdateExtent(); + AssignFastDrawnStates(); + drawnFeatures = mapPointData.Features; } Index: Core/Components/src/Core.Components.DotSpatial/Layer/MapPolygonDataLayer.cs =================================================================== diff -u -racf1c815d99af1ce78dfd0b04b1949203c731803 -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/src/Core.Components.DotSpatial/Layer/MapPolygonDataLayer.cs (.../MapPolygonDataLayer.cs) (revision acf1c815d99af1ce78dfd0b04b1949203c731803) +++ Core/Components/src/Core.Components.DotSpatial/Layer/MapPolygonDataLayer.cs (.../MapPolygonDataLayer.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -41,6 +41,7 @@ /// Creates a new instance of . /// /// The which the map polygon data layer is based upon. + /// Thrown when is null. public MapPolygonDataLayer(MapPolygonData mapPolygonData) { if (mapPolygonData == null) @@ -59,6 +60,10 @@ { converter.ConvertLayerFeatures(mapPolygonData, this); + DataSet.InitializeVertices(); + DataSet.UpdateExtent(); + AssignFastDrawnStates(); + drawnFeatures = mapPolygonData.Features; } Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs =================================================================== diff -u -rf0063cb88cd92a56fe39dbff5dc1e7811217db52 -rce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1 --- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision f0063cb88cd92a56fe39dbff5dc1e7811217db52) +++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision ce921ee0727d9c3ce1f0fdad2d2f89bf287c91f1) @@ -158,7 +158,6 @@ // Assert IFeature feature = mapLineLayer.DataSet.Features[0]; Assert.AreEqual(mapLineData.Features.Length, mapLineLayer.DataSet.Features.Count); - Assert.AreEqual(mapFeature.MapGeometries.Count(), mapLineLayer.DataSet.ShapeIndices.First().Parts.Count); Assert.IsInstanceOf(feature.BasicGeometry); var expectedCoordinates = mapFeature.MapGeometries.SelectMany(mg => mg.PointCollections.ElementAt(0).Select(p => new Coordinate(p.X, p.Y)));