www.pudn.com > drawgistext.rar > Drawtext.pas


unit Drawtext; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ComObj, 
  StdCtrls, OleCtrls, ActiveX, MapObjects2_TLB,sample; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Button2: TButton; 
    Edit1: TEdit; 
    Map1: TMap; 
    procedure Button2Click(Sender: TObject); 
    procedure Map1AfterTrackingLayerDraw(Sender: TObject; hDC: Cardinal); 
    procedure Button1Click(Sender: TObject); 
    procedure Map1MouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure FormShow(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form1   : TForm1; 
  gIMoLine  : IMoLine; 
  sampl   : Tsample; 
  tHeight : double; 
  a       :integer; 
  pts     : IMoPoints; 
implementation 
 
{$R *.DFM} 
 
 
{******************************************************************************} 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
 Map1.Extent :=Map1.fullExtent; 
end; 
 
 
{******************************************************************************} 
procedure TForm1.Map1AfterTrackingLayerDraw(Sender: TObject; hDC: Cardinal); 
var 
 tsym  : IMoTextSymbol; 
 sym   : IMoSymbol; 
 ft    : TFont; 
 oleFt : variant; 
begin 
ft := TFont.Create; 
ft.Name := 'Times New Roman'; 
ft.size := 35; 
oleFt := FontToOleFont(ft); 
 
// make sure there is a line 
if  VarIsEmpty(gIMoLine)=false then 
  begin 
  // make sure there are at least 2 points in the line 
 
   if IMoPoints(gIMoLine.Parts.item(0)).count>1 then 
     begin 
       tsym :=IMoTextSymbol(CreateOleObject('MapObjects2.TextSymbol')); 
       sym := IMoSymbol(CreateOleObject('MapObjects2.Symbol')); 
       // use the font of the edit box control 
       tsym.font := IFontDisp(IDispatch(FontToOleFont(edit1.font))); 
       sym.color :=clred; 
       tsym.Height :=tHeight; 
       tsym.Font := IFontDisp(IDispatch(oleFt)); 
       Map1.DrawShape(gIMoLine,sym); 
       Map1.DrawText(edit1.text,gIMoLine,tsym); 
     end; 
  end; 
 
  ft.Free; 
end; 
 
 
{******************************************************************************} 
procedure TForm1.Button1Click(Sender: TObject); 
var 
 v : Variant; 
begin 
 // get rid of the line 
 gIMoLine := nil; 
 
 Map1.TrackingLayer.Refresh (True,v); 
 pts := nil; 
 pts := IMoPoints(CreateOleObject('MapObjects2.Points')); 
end; 
 
 
{******************************************************************************} 
procedure TForm1.FormShow(Sender: TObject); 
var 
 dc    : IMoDataConnection; 
 layer : IMoMapLayer; 
begin 
 
  pts := IMoPoints(CreateOleObject('MapObjects2.Points')); 
  dc := IMoDataConnection(CreateOleObject('MapObjects2.DataConnection')); 
  dc.DataBase :=sampl.ReturnDataPath('usa'); 
  if not dc.connect then exit; 
 
  layer := IMoMapLayer(CreateOleObject('MapObjects2.MapLayer')); 
  layer.GeoDataset :=dc.FindGeoDataSet('states'); 
  IMoSymbol(layer.Symbol).Color := moPaleYellow; //13697023; 
  Map1.Layers.Add(Layer); 
 
  tHeight :=Map1.Extent.height/8; 
 
end; 
 
 
{******************************************************************************} 
procedure TForm1.Map1MouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
var 
   p : IMoPoint; 
   r : IMoRectangle; 
   v : Variant; 
Begin 
    inc(a); 
    if button =mbleft then 
   // create the line if it does not exist 
   begin 
    if  VarIsEmpty(gIMoLine)=true then 
       gIMoLine := IMoLine(CreateOleObject('MapObjects2.line')); 
 
     // create a point and add it to the line 
     p :=IMoPoint(CreateOleObject('MapObjects2.Point')); 
     p :=Map1.ToMapPoint(x,y); 
     pts.add(p); 
 
     if pts.count =1 then 
       begin 
        gIMoLine.parts.add(pts); 
        pts := IMoPoints(gIMoLine.parts.item(0)); 
       end; 
 
     // refresh the trackinglayer 
     Map1.TrackingLayer.refresh(True,v); 
   end 
 
  else 
   begin 
     r := IMoRectangle(CreateOleObject('MapObjects2.Rectangle')); 
     r :=Map1.TrackRectangle; 
    if VarIsEmpty(r)=false then 
       Map1.Extent :=r; 
   end; 
end; 
 
 
 
 
end.