I have a googlemap (TTMSFNCGoogleMaps) and I would like to add labels to show polygon and polyline names. Also I want to have an option to turn the labels on/off. Is there a way to edit labels and delete them?
Custom labels can be added to the map at a specified location with the Labels
property.
Add a label:
procedure TForm1.ButtonAddClick(Sender: TObject);
var
MapsLabel: TTMSFNCMapsLabel;
begin
TMSFNCMaps1.BeginUpdate;
MapsLabel := TMSFNCMaps1.AddLabel(40, -74, '<b>Bold</b><br>linebreak', gcWhite, gcDarkslateblue);
MapsLabel.Font.Size := 24;
TMSFNCMaps1.EndUpdate;
end;
Update a label:
procedure TForm1.ButtonEditClick(Sender: TObject);
begin
if TMSFNCMaps1.Labels.Count > 0 then
begin
TMSFNCMaps1.BeginUpdate;
TMSFNCMaps1.Labels[0].Text := 'updated';
TMSFNCMaps1.EndUpdate;
end;
end;
Delete a label:
procedure TForm1.ButtonDeleteClick(Sender: TObject);
begin
if TMSFNCMaps1.Labels.Count > 0 then
begin
TMSFNCMaps1.BeginUpdate;
TMSFNCMaps1.Labels[0].Free;
TMSFNCMaps1.EndUpdate;
end;
end;
Further info can be found in the online doc:
Please note that the Google Maps API does not have built-in support to add show labels for polygon and polyline names.
Thanks for quick response!
I got this error message:
"E2247 'TTMSFNCCustomMaps::Labels' is not accessible".
Here are my codes:
void DeleteLabelsFromTMSMap(TTMSFNCGoogleMaps* TheMap) {
//delete all labels
TheMap->BeginUpdate();
int TotalLabelNo=TheMap->Labels->Count;
for (int i = TotalLabelNo-1; i >=0; i--) {
TheMap->Labels->Delete(i);
}
TheMap->EndUpdate();
}
Is there anything I did wrong?
Thanks!
I got it to work by converting the googlemap to TTMSFNCCustomMaps. Labels is accessible for TTMSFNCCustomMaps class. Thanks!