Knowledge Base Article
KB10777 - Please provide sample code showing how to make labels/symbols scalable, i.e, make the size automatically adjust with changes to the map scale?
1. For a given layer lv, assign methods to the layer’s OnPaintShapelabel and OnPaintShape events:
; if ( lv is TGIS_LayerVector ) then begin
; ; lv.OnPaintshapelabel := G_ZoomLabel ;
; ; lv.OnPaintShape := G_PaintShape ;
; end;
2. In the implementation of these methods, calculate the size of the labels and symbols. For example:
procedure TGIS.G_ZoomLabel( const _sender : TObject;
; ; ; ; ; const _shp : TGIS_SHape
; ; ; ; ; );
var
; ; size : Double ;
; ; begin
; ; size := StrToFloatDef( _shp.GetField( G_ATTR_FONT_SIZE ), 1.7 ) ;
; _shp.Params.Labels.Font.Height := round( size*_shp.Params.Labels.font.PixelsPerInch*FGIS.Scale );
; _shp.layer.Params.Labels.Height := 100*_shp.Params.Labels.font.Height;
; _shp.layer.Params.Labels.Width := 2*_shp.layer.Params.Labels.Height;
; _shp.Drawlabel;
; end;
procedure TGIS.G_PaintShape( const _sender : TObject;
; ; ; ; ; const _shp : TGIS_Shape
; ; ; ; ; );
var
; size : Integer;
begin
; If Assigned( _shp.Params.Marker.Symbol ) then begin
; ; ; size := -round( _shp.Params.Marker.Symbol.UserSize*_shp.Params.Labels.font.PixelsPerInch*FGIS.Scale );
; if size = 0 then
; ; _shp.Params.Marker.SmartSize := 1
; else
; ; _shp.Params.Marker.SmartSize := size ;
end;
; If Assigned( _shp.Params.Line.Symbol ) then begin
; ; size := round( _shp.Params.Line.Symbol.UserSize*_shp.Params.Labels.font.PixelsPerInch*FGIS.Scale );
; ; if size = 0 then
; ; ; _shp.Params.Line.SmartSize := 1
; ; else
; ; ; _shp.Params.Line.SmartSize := size ;
end;
; _shp.Draw ;
end;
Symbol and label sizes can also be set to automatically scale by using a setting within the visual layer property control, as described in Knowledge Base item KB10624.
Created: 2007-10-22, Modified: 2009-11-18
|