// 定义常量
const
MINIMAP_R_NAME = 'minimap_rect';
MINIMAP_O_NAME = 'minimap_rect_outline';
MINIMAP_S_NAME = 'minimap_line';
//定义私有变量
minishp: TGIS_Shape; // 鹰眼框
minishpo: TGIS_Shape; // 外围线
miniLine: TGIS_Shape; // 鹰眼中的十字丝
fminiMove: Boolean;
// 声明 过程
procedure miniMapRefresh(Sender: TObject);
procedure TfrmMain.miniMapRefresh(Sender: TObject);
var
ptg1: TGIS_Point;
ptg2: TGIS_Point;
ptg3: TGIS_Point;
ptg4: TGIS_Point;
ptg5, ptg6, ptg7, ptg8: TGIS_Point;
ex: TGIS_Extent;
begin
if GIS.IsEmpty then
exit;
ex := GISm.CS.ExtentFromCS(GIS.CS, GIS.VisibleExtent);
ex := GIS.UnrotatedExtent(ex);
if (ex.XMin < -360) and (ex.XMax > 360) and (ex.YMin < -180) and
(ex.YMax > 180) then
exit;
ptg1 := GisPoint(ex.XMin, ex.YMin);
ptg2 := GisPoint(ex.XMax, ex.YMin);
ptg3 := GisPoint(ex.XMax, ex.YMax);
ptg4 := GisPoint(ex.XMin, ex.YMax);
minishp.Reset;
minishp.Lock(gisLockExtent);
minishp.AddPart;
minishp.AddPoint(ptg1);
minishp.AddPoint(ptg2);
minishp.AddPoint(ptg3);
minishp.AddPoint(ptg4);
minishp.Unlock;
minishpo.Reset;
minishpo.Lock(gisLockExtent);
minishpo.AddPart;
minishpo.AddPoint(ptg1);
minishpo.AddPoint(ptg2);
minishpo.AddPoint(ptg3);
minishpo.AddPoint(ptg4);
minishpo.AddPoint(ptg1);
minishpo.Unlock;
// 用于显示十字丝
ptg5.X := GISm.Left;
ptg5.Y := (ptg1.Y + ptg4.Y) / 2;
ptg6.X := GISm.Left + GISm.Width;
ptg6.Y := (ptg2.Y + ptg3.Y) / 2;
ptg7.X := (ptg1.X + ptg2.X) / 2;
ptg7.Y := 0;
ptg8.X := ptg7.X;
ptg8.Y := GISm.Height;
miniLine.Reset;
miniLine.Lock(gisLockExtent);
miniLine.AddPart;
miniLine.AddPoint(ptg5);
miniLine.AddPoint(ptg6);
miniLine.AddPart;
miniLine.AddPoint(ptg7);
miniLine.AddPoint(ptg8);
miniLine.Unlock;
GISm.Update;
end;
// FormLoad事件中:
llm := TGIS_LayerVector(GisCreateLayer('区县级行政区划', sPathEagle)); // 此处的“sPathEagle”指向与该地图对应的一个shp格式的区域图
llm.UseConfig := false;
llm.Params.Area.Color := clWhite;
llm.Params.Area.OutlineColor := clSilver;
GISm.Add(llm); // add to minimap
lv := TGIS_LayerVector.Create; // minimap transparent rectangle
lv.Transparency := 30;
lv.Params.Area.Color := clRed;
lv.Params.Area.OutlineWidth := -2;
lv.Name := MINIMAP_R_NAME;
lv.CS := llm.CS;
GISm.Add(lv);
minishp := TGIS_LayerVector(GISm.Get(MINIMAP_R_NAME)).CreateShape
(gisShapeTypePolygon);
lw := TGIS_LayerVector.Create;
lw.Params.Line.Color := clMaroon;
lw.Params.Line.Width := -2;
lw.Name := MINIMAP_O_NAME;
lw.CS := llm.CS;
GISm.Add(lw);
minishpo := TGIS_LayerVector(GISm.Get(MINIMAP_O_NAME)).CreateShape
(gisShapeTypeArc);
lx := TGIS_LayerVector.Create;
lx.Params.Line.Color := clMaroon;
lx.Params.Line.Width := -2;
lx.Name := MINIMAP_S_NAME;
lx.CS := llm.CS;
GISm.Add(lx);
miniLine := TGIS_LayerVector(GISm.Get(MINIMAP_S_NAME)).CreateShape
(gisShapeTypeArc);
GISm.FullExtent;
GIS.FullExtent;
GISm.RestrictedExtent := GISm.Extent;
minishp.layer.Extent := GISm.Extent;
GISm.Cursor := crArrow;
fminiMove := false;
// GISAfterPaint事件:
var
ex: TGIS_Extent;
begin
ex := GIS.VisibleExtent;
miniMapRefresh(self);
end;
// GISZoomChange事件:
miniMapRefresh(self);
/* 以上代码只能通过主地图控制鹰眼视图,还不能实现两者之间的互动*/