Jeremy,
Here I made a wrapper with which, you can use the external database much easier. You can change the code a little bit to meet your requirements.
Here is the code:
public class CustomDataShapeFileFeatureLayer : ShapeFileFeatureLayer
{
private Dictionary<string, string> idLinkFieldDictionary = new Dictionary<string, string>();
private Dictionary<string, Dictionary<string, string>> customFieldsDictionaries = new Dictionary<string, Dictionary<string, string>>();
private CustomDataShapeFileFeatureLayer()
: this(string.Empty)
{ }
public CustomDataShapeFileFeatureLayer(string shapeFileFilePath)
: base(shapeFileFilePath)
{
FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch);
}
public void InitDictionaries(string LinkFieldName, DataTable ExternalDataBase, params string[] CustomColumnNames)
{
ShapeFileFeatureLayer.BuildRecordIdColumn(this.ShapePathFileName, "RecId", BuildRecordIdMode.DoNotRebuild);
FeatureSource.Open();
DataTable dataTable = FeatureSource.ExecuteQuery(string.Format("select RecId, {0} from {1}", LinkFieldName, Path.GetFileNameWithoutExtension(this.ShapePathFileName)));
foreach (DataRow dataRow in dataTable.Rows)
{
idLinkFieldDictionary.Add(dataRow["RecId"].ToString(), dataRow[LinkFieldName].ToString());
}
foreach (string customColumnName in CustomColumnNames)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
// Here is you own code getting the dictionary from the LinkField To The customColumn you want
// This sample is using DataTable as the external database. You can change it to consume your own databases.
foreach (DataRow dataRow in ExternalDataBase.Rows)
{
dictionary.Add(dataRow[LinkFieldName].ToString(), dataRow[customColumnName].ToString());
}
customFieldsDictionaries.Add(customColumnName, dictionary);
}
}
void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
{
string LinkFieldValue = idLinkFieldDictionary[e.Id];
if (customFieldsDictionaries[e.ColumnName].ContainsKey(LinkFieldValue))
{
e.ColumnValue = customFieldsDictionaries[e.ColumnName][LinkFieldValue];
}
}
}
// Here is how to use this class
private void DisplayMap_Load(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(WinformsMap.GetVersion());
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
CustomDataShapeFileFeatureLayer worldLayer = new CustomDataShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.InitDictionaries("CNTRY_NAME", GetTestDataTable(), "History", "Population");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("History");
//worldLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("Population");
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
winformsMap1.StaticOverlay.Layers.Add("WorldLayer", worldLayer);
winformsMap1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);
winformsMap1.Refresh();
}
private DataTable GetTestDataTable()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("CNTRY_NAME");
dataTable.Columns.Add("History", Type.GetType("System.Int32"));
dataTable.Columns.Add("Population", Type.GetType("System.Int32"));
DataRow rowChina = dataTable.NewRow();
rowChina["CNTRY_NAME"] = "China";
rowChina["History"] = 5000;
rowChina["Population"] = 1300000000;
dataTable.Rows.Add(rowChina);
DataRow rowUSA = dataTable.NewRow();
rowUSA["CNTRY_NAME"] = "United States";
rowUSA["History"] = 250;
rowUSA["Population"] = 300000000;
dataTable.Rows.Add(rowUSA);
return dataTable;
}
Here is the result:

Thanks,
Ben