3

I'm working with GeoServer and OpenLayers 3, I have a hosted layer in GeoServer that I want displayed using OpenLayers 3 as a WFS layer.

It doesn't show any errors, but I don't get the map. It works with WMS, but not with WFS. Please can anyone help me to fix that?

This is my code:

var v=new ol.layer.Vector({
           source: new ol.source.Vector({
                format: new ol.format.WFS({
                    version: "1.1.0",
                    url: "http://localhost:8080/geoserver/wfs",
                    featurePrefix: "opengeo", //workspace
                    featureType: "opengeo:region_geo", //layer name
                    featureNS: "http://yourdomain/application/catalogLayer", 
                    geometryName: "geom",  //feature name in database
                })
            })  
});
var map = new ol.Map({
          target: 'map-id',
                  layers: [
                            v              
              ],
 view: new ol.View({
 projection: 'EPSG:4326',
      center: [0, 0],
      zoom: 1
    })         
     });

I get this result :

enter image description here

  • 2
    Make sure you're not running into the same origin policy. Use the browser's debugger to look at the XHR requests. Also featureType is without the prefix in it. – bartvde May 20 '15 at 6:41
  • Thank you for reply, i tryed without prefix, but still not working. i dont understand what you said about WHR requests. – gis newbie May 20 '15 at 14:58
  • Read this: developer.chrome.com/devtools – bartvde May 20 '15 at 15:06
  • Hi bartvde,i used firebug, i dont see any XHR requests – gis newbie May 21 '15 at 2:59
  • It looks like you took code from an OL2 tutorial. Have a look at some OL3 wfs code. wordpress-dbauszus.rhcloud.com/?p=50 – Dennis Bauszus Jun 9 '15 at 22:54
1

I had the same problem, and it worked fine after I took my project and put it in ./'Data directory'/www/

After that when I access the WFS from 'http://localhost:8080/geoserver/www/Myproject' using the OL3 example it works fine.

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.