1

I'm working on localhost:8080 and want to get WFS data in a Leaflet map. So, I've read in some posts here that I first I have to enable Jsonp in my web.xml file in Geoserver. So I put

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

But I can't see that Jsonp is allowed with a getCapabilities :

<ows:Parameter name="outputFormat">
<ows:AllowedValues>
<ows:Value>text/xml; subtype=gml/3.2</ows:Value>
<ows:Value>GML2</ows:Value>
<ows:Value>KML</ows:Value>
<ows:Value>SHAPE-ZIP</ows:Value>
<ows:Value>application/gml+xml; version=3.2</ows:Value>
<ows:Value>application/json</ows:Value>
<ows:Value>application/vnd.google-earth.kml xml</ows:Value>
<ows:Value>application/vnd.google-earth.kml+xml</ows:Value>
<ows:Value>application/x-gpkg</ows:Value>
<ows:Value>csv</ows:Value>
<ows:Value>geopackage</ows:Value>
<ows:Value>geopkg</ows:Value>
<ows:Value>gml3</ows:Value>
<ows:Value>gml32</ows:Value>
<ows:Value>gpkg</ows:Value>
<ows:Value>json</ows:Value>
<ows:Value>text/xml; subtype=gml/2.1.2</ows:Value>
<ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
</ows:AllowedValues>

Then, I tried to load my WFS data into a GeoJson layer in leaflet with this code :

<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta charset="utf-8" />
<title>Test WFS</title>        

<link 
    rel="stylesheet" 
    href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"
/>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>
<body>    
<div id="map"></div>

<script>
var center = new L.LatLng(46.707, 4.678);
var map = new L.Map('map', { center: center, zoom: 14, minZoom:11});    

var owsrootUrl = 'http://localhost:8080/geoserver/Vin/ows';

var defaultParameters = {
    service : 'WFS',
    version : '2.0.0',
    request : 'GetFeature',
    typeName : 'Vin:vinChalon',
    maxFeatures : 50,
    outputFormat: 'json'
};

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

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

var ajax = $.ajax({
    url : URL,
    dataType : 'jsonp',
    jsonpCallback : 'getJson',
    success : WFSLayer
}); 

function WFSLayer(data) {
L.geoJson(data, {
style: function (feature) {
    return {color: 'black',
        fillColor: '#ff0000',
        fillOpacity: 0.10};
    }
}).addTo(map);
}

</script>
</body>
</html>

And firefox's console return

SyntaxError: missing ; before statement    ows:1:7

Is someone knows why it doesn't work ?

0

Have you restartet Tomcat / Geoserver after editing the web.xml?

Your capabilities should show this entry:

<ows:Value>text/javascript</ows:Value>

Your javascript-code seems ok. --> slightly adapted with an other Geoserver/Layer here: http://jsfiddle.net/expedio/u1oskkxy/

2
  • Many thanks for your reply Thomas B. Yes, now jsonp is allowed. – Hippipers Oct 13 '15 at 10:27
  • But if I enclose my geoJson in my ajax function, it works, if not, like in your code, it doesn't works ... – Hippipers Oct 13 '15 at 10:35

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.