触摸事件

this.map.value.on("mouseenter", "WatershedsLayer", (event:any) => {
console.log("event.features![0]:",event.features![0].properties)
// 加载区域边界geojson数据文件
this.map.value.addSource('states', {
type: 'geojson',
data: event.features![0],
})
// 给区域绘制边框线
this.map.value.addLayer({
id: 'state-borders',
type: 'line',
source: 'states',
layout: {},
paint: {
'line-color': '#627BC1',
'line-width': 4,
}
})
})
this.map.value.on('mouseleave', "WatershedsLayer", (event:any) => {
if(this.map.value.getLayer("state-borders")) {
this.map.value.removeLayer("state-borders");
}
if(this.map.value.getSource("states")) {
this.map.value.removeSource("states");
}
});
posted @ 2022-12-14 15:17  小林222  阅读(30)  评论(0)    收藏  举报