getFeatureInfo仅针对露天层中的可见层查询6
我是JS和OL的Newby,并且我有一个OpenLayers 6 Map,其中不同的WMS层将不同的WMS分组为几个ol.layer.group
。我想通过“ GetGetFeatureInfourl”索取功能信息。可以在图层树中打开/关闭图层的可见性。我想单击地图中的某个地方时:
- 仅获取目前可见的层的功能信息
- ,如果所选位置有多个层以上的层,请获取所有这些代码的功能信息,
此代码适用于只有一层(在这种情况下为WMSLAYER5),
map.on('singleclick', function (evt) {
if (!wmsLayer5.getVisible()) return;
document.getElementById('info').innerHTML = '';
const viewResolution = /** @type {number} */ (vista.getResolution());
const url = wmsLayer5.getSource().getFeatureInfoUrl(
evt.coordinate,
viewResolution,
'EPSG:25830',
{'INFO_FORMAT': 'text/html'}
);
if (url) {
fetch(url)
.then((response) => response.text())
.then((html) => {
document.getElementById('info').innerHTML = html;
});
}
});
但是我需要一个代码来迭代所有层,并且仅在可见(如果可见)时只能致电GetFeatureInfo。我已经尝试过这个,但不起作用,也不返回控制台中的任何消息
map.on('singleclick', function (evt1) {
document.getElementById('info').innerHTML = '';
var viewResolution = /** @type {number} */
(vista.getResolution());
var url = '';
document.getElementById('info').innerHTML ='';
layers.forEach(function (layer, i, layers) {
if (layer.getVisible() ) {
url = layer.getSource().getGetFeatureInfoUrl(
evt1.coordinate,
viewResolution,
'EPSG:25830', {
'INFO_FORMAT': 'text/html',
'FEATURE_COUNT': '300'
});
if (url) {
fetch(url)
.then((response) => response.text())
.then((html) => {
document.getElementById('info').innerHTML += html;
});
}
}
});
});
来修复它?
I'm a newby with JS and OL, and I have an Openlayers 6 map with different WMS layers grouped into several ol.layer.Group
. I want to request feature information through "getGetFeatureInfoUrl". Visibility of layers can be turned on/off in the layer tree. I'd like to, upon clicking somewhere in the map:
- Get Feature Info ONLY for layers that are currently visible
- and, if there are more than one layers at the chosen location, get the Feature Info for all of them
This code works well for just one layer (wmsLayer5, in this case)
map.on('singleclick', function (evt) {
if (!wmsLayer5.getVisible()) return;
document.getElementById('info').innerHTML = '';
const viewResolution = /** @type {number} */ (vista.getResolution());
const url = wmsLayer5.getSource().getFeatureInfoUrl(
evt.coordinate,
viewResolution,
'EPSG:25830',
{'INFO_FORMAT': 'text/html'}
);
if (url) {
fetch(url)
.then((response) => response.text())
.then((html) => {
document.getElementById('info').innerHTML = html;
});
}
});
But I need a code to iterate over all layers and only call getFeatureInfo if they are visible. I've tried this one, but doesn't work and doesn't return any message in the console
map.on('singleclick', function (evt1) {
document.getElementById('info').innerHTML = '';
var viewResolution = /** @type {number} */
(vista.getResolution());
var url = '';
document.getElementById('info').innerHTML ='';
layers.forEach(function (layer, i, layers) {
if (layer.getVisible() ) {
url = layer.getSource().getGetFeatureInfoUrl(
evt1.coordinate,
viewResolution,
'EPSG:25830', {
'INFO_FORMAT': 'text/html',
'FEATURE_COUNT': '300'
});
if (url) {
fetch(url)
.then((response) => response.text())
.then((html) => {
document.getElementById('info').innerHTML += html;
});
}
}
});
});
Any suggestion to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自6.13版(4个月前)以来,此方法已被弃用,并且在下一个主要版本之前不会更改。我没有使用建议的替换
layer.getData()
。按照代码迭代所有层和查询仅可见图像和类型图像。This method has been deprecated since version 6.13 (4 months ago) and won't be changed before next major release. I didn't use suggested replacement
layer.getData()
. Following code iterates through all the layers and queries only visible ones and of type Image.