Scalable Text on a Map

Problem I'm looking for a way to display scalable text on a map image. How do I make sure the text is displayed using a font size which is proportional to the magnification of the map.
Solution Assuming that you know which pixel position the text has to be placed at, you could use the OnDataRendered event to display a scaled text at this position. Here's a sample code of the event handler:
procedure TForm1.GM1DataRendered(Sender: TObject; Canvas: TCanvas);

const
  FontNormSize = 12;  // font size when magnification equals 1.0

var
  p : TPoint;

begin
p.X := 200;    // location of text in pixel coordinates (map reference frame)
p.Y := 100;
p := GM1.MapImageToControl(p);
Canvas.Font.Size := round(GM1.Magnification*FontNormSize);
Canvas.TextOut(p.x,p.y,'hello');
end;

Hint: In order to convert geographical coordinates to pixel positions in the map reference frame you may use the functions CalcPixelCoords and CalcPixelCoordsUTM.

 


Last Update: 2012-11-25