5

I've ready that I can enable JSONP by setting ENABLE_JSONP in web.xml:

  <context-param>
    <param-name>ENABLE_JSONP</param-name>
    <param-value>true</param-value>
  </context-param>

And I've read you can set outputFormat=json&format_options=callback:myCallback but I only get json back. Is this functionality broken/reverted? I'm on Windows 8.1.

  • Where's your wfs, we can test it. I have it working in GeoServer 2.4, so it must be somethign to do with your config. Did you restart Tomcat after changing the setting? – Alex Leith Mar 5 '14 at 4:57
7

I got it to work using Geoserver 2.3 and Leaflet with WFS 1.0.0 here.

When I changed to version 1.1.0 and 2.0.0 it returned the same json object as 1.0.0 but neither rendered on the map. Not sure why and it's a bit beyond me.

Here's what I'm using:

var rootUrl = 'http://tomcat.capecodgis.com/geoserver/capecodgis/ows';

var defaultParameters = {
    service: 'WFS',
    version: '1.0.0',
    request: 'GetFeature',
    typeName: 'capecodgis:monitor_station',
    maxFeatures: 200,
    outputFormat: 'text/javascript',
    format_options: 'callback: getJson'

};

var parameters = L.Util.extend(defaultParameters);

$.ajax({
    url: rootUrl + L.Util.getParamString(parameters),
    dataType: 'jsonp',
    jsonpCallback: 'getJson',
    success: handleJson
});

function handleJson(data) {
    L.geoJson(data, {
        onEachFeature: onEachFeature,
        pointToLayer: function (feature, latlng) {
            return L.circleMarker(latlng, geojsonMarkerOptions);
            //return L.marker(latlng);
        }
    }).addTo(map);
}

Hope this helps

2

According to this document outputFormat=json is only included for backward compatibility and you should use outputFormat=text/javascript for a JSONP response.

  • 1
    Tried that but got a similar error: Failed to find response for output format text/javascript – ca0v Nov 6 '13 at 16:10
  • what version of geoserver and wfs are you using? What does the getCapabilities doc suggest are available outputs – Ian Turton Nov 6 '13 at 16:12
  • GeoServer 2.4.1 and tried 2.0.0 and 1.1.0 with the same outcome: 127.0.0.1:8080/geoserver/… Seems to be a known issue: jira.codehaus.org/browse/GEOS-5749 – ca0v Nov 6 '13 at 16:14
  • You can't give us a localhost URL. Pastebin the xml, or stick it somewhere. – Alex Leith Mar 5 '14 at 4:58
1

The problem is that the success function is not called with the JSONP call. You need to change the AJAX call accordingly. You need to set jsonp:'format_options' on the AJAX call. The callback is then in the jsonpCallback parameter.

    $.ajax('http://demo.opengeo.org/geoserver/wfs',{
        type: 'GET',
        data: {
            service: 'WFS',
            version: '1.1.0',
            request: 'GetFeature',
            typename: 'osm:water_areas',
            srsname: 'EPSG:3857',
            outputFormat: 'text/javascript',
            bbox: extent.join(',') + ',EPSG:3857'
            },
        dataType: 'jsonp',
        jsonpCallback:'callback:loadFeatures',
        jsonp:'format_options'
        });
    }
  • Unfortunately, no. I'm having the same problem. Using that example works; but using my geoserver tells me it doesn't accept text/javascript, despite enabling it in web.xml – Auspex Jan 26 '17 at 13:36

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.