H.util.ContextItem
Class Summary
Extends: H.util.EventTarget
This class represents contextual information/action.
[ For full details, see the Class Details ]
Property Summary
Properties |
---|
This constant represents the separator for the context item. |
Method Summary
Methods |
---|
This method retrieves the label of the context item. |
This method sets the context item label. |
This method retrieves a value indicating whether the given context item is disabled or not. |
This method enables/disables the context item. |
This method adds a listener for a specific event. |
This method removes a previously added listener from the |
This method dispatches an event on the |
This method removes listeners from the given object. Classes that extend |
This method adds a callback which is triggered when the |
Class Description
This class represents contextual information/action.
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);
}
}));
});
Constructor Details
H.util.ContextItem(opt_options)
- Parameters:
-
opt_options
: -
{H.util.ContextItem.Options=} [optional]
- An object containing the initialization properties
Property Details
static SEPARATOR: {H.util.ContextItem}
This constant represents the separator for the context item.
Method Details
getLabel () : {string}
This method retrieves the label of the context item.
- Returns:
-
{string}
- The label of the context item
setLabel (label) : {H.util.ContextItem}
This method sets the context item label.
- Parameters:
-
label
: -
{string}
- A new label for the context item
- Returns:
-
{H.util.ContextItem}
- An object representing the given context item
isDisabled () : {boolean}
This method retrieves a value indicating whether the given context item is disabled or not.
- Returns:
-
{boolean}
-
true
if the item is disabled,false
otherwise
setDisabled (disabled) : {H.util.ContextItem}
This method enables/disables the context item.
- Parameters:
-
disabled
: -
{boolean}
-
true
to disable andfalse
to enabled the context item
- Returns:
-
{H.util.ContextItem}
- An object representing the given context item
addEventListener (type, handler, opt_capture, opt_scope)
This method adds a listener for a specific event.
Note that to prevent potential memory leaks, you must either call removeEventListener
or dispose
on the given object when you no longer need it.
- Parameters:
-
type
: -
{string}
- The name of the event
-
handler
: -
{!Function}
- An event handler function
-
opt_capture
: -
{boolean=} [optional]
-
true
indicates that the method should listen in the capture phase (bubble otherwise) -
opt_scope
: -
{Object=} [optional]
- An object defining the scope for the handler function
removeEventListener (type, handler, opt_capture, opt_scope)
This method removes a previously added listener from the EventTarget
instance.
- Parameters:
-
type
: -
{string}
- The name of the event
-
handler
: -
{!Function}
- A previously added event handler
-
opt_capture
: -
{boolean=} [optional]
-
true
indicates that the method should listen in the capture phase (bubble otherwise) -
opt_scope
: -
{Object=} [optional]
- An oject defining the scope for the handler function
dispatchEvent (evt)
This method dispatches an event on the EventTarget
object.
- Parameters:
-
evt
: -
{(H.util.Event | string)}
- An object representing the event or a string with the event name
dispose ()
This method removes listeners from the given object. Classes that extend EventTarget
may need to override this method in order to remove references to DOM Elements and additional listeners.
addOnDisposeCallback (callback, opt_scope)
This method adds a callback which is triggered when the EventTarget
object is being disposed.
- Parameters:
-
callback
: -
{!Function}
- The callback function.
-
opt_scope
: -
{Object=} [optional]
- An optional scope for the callback function