[英]Search wms layer in Openlayers based on attributes, zoom on it if found
I'm using Openlayers 2.14 and use WMS fron GeoServer, I was able to extract the info from the layer when it is clicked through getfeatureinfo
events and using new OpenLayers.Control.WMSGetFeatureInfo
. 我正在使用Openlayers 2.14,并使用WMS fron GeoServer,当通过getfeatureinfo
事件并使用new OpenLayers.Control.WMSGetFeatureInfo
单击该图层时,便能够从图层中提取信息。 Somewhat like this: 有点像这样:
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
}
I created a function for it because I have several WMS layer. 我为此创建了一个函数,因为我有几个WMS层。
Now, as what the question implied. 现在,正如问题所暗示的那样。 I wanted to search the layer based on attributes like its building name as basis and show the pop-up when found and zoom on it. 我想根据建筑物名称等属性来搜索图层,并在找到时显示弹出窗口并对其进行缩放。
This is how I want to implement it: 这就是我要实现的方式:
$("#table_brgy").on("click", "tbody tr", function (e) {
e.preventDefault();
var building_name = $(this).find("td").first().text();
....
activateControls(layerName,building_name)
});
When the table row is clicked it will show the matching building info in pop-up. 单击表格行后,它将在弹出窗口中显示匹配的建筑物信息。
I have done my research but I can't seem to make it work: LINK 1 我已经完成研究,但似乎无法使它起作用: 链接1
The OGC WMS Standard does NOT support queries based on attributes, it only supports them based on points (possible operations here ). OGC WMS标准不支持基于属性的查询,仅支持基于点的查询( 此处可能的操作)。 What you need is a WFS Service and it's GetFeature operation. 您需要的是WFS服务 ,它是GetFeature操作。
Sample code: http://dev.openlayers.org/examples/wfs-states.html
示例代码: http://dev.openlayers.org/examples/wfs-states.html
: http://dev.openlayers.org/examples/wfs-states.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.