Skip to content Skip to sidebar Skip to footer

Timeslider Plugin And Leaflet - Markers Not Appearing In Order

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 GEOJSON prop

Solution 1:

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/

Post a Comment for "Timeslider Plugin And Leaflet - Markers Not Appearing In Order"