Repository: python-visualization/folium

Issue:
Performance issue when trying to draw lots of markers: prefer_canvas option inefficient
Trying to plot thousands of circleMarkers, it appeared that rendering the map was very slow.

I tried to use the `prefer_canvas` option during Map creation:
```python

carte = folium.Map(
        location=[48, 8.33],
        tiles='Mapbox Bright',
        prefer_canvas=True,
    )

```
but didn't see any performance improvement. Looking into the generated html, it seems that the  `prefer_canvas` option is rendered as a Global Switch:

```javascript
<script>
            L_PREFER_CANVAS = true;
            L_NO_TOUCH = false;
            L_DISABLE_3D = false;
</script>
```

Unfortunately, it seems that the `L_PREFER_CANVAS` switch isn't supported anymore since Leaflet 1.0, the prefered way of using Canvas is now during the map creation (https://leafletjs.com/reference-1.4.0.html#map-prefercanvas).

Adding directly the ```preferCanvas: true``` option in the html, I saw a huge speed improvement in the drawing of the markers.

Discussion:

Patch:
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 7a0f090a..9bdb40a2 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -60,6 +60,10 @@ The basic workflow for contributing is:
    git checkout -b name-of-your-branch
    ```
 4. Install the dependencies listed in `requirements.txt` and `requirements-dev.txt`.
+   ```
+   pip install -r requirements.txt
+   pip install -r requirements-dev.txt
+   ```
 5. Install Firefox, download [geckodriver](https://github.com/mozilla/geckodriver/releases) 
    and put it in the PATH.
 6. Make changes to your local copy of the folium repository
diff --git a/folium/folium.py b/folium/folium.py
index ac1e1ea8..bf5eb17d 100644
--- a/folium/folium.py
+++ b/folium/folium.py
@@ -55,16 +55,14 @@ class GlobalSwitches(Element):
 
     _template = Template("""
         <script>
-            L_PREFER_CANVAS = {{ this.prefer_canvas|tojson }};
             L_NO_TOUCH = {{ this.no_touch |tojson}};
             L_DISABLE_3D = {{ this.disable_3d|tojson }};
         </script>
     """)
 
-    def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
+    def __init__(self, no_touch=False, disable_3d=False):
         super(GlobalSwitches, self).__init__()
         self._name = 'GlobalSwitches'
-        self.prefer_canvas = prefer_canvas
         self.no_touch = no_touch
         self.disable_3d = disable_3d
 
@@ -269,11 +267,11 @@ class Map(MacroElement):
             max_bounds=max_bounds_array,
             zoom=zoom_start,
             zoom_control=zoom_control,
+            prefer_canvas=prefer_canvas,
             **kwargs
         )
 
         self.global_switches = GlobalSwitches(
-            prefer_canvas,
             no_touch,
             disable_3d
         )


Test patch:
diff --git a/tests/test_folium.py b/tests/test_folium.py
index d2e302fe..baab9b04 100644
--- a/tests/test_folium.py
+++ b/tests/test_folium.py
@@ -103,7 +103,6 @@ class TestFolium(object):
         assert self.m.width == (900, 'px')
         assert self.m.left == (0, '%')
         assert self.m.top == (0, '%')
-        assert self.m.global_switches.prefer_canvas is False
         assert self.m.global_switches.no_touch is False
         assert self.m.global_switches.disable_3d is False
         assert self.m.to_dict() == {
@@ -278,7 +277,7 @@ class TestFolium(object):
                                               'padding': (3, 3), },
                                              sort_keys=True),
             'this': fitbounds,
-            })
+        })
 
         assert ''.join(fit_bounds_rendered.split()) in ''.join(out.split())
 
@@ -310,22 +309,30 @@ class TestFolium(object):
 
     def test_global_switches(self):
         m = folium.Map(prefer_canvas=True)
-        assert m.global_switches.prefer_canvas
+        out = m._parent.render()
+        out_str = ''.join(out.split())
+        assert "preferCanvas:true" in out_str
         assert not m.global_switches.no_touch
         assert not m.global_switches.disable_3d
 
         m = folium.Map(no_touch=True)
-        assert not m.global_switches.prefer_canvas
+        out = m._parent.render()
+        out_str = ''.join(out.split())
+        assert "preferCanvas:false" in out_str
         assert m.global_switches.no_touch
         assert not m.global_switches.disable_3d
 
         m = folium.Map(disable_3d=True)
-        assert not m.global_switches.prefer_canvas
+        out = m._parent.render()
+        out_str = ''.join(out.split())
+        assert "preferCanvas:false" in out_str
         assert not m.global_switches.no_touch
         assert m.global_switches.disable_3d
 
         m = folium.Map(prefer_canvas=True, no_touch=True, disable_3d=True)
-        assert m.global_switches.prefer_canvas
+        out = m._parent.render()
+        out_str = ''.join(out.split())
+        assert "preferCanvas:true" in out_str
         assert m.global_switches.no_touch
         assert m.global_switches.disable_3d