Path: blob/main/tests/plugins/test_overlapping_marker_spiderfier.py
1601 views
"""1Test OverlappingMarkerSpiderfier2--------------------------------3"""45import numpy as np67from folium.folium import Map8from folium.map import Marker9from folium.plugins.overlapping_marker_spiderfier import OverlappingMarkerSpiderfier101112def test_oms_js_inclusion():13"""14Test that the OverlappingMarkerSpiderfier JavaScript library is included in the map.15"""16m = Map([45.05, 3.05], zoom_start=14)17OverlappingMarkerSpiderfier().add_to(m)1819rendered_map = m._parent.render()20assert (21'<script src="https://cdnjs.cloudflare.com/ajax/libs/OverlappingMarkerSpiderfier-Leaflet/0.2.6/oms.min.js"></script>'22in rendered_map23), "OverlappingMarkerSpiderfier JS file is missing in the rendered output."242526def test_marker_addition():27"""28Test that markers are correctly added to the map.29"""30N = 1031np.random.seed(seed=26082009)32data = np.array(33[34np.random.uniform(low=45.0, high=45.1, size=N),35np.random.uniform(low=3.0, high=3.1, size=N),36]37).T3839m = Map([45.05, 3.05], zoom_start=14)40markers = [41Marker(42location=loc,43popup=f"Marker {i}",44)45for i, loc in enumerate(data)46]4748for marker in markers:49marker.add_to(m)5051assert (52len(m._children) == len(markers) + 153), f"Expected {len(markers)} markers, found {len(m._children) - 1}."545556def test_map_bounds():57"""58Test that the map bounds correctly encompass all added markers.59"""60N = 1061np.random.seed(seed=26082009)62data = np.array(63[64np.random.uniform(low=45.0, high=45.1, size=N),65np.random.uniform(low=3.0, high=3.1, size=N),66]67).T6869m = Map([45.05, 3.05], zoom_start=14)70markers = [71Marker(72location=loc,73popup=f"Marker {i}",74)75for i, loc in enumerate(data)76]7778for marker in markers:79marker.add_to(m)8081bounds = m.get_bounds()82assert bounds is not None, "Map bounds should not be None"8384min_lat, min_lon = data.min(axis=0)85max_lat, max_lon = data.max(axis=0)8687assert (88bounds[0][0] <= min_lat89), "Map bounds do not correctly include the minimum latitude."90assert (91bounds[0][1] <= min_lon92), "Map bounds do not correctly include the minimum longitude."93assert (94bounds[1][0] >= max_lat95), "Map bounds do not correctly include the maximum latitude."96assert (97bounds[1][1] >= max_lon98), "Map bounds do not correctly include the maximum longitude."99100101def test_overlapping_marker_spiderfier_integration():102"""103Test that OverlappingMarkerSpiderfier integrates correctly with the map.104"""105m = Map([45.05, 3.05], zoom_start=14)106oms = OverlappingMarkerSpiderfier(107keep_spiderfied=True,108nearby_distance=20,109)110oms.add_to(m)111112assert (113oms.get_name() in m._children114), "OverlappingMarkerSpiderfier is not correctly added to the map."115116117