New polygon event - OnPolygonChanged (code incl.)

I added a new event (OnPolygonChanged) and would like to respectfully submit the changes be incorporated into the TWebGMaps product. 

Please see changes:

In UWebGMaps.pas

interface 

TWebGMaps = class(TWebGMapsBrowser)
  private
  ...
    FOnPolygonChanged: TEventPolygon;
  ...
  protected
  ...
    procedure PolygonChanged(Sender: TObject; IdPolygon:Integer);
  ...
  published
  ...
    property OnPolygonChanged: TEventPolygon read FOnPolygonChanged write FOnPolygonChanged;
  ...
end

implementation

procedure TWebGMaps.PolygonChanged(Sender: TObject; IdPolygon: Integer);
begin
  if Assigned(FOnPolygonChanged) then
    FOnPolygonChanged(Sender,IdPolygon);
end;

constructor TWebGMaps.Create(AOwner: TComponent);
begin
...
  FWebBrowser.OnPolygonChanged := Self.PolygonChanged;
...
end;

In UWebGMapsBrowser.pas

interface

TAppWrapper = class(TObjectWrapper)
  private
    ...
FOnPolygonChanged: TEventPolygon;  
...
  public
    ...
procedure ExternalPolygonChanged(IdPolygon:Integer); 
    ...
  published
    ...
property OnPolygonChanged: TEventPolygon read FOnPolygonChanged write FOnPolygonChanged;
...
  end;
  
  TNewWebBrowser = class(SHDocVw.TWebBrowser, IDocHostUIHandler)
  private
    ...
FOnPolygonChanged: TEventPolygon;
...
  public  
    ...
property OnPolygonChanged: TEventPolygon read FOnPolygonChanged write FOnPolygonChanged
...
  end;
  
implementation

function TNewWebBrowser.GetExternal(out ppDispatch: IDispatch): HResult;
begin
  ...
  AppWrap.OnPolygonChanged := Self.FOnPolygonChanged;  
  ...
end;

procedure TAppWrapper.ExternalPolygonChanged(IdPolygon: Integer);
begin
  if Assigned(FOnPolygonChanged) then
    FOnPolygonChanged(Self,IdPolygon);
end;


In UWebGMapsConst.pas

Add the following events

    //RD
    // Loop through all paths in the polygon and add listeners
    // to them. If we just used `getPath()` then we wouldn't
    // detect all changes to shapes like donuts.
    '  polygon.getPaths().forEach(function(path, index){' + #13 +
    ' ' + #13 +
    '    google.maps.event.addListener(path, "insert_at", function(){ ' + #13 +
    // New point
    '    polygonId=-1;' + #13 +
    '          for (var i = 0; i < allpolygons.length; i++){' + #13 +
    '            if (allpolygons==polygon) {' + #13 +
    '              polygonId=i;' + #13 +
    '            }' + #13 +
    '          }' + #13 +
    '          external.ExternalPolygonChanged(polygonId);' + #13 +
    '    });' + #13 +
    ' ' + #13 +
    '    google.maps.event.addListener(path, "remove_at", function(){ ' + #13 +
    // Point was removed
    '    polygonId=-1;' + #13 +
    '          for (var i = 0; i < allpolygons.length; i++){' + #13 +
    '            if (allpolygons==polygon) {' + #13 +
    '              polygonId=i;' + #13 +
    '            }' + #13 +
    '          }' + #13 +
    '          external.ExternalPolygonChanged(polygonId);' + #13 +
    '    }); ' + #13 +
    ' ' + #13 +
    '    google.maps.event.addListener(path, "set_at", function(){ ' + #13 +
    // Point was moved
    '    polygonId=-1;' + #13 +
    '          for (var i = 0; i < allpolygons.length; i++){' + #13 +
    '            if (allpolygons==polygon) {' + #13 +
    '              polygonId=i;' + #13 +
    '            }' + #13 +
    '          }' + #13 +
    '          external.ExternalPolygonChanged(polygonId);' + #13 +
    '    }); ' + #13 +
    ' ' + #13 +
    '  }); ' + #13 +
    ' ' + #13 +
    '  google.maps.event.addListener(polygon, "dragend", function(){ ' + #13 +
    // Polygon was dragged
    '    polygonId=-1;' + #13 +
    '          for (var i = 0; i < allpolygons.length; i++){' + #13 +
    '            if (allpolygons==polygon) {' + #13 +
    '              polygonId=i;' + #13 +
    '            }' + #13 +
    '          }' + #13 +
    '          external.ExternalPolygonChanged(polygonId);' + #13 +
    '  }); ' + #13 +
    //RD

Now, let's use it...

procedure TMapViewer.WebGMapsPolygonChangedEvent(Sender: TObject;
  IdPolygon: Integer);
begin
  ShowMessage( 'Polygon was changed' );
end;

Kind Regards,
Richard  
  
Hi,

Thank you for your suggestion.
We'll consider adding this functionality in a future version of TMS WebGMaps.
This suggestion has been implemented.

Two new events have been added:
OnPolygonChanged and OnPolylineChanged.
The OnPolygonChanged event is compatible with Polygons of type ptPath, ptCircle and ptRectangle.
The update will be available with the next update of TMS WebGMaps.

Thank you.

I am using the latest version and the PolygonChanged event only fires once (at the very first edit). Any other edits are missed.

Looks like you've added funcionality to the CreateMapPolygon function but didn't add anything into the UpdateMapPolygon.


Thank you for notifying.
This issue has now been fixed.
The update will be available with the next release of the TMS WebGMaps.