首页 文章

WMS GetFeatureInfo;多层,不同来源

提问于
浏览
2

我正在使用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自己的文档中,

收到GetFeatureInfo响应时触发 . 事件对象具有带有响应主体的文本属性(String),带有已解析功能数组的features属性,带有鼠标单击位置的xy属性或触发请求的悬停事件,以及请求属性与请求本身 . 如果drillDown设置为true并且发出了多个请求以从所有层收集功能信息,则text和request将仅包含上一个请求的响应主体和请求对象 .

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

是否有任何API(可以是GeoExt或OpenLayers)选项/方法我都缺少?有什么好的解决方法吗?

谢谢阅读 :-)

PS:对不起,如果我不够清楚,英语不是我的母语 . 如果上面提到的内容不够明确,请告诉我:)

3 回答

  • 1

    我希望对其他人有这个帮助,我意识到:你很难控制在异步模式下执行请求,但这没关系,没问题,真正的问题是当控件处理请求并触发事件时“ getfeatureinfo“所以,我为这个控件修改了2个方法并且它可以工作!所以要做到这一点我首先声明控件,然后在野蛮模式我修改了这里的方法是de code:

    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");}
    

    谢谢,你带我一个发现我的问题的方法,这是我解决的方式,我希望这可以帮助别人 .

  • 4

    saheka的答案几乎是完美的!恭喜并感谢你,我遇到了同样的问题,并且随后我终于设法解决了这个问题 .

    我会在你的代码中改变什么:

    • isArray()不起作用,改变如下:if(request instanceof Array)在getInfo.triggerGetFeatureInfo()的第一行

    • 以弹出方式显示结果这是方法:

    我的代码:

    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);
    
  • 0

    GetFeatureInfo请求作为JavaScript Ajax调用发送到外部服务器 . 因此,出于安全原因,可能会阻止请求 . 您必须通过您自己域上的代理将请求发送到外部服务器 .

    然后,通过将OpenLayers.ProxyHost设置为正确的路径,在openlayers中配置此代理 . 例如:

    OpenLayers.ProxyHost = "/proxy_script";
    

    有关更多背景信息,请参阅http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost .

相关问题