【发布时间】:2020-11-23 15:00:21
【问题描述】:
我正在尝试在 Mapbox 的透明背景层上设置点击事件。这是一个代码sn-p:
map.on('load', function () {
map.addLayer({
id: 'transparent',
type: 'background',
interactive: true,
paint: {
'background-color': '#dedede',
'background-opacity': 0
}
})
}
//This doesn't print Hello World to the console
map.on('click', 'transparent', function () {
console.log('Hello World')
})
在符号图层上调用相同的事件没有问题。任何帮助将不胜感激。
【问题讨论】:
-
docs.mapbox.com/mapbox-gl-js/api/map/#map#on: "只有当它的位置在这个层的可见特征内时才会触发事件"。背景层中没有特征。
标签: events background click mapbox layer