Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ESRI';中的toolbar.deactivate()有问题;s API_Javascript_Draw_Esri_Arcgis Js Api - Fatal编程技术网

Javascript ESRI';中的toolbar.deactivate()有问题;s API

Javascript ESRI';中的toolbar.deactivate()有问题;s API,javascript,draw,esri,arcgis-js-api,Javascript,Draw,Esri,Arcgis Js Api,我正在尝试创建一个按钮,单击该按钮将激活esri.toolbar.Draw.EXTENT,然后再次单击时将停用工具栏并返回正常地图导航 我所拥有的东西在第一次单击时起作用,但在第二次单击时似乎没有停用工具栏 除了工具栏外,其他一切都正常。deactivate()似乎没有启动 function initToolbar(map) { var currentvalue = document.getElementById('searchByExtent').value;

我正在尝试创建一个按钮,单击该按钮将激活esri.toolbar.Draw.EXTENT,然后再次单击时将停用工具栏并返回正常地图导航

我所拥有的东西在第一次单击时起作用,但在第二次单击时似乎没有停用工具栏

除了工具栏外,其他一切都正常。deactivate()似乎没有启动

function initToolbar(map) {
            var currentvalue = document.getElementById('searchByExtent').value;
            var toolbar = new esri.toolbars.Draw(map);
            if (currentvalue == "Off"){
                document.getElementById("searchByExtent").value="On";
                toolbar.activate(esri.toolbars.Draw.EXTENT);
                dojo.connect(toolbar, "onDrawEnd", selectStuff);
                //toolbar.deactivate();
            } else {
                document.getElementById("searchByExtent").value="Off";
                toolbar.deactivate();
            }
        }

<input type    = "button"
       id      = "searchByExtent"
       value   = "Off"
       onclick = "initToolbar(map);">
       Search by Extent
     </input>
函数初始化工具栏(映射){
var currentvalue=document.getElementById('searchByExtent').value;
var toolbar=新的esri.toolbars.Draw(映射);
如果(当前值=“关闭”){
document.getElementById(“searchByExtent”).value=“On”;
激活(esri.toolbars.Draw.EXTENT);
connect(工具栏,“onDrawEnd”,选择Stuff);
//toolbar.deactivate();
}否则{
document.getElementById(“searchByExtent”).value=“Off”;
toolbar.deactivate();
}
}
按范围搜索

您遇到了Javascript范围问题

当您激活工具栏时,一切正常:

var toolbar = new esri.toolbars.Draw(map);
...
toolbar.activate(esri.toolbars.Draw.EXTENT);
…在名为
toolbar
的变量中有一个活动工具栏…但该变量是
initToolbar
函数的本地变量。该函数退出,变量丢失。尝试停用工具栏时,再次调用
initToolbar

var toolbar = new esri.toolbars.Draw(map); // This is NOT the same toolbar!
...
toolbar.deactivate(); // Makes no sense, it's not active.
相反,在函数外部定义
工具栏
,以保持引用:

var toolbar = null; // define it here

function initToolbar(map) {
        var currentvalue = document.getElementById('searchByExtent').value;
        if (currentvalue == "Off"){
            toolbar = new esri.toolbars.Draw(map); // Create the toolbar here

            document.getElementById("searchByExtent").value="On";
            toolbar.activate(esri.toolbars.Draw.EXTENT);
            dojo.connect(toolbar, "onDrawEnd", selectStuff);
        } else if (toolbar) { // If your value is not "Off" and the toolbar exists, then we can kill it.
            document.getElementById("searchByExtent").value="Off";
            toolbar.deactivate();
        }
    }

您是否尝试过在}else{中放置一个console.log来确认它没有启动?这将是调试此程序的一个良好开端