Imagien that I am tracking a car, capturing its lat/long as it drives. At regular intervals, I want to add its latest piece of travel to the map.
I think that that means that I want to add aPolyLineItem to the WeGmap's Path?
Can soemone pelase look at the simple code below and tell me how I would add the 3rd point, not when adding the PolyLine ot the map, but later, when the timer expires?
Thanks in advance.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UWebGMapsCommon, UWebGMaps, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
WebGMaps1: TWebGMaps;
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
procedure WebGMaps1FullyInitialized(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses UWebGMapsPolylines;
procedure TForm1.FormShow(Sender: TObject);
begin
Timer1.Enabled := False;
WebGMaps1.MapOptions.DefaultLatitude := 38.58108;
WebGMaps1.MapOptions.DefaultLongitude := -105.63535;
WebGMaps1.MapOptions.ZoomMap := 11;
WebGMaps1.OnDownloadFinish := WebGMaps1FullyInitialized;
WebGMaps1.Launch();
end;
procedure TForm1.WebGMaps1FullyInitialized(Sender: TObject);
var
Path: TPath;
pi: TPathItem;
Symbols: TSymbols;
si: TSymbol;
Item: TPolylineItem;
begin
Path := TPath.Create;
pi := Path.Add;
pi.Latitude := 38.58108;
pi.Longitude := -105.63535;
pi := Path.Add;
pi.Latitude := 38.58108;
pi.Longitude := -105.74565;
// I want to do this when the timer expires, not here. How?
pi := Path.Add;
pi.Latitude := 38.68108;
pi.Longitude := -105.74565;
Symbols := TSymbols.Create;
si := Symbols.Add;
si.SymbolType := UWebGMapsCommon.stCircle;
si.Offset := 0;
si := Symbols.Add;
si.SymbolType := UWebGMapsCommon.stForwardClosedArrow;
si.Offset := 100;
Item := WebGMaps1.Polylines.Add(True, True, False, Symbols, Path, clBlue, 255, 4, True, 0);
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
// How to extend the path here?
end;
end.
Hi,
- Call WebGMaps1.UpdateMapPolyline(WebGMaps1.Polylines[0].Polyline);
Sorry, it isn't working, after I add the 3rd Path Item, WebGMaps1.Polylines[0].Polyline.path.count is still 2.
Can you see what I am doing wrong?
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UWebGMapsCommon, UWebGMaps, Vcl.ExtCtrls,
UWebGMapsPolylines;
type
TForm1 = class(TForm)
WebGMaps1: TWebGMaps;
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
Path: TPath;
procedure WebGMaps1FullyInitialized(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Timer1.Enabled := False;
WebGMaps1.MapOptions.DefaultLatitude := 38.58108;
WebGMaps1.MapOptions.DefaultLongitude := -105.63535;
WebGMaps1.MapOptions.ZoomMap := 11;
WebGMaps1.OnDownloadFinish := WebGMaps1FullyInitialized;
WebGMaps1.Launch();
end;
procedure TForm1.WebGMaps1FullyInitialized(Sender: TObject);
var
pi: TPathItem;
Symbols: TSymbols;
si: TSymbol;
Item: TPolylineItem;
begin
Path := TPath.Create;
pi := Path.Add;
pi.Latitude := 38.58108;
pi.Longitude := -105.63535;
pi := Path.Add;
pi.Latitude := 38.58108;
pi.Longitude := -105.74565;
Symbols := TSymbols.Create;
si := Symbols.Add;
si.SymbolType := UWebGMapsCommon.stCircle;
si.Offset := 0;
si := Symbols.Add;
si.SymbolType := UWebGMapsCommon.stForwardClosedArrow;
si.Offset := 100;
Item := WebGMaps1.Polylines.Add(True, True, False, Symbols, Path, clBlue, 255, 4, True, 0);
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var pi: TPathItem;
begin
Timer1.Enabled := False;
pi := Path.Add;
pi.Latitude := 38.68108;
pi.Longitude := -105.74565;
// At this point, WebGMaps1.Polylines[0].Polyline.path.count is still 2
WebGMaps1.UpdateMapPolyline(WebGMaps1.Polylines[0].Polyline);
end;
end.
When updating the Polyline path you should use the Polyline.Path instead of the Path object.
pi.Latitude := 38.68108;
pi.Longitude := -105.74565;
WebGMaps1.UpdateMapPolyline(WebGMaps1.Polylines[0].Polyline);
Bart Holvoet2013-09-18 03:24:48
Thank you you so very much!