//增加图元,包括数据集、自定义字段、样式、标签
string sPath = Application.StartupPath + "//china//China.gst";
Mapx.GeoSet = sPath;
Mapx.TitleText = "";
Mapx.MapUnit = MapXLib.MapUnitConstants.miUnitKilometer;
MapXLib.Fields fld = new MapXLib.Fields();
fld.AddStringField("Label", 200, false); fld.AddStringField("DamCode", 20, false);
//图层信息
MapXLib.LayerInfo layerInfo = new MapXLib.LayerInfo();
layerInfo.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
layerInfo.AddParameter("fileSpec", "My Layer");
layerInfo.AddParameter("Name", "DamLayer" + i);
layerInfo.AddParameter("Fields", fld);
//创建图层
MapXLib.Layer layer = Mapx.Layers.Add(layerInfo,i);
//创建图层数据集
MapXLib.Dataset layerDataSet = Mapx.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, layer, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//对标签属性进行设置
layer.LabelProperties.Dataset = layerDataSet;
layer.LabelProperties.DataField = layerDataSet.Fields["Label"];
layer.LabelProperties.Position = MapXLib.PositionConstants.miPositionCL;
layer.LabelProperties.Offset = 2;
layer.LabelProperties.Overlap = true;
layer.LabelProperties.Style.TextFont.Size = 9;
layer.LabelProperties.Style.TextFont.Name = "楷书_GB2312";
layer.LabelProperties.Style.TextFont.Bold = true;
layer.LabelProperties.Style.TextFontColor = (uint)ColorTranslator.ToOle(Color.Red);
layer.ZoomLayer = true;
layer.ZoomMax = iMax;
layer.ZoomMin = 0;
layer.AutoLabel = true;
//点
MapXLib.Point ptObj = new MapXLib.PointClass();
//点赋值
ptObj.Set(double.Parse(Dboper.sdr["EL"].ToString()), double.Parse(Dboper.sdr["NL"].ToString()));
//字段赋值
MapXLib.RowValues rv = layerDataSet.get_RowValues(0);
rv["Label"].Value = Dboper.sdr["RSNM"].ToString();
rv["DamCode"].Value = Dboper.sdr["RSID"].ToString();
//样式
MapXLib.Style style = new MapXLib.Style();
style.SymbolFont.Name = "MapInfo Oil&Gas";
style.SymbolCharacter = 47;
style.SymbolFontColor = (uint)ColorTranslator.ToOle(Color.Red);
style.SymbolFont.Size = 12;
//图元 MapXLib.Feature f = Mapx.FeatureFactory.CreateSymbol(ptObj, style);
//图元加到图层上
layer.AddFeature(f, rv);
private void Mapx_SelectionChanged(object sender, EventArgs e)
{
pXLib.Features FeaObjs;
pXLib.RowValues rv;
String sDamCode;
int iSerial = 0;
lv_Dam.Items.Clear();
try
{
for (int i = 0; i < iCountPRJSC; i++)
{
FeaObjs = Mapx.Layers["DamLayer" + i].Selection.Clone();
if (FeaObjs != null)
{
if (FeaObjs.Count > 0)
{
for (int j = 1; j <= FeaObjs.Count; j++)
{
rv = Mapx.Layers["DamLayer" + i].DataSets[1].get_RowValues(FeaObjs[j]); sDamCode = rv["DamCode"].Value.ToString();
iSerial++;
AddDamInfo(sDamCode,iSerial);
}
}
}
}
}
catch
{
MessageBox.Show("选择图元时发生错误!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation );
}
}