在单元中引用ComObj后:
1。定点画线:
procedure TForm1.Button1Click(Sender: TObject);
var
pt : point;
pts: points;
ln : Line;
begin
pt := point(CreateOleObject('MapObjects2.point'));
pts := points(CreateOleObject('MapObjects2.points'));
pt.X:=map1.Extent.Left;
pt.Y:=map1.Extent.Top-map1.Extent.Height/2;
pts.Add(pt);
pt.X:=map1.Extent.Left+map1.Extent.Width/4;
pt.Y:=map1.Extent.Top-map1.Extent.Height/4;
pts.Add(pt);
pt:=map1.Extent.Center;
pts.Add(pt);
pt.X:=map1.Extent.Center.x+map1.Extent.Width/4;
pt.Y:=map1.Extent.Top-map1.Extent.Height/4;
pts.Add(pt);
ln:=line(CreateOleObject('MapObjects2.line'));
ln.Parts.Add(pts);
map1.TrackingLayer.Refresh(true,'');
end;
2。TrackingLayer层里画线
procedure TForm1.Map1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
pt : point;
pts: points;
ln : Line;
tl : TrackingLayer;
sym: Symbol;
begin
tl:=TrackingLayer(CreateOleObject('MapObjects2.TrackingLayer'));
tl:=map1.TrackingLayer;
tl.SymbolCount:=1;
sym := Symbol(CreateOleObject('MapObjects2.Symbol'));
sym:=tl.Symbol[0]; //定义直线符号
sym.SymbolType:=1;
sym.Color :=moBlue;
sym.style:=moSolidLine;
ln:=line(CreateOleObject('MapObjects2.line'));
ln:=map1.TrackLine;
Map1.TrackingLayer.AddEvent(ln,0);
end;
3。还可以在Map.refresh调用的特定Map事件(AfterTrackingLayer)中,调用DrawShape()画线。