This code places an Elementary map widget on a window, to exemplify part of the widget's API, related to overlays.
We'll start this example in the same way as Map Example 1. Adding a map with buttons to control zoom, so if you didn't read it yet, just do it now.
Overlays can be placed over the map to represent anything we want. Let's say we want to represent some countries and cities with overlays.
Before we create city or country overlays, let's create class overlays.
These lines create a class overlay which represents cities. This class overlay will be used for grouping city overlays. Later city overlays in the same class are appended to this class overlay. if city overlays are near each other, they will be grouped.
We can set the icon for the class so that the icon will be displayed when city overlays are grouped. We can set the zoom required to display the overlays that belongs to this class, so if the zoom is less than this value, nothing will be shown.
Country class can be created in the same way.
Next we'll create some overlays representing cities and countries. We set the data for the overlay so that can be used later when clicked callback is called. We'll append them into city class to be grouped. We'll append them in a list, to close up them later. To create a default overlay, we need to pass the coordinates.
We subscribe a smart callback "overlay,clicked" to create bubble on the clicked overlay.
Finally, on our main
function, we ask the map to show all the overlays with the biggest zoom possible, passing the list of overlays added.
We have created a specific structure for this example to store the name of the place and a path to a image file to represent it.
We'll create instances for each place:
To return an icon, all we need to do is to add a elm_icon and return it:
For the content, let's return something more elaborate. We will return a box with an image representing the place, and the name of this place:
See map_example_02.c for full source, whose window should look like this picture: