TimeSlider Plugin and Leaflet - Markers not appearing in order

后端 未结 1 1891
天命终不由人
天命终不由人 2021-01-25 06:02

Updated with a JSFIDDLE link

I am using LeafletJS to build a web map with a timeline slider. I am using the LeafletSlider plugin to show a group of markers based on a G

1条回答
  •  太阳男子
    2021-01-25 06:09

    EDIT:

    As ghybs mentions below (and shows in an example), the proper way to ensure that the slider returns data in the correct order is to sort the options.markers array of the sliderControl:

    sliderControl.options.markers.sort(function(a, b) {
        return (a.feature.properties.DATE_START > b.feature.properties.DATE_START);
    });
    

    My original answer (below) sorts the features of the GeoJSON, but this does not guarantee that Leaflet will return them in the correct order.


    Original answer:

    You can use the array.sort method to sort the features array in place:

    camps.features.sort(function(a, b) {
      return (a.properties.DATE_START > b.properties.DATE_START);
    });
    

    http://jsfiddle.net/nathansnider/ngeLm8c0/4/

    0 讨论(0)
提交回复
热议问题