在我的 default.aspx 页面中,我在工具栏中有一些 ESRI 工具(和一些命令),所以是这样的。
<ToolbarItems>
<esri:Tool ClientAction="MapPoint('Map1','%toolbarItem%',false,'crosshair') DefaultImage="~/images/default_tool.gif"
EnablePostBack="True" JavaScriptFile="" Name="TestTool" SelectedImage="~/images/selected_tool.gif" DisabledImage="~/images/disabled_tool.gif"
ServerActionAssembly="Test.Web.Mapping" ServerActionClass="Test.Web.Mapping.TestTool"
Text="It's a tool!" ToolTip="Use it." />
</ToolbarItems>
现在,我有一些代码用于禁用该工具,有效地改变它的图像。代码基本上在工具栏上循环以查找需要禁用的工具并执行此操作。
代码运行后,一切正常。正确的工具已被禁用,图像已相应更改。
问题是,如果我选择放大工具,我刚刚禁用的工具的图像会立即变回默认图像。
似乎必须有一些 Javascript 块在某处运行,将所有工具的状态重置为 Default.aspx 页面中定义的默认值。我很难找到它。有任何想法吗?
编辑:禁用按钮的代码是 C# 代码,类似于以下内容...
foreach (InteractiveImageToolbarItem toolbarTool in toolbar.ToolbarItems)
{
// First check to see if the dictionary even contains the tool, if not we assume the tool is enabled for all themes, so enable it and
// move to the next iteration.
if (!enabledTools.Keys.Contains(toolbarTool.Name))
{
toolbarTool.Disabled = false;
continue;
}
// So the tool is in the list, this loop checks to see if the tool is enabled for the current theme, meaning the theme is in the list
// associated with the tool.
foreach (string themeFromConfig in enabledTools[toolbarTool.Name])
{
if (currentTheme != themeFromConfig)
{
toolbarTool.Disabled = true;
}
else
{
toolbarTool.Disabled = false;
break;
}
}
}
它可以通过查看配置值来了解应该启用什么。我再一次提到,这部分工作正常。
2009 年 9 月 3 日更新:好的,所以我想我知道问题出在哪里。在 Web ADF 中,被调用的方法 ToolbarMouseDown 在其末尾有一个调用...
Toolbars[toolbarName].refreshGroup();
如果单击与我的工具栏属于同一组的任何工具栏中的工具,则图像将被重置。我不确定我是否了解它背后的逻辑,它使得无法禁用工具或更改图像并让它持续存在。任何...
无论如何,这都是关于 Javascript 方面的事情,有什么方法可以告诉我何时进行了 refreshGroup 调用或其他什么?我认为需要发生的是,当图像重置为启用时,我需要立即将其设置回禁用状态。