实际上我正在使用此代码用于弹出示例的GetFeatureInfo现在我想限制弹出窗口中的字段。
<html>
<head>
<title>GetFeatureInfo Popup</title>
<script src="ol/OpenLayers.js"></script>
<link rel="stylesheet" href="ol/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="ol/examples/style.css" type="text/css" />
<script>
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
/*Same as identifier*/
var map, info;
function load() {
map = new OpenLayers.Map({
div: "map",
maxExtent: new OpenLayers.Bounds(143.834,-43.648,148.479,-39.573)
});
var political = new OpenLayers.Layer.WMS("State Boundaries",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
{isBaseLayer: true}
);
var roads = new OpenLayers.Layer.WMS("Roads",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
var cities = new OpenLayers.Layer.WMS("Cities",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
var water = new OpenLayers.Layer.WMS("Bodies of Water",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
map.addLayers([political, roads, cities, water]);
info = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
title: 'Identify features by clicking',
queryVisible: true,
eventListeners: {
getfeatureinfo: function(event) {
map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",
//document.getElementById('get').innerHTML = xmlResponse.attribute.state;
map.getLonLatFromPixel(event.xy),
null,
event.text,
null,
true
));
xmlResponse = new OpenLayers.Format.XML().read(event.text);
document.getElementById('h').innerHTML = xmlResponse.attribute.STATE;
}
}
});
map.addControl(info);
info.activate();
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="load()">
<h1 id="title">Feature Info in Popup</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrates the WMSGetFeatureInfo control for fetching information
about a position from WMS (via GetFeatureInfo request). Results
are displayed in a popup.
</p>
<div id="map" class="smallmap"></div>
<form>
<input type="lable" id="h">
</form>
<div id="docs"></div>
</body>
</html>
现在我只想要特定字段或限制弹出功能中的字段。请g我,我是新来的。
答案 0 :(得分:6)
如果您使用GeoServer生成WMS,可以按照本教程创建自定义GetFeatureInfo模板:http://docs.geoserver.org/latest/en/user/tutorials/GetFeatureInfo/index.html
答案 1 :(得分:0)
您应该使用getGetFeatureInfoUrl参数的propertyName
功能。
例如,如果您想要功能name
和id
,则应执行以下操作:
var url = source.getGetFeatureInfoUrl(
evt.coordinate, viewResolution, view.getProjection(),
{'INFO_FORMAT': 'application/json','propertyName':'name,id'});