1

So I found this course on Udemy and I made it to the part where we start adding vector layers into an OpenLayers map. However, the layer we add does not appear on my map! The code for this is here:

wfs_url = 'http://localhost:8080/geoserver/richland_postgres/wfs?service=WFS&' +
          'version=1.1.0' +
          '&request=GetFeature' +
          '&typename=richland_postgres:schools&' +
          '&CQL_FILTER=' + cqlfilter + '&' +
          'outputFormat=application/json&srsname=EPSG:3857&' +
          ',EPSG:3857';
        prompt('',wfs_url);

        var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: function(extent) {
      return 'http://localhost:8080/geoserver/richland_postgres/wfs?service=WFS&' +
          'version=1.1.0' +
          '&request=GetFeature' +
          '&typename=richland_postgres:schools&' +
          '&CQL_FILTER=' + cqlfilter + '&' +
          'outputFormat=application/json' +
          '&srsname=EPSG:3857&,EPSG:3857';
    },
    strategy: ol.loadingstrategy.bbox
  });

  var vector = new ol.layer.Vector({
    source: vectorSource
  });

I copied and pasted the URL from the prompt into GeoServer and it gave me this: enter image description here

I think that is a GeoServer issue and I am about to have it re-installed anyway. However, I took out the CQL from my code and while the URL worked perfectly, however the layer still doesn't show up.

Looking around this site I did find another student from this class who had the same problem and someone suggested adding a BBOX. I tried that myself and it didn't work. I don't know whether it worked for them. I've tried a variety of tutorials but I have never been able to get a WFS into OpenLayers, however I can get it into QGIS. I wonder if this is a GeoServer issue.

  • 1
    What happens when you load the URL without the CQL filter in your browser? Additionally, have you checked the output of your WFS in Geoserver's OpenLayers previewer? – Brynne Dec 14 '17 at 21:21
  • When I load the URL without the CQL filter it gives me the JSON. And yes, I have checked the output and it gives me the same thing. – Ryan Norton Dec 18 '17 at 17:03
2

It is not a GeoServer issue!

The error message is quite clear the function is not recognised. If you turn up logging in GeoServer and then look in the log file you will see exactly which function is wrong. I suspect it may be to do with the double quoting of the attribute name, or the name of the geometry is wrong.

WFS queries don't work when you have a filter and a BBOX so the issue may be related to using a BBOX Strategy.

Another issue with your URL is the SRS is set as EPSG:3857&,EPSG:3857 when it should be just EPSG:3857.

  • Okay, it turns out the stable release does not have the querylayer module installed, so I can't use those functions. I couldn't find out where I could download that. I may just get the maintenance version installed next week. As for the vector layer, it still doesn't show up even after I eliminate all queries from my code and change the BBOX strategy. – Ryan Norton Dec 15 '17 at 16:52
  • It is under cross layer filtering for stable sourceforge.net/projects/geoserver/files/GeoServer/2.12.1/… – Ian Turton Dec 15 '17 at 18:02
  • Okay, but do you know why I don't see my vector layer? I see the WMS layer just fine! – Ryan Norton Dec 18 '17 at 17:04
  • is anything returned from the server? if yes, then your projections do not match. If no, then your request is broken. – Ian Turton Dec 19 '17 at 9:09
  • Hmm. The vector layer now shows up in my map. Maybe I hadn't put localhost:8080/geoserver/www/map.html as my URL? I could've sworn that I had! In any case, the problem is solved! – Ryan Norton Dec 20 '17 at 16:03

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.