Nous allons voir comment incruster une mini carte synchronisée sur la carte principale
Design
Placez un TPanel sur votre composant TECNativeMap, fixez les propriétés color à clWhite, BevelInner et BevelOuter à false et BorderWidth à 4
Déposez sur le TPanel un composant TECNativeMap avec ses propriétés Align à alClient, dblClickZoom et Draggable à false
Code
La mini carte devra être centrée sur la carte principale avec un zoom 5 crans en dessous, et nous y dessinerons une zone rectangulaire correspondante à la vue de la carte principale.
procedure TForm1.UpdateMiniMap;
begin
// if the call comes from the
direct change of the minimap, you must leave otherwise we
go into an infinite loop
if minimap.tag =
1 then exit;
// indicates that map has initiated
the movement
map.tag := 1;
if not assigned(FMiniPolygone) then
begin
minimap.ShowCopyrightTile := false;
minimap.shapes.Polygones.add(0,0) ;
FMinipolygone := minimap.shapes.Polygones[0];
FMinipolygone.ShowText := false;
FMinipolygone.fillColor := clBlue;
FMinipolygone.hoverColor := clBlue;
FMinipolygone.Opacity := 50;
minimap.OnChangeMapZoom := minimapChangeMapZoom;
minimap.OnMapMove := minimapMapMove;
end;
minimap.setCenter(Map.latitude,Map.longitude);
minimap.zoom := Map.zoom - 5;
FMinipolygone.SetPath([ Map.SouthWestLatitude,
Map.SouthWestLongitude,
Map.SouthWestLatitude, Map.NorthEastLongitude,
Map.NorthEastLatitude, Map.NorthEastLongitude,
Map.NorthEastLatitude, Map.SouthWestLongitude,
Map.SouthWestLatitude, Map.SouthWestLongitude
]);
map.tag := 0;
end;
Vous devrez appeler UpdateMiniMap dans les événenemts OnMapMove et OnChangeMapBounds de la carte principale.
Vous devrez aussi répondre aux événements OnMapMove et OnChangeMapBounds pour ajuster la vue de la carte principale lorsque l'on actionne directement la mini carte, sans oublier d'ajuster la position de la minimap dans l'événement OnResize
unit
UMainNativeMiniMap;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, uecNativeMapControl, ExtCtrls,
StdCtrls,uecNativeShape;
type
TForm1 = class(TForm)
Panel1: TPanel;
Map: TECNativeMap;
plus: TButton;
Button1: TButton;
pnMiniMap: TPanel;
minimap: TECNativeMap;
procedure FormCreate(Sender:
TObject);
procedure MapMapMove(sender:
TObject; const Lat, Lng:
Double);
procedure MapResize(Sender:
TObject);
procedure
MapChangeMapBounds(Sender: TObject);
procedure
minimapMapMove(sender: TObject; const Lat, Lng: Double);
procedure
minimapChangeMapZoom(Sender: TObject);
private
{ Déclarations privées
}
procedure
UpdateMiniMap;
var FMiniPolygone :
TECShapePolygone;
public
{ Déclarations publiques
}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure
TForm1.FormCreate(Sender: TObject);
begin
Map.LocalCache := ExtractFilePath(application.exename) +
'cache';
end;
procedure
TForm1.MapChangeMapBounds(Sender: TObject);
begin
UpdateMiniMap;
end;
procedure
TForm1.MapMapMove(sender: TObject; const Lat, Lng: Double);
begin
UpdateMiniMap;
end;
procedure
TForm1.MapResize(Sender: TObject);
begin
pnMiniMap.Top := Map.Height - pnMiniMap.Height
-16;
pnMiniMap.Left:= Map.width - pnMiniMap.width -
8;
end;
procedure
TForm1.minimapChangeMapZoom(Sender: TObject);
begin
// it deals only with direct access
to the minimap
if map.tag=1 then
exit;
// indicates that minimap has
initiated the movement
minimap.tag := 1;
Map.zoom := minimap.zoom + 5;
minimap.tag := 0;
end;
procedure
TForm1.minimapMapMove(sender: TObject; const Lat, Lng: Double);
begin
// it deals only with direct access
to the minimap
if map.tag=1 then
exit;
// indicates that minimap has
initiated the movement
minimap.tag := 1;
Map.setCenter(minimap.latitude,minimap.longitude);
minimap.tag := 0;
end;
procedure
TForm1.UpdateMiniMap;
begin
// if the call comes from the
direct change of the minimap, you must leave otherwise we
go into an infinite loop
if minimap.tag =
1 then exit;
// indicates that map has initiated
the movement
map.tag := 1;
// if the first call, creation of
the polygon indicates the main view
if not assigned(FMiniPolygone) then
begin
minimap.ShowCopyrightTile := false;
minimap.shapes.Polygones.add(0,0) ;
FMinipolygone := minimap.shapes.Polygones[0];
FMinipolygone.ShowText := false;
FMinipolygone.fillColor := clBlue;
FMinipolygone.hoverColor := clBlue;
FMinipolygone.Opacity := 50;
end;
minimap.setCenter(map1.latitude,map1.longitude);
minimap.zoom := map1.zoom - 5;
// update polygon with boundingbox
main map
FMinipolygone.SetPath([ map1.SouthWestLatitude,
map1.SouthWestLongitude,
map1.SouthWestLatitude, map1.NorthEastLongitude,
map1.NorthEastLatitude, map1.NorthEastLongitude,
map1.NorthEastLatitude, map1.SouthWestLongitude,
map1.SouthWestLatitude, map1.SouthWestLongitude
]);
map.tag := 0;
end;
end.