我正在尝试更改圆形标记的颜色,该标记是使用图层上的 paint 属性绘制的。
按照本教程:https :
//docs.mapbox.com/mapbox-gl-js/example/hover-styles/
我已将 设置circle-color为依赖于 a feature-state:
map.addLayer({
id: "singles",
type: "circle",
source: "users",
filter: ["!has", "point_count"],
paint: {
'circle-radius': {
'base': 10,
'stops': [[5, 20], [15, 500]]
},
'circle-color': ["case",
["boolean", ["feature-state", "hover"], false],
'#ddffc8',
'#ff0000'
],
}
});
Run Code Online (Sandbox Code Playgroud)
然后当有人将鼠标悬停在侧边栏上时,我想更新功能状态并更改颜色:
function highlightMarkersOnHoverOnSidebar (markers, map) {
let marks = markers
Array.from(document.querySelectorAll('.sideBarItems')).map( (x, i) => {
x.addEventListener('mouseenter', function(){
map.setFeatureState({source: 'users', id: marks.features[i].properties.id}, { hover: true});
}, false)
x.addEventListener('mouseleave', function(){
map.setFeatureState({source: 'users', id: marks.features[i].properties.id}, { hover: false});
}, false)
})
}
Run Code Online (Sandbox Code Playgroud)
但是,当我将鼠标悬停在侧边栏元素时没有任何反应......它甚至没有抛出错误。
我有什么遗漏吗?谢谢。