Feature Events

There are a few ways of handling events on features, each of which is suited best for specific tasks. For the most part you will be using the ALKMaps.Control.SelectFeature and ALKMaps.Control.FeatureEvent controls for handling these events. Please note that this does not include markers, any attempt to use these controls on a ALKMaps.Layer.Markers layer or ALKMaps.Marker object will not work.

Special Cases

Please note that the FeatureEvent and SelectFeature controls must be deactivated in order to perform certain actions on a layer. For example the control will need to be temporarily deactivated in order to be able to use a layer’s setOpacity function. The control must also be deactivated in order to set a layer’s z-index.

SelectFeature Control

The ALKMaps.Control.SelectFeature is best suited for actually selecting one or more features on hover, click, or drag box. The default functionality of this control is to simply highlight any selected features using a predetermined style object. You also have ability to use a custom style object for highlighting a feature when it is selected, or you can choose to not highlight the features at all. Another useful feature of this control is an optional set of user defined functions to be called right before a feature is selected, on selection, and on unselection; as well as triggering “beforefeatureselected”, “featureselected”, and “featureunselected” events respectively.

SelectFeature Parameters

ParameterTypeDescription/Values
multipleKeyStringAn event modifier ('altKey' or 'shiftKey') that temporarily sets the multiple property to true. Default is null.
toggleKeyStringAn event modifier ('altKey' or 'shiftKey') that temporarily sets the toggle property to true. Default is null.
multipleBooleanAllow selection of multiple geometries. Default is false.
clickoutBooleanUnselect features when clicking outside any feature. Default is true.
toggleBooleanUnselect a selected feature on click. Default is false. Only has meaning if hover is false.
hoverBooleanSelect on mouse over and deselect on mouse out. If true, this ignores clicks and only listens to mouse moves. Default is false.
highlightOnlyBooleanIf true do not actually select features (that is place them in the layer's selected features array), just highlight them. This property has no effect if hover is false. Defaults to false.
boxBooleanAllow feature selection by drawing a box.
onBeforeSelectFunctionOptional function to be called before a feature is selected. The function should expect to be called with a feature.
onSelectFunctionOptional function to be called when a feature is selected. The function should expect to be called with a feature.
onUnselectFunctionOptional function to be called when a feature is unselected. The function should expect to be called with a feature.
scopeObjectThe scope to use with the onBeforeSelect, onSelect, onUnselect callbacks. If null the scope will be this control.
geometryTypesArray(String)To restrict selecting to a limited set of geometry types, send a list of strings corresponding to the geometry class names.
layersArray(ALKMaps.Layer.Vector |
ALKMaps.Layer.VectorMarkers)
The layers this control will work on.
selectStyleObjectHash of styles to be used for feature selection.

Click The Point To Highlight It

FeatureEvent Control

The ALKMaps.Control.FeatureEvent control is very useful for detecting mouse events on a feature and triggering a corresponding event. The FeatureEvent control has a couple significant advantages over the SelectFeature control. When dealing with multiple layers, it is important to note that the FeatureEvent control gives you the ability to handle these events on a per layer basis by only triggering the event on the layer which the feature is from. Another exciting aspect is the control’s ability to filter out specific features by attribute and have the control ignore the rest. This control now also supports right click events on features. The following table outlines the list of supported events for the FeatureEvent control.

Supported Events

EventDescription
featureclickedTriggered when a feature is clicked.
featurerightclickedTriggered when a feature is right clicked.
featureclickedoutTriggered when there is a click outside of a feature after a “featureclicked” or “featurerightclicked” event has been triggered for that feature. Last stored feature will be returned in the event.
featurerightclickedoutTriggered when there is a right click outside of a feature after a “featureclicked” or “featurerightclicked” event has been triggered for that feature. Last stored feature will be returned in the event.
overFeatureTriggered when mouse over a feature.
outFeatureTriggered when mouse out a feature.

Hover Over The Left Point To Remove It

As you can see in the sample below, the event can be registered to the specific layer preventing features on other layers from interfering. This FeatureEvent in this sample also uses the featureAttributesFilter option so that only features containing the eventDetection attribute with a value of true will trigger the “overFeature” event.

Last updated November 5, 2019.