8

I'm trying to add a vector layer with a WFS layer and it's not working. Can anyone point a solution?

OpenLayers code:

var wfs = new OpenLayers.Layer.Vector(
                "Stavros Features",
                {
                    strategies: [new OpenLayers.Strategy.BBOX()]
                    ,projection: new OpenLayers.Projection("EPSG:4326")
                    ,protocol: new OpenLayers.Protocol.WFS({
                        version: "1.1.0"
                        ,srsName: "EPSG:4326"
                        ,url: "http://localhost:8080/geoserver/wfs"
                        ,featureNS :  "http://postgis.org"
                        ,featureType: "polygon"
                        ,geometryName: "the_geom"
                    })
                });

In the GeoServer configuration, I have a workspace 'myWorkspace', a store 'myStore' and a layer 'myLayer' and WFS is enabled. Also in the 'publishing' tab of my layer in the 'WMS Settings Default Style' I have selected 'polygon' as myLayer is multipolygon.

What am I doing wrong?

Am I supposed to specify the workspace name in the 'featureNS' property?

Is there a good tutorial for OpenLayers?
I have read the docs which are very poor and the examples doesn't help me always. I have also read the user manual of GeoServer and I found it very good.

  • 1
    Is your OpenLayers application is running on port 80 or port 8080? – geographika Jul 13 '11 at 15:11
  • 1
    can you see the result of the request in firebug? – Ian Turton Jul 14 '11 at 10:50
13

Okay few things i would change and give another try:

  1. Make sure your featureNS value is in the "Edit Workspace Page under Namespace URI" in your GEOSERVER. Do not use something as generic as "http://postgis.org". Use something like "http://yourdomain/application/catalogLayer" or something unique like that. You can make this URI up, just make it unique.
  2. You have new BBOX() as a strategy but what do that box have as dimensions? I would change it to [new OpenLayers.Strategy.Fixed()] for testing.
  3. featureType is not actually the type of geometry, it's your "Layer Name" in GEOSERVER (i know, misleading).
  4. geometryName is the name of the field in your postgis database that has the Geometry data type. In GEOSERVER, Under "Edit Layer" you can see at the bottom "Feature Type details". There you will see a field with type "Geometry". Use the value under the property column.

featureNS

enter image description here

featureType

enter image description here

geometryName

enter image description here

  • 1
    Great job, thanks for sharing that. I've found it's imperative to set the NS to be correct, and NOT to use special characters like : in the names of layers. – JayCrossler Jan 31 '13 at 2:52

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.