Change cursor type over the map


In [1]:
from ipyleaflet import Map
m = Map()
m.zoom = 3
m


There are two instances when you can change the cursor type: when dragging, and when not dragging

Not dragging (default)


In [3]:
# Crosshair
m.default_style = {'cursor': 'crosshair'}

In [4]:
# Pointer
m.default_style = {'cursor': 'default'}

In [5]:
# Waiting
m.default_style = {'cursor': 'wait'}

In [6]:
# Not allowed value
m.default_style = {'cursor': 'notallowedcursor'}


---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)
<ipython-input-6-17175832f6fc> in <module>
      1 # Not allowed value
----> 2 m.default_style = {'cursor': 'notallowedcursor'}

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in __set__(self, obj, value)
    583             raise TraitError('The "%s" trait is read-only.' % self.name)
    584         else:
--> 585             self.set(obj, value)
    586 
    587     def _validate(self, obj, value):

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in set(self, obj, value)
    557 
    558     def set(self, obj, value):
--> 559         new_value = self._validate(obj, value)
    560         try:
    561             old_value = obj._trait_values[self.name]

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in _validate(self, obj, value)
    589             return value
    590         if hasattr(self, 'validate'):
--> 591             value = self.validate(obj, value)
    592         if obj._cross_validation_lock is False:
    593             value = self._cross_validate(obj, value)

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/ipywidgets/widgets/trait_types.py in validate(self, obj, value)
    135     def validate(self, obj, value):
    136         if isinstance(value, dict):
--> 137             return super(InstanceDict, self).validate(obj, self.klass(**value))
    138         else:
    139             return super(InstanceDict, self).validate(obj, value)

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/ipywidgets/widgets/widget.py in __init__(self, **kwargs)
    409         """Public constructor"""
    410         self._model_id = kwargs.pop('model_id', None)
--> 411         super(Widget, self).__init__(**kwargs)
    412 
    413         Widget._call_widget_constructed(self)

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in __init__(self, *args, **kwargs)
    995             for key, value in kwargs.items():
    996                 if self.has_trait(key):
--> 997                     setattr(self, key, value)
    998                 else:
    999                     # passthrough args that don't set traits to super

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in __set__(self, obj, value)
    583             raise TraitError('The "%s" trait is read-only.' % self.name)
    584         else:
--> 585             self.set(obj, value)
    586 
    587     def _validate(self, obj, value):

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in set(self, obj, value)
    557 
    558     def set(self, obj, value):
--> 559         new_value = self._validate(obj, value)
    560         try:
    561             old_value = obj._trait_values[self.name]

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in _validate(self, obj, value)
    589             return value
    590         if hasattr(self, 'validate'):
--> 591             value = self.validate(obj, value)
    592         if obj._cross_validation_lock is False:
    593             value = self._cross_validate(obj, value)

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in validate(self, obj, value)
   2136         if value in self.values:
   2137                 return value
-> 2138         self.error(obj, value)
   2139 
   2140     def info(self):

~/Python/envs/ipyleaflet/lib/python3.5/site-packages/traitlets/traitlets.py in error(self, obj, value)
    623             e = "The '%s' trait must be %s, but a value of %r was specified." \
    624                 % (self.name, self.info(), repr_type(value))
--> 625         raise TraitError(e)
    626 
    627     def get_metadata(self, key, default=None):

TraitError: The 'cursor' trait of a MapStyle instance must be any of ['alias', 'cell', 'grab', 'move', 'crosshair', 'context-menu', 'n-resize', 'ne-resize', 'e-resize', 'se-resize', 's-resize', 'sw-resize', 'w-resize', 'nw-resize', 'nesw-resize', 'nwse-resize', 'row-resize', 'col-resize', 'copy', 'default', 'grabbing', 'help', 'no-drop', 'not-allowed', 'pointer', 'progress', 'text', 'wait', 'zoom-in', 'zoom-out'], but a value of 'notallowedcursor' <class 'str'> was specified.

When dragging


In [7]:
# col resize
m.dragging_style = {'cursor': 'col-resize'}