Skip to main content
Improved answer - 'hover' functionality
Source Link
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.

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

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.

added 209 characters in body
Source Link
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

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

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

Source Link
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