代码
MapObjects2.DataConnection dc = new MapObjects2.DataConnection();
dc.Database = @"C:\Program Files\ESRI\MapObjects2\Samples\Data\Usa"; //指定数据库路径
if (dc.Connect())
{
MapObjects2.MapLayer layer = new MapObjects2.MapLayer(); //创建新图层
layer.GeoDataset = dc.FindGeoDataset("states"); //指定数据源
layer.Symbol.Color = ToOleColor(Color.PaleGreen); //指定颜色
axMap1.Layers.Add(layer);
}
dc.Database = @"C:\Program Files\ESRI\MapObjects2\Samples\Data\Usa"; //指定数据库路径
if (dc.Connect())
{
MapObjects2.MapLayer layer = new MapObjects2.MapLayer(); //创建新图层
layer.GeoDataset = dc.FindGeoDataset("states"); //指定数据源
layer.Symbol.Color = ToOleColor(Color.PaleGreen); //指定颜色
axMap1.Layers.Add(layer);
}
这里需要把System.Drawing.Color颜色转换成uint格式
代码
/// <summary>
/// Color转成unit
/// </summary>
/// <param name="color">Color</param>
/// <returns></returns>
public uint ToOleColor(Color color)
{
return (uint)(color.B << 16 | color.G << 8 | color.R);
}
/// Color转成unit
/// </summary>
/// <param name="color">Color</param>
/// <returns></returns>
public uint ToOleColor(Color color)
{
return (uint)(color.B << 16 | color.G << 8 | color.R);
}
或者直接通过MapObjects的颜色常量枚举指定, 如返回红色:(uint)MapObjects2.ColorConstants.moRed;