How to use the folium.FeatureGroup function in folium

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 python-visualization / folium / tests / plugins / test_dual_map.py View on Github external
def test_dual_map():
    m = folium.plugins.DualMap((0, 0))

    folium.FeatureGroup(name='both').add_to(m)
    folium.FeatureGroup(name='left').add_to(m.m1)
    folium.FeatureGroup(name='right').add_to(m.m2)

    figure = m.get_root()
    assert isinstance(figure, folium.Figure)
    out = normalize(figure.render())

    script = ''  # noqa
    assert script in out

    tmpl = Template("""
        {{ this.m1.get_name() }}.sync({{ this.m2.get_name() }});
        {{ this.m2.get_name() }}.sync({{ this.m1.get_name() }});
    """)

    assert normalize(tmpl.render(this=m)) in out
github python-visualization / folium / tests / test_folium.py View on Github external
def test_feature_group(self):
        """Test FeatureGroup."""

        m = folium.Map()
        feature_group = folium.FeatureGroup()
        feature_group.add_child(folium.Marker([45, -30],
                                              popup=folium.Popup('-30')))
        feature_group.add_child(folium.Marker([45, 30],
                                              popup=folium.Popup('30')))
        m.add_child(feature_group)
        m.add_child(folium.LayerControl())

        m._repr_html_()

        bounds = m.get_bounds()
        assert bounds == [[45, -30], [45, 30]], bounds
github python-visualization / folium / tests / test_folium.py View on Github external
def test_feature_group(self):
        """Test FeatureGroup."""

        m = folium.Map()
        feature_group = folium.FeatureGroup()
        feature_group.add_child(folium.Marker([45, -30],
                                              popup=folium.Popup('-30')))
        feature_group.add_child(folium.Marker([45, 30],
                                              popup=folium.Popup('30')))
        m.add_child(feature_group)
        m.add_child(folium.LayerControl())

        m._repr_html_()

        bounds = m.get_bounds()
        assert bounds == [[45, -30], [45, 30]], bounds
github QratorLabs / measurement_tools / atlas_tools / dns_map.py View on Github external
resolves_counters = defaultdict(int)
    for name, row in panda_probes.iterrows():
        resolves_counters[row["dst_ip"]] += 1

    resolves_counters = [
        (dst_ip, count) for dst_ip, count in resolves_counters.items()
    ]
    resolves_counters.sort(key=lambda tup: tup[1], reverse=True)

    marker_clusters = defaultdict(dict)
    for i, (dst_ip, count) in enumerate(resolves_counters):
        color = MAP_COLORS[i % len(MAP_COLORS)]
        marker_clusters[dst_ip]['count'] = count
        marker_clusters[dst_ip]['color'] = color

        feature_layer = folium.FeatureGroup(
            name='Resolved ip: %s, color: %s, count: %s' %
                 (dst_ip, color, count)
        ).add_to(dns_map)
        marker_clusters[dst_ip]['layer'] = feature_layer

    for name, row in panda_probes.iterrows():
        dst_ip = row['dst_ip']
        folium.CircleMarker(
            location=[float(row['latitude']), float(row['longitude'])],
            popup="Probe_id: %s<br>Resolved_ip: %s" %
                  (row['probe_id'], dst_ip),
            radius=2,
            fill=True,
            color=marker_clusters[dst_ip]['color'],
            fill_opacity=1.0
        ).add_to(marker_clusters[dst_ip]['layer'])
github azavea / bus-plan / analysis / map_solver.py View on Github external
def a(df, line_name, pal, m):

            def c(df, line_name):
                line = df[df.route_id == line_name]
                stops = line[line.stop_sequence == 0].append(line[-1:])
                coords = [[row[1]['y'], row[1]['x']] for row in line.iterrows()]
                stops = [[row[1]['y'], row[1]['x']] for row in stops.iterrows()]
                return coords, stops

            coords, stops = c(df, line_name)
            color = pal[line_name]
            fg = folium.FeatureGroup(name='Route ' + str(line_name))
            fg.add_child(folium.PolyLine(coords, weight=3, opacity=0.75, color=color))
            for point in stops:
                if point == stops[0]:
                    fc = [4, '#006600']
                elif point == stops[-2]:
                    fc = [4, '#CC0000']
                else:
                    fc = [2, '#FFFFFF']
                cm = folium.CircleMarker(
                    point, color=color, fill=True,
                    fill_color=fc[1], fill_opacity=1, radius=fc[0])
                fg.add_child(cm)
            m.add_child(fg)