Display WFS layer in ol3

只愿长相守 提交于 2019-12-03 21:29:50
gis newbie

Finally, I solved my problem, so I want to share the solution with you.

First thing there were some mistakes in my previous code, this the right way to set a wfs layer :

var u = "http://localhost/geoserver/wfs?&service=wfs&version=1.1.0&request=GetFeature&typeNames=opengeo:comgeo";
var v = new ol.layer.Vector({
    title: 'comgeo',
           source: new ol.source.Vector({
                url: '/cgi-bin/proxy.cgi?url='+ encodeURIComponent(u),

                format: new ol.format.WFS({

                })
           })   
});

u is the wfs request, the paramvalue opengeo is the workspace in geoserver, and comgeo is the layer.

You need to escape this url by using encodeURIComponent function, so you don't get the famous error like :

Could not determine geoserver request from http request

The first part of my url /cgi-bin/proxy.cgi?url= is that because you need a proxy if your application is running from another location (I'm using wamp to host mine).

To get your proxy working try this tutorial: set proxy

Use the proxy like in my code, this

OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

is not available in ol3.

It looks like you are mixing up OpenLayers 2 and OpenLayers 3. Please take a look at this or this example. These examples are using JSONP so that you don't need a proxy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!