[GIS] OpenLayers WFS vector layer

openlayers-2overlayvectorwfs

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.

Best Answer

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