createLegend method

void createLegend ()

Sets up the legend

Implementation

void createLegend() {
  Map<LegA, String> attr = Map.from(Legend.LEGEND_DEFAULT_ATTRIBUTES);
  if (legendAttr != null) {
    attr.addAll(legendAttr); // merge with defaults
    legendAttr = attr;
  } else {
    legendAttr = attr;
  }

  if (legendAttr[LegA.TOP_TITLE] == null) {
    return;
  }

  int nsubtitles = 0;
  List<String> subtitles;
  // setup the subtitle lines, use same color as for polylines
  if (legendAttr[LegA.SUB_TITLES] != null) {
    subtitles = json.decode(legendAttr[LegA.SUB_TITLES]).cast<String>();
    nsubtitles = subtitles.length;
  }

  legend = Legend(legendAttr, nsubtitles); // create the legend

  // draw subtitles only if nsubtitles > 0:
  // - cut color list to the number needed
  // - note that setText draws from bottom up
  List<String> colors = List.from(poly_colors.sublist(0, nsubtitles));
  for (int i = nsubtitles - 1; i >= 0; i--) {
    legend.setText("${i + 1}", subtitles[i], colors[i]);
  }
}