Search code examples
delphileaflettms-web-core

How do I draw a line between two coordinates in the TWebLeafletMaps component?


In this blog post, they clearly show how to draw a line between coordinates:

procedure TForm2.WebFileUpload1GetFileAsText(Sender: TObject; AFileIndex: Integer; AText: string);  
var  
  ja: TJSArray;  
begin  
  ja := GPXToCoordinates(AText);  
  WebLeafletMaps1.AddPolyLine(ja, clBlue, 3);
end;

So you can draw lines using the AddPolyLine function, but I'm having some trouble with what to pass to the AddPolyLine function. They're using the GPXToCoordinates function to convert a GPX file to a TJSArray, but how should this array look?

How can I use my own custom coordinates for the AddPolyLine function? I don't want to use a GPX file.


Solution

  • This is how you can draw a line between two points on the map without needing to use a GPX file:

    procedure TForm1.WebFormShow(Sender: TObject);
    var
      MyCoordinates: TJSArray;
    begin
      MyCoordinates := TJSArray.New;
      asm
        MyCoordinates = [
          [-27.1251322, 23.1663553],
          [-28.1244564, 26.1643535]
        ];
      end;
    
    
      WebLeafletMaps1.AddPolyLine(MyCoordinates, clBlue, 3);
    end;