Friday 15 March 2019

leaflet - WFS request works in Geoserver but server returns error


I'm trying to send a WFS request to my Geoserver but there is something wrong. Here's what I get when I select the JSONP:



http://130.239.57.16:8080/geoserver/beta/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=beta:states&maxFeatures=50&outputFormat=text%2Fjavascript


Here's the javascript:


    var owsrootUrl = 'http://130.239.57.16:8080/geoserver/ows';

var defaultParameters = {
service : 'WFS',
version : '1.0',
request : 'GetFeature',
typeName : 'beta:admin>',
outputFormat : 'text/javascript',

format_options : 'callback:getJson',
SrsName : 'EPSG:4326'
};

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

var WFSLayer = null;
var ajax = $.ajax({
url : URL,

dataType : 'jsonp',
jsonpCallback : 'getJson',
success : function (response) {
WFSLayer = L.geoJson(response, {
style: function (feature) {
return {
stroke: true,
fillColor: '#FF0000',
fillOpacity: 0
};

},
onEachFeature: function (feature, layer) {
popupOptions = {maxWidth: 200};
layer.bindPopup("Popup text, access attributes with feature.properties.ATTRIBUTE_NAME"
,popupOptions);
}
}).addTo(map);
}
});


Nothing shows up on the web page, and Firebug shows that the request is made to the server, but the response is:


http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd"> Feature type beta:states> unknown


It seems like the feature type is unknown, but I don't know now to fix it.



Answer



You have a typo in your script.There is a letter ">" in your layername.


Its typeName : 'beta:admin' and not typeName : 'beta:admin>' (but obviously a layer named "beta:admin" is not published in your geoserver)


for your states-layer it's:


var defaultParameters = {
service : 'WFS',
version : '1.0',

request : 'GetFeature',
typeName : 'beta:states',
outputFormat : 'text/javascript',
format_options : 'callback:getJson',
SrsName : 'EPSG:4326'
};

http://jsfiddle.net/hqmjc4nw/


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...