0

I WFS request from Leaflet to GeoServer is successful (200). But no features have been displayed. Response of request is big GeoJSON with features. What is the problem and what is wrong with my code (how to display features)? I used one from examples from StackOverflow answers.

var owsrootUrl = 'http://gis-domen/geoserver/ows';

               var defaultParameters = {
                    service : 'WFS',
                    version : '2.0',
                    request : 'GetFeature',
                    typeName : 'test_osm:my_points',
                    outputFormat : 'application/json',
                    format_options : 'callback:getJson',
                    SrsName : 'EPSG:3857'
                };

                var parameters = L.Util.extend(defaultParameters);
                var URL = owsrootUrl + L.Util.getParamString(parameters);

                var WFSLayer = null;

                var ajax = $.ajax({
                    url : URL,
                    dataType : 'json',
                    jsonpCallback : 'getJson',
                    success : function (response) {
                        WFSLayer = L.geoJson(response, {
                            style: function (feature) {
                                return {
                                    stroke: false,
                                    fillColor: 'black',
                                    fillOpacity: 0
                                };
                            },
                            onEachFeature: function (feature, layer) {
                                popupOptions = {maxWidth: 200};
                                layer.bindPopup("geom"
                                    ,popupOptions);
                            }
                        }).addTo(mymap);
                    }
                });   
  • Did you check in debugger contents of response in $.ajax call ? – TomazicM Jul 19 at 14:22
  • @TomazicM message: "response is not defined" stack: "ReferenceError: response is not defined↵ at eval (eval at <anonymous> (file:///D:/index.html:74:17), <anonymous>:1:1)↵ at file:///D:/index.html:101:17" __proto__: Error – Tyomik_mnemonic Jul 19 at 14:41
  • If you set break at line that starts with WFSLayer = L.geoJson(response, { ..., you should be able to inspect value of response. – TomazicM Jul 19 at 14:48
  • @TomazicM Thanks, but no. ReferenceError: response is not defined for every strings – Tyomik_mnemonic Jul 19 at 14:51
  • 1
    comment out format_options and jsonpcallback lines – neogeomat Jul 19 at 19:24

Your Answer

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

Browse other questions tagged or ask your own question.