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