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.
elm_object_text_set(bt, "+");
elm_object_text_set(bt, "-");
elm_object_text_set(bt, "X");
elm_object_text_set(bt, "#");
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.
typedef struct _Overlay_Data
{
const char *name;
const char *file;
} Overlay_Data;
We'll create instances for each place:
Overlay_Data data_argentina = {"Argentina", NULL};
Overlay_Data data_chile = {"Chile", NULL};
Overlay_Data data_sampa = {"São Paulo", NULL};
Overlay_Data data_rio = {"Rio de Janeiro", NULL};
Overlay_Data data_brasilia = {"Brasília", NULL};
const char *data_dir;
{
return icon;
}
{
char buf[256];
snprintf(buf, sizeof(buf), "%s/images/icon_07.png", data_dir);
return _icon_get(obj, buf);
}
{
char buf[256];
snprintf(buf, sizeof(buf), "%s/images/icon_05.png", data_dir);
return _icon_get(obj, buf);
}
{
char buf[256];
snprintf(buf, sizeof(buf), "%s/images/icon_06.png", data_dir);
return _icon_get(obj, buf);
}
{
char buf[256];
snprintf(buf, sizeof(buf), "%s/images/icon_04.png", data_dir);
return _icon_get(obj, buf);
}
{
elm_object_text_set(label, data->name);
return bx;
}
static void
{
printf("Overlay clicked\n");
}
static void
{
int zoom;
}
static void
{
int zoom;
}
static void
{
}
static void
{
}
_nasty_hack(void *data)
{
}
EAPI_MAIN int
{
char buf[255];
snprintf(buf, sizeof(buf), "%s/images/rock_01.jpg", "sdf");
data_argentina.file = strdup(buf);
snprintf(buf, sizeof(buf), "%s/images/rock_02.jpg", "sdf");
data_chile.file = strdup(buf);
snprintf(buf, sizeof(buf), "%s/images/sky_01.jpg", "sdf");
data_sampa.file = strdup(buf);
snprintf(buf, sizeof(buf), "%s/images/sky_02.jpg", "sdf");
data_rio.file = strdup(buf);
snprintf(buf, sizeof(buf), "%s/images/sky_03.jpg", "sdf");
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:
{
elm_object_text_set(label, data->name);
return bx;
}
See map_example_02.c for full source, whose window should look like this picture:
void elm_map_overlay_data_set(Elm_Map_Overlay *overlay, void *data)
Set a pointer of user data for a overlay.
Definition: elm_map.c:4919
int elm_map_zoom_get(const Eo *obj)
Get the zoom level of the map.
Definition: elm_map.c:4349
Evas_Object * evas_object_image_add(Evas *eo_e)
Creates a new image object on the given Evas e canvas.
Definition: evas_image_legacy.c:25
Evas_Object * elm_map_add(Evas_Object *parent)
Add a new map widget to the given parent Elementary (container) object.
Definition: elm_map.c:4299
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8995
Elm_Map_Overlay * elm_map_overlay_add(Elm_Map *obj, double lon, double lat)
Add a new overlay to the map object.
Definition: elm_map_eo.legacy.c:183
void evas_object_image_filled_set(Evas_Object *eo_obj, Eina_Bool value)
Set whether the image object's fill property should track the object's size.
Definition: evas_image_legacy.c:81
EAPI Eina_List * eina_list_append(Eina_List *list, const void *data)
Appends the given data to the given linked list.
Definition: eina_list.c:584
void evas_object_size_hint_min_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Sets the hints for an object's minimum size.
Definition: evas_object_main.c:2611
EAPI Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:421
const char * elm_app_data_dir_get(void)
Get the application's run time data prefix directory, as set by elm_app_info_set() and the way (envir...
Definition: elm_main.c:586
#define EINA_UNUSED
Definition: eina_types.h:339
Definition: elm_widget_map.h:252
@ ELM_MAP_ZOOM_MODE_AUTO_FILL
Zoom until map fills scroll, ensuring no pixels are left unfilled.
Definition: elm_map_legacy.h:22
Evas * evas_object_evas_get(const Eo *eo_obj)
Get the Evas to which this object belongs to.
Definition: evas_object_main.c:2662
Elm_Map_Overlay * elm_map_overlay_class_add(Elm_Map *obj)
Add a new class overlay to the map object.
Definition: elm_map_eo.legacy.c:105
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
void elm_map_overlay_bubble_content_append(Elm_Map_Overlay *bubble, Evas_Object *content)
Add a content object to the bubble overlay.
Definition: elm_map.c:5477
void elm_map_zoom_set(Eo *obj, int zoom)
Set the zoom level of the map.
Definition: elm_map.c:4343
Elm_Map_Overlay * elm_map_overlay_bubble_add(Elm_Map *obj)
Add a new bubble overlay to the map object.
Definition: elm_map_eo.legacy.c:111
void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:185
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
Evas_Object * elm_icon_add(Evas_Object *parent)
Add a new icon object to the parent.
Definition: elm_icon.c:613
void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
void evas_smart_objects_calculate(Eo *eo_e)
Call user-provided calculate smart functions and unset the flag signalling that the object needs to g...
Definition: evas_main.c:1996
@ ELM_MAP_ZOOM_MODE_MANUAL
Zoom controlled manually by elm_map_zoom_set().
Definition: elm_map_legacy.h:18
void elm_map_zoom_mode_set(Eo *obj, Elm_Map_Zoom_Mode mode)
Set the zoom mode used by the map object.
Definition: elm_map.c:4397
void elm_app_info_set(void *mainfunc, const char *dom, const char *checkfile)
Re-locate the application somewhere else after compilation, if the developer wishes for easier distri...
Definition: elm_main.c:496
EAPI Eina_Bool elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
Set the file that will be used as the image's source.
Definition: efl_ui_image.c:2440
void elm_map_overlay_displayed_zoom_min_set(Elm_Map_Overlay *overlay, int zoom)
Set the minimum zoom from where the overlay is displayed.
Definition: elm_map.c:4964
void elm_map_overlay_bubble_content_clear(Elm_Map_Overlay *bubble)
Clear all contents inside the bubble overlay.
Definition: elm_map.c:5494
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
void elm_map_overlays_show(Eina_List *overlays)
Move and zoom the map to display a list of overlays.
Definition: elm_map.c:5056
Eo Evas
Definition: Evas_Common.h:163
EAPI Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
#define EINA_TRUE
Definition: eina_types.h:539
void elm_map_overlay_bubble_follow(Elm_Map_Overlay *bubble, const Elm_Map_Overlay *parent)
Follow a other overlay.
Definition: elm_map.c:5457
@ ELM_MAP_ZOOM_MODE_AUTO_FIT
Zoom until map fits inside the scroll frame with no pixels outside this area.
Definition: elm_map_legacy.h:20
unsigned char Eina_Bool
Definition: eina_types.h:527
void evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
Set the source file from where an image object must fetch the real image data (it may be an Eet file,...
Definition: evas_image_legacy.c:194
#define ECORE_CALLBACK_CANCEL
Return value to remove a callback.
Definition: Ecore_Common.h:152
Definition: eina_list.h:317
void elm_map_overlay_class_append(Elm_Map_Overlay *klass, Elm_Map_Overlay *overlay)
Add a new overlay member to the class overlay.
Definition: elm_map.c:5324
void elm_map_overlay_icon_set(Elm_Map_Overlay *overlay, Evas_Object *icon)
Set a icon of the overlay.
Definition: elm_map.c:5134
void * elm_map_overlay_data_get(const Elm_Map_Overlay *overlay)
Get the user data stored on a overlay.
Definition: elm_map.c:4930