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!!!

Sam007
  • 4,395
  • 7
  • 48
  • 69
  • 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 May 14 '12 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 May 14 '12 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 May 15 '12 at 06: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 May 15 '12 at 07:25
  • 3
    Not sure what could be wrong but I would try setting up the proxy if you have not already done so. – CaptDragon May 15 '12 at 12:45
  • My code is already in the /var/www/test/map.html @YossBen. CaptDragon how do I setup a proxy? – Sam007 May 15 '12 at 16:16
  • If you've your HTML files in the www folder of GeoServer, you won't need to set up proxy!! – YossBen May 15 '12 at 18:03
  • I don't think that var/www is the www folder of GeoServer. Mine for example is /Library/Tomcat/webapps/GeoServer/data/www/myfile.html – YossBen May 15 '12 at 18:16
  • Ok now WMS is working but the map container is not visible if I use WFS. The container itself disappears. The developer tool is giving me this error Uncaught TypeError: Cannot read property 'Fixed' of undefined and yes the previous one which was NOT in /geoserver/data/www/ was giving this error in the developer tool XMLHttpRequest cannot load http://localhost:8080/geoserver/wfs. Origin http://localhost is not allowed by Access-Control-Allow-Origin. – Sam007 May 15 '12 at 18:42

3 Answers3

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!

YossBen
  • 473
  • 1
  • 5
  • 15
  • Okay my answer is now outdated since you finally found the right www folder of geoserver. :) – YossBen May 15 '12 at 19:17
  • Yup and I am facing new problem which I updated in my question as Update 3.0 – Sam007 May 15 '12 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 May 15 '12 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 May 15 '12 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 May 15 '12 at 22:23
  • ok it seems that the OL requires lib folder in openlayer which is not in the root forlder(/data/www) of geoserver so i think I will have to use proxy. Can u suggest a good place where I can pick up proxy for OL? – Sam007 May 15 '12 at 23:43
  • even though I am using no logic now, just try it, place all your OL folder in the www folder of GeoServer, don't forget to modify path to script in html file. – YossBen May 16 '12 at 18:29
  • I re-installed the entire open-geo suite on Ubuntu server 11.04 and added the proxy.cgi in /usr/lib/cgi-bin/ as stated in the FAQ and it worked. I am still working on Ubuntu 12.04 but atleast now I will able to move forward. – Sam007 Jun 04 '12 at 22:16
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

Thomas B
  • 8,807
  • 1
  • 21
  • 62
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()]

YossBen
  • 473
  • 1
  • 5
  • 15
  • 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 May 15 '12 at 21:37