Skip to main content
3 of 3
Improved answer - 'hover' functionality
Tommaso
  • 1k
  • 9
  • 13

You can pass an array of layers to the select control

selectControl = new OpenLayers.Control.SelectFeature(
    [lineLayer, pointLayer],
    {
        clickout: true, toggle: false,
        multiple: false, hover: false,
        toggleKey: "ctrlKey", // ctrl key removes from selection
        multipleKey: "shiftKey" // shift key adds to selection
    }
);
        
map.addControl(selectControl);
selectControl.activate();

See the openlayers documentation

To add different behavior for each layer, you could use the "featureselected" and "featureunselected" like in this example

EDIT

How to handle both click and hover control? I didn't try, but following this example should be done easily. Notice that the "hover" control is nothing else that a select control with 'hover': true. So, just add another control passing to it the array of layers.

Tommaso
  • 1k
  • 9
  • 13