Monday 9 January 2017

geoserver - GeoJSON filtering based on properties not working


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)



Answer



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
});

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...