Repository navigation
Expand file tree
/
Copy pathUmapalbum.pas
More file actions
248 lines (206 loc) · 7.1 KB
/
Copy pathUmapalbum.pas
File metadata and controls
248 lines (206 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
{***************************************************************************}
{ TMS Map Album demo }
{ for Delphi & C++Builder }
{ }
{ written by TMS Software }
{ copyright © 2026 }
{ Email : info@tmssoftware.com }
{ Web : http://www.tmssoftware.com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{***************************************************************************}
unit Umapalbum;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCL.TMSFNCTypes, VCL.TMSFNCUtils,
VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes, VCL.TMSFNCMapsCommonTypes,
Vcl.StdCtrls, VCL.TMSFNCCustomControl, VCL.TMSFNCWebBrowser, VCL.TMSFNCMaps,
Vcl.ExtCtrls, Vcl.ComCtrls;
type
TMapAlbumForm = class(TForm)
Panel1: TPanel;
TMSFNCMaps1: TTMSFNCMaps;
openImage: TOpenDialog;
btnAddPhotos: TButton;
btnAddRoutes: TButton;
openRoute: TOpenDialog;
btnClear: TButton;
ColorDialog1: TColorDialog;
clrPanel: TPanel;
pbLoading: TProgressBar;
procedure btnAddPhotosClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnAddRoutesClick(Sender: TObject);
procedure clrPanelClick(Sender: TObject);
procedure TMSFNCMaps1MapInitialized(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Coords: TTMSFNCMapsBoundsRec;
end;
var
MapAlbumForm: TMapAlbumForm;
implementation
{$R *.dfm}
uses
jpeg, System.NetEncoding, EXIF4D;
function JpegToBase64(const AJpegFileName: string; Width: integer): string;
var
Src: TJPEGImage;
DstBmp: TBitmap;
DstJpg: TJPEGImage;
OutStream: TMemoryStream;
NewHeight: Integer;
NewWidth: Integer;
begin
Src := TJPEGImage.Create;
DstBmp := TBitmap.Create;
DstJpg := TJPEGImage.Create;
OutStream := TMemoryStream.Create;
NewWidth := Width;
try
Src.LoadFromFile(AJpegFileName);
if Src.Width <= 0 then
raise Exception.Create('Invalid JPEG width.');
NewHeight := Round(Src.Height * NewWidth / Src.Width);
DstBmp.SetSize(NewWidth, NewHeight);
DstBmp.Canvas.StretchDraw(Rect(0, 0, NewWidth, NewHeight), Src);
DstJpg.Assign(DstBmp);
DstJpg.CompressionQuality := 85;
DstJpg.SaveToStream(OutStream);
OutStream.Position := 0;
Result :=
'data:image/jpeg;base64,' +
TNetEncoding.Base64.EncodeBytesToString(
OutStream.Memory,
OutStream.Size
);
finally
OutStream.Free;
DstJpg.Free;
DstBmp.Free;
Src.Free;
end;
end;
function AddImageOnMap(Map: TTMSFNCMaps; fname: string; idx: integer; var Coords: TTMSFNCMapsBoundsRec): boolean;
var
img: TAdvCloudExifImage;
m: TTMSFNCMapsMarker;
lon,lat: double;
begin
Result := false;
img := TAdvCloudExifImage.Create(MapAlbumForm);
try
img.AutoLoad := false;
img.FileName := fname;
img.LoadData;
if img.HasGPSData then
begin
lon := img.Longitude;
lat := img.Latitude;
outputdebugstring(pchar(Format('%.6f // %.6f',[img.Longitude, img.Latitude])));
if Coords.NorthEast.Longitude = 200 then
Coords.NorthEast.Longitude := lon;
if Coords.NorthEast.Latitude = 200 then
Coords.NorthEast.Latitude := lat;
if Coords.SouthWest.Longitude = 200 then
Coords.SouthWest.Longitude := lon;
if Coords.SouthWest.Latitude = 200 then
Coords.SouthWest.Latitude := lat;
if img.Longitude > Coords.NorthEast.Longitude then
Coords.NorthEast.Longitude := lon;
if img.Longitude < Coords.SouthWest.Longitude then
Coords.SouthWest.Longitude := lon;
if img.Latitude > Coords.NorthEast.Latitude then
Coords.NorthEast.Latitude := lat;
if img.Latitude < Coords.SouthWest.Latitude then
Coords.SouthWest.Latitude := lat;
Result := true;
m := Map.AddMarker(lat,lon);
m.IconURL := JpegToBase64(fname, 240);
end;
finally
img.Free;
end;
end;
procedure ClearCoords(var Coords: TTMSFNCMapsBoundsRec);
begin
// set coords outside valid range to indicate it is uninitialized
Coords.NorthEast.Longitude := 200;
Coords.NorthEast.Latitude := 200;
Coords.SouthWest.Longitude := 200;
Coords.SouthWest.Latitude := 200;
end;
procedure TMapAlbumForm.btnAddPhotosClick(Sender: TObject);
var
i: integer;
res,hasgps: boolean;
begin
if openImage.Execute and (openImage.Files.Count > 0) then
begin
hasgps := false;
pbLoading.Max := openImage.Files.Count;
for i := 0 to openImage.Files.Count - 1 do
begin
pbLoading.Position := i + 1;
res := AddImageOnMap(TMSFNCMaps1, openImage.Files[i], i, Coords);
if res then
hasgps := true;
end;
pbLoading.Position := 0;
if not hasgps then
begin
ShowMessage('Sorry, no images with GPS data found');
end
else
begin
if (Coords.NorthEast.Longitude <> 200) then
begin
if (Coords.NorthEast.Longitude = Coords.SouthWest.Longitude) and
(Coords.NorthEast.Latitude = Coords.SouthWest.Latitude) then
TMSFNCMaps1.SetCenterCoordinate(Coords.NorthEast)
else
TMSFNCMaps1.ZoomToBounds(Coords.NorthEast, Coords.SouthWest);
end;
end;
end;
end;
procedure TMapAlbumForm.btnAddRoutesClick(Sender: TObject);
begin
if openRoute.Execute then
begin
TMSFNCMaps1.LoadGPXFromFile(openRoute.FileName, true, true, 3, clrPanel.Color);
end;
end;
procedure TMapAlbumForm.btnClearClick(Sender: TObject);
begin
TMSFNCMaps1.ClearMarkers;
TMSFNCMaps1.ClearPolylines;
end;
procedure TMapAlbumForm.FormCreate(Sender: TObject);
begin
ClearCoords(Coords);
end;
procedure TMapAlbumForm.TMSFNCMaps1MapInitialized(Sender: TObject);
begin
btnAddPhotos.Enabled := true;
btnAddRoutes.Enabled := true;
btnClear.Enabled := true;
end;
procedure TMapAlbumForm.clrPanelClick(Sender: TObject);
begin
if colordialog1.Execute then
begin
clrPanel.Color := ColorDialog1.Color;
end;
end;
end.