|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +''' |
| 3 | +Folium Plugins Tests |
| 4 | +-------------------- |
| 5 | +
|
| 6 | +''' |
| 7 | +import folium |
| 8 | +from folium import plugins |
| 9 | +import numpy as np |
| 10 | +import json |
| 11 | + |
| 12 | +class testPlugins(object): |
| 13 | + '''Test class for Folium plugins''' |
| 14 | + |
| 15 | + def test_scroll_zoom_toggler(self): |
| 16 | + mapa = folium.Map([45.,3.], zoom_start=4) |
| 17 | + mapa.add_plugin(plugins.ScrollZoomToggler()) |
| 18 | + mapa._build_map() |
| 19 | + |
| 20 | + |
| 21 | + def test_marker_cluster(self): |
| 22 | + N = 100 |
| 23 | + data = np.array([ |
| 24 | + np.random.uniform(low=35,high=60, size=N), # random latitudes in Europe |
| 25 | + np.random.uniform(low=-12,high=30, size=N), # random longitudes in Europe |
| 26 | + range(N), # popups are simple numbers |
| 27 | + ]).T |
| 28 | + mapa = folium.Map([45.,3.], zoom_start=4) |
| 29 | + mapa.add_plugin(plugins.MarkerCluster(data)) |
| 30 | + mapa._build_map() |
| 31 | + |
| 32 | + def test_terminator(self): |
| 33 | + mapa = folium.Map([45.,3.], zoom_start=1) |
| 34 | + mapa.add_plugin(plugins.Terminator()) |
| 35 | + mapa.add_plugin(plugins.ScrollZoomToggler()) |
| 36 | + mapa._build_map() |
| 37 | + |
| 38 | + def test_boat_marker(self): |
| 39 | + mapa = folium.Map([30.,0.], zoom_start=3) |
| 40 | + mapa.add_plugin(plugins.BoatMarker((34,-43), heading=45, |
| 41 | + wind_heading=150, wind_speed=45, color="#8f8")) |
| 42 | + mapa.add_plugin(plugins.BoatMarker((46,-30), heading=-20, |
| 43 | + wind_heading=46, wind_speed=25, color="#88f")) |
| 44 | + mapa._build_map() |
| 45 | + |
| 46 | + def test_layer(self): |
| 47 | + mapa = folium.Map([48.,5.], zoom_start=6) |
| 48 | + mapa.add_plugin(plugins.Layer('//otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', |
| 49 | + layer_name='MapQuest')) |
| 50 | + mapa.add_plugin(plugins.LayerControl()) |
| 51 | + mapa._build_map() |
| 52 | + |
| 53 | + def test_geo_json(self): |
| 54 | + N=100 |
| 55 | + lons = +5 - np.random.normal(size=N) |
| 56 | + lats = 48 - np.random.normal(size=N) |
| 57 | + |
| 58 | + data = { |
| 59 | + "type": "FeatureCollection", |
| 60 | + "features": [ |
| 61 | + { |
| 62 | + "type": "Feature", |
| 63 | + "geometry": { |
| 64 | + "type": "MultiPoint", |
| 65 | + "coordinates": [[lon, lat] for (lat,lon) in zip(lats,lons)], |
| 66 | + }, |
| 67 | + "properties": {"prop0": "value0"} |
| 68 | + }, |
| 69 | + ], |
| 70 | + } |
| 71 | + |
| 72 | + mapa = folium.Map([48.,5.], zoom_start=6) |
| 73 | + mapa.add_plugin(plugins.GeoJson(data)) |
| 74 | + mapa._build_map() |
| 75 | + |
| 76 | + open('geojson_plugin_test1.json','w').write(json.dumps(data)) |
| 77 | + mapb = folium.Map([48.,5.], zoom_start=6) |
| 78 | + mapb.add_plugin(plugins.GeoJson(open('geojson_plugin_test1.json'))) |
| 79 | + mapb._build_map() |
| 80 | + |
| 81 | + data = { |
| 82 | + "type": "FeatureCollection", |
| 83 | + "features": [ |
| 84 | + { |
| 85 | + "type": "Feature", |
| 86 | + "geometry": { |
| 87 | + "type": "MultiPolygon", |
| 88 | + "coordinates": [[[[lon+1e-4, lat+1e-4], |
| 89 | + [lon+1e-4, lat-1e-4], |
| 90 | + [lon-1e-4, lat-1e-4], |
| 91 | + [lon-1e-4, lat+1e-4]]] for (lat,lon) in zip(lats,lons)], |
| 92 | + }, |
| 93 | + "properties": {"prop0": "value0"} |
| 94 | + }, |
| 95 | + ], |
| 96 | + } |
| 97 | + |
| 98 | + mapc = folium.Map([48.,5.], zoom_start=6) |
| 99 | + mapc.add_plugin(plugins.GeoJson(data)) |
| 100 | + mapc._build_map() |
| 101 | + |
| 102 | + open('geojson_plugin_test2.json','w').write(json.dumps(data)) |
| 103 | + mapd = folium.Map([48.,5.], zoom_start=6) |
| 104 | + mapd.add_plugin(plugins.GeoJson(open('geojson_plugin_test2.json'))) |
| 105 | + mapd._build_map() |
| 106 | + |
0 commit comments