我正在工作Openlayers 3。我在地图上添加了三层WMS,顺序如下:公社、区、省。我在缩放时使用“forEachLayerAtPixel”来获取当前图层的信息。示例:缩放到 District 图层然后获取信息图层 District,或缩放到 Commune 图层然后获取信息图层 Commune。但它只获取图层省份的信息,当缩放到图层 District 时返回"undefined"。我使用事件“pointermove”在地图上悬停:
map.on("pointermove", function (evt) {
if (evt.dragging) return;
const hit = map.forEachLayerAtPixel(evt.pixel, (layer) => {
if (layer instanceof ol.layer.Tile)
return layer;
return null;
});
console.log(hit);