官术网_书友最值得收藏!

Sorting the feature list

So far, no use has been made of the third piece of data in the coordinates list, which is the depth of the quake. This data will be presented in the form of a sorted list of the current features when the user presses the Sort button. Let's have a look at the following code snippet:

void sortFeatures(Event evt) {
  featPlotter.sortFeatures();
  DivElement out = querySelector('#depthDetail');
  out.nodes.clear();
  featPlotter.geoFeatures.forEach((feature) {
    LIElement detail = new LIElement();
    detail.innerHtml = "${feature[5]}km - ${feature[3]}";
    out.nodes.add(detail);
  });
}

The list of features is sorted in the method sortFeatures, and as Dart knows nothing of the meaning of the contents of the list, we provide a comparator function that decides which feature is deeper by comparing the depth measurement held at index 5 of the list:

  List sortFeatures(){
    geoFeatures.sort( (a,b) => a[5] - b[5] );
    return geoFeatures;
  }

The comparator receives two arguments and returns 0 for items that are equal, a negative integer if a is less than b, or a positive integer if a is greater than b. Let's have a look at the following screenshot:

Sorting the feature list

The depths are sorted in ascending order and presented as a simple bulleted list together with the location information.

主站蜘蛛池模板: 临西县| 白山市| 丹东市| 开原市| 洪泽县| 磐安县| 轮台县| 揭东县| 库伦旗| 安福县| 金沙县| 上饶市| 西平县| 神农架林区| 六盘水市| 竹山县| 新民市| 金华市| 梅河口市| 兴义市| 民勤县| 安龙县| 邹平县| 姚安县| 武川县| 郁南县| 靖州| 禹城市| 永年县| 阳山县| 资溪县| 海阳市| 阳谷县| 株洲县| 北辰区| 东港市| 施甸县| 隆昌县| 万州区| 临颍县| 彭泽县|