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.

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

share|improve this question
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 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 May 15 '12 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 May 15 '12 at 12:45
show 4 more comments

2 Answers 2

up vote 3 down vote accepted

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!

share|improve this answer
    
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
show 4 more comments

Since this:

Uncaught TypeError: Cannot read property 'Fixed' of undefined

Try this :

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

Instead of :

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

share|improve this answer
    
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
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.