使用getFeatureInfo从WFS(矢量)层显示数据

问题描述 投票:1回答:3

正如标题所说的...我试图访问与矢量层关联的数据,但没有成功。我收到以下错误:“没有请求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);
            });

关于我在做什么错的任何建议,将不胜感激

关于克里斯

gis openlayers geoserver
3个回答
1
投票

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

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


0
投票

您的源URL(WFS服务器)是否正常工作?当我try to go there超时时。


0
投票
// 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. //

}

© www.soinside.com 2019 - 2024. All rights reserved.