Quantcast
Viewing all articles
Browse latest Browse all 2341

New Post: ApplyLegendColors in Delphi

Hi Andrey,

Ik you are working with Delphi 5 or above and mapwingis > 4.8 following code snippet for 'HandleLayer = 0' to set random colors for the current layer filling.
Only then bold code represents the use of colorscheme

procedure TViewer.btnOpenClick(Sender: TObject);
var
fName: string;
Rec: PLRec;
idx: integer;
clr: ColorScheme;
begin
OpenDialog1.InitialDir := ExtractFilePath(ParamStr(0)) + 'Maps\';
SetCurrentDir(ExtractFileDir(ParamStr(0)) + 'Maps\');
if (opendialog1.Execute) and (opendialog1.FileName <> '') then
begin
fName := opendialog1.FileName;
shp := CoShapefile.Create;
shp.Open(fName, nil);
HandleLayer := map1.AddLayer(shp, true);
if HandleLayer = 0 then
begin
  if map1.Shapefile[HandleLayer].NumShapes < 50 then
  begin
    idx := map1.Shapefile[HandleLayer].Table.FieldIndexByName['Name'];
    map1.Shapefile[HandleLayer].Categories.Generate(idx, ctUniqueValues, 7);
    map1.Shapefile[HandleLayer].Categories.ApplyExpressions;
    clr := CoColorScheme.create;
    clr.SetColors2(wheat, Salmon);
    map1.Shapefile[HandleLayer].Categories.ApplyColorScheme(ctUniqueValues, clr);
  end
  else
  begin
    map1.Shapefile[HandleLayer].DefaultDrawingOptions.FillColor := clWhite;
    map1.Shapefile[HandleLayer].DefaultDrawingOptions.LineColor := clblack;
  end;
end;

if HandleLayer > 0 then
begin
  map1.ShapelayerFillTransparency[HandleLayer] := 0.1;
  map1.ShapeLayerLineColor[HandleLayer] := clred;
  map1.ShapeLayerLineWidth[HandleLayer] := 2.0;
end;
end
else
begin
showMessage('You have to select a shape file first!');
exit;
end;
new(Rec);
rec^.lyrid := HandleLayer;
chklayer.Items.AddObject(fname, TObject(rec));
map1.LayerVisible[HandleLayer] := False;
HandleLayer := HandleLayer + 1;
CheckListboxState(chklayer);
end;

Viewing all articles
Browse latest Browse all 2341

Trending Articles