1

我尝试使用 OpenLayers (v2.12) 加载 WFS 层,但不幸的是,在向我的 wfs 服务器发出 HTTP OPTIONS 请求后加载中断。FireBug 显示我的服务器发送了一个空响应。未检测到错误。在较旧的 OpenLayers 版本(v2.8)中,我在另一个应用程序中使用的是没有 OPTIONS 请求。这段旧代码发送一个纯 HTTP GET,如下所示:

http://myWfsServer/wfs?typename=someName&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A4326&BBOX=...

这是当前代码

map = new OpenLayers.Map( 'map',{
    maxExtent:OpenLayers.Bounds.fromArray([7,47,10,49]),
    units: 'm'});

layer = new OpenLayers.Layer.OSM( "Simple OSM Map","http://myWfsServer/tiles/${z}/${x}/${y}.png");
map.addLayer(layer);
wfsLayer = new OpenLayers.Layer.Vector("WFS", {
    projection: "EPSG:4326",
    maxExtent: OpenLayers.Bounds.fromArray([7,47,10,49]),
        strategies : [new OpenLayers.Strategy.BBOX()],
        protocol : new OpenLayers.Protocol.WFS.v1_0_0({
        url : "http://myWfsServer/wfs",
        featureType : "ms:lsaId",
        featureNS : "http://mapserver.gis.umn.edu/mapserver",
    format: new OpenLayers.Format.WFST.v1_0_0({
        featureType: "ms:lsaId",
        featureNS: "http://mapserver.gis.umn.edu/mapserver"})
        })
});
map.addLayer(wfsLayer);
map.setCenter(new OpenLayers.LonLat(9,48).transform(
      new OpenLayers.Projection("EPSG:4326"),
      map.getProjectionObject()), 16);    


问题 1:有没有办法跳过这个请求并像早期的 OpenLayers 版本一样继续使用标准的 GET 请求?

问题 2:OpenLayers 期望什么响应?

4

1 回答 1

1

问题解决了。OPTIONS 请求来自浏览器而不是来自 OpenLayers。原因是 WFS 服务器不是服务器提供我的 Web 应用程序。这个请求与允许跨域访问有关。

问题1:让应用程序主机提供WFS数据。例如,将 Apache 配置为原始 WFS 的代理。

问题2:没有想法:-D

于 2012-09-20T20:50:53.073 回答