How-to: Use setSelectionFilter

Language: JavaScript

The method setSelectionFilter is useful for leveraging the selection operation to get list of selected nodes and then being able to apply functions from, say, the Model class.

Below is a very rudimentary example where the function sets the visibility to off for selected nodes with even-numbered node ids. To best illustrate the function, use the area selection operator to select multiple model nodes


function mySelectionFilter(nodeId) {
	if (nodeId%2 == 0) {
		//console.log("nodeid: " + nodeId);
		hwv.model.setNodesVisibility([nodeId], false);	
	}
} 

var sm = hwv.selectionManager;
sm.setSelectionFilter(mySelectionFilter);

It’s worth noting that a selection operation, in this example, is not actually made when using setSelectionFilter (unless you add return nodeId; to the function). To check, run the following:

sm.getResults();

Notice the returned array is empty. To get back to the original behavior of the selection operator, call:

sm.setSelectionFilter(null);