openlayers空间点查询之GetFeatureInfo

Posted SWEETFAN

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openlayers空间点查询之GetFeatureInfo相关的知识,希望对你有一定的参考价值。

在map对象上注册点击方法监听, 这里我用的是wms,当然你也可以查询wfs

    map.events.register(‘click‘, map, function (e) {
                     var params = {
                             REQUEST: "GetFeatureInfo",
                             EXCEPTIONS: "application/vnd.ogc.se_xml",
                             BBOX: map.getExtent().toBBOX(),
                             SERVICE: "WMS",
                             VERSION: "1.1.1",
                             X: e.xy.x,
                             Y: e.xy.y,
                          //   INFO_FORMAT: ‘text/html‘,  这里必须注意啦 查询结果会返回不同的格式滴,根据自己的需呀要做不同设置哦,text/html或者application/vnd.ogc.gml
                             INFO_FORMAT: ‘application/vnd.ogc.gml‘,  
                            QUERY_LAYERS: map.layers[1].params.LAYERS,
                             FEATURE_COUNT: 50,
                             Layers: ‘mine:locatorinfo_‘+MineCode,
                             WIDTH: map.size.w,
                             HEIGHT: map.size.h,
                             format: format,
                             styles: map.layers[1].params.STYLES,
                             srs: map.layers[1].params.SRS};
                     //    alert(map.layers[1].params.LAYERS); 
                         OpenLayers.loadURL("http://172.16.0.81:8080/geoserver/mine/wms", params, this, setHTML, failhttml);
                         tpoint = map.getLonLatFromPixel(e.xy),  
                         OpenLayers.Event.stop(e);
                });

查询完毕且成功回调方法是:setHTML   【加载查询失败的方法时failhtml】

 var popup1;
            function setHTML(response){    
            //    alert(response.responseText);
                //获取要素结果集
                var g = new OpenLayers.Format.GML();
              var   features = g.read(response.responseText);
              var tempstr = ‘‘;
              var nfid = ‘‘;
              var nm = ‘‘;
                //遍历要素集
                for(var feat=0;feat<features.length;feat++){
                 nm = features[feat].attributes.equipmentid;    //获取属性的时候
                 nfid = features[feat].fid;   //fid的获取比较特殊哦,不是按照属性获取方式的,可以参考geoserver发布的服务就能看出那些时属性设置
                 tempstr += nfid;
                }
                
                if(popup1!=null){
                    map.removePopup(popup1);
                }
                popup1 = new OpenLayers.Popup.FramedCloud("chicken",
                        tpoint,
                        new OpenLayers.Size(200,200),
                       tempstr,
                       null,
                        true);
            popup1.autoSize=true;
            map.addPopup(popup1);
            }; 

执行逻辑是这样滴,点击图层,查询结果弹出tip提示窗口。

技术分享图片效果如图哦





















































以上是关于openlayers空间点查询之GetFeatureInfo的主要内容,如果未能解决你的问题,请参考以下文章

请教openlayers中,怎么给point,line添加单击事件.多谢

openlayers入门开发系列之批量叠加zip压缩SHP图层篇

Elasticsearch系列(14)Query之地理空间查询

OpenLayers-如果从文件系统或Web服务器上查看,地图比例会有所不同

openlayers二次简单封装 线性、点

Openlayers 高德腾讯、百度、天地图坐标相互转换