【问题标题】:displaying data from a WFS (vector) layer using getFeatureInfo使用 getFeatureInfo 显示来自 WFS(矢量)层的数据
【发布时间】:2010-08-29 01:57:22
【问题描述】:

正如标题所说...我试图访问与矢量图层关联的数据,但没有任何成功。
我收到以下错误: "没有请求QUERY_LAYERS,或者请求中没有可查询的层"

我正在使用 geoserver、openlayers 和下面显示的脚本....

           map.events.register('click', map, function (e) {
           document.getElementById('nodelist').innerHTML = "Loading... please wait...";
                var params = {
                    REQUEST: "GetFeatureInfo",
                    EXCEPTIONS: "application/vnd.ogc.se_xml",
                    BBOX: map.getExtent().toBBOX(),
                    X: e.xy.x,
                    Y: e.xy.y,
                    INFO_FORMAT: 'text/html',
                    QUERY_LAYERS: map.layers[1].options.typename,
                    FEATURE_COUNT: 50,
                    Layers: 'monitor:Routers',
                    Styles: '',
                    Srs: 'EPSG:4326',
                    WIDTH: map.size.w,
                    HEIGHT: map.size.h,
                    };
                OpenLayers.loadURL("http://tobagoborn.com:8080/geoserver/wfs", params, this, setHTML, setHTML);
                OpenLayers.Event.stop(e);
            });

非常感谢任何关于我做错了什么的建议

问候 克里斯

【问题讨论】:

  • 由于您不显示页面的其余部分,map.layers[1].options.typename 包含什么?我的 OL 页面中没有这个值 :)

标签: gis openlayers geoserver


【解决方案1】:

您可以使用 request=getfeature 让 WFS 向您发送数据,但如果您使用 getfeatureinfo,则需要 WMS 服务器。 GeoServer 可以通过这两个接口提供数据,但最好不要将两者混用。

在您显示的代码中,最可能的问题是您的地图中没有 2 层,因为数组从 0 开始编号。

【讨论】:

    【解决方案2】:

    您的源 URL(WFS 服务器)是否真的有效?当我try to go there 时,我会超时。

    【讨论】:

    • 这是个好问题...我不确定...我尝试在 URL 上使用 WFS、OWS 或 WMS,但没有一个适用于脚本...作为测试,当我在我的浏览器中输入以下链接,它会成功返回数据:tobagoborn.com:8080/geoserver/… 所以我不知道什么不起作用
    【解决方案3】:
    // Your map object //
     map = new ol.Map({})
    
    // on click event call displayFeatureInfo method and pass the pixel as a 
       argument in this method  //
    
       map.on('click', function(event) {
         displayFeatureInfo(event.pixel)
       })
    
    
    // execute the displayFeatureInfo  method //
    
    var displayFeatureInfo  = function(pixel) {
    var features = map.getFeaturesAtPixel(pixel, function(feature) {
       return feature 
    })
    
    console.log(features)
    console.log(features.R)
    
    // 1. when you see features in console, it is either object or array //
    // 2. if got a multiple value on click event then it gives you a array and if 
           got a single value on click event then it gives you a object  //
    // 3. now we assume it is object, see (features.R) in console. information is 
          in single single character, then you can concat. //
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多