I have a Map
control on a Form
. The map control contains a collection of layers which each have a "IsVisible" to hide or show the layer.
I have a TreeView
control with CheckBoxes
with each node
representing a layer, all contained under a single parent node
.
When I check/uncheck a node, I want the related layer's IsVisible
property to be set equal to the node's checked state.
Here's what I'm currently doing:
private void LayerTreeView_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Node.Parent == null) //if it's a parent node, make any children nodes match its checked state
{
foreach (TreeNode node in e.Node.Nodes)
{
node.Checked = e.Node.Checked;
Map.BeginInvoke((MethodInvoker)delegate () { Map.FindFeatureLayer(node.Name).IsVisible = node.Checked; });
}
}
else //it's a child node
{
Map.FindFeatureLayer(e.Node.Name).IsVisible = e.Node.Checked;
}
Map.BeginInvoke((MethodInvoker)delegate () { Map.Refresh(); }); //culprit is here
}
The problem is that there is a noticeable lag which increases with the more layers/nodes I have. In the code above, the last line contains the Map.Refresh();
The nodes don't update visibly until the Map.Refresh()
is called, which is called for each node that has it's checked state changed. This causes the delay. I need the nodes to update immediately. It doesn't matter if the Map
control lags behind with it's refresh, but it shouldn't be the opposite.
Aucun commentaire:
Enregistrer un commentaire