2

I am a student enginner in GIS , I want to load my features from geoserver using WFS protocol. I'm using this code but it's not appearing in my browser

    OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
var map,wfs;


function init() {
//-11593508, 5509847, -11505759, 5557774
    var extent = new OpenLayers.Bounds(
        474813,  211897, 491713, 227436.5
    );
map = new OpenLayers.Map('map', {
    controls: [
        new OpenLayers.Control.PanZoom(),
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.LayerSwitcher({'ascending':false}),
    ]
});
  var wms = new OpenLayers.Layer.WMS(
                    "test_postgres:territoire", "http://mylocalhost:8080/geoserver/test_postgres/wms",
                    {
                        LAYERS: 'test_postgres:territoire',
                        STYLES: '',
            format: 'image/svg',
                    },
                    {
                        isBaseLayer: true,
                    } 
                );
  var wfsLayer = new OpenLayers.Layer.Vector("WFS", {
        strategies: [new OpenLayers.Strategy.BBOX()],
        styleMap: new OpenLayers.StyleMap({
            strokeWidth: 3,
            strokeColor: "#333333"
        }) 
    });


        map.addLayer(wfsLayer);


map.zoomToMaxExtent();
1

You have not specified the required parameters for making a WFS request. see this Syntax of WFS request in OpenLayers , the parameters are defined in the protocol.

you will also need to setup a proxy for making WFS request, otherwise you will get cross-domain-allow-origin problem. If you came across this see How to proxy Geoserver through Apache in Windows

WFS is always difficult for starters so don't lose your hope soon.

UPDATE My allowed host list

allowedHosts = ['www.openlayers.org', 'openlayers.org', 
            'labs.metacarta.com', 'world.freemap.in', 
            'prototype.openmnnd.org', 'geo.openplans.org',
            'sigma.openplans.org', 'demo.opengeo.org',
            'www.openstreetmap.org', 'sample.azavea.com',
            'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080', 
            'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
            '127.0.0.1:8888', '127.0.0.1',
            'localhost:8888', 'localhost'
            ]

also check whether the proxy is working or not for this goto

http://localhost/cgi-bin/proxy.cgi 

in your browser, this should open up the OpenLayers website

  • Thank's byom for your reply to my question ! i added the protocole & all required parameters but it is not work – Yahia El Haddad Apr 11 '13 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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