地理信息?

zwlwenlong 2004-12-08 04:29:32
我做了个程序是要在地图上显示汽车,其中汽车是bmp文件。但是出来的是一个7。请问高手怎么修改?
procedure TForm1.Map1ToolUsed(ASender: TObject; ToolNum: Smallint; X1, Y1,
X2, Y2, Distance: Double; Shift, Ctrl: WordBool;
var EnableDefault: WordBool);
Var
s : variant;
Pnt : cmapxPoint; //点
FeaFac :cmapxFeatureFactory; //地图图元
Lyr : cmapxLayer; //图层
Ftr : cmapxFeature ; //图元对象
NewStyle : cmapxStyle ; //点对象的样式符号
Nothing:variant;
begin
s :=CreateOleObject('MapX.Point.4');
s:=map1.Layers.CreateLayer('temp',emptyparam,emptyparam,emptyparam,emptyparam);
Lyr:=Map1.Layers.Item('temp'); // 新建图层
Lyr.Style.SupportsBitmapSymbols;
Lyr.Style.SymbolBitmapOverrideColor;
FeaFac:=map1.featurefactory; //土元
NewStyle:=Lyr.Style;
//NewStyle.SupportsBitmapSymbols;
// NewStyle.SymbolBitmapOverrideColor;
With NewStyle do
begin
SymbolType:=miSymbolTypeBitmap; //SymbolType是如何显示点图元(以图)
SymbolBitmapSize:= 24 ;
SymbolBitmapTransparent:= False ;
SymbolBitmapName:='F:\应用mapx\导入bmp文件\GiftService.bmp';
end;
map1.AutoRedraw:=False; //禁止自动刷新
Lyr.Editable:=True;//置当前图层为可写状态
pnt := CoPoint.Create;
pnt.Set_(x1,y1);
//Lyr.SearchAtPoint(s,emptyparam); //'创建点对象
//'添加进当前图层
Ftr:=FeaFac.CreateSymbol(Pnt,Newstyle);
Ftr:=FeaFac. CreateSymbol (Pnt,map1.DefaultStyle);
Lyr.AddFeature(Ftr,EmptyParam);
Lyr.Refresh;
Map1.AutoRedraw:=True;
Lyr.Editable:=False;
end;

另我也做了一个别的程序也是显示汽车的
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MapXLib_TLB, StdCtrls;

type
TForm1 = class(TForm)
Map1: TMap;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure car;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
var
dxpos,dypos:double;
{$R *.dfm}

{ TForm1 }

procedure TForm1.car;
var
G_CarLayer:MapXLib_TLB.layer;
fMapSymbol:MapXLib_TLB.Feature;
fNewSymbol:MapXLib_TLB.Feature;
begin
dxpos:= Map1.CenterX;
dypos:= Map1.CenterY;
G_CarLayer:=Map1.Layers.CreateLayer('temp',emptyparam,emptyparam,emptyparam,emptyparam);
G_CarLayer.Style.SupportsBitmapSymbols;
G_CarLayer.Style.SymbolBitmapOverrideColor;
Map1.Layers.AnimationLayer:=G_CarLayer;
fNewSymbol.Attach(map1);
With Map1.DefaultStyle do
begin
// SymbolFont: = 'custom symbols';
SymbolType :=1;
SymbolBitmapName :='TEMP1-32.BMP';
SymbolBitmapSize:= 24;
SymbolBitmapTransparent := True;
end;
fNewSymbol.Type_:=miFeatureTypeSymbol;
fNewSymbol.Style:=Map1.DefaultStyle;
fNewSymbol.Point.Set_(dxpos, dypos) ;
fMapSymbol:=G_CarLayer.AddFeature(fNewSymbol,emptyparam);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
car;
end;

end.其中一直说fNewSymbol.Attach(map1);有问题,请问怎么解决啊?
...全文
143 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwlwenlong 2004-12-09
  • 打赏
  • 举报
回复
谢谢各位大哥大姐了。终于可以了啊。
anbeel 2004-12-09
  • 打赏
  • 举报
回复
用于显示的BMP图片必须放在MapX安装目录下的CUSTSYMB子目录下,存为不大于256色的图片,这样才可以用.SymbolBitmapName = "XXX.BMP"这样的语句来调用显示。
zwlwenlong 2004-12-09
  • 打赏
  • 举报
回复
我怎么加的bmp文件后是一个黑块啊?怎么回事?
zwlwenlong 2004-12-09
  • 打赏
  • 举报
回复
to: okgxs(一叶风铃) ,谢了。去研究一下~~
okgxs 2004-12-09
  • 打赏
  • 举报
回复
procedure TForm1.Button4Click(Sender: TObject);
var
ssymbol :cmapxstyle;
p: CMapXPoint;
f: cmapxfeature;
FoundObject :CMapXFindFeature ;
begin
I:=i+1;
ssymbol:=costyle.create;
ssymbol.SymbolType :=1;
ssymbol.SymbolBitmapSize:=25;
ssymbol.SymbolBitmapName:='ambelut.BMP';
ssymbol.SymbolBitmapTransparent:=true;
p := CoPoint.Create;
f :=cofeature.Create ;
p.Set_(strtofloat(edit1.Text), strtofloat(edit2.Text));
//if toolnum=111 then begin
f:=map1.ControlInterface.FeatureFactory.CreateSymbol(p,ssymbol);
f.KeyValue :='急救车'+inttostr(I);
map1.ControlInterface.Layers.Item(1).AddFeature(f,EmptyParam);
// map1.ControlInterface.Layers.
// f.
map1.Refresh;

end;
okgxs 2004-12-09
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
Bitmaps: BitmapSymbols;
StyleBitmap : Style;
pt:Point;
fNewSymbol: Variant;
// fMapSymbol: Feature;
lyrLayer :Layer;
aaa:CMapXStyle;
begin
map1.Layers.CreateLayer('急救站', EmptyParam,1, EmptyParam, EmptyParam);
Map1.Layers.Item(1).Editable := True;
Map1.Layers.InsertionLayer := Map1.Layers.Item(1);
lyrLayer:=map1.Layers.Item(1);
lyrLayer.AutoLabel:=true;
lyrlayer.Editable:=true;
end;
okgxs 2004-12-09
  • 打赏
  • 举报
回复
procedure TForm1.MovePoint(Id:string;X, Y: double);
var
i : Integer;
Bitmaps: BitmapSymbols;
StyleBitmap : Style;
pt:Point;
fNewSymbol: Variant;
aaa:CMapXStyle;
lyrLayer :Layer;
begin
//========================================================================
lyrLayer:=map1.Layers.Item('急救站');
Bitmaps := CoBitmapSymbols.Create; //Bitmaps.Count
StyleBitmap := coStyle.Create;
with StyleBitmap do
begin
SymbolType := miSymbolTypeBitmap;
SymbolBitmapTransparent := True;
SymbolBitmapSize := 24;
end;
//显示目标图标
pt:=CoPoint.Create;
pt.Set_(0, 0);
aaa:=CreateOleObject('MapX.Style.4') as CMapXStyle;
aaa.SymbolType:=1;
aaa.SymbolBitmapTransparent:=true;
aaa.SymbolBitmapName:='ambelut.BMP';//
aaa.SymbolBitmapSize:=10;
Map1.DefaultStyle:=aaa;
SetLength(GoalFeature, 200);//车的数量
for i:=0 to Length(GoalFeature)-1 do
begin
StyleBitmap.SymbolBitmapName :=aaa.SymbolBitmapName ; //选的图标
fNewSymbol := Map1.FeatureFactory.CreateSymbol(pt, StyleBitmap);
fNewSymbol.KeyValue :=inttostr(i);//+'号急救车';
// fNewSymbol := lyrLayer.AddFeature(fNewSymbol, EmptyParam);
//可以重复往里面加Feature
GoalFeature[i] := lyrLayer.AddFeature(fNewSymbol, EmptyParam);

end;
VarClear(fNewSymbol);
end;
zwlwenlong 2004-12-08
  • 打赏
  • 举报
回复
有做这方面的吗?给帮帮
zwlwenlong 2004-12-08
  • 打赏
  • 举报
回复
to: okgxs(一叶风铃)
有没有delphi的?vb的我也看到了不少,但是转为delphi后出问题了。我对vb没有经验。谢谢了。
okgxs 2004-12-08
  • 打赏
  • 举报
回复
必要:创建地图对象,必须使用FeatureFactory对象

1、 创建一个点对象

点对象有一个坐标点(X,Y),点对象变量是Point类型,点对象的样式(Style)是符号

样式。

Dim Pnt AS MapXLib.Point

Dim FeaFac AS MapXLib.FeatureFactory

Dim Lyr AS MapXLib.Layer

Dim Ftr AS MapXLib.Feature

Dim NewStyle AS MapXLib.Style



‘绑定

SET Lyr=MainMap.Layers.Item(LayerName)

SET FeaFac=mainmap.featurefactory

‘设置点对象样式

With NewStyle

.SymbolType = miSymbolTypeBitmap

.SymbolBitmapSize = 24

.SymbolBitmapTransparent = False

.SymbolBitmapName = "YIEL2-32.BMP"

End With

Mainmap.AutoRedraw=False ‘禁止自动刷新

Lyr.Editable=True ‘置当前图层为可写状态

‘创建点对象

pnt.set X1,Y1

‘添加进当前图层

Set Ftr=FeaFac. CreateSymbol (Pnt,Newstyle) ‘创建符号

‘Set Ftr=FeaFac. CreateSymbol (Pnt,MainMap.DefaultStyle)

‘添加

Lyr.AddFeature Ftr

Lyr.Refresh

Mainmap.AutoRedraw=True

Lyr.Editable=False

‘释放

SET Pnt = Nothing

SET FeaFac = Nothing

SET Lyr = Nothing

SET Ftr = Nothing

‘以上代码放在MapX的ToolUsed事件下



单独修改某个图元的样式:SET Ftr.Style=NewStyle,再用Update 即可

2、 创建一个线矩形

Dim Pnts AS MapXLib.Points



With NewStyle

.LineColor=Rgb(0, 0,255)

End With

‘第一个点

Pnt.Set X1,Y1

Pnts.add Pnt

‘第二个点

Pnt.Set X2,Y1

Pnts.add Pnt

‘第三个点

Pnt.Set X2,Y2

Pnts.add Pnt

‘第四个点

Pnt.Set X1,Y2

Pnts.add Pnt

‘第五个点

Pnt.Set X1,Y1

Pnts.add Pnt



‘创建线矩形

SET Ftr=FeaFac.CreateLine(Pnts,NewStyle)

Lyr.AddFeature Ftr

Lyr.Refresh



3、 上面创建对象中存在的问题:并未对其数据数据进行赋值

创建对象的同时创建其数据集合

Dim Pnt AS MapXLib.Point

Dim FeaFac AS MapXLib.FeatureFactory

Dim Lyr AS MapXLib.Layer

Dim Ftr AS MapXLib.Feature

Dim NewStyle AS MapXLib.Style

Dim ds AS MapXLib.Dataset

Dim Flds AS MapXLib.Fields



‘绑定

SET Lyr=MainMap.Layers.Item(LayerName)

SET ds=Lyr.Datasets.Item(1)

Set Flds=ds.Fields

SET FeaFac=mainmap.featurefactory

‘设置点对象样式

With NewStyle

.SymbolType = miSymbolTypeBitmap

.SymbolBitmapSize = 24

.SymbolBitmapTransparent = False

.SymbolBitmapName = "YIEL2-32.BMP"

End With

Mainmap.AutoRedraw=False ‘禁止自动刷新

Lyr.Editable=True ‘置当前图层为可写状态

‘创建点对象

pnt.set X1,Y1

‘创建图形

Set Ftr=FeaFac. CreateSymbol (Pnt,Newstyle) ‘创建符号

‘Set Ftr=FeaFac. CreateSymbol (Pnt,MainMap.DefaultStyle)

‘设置属性

For I=1 to Flds.Count

Lyr.KeyFields=Flds.Item(i).Name

Ftr.KeyValue=ValueStr(I) ‘这里并没有对字段类型进行判断

Next

‘另外一种方法:使用RowValues和RowValue对象

‘添加

Lyr.AddFeature Ftr

Lyr.Refresh

Mainmap.AutoRedraw=True

Lyr.Editable=False

‘释放

SET Pnt = Nothing

SET FeaFac = Nothing

SET Lyr = Nothing

SET Ftr = Nothing



SET ds = Nothing

SET Flds = Nothing

4、 创建表

(1) 临时表:

A、用MainMap.Layers.CreateLayer方法创建临时表。但这个临时表只有一个字段:GeoNa

me( Char 24)。程序运行过程中该表存放位置为系统临时文件夹下

B、使用LayerInfo对象创建临时表,可以指定字段。示例:



Dim Lyr As MapXLib.Layer

Dim LayerInfo As New MapXLib.LayerInfo

Dim Flds As New MapXLib.Fields



‘字段定义

Flds.AddStringField "ID", 12

Flds.AddStringField "Name", 50

Flds.AddNumericField "Deptch", 12, 2

Flds.AddIntegerField "Length"



´

LayerInfo.Type = miLayerInfoTypeTemp

LayerInfo.AddParameter "FileSpec", FileName

LayerInfo.AddParameter "NAME", LayerName

LayerInfo.AddParameter "Fields", Flds



Set Lyr = MainMap.Layers.Add(LayerInfo, 1)



Set Lyr = Nothing

Set LayerInfo = Nothing



(2) 创建永久表

Dim Lyr As MapXLib.Layer

Dim LayerInfo As New MapXLib.LayerInfo

Dim Flds As New MapXLib.Fields



Flds.AddStringField "ID", 12

Flds.AddStringField "Name", 50

Flds.AddNumericField "Deptch", 12, 2

Flds.AddIntegerField "Length"



´

LayerInfo.Type = miLayerInfoTypeNewTable

LayerInfo.AddParameter "FileSpec", FilePath + "" + FileName

LayerInfo.AddParameter "NAME", LayerName

LayerInfo.AddParameter "Fields", Flds



Set Lyr = MainMap.Layers.Add(LayerInfo, 1)



Set Lyr = Nothing

Set LayerInfo = Nothing





5、 创建工具句柄

系统已经定义工具句柄都以整数(包括16进制)常数存在,句柄号大于1000和小于12基本

都为系统使用。

A. 定义常数:必须为全局变量

Global Const CreateSymbolTool = 13 ´创建节点

Global Const CreateLineTool = 15 ´创建管线

Global Const InfoTipTool = 16 ´信息工具

Global Const MoveFeature = 17 ´移动地图

Global Const ScaleDistanceTool = 18 ´测量两点间的距离



B. 使用CreateCustomTool创建新的工具句柄:

MainMap.CreateCustomTool CreateSymbolTool, miToolTypePoint, miSymbolCursor

MainMap.CreateCustomTool CreateLineTool, miToolTypeLine, miCrossCursor

MainMap.CreateCustomTool InfoTipTool, miToolTypePoint, miCrossCursor

MainMap.CreateCustomTool MoveFeature, miToolTypeLine, miPanCursor

MainMap.CreateCustomTool ScaleDistanceTool, miToolTypeLine, miPanCursor

C. 如何使用?

在Map对象的ToolUsed事件的ToolNum参数为当前所激活的工具

使当

前操作指向某行为:MainMap.CurrentTool=工具句柄号,如放大:MainMap.CurrentTool=

miZoomInTool,移动图元:MainMap.CurrentTool=MoveFeature

操作具体的工具句柄时,执行该捕捉到的工具句柄的代码:

在ToolUsed事件中:



Select Case ToolNum

Case MoveFeature

‘执行代码

End Select


删除图元:Lyr.DeleteFeature Ftr
okgxs 2004-12-08
  • 打赏
  • 举报
回复
你可以到www.Delphibbs.com 的 新技术GIS 板块 查询一下,应该有的!
okgxs 2004-12-08
  • 打赏
  • 举报
回复
SymbolBitmapName:='F:\应用mapx\导入bmp文件\GiftService.bmp';
显示的图片,你最好用Mapx自带的图片或者尺寸大小一样的图片。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧