Yonker
Yonker

Reputation: 124

Leaflet, geojson: filter out entire features/objects with a null value in them

I have a geojson file which I'm getting from this website which somehow contains corrupt data, with a coordinate value = null.

http://measuringamsterdam.nl/datalist/kijk/

And I'm using it in my code like this:

//Retrieve all data and add to map
$.each(datalistObject['idlist'], function(key, value) { 
    $.getJSON('http://measuringamsterdam.nl/datalist/kijk/' + value['id'], function(data) {

        textbox = value['name'];

        var dataid = L.geoJson([data], {

            style: function (feature) {
                return feature.properties && feature.properties.style;
            },
            onEachFeature: onEachFeature,
            pointToLayer: function (feature, latlng) {
                return L.marker(latlng, {
                    icon: value['icon']
                });
            }
        }).addTo(jsonGroup);

        console.log(jsonGroup);

    },function(xhr) { console.error(xhr); });
});

Now somehow I need to filter out the features/objects where the coordinates have a null value.

I really need to filter the data that point in my code since I need the + value['id'] part in the getJSON code.

Ane ideas?

Upvotes: 1

Views: 672

Answers (1)

Titsjmen
Titsjmen

Reputation: 809

Using the following code you will generate a new array. Which will include only the filtered data.

var newArray = data.filter(function (el) {
     return el.value != 'null';
});

You can also apply multiple filters, for example:

 return el.value_a != 'null' && el.value_b > 100;

Hopefully this will work!

Upvotes: 2

Related Questions