我想要做的是访问featureTarget
从 MapboxGL 返回的鼠标事件对象的属性。
我的代码是这样的:
// map is the instance of MapboxGL
map.on('mousemove', e => {
console.log("***");
console.log(e);
console.log(e.featureTarget);
console.log("***");
});
然后 Chrome 的控制台显示如下:
***
n {point: c, lngLat: B, originalEvent: MouseEvent, type: "mousemove", _defaultPrevented: false, …}
featureTarget: bs {type: "Feature", _vectorTileFeature: qa, properties: {…}, layer: {…}, source: "mapbox-gl-draw-cold", …}
lngLat: B {lng: 172.4191589376344, lat: -43.49662499361186}
originalEvent: MouseEvent {isTrusted: true, screenX: 561, screenY: 524, clientX: 561, clientY: 421, …}
point: c {x: 442, y: 289}
target: Map {_moving: false, _zooming: false, transform: wi, _bearingSnap: 7, _renderFrameCallback: ƒ, …}
type: "mousemove"
_defaultPrevented: false
defaultPrevented: (...)
__proto__: F
undefined
***
我超级困惑...第二行显示featureTarget
成员,但第三行未定义!如您所见,没有错字。
有人对我为什么无法访问featureTarget
价值有任何想法吗?