Index: Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs
===================================================================
diff -u -re54cb513676688e423c1b6304ced7eb9337de5f0 -r3f64435bdc16678eb063fd02f1dd1cb2e0f9e535
--- Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision e54cb513676688e423c1b6304ced7eb9337de5f0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/FeatureBasedMapDataConverter.cs (.../FeatureBasedMapDataConverter.cs) (revision 3f64435bdc16678eb063fd02f1dd1cb2e0f9e535)
@@ -102,13 +102,13 @@
layer.ShowLabels = data.ShowLabels;
((IMapFeatureLayer) layer).LabelLayer = GetLabelLayer(GetAttributeMapping(data), layer.DataSet, data.SelectedMetaDataAttribute);
- if (data.MapTheme == null)
+ if (HasMapTheme(data))
{
- layer.Symbolizer = CreateSymbolizer(data);
+ layer.Symbology = CreateCategoryScheme(data);
}
else
{
- layer.Symbology = CreateCategorySchemes(data);
+ layer.Symbolizer = CreateSymbolizer(data);
}
}
@@ -130,12 +130,6 @@
protected abstract IFeatureSymbolizer CreateSymbolizer(TFeatureBasedMapData mapData);
///
- /// Creates a new to be applied on the data.
- ///
- /// The newly created .
- protected abstract IFeatureScheme CreateScheme();
-
- ///
/// Creates a new based on .
///
/// The map data to base the category on.
@@ -144,15 +138,6 @@
protected abstract IFeatureCategory CreateDefaultCategory(TFeatureBasedMapData mapData);
///
- /// Creates a new with a different color than specified in the .
- ///
- /// The map data to base the category on.
- /// The desired color of the category.
- /// The newly created .
- /// null should never be returned as this will break DotSpatial.
- protected abstract IFeatureCategory CreateCategory(TFeatureBasedMapData mapData, Color color);
-
- ///
/// Converts an of to an
/// of .
///
@@ -164,38 +149,26 @@
}
///
- /// Creates the based on the .
+ /// Determines if the has a categorical theming to be applied
+ /// on the data it contains
///
- /// The map data to base the scheme on.
- /// The newly created .
+ /// The map data to determine if it has categorical theming.
+ /// true if the has categorical theming, false otherwise.
+ protected abstract bool HasMapTheme(TFeatureBasedMapData mapData);
+
+ ///
+ /// Creates the based on the categorical theming of .
+ ///
+ /// The map data to create the categorical theming for.
+ /// A configured based on the map data theme.
+ /// null should never be returned as this will break DotSpatial.
/// Thrown when the
/// could not be successfully converted to a scheme.
- private IFeatureScheme CreateCategorySchemes(TFeatureBasedMapData mapData)
- {
- IFeatureScheme scheme = CreateScheme();
- ClearFeatureScheme(mapData, scheme);
+ protected abstract IFeatureScheme CreateCategoryScheme(TFeatureBasedMapData mapData);
- MapTheme mapTheme = mapData.MapTheme;
- Dictionary attributeMapping = GetAttributeMapping(mapData);
-
- if (attributeMapping.ContainsKey(mapTheme.AttributeName))
- {
- int attributeIndex = attributeMapping[mapTheme.AttributeName];
-
- foreach (CategoryTheme categoryTheme in mapTheme.CategoryThemes)
- {
- IFeatureCategory category = CreateCategory(mapData, categoryTheme.Color);
- category.FilterExpression = CreateFilterExpression(attributeIndex, categoryTheme.Criterion);
- scheme.AddCategory(category);
- }
- }
-
- return scheme;
- }
-
private void ClearFeatureScheme(TFeatureBasedMapData mapData, IScheme scheme)
{
- if (mapData.MapTheme != null)
+ if (HasMapTheme(mapData))
{
scheme.ClearCategories();
scheme.AddCategory(CreateDefaultCategory(mapData));
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs
===================================================================
diff -u -re54cb513676688e423c1b6304ced7eb9337de5f0 -r3f64435bdc16678eb063fd02f1dd1cb2e0f9e535
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs (.../FeatureBasedMapDataConverterTest.cs) (revision e54cb513676688e423c1b6304ced7eb9337de5f0)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/FeatureBasedMapDataConverterTest.cs (.../FeatureBasedMapDataConverterTest.cs) (revision 3f64435bdc16678eb063fd02f1dd1cb2e0f9e535)
@@ -30,12 +30,12 @@
using Core.Components.Gis.Features;
using Core.Components.Gis.Geometries;
using Core.Components.Gis.TestUtil;
-using Core.Components.Gis.Theme;
using DotSpatial.Controls;
using DotSpatial.Data;
using DotSpatial.Projections;
using DotSpatial.Symbology;
using NUnit.Framework;
+using Rhino.Mocks;
using Point = DotSpatial.Topology.Point;
namespace Core.Components.DotSpatial.Test.Converter
@@ -512,92 +512,79 @@
}
[Test]
- public void ConvertLayerProperties_MapDataWithMapThemeAndMetaDataNameNotInFeatures_AddsOnlyDefaultCategory()
+ public void ConvertLayerProperties_WithMapData_CallsHasMapThemeWithCorrectInput()
{
// Setup
- var random = new Random(21);
+ var mapData = new TestFeatureBasedMapData("test data")
+ {
+ Features = new[]
+ {
+ new MapFeature(Enumerable.Empty())
+ }
+ };
- var featureScheme = new PointScheme();
- var defaultCategory = new PointCategory();
- var category = new PointCategory();
+ var testConverter = new TestFeatureBasedMapDataConverter();
- var theme = new MapTheme("Meta", new[]
- {
- new CategoryTheme(Color.FromKnownColor(random.NextEnum()),
- new ValueCriterion(random.NextEnum(),
- "test value"))
- });
+ var mapLayer = new TestFeatureLayer();
+ // Call
+ testConverter.ConvertLayerProperties(mapData, mapLayer);
+
+ // Assert
+ Assert.AreSame(mapData, testConverter.MapDataInput);
+ }
+
+ [Test]
+ public void ConvertLayerProperties_MapDataHasMapTheme_SetsSymbology()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var scheme = mocks.Stub();
+ mocks.ReplayAll();
+
+ var mapLayer = new TestFeatureLayer();
var mapData = new TestFeatureBasedMapData("test data")
{
Features = new[]
{
new MapFeature(Enumerable.Empty())
- },
- MapTheme = theme
+ }
};
var testConverter = new TestFeatureBasedMapDataConverter
{
- CreatedFeatureScheme = featureScheme,
- CreatedDefaultCategory = defaultCategory,
- CreatedCategory = category
+ CreatedFeatureScheme = scheme,
+ MapDataHasTheme = true
};
- var mapLayer = new TestFeatureLayer();
-
// Call
testConverter.ConvertLayerProperties(mapData, mapLayer);
// Assert
- Assert.AreSame(defaultCategory, mapLayer.Symbology.Categories.Single());
+ Assert.AreSame(scheme, mapLayer.Symbology);
+ mocks.VerifyAll();
}
[Test]
- [TestCase(ValueCriterionOperator.EqualValue, "[1] = '{0}'", TestName = "EqualValue")]
- [TestCase(ValueCriterionOperator.UnequalValue, "NOT [1] = '{0}'", TestName = "UnequalValue")]
- public void ConvertLayerProperties_MapDataWithMapThemeAndValidValueCriteria_SetsCorrectFilterExpression(ValueCriterionOperator criterionOperator,
- string expressionFormat)
+ public void ConvertLayerProperties_MapDataHasMapTheme_CallsCreateCategorySchemeWithCorrectInput()
{
// Setup
- var random = new Random(21);
- const string metadataAttributeName = "Meta";
- const string value = "test value";
+ var mocks = new MockRepository();
+ var scheme = mocks.Stub();
+ mocks.ReplayAll();
- var featureScheme = new PointScheme();
- var defaultCategory = new PointCategory();
- var category = new PointCategory();
-
- var valueCriterion = new ValueCriterion(criterionOperator,
- value);
- var theme = new MapTheme(metadataAttributeName, new[]
- {
- new CategoryTheme(Color.FromKnownColor(random.NextEnum()),
- valueCriterion)
- });
-
var mapData = new TestFeatureBasedMapData("test data")
{
Features = new[]
{
new MapFeature(Enumerable.Empty())
- {
- MetaData =
- {
- {
- metadataAttributeName, new object()
- }
- }
- }
- },
- MapTheme = theme
+ }
};
var testConverter = new TestFeatureBasedMapDataConverter
{
- CreatedFeatureScheme = featureScheme,
- CreatedDefaultCategory = defaultCategory,
- CreatedCategory = category
+ CreatedFeatureScheme = scheme,
+ MapDataHasTheme = true
};
var mapLayer = new TestFeatureLayer();
@@ -606,41 +593,17 @@
testConverter.ConvertLayerProperties(mapData, mapLayer);
// Assert
- Assert.AreSame(featureScheme, mapLayer.Symbology);
-
- Assert.IsNull(defaultCategory.FilterExpression);
- string expectedFilterExpression = string.Format(expressionFormat, value);
- Assert.AreEqual(expectedFilterExpression, category.FilterExpression);
-
- CollectionAssert.AreEqual(new[]
- {
- defaultCategory,
- category
- }, mapLayer.Symbology.Categories);
-
- CollectionAssert.AreEqual(new[]
- {
- Tuple.Create(mapData, Color.Transparent),
- Tuple.Create(mapData, theme.CategoryThemes.Single().Color)
- }, testConverter.CreatedCategories);
+ Assert.AreSame(mapData, testConverter.MapDataInput);
+ mocks.VerifyAll();
}
[Test]
public void GivenLayerWithConvertedProperties_WhenFeaturesClearedAndConverted_ThenOnlyDefaultCategoryAdded()
{
// Given
- var random = new Random(21);
const string metadataAttributeName = "Meta";
var defaultCategory = new PointCategory();
-
- var theme = new MapTheme(metadataAttributeName, new[]
- {
- new CategoryTheme(Color.FromKnownColor(random.NextEnum()),
- new ValueCriterion(random.NextEnum(),
- "test value"))
- });
-
var mapData = new TestFeatureBasedMapData("test data")
{
Features = new[]
@@ -654,20 +617,29 @@
}
}
}
- },
- MapTheme = theme
+ }
};
+ var mocks = new MockRepository();
+ var categoryOne = mocks.Stub();
+ var categoryTwo = mocks.Stub();
+ mocks.ReplayAll();
+
+ var scheme = new PointScheme();
+ scheme.Categories.Add(categoryOne);
+ scheme.Categories.Add(categoryTwo);
+
+ var mapLayer = new TestFeatureLayer
+ {
+ Symbology = scheme
+ };
+
var testConverter = new TestFeatureBasedMapDataConverter
{
- CreatedFeatureScheme = new PointScheme(),
CreatedDefaultCategory = defaultCategory,
- CreatedCategory = new PointCategory()
+ MapDataHasTheme = true
};
- var mapLayer = new TestFeatureLayer();
- testConverter.ConvertLayerProperties(mapData, mapLayer);
-
// Precondition
Assert.AreEqual(2, mapLayer.Symbology.Categories.Count);
@@ -689,47 +661,33 @@
private class TestFeatureBasedMapDataConverter : FeatureBasedMapDataConverter
{
- private readonly List> createdCategories;
-
- public TestFeatureBasedMapDataConverter()
- {
- createdCategories = new List>();
- }
-
public IFeatureCategory CreatedDefaultCategory { private get; set; }
- public IFeatureCategory CreatedCategory { private get; set; }
-
public IFeatureScheme CreatedFeatureScheme { private get; set; }
- public IEnumerable> CreatedCategories
- {
- get
- {
- return createdCategories;
- }
- }
+ public TestFeatureBasedMapData MapDataInput { get; private set; }
+ public bool MapDataHasTheme { private get; set; }
+
protected override IFeatureSymbolizer CreateSymbolizer(TestFeatureBasedMapData mapData)
{
return new PointSymbolizer();
}
- protected override IFeatureScheme CreateScheme()
+ protected override IFeatureCategory CreateDefaultCategory(TestFeatureBasedMapData mapData)
{
- return CreatedFeatureScheme;
+ return CreatedDefaultCategory;
}
- protected override IFeatureCategory CreateDefaultCategory(TestFeatureBasedMapData mapData)
+ protected override bool HasMapTheme(TestFeatureBasedMapData mapData)
{
- createdCategories.Add(Tuple.Create(mapData, Color.Transparent));
- return CreatedDefaultCategory;
+ return MapDataHasTheme;
}
- protected override IFeatureCategory CreateCategory(TestFeatureBasedMapData mapData, Color color)
+ protected override IFeatureScheme CreateCategoryScheme(TestFeatureBasedMapData mapData)
{
- createdCategories.Add(Tuple.Create(mapData, color));
- return CreatedCategory;
+ MapDataInput = mapData;
+ return CreatedFeatureScheme;
}
protected override IEnumerable CreateFeatures(MapFeature mapFeature)