Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to add one of the included datasets with geoserver to an openlayers map. I've followed the opengeo tutorials, seen similar thread on here, but I can't seem to crack it. Can somebody take a glance at my code and geoserver setup and tell me where i'm going wrong?

Here's my code:

            //WMS map
            world = new OpenLayers.Layer.WMS("Global Imagery", "http://maps.opengeo.org/geowebcache/service/wms", {
                layers : "openstreetmap",
                format : "image/png"
            });
            map.addLayer(world);

            //WFS
            parks = new OpenLayers.Layer.Vector("WFS", {
                strategies : [new OpenLayers.Strategy.BBOX()],
                protocol : new OpenLayers.Protocol.WFS({
                    url : "http://localhost:8081/geoserver/wfs",
                    featureType : "medford:parks",
                    featureNS : "http://medford.opengeo.org/medford"
                })
            });

            map.addLayer(parks);

            map.zoomToMaxExtent();

GeoServer details: workspace name = medford, Namespace URI = http://medford.opengeo.org For the feature type I have tried "parks" and "medford:parks"

The layer is enabled, advertised and has a 30 feature return limit.

I'm struggling to put a simple map together

Thanks, James

share|improve this question

1 Answer

Firstly could you give some more info about any errors that are occuring by using a debugging tool like firebug. my first guess would be that the geoserver instance is not running on the same domain (this includes a different port on the same domain) and requests to the server are being blocked by the cross-site scripting restrictions.

If this is the case OpenLayers comes with some example CGI proxy scripts to allow you to proxy the call to geoserver. have a look here for more info.

hope that helps, if not maybe post some more info relating to any errors you see.

share|improve this answer
you are right - most likely the problem is that wfs-requests are being sent to different domain - localhost:8081 – igorti Jan 21 '12 at 14:47
OK I've now moved my code to localhost:8081/apps/index.html and changed my featureNS. I can now see 30 features coming back on the response...<rpid:OBJECTID>25</rpid:OBJECTID><rpid:FIELD_ID>NS/86427/74196</rpid:‌​FIELD_ID><rpid:GROSS_AREA>2.307</rpid:GROSS_AREA>. However I'm not seeing any of the features on my map. When added as WMS I can see them fine. The only other layer is a base WMS. – gis_rookie Jan 30 '12 at 18:44
this sounds like it coul be unrelated to the openlayers code. perhaps a styling issue for the layer in geoserver? does the WFS return include location information for the features? if you could add some debug output, like a snippet from the WFS return, in the question above i'll take a look – olly_uk Jan 30 '12 at 18:53

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.