没入门,请问怎么将一个小图标放到地图的某个位置~~~(50分)

  • 主题发起人 主题发起人 neverdeath
  • 开始时间 开始时间
N

neverdeath

Unregistered / Unconfirmed
GUEST, unregistred user!
在Mapx5中,怎样将小图标放到地图的某个位置?
 
是不是我说的不明白,就是增删站点图标的功能。
 
大家说说好不?我找了一点,但总是不行
procedure TForm1.Button2Click(Sender: TObject);
var ssymbol:mapxlib_tlb.style;
p:mapxlib_tlb.point;
f:mapxlib_tlb.feature;
begin

ssymbol:=costyle.Create;
ssymbol.SymbolType;
ssymbol.SymbolBitmapSize:=25;
ssymbol.SymbolBitmapName:='towe1-32.bmp';
p:=copoint.Create;
f:=cofeature.Create;
p.Set_(1062,-751);
f:=map1.FeatureFactory.CreateSymbol(p,ssymbol);
map1.Layers.Item[1].AddFeature(f,emptyparam);
end;
 
看不懂,你都没入门那我更是门外汉了。
mapxlib_tlb.style是个什么控件包的
 
mapxlib_tlb是Mapx安装后的 pas文件
 
各位仁兄,我快受不了了,能不能拉小弟一把,我感觉不应该难呀,是不是太简单,大家不屑一顾呀!
 
你到Mapx5安装目录下的demo可以看到一个演示程序,是关于车辆移动的。贴图片可以创建活动图层加个标签,或者动态创建INAGE来弄。想入门建议你去看一本《地理信息系统组件编程》那边书。
 
不好意思,我下得mapx5没有DEMO,你能发给我么?我的邮箱是neverdeath@163.com
 
你把Mapx5重装一下,安装时候有个选项让你选择示例程序的语言,你选DELPHI就有的啊。偶现在已经不做这个东西,如果你还没有的话,我可以等有空发个给你。
 
看来是不行了,我又从www.mapinfo.com.cn上下了个,耽误了点时间,见谅,安的时候没看见提示选择示例程序的语言,我记得曾经有过DEMO,不过是Mapx4的。如果有时间的话,帮忙发一下吧!嘿嘿
 
已经发了
 
谢谢,我刚开见,去瞅瞅~~
 
老大,是不是没有车辆运行的呀~
 
我也在学习中,楼主搞通了给说贴上啊
 
好的,谢谢弟兄们的支持,可是没高手,时间上可能会长点哈~~~
 
这样试试看能看见不
procedure TForm1.Button2Click(Sender: TObject);
var ssymbol:mapxlib_tlb.style;
p:mapxlib_tlb.point;
f:mapxlib_tlb.feature;
begin

ssymbol:=costyle.Create;
ssymbol.SymbolType:=misymboltypebitmap;
ssymbol.SymbolBitmapSize:=25;
ssymbol.SymbolBitmapName:='towe1-32.bmp';
p:=copoint.Create;
f:=cofeature.Create;
p.Set_(1062,-751);
f:=map1.FeatureFactory.CreateSymbol(p,ssymbol);
map1.Layers.Item[1].AddFeature(f,emptyparam);
Map1.Layers.Item[1].Refresh;
map1.CenterX=1062;
map1.CenterY=-751;
end;
 
现在的人一问问题怎么都喜欢要把源码贴出来啊。其实入门不是会几行代码,关键是要把其对象,结构搞明白。要不然碰到下一个问题还是要人家怎么写代码,呵呵,建议楼主可以去一些Gis二次开发网站看看。
 
信兄,不好意思,去听课了。还是不行,结果是空白一片。
 
//demo
unit CarTrackerFrm;

interface

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

type
TfrmCarTracker = class(TForm)
cmdPlotCar: TButton;
cmdSetStyle: TButton;
cmdLayerControl: TButton;
Timer1: TTimer;
vehicleLabel: TLabel;
lstCars: TListBox;
grpbxVehicleInformation: TGroupBox;
lblVehicleName: TLabel;
lblVehicleHeading: TLabel;
lblVehicleSpeed: TLabel;
txtVehicleName: TEdit;
txtVehicleHeading: TEdit;
txtVehicleSpeed: TEdit;
ZoomInBtn: TButton;
ZoomOutBtn: TButton;
Map1: TMap;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure cmdPlotCarClick(Sender: TObject);
procedure cmdSetStyleClick(Sender: TObject);
procedure cmdLayerControlClick(Sender: TObject);
procedure Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1, Y1, X2,
Y2, Distance:do
uble;
Shift, Ctrl: Wordbool;
var EnableDefault: Wordbool);
procedure lstCarsClick(Sender: TObject);
procedure txtVehicleNameChange(Sender: TObject);
procedure txtVehicleHeadingChange(Sender: TObject);
procedure txtVehicleSpeedChange(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Map1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure ZoomInBtnClick(Sender: TObject);
procedure ZoomOutBtnClick(Sender: TObject);
private
procedure updateListCars;
public
{ Public declarations }
end;


type
TVehicle = record //车辆结构
fFeature : Variant;
//图元
sName : String;

iSpeed : Integer;
//速度
dHeading :do
uble;//方向
end;


Const
PLOT_VEHICLE_TOOL = 1;
VEHICLE_LIMIT = 9;

var
frmCarTracker: TfrmCarTracker;
fArray: Array[0..VEHICLE_LIMIT] of TVehicle;
lyrMyLayer: Variant;
st: Variant;
iVehicleCount: Integer;
iCarNum: Integer;

implementation

{$R *.DFM}

procedure TfrmCarTracker.FormCreate(Sender: TObject);
begin

// Set vehicle count initially to zero
iVehicleCount := 0;

// disable data text boxes initially
txtVehicleName.Enabled := False;
txtVehicleHeading.Enabled := False;
txtVehicleSpeed.Enabled := False;
end;


procedure TfrmCarTracker.FormActivate(Sender: TObject);
var
unusedVt: OleVariant;
MyFont: TFont;
begin

TVarData(unusedVt).vType := varError;
TVarData(unusedVt).vError := 2147614724;
// DISP_E_PARAMNOTFOUND;
// 创建图层
lyrMyLayer := Map1.Layers.CreateLayer('Cars', unusedVt, 1, unusedVt, unusedVt);

//成为活动图层
Map1.Layers.AnimationLayer := Map1.Layers.Item[lyrMyLayer.name];

// Create custom tool to be used to plot vehicles
Map1.CreateCustomTool(PLOT_VEHICLE_TOOL, miToolTypePoint, miSizeCursor, miSizeCursor, miSizeCursor, unusedVt);

MyFont := TFont.Create;
OleFontToFont(Map1.DefaultStyle.SymbolFont, MyFont);
MyFont.Size := 24;
MyFont.Name := 'MapInfo Transportation';
Map1.DefaultStyle.SymbolCharacter := 66;
end;


procedure TfrmCarTracker.cmdPlotCarClick(Sender: TObject);
begin

// Set active tool to be vehicle plotting tool
Map1.CurrentTool := PLOT_VEHICLE_TOOL;
end;


procedure TfrmCarTracker.cmdSetStyleClick(Sender: TObject);
begin

// Display symbol picker dialog
Map1.DefaultStyle.PickSymbol;
end;


procedure TfrmCarTracker.cmdLayerControlClick(Sender: TObject);
var
unusedVt: OleVariant;
begin

TVarData(unusedVt).vType := varError;
TVarData(unusedVt).vError := 2147614724;
//DISP_E_PARAMNOTFOUND;
// Display MapX stock layer control dialog
Map1.Layers.LayersDlg(unusedVt, unusedVt);
end;


procedure TfrmCarTracker.Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1, Y1, X2, Y2, Distance:do
uble;
Shift, Ctrl: Wordbool;
var EnableDefault: Wordbool);
var
fNewSymbol: Variant;
fMapSymbol: Variant;
fFtrFactory : Variant;
pItem : Variant;
begin

Case ToolNum of
PLOT_VEHICLE_TOOL :
begin

if iVehicleCount <= 9 then

begin

// Create standAlone feature object
fFtrFactory := Map1.FeatureFactory;

// Create point object to pass to CreateSymbol
pItem := CreateOleObject('MapX.Point.5');
pItem.Set(X1, Y1);

//User Feature Factory to create new Feature
fNewSymbol := fFtrFactory.CreateSymbol(pItem, Map1.DefaultStyle);

// Add Feature to layer
fMapSymbol := lyrMyLayer.AddFeature(fNewSymbol);

// Set form controls for newly added feature
fArray[iVehicleCount].fFeature := fMapSymbol;
fArray[iVehicleCount].iSpeed := 0;
fArray[iVehicleCount].dHeading := 0;
fArray[iVehicleCount].sName := 'Vehicle ' + intToStr(iVehicleCount + 1);

// call updatelist function
updateListCars;

// increase vehicle count by 1
iVehicleCount := iVehicleCount + 1;

// clear memory of variant variables
VarClear(fNewSymbol);
VarClear(fMapSymbol);
end
else

ShowMessage('Reached Car Limit. Limit: 10');
end // Case PLOT_VEHICLE_TOOL
end // Case Statement
end;


procedure TfrmCarTracker.updateListCars;
var
iCount: Integer;
iSelected: Integer;
begin

// Clear listbox and re-add all vehicl
iSelected := lstCars.ItemIndex;
lstCars.Clear;
for iCount := 0 to iVehicleCountdo

lstCars.Items.Add(fArray[iCount].sName);
lstCars.ItemIndex := iSelected;
end;


procedure TfrmCarTracker.lstCarsClick(Sender: TObject);
var
sTemp: String;
begin

iCarNum := lstCars.ItemIndex;
// update controls when different vehicle is chosen in the
// vehicle list box
txtVehicleName.Enabled := True;
txtVehicleHeading.Enabled := True;
txtVehicleSpeed.Enabled := True;

txtVehicleName.Text := fArray[iCarNum].sName;

Str(fArray[iCarNum].dHeading:5:0, sTemp);
txtVehicleHeading.Text := TrimLeft(sTemp);

txtVehicleSpeed.Text := intToStr(fArray[iCarNum].iSpeed);
end;


procedure TfrmCarTracker.txtVehicleNameChange(Sender: TObject);
begin

// If vehicle name is changed, update the feature
fArray[iCarNum].sName := txtVehicleName.Text;
fArray[iCarNum].fFeature.KeyValue := txtVehicleName.Text;
fArray[iCarNum].fFeature.Update;
updateListCars;
end;


procedure TfrmCarTracker.txtVehicleHeadingChange(Sender: TObject);
begin

if txtVehicleHeading.Text <> '' then

begin

fArray[iCarNum].dHeading := StrToFloat(txtVehicleHeading.Text);
fArray[iCarNum].fFeature.Update;
end;

end;


procedure TfrmCarTracker.txtVehicleSpeedChange(Sender: TObject);
begin

if txtVehicleSpeed.Text <> '' then

begin

fArray[iCarNum].iSpeed := StrToInt(txtVehicleSpeed.Text);
fArray[iCarNum].fFeature.Update;
end;

end;


procedure TfrmCarTracker.Timer1Timer(Sender: TObject);
var
dYcomp, dXcomp, dYpos, dXpos:do
uble;
iCount: Integer;
begin

for iCount := 0 to iVehicleCount - 1do

begin

if fArray[iCount].iSpeed <> 0 then

begin

with fArray[iCount]do

begin

dYcomp := iSpeed * Sin(dHeading * 3.14159 / 180);
dXcomp := iSpeed * Cos(dHeading * 3.14159 / 180);
dYpos := fFeature.CenterY + (1 / 69 * dYcomp * Timer1.interval / 1000 * 1 /3600);
dXpos := fFeature.CenterX + (1 / 69 * dXcomp * Timer1.interval / 1000 * 1 /3600);
fFeature.Point.Set(dXpos, dYpos);
fFeature.Update;
end;

//with
end;

//if
end;

//for
end;


procedure TfrmCarTracker.Map1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin

case button of
mbRight : Map1.PropertyPage;
end;

end;


procedure TfrmCarTracker.ZoomInBtnClick(Sender: TObject);
begin

Map1.CurrentTool := miZoomInTool;
end;


procedure TfrmCarTracker.ZoomOutBtnClick(Sender: TObject);
begin

Map1.CurrentTool := miZoomOutTool;
end;


en
 
To jacket84:
不好意思给你添麻烦了,我是找了好久资料没解决才问的。
GIS帝国论坛,Gis fotum ,James Mapinfo 我都去找过资料,没解决才会出来请教的。
 
后退
顶部