diff --git a/components/lazmapviewer/example/MapViewer_Demo.lpi b/components/lazmapviewer/example/MapViewer_Demo.lpi index 9c21d4514..cb636c771 100644 --- a/components/lazmapviewer/example/MapViewer_Demo.lpi +++ b/components/lazmapviewer/example/MapViewer_Demo.lpi @@ -33,7 +33,7 @@ - + @@ -57,6 +57,13 @@ + + + + + + + diff --git a/components/lazmapviewer/example/MapViewer_Demo.lpr b/components/lazmapviewer/example/MapViewer_Demo.lpr index 2aebd7ef3..773f46c9b 100644 --- a/components/lazmapviewer/example/MapViewer_Demo.lpr +++ b/components/lazmapviewer/example/MapViewer_Demo.lpr @@ -5,7 +5,7 @@ program MapViewer_Demo; uses {$IFDEF UNIX}cthreads,{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, Main, gpslistform, globals + Forms, Main, gpslistform, globals, gpsptform { you can add units after this }; {$R *.res} diff --git a/components/lazmapviewer/example/gpsptform.lfm b/components/lazmapviewer/example/gpsptform.lfm new file mode 100644 index 000000000..1b2c89e27 --- /dev/null +++ b/components/lazmapviewer/example/gpsptform.lfm @@ -0,0 +1,167 @@ +object GPSPointForm: TGPSPointForm + Left = 720 + Height = 199 + Top = 322 + Width = 226 + ActiveControl = edGPSPointLabel + AutoSize = True + BorderStyle = bsDialog + Caption = 'GPS Location' + ClientHeight = 199 + ClientWidth = 226 + OnShow = FormShow + LCLVersion = '2.1.0.0' + object ButtonPanel1: TButtonPanel + AnchorSideTop.Control = cbSymbols + AnchorSideTop.Side = asrBottom + Left = 6 + Height = 34 + Top = 159 + Width = 214 + Anchors = [akLeft, akRight] + OKButton.Name = 'OKButton' + OKButton.DefaultCaption = True + HelpButton.Name = 'HelpButton' + HelpButton.DefaultCaption = True + CloseButton.Name = 'CloseButton' + CloseButton.DefaultCaption = True + CancelButton.Name = 'CancelButton' + CancelButton.DefaultCaption = True + TabOrder = 1 + ShowButtons = [pbOK, pbCancel] + end + object Panel1: TPanel + Left = 12 + Height = 141 + Top = 12 + Width = 202 + Align = alClient + AutoSize = True + BorderSpacing.Left = 12 + BorderSpacing.Top = 12 + BorderSpacing.Right = 12 + BevelOuter = bvNone + ClientHeight = 141 + ClientWidth = 202 + TabOrder = 0 + object Label1: TLabel + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = Panel1 + Left = 0 + Height = 15 + Top = 0 + Width = 104 + Caption = 'Name of GPS point:' + ParentColor = False + end + object edGPSPointLabel: TEdit + AnchorSideLeft.Control = Label1 + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + Left = 0 + Height = 23 + Top = 17 + Width = 200 + BorderSpacing.Top = 2 + TabOrder = 0 + end + object clbSymbolColor: TColorBox + AnchorSideLeft.Control = cbSymbols + AnchorSideTop.Control = edGPSPointLabel + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = edGPSPointLabel + AnchorSideRight.Side = asrBottom + Left = 51 + Height = 22 + Top = 44 + Width = 149 + Style = [cbStandardColors, cbExtendedColors, cbPrettyNames] + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + BorderSpacing.Bottom = 4 + DropDownCount = 24 + ItemHeight = 16 + TabOrder = 1 + end + object Label2: TLabel + AnchorSideLeft.Control = edGPSPointLabel + AnchorSideTop.Control = clbSymbolColor + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 15 + Top = 48 + Width = 32 + BorderSpacing.Top = 8 + Caption = 'Color:' + ParentColor = False + end + object lblSymbol: TLabel + AnchorSideLeft.Control = edGPSPointLabel + AnchorSideTop.Control = cbSymbols + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 15 + Top = 101 + Width = 43 + BorderSpacing.Top = 8 + Caption = 'Symbol:' + ParentColor = False + end + object cbSymbols: TComboBox + AnchorSideLeft.Control = lblSymbol + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = seSize + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = edGPSPointLabel + AnchorSideRight.Side = asrBottom + Left = 51 + Height = 23 + Top = 97 + Width = 149 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 + ItemHeight = 15 + ItemIndex = 0 + Items.Strings = ( + 'plus ( + )' + 'corss (⛌)' + 'filled circle (⚫)' + 'open circle (⚪)' + 'filled square (■)' + 'open square (□)' + ) + Style = csDropDownList + TabOrder = 3 + Text = 'plus ( + )' + end + object lblSize: TLabel + AnchorSideLeft.Control = edGPSPointLabel + AnchorSideTop.Control = seSize + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 15 + Top = 74 + Width = 20 + Caption = 'Size' + ParentColor = False + end + object seSize: TSpinEdit + AnchorSideLeft.Control = cbSymbols + AnchorSideTop.Control = clbSymbolColor + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = clbSymbolColor + AnchorSideRight.Side = asrBottom + Left = 51 + Height = 23 + Top = 70 + Width = 149 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + MaxValue = 50 + MinValue = 1 + TabOrder = 2 + Value = 1 + end + end +end diff --git a/components/lazmapviewer/example/gpsptform.pas b/components/lazmapviewer/example/gpsptform.pas new file mode 100644 index 000000000..423dbce0a --- /dev/null +++ b/components/lazmapviewer/example/gpsptform.pas @@ -0,0 +1,87 @@ +unit gpsptform; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, + ButtonPanel, ColorBox, Spin, mvExtraData; + +type + + TGPSSymbol = (gpsPlus, gpsCross, gpsFilledCircle, gpsOpenCircle, + gpsFilledRect, gpsOpenRect); + + TGPSExtraData = class(TDrawingExtraData) + private + FSymbol: TGPSSymbol; + FSize: Integer; + public + constructor Create(aID: Integer); override; + property Symbol: TGPSSymbol read FSymbol write FSymbol; + property Size: Integer read FSize write FSize; + end; + + { TGPSPointForm } + + TGPSPointForm = class(TForm) + ButtonPanel1: TButtonPanel; + clbSymbolColor: TColorBox; + cbSymbols: TComboBox; + edGPSPointLabel: TEdit; + Label1: TLabel; + Label2: TLabel; + lblSymbol: TLabel; + lblSize: TLabel; + Panel1: TPanel; + seSize: TSpinEdit; + procedure FormShow(Sender: TObject); + private + + public + procedure GetData(var AName: String; var AColor: TColor; + var ASymbol: TGPSSymbol; var ASize: Integer); + procedure SetData(const AName: String; AColor: TColor; + ASymbol: TGPSSymbol; ASize: Integer); + end; + +var + GPSPointForm: TGPSPointForm; + +implementation + +{$R *.lfm} + +constructor TGPSExtraData.Create(aID: Integer); +begin + inherited Create(aID); + FSymbol := gpsPlus; + FSize := 10; +end; + +procedure TGPSPointForm.FormShow(Sender: TObject); +begin + edGPSPointLabel.SetFocus; +end; + +procedure TGPSPointForm.GetData(var AName: String; var AColor: TColor; + var ASymbol: TGPSSymbol; var ASize: Integer); +begin + AName := edGPSPointLabel.Text; + AColor := clbSymbolColor.Selected; + ASymbol := TGPSSymbol(cbSymbols.ItemIndex); + ASize := seSize.Value; +end; + +procedure TGPSPointForm.Setdata(const AName: String; AColor: TColor; + ASymbol: TGPSSymbol; ASize: Integer); +begin + edGPSPointLabel.Text := AName; + clbSymbolColor.Selected := AColor; + cbSymbols.ItemIndex := ord(ASymbol); + seSize.Value := ASize +end; + +end. + diff --git a/components/lazmapviewer/example/main.lfm b/components/lazmapviewer/example/main.lfm index b17760722..fa8c49e54 100644 --- a/components/lazmapviewer/example/main.lfm +++ b/components/lazmapviewer/example/main.lfm @@ -476,13 +476,13 @@ object MainForm: TMainForm AnchorSideTop.Control = BtnGPSPoints AnchorSideRight.Control = BtnGPSPoints Left = 8 - Height = 30 + Height = 45 Top = 4 Width = 178 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 8 BorderSpacing.Top = 4 - Caption = 'Click with right mouse button to add a GPS point.' + Caption = 'Click with right mouse button to add a GPS point.'#13#10'Settings on page "Config".' ParentColor = False WordWrap = True end @@ -495,8 +495,8 @@ object MainForm: TMainForm AnchorSideBottom.Control = GbGPS AnchorSideBottom.Side = asrBottom Left = 8 - Height = 35 - Top = 50 + Height = 20 + Top = 65 Width = 237 Anchors = [akTop, akLeft, akRight, akBottom] AutoSize = False @@ -716,32 +716,18 @@ object MainForm: TMainForm OnChange = CbDebugTilesChange TabOrder = 3 end - object CbShowPOIImage: TCheckBox - AnchorSideLeft.Control = CbDebugTiles - AnchorSideTop.Control = Bevel1 - AnchorSideTop.Side = asrBottom - Left = 6 - Height = 19 - Top = 143 - Width = 107 - BorderSpacing.Top = 6 - Caption = 'Show POI image' - OnChange = CbShowPOIImageChange - TabOrder = 4 - end object BtnPOITextFont: TButton - AnchorSideLeft.Control = CbShowPOIImage - AnchorSideTop.Control = CbShowPOIImage + AnchorSideTop.Control = rgPOIMode AnchorSideTop.Side = asrBottom - Left = 6 + Left = 16 Height = 25 - Top = 170 + Top = 230 Width = 93 AutoSize = True BorderSpacing.Top = 8 Caption = 'POI text font' OnClick = BtnPOITextFontClick - TabOrder = 5 + TabOrder = 4 end object cbPOITextBgColor: TColorBox AnchorSideLeft.Control = LblPOITextBgColor @@ -749,26 +735,26 @@ object MainForm: TMainForm AnchorSideTop.Control = BtnPOITextFont AnchorSideTop.Side = asrCenter AnchorSideRight.Side = asrBottom - Left = 154 + Left = 164 Height = 22 - Top = 171 - Width = 107 + Top = 231 + Width = 97 NoneColorColor = clWhite Style = [cbStandardColors, cbExtendedColors, cbIncludeNone, cbCustomColor, cbPrettyNames, cbCustomColors] Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 8 ItemHeight = 16 OnChange = cbPOITextBgColorChange - TabOrder = 6 + TabOrder = 5 end object LblPOITextBgColor: TLabel AnchorSideLeft.Control = BtnPOITextFont AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = BtnPOITextFont AnchorSideTop.Side = asrCenter - Left = 107 + Left = 117 Height = 15 - Top = 175 + Top = 235 Width = 39 BorderSpacing.Left = 8 Caption = 'Backgr.' @@ -787,6 +773,36 @@ object MainForm: TMainForm BorderSpacing.Top = 8 Shape = bsTopLine end + object rgPOIMode: TRadioGroup + AnchorSideLeft.Control = CbProviders + AnchorSideTop.Control = Bevel1 + AnchorSideTop.Side = asrBottom + Left = 6 + Height = 77 + Top = 145 + Width = 143 + AutoFill = True + AutoSize = True + BorderSpacing.Top = 8 + Caption = 'POI Mode' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.EnlargeHorizontal = crsHomogenousChildResize + ChildSizing.EnlargeVertical = crsHomogenousChildResize + ChildSizing.ShrinkHorizontal = crsScaleChilds + ChildSizing.ShrinkVertical = crsScaleChilds + ChildSizing.Layout = cclLeftToRightThenTopToBottom + ChildSizing.ControlsPerLine = 1 + ClientHeight = 57 + ClientWidth = 139 + ItemIndex = 0 + Items.Strings = ( + 'default drawing' + 'default POI image' + 'custom drawing' + ) + OnClick = rgPOIModeClick + TabOrder = 6 + end end end object GeoNames: TMVGeoNames diff --git a/components/lazmapviewer/example/main.pas b/components/lazmapviewer/example/main.pas index 092c43220..21046ca70 100644 --- a/components/lazmapviewer/example/main.pas +++ b/components/lazmapviewer/example/main.pas @@ -29,7 +29,6 @@ type CbMouseCoords: TGroupBox; CbDistanceUnits: TComboBox; CbDebugTiles: TCheckBox; - CbShowPOIImage: TCheckBox; cbPOITextBgColor: TColorBox; FontDialog: TFontDialog; GbCenterCoords: TGroupBox; @@ -62,6 +61,7 @@ type PageControl: TPageControl; PgData: TTabSheet; PgConfig: TTabSheet; + rgPOIMode: TRadioGroup; ZoomTrackBar: TTrackBar; procedure BtnGoToClick(Sender: TObject); procedure BtnLoadGPXFileClick(Sender: TObject); @@ -93,6 +93,7 @@ type procedure MapViewZoomChange(Sender: TObject); procedure BtnLoadMapProvidersClick(Sender: TObject); procedure BtnSaveMapProvidersClick(Sender: TObject); + procedure rgPOIModeClick(Sender: TObject); procedure ZoomTrackBarChange(Sender: TObject); private @@ -119,7 +120,7 @@ implementation uses LCLType, IniFiles, Math, FPCanvas, FPImage, GraphType, mvEngine, mvGPX, - globals, gpslistform; + globals, gpsPtForm, gpslistform; type TLocationParam = class @@ -292,10 +293,12 @@ end; procedure TMainForm.CbShowPOIImageChange(Sender: TObject); begin + { if CbShowPOIImage.Checked then MapView.POIImage.Assign(POIImage) else MapView.POIImage.Clear; + } end; procedure TMainForm.CbUseThreadsChange(Sender: TObject); @@ -379,20 +382,91 @@ end; procedure TMainForm.MapViewDrawGpsPoint(Sender: TObject; ADrawer: TMvCustomDrawingEngine; APoint: TGpsPoint); -const - R = 5; var P: TPoint; + d: Integer; + sym: TGPSSymbol; + clr: TColor; + extent: TSize; begin // Screen coordinates of the GPS point P := TMapView(Sender).LonLatToScreen(APoint.RealPoint); - // Draw the GPS point as a circle - ADrawer.BrushColor := clRed; + // Draw the GPS point as specified by the data in the point's ExtraData + if not (APoint.ExtraData is TGPSExtraData) then + exit; + + // Get the POI attributes + with TGPSExtraData(APoint.ExtraData) do + begin + clr := Color; + sym := Symbol; + d := Size div 2; + end; + + // Draw the POI symbol + ADrawer.PenColor := clr; + case sym of + gpsPlus: + begin + ADrawer.Line(P.X - d, P.Y, P.X + d, P.Y); + ADrawer.Line(P.X, P.Y - d, P.X , P.Y + d); + end; + gpsCross: + begin + ADrawer.Line(P.x - d, P.Y - d, P.X + d, P.Y + d); + ADrawer.Line(P.x - d, P.Y + d, P.X + d, P.Y - d); + end; + gpsFilledCircle: + begin + ADrawer.BrushStyle := bsSolid; + ADrawer.BrushColor := clr; + ADrawer.Ellipse(P.X - d, P.Y - d, P.X + d, P.Y + d); + end; + gpsOpenCircle: + begin + ADrawer.BrushStyle := bsClear; + ADrawer.Ellipse(P.X - d, P.Y - d, P.X + d, P.Y + d); + end; + gpsFilledRect: + begin + ADrawer.BrushStyle := bsSolid; + ADrawer.BrushColor := clr; + ADrawer.Rectangle(P.X - d, P.Y - d, P.X + d, P.Y + d); + end; + gpsOpenRect: + begin + ADrawer.BrushStyle := bsClear; + ADrawer.Rectangle(P.X - d, P.Y - d, P.X + d, P.Y + d); + end; + end; + + // Prepare text output: background color... + inc(P.Y, d + 4); + extent := ADrawer.TextExtent(APoint.Name); + if cbPOITextBgColor.selected = clNone then + ADrawer.BrushStyle := bsClear + else + begin + ADrawer.BrushStyle := bsSolid; + ADrawer.BrushColor := cbPOITextBgColor.Selected; + end; + + // ... and font + ADrawer.FontColor := MapView.Font.Color; + ADrawer.FontName := MapView.Font.Name; + ADrawer.FontSize := MapView.Font.Size; + ADrawer.FontStyle := MapView.Font.Style; + + // Write the POI text + ADrawer.TextOut(P.X - extent.CX div 2, P.Y, APoint.Name); +end; + +{ ADrawer.BrushColor := clRed; ADrawer.BrushStyle := bsSolid; ADrawer.Ellipse(P.X - R, P.Y - R, P.X + R, P.Y + R); end; - + } procedure TMainForm.MapViewMouseLeave(Sender: TObject); begin UpdateCoords(MaxInt, MaxInt); @@ -440,13 +514,41 @@ var rPt: TRealPoint; gpsPt: TGpsPoint; gpsName: String; + gpsSize: Integer; + gpsSymbol: TGPSSymbol; + gpsColor: TColor; + F: TGPSPointForm; begin if (Button = mbRight) then begin - if not InputQuery('Name of GPS location', 'Please enter name', gpsName) then - exit; rPt := MapView.ScreenToLonLat(Point(X, Y)); - gpsPt := TGpsPoint.CreateFrom(rPt); - gpsPt.Name := gpsName; + + if rgPOIMode.ItemIndex in [0, 1] then + begin + if not InputQuery('Name of GPS location', 'Please enter name', gpsName) then + exit; + gpsPt := TGpsPoint.CreateFrom(rPt); + gpsPt.Name := gpsName; + end else + begin + if GPSPointForm = nil then begin + GPSPointForm := TGPSPointForm.Create(Application); + GPSPointForm.Position := poMainformCenter; + GPSPointForm.SetData('', clRed, gpsPlus, 10); + end; + if GPSPointForm.ShowModal <> mrOK then + exit; + + GPSPointForm.GetData(gpsName, gpsColor, gpsSymbol, gpsSize); + gpsPt := TGpsPoint.CreateFrom(rPt); + gpsPt.Name := gpsName; + gpsPt.ExtraData := TGPSExtraData.Create(_CLICKED_POINTS_); + with TGPSExtraData(gpsPt.ExtraData) do + begin + Color := gpsColor; + Symbol := gpsSymbol; + Size := gpsSize; + end; + end; MapView.GpsItems.Add(gpsPt, _CLICKED_POINTS_); end; end; @@ -532,6 +634,24 @@ begin end; end; +procedure TMainForm.rgPOIModeClick(Sender: TObject); +begin + case rgPOIMode.ItemIndex of + 0: begin // default + MapView.POIImage.Clear; + MapView.OnDrawGPSPoint := nil; + end; + 1: begin + MapView.POIImage.Assign(POIImage); + MapView.OnDrawGPSPoint := nil; + end; + 2: begin + MapView.POIImage.Clear; + MapView.OnDrawGPSPoint := @MapViewDrawGpsPoint; + end; + end; +end; + procedure TMainForm.UpdateCoords(X, Y: Integer); var rPt: TRealPoint;