gpt4 book ai didi

extjs - WMS GetFeatureInfo;多层,不同来源

转载 作者:行者123 更新时间:2023-12-02 05:20:32 25 4
gpt4 key购买 nike

我正在使用 GeoExt、OpenLayers 开发一个 Web 应用程序,并拥有自己的 GeoServer 来为各种 map 提供服务。尽管如此,我还是想让用户在需要时添加其他 WMS,以便能够使用所有需要的图层。

因此,我的 GetFeatureInfo 请求出现了问题。现在我有一个工具栏按钮附加到 geoext 的 map 面板,

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 自己的文档,

Triggered when a GetFeatureInfo response is received. The event object has a text property with the body of the response (String), a features property with an array of the parsed features, an xy property with the position of the mouse click or hover event that triggered the request, and a request property with the request itself. If drillDown is set to true and multiple requests were issued to collect feature info from all layers, text and request will only contain the response body and request object of the last request.

所以,是的,它显然不会马上那样工作。看一下调试器,我可以清楚地看到,从不同的源提供两层,它实际上执行请求,只是它不等待第一个的响应并跳转到下一个(显然,是异步的)。我考虑过一个接一个地执行请求,这意味着如上所述执行第一个请求,一旦完成并保存响应,就进行下一个请求。但我仍在习惯 GeoExt 使用的数据结构。

我是否缺少任何 API(无论是 GeoExt 还是 OpenLayers)选项/方法?有什么好的解决方法吗?

感谢阅读:-)

PS:对不起,如果我不够清楚,英语不是我的母语。如果上面说的不够清楚,请告诉我:)

最佳答案

我希望这对其他人有帮助,我意识到:你认为这个控件以异步模式发出请求是正确的,但这没关系,没问题,真正的问题是控件处理请求和触发时事件“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");}

谢谢,你给我提供了一种发现问题的方法,这是我解决问题的方法,我希望这对其他人有帮助。

关于extjs - WMS GetFeatureInfo;多层,不同来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13915558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com