那位大哥在帮帮我!!delphi+mapx如何画折线并测量距离??? 只有这末多分了!(30分)

  • 主题发起人 主题发起人 okgxsh
  • 开始时间 开始时间
O

okgxsh

Unregistered / Unconfirmed
GUEST, unregistred user!
那位大哥在帮帮我!!delphi+mapx如何画折线并测量距离????
 
//一下这种方法画完折线后,只能计算第一个点和最后一个点之间的距离!
//如何才能把折线的折点按顺序的采集下来并按顺序的计算距离,然后再累加??

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;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1, Y1, X2,
Y2, Distance:do
uble;
Shift, Ctrl: WordBool;
var EnableDefault: WordBool);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin

map1.Layers.CreateLayer('temp', EmptyParam,1, EmptyParam, EmptyParam);
Map1.Layers.Item(1).Editable := True;
Map1.Layers.InsertionLayer := Map1.Layers.Item(1);

Map1.CurrentTool := miAddPolylineTool;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

map1.Layers.Remove ('temp');
end;


procedure TForm1.Button2Click(Sender: TObject);
begin

Map1.Layers.Remove ('temp');
end;


procedure TForm1.Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1, Y1,
X2, Y2, Distance:do
uble;
Shift, Ctrl: WordBool;
var EnableDefault: WordBool);
var
distStr: string;
sngTemp : Single;
begin

begin

memo1.Lines.Add(floattostr(x1)+'==='+floattostr(y1));
memo1.Lines.Add(floattostr(x2)+'==='+floattostr(y2));
sngTemp := sngTemp +Map1.distance(x1,y1,x2,y2);
showmessage(floattostr(sngtemp));
end;

end;


procedure TForm1.Button3Click(Sender: TObject);
begin

Map1.Currenttool := 1;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
unusedParam: OleVariant;
begin

Map1.CreateCustomTool(1, miToolTypeLine, miSizeCursor, miSizeCursor, miSizeCursor, unusedParam);
end;

end.
 
我给你相关代码,你自己整理一下。距离显示在另一个小窗体。
Map1.CreateCustomTool(miMDistanceRuler, miToolTypePoly, miLabelCursor);
miMDistanceRuler为一常数;
procedure TMapXOperation.Map1MouseMove(Sender: TObject;
Shift: TShiftState;
X, Y: Integer);
var
d, m : integer;
mLon, mLat :do
uble;
begin

mScreenX := X;
mScreenY := Y;
MapX.ConvertCoord(mScreenX, mScreenY, mLon, mLat, miScreenToMap);

if (MapX.CurrentTool=miMDistanceRuler) and mRulerStart then

begin

mDistance := MapX.Distance(mLongitude, mLatitude, mLon, mLat);
frmDistanceRuler.lblDistance.Caption := FloatToStrF(mDistance, ffNumber, 10, 3)+' 公里';
frmDistanceRuler.lblTotalDistance.Caption := FloatToStrF(mDistance+mTotalDistance, ffNumber, 10, 3)+' 公里';
end;

end;

procedure TMapXOperation.Map1PolyToolUsed(Sender: TObject;
ToolNum: Smallint;
Flags: Integer;
const Points: IDispatch;
bShift, bCtrl: WordBool;
var EnableDefault: WordBool);
var
ftrsFinds : Features;
Newobj : Feature;
begin

if ToolNum = miMDistanceRuler then
//测距离
case Flags of
miPolyToolbegin
: begin

mRulerStart := true;
mTotalDistance := 0;
end;

miPolyToolInProgress: mTotalDistance :=mTotalDistance + mDistance;
miPolyToolEnd: mRulerStart := false;
end;

end;

下面用于显示距离的窗体frmDistanceRuler,上面放二个label,名字同上
MapX.CurrentTool := miMDistanceRuler;
if frmDistanceRuler=nil then

frmDistanceRuler := TfrmDistanceRuler.Create(Self);
frmDistanceRuler.formStyle := fsStayOnTop;
frmDistanceRuler.Show;

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

mScreenX := X;
mScreenY := Y;
MapX.ConvertCoord(mScreenX, mScreenY, mLongitude, mLatitude, miScreenToMap);
end;


其中部分是模块变量
 
感谢·!yostgxf 兄!大力帮助!我先试试!!!再来
 
问题解决!再次感谢 yostgxf大力帮助!!!!!

新年快到了!恭祝:新年快乐!发大才!
 
接受答案了.
 
后退
顶部