This topic describes how to write custom functions to handle selection change events in an ENVIView.

  • Write a function using the following syntax:

    Result = FunctionName(View, Graphic, Mode, WasSelected)

  • Avoid a generic function name such as "SelectionChangeEventHandler" to prevent name collisions with other applications using event handlers.
  • The function must return a value of 0 to turn off default event handling or 1 to perform event handling.
  • In the main program where you run ENVI and display an ENVIView, set the SELECTION_CHANGE_HANDLER property of ENVIView to the name of the event handler function.
  • You can also write a general event handler class that contains all event-handling code, instead of creating separate functions for each event handler.

Arguments


View

A reference to an ENVIView object in which the selection change event occurred.

Graphic

The graphic to be selected or un-selected.

Mode

A value representing the mode used for the current selection. Possible values are:

  • 0: Unselect
  • 1: Select
  • 2: Toggled selection
  • 3: Additive

WasSelected

A value of 1 indicates an item was selected prior to the event; a value of 0 indicates an item was not selected.

Example


The following example opens and displays two different color combinations of the same raster, each in a separate view. Pan in the first view, then pan in the second view. Select the first view again, and the yellow snail trail in the Overview window will redraw and clear the trail where you just panned.

Copy and paste the following code into a new file named ExampleAPIEventsSelection.pro, compile it, then run it.

FUNCTION ExampleAPIEventsSelectionChangeHandler, View, $
  graphic, mode, isSelected
  IF ISA(graphic) && ISA(graphic, 'ENVIRASTERLAYER') && ~isSelected THEN BEGIN
  View.ClearSnailTrail
  ENDIF
  RETURN, 1 ; Perform default event handling
END
 
PRO ExampleAPIEventsSelection
  ; Launch the application
  e = ENVI()
 
  ; Open a raster
  file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $
    SUBDIRECTORY = ['data'])
  raster = e.OpenRaster(file)
 
  ; Create two layers
  view1 = e.GetView()
  v1layer1 = view1.CreateLayer(raster)
  v1layer2 = view1.CreateLayer(raster, /CIR)
  view1.SHOW_OVERVIEW = 1
  view1.SHOW_SNAIL_TRAIL = 1
 
  ; Create two layers in another view in opposite order
  view2 = e.CreateView()
  v2layer1 = view2.CreateLayer(raster, /CIR)
  v2layer2 = view2.CreateLayer(raster)
  view2.SHOW_OVERVIEW = 1
  view2.SHOW_SNAIL_TRAIL = 1
  view1.SetProperty, SELECTION_CHANGE_HANDLER='ExampleAPIEventsSelectionChangeHandler'
  view2.SetProperty, SELECTION_CHANGE_HANDLER='ExampleAPIEventsSelectionChangeHandler'
END