LazMapViewer: In GridPlugin, draw grid lines before objects. Extend demo to add/delete points of interest (note: memory leak after deleting!)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9523 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-12-13 10:05:32 +00:00
parent 1e63bb3075
commit 23c9bb97e8
4 changed files with 2663 additions and 31 deletions
components/lazmapviewer
examples/plugin_demos/grid_demo
source/addons/plugins

View File

@ -65,6 +65,7 @@
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
<UseHeaptrc Value="True"/>
</Debugging>
<Options>
<Win32>

View File

@ -7,7 +7,7 @@ interface
uses
Classes, ComCtrls, DividerBevel, ExtCtrls, Spin, StdCtrls, SysUtils,
Forms, Controls, Graphics, Dialogs, //LazLogger,
mvMapViewer, mvEngine, mvPluginCore, mvPlugins;
mvMapViewer, mvTypes, mvEngine, mvPluginCore, mvPlugins;
type
TForm1 = class(TForm)
@ -24,6 +24,8 @@ type
divLines: TDividerBevel;
divLabels: TDividerBevel;
GroupBox1: TGroupBox;
ImageList1: TImageList;
Label1: TLabel;
lblLabelDistance: TLabel;
lblIncrement: TLabel;
lblOpacity: TLabel;
@ -40,9 +42,12 @@ type
procedure clbPenColorColorChanged(Sender: TObject);
procedure cmbIncrementChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MapViewMouseUp(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
procedure seLabelDistanceChange(Sender: TObject);
procedure tbOpacityChange(Sender: TObject);
private
procedure AddPointOfInterest(X, Y: Integer);
public
@ -57,6 +62,7 @@ implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
MapView.Zoom := 5;
with TGridPlugin.Create(PluginManager) do
begin
@ -67,9 +73,44 @@ begin
end;
end;
procedure TForm1.seLabelDistanceChange(Sender: TObject);
procedure TForm1.AddPointOfInterest(X, Y: Integer);
const
DELTA = 4;
var
layer: TMapLayer;
poi: TPointOfInterest;
RP: TRealPoint;
area: TRealArea;
list: TMapObjectList;
i: Integer;
begin
(PluginManager.PluginList[0] as TGridPlugin).GridLabels.Distance := seLabelDistance.Value;
if MapView.Layers.Count = 0 then
layer := TMapLayer(MapView.Layers.Add)
else
layer := MapView.Layers[0];
RP := MapView.Engine.ScreenToLatLon(Point(X, Y));
area := MapView.Engine.ScreenRectToRealArea(Rect(X-DELTA, Y-DELTA, X+DELTA, Y+DELTA));
list := layer.PointsOfInterest.HitTest(area);
if (list = nil) then
begin
poi := TPointOfInterest(layer.PointsOfInterest.Add);
poi.Caption := 'Test ' + IntToStr(layer.PointsOfInterest.Count);
poi.ImageIndex := Random(ImageList1.Count);
poi.Longitude := RP.Lon;
poi.Latitude := RP.Lat;
end else
begin
for i := list.Count-1 downto 0 do
begin
if list[i] is TPointOfInterest then
begin
poi := TPointOfInterest(list[i]);
poi.Free;
end;
end;
end;
end;
procedure TForm1.cbCyclicChange(Sender: TObject);
@ -77,32 +118,6 @@ begin
MapView.Cyclic := cbCyclic.Checked;
end;
procedure TForm1.LabelPositionChange(Sender: TObject);
begin
with (PluginManager.PluginList[0] as TGridPlugin).GridLabels do
begin
if cbLeft.Checked then
Position := Position + [glpLeft]
else
Position := Position - [glpLeft];
if cbTop.Checked then
Position := Position + [glpTop]
else
Position := Position - [glpTop];
if cbRight.Checked then
Position := Position + [glpRight]
else
Position := Position - [glpRight];
if cbBottom.Checked then
Position := Position + [glpBottom]
else
Position := Position - [glpBottom];
end;
end;
procedure TForm1.cbEnabledChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Enabled := cbEnabled.Checked;
@ -156,6 +171,44 @@ begin
end;
end;
procedure TForm1.LabelPositionChange(Sender: TObject);
begin
with (PluginManager.PluginList[0] as TGridPlugin).GridLabels do
begin
if cbLeft.Checked then
Position := Position + [glpLeft]
else
Position := Position - [glpLeft];
if cbTop.Checked then
Position := Position + [glpTop]
else
Position := Position - [glpTop];
if cbRight.Checked then
Position := Position + [glpRight]
else
Position := Position - [glpRight];
if cbBottom.Checked then
Position := Position + [glpBottom]
else
Position := Position - [glpBottom];
end;
end;
procedure TForm1.MapViewMouseUp(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
if Button = mbRight then
AddPointOfInterest(X, Y);
end;
procedure TForm1.seLabelDistanceChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).GridLabels.Distance := seLabelDistance.Value;
end;
procedure TForm1.tbOpacityChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Opacity := tbOpacity.Position / 100;

View File

@ -82,7 +82,7 @@ type
private
procedure Changed(Sender: TObject);
protected
procedure AfterDrawObjects(AMapView: TMapView; var {%H-}Handled: Boolean); override;
procedure BeforeDrawObjects(AMapView: TMapView; var {%H-}Handled: Boolean); override;
function CalcIncrement(AMapView: TMapView; Area: TRealArea): Double;
function CalcVisibleArea(AMapView: TMapView): TRealArea;
procedure DrawGridLine(ADrawingEngine: TMvCustomDrawingEngine;
@ -387,7 +387,7 @@ begin
inherited;
end;
procedure TGridPlugin.AfterDrawObjects(AMapView: TMapView; var Handled: Boolean);
procedure TGridPlugin.BeforeDrawObjects(AMapView: TMapView; var Handled: Boolean);
var
area: TRealArea;
coordType: TGridCoordType;