2

I am getting the GeoJSON URL from GeoServer and the data is getting displayed on the map using Leaflet. Now I need to display a few of the features based on the property "status" whether it is pass or rescan.

But I'm getting the following error:

Uncaught TypeError: Cannot read property 'status' of undefined

Below is my code:

var Dupont = new L.GeoJSON.AJAX("http://localhost:8080/geoserver/ABHI/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ABHI:Dupont_new&maxFeatures=50&outputFormat=application%2Fjson",{dataType:"json"});       
Dupont.addTo(map);


var stataupass=L.geoJson(Dupont, {
 filter: function(feature, layer) {
    return (feature.properties.status)=="rescan";
  }

}).addTo(map);

link to Geojson data (fiddle)

1
  • Your sample data works for me so I suspect that you are not getting anything returned in your Ajax call. So, I don't think it is your filter function that is at fault. +1 for alerting me to the L.GeoJSON.AJAX plugin though - I've always done old school Ajax calls! Commented Aug 25, 2016 at 12:43

1 Answer 1

1

leaflet-ajax plugin gives you directly an L.GeoJSON Layer Group (what you record in your Dupont variable).

Therefore you cannot feed Dupont into another L.geoJson() factory: it is not a plain GeoJSON data, but a Leaflet Layer Group. Hence the error message.

If you want to set some options (filter in your case) on that Layer Group, you can directly pass options as 2nd argument of L.geoJson.ajax() factory, even though it is not clearly advertised, exactly like for a regular L.GeoJSON group (besides the plugin special options):

L.geoJson.ajax(url, {
  dataType: "json",
  filter: fn
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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