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

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.

主站蜘蛛池模板: 会昌县| 宜州市| 静宁县| 如东县| 凤冈县| 平遥县| 霍山县| 揭东县| 恩施市| 壤塘县| 冕宁县| 白银市| 海原县| 玉溪市| 自治县| 湘潭县| 民丰县| 海南省| 衡阳市| 平乡县| 德保县| 乐清市| 乌兰察布市| 夏津县| 海林市| 阜新| 德昌县| 鄢陵县| 深水埗区| 新丰县| 泗洪县| 南溪县| 汕头市| 离岛区| 峨眉山市| 清远市| 拜泉县| 永年县| 巢湖市| 延川县| 德庆县|