首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi中 地图x鹰眼图的实现

2012-08-17 
delphi中 mapx鹰眼图的实现道理很简单,就是用两个mapx,一个显示大图,一个显示小图,废话少说,直接上代码//

delphi中 mapx鹰眼图的实现

道理很简单,就是用两个mapx,一个显示大图,一个显示小图,废话少说,直接上代码

//声明两个全局变量

var  

layer: CMapXLayer; //鹰眼图中,用于显示显示范围的那个图层,下面详细解释

ftr: CMapXFeature;  //鹰眼框

//窗体创建时,添加鹰眼框图层

procedure TForm1.FormCreate(Sender: TObject);
begin
  layer := map2.Layers.CreateLayer('rectlayer', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;

//大图显示范围变化时,鹰眼图根据大图的情况来显示鹰眼框的大小

procedure TForm1.map1MapViewChanged(Sender: TObject);
var
  tmpFea: CMapXFeature;
  tmpPnts: CMapXPoints;
  tmpStyle: CMapXStyle;
begin

  //绘制鹰眼框
  if layer.AllFeatures.Count = 0 then begin
    tmpStyle := CoStyle.Create;
    tmpStyle.RegionBorderColor := clRed;
    tmpStyle.RegionPattern := miPatternNoFill;
    tmpStyle.RegionBackColor := clRed;
    tmpStyle.RegionBorderWidth := 1;
    tmpFea := map2.FeatureFactory.CreateRegion(map1.Bounds, tmpStyle);
    ftr := layer.AddFeature(tmpFea, EmptyParam);
  end else
  begin
    with ftr.Parts.Item[1] do begin
      RemoveAll;
      AddXY(map1.Bounds.XMin, map1.Bounds.YMin, EmptyParam);
      AddXY(map1.Bounds.XMax, map1.Bounds.YMin, EmptyParam);
      AddXY(map1.Bounds.XMax, map1.Bounds.YMax, EmptyParam);
      AddXY(map1.Bounds.XMin, map1.Bounds.YMax, EmptyParam);
      ftr.Update(ftr, EmptyParam);
    end;
  end;
  //mp2.Zoom := mp1.Zoom;
end;

//鹰眼图坐标变化,大图跟随变化

procedure TForm1.map2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var MapX, MapY: Double;
    x1, y1: Single;
begin
  x1 := x + 0.0;
  y1 := y + 0.0;
  map2.ConvertCoord(x1, y1, MapX, MapY, miScreenToMap);  ;
  map1.CenterX := MapX;
  map1.CenterY := MapY;
end;

delphi中 地图x鹰眼图的实现

热点排行