Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Good Morning!

I have some troubles displaying a WFS layer with OpenLayers and hope someone here can give me a hint. Before moving on, I precise that I have already checked other posts, like here and here but, for any reason, it hasn't solved my problem yet (and by the way, thank you to the contributors to those posts, they made me understand a little bit better already)... The WFS layer appears in the layer switcher, but not at all on the map.

So, here is the configuration of my data:

and here is my OpenLayers code:

var adresspt_wfs = new OpenLayers.Layer.Vector("Adress points WFS", {
  strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
    url: "http://localhost:8080/geoserver/wfs",
    featurePrefix:"luma_project",
    featureType: "adresspt",
    featureNS: "http://localhost:8080/luma",
    srsName: "EPSG:4326",
    geometryName: "the_geom",
    version: "1.0.0"
  })
});
map.addLayer(adresspt_wfs);

Do you see anything missing here? As my data is stored in a (local) PostGIS database, should I refer to it as workspace:store:layer? or workspace:layer?

Also, I precise that I have no trouble to display this layer as WMS in OpenLayers and that I can even display it as WFS in Quantum GIS. The problem thus doesn't come from the data or the Geoserver, but really from my OpenLayers code.

Any help will be greatly appreciated!

Thanks a lot in advance,

Stéphane

EDIT:

Here is the full code:

var map;

function init() {
var bounds = new OpenLayers.Bounds(
    13, 55.67, 13.5, 55.8
  );

 var options = {
    projection: new OpenLayers.Projection("EPSG:4326"),
    displayProjection: new OpenLayers.Projection("EPSG:4326"),
    maxExtent: bounds,
    units: 'degrees'
  };

  map = new OpenLayers.Map('map');

  var transportation = new OpenLayers.Layer.WMS(
    "Lund transportation network", "http://localhost:8080/geoserver/wms",
    { layers: 'lu_transportation',
      format: 'image/png',
      srs:'EPSG:4326',
      transparent:'true',
      zoomOffset: 11, 
   },
   {isBaseLayer: true, opacity: 0.4});

  var adresspt_wfs = new OpenLayers.Layer.Vector("Adress points WFS", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
      url: "http://localhost:8080/geoserver/wfs",
      //featurePrefix:"luma_project",
      featureType: "luma_project:adresspt",
      featureNS: "http://localhost:8080/luma",
      srsName: "EPSG:4326",
      geometryName: "the_geom",
      version: "1.0.0"
    })
  });

    map.addLayer(transportation);
    map.addLayer(adresspt_wfs);

  map.addControl(new OpenLayers.Control.Navigation());
  map.addControl(new OpenLayers.Control.LayerSwitcher());
  map.addControl(new OpenLayers.Control.Scale($('scale')));
  map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));

  map.zoomToExtent(bounds);

}

And then the html code:

  <body onload="init()">
  <div id="wrapper">
    Coordinates of the mouse: <div id="location">...</div>
    <br>
    <div id="scale"></div>
  </div>

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

  </body>

EDIT (2)

Just to try out, I have added another WFS layer, from a remote server, and still nothing displays... I took the exact code of this page, which is:

var test_wfs = new OpenLayers.Layer.Vector("WFS", {
  strategies: [new OpenLayers.Strategy.BBOX()],
  protocol: new OpenLayers.Protocol.WFS({
    url: "http://demo.opengeo.org/geoserver/wfs",
    featureType: "tasmania_roads",
    featureNS: "http://www.openplans.org/topp"
  })
});

I really don't understand... this layer displays perfectly on this page, but not on mine... with the same code...

share|improve this question
1  
we need to see all of your openlayers code - especially the map set up and any other layers you are adding. –  iant Feb 17 '12 at 11:07
    
Sorry for that. Here is the full code –  Stéphane Henriod Feb 17 '12 at 11:41
    
If you are using firefox I've found httpfox also useful for examining GET/POST commands. It has a little more detail than firefox for somethings: addons.mozilla.org/en-US/firefox/addon/httpfox Also, the javascript terminal in Chrome can give errors described slightly differently, which can be helpful. –  djq Feb 17 '12 at 16:10
add comment

2 Answers

All your code looks good - can you see if there are features being returned in Firebug?

If there are the next thing to check is if those points are in lat/lon or lon/lat order. If they are not in the order you are expecting then read http://geoserver.org/display/GEOS/Unambiguous+Communication+of+CRS on how to deal with this.

share|improve this answer
    
Thanks for this, but can you tell me what I have to check in Firebug? Under Network / all, I have lots of GET for the WMS, but not for the WFS. I guess it means that nothing is being returned? I will also check your link, but I assume that the coordinates are in the correct order, as they are stored as Geometry in PostGIS and as I have no problem to display them as WMS (or even as WFS in Quantum GIS) –  Stéphane Henriod Feb 17 '12 at 12:02
    
If there are no WFS requests in the net tab then something is wrong with the OpenLayers code. I can't see anything may be others can –  iant Feb 17 '12 at 12:19
    
This is what I think as well... also, I have tried with the sample data provided by Geoserver (tiger, topp...) and I have the exact same problem. So, a priori not a problem with the datasets. If someone else has an idea? –  Stéphane Henriod Feb 17 '12 at 12:59
    
Still googling around for my problem and found some references about needing to setup a cgi script... Is that really necessary, knowing that, for now, I run the app exclusively on localhost? Also, I do not have Apache installed, and Geoserver runs on Jetty, not Tomcat (the "easy and straight-forward" installation), on Windows 7 –  Stéphane Henriod Feb 17 '12 at 13:55
2  
are you loading your HTML page from the same port as your GeoServer is running on? if not you will need a proxy or to move your html to the www directory of GeoServer –  iant Feb 17 '12 at 15:06
show 5 more comments
up vote 2 down vote accepted

Thanks to iant I have solved my problem! What I didn't know (and could also be useful for other Geoserver newbies like me) is that the html files must be in the Geoserver web directory (for the default installation on windows:

C:/Program Files/GeoServerx.x.x/data_dir/www/something) 

and must be accessed by the url. If on localhost:

http://localhost:8080/geoserver/web/something 

For any reason, "double-clicking" on the html file to display it in your browser will work for WMS feeds but not for WFS (there must be a rationale explanation, but I don't know it).

I still need to find out how to display the WFS on top of OpenStreetMap and Google tiles, as there is apparently a new problem with the projection. I already solved it for the WMS layers, but the WFS doesn't appear yet when the projection is EPSG:900913. I'll investigate.

Thanks to all of you for your help and contribution!

EDIT:

Actually, for my 2nd problem, the solution is very easy: in the parameters of the WFS layer, it is necessary to define the srs of the map, not the one of the layer itself. So, instead of:

   var adresspt_wfs = new OpenLayers.Layer.Vector("Adress points WFS", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
      url: "http://localhost:8080/geoserver/wfs",
      featurePrefix:"luma_project",
      featureType: "adresspt",
      featureNS: "http://localhost:8080/luma_project",
      srsName: "EPSG:4326",
      geometryName: "the_geom",
      version: "1.1.0"
    })
  });

you should write:

   var adresspt_wfs = new OpenLayers.Layer.Vector("Adress points WFS", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
      url: 'http://localhost:8080/geoserver/wfs',
      featurePrefix:"luma_project",
      featureType: "adresspt",
      featureNS: "http://localhost:8080/luma_project",
      srsName: "EPSG:900913",
      geometryName: "the_geom",
      version: "1.1.0"
    })
  });
share|improve this answer
    
The reason it doesn't work when you double click is the "Same Origin Policy" it's for your own safety. –  iant Feb 18 '12 at 17:28
    
Ok, but serving WMS feeds doesn't mess with the Same Origin Policy then? –  Stéphane Henriod Feb 19 '12 at 10:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.