I needed the ability to display a label on top of polygons. So I came up with the following code and respectfully ask this code be considered to be icluded in the WebGMaps product.
In WebGMapsConst.pas
First, declare a new array in which we will store the polygons info windows...
'<script type="text/javascript">' + #13 +
...
...
' var allPolygonsInfoWindows = [];' + #13 +
Then add the following JavaScript routines to display/close the polygons info windows...
' function DisplayInfoWindow(aPolygonId, aLat, aLng, aCaption){ ' + #13 +
' var LatLong = new google.maps.LatLng(parseFloat(aLat),parseFloat(aLng));' + #13 +
' var infowindow = new google.maps.InfoWindow({polygonId: aPolygonId, position:LatLong, content:aCaption}); ' + #13 +
' infowindow.open(map);' + #13 +
' allPolygonsInfoWindows.push(infowindow); ' + #13 +
' }' + #13 +
' ' + #13 +
' function CloseInfoWindow(aPolygonId){ ' + #13 +
' for (var i = 0; i < allPolygonsInfoWindows.length; i++){' + #13 +
' infowindow = allPolygonsInfoWindows;' + #13 +
' if (infowindow.polygonId == aPolygonId) {' + #13 +
' infowindow.close();' + #13 +
' }' + #13 +
' }' + #13 +
' }' + #13 +
' ' + #13 +
' function CloseAllPolygonsInfoWindows() ' + #13 +
' { ' + #13 +
' for (var i = 0; i < allPolygonsInfoWindows.length; i++)' + #13 +
' {' + #13 +
' infowindow = allPolygonsInfoWindows;' + #13 +
' infowindow.close();' + #13 +
' }' + #13 +
' }' + #13 +
' ' + #13 +
In WebGMaps.pas
procedure TWebGMaps.DisplayInfoWindow(APolygonId: Integer; ALat, ALong: Double; ACaption: String);
begin
InvokeScript( Format( 'DisplayInfoWindow(%d, %.12f, %.13f, "%s" )',
[ APolygonId, ALat, ALong, ACaption ] ) );
end;
procedure TWebGMaps.CloseAllPolygonsInfoWindows;
begin
InvokeScript( 'CloseAllPolygonsInfoWindows();' );
end;
procedure TWebGMaps.CloseInfoWindow( APolygonId: Integer );
begin
InvokeScript( Format( 'CloseInfoWindow(%d)',
[ APolygonId ] ) );
end;
The consumer of this code can then add the appropriate calls to display a label when a polygon is created/edited.
Kind Regards,
Richard