Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._add_unit(name, factor, decimals)
def _add_unit(self, name, factor, decimals):
self._custom_units_dict[name] = {
'factor': factor,
'display': name,
'decimals': decimals
}
self._custom_units = dict(**self._custom_units_dict)
class SplitMapControl(Control):
_view_name = Unicode('LeafletSplitMapControlView').tag(sync=True)
_model_name = Unicode('LeafletSplitMapControlModel').tag(sync=True)
left_layer = Union((Instance(Layer), List(Instance(Layer)))).tag(sync=True, **widget_serialization)
right_layer = Union((Instance(Layer), List(Instance(Layer)))).tag(sync=True, **widget_serialization)
@default('left_layer')
def _default_left_layer(self):
return TileLayer()
@default('right_layer')
def _default_right_layer(self):
return TileLayer()
def __init__(self, **kwargs):
super(SplitMapControl, self).__init__(**kwargs)
self.on_msg(self._handle_leaflet_event)
def _handle_leaflet_event(self, _, content, buffers):
if content.get('event', '') == 'dividermove':
self._dblclick_callbacks.register_callback(callback, remove=remove)
def on_mousedown(self, callback, remove=False):
self._mousedown_callbacks.register_callback(callback, remove=remove)
def on_mouseup(self, callback, remove=False):
self._mouseup_callbacks.register_callback(callback, remove=remove)
def on_mouseover(self, callback, remove=False):
self._mouseover_callbacks.register_callback(callback, remove=remove)
def on_mouseout(self, callback, remove=False):
self._mouseout_callbacks.register_callback(callback, remove=remove)
class UILayer(Layer):
_view_name = Unicode('LeafletUILayerView').tag(sync=True)
_model_name = Unicode('LeafletUILayerModel').tag(sync=True)
class Icon(UILayer):
_view_name = Unicode('LeafletIconView').tag(sync=True)
_model_name = Unicode('LeafletIconModel').tag(sync=True)
icon_url = Unicode('').tag(sync=True, o=True)
shadow_url = Unicode(None, allow_none=True).tag(sync=True, o=True)
icon_size = Tuple((10, 10), allow_none=True).tag(sync=True, o=True)
shadow_size = Tuple((10, 10), allow_none=True).tag(sync=True, o=True)
icon_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)
shadow_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)
popup_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)
location = List(def_loc).tag(sync=True)
# Options
radius = Int(10, help='radius of circle in pixels').tag(sync=True, o=True)
class Circle(CircleMarker):
_view_name = Unicode('LeafletCircleView').tag(sync=True)
_model_name = Unicode('LeafletCircleModel').tag(sync=True)
# Options
radius = Int(1000, help='radius of circle in meters').tag(sync=True, o=True)
class MarkerCluster(Layer):
_view_name = Unicode('LeafletMarkerClusterView').tag(sync=True)
_model_name = Unicode('LeafletMarkerClusterModel').tag(sync=True)
markers = Tuple().tag(trait=Instance(Marker), sync=True, **widget_serialization)
class LayerGroup(Layer):
_view_name = Unicode('LeafletLayerGroupView').tag(sync=True)
_model_name = Unicode('LeafletLayerGroupModel').tag(sync=True)
layers = Tuple().tag(trait=Instance(Layer), sync=True, **widget_serialization)
_layer_ids = List()
@validate('layers')
def _validate_layers(self, proposal):
# Options
min_width = Int(50).tag(sync=True, o=True)
max_width = Int(300).tag(sync=True, o=True)
max_height = Int(default_value=None, allow_none=True).tag(sync=True, o=True)
auto_pan = Bool(True).tag(sync=True, o=True)
auto_pan_padding_top_left = List(allow_none=True, default_value=None).tag(sync=True, o=True)
auto_pan_padding_bottom_right = List(allow_none=True, default_value=None).tag(sync=True, o=True)
auto_pan_padding = List([5, 5]).tag(sync=True, o=True)
keep_in_view = Bool(False).tag(sync=True, o=True)
close_button = Bool(True).tag(sync=True, o=True)
auto_close = Bool(True).tag(sync=True, o=True)
close_on_escape_key = Bool(True).tag(sync=True, o=True)
class_name = Unicode('').tag(sync=True, o=True)
class RasterLayer(Layer):
_view_name = Unicode('LeafletRasterLayerView').tag(sync=True)
_model_name = Unicode('LeafletRasterLayerModel').tag(sync=True)
opacity = Float(1.0, min=0.0, max=1.0).tag(sync=True)
visible = Bool(True).tag(sync=True)
class TileLayer(RasterLayer):
_view_name = Unicode('LeafletTileLayerView').tag(sync=True)
_model_name = Unicode('LeafletTileLayerModel').tag(sync=True)
bottom = Bool(True).tag(sync=True)
url = Unicode('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').tag(sync=True)
min_zoom = Int(0).tag(sync=True, o=True)
max_zoom = Int(18).tag(sync=True, o=True)
min_native_zoom = Int(0).tag(sync=True, o=True)
def __iadd__(self, item):
if isinstance(item, Layer):
self.add_layer(item)
elif isinstance(item, Control):
self.add_control(item)
return self
# Options
attribution = Unicode().tag(sync=True, o=True)
class VideoOverlay(RasterLayer):
_view_name = Unicode('LeafletVideoOverlayView').tag(sync=True)
_model_name = Unicode('LeafletVideoOverlayModel').tag(sync=True)
url = Unicode().tag(sync=True)
bounds = List([def_loc, def_loc], help='SW and NE corners of the image').tag(sync=True)
# Options
attribution = Unicode().tag(sync=True, o=True)
class Velocity(Layer):
_view_name = Unicode('LeafletVelocityView').tag(sync=True)
_model_name = Unicode('LeafletVelocityModel').tag(sync=True)
zonal_speed = Unicode('', help='Name of the zonal speed in the dataset')
meridional_speed = Unicode('', help='Name of the meridional speed in the dataset')
latitude_dimension = Unicode('latitude', help='Name of the latitude dimension in the dataset')
longitude_dimension = Unicode('longitude', help='Name of the longitude dimension in the dataset')
units = Unicode(None, allow_none=True)
data = Dataset().tag(dtype=None, sync=True, to_json=ds_x_to_json)
# Options
display_values = Bool(True).tag(sync=True, o=True)
display_options = Dict({
'velocityType': 'Global Wind',
'position': 'bottomleft',
class Heatmap(RasterLayer):
_view_name = Unicode('LeafletHeatmapView').tag(sync=True)
_model_name = Unicode('LeafletHeatmapModel').tag(sync=True)
locations = List().tag(sync=True)
# Options
min_opacity = Float(0.05).tag(sync=True, o=True)
max_zoom = Int(18).tag(sync=True, o=True)
max = Float(1.0).tag(sync=True, o=True)
radius = Float(25.0).tag(sync=True, o=True)
blur = Float(15.0).tag(sync=True, o=True)
gradient = Dict({0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red'}).tag(sync=True, o=True)
class VectorLayer(Layer):
_view_name = Unicode('LeafletVectorLayerView').tag(sync=True)
_model_name = Unicode('LeafletVectorLayerModel').tag(sync=True)
class Path(VectorLayer):
_view_name = Unicode('LeafletPathView').tag(sync=True)
_model_name = Unicode('LeafletPathModel').tag(sync=True)
# Options
stroke = Bool(True).tag(sync=True, o=True)
color = Color('#0033FF').tag(sync=True, o=True)
weight = Int(5).tag(sync=True, o=True)
fill = Bool(True).tag(sync=True, o=True)
fill_color = Color('#0033FF').tag(sync=True, o=True)
fill_opacity = Float(0.2).tag(sync=True, o=True)
dash_array = Unicode(allow_none=True, default_value=None).tag(sync=True, o=True)
def __init__(self, **kwargs):
super(Layer, self).__init__(**kwargs)
self.on_msg(self._handle_mouse_events)
class Circle(CircleMarker):
_view_name = Unicode('LeafletCircleView').tag(sync=True)
_model_name = Unicode('LeafletCircleModel').tag(sync=True)
# Options
radius = Int(1000, help='radius of circle in meters').tag(sync=True, o=True)
class MarkerCluster(Layer):
_view_name = Unicode('LeafletMarkerClusterView').tag(sync=True)
_model_name = Unicode('LeafletMarkerClusterModel').tag(sync=True)
markers = Tuple().tag(trait=Instance(Marker), sync=True, **widget_serialization)
class LayerGroup(Layer):
_view_name = Unicode('LeafletLayerGroupView').tag(sync=True)
_model_name = Unicode('LeafletLayerGroupModel').tag(sync=True)
layers = Tuple().tag(trait=Instance(Layer), sync=True, **widget_serialization)
_layer_ids = List()
@validate('layers')
def _validate_layers(self, proposal):
'''Validate layers list.
Makes sure only one instance of any given layer can exist in the
layers list.
'''
self._layer_ids = [l.model_id for l in proposal.value]
if len(set(self._layer_ids)) != len(self._layer_ids):