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();
Zachary
6,2005 gold badges35 silver badges51 bronze badges
asked Apr 11, 2013 at 15:24

1 Answer 1

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

answered Apr 11, 2013 at 17:20
1
  • Thank's byom for your reply to my question ! i added the protocole & all required parameters but it is not work Commented Apr 11, 2013 at 18:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.