LazMapViewer: Introduce TMvDrawPlugin as common descendant for plugs which draw into the map. Update demos.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9533 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-12-14 17:41:17 +00:00
parent ce41a9f02c
commit a2fdd960ea
11 changed files with 530 additions and 192 deletions

View File

@ -164,9 +164,9 @@ object MainForm: TMainForm
Left = 0
Height = 15
Top = 279
Width = 41
Width = 108
BorderSpacing.Top = 8
Caption = 'Opacity'
Caption = 'Background Opacity'
end
object clbPenColor: TColorButton
AnchorSideLeft.Control = ParamsPanel

View File

@ -85,7 +85,7 @@ begin
MapView := FMapView1;
edLegalNotice.Text := LegalNotice;
seOpacity.Value := round(Opacity * 100);
seOpacity.Value := round(BackgroundOpacity * 100);
end;
with TLegalNoticePlugin.Create(FPluginManager) do
@ -116,9 +116,9 @@ end;
procedure TMainForm.FloatSpinEdit1Change(Sender: TObject);
begin
(FPluginManager.Item[0] as TLegalNoticePlugin).Opacity := seOpacity.Value / 100;
(FPluginManager.Item[0] as TLegalNoticePlugin).BackgroundOpacity := seOpacity.Value / 100;
if FPluginManager.PluginList.Count > 1 then
(FPluginManager.Item[1] as TLegalNoticePlugin).Opacity := seOpacity.Value / 100;
(FPluginManager.Item[1] as TLegalNoticePlugin).BackgroundOpacity := seOpacity.Value / 100;
end;
procedure TMainForm.btnSaveToImageClick(Sender: TObject);

View File

@ -5,17 +5,29 @@ object MainForm: TMainForm
Width = 1109
Caption = 'Linked maps demo'
ChildSizing.HorizontalSpacing = 4
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ChildSizing.ControlsPerLine = 1
ClientHeight = 406
ClientWidth = 1109
LCLVersion = '4.99.0.0'
OnCreate = FormCreate
object Panel1: TPanel
Left = 0
Height = 375
Top = 0
Width = 1109
Align = alClient
BevelOuter = bvNone
ChildSizing.HorizontalSpacing = 4
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 375
ClientWidth = 1109
TabOrder = 0
object MapView1: TMapView
Left = 0
Height = 406
Height = 375
Top = 0
Width = 552
Cyclic = True
@ -30,7 +42,7 @@ object MainForm: TMainForm
end
object MapView2: TMapView
Left = 556
Height = 406
Height = 375
Top = 0
Width = 553
Cyclic = True
@ -43,6 +55,17 @@ object MainForm: TMainForm
UseThreads = True
ZoomToCursor = False
end
end
object Label1: TLabel
Left = 8
Height = 15
Top = 383
Width = 1093
Align = alBottom
Alignment = taCenter
BorderSpacing.Around = 8
Caption = 'Zoom or move one map, and the other map will follow.'
end
object PluginManager: TMvPluginManager
Left = 424
Top = 144

View File

@ -5,13 +5,19 @@ unit main;
interface
uses
Classes, ExtCtrls, mvMapViewer, mvPluginCore, mvPlugins, SysUtils, Forms,
Controls, Graphics;
Classes, SysUtils,
Graphics, Controls, StdCtrls, ExtCtrls, Forms,
mvMapViewer, mvPluginCore, mvPlugins;
type
{ TMainForm }
TMainForm = class(TForm)
Label1: TLabel;
MapView1: TMapView;
MapView2: TMapView;
Panel1: TPanel;
PluginManager: TMvPluginManager;
LinkedMapsPlugin: TLinkedMapsPlugin;
procedure FormCreate(Sender: TObject);

View File

@ -51,13 +51,15 @@ object Form1: TForm1
end
object ValueListEditor1: TValueListEditor
Left = 16
Height = 255
Height = 288
Top = 72
Width = 192
Anchors = [akTop, akLeft, akBottom]
FixedCols = 0
RowCount = 2
TabOrder = 1
DisplayOptions = [doColumnTitles, doAutoColResize]
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goAlwaysShowEditor, goThumbTracking]
TitleCaptions.Strings = (
'Index'
'Plugin'
@ -73,24 +75,24 @@ object Form1: TForm1
Top = 120
object MvPluginManager1LegalNoticePlugin1: TLegalNoticePlugin
BackgroundColor = clWhite
BackgroundOpacity = 1
Font.Height = -19
LegalNotice = 'Test 1'
Opacity = 1
end
object MvPluginManager1LegalNoticePlugin2: TLegalNoticePlugin
BackgroundColor = clYellow
BackgroundOpacity = 1
Font.Color = clRed
Font.Height = -19
LegalNotice = 'Test 2'
Opacity = 1
Spacing = 14
end
object MvPluginManager1LegalNoticePlugin3: TLegalNoticePlugin
BackgroundColor = clBlue
BackgroundOpacity = 1
Font.Color = clWhite
Font.Height = -19
LegalNotice = 'Test 3'
Opacity = 1
Spacing = 24
end
end

View File

@ -1,18 +1,18 @@
object MainForm: TMainForm
Left = 390
Height = 467
Height = 555
Top = 139
Width = 936
Caption = 'Map Scale Demo'
ClientHeight = 467
ClientHeight = 555
ClientWidth = 936
LCLVersion = '4.99.0.0'
OnCreate = FormCreate
object MapView: TMapView
Left = 328
Height = 467
Left = 336
Height = 555
Top = 0
Width = 608
Width = 600
Align = alClient
DownloadEngine = MapView.BuiltInDLE
DrawingEngine = MapView.BuiltInDE
@ -32,15 +32,15 @@ object MainForm: TMainForm
OnZoomChange = MapViewZoomChange
end
object ParamsPanel: TPanel
Left = 8
Height = 451
Top = 8
Left = 12
Height = 531
Top = 12
Width = 312
Align = alLeft
AutoSize = True
BorderSpacing.Around = 8
BorderSpacing.Around = 12
BevelOuter = bvNone
ClientHeight = 451
ClientHeight = 531
ClientWidth = 312
TabOrder = 1
object cbScaleVisible: TCheckBox
@ -70,7 +70,7 @@ object MainForm: TMainForm
AutoFill = True
AutoSize = True
BorderSpacing.Top = 12
Caption = 'Scale Align'
Caption = 'Scale Alignment'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 6
@ -128,7 +128,7 @@ object MainForm: TMainForm
ItemIndex = 0
Items.Strings = (
'metric (km, m)'
'imperial (miles)'
'imperial (miles, feet)'
)
TabOrder = 2
OnClick = rgLengthUnitsClick
@ -144,7 +144,7 @@ object MainForm: TMainForm
Top = 211
Width = 312
BorderSpacing.Top = 16
Caption = 'Zoom minimum'
Caption = 'Zoom Minimum'
ClientHeight = 85
ClientWidth = 308
TabOrder = 3
@ -158,6 +158,7 @@ object MainForm: TMainForm
Height = 30
Top = 39
Width = 284
Alignment = taCenter
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
BorderSpacing.Around = 12
@ -167,12 +168,12 @@ object MainForm: TMainForm
object seZoomMin: TSpinEdit
AnchorSideLeft.Control = gbZoomMin
AnchorSideTop.Control = gbZoomMin
Left = 12
Left = 24
Height = 23
Top = 0
Width = 92
Alignment = taRightJustify
BorderSpacing.Left = 12
BorderSpacing.Left = 24
TabOrder = 0
OnChange = seZoomMinChange
end
@ -183,18 +184,221 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = gbZoomMin
AnchorSideRight.Side = asrBottom
Left = 104
Left = 116
Height = 15
Top = 4
Width = 204
Width = 192
Alignment = taCenter
Anchors = [akTop, akLeft, akRight]
Caption = 'Current zoom level: '
end
end
object gbPen: TGroupBox
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = gbZoomMin
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 53
Top = 332
Width = 312
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 16
Caption = 'Scale Bar Pen'
ClientHeight = 33
ClientWidth = 308
TabOrder = 4
object lblPenWidth: TLabel
AnchorSideLeft.Control = gbPen
AnchorSideTop.Control = sePenWidth
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 4
Width = 32
BorderSpacing.Left = 24
Caption = 'Width'
end
object sePenWidth: TSpinEdit
AnchorSideLeft.Control = lblPenWidth
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Bevel1
Left = 68
Height = 23
Top = 0
Width = 74
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 12
MaxValue = 10
MinValue = 1
TabOrder = 0
Value = 1
OnChange = sePenWidthChange
end
object clbPenColor: TColorButton
AnchorSideLeft.Control = Bevel1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = gbPen
AnchorSideRight.Control = gbPen
AnchorSideRight.Side = asrBottom
Left = 166
Height = 25
Top = 0
Width = 134
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Line color'
OnColorChanged = clbPenColorChanged
end
object Bevel1: TBevel
AnchorSideLeft.Control = gbPen
AnchorSideLeft.Side = asrCenter
Left = 142
Height = 26
Top = 1
Width = 24
Shape = bsSpacer
end
end
object gbFont: TGroupBox
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = gbPen
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 53
Top = 401
Width = 312
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 16
Caption = 'Font'
ClientHeight = 33
ClientWidth = 308
TabOrder = 5
object btnFont: TButton
AnchorSideLeft.Control = gbFont
AnchorSideTop.Control = gbFont
Left = 24
Height = 25
Top = 0
Width = 75
BorderSpacing.Left = 24
BorderSpacing.Bottom = 8
Caption = 'Font...'
TabOrder = 0
OnClick = btnFontClick
end
object lblFontSample: TLabel
AnchorSideLeft.Control = btnFont
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = btnFont
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = gbFont
AnchorSideRight.Side = asrBottom
Left = 99
Height = 15
Top = 5
Width = 209
Alignment = taCenter
Anchors = [akTop, akLeft, akRight]
Caption = '1000 km'
end
end
object gbBackground: TGroupBox
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = gbFont
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 53
Top = 470
Width = 312
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 16
Caption = 'Background'
ClientHeight = 33
ClientWidth = 308
TabOrder = 6
object lblOpacity: TLabel
AnchorSideLeft.Control = gbBackground
AnchorSideTop.Side = asrCenter
Left = 16
Height = 15
Top = 5
Width = 41
BorderSpacing.Left = 16
Caption = 'Opacity'
end
object clbBackgroundColor: TColorButton
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = gbBackground
AnchorSideRight.Control = gbBackground
AnchorSideRight.Side = asrBottom
Left = 166
Height = 25
Top = 0
Width = 134
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
BorderWidth = 2
ButtonColorAutoSize = False
ButtonColorSize = 16
ButtonColor = clBlack
Caption = 'Background color'
OnColorChanged = clbBackgroundColorChanged
end
object Bevel2: TBevel
AnchorSideLeft.Control = gbBackground
AnchorSideLeft.Side = asrCenter
Left = 142
Height = 26
Top = 2
Width = 24
Shape = bsSpacer
end
object seOpacity: TFloatSpinEdit
AnchorSideLeft.Control = lblOpacity
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Bevel2
Left = 69
Height = 23
Top = 2
Width = 73
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 12
Increment = 0.05
MaxValue = 1
TabOrder = 0
Value = 1
OnChange = seOpacityChange
end
end
end
object PluginManager: TMvPluginManager
Left = 429
Top = 105
end
object FontDialog: TFontDialog
MinFontSize = 0
MaxFontSize = 0
Left = 132
Top = 398
end
end

View File

@ -14,8 +14,20 @@ type
{ TMainForm }
TMainForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
btnFont: TButton;
cbScaleVisible: TCheckBox;
clbBackgroundColor: TColorButton;
clbPenColor: TColorButton;
FontDialog: TFontDialog;
gbFont: TGroupBox;
gbBackground: TGroupBox;
gbZoomMin: TGroupBox;
gbPen: TGroupBox;
lblFontSample: TLabel;
lblPenWidth: TLabel;
lblOpacity: TLabel;
lblZoomMinInfo: TLabel;
lblCurrentZoom: TLabel;
MapView: TMapView;
@ -23,12 +35,19 @@ type
ParamsPanel: TPanel;
rgLengthUnits: TRadioGroup;
rgScaleAlign: TRadioGroup;
seOpacity: TFloatSpinEdit;
seZoomMin: TSpinEdit;
sePenWidth: TSpinEdit;
procedure btnFontClick(Sender: TObject);
procedure cbScaleVisibleChange(Sender: TObject);
procedure clbBackgroundColorChanged(Sender: TObject);
procedure clbPenColorChanged(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MapViewZoomChange(Sender: TObject);
procedure rgLengthUnitsClick(Sender: TObject);
procedure rgScaleAlignClick(Sender: TObject);
procedure seOpacityChange(Sender: TObject);
procedure sePenWidthChange(Sender: TObject);
procedure seZoomMinChange(Sender: TObject);
private
FScalePlugin: TMapScalePlugin;
@ -60,13 +79,23 @@ begin
seZoomMin.MaxValue := zoomMax;
seZoomMin.MinValue := zoomMin;
seZoomMin.Value := FScalePlugin.ZoomMin;
sePenWidth.Value := FScalePlugin.Pen.Width;
seOpacity.Value := FScalePlugin.BackgroundOpacity;
clbPenColor.ButtonColor := FScalePlugin.Pen.Color;
clbBackgroundColor.ButtonColor := FScalePlugin.BackgroundColor;
lblFontSample.Font.Assign(FScalePlugin.Font);
UpdateZoomInfo;
end;
procedure TMainForm.MapViewZoomChange(Sender: TObject);
procedure TMainForm.btnFontClick(Sender: TObject);
begin
UpdateZoomInfo;
FontDialog.Font.Assign(FScalePlugin.Font);
if FontDialog.Execute then
begin
FScalePlugin.Font.Assign(FontDialog.Font);
lblFontSample.Font.Assign(FontDialog.Font);
end;
end;
procedure TMainForm.cbScaleVisibleChange(Sender: TObject);
@ -74,11 +103,26 @@ begin
FScalePlugin.Enabled := cbScaleVisible.Checked;
end;
procedure TMainForm.clbBackgroundColorChanged(Sender: TObject);
begin
FScalePlugin.BackgroundColor := clbBackgroundColor.ButtonColor;
end;
procedure TMainForm.clbPenColorChanged(Sender: TObject);
begin
FScalePlugin.Pen.Color := clbPenColor.ButtonColor;
end;
procedure TMainForm.rgLengthUnitsClick(Sender: TObject);
begin
FScalePlugin.Imperial := rgLengthUnits.ItemIndex = 1;
end;
procedure TMainForm.MapViewZoomChange(Sender: TObject);
begin
UpdateZoomInfo;
end;
procedure TMainForm.rgScaleAlignClick(Sender: TObject);
var
alignSet: TScaleAlignSet;
@ -98,6 +142,16 @@ begin
FScalePlugin.AlignSet := alignSet;
end;
procedure TMainForm.seOpacityChange(Sender: TObject);
begin
FScalePlugin.BackgroundOpacity := seOpacity.Value;
end;
procedure TMainForm.sePenWidthChange(Sender: TObject);
begin
FScalePlugin.Pen.Width := sePenWidth.Value;
end;
procedure TMainForm.seZoomMinChange(Sender: TObject);
begin
FScalePlugin.ZoomMin := seZoomMin.Value;

View File

@ -16,36 +16,25 @@ type
TMapGridLabelPosition = (glpLeft, glpTop, glpRight, glpBottom);
TMapGridLabelPositions = set of TMapGridLabelPosition;
TMapGridPlugin = class(TMvPlugin)
TMapGridPlugin = class(TMvDrawPlugin)
private
const
DEFAULT_LABEL_POSITIONS = [glpLeft, glpTop];
DEFAULT_MAX_DISTANCE = 200;
DEFAULT_MIN_DISTANCE = 80;
DEFAULT_OPACITY = 0.55;
type
TGridCoordType = (gctLatitude, gctLongitude);
private
FBackgroundColor: TColor;
FBackgroundOpacity: Single;
FFont: TFont;
FIncrement: Double;
FPen: TPen;
FLabelDistance: Integer;
FLabelPositions: TMapGridLabelPositions;
FMaxDistance: Integer;
FMinDistance: Integer;
procedure SetBackgroundColor(AValue: TColor);
procedure SetBackgroundOpacity(AValue: Single);
procedure SetFont(AValue: TFont);
procedure SetIncrement(AValue: Double);
procedure SetLabelDistance(AValue: Integer);
procedure SetLabelPositions(AValue: TMapGridLabelPositions);
procedure SetMaxDistance(AValue: Integer);
procedure SetMinDistance(AValue: Integer);
procedure SetPen(AValue: TPen);
private
procedure Changed(Sender: TObject);
protected
procedure BeforeDrawObjects(AMapView: TMapView; var {%H-}Handled: Boolean); override;
function CalcIncrement(AMapView: TMapView; Area: TRealArea): Double;
@ -57,17 +46,18 @@ type
function GetLatLonAsString(AValue: Double; ACoordType: TGridCoordType): String; virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(ASource: TPersistent); override;
published
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clWhite;
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity;
property Font: TFont read FFont write SetFont;
property Increment: Double read FIncrement write SetIncrement; // 0 = automatic increment detection
property LabelDistance: Integer read FLabelDistance write SetLabelDistance default 0;
property LabelPositions: TMapGridLabelPositions read FLabelPositions write SetLabelPositions default DEFAULT_LABEL_POSITIONS;
property MaxDistance: Integer read FMaxDistance write SetMaxDistance default DEFAULT_MAX_DISTANCE;
property MinDistance: Integer read FMinDistance write SetMinDistance default DEFAULT_MIN_DISTANCE;
property Pen: TPen read FPen write SetPen;
// inherited properties
property BackgroundColor;
property BackgroundOpacity;
property Font;
property Pen;
end;
implementation
@ -81,22 +71,19 @@ uses
constructor TMapGridPlugin.Create(AOwner: TComponent);
begin
inherited;
FBackgroundColor := clWhite;
FBackgroundOpacity := DEFAULT_OPACITY;
FFont := TFont.Create;
FFont.OnChange := @Changed;
FPen := TPen.Create;
FPen.OnChange := @Changed;
FMaxDistance := DEFAULT_MAX_DISTANCE;
FMinDistance := DEFAULT_MIN_DISTANCE;
FLabelPositions := DEFAULT_LABEL_POSITIONS;
end;
destructor TMapGridPlugin.Destroy;
procedure TMapGridPlugin.Assign(ASource: TPersistent);
begin
FPen.Free;
FFont.Free;
inherited;
if (ASource is TMapGridPlugin) then
begin
FLabelPositions := TMapGridPlugin(ASource).LabelPositions;
FMaxDistance := TMapGridPlugin(ASource).MaxDistance;
FMinDistance := TMapGridPlugin(ASource).MinDistance;
end;
end;
procedure TMapGridPlugin.BeforeDrawObjects(AMapView: TMapView; var Handled: Boolean);
@ -120,14 +107,14 @@ begin
else
incr := FIncrement;
AMapView.DrawingEngine.PenStyle := FPen.Style;
AMapView.DrawingEngine.PenWidth := FPen.Width;
AMapView.DrawingEngine.PenColor := FPen.Color;
AMapView.DrawingEngine.BrushColor := FBackgroundColor;
AMapView.DrawingEngine.FontName := FFont.Name;
AMapView.DrawingEngine.FontSize := FFont.Size;
AMapView.DrawingEngine.FontStyle := FFont.Style;
AMapView.DrawingEngine.FontColor := FFont.Color;
AMapView.DrawingEngine.PenStyle := Pen.Style;
AMapView.DrawingEngine.PenWidth := Pen.Width;
AMapView.DrawingEngine.PenColor := Pen.Color;
AMapView.DrawingEngine.BrushColor := BackgroundColor;
AMapView.DrawingEngine.FontName := Font.Name;
AMapView.DrawingEngine.FontSize := Font.Size;
AMapView.DrawingEngine.FontStyle := Font.Style;
AMapView.DrawingEngine.FontColor := Font.Color;
for coordType in TGridCoordType do
begin
@ -191,11 +178,6 @@ begin
end;
end;
procedure TMapGridPlugin.Changed(Sender: TObject);
begin
Update;
end;
procedure TMapGridPlugin.DrawGridLine(ADrawingEngine: TMvCustomDrawingEngine;
AValue: Double; P1, P2: TPoint; AMapRect: TRect);
var
@ -271,9 +253,9 @@ begin
end;
// Draw (semi-transparent) background
if FBackgroundColor <> clNone then
if BackgroundColor <> clNone then
begin
ADrawingEngine.Opacity := FBackgroundOpacity;
ADrawingEngine.Opacity := BackgroundOpacity;
ADrawingEngine.BrushStyle := bsSolid;
case coordType of
gctLatitude:
@ -452,30 +434,6 @@ begin
end;
end;
procedure TMapGridPlugin.SetBackgroundColor(AValue: TColor);
begin
if FBackgroundColor <> AValue then
begin
FBackgroundColor := AValue;
Update;
end;
end;
procedure TMapGridPlugin.SetBackgroundOpacity(AValue: Single);
begin
if FBackgroundOpacity <> AValue then
begin
FBackgroundOpacity := AValue;
Update;
end;
end;
procedure TMapGridPlugin.SetFont(AValue: TFont);
begin
FFont := AValue;
Update;
end;
procedure TMapGridPlugin.SetIncrement(AValue: Double);
begin
if FIncrement <> AValue then
@ -521,12 +479,6 @@ begin
end;
end;
procedure TMapGridPlugin.SetPen(AValue: TPen);
begin
FPen.Assign(AValue);
Update;
end;
initialization
RegisterPluginClass(TMapGridPlugin, 'Map grid');

View File

@ -12,24 +12,20 @@ uses
type
{ TCenterMarkerPlugin - draws a cross in the map center }
TCenterMarkerPlugin = class(TMvPlugin)
TCenterMarkerPlugin = class(TMvDrawPlugin)
private
const
DEFAULT_MARKER_SIZE = 15;
private
FPen: TPen;
FSize: Integer;
procedure Changed(Sender: TObject);
procedure SetPen(AValue: TPen);
procedure SetSize(AValue: Integer);
protected
procedure AfterDrawObjects(AMapView: TMapView; var {%H-}Handled: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Pen: TPen read FPen write SetPen;
property Pen;
property Size: Integer read FSize write SetSize default DEFAULT_MARKER_SIZE;
end;
@ -57,17 +53,17 @@ type
private
FLegalNotice: String;
FLegalNoticeURL: String;
FOpacity: Single;
FBackgroundOpacity: Single;
FPosition: TLegalNoticePosition;
FFont: TFont;
FSpacing: Integer;
FBackgroundColor: TColor;
private
procedure SetBackgroundColor(AValue: TColor);
procedure SetBackgroundOpacity(AValue: Single);
procedure SetFont(AValue: TFont);
procedure SetLegalNotice(AValue: String);
procedure SetLegalNoticeURL(AValue: String);
procedure SetOpacity(AValue: Single);
procedure SetPosition(AValue: TLegalNoticePosition);
procedure SetSpacing(AValue: Integer);
protected
@ -86,29 +82,29 @@ type
procedure Assign(Source: TPersistent); override;
published
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clNone;
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity default DEFAULT_LEGALNOTICE_OPACITY; // 0..1
property Font: TFont read FFont write SetFont;
property LegalNotice: String read FLegalNotice write SetLegalNotice;
property LegalNoticeURL: String read FLegalNoticeURL write SetLegalNoticeURL;
property Opacity: Single read FOpacity write SetOpacity default DEFAULT_LEGALNOTICE_OPACITY;
property Position: TLegalNoticePosition read FPosition write SetPosition default lnpBottomRight;
property Spacing: Integer read FSpacing write SetSpacing default DEFAULT_LEGALNOTICE_SPACING;
// inherited properties
property MapView;
end;
{ TDraggableMarkerPlugin }
TDraggableMarkerPlugin = class;
TDraggableMarkerCanMoveEvent = function (Sender : TDraggableMarkerPlugin; AMarker : TGPSPoint) : Boolean of object;
TDraggableMarkerMovedEvent = procedure (Sender : TDraggableMarkerPlugin; AMarker : TGPSPoint; AOrgPosition : TRealPoint) of object;
{ TLegalNoticePluginData }
{ TDraggableMarkerData }
PDraggableMarkerData = ^TDraggableMarkerData;
TDraggableMarkerData = record
FDraggableMarker : TGPSPoint;
FOrgPosition : TRealPoint;
end;
{ TDraggableMarkerPlugin }
TDraggableMarkerPlugin = class(TMvMultiMapsPlugin)
private
FDraggableMarkerCanMoveEvent : TDraggableMarkerCanMoveEvent;
@ -203,24 +199,13 @@ uses
constructor TCenterMarkerPlugin.Create(AOwner: TComponent);
begin
inherited;
FPen := TPen.Create;
FPen.OnChange := @Changed;
FSize := DEFAULT_MARKER_SIZE;
end;
destructor TCenterMarkerPlugin.Destroy;
begin
FPen.Free;
inherited;
end;
procedure TCenterMarkerPlugin.Assign(Source: TPersistent);
begin
if Source is TCenterMarkerPlugin then
begin
FPen.Assign(TCenterMarkerPlugin(Source).Pen);
FSize := TCenterMarkerPlugin(Source).Size;
end;
inherited;
end;
@ -230,25 +215,14 @@ var
C: TPoint;
begin
C := Point(AMapView.ClientWidth div 2, AMapView.ClientHeight div 2);
AMapView.DrawingEngine.PenColor := FPen.Color;
AMapView.DrawingEngine.PenStyle := FPen.Style;
AMapView.DrawingEngine.PenWidth := FPen.Width;
AMapView.DrawingEngine.PenColor := Pen.Color;
AMapView.DrawingEngine.PenStyle := Pen.Style;
AMapView.DrawingEngine.PenWidth := Pen.Width;
AMapView.DrawingEngine.Opacity := 1.0;
AMapView.DrawingEngine.Line(C.X, C.Y - FSize, C.X, C.Y + FSize);
AMapView.DrawingEngine.Line(C.X - FSize, C.Y, C.X + FSize, C.Y);
end;
procedure TCenterMarkerPlugin.Changed(Sender: TObject);
begin
Update;
end;
procedure TCenterMarkerPlugin.SetPen(AValue: TPen);
begin
FPen.Assign(AValue);
Update;
end;
procedure TCenterMarkerPlugin.SetSize(AValue: Integer);
begin
if FSize <> AValue then
@ -338,7 +312,7 @@ begin
FPosition := lnpBottomRight;
FFont := TFont.Create;
FFont.OnChange := @Changed;
FOpacity := DEFAULT_LEGALNOTICE_OPACITY;
FBackgroundOpacity := DEFAULT_LEGALNOTICE_OPACITY;
FSpacing := DEFAULT_LEGALNOTICE_SPACING;
end;
@ -356,7 +330,7 @@ begin
FFont.Assign(TLegalNoticePlugin(Source).Font);
FLegalNotice := TLegalNoticePlugin(Source).LegalNotice;
FLegalNoticeURL := TLegalNoticePlugin(Source).LegalNoticeURL;
FOpacity := TLegalNoticePlugin(Source).Opacity;
FBackgroundOpacity := TLegalNoticePlugin(Source).BackgroundOpacity;
FPosition := TLegalNoticePlugin(Source).Position;
FSpacing := TLegalNoticePlugin(Source).Spacing;
end;
@ -380,7 +354,7 @@ begin
try
if FBackgroundColor <> clNone then
begin
AMapView.DrawingEngine.Opacity := FOpacity;
AMapView.DrawingEngine.Opacity := FBackgroundOpacity;
AMapView.DrawingEngine.BrushStyle := bsSolid;
AMapView.DrawingEngine.BrushColor := ColorToRGB(FBackgroundColor);
with lClickableRect do
@ -464,9 +438,10 @@ var
lClickableRect : TRect;
begin
if GetMapViewData(AMapView,lClickableRect,SizeOf(lClickableRect)) < SizeOf(lClickableRect) then
CalcClickableRect(AMapView,lClickableRect);
CalcClickableRect(AMapView, lClickableRect);
if PtInRect(lClickableRect, Point(X, Y)) and (not AMapView.Engine.InDrag) then
if PtInRect(lClickableRect, Point(X, Y)) and (not AMapView.Engine.InDrag) and
(FLegalNoticeURL <> '') then
begin
FFont.Style := [fsUnderline];
AMapView.Cursor := crHandPoint;
@ -480,13 +455,6 @@ begin
Update;
end;
procedure TLegalNoticePlugin.SetOpacity(AValue: Single);
begin
if FOpacity = AValue then Exit;
FOpacity := AValue;
Update;
end;
procedure TLegalNoticePlugin.SetPosition(AValue: TLegalNoticePosition);
begin
if FPosition = AValue then Exit;
@ -515,6 +483,13 @@ begin
Update;
end;
procedure TLegalNoticePlugin.SetBackgroundOpacity(AValue: Single);
begin
if FBackgroundOpacity = AValue then Exit;
FBackgroundOpacity := AValue;
Update;
end;
procedure TLegalNoticePlugin.SetFont(AValue: TFont);
begin
FFont.Assign(AValue);

View File

@ -16,7 +16,7 @@ type
TScaleAlignSet = set of alTop..alRight;
TMapScalePlugin = class(TMvPlugin)
TMapScalePlugin = class(TMvDrawPlugin)
private
FSpaceY: Integer;
FAlignSet: TScaleAlignSet;
@ -41,6 +41,11 @@ type
property SpaceY: Integer read FSpaceY write SetSpaceY default 10;
property WidthMax: Integer read FWidthMax write SetWidthMax default 250;
property ZoomMin: Integer read FZoomMin write SetZoomMin default 8;
// inherited properties
property BackgroundColor;
property BackgroundOpacity;
property Font;
property Pen;
end;
implementation
@ -156,16 +161,16 @@ begin
with AMapView.DrawingEngine do
try
// Semitransparent background
Opacity := 0.55;
Opacity := BackgroundOpacity;
BrushStyle := bsSolid;
BrushColor := clWhite;
BrushColor := BackgroundColor;
FillRect(R.Left, R.Top, R.Right, R.Bottom);
// Bar
Opacity := 1.0;
PenStyle := psSolid;
PenColor := clBlack;
PenWidth := 1;
PenStyle := Self.Pen.Style;
PenColor := Self.Pen.Color;
PenWidth := Self.Pen.Width;
Polyline([
R.TopLeft + Point(0, 10),
R.TopLeft,
@ -175,6 +180,8 @@ begin
// Caption
BrushStyle := bsClear;
FontName := Self.Font.Name;
SetFont(Self.Font.Name, Self.Font.Size, Self.Font.Style, ColorToRGB(Self.Font.Color));
TextOut(R.CenterPoint.X - Extent.CX div 2, R.Top + 3, Capt);
finally
Opacity := OldOpacity;

View File

@ -5,8 +5,8 @@ unit mvPluginCore;
interface
uses
Classes, SysUtils, StrUtils, Math, LazLoggerBase,
Controls, Dialogs, Contnrs,
Classes, SysUtils, StrUtils, Contnrs, Math, LazLoggerBase,
Graphics, Controls, Dialogs,
mvMapViewer, mvTypes, mvGpsObj, mvClassRegistration;
type
@ -82,6 +82,35 @@ type
property MapView;
end;
{ TMvDrawPlugin - common ancestor of all plugins drawing something in the map }
TMvDrawPlugin = class(TMvPlugin)
private
const
DEFAULT_OPACITY = 0.55;
DEFAULT_BACKGROUND_COLOR = clWhite;
private
FBackgroundColor: TColor;
FBackgroundOpacity: Single;
FFont: TFont;
FPen: TPen;
function IsOpacityStored: Boolean;
procedure SetBackgroundColor(AValue: TColor);
procedure SetBackgroundOpacity(AValue: Single);
procedure SetFont(AValue: TFont);
procedure SetPen(AValue: TPen);
protected
procedure Changed(Sender: TObject);
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default DEFAULT_BACKGROUND_COLOR;
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity stored IsOpacityStored;
property Font: TFont read FFont write SetFont;
property Pen: TPen read FPen write SetPen;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(ASource: TPersistent); override;
end;
{ TMvMultiMapsPluginData }
TMvMultiMapsPluginData = class(TObject)
@ -233,8 +262,7 @@ end;
procedure TMvCustomPlugin.Assign(Source: TPersistent);
begin
if Source is TMvCustomPlugin then
FEnabled := TMvCustomPlugin(Source).Enabled
else
FEnabled := TMvCustomPlugin(Source).Enabled;
inherited Assign(Source);
end;
@ -393,6 +421,93 @@ begin
end;
}
{ TMvDrawPlugin }
constructor TMvDrawPlugin.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBackgroundColor := DEFAULT_BACKGROUND_COLOR;
FBackgroundOpacity := DEFAULT_OPACITY;
FFont := TFont.Create;
FFont.OnChange := @Changed;
FPen := TPen.Create;
FPen.OnChange := @Changed;
end;
destructor TMvDrawPlugin.Destroy;
begin
FFont.Free;
FPen.Free;
inherited Destroy;
end;
procedure TMvDrawPlugin.Assign(ASource: TPersistent);
begin
if ASource is TMvDrawPlugin then
begin
FBackgroundColor := TMvDrawPlugin(ASource).BackgroundColor;
FBackgroundOpacity := TMvDrawPlugin(ASource).BackgroundOpacity;
FFont.Assign(TMvDrawPlugin(ASource).Font);
FPen.Assign(TMvDrawPlugin(ASource).Pen);
end;
inherited;
end;
procedure TMvDrawPlugin.Changed(Sender: TObject);
begin
Update;
end;
function TMvDrawPlugin.IsOpacityStored: Boolean;
begin
Result := FBackgroundOpacity <> DEFAULT_OPACITY;
end;
procedure TMvDrawPlugin.SetBackgroundColor(AValue: TColor);
begin
if FBackgroundColor <> AValue then
begin
FBackgroundColor := AValue;
Update;
end;
end;
procedure TMvDrawPlugin.SetBackgroundOpacity(AValue: Single);
begin
if FBackgroundOpacity <> AValue then
begin
FBackgroundOpacity := AValue;
Update;
end;
end;
procedure TMvDrawPlugin.SetFont(AValue: TFont);
begin
if (AValue = nil) then
exit;
if (AValue.Name = FFont.Name) and (AValue.Size = FFont.Size) and
(AValue.Style = FFont.Style) and (AValue.Color = FFont.Color)
then
exit;
FFont.Assign(AValue);
Changed(Self);
end;
procedure TMvDrawPlugin.SetPen(AValue: TPen);
begin
if (AValue = nil) then
exit;
if (AValue.Color = FPen.Color) and (AValue.Width = FPen.Width) and
(AValue.Style = FPen.Style) and (AValue.Mode = FPen.Mode) and
(AValue.JoinStyle = FPen.JoinStyle) and (AValue.EndCap = FPen.EndCap)
then
exit;
FPen.Assign(AValue);
Changed(Self);
end;
{ TMvMultiMapsPluginData }
function TMvMultiMapsPluginData.GetDataSize: Integer;