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

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.

主站蜘蛛池模板: 阿拉善右旗| 应用必备| 阜阳市| 赣州市| 临桂县| 富川| 墨竹工卡县| 资溪县| 常熟市| 宝丰县| 黎川县| 囊谦县| 简阳市| 日照市| 河东区| 雷州市| 正镶白旗| 金川县| 平谷区| 乌兰察布市| 双城市| 松潘县| 延长县| 泸西县| 龙南县| 揭西县| 兴安盟| 丹棱县| 曲周县| 罗源县| 泌阳县| 阿勒泰市| 天长市| 章丘市| 新昌县| 怀宁县| 阳春市| 堆龙德庆县| 米脂县| 平南县| 涞水县|