displaying data from a WFS (vector) layer using getFeatureInfo
As the title says... I trying to access that data associated with a vector layer but not having any success.
I get the following error: "No QUERY_LAYERS has been requested, or no queriable layer in the request anyways "I am using geoserver, openlayers and and the script shown below....
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
开发者_Go百科 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);
});
Any suggestion as to what I am doing wrong would be very much appreciated
Regards Chris
You can ask a WFS to send you data using request=getfeature but if you are using getfeatureinfo you need a WMS server. GeoServer can provide data through both interfaces but it's best not to mix the two.
In the code you show the most likely problem is that you don't have 2 layers in your map, as the array is numbered from 0.
Is your source URL (the WFS server) actually working? When I try to go there I get a timeout.
// 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. //
}
精彩评论