Animated lines in python folium maps

folium_antpath

Animated lines in python folium maps

Table of Contents

Prerequisites


In this post we will learn how to draw animated lines with moving ants animation effect in python folium maps using antpath plugin of folium python module

import folium
from folium.plugins import AntPath

# create a map object
mapObj = folium.Map(location=[18.906286495910905, 79.40917968750001],
                    zoom_start=5)

# latitude longitude coordinates of the lines
pathLatLngs = [(19.082502,72.7163773), (12.9541467,77.3191065), (23.199546,77.3234906), (19.0860154,82.0145882), (22.5355649,88.2649519)]
pathLatLngs2 = [(13.0478078,80.0442025), (17.6615468,75.8774177), (24.6083586,73.6636725), (26.8488213,80.860112)]

# create antpaths and add to map
AntPath(pathLatLngs, delay=400, dash_array=[30,15], color="red", weight=3).add_to(mapObj)

AntPath(pathLatLngs2, delay=200, dash_array=[10,50], color="blue", pulse_color="orange", weight=5, opacity=1).add_to(mapObj)

# save the map object as a html
mapObj.save('output.html')

  • As shown in the above code, using “Antpath” class, antpath objects can be created and added to map object
  • Some of the parameters of the antpath line are
    • delay - configures speed to animation, smaller value will increase speed
    • color - color of the line
    • pulse_color - color of the moving ants on the line
    • weight - thickness of the line
    • opacity - sets the transparency of the line, 1 means no transparency
    • dash_array - the first number determines the length of each ant and the second number determines the distance between 2 ants
  • The configuration options can be interactively previewed at https://rubenspgcavalcante.github.io/leaflet-ant-path/

folium_antpath_demo.gif

Video

The video for this post can be seen here

References

Comments