I am developing an app using geoserver and openlayers. I have a zip
code layer which is working via WMS and am trying to serve the same
layer via WFS. My openlayers code is...
var redZipSrc = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
var url = 'http://shmewco.shimilla.net:8080/geoserver/wfs';
var args = [
'service=WFS',
'version=1.1',
'request=GetFeature',
'typename=floodbroker:zcta',
'outputFormat=application/json',
'srsname=EPSG:3857',
'bbox=' + extent.join(',') + ',EPSG:3857'
];
return url + '?' + args.join('&');
},
strategy: ol.loadingstrategy.bbox
});
var censusPanels = new ol.layer.Group({
title: 'Census Layers',
layers: [
new ol.layer.Tile({
title: 'Zip Codes',
visible: true,
source: new ol.source.TileWMS({
url: 'http://shmewco.shimilla.net:8080/geoserver/wms',
params: {
layers: 'floodbroker:zcta',
format: 'image/png',
tiled: true
}
})
}),
new ol.layer.Vector({
title: 'Red Zips',
visible: false,
source: redZipSrc,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: [ 255, 0, 0, 1 ],
width: 2
})
})
})
]
});
The URL generated is ...
http://shmewco.shimilla.net:8080/geoserver/wfs?service=WFS&version=1.1&request=GetFeature&typename=floodbroker:zcta&outputFormat=application/json&srsname=EPSG:3857&bbox=-8657794.484466808,5326810.367664881,-8628060.480463875,5345461.002566464,EPSG:3857
In Firefox Developer Tools, this produces a JSON syntax error,
unexpected end of data in line 1 column 1. Needless to say, nothing
appears on my map. However, if I copy and paste the URL into a browser
I get a bunch of valid JSON (I tried parsing it).
The geoserver log shows this while processing the request:
28 Mar 15:15:05 INFO [geoserver.wfs] -
Request: getServiceInfo
28 Mar 15:15:05 INFO [geoserver.wfs] -
Request: getFeature
service = WFS
version = 1.1
baseUrl = http://shmewco.shimilla.net:8080/geoserver/
query[0]:
filter = [ bbox POLYGON ((-8657794.484466808
5326810.367664881, -8657794.484466808 5345461.002566464,
-8628060.480463875 5345461.002566464, -8628060.480463875
5326810.367664881, -8657794.484466808 5326810.367664881)) ]
srsName = EPSG:3857
typeName[0] =
{https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer}zcta
outputFormat = application/json
resultType = results
28 Mar 15:15:05 INFO [wfs.json] - about to encode JSON
I've tried a bunch of different output formats and nothing works. If I
instead use this for a vector layer ...
var redZipSrc = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
var url = 'https://ahocevar.com/geoserver/wfs';
var args = [
'service=WFS',
'version=1.1',
'request=GetFeature',
'typename=osm:water_areas',
'outputFormat=application/json',
'srsname=EPSG:3857',
'bbox=' + extent.join(',') + ',EPSG:3857'
];
return url + '?' + args.join('&');
},
strategy: ol.loadingstrategy.bbox
});
... it works. The water features are displayed.
Sorry for the long-winded question, but I thought it was better to be
complete. Can anybody help?
Thanks,
Bob Miller
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users