1

我正在工作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);
4

1 回答 1

1

可能问题是:如何使用 forEachLayerAtPixel 方法跟踪特定层?因为显然总是返回未定义的又名变量未设置。

于 2017-02-28T16:44:50.393 回答