How to use folium - 10 common examples

To help you get started, we’ve selected a few folium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-mobility / scikit-mobility / skmob / utils / plot.py View on Github external
if nu >= max_users:
            break
        nu += 1

        traj = df[[constants.LONGITUDE, constants.LATITUDE]]

        if max_points is None:
            di = 1
        else:
            di = max(1, len(traj) // max_points)
        traj = traj[::di]

        if nu == 1 and map_f is None:
            # initialise map
            center = list(np.median(traj, axis=0)[::-1])
            map_f = folium.Map(location=center, zoom_start=zoom, tiles=tiles)

        trajlist = traj.values.tolist()
        line = LineString(trajlist)

        if hex_color == -1:
            color = get_color(hex_color)
        else:
            color = hex_color

        tgeojson = folium.GeoJson(line,
                                  name='tgeojson',
                                  style_function=style_function(weight, color, opacity)
                                  )
        tgeojson.add_to(map_f)

        if start_end_markers:
github python-visualization / folium / tests / plugins / test_scroll_zoom_toggler.py View on Github external
def test_scroll_zoom_toggler():
    m = folium.Map([45., 3.], zoom_start=4)
    szt = plugins.ScrollZoomToggler()
    m.add_child(szt)

    out = normalize(m._parent.render())

    # Verify that the div has been created.
    tmpl = Template("""
        <img style="z-index: 999999" src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/png/512/arrow-move.png" alt="scroll" id="{{this.get_name()}}">
    """)
    assert ''.join(tmpl.render(this=szt).split()) in ''.join(out.split())

    # Verify that the style has been created
    tmpl = Template("""
        <style></style>
github python-visualization / folium / tests / test_map.py View on Github external
def test_popup_unicode():
    popup = Popup(u"Ça c'est chouette", parse_html=True)
    _id = list(popup.html._children.keys())[0]
    kw = {
        'id': _id,
        'width': '100.0%',
        'height': '100.0%',
        'text': u'Ça c&#39;est chouette',
    }
    assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
github python-visualization / folium / tests / test_map.py View on Github external
def test_popup_quotes():
    popup = Popup("Let's try quotes", parse_html=True)
    _id = list(popup.html._children.keys())[0]
    kw = {
        'id': _id,
        'width': '100.0%',
        'height': '100.0%',
        'text': 'Let&#39;s try quotes',
    }
    assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
github python-visualization / folium / tests / test_map.py View on Github external
def test_popup_ascii():
    popup = Popup('Some text.')
    _id = list(popup.html._children.keys())[0]
    kw = {
        'id': _id,
        'width': '100.0%',
        'height': '100.0%',
        'text': 'Some text.',
    }
    assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
github python-visualization / folium / tests / test_folium.py View on Github external
def setup(self):
        """Setup Folium Map."""
        with mock.patch('branca.element.uuid4') as uuid4:
            uuid4().hex = '0' * 32
            attr = 'http://openstreetmap.org'
            self.m = folium.Map(
                location=[45.5236, -122.6750],
                width=900,
                height=400,
                max_zoom=20,
                zoom_start=4,
                max_bounds=True,
                attr=attr
            )
        self.env = Environment(loader=PackageLoader('folium', 'templates'))
github bukun / book_python_gis / part010 / ch09_others / sec5_folium / test_2_data_x_x.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###############################################################################
import folium; import json
map_a = folium.Map(location=[46.3014, -123.7390],
    zoom_start=7,tiles='Stamen Terrain')
popup1 = folium.Popup(max_width=800,).add_child(
    folium.Vega(
        json.load(open('/gdata/folium/data/vis1.json')),
        width=500, height=250))
folium.RegularPolygonMarker([47.3489, -124.708],
   fill_color='#ff0000', radius=12, popup=popup1
    ).add_to(map_a)
###############################################################################
popup2 = folium.Popup(max_width=800,).add_child(
    folium.Vega(
        json.load(open('/gdata/folium/data/vis2.json')),
        width=500, height=250))
folium.RegularPolygonMarker([44.639, -124.5339],
    fill_color='#00ff00', radius=12, popup=popup2
    ).add_to(map_a)
github python-visualization / folium / tests / test_repr.py View on Github external
def m_png():
    yield folium.Map(png_enabled=True)
github python-visualization / folium / tests / plugins / test_heat_map.py View on Github external
def test_heat_map():
    np.random.seed(3141592)
    data = (np.random.normal(size=(100, 2)) * np.array([[1, 1]]) +
            np.array([[48, 5]])).tolist()
    m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
    hm = plugins.HeatMap(data)
    m.add_child(hm)
    m._repr_html_()

    out = normalize(m._parent.render())

    # We verify that the script import is present.
    script = ''  # noqa
    assert script in out

    # We verify that the script part is correct.
    tmpl = Template("""
            var {{this.get_name()}} = L.heatLayer(
                {{this.data}},
                {
                    minOpacity: {{this.min_opacity}},
github python-visualization / folium / tests / test_utilities.py View on Github external
def test_get_obj_in_upper_tree():
    m = Map()
    fg = FeatureGroup().add_to(m)
    marker = Marker(location=(0, 0)).add_to(fg)
    assert get_obj_in_upper_tree(marker, FeatureGroup) is fg
    assert get_obj_in_upper_tree(marker, Map) is m
    # The search should only go up, not down:
    with pytest.raises(ValueError):
        assert get_obj_in_upper_tree(fg, Marker)
    with pytest.raises(ValueError):
        assert get_obj_in_upper_tree(marker, Popup)