ApplyLegendColors in Delphi

Oct 8, 2012 at 11:35 AM

Hello!

I'm Russian, so I apologize for my English.Can not display a legend in Mapschindoschgis development environment Delphi 7.Here is the code

break:=CoShapefileColorBreak.Create;
      break.Caption:='test';
      break.StartColor:=RGB(255,221,187);
      break.EndColor :=RGB(255,221,187);
      break.StartValue:=33330;
      break.EndValue:=38000;
     colorSheme:=CoShapefileColorScheme.Create;
     colorSheme.LayerHandle:=handler;
       colorSheme.FieldIndex:=0;
      colorSheme.Add(break);
     Map1.ApplyLegendColors(colorSheme);
But nothing is displayed, perhaps help...

Coordinator
Oct 10, 2012 at 6:45 AM

We don't have a lot of sample code for Delphi. I do know a few people use MapWinGIS with Delphi and most of them have issues getting started.

You might also want to look at the forums at http://www.mapwindow.org/phorum/index.php

I can already tell you the symbology has been changed in the latest version. You need to look at Categories:
http://www.mapwindow.org/documentation/mapwingis4.8/class_shapefile_category.html

Here's some sample code using it:
http://www.mapwindow.org/phorum/read.php?2,24207,24223#msg-24223

--
Paul

Dec 29, 2014 at 2:40 PM
What kind od components ara CoShapeFileColorBreak and CoShapeFileColorScheme?
Developer
Dec 29, 2014 at 4:32 PM
This code will only work in earlier versions (I don't see what version you are using). In 4.8/4.9 the proper way to go is to use Shapefile.Categories.Generate. ColorScheme and ColorBreak classes are [marked as deprecated] in the docs (http://www.mapwindow.org/documentation/mapwingis4.9/class_shapefile_color_scheme.html). In fact in the current 4.9.3 release they were totally removed from the API.
Marked as answer by pmeems on 1/1/2015 at 3:02 AM
Jan 17, 2015 at 8:33 AM
Edited Jan 18, 2015 at 7:40 AM
Hi Andrey,

Ik you are working with Delphi 5 or above and mapwingis > 4.8 the code snippet from 'HandleLayer = 0' to set random colors to fill the current layer can be useful for you.

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;

Peter