zjiemarco

导航

Delphi+AO(2)

  1. 地图的放大、缩小、漫游和全景显示
    在Mapcontrol控件的OnMouseDown事件里加入以下的代码:
    procedure TForm1.MapControlMouseDown(Sender: TObject; button, shift, x,
    y: Integer; mapX, mapY: Double);
    var
    envlp: IEnvelope;
    bIsEmpty: wordbool;
    begin
    //在Mapcontrol上按下鼠标左键后做拉框操作,实现地图放大功能
    if (Button = 1) and (Shift = 0) then
    begin
    MapControl.MousePointer := esriPointerZoomIn;
    envlp := MapControl.TrackRectangle;
    envlp.Get_IsEmpty(bIsEmpty);
    if not bIsEmpty then
    MapControl.Extent := envlp
    exit
    end;
    //按下Shift键的同时在Mapcontrol上按下鼠标左键在做点击操作,实现地图缩小功能
    if (Button = 1) and (Shift = 1) then
    begin
    MapControl.MousePointer := esriPointerZoomOut;
    envlp := MapControl.Extent;
    envlp.Expand(2,2,False);
    MapControl.Extent := envlp;
    exit;
    end;
    //在Mapcontrol上按下鼠标右键键后做拖动操作,实现地图漫游功能
    if (Button = 2) and (Shift = 0) then
    begin
    MapControl.MousePointer := esriPointerPanning;
    MapControl.Pan;
    MapControl.MousePointer := esriPointerPan;
    exit;
    end;
    end;

在Mapcontrol控件的OnDoubleClick事件里加入以下的代码:
procedure TForm1.MapControl1DoubleClick(Sender: TObject; button, shift, x,
y: Integer; mapX, mapY: Double);
begin
// 在Mapcontrol上双击,实现地图全景显示功能
MapControl1.Extent := MapControl1.FullExtent;
end;

  1. 地图上添加点状图形标记的功能
    先声明两个窗体Form1的私有变量:
    F_MultiPoint: IMultiPoint;
    F_Pts: IPointCollection;
    再在窗体Form1的OnCreate事件里加入以下的代码:
    F_MultiPoint := CoMultiPoint.Create as IMultiPoint;
    F_Pts := F_MultiPoint as IPointCollection;
    然后给Form1窗体添加一个的用于添加点状图形标记的全局的方法DrawPoint,
    实现代码如下:
    procedure TForm1.DrawPoint;
    var
    pt_cnt,i: integer;
    sym: ICharacterMarkerSymbol;
    pt: IPoint;
    ft: TFont;
    oleft: variant;
    ScreenDisplay: IScreenDisplay;
    ActiveView: IActiveView;
    begin
    ActiveView := MapControl.ActiveView;
    ActiveView.Get_ScreenDisplay(ScreenDisplay);
    F_Pts.Get_PointCount(pt_cnt);
    if pt_cnt > 0 then
    begin
    ScreenDisplay.StartDrawing(0,0);
    for i := 0 to pt_cnt-1 do
    begin
    F_Pts.Get_Point(i,pt);
    sym := coCharacterMarkerSymbol.Create as ICharacterMarkerSymbol;
    sym.Set_Size(30);
    ft := TFont.Create;
    ft.Size := 40;
    ft.Name := 'Wingdings';
    oleft := FontToOleFont(ft);
    sym.Set_Font(IFontDisp(IDispatch(oleft)));
    sym.Set_CharacterIndex(i+33);
    ScreenDisplay.SetSymbol(sym as ISymbol);
    ScreenDisplay.DrawPoint(pt);
    end;
    ScreenDisplay.FinishDrawing;
    end;
    end;

然后在Mapcontrol控件的OnMouseDown事件里加入以下的代码:
//按下Shift键的同时在Mapcontrol上按下鼠标右键在做点击操作,
//实现在地图上添加点状图形标记的功能
if (Button = 2) and (Shift = 1) then
begin
pt := mapcontrol1.ToMapPoint(x,y);
F_Pts.AddPoint(pt,EmptyParam,EmptyParam);
DrawPoint;
exit;
end;
最后,在Mapcontrol控件的OnAfterDraw事件里加入以下的代码:
procedure TForm1.MapControlAfterDraw(Sender: TObject; const
display: IDisplay; phase: TOleEnum);
begin
DrawPoint; //用于刷新添加在地图上的点状图形标
end;
这样,一个包含了一些简单的GIS功能的应用程序就完成了(按F9可以运行)。

posted on 2005-08-17 12:09  zjiemarco  阅读(478)  评论(0)    收藏  举报