c#下 mapx添加动态图层
刚刚接触mapx,在网上找到的代码privatevoidbutton1_Click(objectsender,EventArgse){MapXLib.LayerInfoC...
刚刚接触mapx,在网上找到的代码
private void button1_Click(object sender, EventArgs e)
{
MapXLib.LayerInfoClass li = new MapXLib.LayerInfoClass();
MapXLib.Features ftrs = null;
MapXLib.FieldsClass flds = new MapXLib.FieldsClass();
MapXLib.Fields Myflds = null;
MapXLib.Dataset dts = null;
flds.Add("State", "State_Name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString);
dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);
Myflds = dts.Fields;
ftrs = axMap1.Layers._Item("USA").Selection.Clone();
li.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
li.AddParameter("Name", "USA Temp Layer");
li.AddParameter("Fields", Myflds);
li.AddParameter("Features", ftrs);
axMap1.Layers.Add(li, 1);
axMap1.Layers.LayersDlg("", "");
}
为什么我每次运行到 dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);这一句就弹出错误呢。
错误信息:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: No object was found using the index you specified. 展开
private void button1_Click(object sender, EventArgs e)
{
MapXLib.LayerInfoClass li = new MapXLib.LayerInfoClass();
MapXLib.Features ftrs = null;
MapXLib.FieldsClass flds = new MapXLib.FieldsClass();
MapXLib.Fields Myflds = null;
MapXLib.Dataset dts = null;
flds.Add("State", "State_Name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString);
dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);
Myflds = dts.Fields;
ftrs = axMap1.Layers._Item("USA").Selection.Clone();
li.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
li.AddParameter("Name", "USA Temp Layer");
li.AddParameter("Fields", Myflds);
li.AddParameter("Features", ftrs);
axMap1.Layers.Add(li, 1);
axMap1.Layers.LayersDlg("", "");
}
为什么我每次运行到 dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);这一句就弹出错误呢。
错误信息:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: No object was found using the index you specified. 展开
2个回答
展开全部
private void button1_Click(object sender, EventArgs e)
{
MapXLib.LayerInfoClass li = new MapXLib.LayerInfoClass();
MapXLib.Features ftrs = null;
MapXLib.FieldsClass flds = new MapXLib.FieldsClass();
MapXLib.Fields Myflds = null;
MapXLib.Dataset dts = null;
flds.Add(1,"State_Name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString);
dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);
Myflds = dts.Fields;
ftrs = axMap1.Layers._Item("USA").Selection.Clone();
li.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
li.AddParameter("Name", "USA Temp Layer");
li.AddParameter("Fields", Myflds);
li.AddParameter("Features", ftrs);
axMap1.Layers.Add(li, 1);
axMap1.Layers.LayersDlg("", "");
}
{
MapXLib.LayerInfoClass li = new MapXLib.LayerInfoClass();
MapXLib.Features ftrs = null;
MapXLib.FieldsClass flds = new MapXLib.FieldsClass();
MapXLib.Fields Myflds = null;
MapXLib.Dataset dts = null;
flds.Add(1,"State_Name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString);
dts = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, axMap1.Layers._Item(1), "MyLayer", 0, 0, 0, flds, false);
Myflds = dts.Fields;
ftrs = axMap1.Layers._Item("USA").Selection.Clone();
li.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
li.AddParameter("Name", "USA Temp Layer");
li.AddParameter("Fields", Myflds);
li.AddParameter("Features", ftrs);
axMap1.Layers.Add(li, 1);
axMap1.Layers.LayersDlg("", "");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询