我正在使用GeoExt、OpenLayers开发一个web应用程序,并拥有自己的GeoServer来提供各种地图。不过,如果需要的话,我想让用户添加其他的WMS,以便能够在所有想要的层中游玩。
因此,我的GetFeatureInfo请求有问题。现在我有一个工具栏按钮附加到geoext的地图面板上,
new GeoExt.Action({
iconCls: "feature",
map: map,
toggleGroup: "tools",
tooltip: "Feature",
control: featureControl
})它的控制属性是
var featureControl = new OpenLayers.Control.WMSGetFeatureInfo({
queryVisible: true,
drillDown: true,
infoFormat:"application/vnd.ogc.gml"
});我还定义了一个事件侦听器,以便在收到响应后做我真正想做的事情,但这与此无关。我的问题是:
考虑到用户单击存在2+可见层的点,其中至少有一个来自不同的源,OpenLayers将不得不为每个不同的源执行一个AJAX请求,并且根据OpenLayers自己的文档,
当接收到GetFeatureInfo响应时触发。事件对象具有具有响应体(String)的文本属性、具有已解析功能数组的功能属性、具有触发请求的鼠标单击或悬停事件位置的xy属性,以及具有请求本身的请求属性。如果将drillDown设置为true,并发出多个请求以收集所有层的特性信息,则文本和请求将只包含上一次请求的响应体和请求对象。
所以,是的,它显然不会立即这样工作。通过查看调试器,我可以清楚地看到,给出了来自不同来源的两个层,它实际上是执行请求的,只是它不等待第一个响应,而是跳到下一个响应(显然,是异步的)。我已经考虑过一个接一个地执行请求,意思是按照上面所说的做第一个请求,一旦它完成并且保存了响应,就转到下一个请求。但我仍然习惯了GeoExt使用的数据结构。
我缺少任何API ( GeoExt或OpenLayers)选项/方法吗?有什么好的解决办法吗?
谢谢阅读:-)
对不起,如果我说得不够清楚,英语不是我的母语。如果上面所述的事情不够清楚,请告诉我:)
发布于 2013-03-07 01:08:59
我希望这能对其他人有所帮助,我意识到:这个控件在异步模式下发出请求是严格的,但这没有问题,真正的问题是当控件处理请求并触发事件"getfeatureinfo“时,我为该控件修改了2个方法,它工作了!,为此,我首先声明控件,然后在野蛮模式中修改以下方法:
getInfo = new OpenLayers.Control.WMSGetFeatureInfo({ drillDown:true , queryVisible: true , maxFeatures:100 });
//then i declare a variable that help me to handle more than 1 request.....
getInfo.responses = [];
getInfo.handleResponse=function(xy, request) { var doc = request.responseXML;
if(!doc || !doc.documentElement) { doc = request.responseText; }
var features = this.format.read(doc);
if (this.drillDown === false) {
this.triggerGetFeatureInfo(request, xy, features);
} else {
this._requestCount++;
this._features = (this._features || []).concat(features);
if( this._numRequests > 1){
//if the num of RQ, (I mean more than 1 resource ), i put the Request in array, this is for maybe in a future i could be need other properties or methods from RQ, i dont know.
this.responses.push(request);}
else{
this.responses = request;}
if (this._requestCount === this._numRequests) {
//here i change the code....
//this.triggerGetFeatureInfo(request, xy, this._features.concat());
this.triggerGetFeatureInfo(this.responses, xy, this._features.concat());
delete this._features;
delete this._requestCount;
delete this._numRequests;
// I Adding this when the all info is done 4 reboot
this.responses=[];
}
}
}
getInfo.triggerGetFeatureInfo= function( request , xy , features) {
//finally i added this code for get all request.responseText's
if( isArray( request ) ){
text_rq = '';
for(i in request ){
text_rq += request[i].responseText;
}
}
else{
text_rq = request.responseText;
}
this.events.triggerEvent("getfeatureinfo", {
//text: request.responseText,
text : text_rq,
features: features,
request: request,
xy: xy
});
// Reset the cursor.
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");}谢谢,你给我带来了发现我的问题的方法,这是我解决问题的方法,我希望这能对别人有所帮助。
发布于 2013-12-19 14:42:15
沙伊卡的回答几乎完美!恭喜你,谢谢你,我也遇到了同样的问题,我终于解决了这个问题。
我会在你的代码中改变什么:
我的代码:
getInfo.addPopup = function(map, text, xy) {
if(map.popups.length > 0) {
map.removePopup(map.popups[0]);
}
var popup = new OpenLayers.Popup.FramedCloud(
"anything",
map.getLonLatFromPixel(xy),
null,
text,
null,
true
);
map.addPopup(popup);
}在getInfo.triggerGetFeatureInfo()函数中,在最后一行之后追加:
this.addPopup(map, text_rq, xy);发布于 2012-12-26 11:11:27
GetFeatureInfo请求作为对外部服务器的JavaScript Ajax调用发送。因此,由于安全原因,请求可能会被阻止。您必须通过您自己域中的代理将请求发送到外部服务器。
然后,通过将OpenLayers.ProxyHost设置为正确的路径,在打开层中配置此代理。例如:
OpenLayers.ProxyHost = "/proxy_script";有关更多背景信息,请参见http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost。
https://stackoverflow.com/questions/13915558
复制相似问题