0

I'm trying to add about 13 thousand points in a map using the TimeSlide plugin, but my points are not following a logical order of appearance. When I use the slider I get the dates in the box below in a arbitrary order, I'm tryng to add based in a yearly progression by the first year being 1985 and the last year being 2013. Here is my code:

        //calling the geoJSON    
        var SaoPaulo = L.geoJson(SP_ResSinglePoint, {

            pointToLayer: function (feature, latlng) {
                var popupContent = "<b>Year Built: </b>" + feature.properties.Timestrg;
                //console.log(popupContent);
                return L.circleMarker(latlng, Style(feature)).bindPopup(popupContent);
            },

        });

        //Create sliderControl
        var sliderControl = L.control.sliderControl({
            position: "bottomright",
            layer: SaoPaulo,
            range: true,
            timeAttribute: "Timestrg",
            follow: true,
        });

        //add sliderControl to the map
        map.addControl(sliderControl);

        //initialize sliderControl
        sliderControl.startSlider()

Part of my json:

 "features": [{
    "type": "Feature",
    "properties": {
        "ID": 15897,
        "Time": 2013,
        "Timestrg": "2013"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-46.793243, -23.691582]
    }
}, {
    "type": "Feature",
    "properties": {
        "ID": 7422,
        "Time": 2001,
        "Timestrg": "2001"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-46.800534, -23.687368]
    }

The documentation says that I have to alter the time property to fit my project, I believe that by using the timeAttribute: "Timestrg", it changes the time attribute right?

Best,

Updated code with part of my geoJson request.

0

Seems that you need to order the geojson first.

// take your geojson features
var featuresArray = geojson.features;

featuresArray = featuresArray.sort(function(a,b) { 
    return parseFloat(a.properties.Timestrg) - parseFloat(b.properties.Timestrg) } 
);

var orderGeojson = {
    "type": "FeatureCollection",
     "features": []
}
orderGeojson.features = featuresArray;

// include geojson layer
var SaoPaulo = L.geoJson(orderGeojson)

Order function taken from this stackoverflow question

  • Thanks for the tip, but I still having trouble, now I get the error: Uncaught TypeError: Cannot read property 'sort' of undefined. Isn't sorta function that has to be defined? – Ricardo Oliveira Apr 4 '15 at 18:55
  • 1
    Like sigon pointed earlier I did have to order my geoJson, but since I'm not that proficient in javascript I could not use function to make do it. Instead, I took my original shapefile and used the Sort tool in ArcGIS to make it ascendant, after that I just re-converted to geoJson and done! I will make it as a answer since it lead me to the right path. However if someone knows any alternative to ESRI's tool feel free to say! – Ricardo Oliveira Apr 5 '15 at 2:08
  • 1
    Hey Ricardo, you can use QGIS, there is a plugin called MMQGIS [michaelminn.com/linux/mmqgis/]. Sort tool permits sorting of attribute data and associated shapefile data to maintain alignment.DOnt know why the js sort gives you an error, sort function dont have to be defined. – sigon Apr 6 '15 at 12:03
  • The eror is maybe in the featuresArray var, it should be defined with the name of your geojson, like this: var featuresArray = yourGeojsonName.features – sigon Apr 6 '15 at 12:09
0

I know it's almost a year since this question was posted, but I had the same issue and I was able to solve it. Here's my question if you want to see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.