@@ -118,6 +118,17 @@ class LegacyMap(MacroElement):
118118 (going from bottom to top).
119119 control_scale : bool, default False
120120 Whether to add a control scale on the map.
121+ prefer_canvas : bool, default False
122+ Forces Leaflet to use the Canvas back-end (if available) for
123+ vector layers instead of SVG. This can increase performance
124+ considerably in some cases (e.g. many thousands of circle
125+ markers on the map).
126+ no_touch : bool, default False
127+ Forces Leaflet to not use touch events even if it detects them.
128+ disable_3d : bool, default False
129+ Forces Leaflet to not use hardware-accelerated CSS 3D
130+ transforms for positioning (which may cause glitches in some
131+ rare environments) even if they're supported.
121132
122133 Returns
123134 -------
@@ -142,7 +153,8 @@ def __init__(self, location=None, width='100%', height='100%',
142153 zoom_start = 10 , continuous_world = False , world_copy_jump = False ,
143154 no_wrap = False , attr = None , min_lat = - 90 , max_lat = 90 ,
144155 min_lon = - 180 , max_lon = 180 , max_bounds = True ,
145- detect_retina = False , crs = 'EPSG3857' , control_scale = False ):
156+ detect_retina = False , crs = 'EPSG3857' , control_scale = False ,
157+ prefer_canvas = False , no_touch = False , disable_3d = False ):
146158 super (LegacyMap , self ).__init__ ()
147159 self ._name = 'Map'
148160 self ._env = ENV
@@ -176,6 +188,8 @@ def __init__(self, location=None, width='100%', height='100%',
176188 self .crs = crs
177189 self .control_scale = control_scale
178190
191+ self .global_switches = GlobalSwitches (prefer_canvas , no_touch , disable_3d )
192+
179193 if tiles :
180194 self .add_tile_layer (
181195 tiles = tiles , min_zoom = min_zoom , max_zoom = max_zoom ,
@@ -254,6 +268,9 @@ def render(self, **kwargs):
254268 assert isinstance (figure , Figure ), ("You cannot render this Element "
255269 "if it's not in a Figure." )
256270
271+ # Set global switches
272+ figure .header .add_child (self .global_switches , name = 'global_switches' )
273+
257274 # Import Javascripts
258275 for name , url in _default_js :
259276 figure .header .add_child (JavascriptLink (url ), name = name )
@@ -284,6 +301,24 @@ def render(self, **kwargs):
284301 super (LegacyMap , self ).render (** kwargs )
285302
286303
304+ class GlobalSwitches (Element ):
305+ def __init__ (self , prefer_canvas = False , no_touch = False , disable_3d = False ):
306+ super (GlobalSwitches , self ).__init__ ()
307+ self ._name = 'GlobalSwitches'
308+
309+ self .prefer_canvas = prefer_canvas
310+ self .no_touch = no_touch
311+ self .disable_3d = disable_3d
312+
313+ self ._template = Template (
314+ '<script>'
315+ 'L_PREFER_CANVAS = {% if this.prefer_canvas %}true{% else %}false{% endif %}; '
316+ 'L_NO_TOUCH = {% if this.no_touch %}true{% else %}false{% endif %}; '
317+ 'L_DISABLE_3D = {% if this.disable_3d %}true{% else %}false{% endif %};'
318+ '</script>'
319+ )
320+
321+
287322class Layer (MacroElement ):
288323 """An abstract class for everything that is a Layer on the map.
289324 It will be used to define whether an object will be included in
0 commit comments