首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用getFeatureInfo显示来自WFS (矢量)图层的数据

使用getFeatureInfo显示来自WFS (矢量)图层的数据
EN

Stack Overflow用户
提问于 2010-08-29 09:57:23
回答 3查看 2.7K关注 0票数 1

正如标题所说..。我试图访问与矢量层相关的数据,但没有任何成功。

我得到以下错误:“没有请求QUERY_LAYERS,或者请求中没有可查询的层”

我使用的是geoserver、openlayer和下面显示的脚本……

代码语言:javascript
复制
           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);
            });

如果有任何关于我做错了什么的建议,我将不胜感激。

致敬Chris

EN

回答 3

Stack Overflow用户

发布于 2011-02-24 02:34:36

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

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

票数 1
EN

Stack Overflow用户

发布于 2010-08-31 04:42:17

您的源URL ( WFS服务器)真的在工作吗?当我超时( try to go there )时,我得到一个超时。

票数 0
EN

Stack Overflow用户

发布于 2020-06-12 16:25:57

代码语言:javascript
复制
// 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. //

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3593248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档