This class represents contextual information/action.
| Name | Type | Description |
|---|---|---|
opt_options |
H.util.ContextItem.Options |
optional
An object containing the initialization properties |
Example
// Enable map events such as "contextmenu"
var events = new H.mapevents.MapEvents(map);
// Show default controls as well as the Context Menu control
var ui = H.ui.UI.createDefault(map, defaultLayers, 'en-US');
// Add 'Zoom in' context menu item
map.addEventListener('contextmenu', function(e) {
e.items.push(new H.util.ContextItem({
label: 'Zoom in',
callback: function() {
map.setZoom(map.getZoom() + 1);
}
}));
});
Extends
Members
-
H.util.ContextItem.SEPARATOR H.util.ContextItem staticconstantnon-null
-
This constant represents the separator for the context item.
Methods
-
addEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method adds a listener for a specific event.
Note that to prevent potential memory leaks, you must either call
removeEventListenerordisposeon the given object when you no longer need it.Name Type Description typestring The name of the event
handlerfunction An event handler function
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
addOnDisposeCallback (callback, opt_scope) inherited
-
This method adds a callback which is triggered when the
EventTargetobject is being disposed.Name Type Description callbackfunction The callback function.
opt_scopeObject optional An optional scope for the callback function
-
dispatchEvent (evt) inherited
-
This method dispatches an event on the
EventTargetobject.Name Type Description evtH.util.Event | string An object representing the event or a string with the event name
-
dispose () inherited
-
This method removes listeners from the given object. Classes that extend
EventTargetmay need to override this method in order to remove references to DOM Elements and additional listeners. -
This method retrieves the label of the context item.
Returns:
Type Description string The label of the context item -
This method retrieves a value indicating whether the given context item is disabled or not.
Returns:
Type Description boolean trueif the item is disabled,falseotherwise -
removeEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method removes a previously added listener from the
EventTargetinstance.Name Type Description typestring The name of the event
handlerfunction A previously added event handler
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
setDisabled (disabled)H.util.ContextItem
-
This method enables/disables the context item.
Name Type Description disabledboolean trueto disable andfalseto enabled the context itemFires:
- H.util.ContextItem#event:update
Returns:
Type Description H.util.ContextItem An object representing the given context item -
setLabel (label)H.util.ContextItem
-
This method sets the context item label.
Name Type Description labelstring A new label for the context item
Fires:
- H.util.ContextItem#event:update
Returns:
Type Description H.util.ContextItem An object representing the given context item
Type Definitions
-
This type defines options which can be used to initialize the context item.
Properties:
Name Type Argument Description labelstring <optional>
The label for the context item
disabledboolean <optional>
A flag indicating whether the context item is disabled (
true) or not (false, default)callbackfunction <optional>
Optional callback function to call when the context item is selected