-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathChatFMX.Frame.Attachment.Geo.pas
96 lines (82 loc) · 2.57 KB
/
ChatFMX.Frame.Attachment.Geo.pas
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
unit ChatFMX.Frame.Attachment.Geo;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
VK.API, FMX.Objects, VK.Types, System.Messaging, VK.Entity.Geo,
ChatFMX.Frame.Attachment;
type
TFrameAttachmentGeo = class(TFrameAttachment)
RectangleMap: TRectangle;
private
FImageUrl: string;
FImageFile: string;
procedure FOnReadyImage(const Sender: TObject; const M: TMessage);
public
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
destructor Destroy; override;
procedure Fill(Geo: TVkGeo); overload;
procedure Fill(Geo: TVkGeoWall); overload;
end;
implementation
uses
ChatFMX.PreviewManager, System.Threading;
{$R *.fmx}
{ TFrameAttachmentPhoto }
constructor TFrameAttachmentGeo.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited;
end;
destructor TFrameAttachmentGeo.Destroy;
begin
TPreview.Instance.Unsubscribe(FOnReadyImage);
inherited;
end;
procedure TFrameAttachmentGeo.Fill(Geo: TVkGeo);
var
Lat, Long: string;
begin
if Assigned(Geo.Place) then
RectangleMap.Hint := Geo.Place.Title;
if Assigned(Geo.Coordinates) then
begin
Lat := Geo.Coordinates.Latitude.ToString.Replace(',', '.');
Long := Geo.Coordinates.Longitude.ToString.Replace(',', '.');
FImageUrl :=
'https://static-maps.yandex.ru/1.x/?ll=' + Long + ',' + Lat + '&size=340,127&z=12&lang=ru_RU&l=map&pt=' + Long + ',' + Lat + ',vkbkm';
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage);
end;
end;
procedure TFrameAttachmentGeo.Fill(Geo: TVkGeoWall);
begin
if Assigned(Geo.Place) then
RectangleMap.Hint := Geo.Place.Title;
if not Geo.Coordinates.IsEmpty then
begin
FImageUrl :=
'https://static-maps.yandex.ru/1.x/?ll=' + Geo.Coordinates + '&size=340,127&z=12&lang=ru_RU&l=map&pt=' + Geo.Coordinates + ',vkbkm';
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage);
end;
end;
procedure TFrameAttachmentGeo.FOnReadyImage(const Sender: TObject; const M: TMessage);
var
Data: TMessagePreview absolute M;
begin
if Data.Value.Url <> FImageUrl then
Exit;
TPreview.Instance.Unsubscribe(FOnReadyImage);
FImageFile := Data.Value.FileName;
if FImageFile.IsEmpty then
begin
RectangleMap.Fill.Kind := TBrushKind.Solid;
end
else
try
RectangleMap.Fill.Bitmap.Bitmap.LoadFromFile(FImageFile);
RectangleMap.Fill.Kind := TBrushKind.Bitmap;
RectangleMap.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
except
RectangleMap.Fill.Kind := TBrushKind.Solid;
end;
end;
end.