Map Example - Creation and Zoom

This code places an Elementary map widget on a window, to exemplify part of the widget's API.

Let's start adding a map to our window:

map = elm_map_add(win);
evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

It's enough to display a world map inside our window. But usually you'll need to let user interact with the map. We need to place some buttons, so the user could control the map. It's done on the following code. If you don't know about boxes, or buttons, check their examples, Box Example 1 and Button Example 1.

box = elm_box_add(win);
bt = elm_button_add(win);
elm_object_text_set(bt, "+");
elm_box_pack_end(box, bt);
evas_object_smart_callback_add(bt, "clicked", _bt_zoom_in, map);
bt = elm_button_add(win);
elm_object_text_set(bt, "-");
elm_box_pack_end(box, bt);
evas_object_smart_callback_add(bt, "clicked", _bt_zoom_out, map);
bt = elm_button_add(win);
elm_object_text_set(bt, "X");
elm_box_pack_end(box, bt);
evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fit, map);
bt = elm_button_add(win);
elm_object_text_set(bt, "#");
elm_box_pack_end(box, bt);
evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map);

We are adding callback functions that will be called when the user clicks over these buttons. Let's study such functions, starting from the function that will zoom in the map:

static void
_bt_zoom_in(void *data, Evas_Object *obj EINA_UNUSED, void *ev EINA_UNUSED)
{
int zoom;
zoom = elm_map_zoom_get(data);
elm_map_zoom_set(data, zoom + 1);
}

First thing done is assure zoom mode is set to manual. It's the default mode, but the other buttons will change this, so before setting a new zoom value, we need to change the zoom mode.

Then, we get the current zoom value, increment that, and set the new value to the map. If it's bigger than max zoom value allowed, it will remain on the maximum allowed, nothing bad will happen. This way we don't need to check first if it won't be bigger than max.

Zoom out function is basically the same thing, but zoom will be decremented instead of incremented:

static void
_bt_zoom_out(void *data, Evas_Object *obj EINA_UNUSED, void *ev EINA_UNUSED)
{
int zoom;
zoom = elm_map_zoom_get(data);
elm_map_zoom_set(data, zoom - 1);
}

The "X" button, when pressed, will call a function that will zoom the map until it fits inside the scroll frame with no pixels outside this area:

static void
_bt_zoom_fit(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
}

And the "#" button, will call a function that will zoom until map fills scroll, ensuring no pixels are left unfilled:

static void
_bt_zoom_fill(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
}

But we can also set map to show something different from default world map, changing the zoom level and region shown. Let's pick a wonderful city coordinates, one placed at 43 20 S, 22 90 W . Since map uses double variables to represent latitude and longitude, to represent north or east, we should represent it as positive values, and south or west as negative. Also, the value will be represented as degree.min. So, for example, our longitude 43 20 S will be represented by the value -43.20 . A zoom set to 12 should be enough to show a city.

elm_map_region_show(map, -43.2, -22.9);

See map_example_01.c for full source, whose window should look like this picture:

elm_box_add
EAPI Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:366
EINA_UNUSED
#define EINA_UNUSED
Definition: eina_types.h:321
elm_button_add
EAPI Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:477
EVAS_HINT_EXPAND
#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:292
evas_object_smart_callback_add
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:980
Evas_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:180
elm_map_add
Evas_Object * elm_map_add(Evas_Object *parent)
Add a new map widget to the given parent Elementary (container) object.
Definition: elm_map.c:4300
ELM_MAP_ZOOM_MODE_AUTO_FILL
@ ELM_MAP_ZOOM_MODE_AUTO_FILL
Zoom until map fills scroll, ensuring no pixels are left unfilled.
Definition: elm_map_legacy.h:22
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
elm_map_zoom_set
void elm_map_zoom_set(Eo *obj, int zoom)
Set the zoom level of the map.
Definition: elm_map.c:4344
elm_win_resize_object_add
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:8899
ELM_MAP_ZOOM_MODE_MANUAL
@ ELM_MAP_ZOOM_MODE_MANUAL
Zoom controlled manually by elm_map_zoom_set().
Definition: elm_map_legacy.h:18
ELM_MAP_ZOOM_MODE_AUTO_FIT
@ 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
elm_map_zoom_get
int elm_map_zoom_get(const Eo *obj)
Get the zoom level of the map.
Definition: elm_map.c:4350
elm_map_zoom_mode_set
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:4398