繁体   English   中英

根据属性在Openlayers中搜索wms层,如果找到则放大它

[英]Search wms layer in Openlayers based on attributes, zoom on it if found

我正在使用Openlayers 2.14,并使用WMS fron GeoServer,当通过getfeatureinfo事件并使用new OpenLayers.Control.WMSGetFeatureInfo单击该图层时,便能够从图层中提取信息。 有点像这样: 在此处输入图片说明

function activateControls(layerName) {
     //get wms feature info start
     infoControls ={
         click: new OpenLayers.Control.WMSGetFeatureInfo({
             url: geoserver_url,
             title: 'Identify features by clicking',
             layers: [layerName],
             queryVisible: true,
             infoFormat:'application/vnd.ogc.gml',
             eventListeners: {
                 getfeatureinfo: function(event) {
                     //console.log(event);
                     //var obj = jQuery.parseJSON(event.text);
                     //console.log(event.text);
                     //remove pop-ups when selecting others
                     var pops = map.popups;
                     for (var a = 0; a < pops.length; a++) {
                         if (pops.length == 1) {
                             map.removePopup(map.popups[0]);
                         }
                     };
                     map.addPopup(new OpenLayers.Popup.FramedCloud(
                        "chicken",
                        map.getLonLatFromPixel(event.xy),
                        null,
                        GenPopText(event),
                        null,
                        true
                     ));
                 }
             }
         })
     };
    for (var i in infoControls) {
        infoControls[i].events.register("getfeatureinfo", this, showInfo);
        map.addControl(infoControls[i]);
    }
    infoControls.click.activate();
 }//end of get wms feature info

function showInfo(evt) {
    if (evt.features && evt.features.length) {
         highlightLayer.destroyFeatures();
         highlightLayer.addFeatures(evt.features);
         highlightLayer.redraw();
         //console.log(GenPopText(evt));
    } else {
        console.log(evt.text);
    }
}

function GenPopText(evt){
     var temstr= "<b><i>" + evt.features[0].gml.featureType + "</i></b><br/>";
     for(var key in evt.features[0].attributes){
        temstr += "<b><span class='text-capitalize'>" + key + "</span></b>:" + evt.features[0].attributes[key] + "<br/>";
     }
     return temstr
}

我为此创建了一个函数,因为我有几个WMS层。

现在,正如问题所暗示的那样。 我想根据建筑物名称等属性来搜索图层,并在找到时显示弹出窗口并对其进行缩放。

这就是我要实现的方式:

 $("#table_brgy").on("click", "tbody tr", function (e) {
     e.preventDefault();
     var building_name = $(this).find("td").first().text();
     ....
     activateControls(layerName,building_name)
 });

像这样: 在此处输入图片说明

单击表格行后,它将在弹出窗口中显示匹配的建筑物信息。

我已经完成研究,但似乎无法使它起作用: 链接1

OGC WMS标准不支持基于属性的查询,仅支持基于点的查询( 此处可能的操作)。 您需要的是WFS服务 ,它是GetFeature操作。

示例代码: http://dev.openlayers.org/examples/wfs-states.html : http://dev.openlayers.org/examples/wfs-states.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM