Search code examples
delphigmlib

Create new polygon by code


I have look into MegaDemo code, but could not find a way to create Polygon by code. Can someone help me how this is done .

I have tried

GMPolygon1.Add.AddLinePoint(5.54491313409736, 100.162353515625);
GMPolygon1.Add.AddLinePoint(5.34805212812321, 100.483703613281);
GMPolygon1.Add.AddLinePoint(5.23318714302897, 100.1953125);

no polygon displayed, I also need to make it editable and captured the editable coordinates. Some direction mmuch appreciated.


Solution

  • Try with this

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with GMPolygon1.Add do
      begin
        AddLinePoint(5.54491313409736, 100.162353515625);
        AddLinePoint(5.34805212812321, 100.483703613281);
        AddLinePoint(5.23318714302897, 100.1953125);
        Editable := True;
      end;
    end;
    
    procedure TForm1.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
    begin
      if first then GMMap1.DoMap;
    end;
    
    procedure TForm1.GMPolygon1PathChange(Sender: TObject; Index: Integer;
      LinkedComponent: TLinkedComponent);
    begin
      ShowMessage('Path change!!');
    end;