阅读:1637回复:1
请教初级问题:C#中如何在可编辑图层中动态增加标注?
<P>MapXLib.Point pt = new MapXLib.Point();<BR> pt.Set(p.X,p.Y);<BR> MapXLib.Style st = new MapXLib.Style();<BR> st.PickSymbol();<BR> MapXLib.Feature f = this.axMap1.FeatureFactory.CreateSymbol(pt,st);<BR> MapXLib.Feature ft = new MapXLib.FeatureClass();<BR> //MapXLib.RowValues rvs =new MapXLib.RowValues();<BR> MapXLib.RowValues rvs =this.axMap1.DataSets._Item("定位图层").get_RowValues(oMissiong).Clone();<BR> <BR> MapXLib.RowValue rv =new MapXLib.RowValueClass();</P>
<P> rv.Field=this.axMap1.DataSets._Item("定位图层").Fields._Item("Name");//._Item(1); <BR> rv.Value="目标1";<BR> rvs.Add(rv); <BR> <BR> rv.Field=this.axMap1.DataSets._Item("定位图层").Fields._Item("ID");//._Item(2);<BR> rv.Value="1000";<BR> rvs.Add(rv);</P> <P> lyr.KeyField = "Name";<BR> f.KeyValue= "vehice1";<BR> ft = lyr.AddFeature(f,rvs); <BR> <BR> f.Update(ft,rvs);</P> <P>执行到 ft = lyr.AddFeature(f,rvs); 时抛出:未将对象引用设置到对象的实例,请问是怎么回事啊?<BR></P> |
|
1楼#
发布于:2005-09-12 14:27
<P> public static void DrawXL(double x, double y,AxMapXLib.AxMap mpMainMap,ref string lay)<BR> {<BR> try<BR> {<BR> mpMainMap.Layers._Item(lay).KeyField = "terminal_Num";<BR> //mpMainMap.Layers._Item("Terminal").GetFeatureByKey<BR> MapXLib.Feature ft = new MapXLib.FeatureClass();<BR> MapXLib.PointClass ptCenter = new MapXLib.PointClass();<BR> MapXLib.Style s=new StyleClass();<BR> MapXLib.RowValuesClass r = new RowValuesClass();</P>
<P> </P> <P> //图元的样式设置<BR> s.SymbolBitmapName = "Mapinfo Symbols";<BR> s.SymbolFont.Size = 8;//大小<BR> s.SymbolCharacter = 33;//36星<BR> s.SymbolFontColor = 1670000;//220;//颜色<BR> <BR> s.SymbolFont.Bold = true;<BR> s.SymbolFontHalo = true;<BR> s.SymbolFontShadow = true;<BR> s.SymbolFontBackColor = 2105376;<BR> s.SymbolBitmapTransparent = true;</P> <P> <BR> //s.SymbolBitmapName = "FIRE1_32";<BR> //s.PickSymbol();<BR> //设置 坐标<BR> ptCenter.Set(x, y);<BR> mpMainMap.Layers._Item(lay).Style = s;<BR> <BR> //增加图元<BR> ft = mpMainMap.FeatureFactory.CreateSymbol(ptCenter,s);<BR> <BR> System.Console.WriteLine(mpMainMap.DataSets.Count);<BR> MapXLib.Dataset ds = mpMainMap.DataSets._Item(lay);<BR> <BR> RowValue newrv = new MapXLib.RowValueClass();<BR> RowValues newrvs = new MapXLib.RowValuesClass();<BR> newrv.Dataset = ds;<BR> MapXLib.Fields fid = ds.Fields;</P> <P> newrv.Field = fid._Item(1);<BR> newrv.Value = Id;<BR> newrvs.Add(newrv);<BR> newrv.Field = fid._Item(2);<BR> newrv.Value = Name;<BR> newrvs.Add(newrv);<BR> <BR> newrv.Field = fid._Item(3);<BR> newrv.Value = Mobile;<BR> newrvs.Add(newrv);</P> <P> newrv.Field = fid._Item(4);<BR> newrv.Value = GlID;<BR> newrvs.Add(newrv);</P> <P> newrv.Field = fid._Item(5);<BR> newrv.Value = GlName;<BR> newrvs.Add(newrv);</P> <P> mpMainMap.Layers._Item(lay).AddFeature(ft,newrvs);<BR> <BR> }<BR> catch (Exception exc)<BR> {<BR> throw exc;<BR> }<BR> //</P> <P> }</P> |
|