How to set up an interactive map in 5 steps (PyCon SK 2022)
The PyCon SK 2022 conference, held in Bratislava, is an annual gathering of the Python community. It is organised by volunteers from the SPy organization dedicated to the propagation of the Python language and other open source technologies and ideas.
This year was also packed with interesting lectures and workshops, which attracted a lot of Python enthusiasts. In this article, we will present a topic that caught our attention for its simplicity, speed of implementation and the benefits it can bring.
The lecture is Set up an interactive map in browser in a few steps, presented by Mr. Vojta Filipec. What did we learn in it?
- How to make an interactive, easy-to-share map
- How to display points of interest (POIs)
- Set the colour, size and shape of POIs on the map
- Display a pop-up window with detailed POI information
Step 1
We will use OpenStreetMap to download information about the location of all libraries in Slovakia.
Step 2
With transformations we modify the data into the desired shape. The complete code can be found at this link
Step 3
Use the folium package to create and display the map.
Step 4
We add points of interest - POIs - to the map, for which we can define a color, for example, according to a certain condition, as shown in the example on github.
Step 5
In the last step, we set up a pop-up window that appears when you click on a POI. We will define a function that will create the pop-up and set it as a parameter when creating the POI.
That's it! We've displayed the POIs on the map, set the POI color based on the condition, and created a pop-up that appears when you click on it. And this is what the final result looks like:
The result can be further configured, such as changing the underlying map, or using different icons instead of the circles that indicate POIs. If you are interested in this map creation option, feel free to watch this talk, which is available on YouTube.