const drawPolygon = (index: number, callback: () => void) => () => {
setIndex(index as number);
draw?.changeMode('draw_polygon');
mapInstance.on('draw.create', getEntity);
mapInstance.on('draw.update', getEntity);
callback?.();
};
点击按钮触发drawPolygon事件,开始绘制面对象,
const destroyInstance = () => {
console.log('destroyInstance******');
mapInstance.off('draw.create', getEntity);
mapInstance.off('draw.update', getEntity);
};
React.useEffect(() => {
destroyInstance();
return () => {
console.log('页面销毁....');
};
});
//切换到别的组件,进行面绘制,发现当前组件的getEntity事件依然有输出,说明当前组件的未解绑,求解!!!