Map Example - Creation and Zoom

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

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);
elm_map_add
Evas_Object * elm_map_add(Evas_Object *parent)
Widget is broken due to on-line service API breaks.
Definition: elm_map.c:250
evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, map);
evas_object_show(map);
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:297
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:8997
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_size_hint_weight_set
EVAS_API 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

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);
elm_box_add
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
evas_object_show(box);
bt = elm_button_add(win);
elm_object_text_set(bt, "+");
elm_box_pack_end(box, bt);
evas_object_show(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_show(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_show(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_show(bt);
evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map);
elm_box_pack_end
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
elm_button_add
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:459
evas_object_smart_callback_add
EVAS_API 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

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;
elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
zoom = elm_map_zoom_get(data);
elm_map_zoom_set(data, zoom + 1);
}
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
elm_map_zoom_set
void elm_map_zoom_set(Eo *obj, int zoom)
Widget is broken due to on-line service API breaks Widget is broken due to on-line service API breaks...
Definition: elm_map.c:279
elm_map_zoom_get
int elm_map_zoom_get(const Eo *obj)
Widget is broken due to on-line service API breaks Widget is broken due to on-line service API breaks...
Definition: elm_map.c:283
elm_map_zoom_mode_set
void elm_map_zoom_mode_set(Eo *obj, Elm_Map_Zoom_Mode mode)
Widget is broken due to on-line service API breaks Widget is broken due to on-line service API breaks...
Definition: elm_map.c:295
ELM_MAP_ZOOM_MODE_MANUAL
@ ELM_MAP_ZOOM_MODE_MANUAL
Zoom controlled manually by elm_map_zoom_set().
Definition: elm_map_legacy.h:8
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185

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;
elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
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)
{
elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FIT);
}
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:10

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)
{
elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FILL);
}
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:12

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);
elm_map_region_show
void elm_map_region_show(Elm_Map *obj, double lon, double lat)
Widget is broken due to on-line service API breaks.
Definition: elm_map_eo.legacy.c:135

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