阅读:1075回复:1
[求助]在MapX中使用自定义栅格符号遇到的问题
<P>要求根据数据库中某个值(比如NUM)的不同,在与该数据库绑定的图层上显示不同的自定义图符。</P>
<P>网上看到有这样一个例子:</P> <P><b><FONT face=宋体>在</FONT><FONT face="Times New Roman">MapX</FONT>中如何使用自定义栅格符号<p></p></b></P> <P >使用自定义符号首先需要设定<FONT face="Times New Roman">style.SymbolType </FONT>为<FONT face="Times New Roman">miSymbolTypeBitmap</FONT>,然后指定<FONT face="Times New Roman">SymbolBitmapName </FONT>为栅格图像名即可。</P> <P >下面的代码演示了如何在<FONT face="Times New Roman">delphi</FONT>中使用自定义的栅格符号</P> <P >首先调用自定义工具画点</P> <P ><FONT face="Times New Roman">Procedure TForm1.new1Click(Sender: TObject);</FONT></P> <P ><FONT face="Times New Roman">Begin</FONT></P> <P ><FONT face="Times New Roman">map1.ControlInterface.CurrentTool :=111;</FONT></P> <P ><FONT face="Times New Roman">End;</FONT></P> <P >在<FONT face="Times New Roman">tooluses</FONT>事件中如下:</P> <P ><FONT face="Times New Roman">procedure TForm1.Map1ToolUsed(Sender: TObject; ToolNum: Smallint; X1, Y1,X2, Y2, Distance: Double; Shift, Ctrl: WordBool;</FONT></P> <P ><FONT face="Times New Roman">var EnableDefault: WordBool);</FONT></P> <P ><FONT face="Times New Roman">var</FONT></P> <P ><FONT face="Times New Roman">ssymbol :cmapxstyle;</FONT></P> <P ><FONT face="Times New Roman">p: CMapXPoint;</FONT></P> <P ><FONT face="Times New Roman">f: cmapxfeature;</FONT></P> <P ><FONT face="Times New Roman">begin</FONT></P> <P ><FONT face="Times New Roman">ssymbol:=costyle.create;</FONT></P> <P ><FONT face="Times New Roman">ssymbol.SymbolType :=1;</FONT></P> <P ><FONT face="Times New Roman">ssymbol.SymbolBitmapSize:=25;</FONT></P> <P ><FONT face="Times New Roman">{</FONT>请注意将<FONT face="Times New Roman">test.bmp</FONT>文件考到<FONT face="Times New Roman">mapx </FONT>“共有文件路径”<FONT face="Times New Roman">+</FONT>“<FONT face="Times New Roman">\CUSTSYMB</FONT>”路径下<FONT face="Times New Roman">,</FONT>例如<FONT face="Times New Roman">C:\Program Files\Common Files\MapInfo Shared\MapX Common </FONT>是<FONT face="Times New Roman"> MapX </FONT>共有文件的缺省安装路径<FONT face="Times New Roman">}</FONT></P> <P ><FONT face="Times New Roman">ssymbol.SymbolBitmapName:='test.BMP';</FONT></P> <P ><FONT face="Times New Roman">p := CoPoint.Create;</FONT></P> <P ><FONT face="Times New Roman">f :=cofeature.Create ;</FONT></P> <P ><FONT face="Times New Roman">p.Set_(x1,y1);</FONT></P> <P ><FONT face="Times New Roman">if toolnum=111 then begin</FONT></P> <P ><FONT face="Times New Roman">f:=map1.ControlInterface.FeatureFactory.CreateSymbol(p,ssymbol);</FONT></P> <P ><FONT face="Times New Roman">map1.ControlInterface.Layers.Item(1).<FONT color=#ff0000><b>AddFeature(f,EmptyParam);</b></FONT></FONT></P> <P ><FONT face="Times New Roman">end;</FONT></P> <P ><FONT face="Times New Roman">end;</FONT></P> <P ><FONT face="Times New Roman"></FONT> </P> <P ><FONT face="Times New Roman"><b>问题:但是在编译时红字部分</b><FONT color=#ff0000><b>AddFeature(f,EmptyParam);</b><FONT color=#000000><b>老出错,说指定的ROWVALUE值无效</b>(原例中emptyparam忘了定义,我添加一个var emptyparam :variant后还是同样的错误)。<b>我也试使用AddFeature(f); 但还是编译不过,说“参数不够”,到底该如何设置?</b></FONT></FONT></FONT></P> <P ><FONT face="Times New Roman"></FONT> </P> <P ><FONT face="Times New Roman">查看addfeature的帮助如下</FONT></P> <P >[feature=]OBJECT.AddFeature (Source, [RowValues]) </P> <P > 部分 说明 OBJECT 表示 Layer 对象。 Source Source 是 Feature 对象。 RowValues RowValues 表示一行数据的属性数据新值。RowValues 集合中的每个值均相应于属性数据的一列。此参数只适用于 miDatasetLayer 类型的 Dataset。</P> <P > </P> <P >我用的是midatasetado类型的DATASET。不知该如何设置??</P> <P > </P> <P >还有我在MAPX自带的一个OBJECTEDIT的例程中有一个画点的例子</P> <P >procedure TMainMap.Map1ToolUsed(Sender: TObject; ToolNum: Smallint; X1, Y1, X2, Y2, Distance: Double; Shift, Ctrl: Wordbool; var EnableDefault: Wordbool); var newObj : Variant; // Used for storing new feature object pt : Variant; // Used for storing point of click pts : Variant; // Used for storing collection of points ftrs : Variant; // Used for storing collection of features ssymbol:cmapxstyle; begin Case ToolNum of CUSTOM_POINT_TOOL : // Set feature type to be a symbol, set its style ; XY values. // Add it to editing layer begin pt := CreateOleObject('MapX.Point.5'); pt.Set(X1, Y1); ssymbol:=costyle.Create; ssymbol.SymbolType:=miSymbolTypeBitmap; ssymbol.SymbolBitmapName:='wugong_run.bmp'; newObj := Map1.FeatureFactory.CreateSymbol(pt,ssymbol); //ssymbol is the custom style; original:Map1.DefaultStyle EditLayer.<FONT color=#0000ff><b>AddFeature(newObj); //此处蓝字部分也只用了一个参数,</b></FONT></P> <P ><FONT color=#0000ff><b> //却在例程中能编译通过,wei为何??</b></FONT> end; </P> |
|
1楼#
发布于:2005-01-26 11:23
<P>你把下面这句话去掉看看</P><P><FONT face="Times New Roman">f :=cofeature.Create ;</FONT></P>
|
|