Javascript 您能否自动打开';鼠标';?

Javascript 您能否自动打开';鼠标';?,javascript,button,leaflet,Javascript,Button,Leaflet,我希望用户能够打开状态更改简易按钮,选择地图上的一个区域(通过按住shift键并拖动鼠标),然后释放鼠标后,自动关闭简易按钮。现在,打开easybutton,选择一个区域,为边界框提供Lat/Long。效果很好。但是,当您单击关闭EasyButton时,它会覆盖您的选择(为您单击的EasyButton所在区域指定新坐标)。我的代码: var stateChangingButton = L.easyButton({ states: [{

我希望用户能够打开状态更改简易按钮,选择地图上的一个区域(通过按住shift键并拖动鼠标),然后释放鼠标后,自动关闭简易按钮。现在,打开easybutton,选择一个区域,为边界框提供Lat/Long。效果很好。但是,当您单击关闭EasyButton时,它会覆盖您的选择(为您单击的EasyButton所在区域指定新坐标)。我的代码:

    var stateChangingButton = L.easyButton({
            states: [{
                    stateName: 'ButtonOff',      
                    icon:      'X',               
                    title:     'Turn Button On', 
                    onClick: function(btn, map) {    
                            btn.button.style.backgroundColor = 'red';
                            btn.state('ButtonOn');
                            map.on('mousedown', getClickLocation);
                            map.on('mouseup', getReleaseLocation);
                            map.on('mouseup', toGeoJsonBounds);
                            map.on('mouseup', addSelectionLayer);
                            map.on('mouseup', addColorSelection);                                
                    }
                }, {
                    stateName: 'ButtonOn',
                    icon:      'X',
                    title:     'Turn Button Off',
                    onClick: function(btn, map) {
                        btn.state('ButtonOff');
                            btn.state('ButtonOff');
                            btn.button.style.backgroundColor = 'white';
                            map.off('mousedown', getClickLocation);
                            map.off('mouseup', getReleaseLocation);
                            map.off('mouseup', toGeoJsonBounds);
                            map.off('mouseup', addSelectionLayer);
                            map.off('mouseup', addColorSelection);                             

                    }
                    }]
                });

                stateChangingButton.addTo(map);
我在绝望中尝试了这一点,但它给出了一个错误:

       //map.on('mouseup', btn.state('ButtonOff')); 
我试过创建一个函数,它说btn未定义:

        function buttonAutoOff(){
            btn.state('ButtonOff');
         }
我不熟悉JavaScript和传单,我必须为我的工作这么做。我问的可能吗

谢谢大家!

您应该使用“boxzoomend”事件

jsidle示例:

您应该使用“boxzoomend”事件

JSFIDLE示例:

map.on('boxzoomend', function(){
  stateChangingButton.state('ButtonOff');
  stateChangingButton.button.style.backgroundColor = 'white';
});