supress on react中的点击事件

发布于 2025-02-11 18:33:11 字数 2296 浏览 2 评论 0原文

这是标识符按钮的点击功能。当用户单击地图上的某些功能时,此功能将触发弹出设计功能。我希望当用户第二次点击标识符按钮时,在该功能上进行此点击功能。这意味着标识符按钮应像起动开关一样。

此函数在usefect()内部,#IndenFierClickreturn> return {} part中的按钮的ID,该按钮将触发单击事件。

const IdentifierClick = () => {
            console.log("working");
            // clicktimes = clicktimes+1;
            // console.log("Button click times ",clicktimes)
                
                if((enableIdentify == false))
                {
                        initialMap.on('singleclick', function (evt) 
                        {
                            console.log(evt, "printevt");
                            var myLayerChecked;
                            console.log(layerlist, "printlayerlist");
                            for (let i = 0; i <= 4; i++) 
                            {
                                layerlist[1].values_.layers.array_[i].values_.layers.array_.forEach(arrayItem => {
                                    myLayerChecked = arrayItem.state_.visible;
                                    console.log("myLayerChecked", myLayerChecked);
                                    // console.log(layerlists,"printlayerlist");
                                    if (myLayerChecked == true) {
                                        document.getElementById('popup-content').innerHTML = '<p class="identifier_p"><b>Identifier Details</b></p>';
                                        console.log("My Array Data", arrayItem.values_.source)
                                        designHtml(evt, arrayItem.values_.source, arrayItem.values_.title);
                                        enableIdentify = true;
                                    }
                                    else 
                                    {
                                        console.log("No Layer is checked");
                                    }

                                });
                            }
                        })
                }
                else {
                    
                }
                
        });

intialmap.on('singleclick',function())应通过dissideifierClick函数启用和禁用,当我们单击以触发函数时。请帮助我完成这项任务。

This is an on-click function for the identifier button. This function will trigger a popup design function when the user clicks on some feature on the map. I want this click functionality on that feature to be suppressed when the user clicks the identifier button a second time. This means the identifier button should act like a start-stop switch.

This function is inside useEffect() and the #IdentifierClick is the id for the button which is in return{} part which will trigger the click event.

const IdentifierClick = () => {
            console.log("working");
            // clicktimes = clicktimes+1;
            // console.log("Button click times ",clicktimes)
                
                if((enableIdentify == false))
                {
                        initialMap.on('singleclick', function (evt) 
                        {
                            console.log(evt, "printevt");
                            var myLayerChecked;
                            console.log(layerlist, "printlayerlist");
                            for (let i = 0; i <= 4; i++) 
                            {
                                layerlist[1].values_.layers.array_[i].values_.layers.array_.forEach(arrayItem => {
                                    myLayerChecked = arrayItem.state_.visible;
                                    console.log("myLayerChecked", myLayerChecked);
                                    // console.log(layerlists,"printlayerlist");
                                    if (myLayerChecked == true) {
                                        document.getElementById('popup-content').innerHTML = '<p class="identifier_p"><b>Identifier Details</b></p>';
                                        console.log("My Array Data", arrayItem.values_.source)
                                        designHtml(evt, arrayItem.values_.source, arrayItem.values_.title);
                                        enableIdentify = true;
                                    }
                                    else 
                                    {
                                        console.log("No Layer is checked");
                                    }

                                });
                            }
                        })
                }
                else {
                    
                }
                
        });

The intialMap.on('singleclick',function()) should be enabled and disabled by IdentifierClick function when we click to trigger the function. Please help me achieve this task.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文