4

I know there has been lots of WFS assistant and I did follow this one word by word, which I found was the best in the entire gis stack but still no clue why I am unbale to render a WFS on base map.

Here is the code,

var map = new OpenLayers.Map("map-id");
            var bio = new OpenLayers.Layer.WMS(
              "bio11",
              "http://localhost:8080/geoserver/iPlant/wms",
              {layers: 'iPlant:bio11'}
            );
            var imagery = new OpenLayers.Layer.WMS(
                "Global Imagery",
                "http://maps.opengeo.org/geowebcache/service/wms",
                {layers: "bluemarble"}
            );

            /*var QuebecSpecies = new OpenLayers.Layer.WMS(
              "AllQuebecSpecies",
              "http://localhost:8080/geoserver/iPlant/wms",
              {layers: 'iPlant:AllQuebecSpecies'},
              {'opacity': 0.4, 'isBaseLayer': false, 'visibility': true}
            );*/

            var QuebecSpecies = new OpenLayers.Layer.Vector(
            "AllQuebecSpecies",
            {
                strategies: [new OpenLayers.Strategy.Fixed()]
                , projection: new OpenLayers.Projection("EPSG:4326")
                , protocol: new OpenLayers.Protocol.WFS({
                    version: "1.1.0",
                    url: "http://localhost:8080/geoserver/wfs",
                    featurePrefix: 'iPlant', //geoserver worspace name
                    featureType: "iPlant:AllQuebecSpecies", //geoserver Layer Name
                    featureNS: "http://geoserver.org/iPlant", // Edit Workspace Namespace URI
                    geometryName: "the_geom" // field in Feature Type details with type "Geometry"
                })
            });

            map.addLayers([imagery, bio, QuebecSpecies]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));

As you can see in the code i have commented out the part where I am using the same layer as WMS, where it works perfectly fine, but then it does not overlay on the base map (meaning Quebec layer is a point shapefile had so the rest of the space is white background which covers up the base raster, that is why I have set the transparency to be 0.4).

Help me out guys, really tired of finding and trying and having no luck.

UPDATE

I moved the shapefile folder of mine to www folder and also changed the store location folder to www.

Workspace : iPlant Store Name : SpeciesShp FeatureLayer : AllQuebecSpecies

Is there some other way to add shapefile to Geoserver for using it as a WFS?

UPDATE 2.0

Since there were suggesstions of maybe my html file is not in the right folder, I now have my HTML file in /var/www/test.map/html as well as /var/lib/tomcat6/webapps/test.map.html. Still no luck, WFS does not show up :(

This is the error I am getting in develoepr tools,

XMLHttpRequest cannot load http://localhost:8080/geoserver/wfs. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

UPDATE 3.0

Ok thanks to more suggesstions now I have my map.html in /var/lib/tomcat6/webapps/geoserver/data/www/map.html. Now I can still work with WMS but now if i try to use WFS, the error I can see in the developer tool is

Uncaught TypeError: Cannot read property 'Fixed' of undefined

Also the map container itself disappears.

HELP!!!

9
  • 1
    From which folder are you serving your files? Is it from the www folder of GeoServer ? If not, for example if u're serving them from apache, then u need to set up proxy..I had the same issue. Answer so I can help u..
    – YossBen
    Commented May 14, 2012 at 23:27
  • it is not in the www folder but it is hosted on the geoserver plus it works fine as a WMS
    – Sam007
    Commented May 14, 2012 at 23:42
  • 2
    I am not talking about the location of ur shapefiles. It's about your HTML files containing your OpenLayers code..
    – YossBen
    Commented May 15, 2012 at 6:52
  • 1
    Besides, there's no specific treatment to any layer in GeoServer to serve it as WFS. The Layer you serve as WMS can be served as well as WFS with no change in GeoServer. The change is in your OpenLayers code which u've done correctly..Keep ur shapefiles as they were. So tell me where are located your HTML files?
    – YossBen
    Commented May 15, 2012 at 7:25
  • 3
    Not sure what could be wrong but I would try setting up the proxy if you have not already done so.
    – CaptDragon
    Commented May 15, 2012 at 12:45

3 Answers 3

5

Since you have this error:

XMLHttpRequest cannot load http//localhost:8080/geoserver/wfs. Origin http//localhost is not allowed by Access-Control-Allow-Origin.

It's now for sure that your html files are not served from within the www folder of GeoServer. What u've been using is www folder of other servers installed on your machine.

Here is the tutorial I followed step by step to setup a WFS layer served from another folder than www of GeoServer link.

If you want to now more about why you're getting the HTMlHtppRequest error and why you need to setup a proxy to avoid it, look at this link

Finally, I recommand strongly that u first run your WFS test from the GeoServer/data/www folder and only if that works, then you can run it from www folder of other servers. This way, if any error occurs, you'll be sure that it has nothing to do with your OpenLayers code. Instead, it will be due to some misconfiguration of proxy between your GeoServer and the server whose www folder contains your HTML files.

Hope this helps!

9
  • Okay my answer is now outdated since you finally found the right www folder of geoserver. :)
    – YossBen
    Commented May 15, 2012 at 19:17
  • Yup and I am facing new problem which I updated in my question as Update 3.0
    – Sam007
    Commented May 15, 2012 at 19:26
  • Why don't you try to serve in WFS mode one of the layers that come by default in GesoServer let say that of topp:tasmania_cities. just to be sure it's not because of your shapefile..
    – YossBen
    Commented May 15, 2012 at 19:43
  • Ok I tried USA states which was a default layer in the geoserver and the same error. seems the code is fine problem could be associated with the Ubuntu OS. Some permissions. Because the new error means the javascript is not being fully read or some file or folder permission issue
    – Sam007
    Commented May 15, 2012 at 22:21
  • Also there was a default WFS html called wfs-t.html which i think u will find too in /geoserver/data/www/wfs-t.html. On running that file (which is topp:tasmania_cities) only pink background in the map comes with broken image
    – Sam007
    Commented May 15, 2012 at 22:23
0

Since this:

Uncaught TypeError: Cannot read property 'Fixed' of undefined

Try this :

strategies: [new OpenLayers.Strategy.BBOX()]

Instead of :

strategies: [new OpenLayers.Strategy.Fixed()]

1
  • For that it gives me the same error except remove Fixed form the error and add BBOX :P Uncaught TypeError: Cannot read property 'BBOX' of undefined
    – Sam007
    Commented May 15, 2012 at 21:37
0

do you use the OpenLayers.js that was delivered with the geoserver installation or a different one? If you use the local one try this one instead:

http://dev.openlayers.org/releases/OpenLayers-2.13.1/OpenLayers.js

If that's not the problem check if the geoserver delivers the WFS correctly (Geoserver Layer Preview --> Dropdown --> WFS --> GML

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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