2 * Simple Elementary's <b>map widget</b> example, illustrating route and
5 * See stdout/stderr for output. Compile with:
8 * gcc -g map_example_03.c -o map_example_03 `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
14 typedef struct _Example_Data
16 Evas_Object *map, *entry;
18 double start_lon, start_lat, dest_lon, dest_lat;
20 Elm_Map_Overlay *route_ovl;
23 static Example_Data example_data;
26 _route_loaded(void *data, Evas_Object *obj, void *ev)
28 Example_Data *exam_data = data;
30 exam_data->route_ovl = elm_map_overlay_route_add(obj, exam_data->route);
31 elm_map_overlay_color_set(exam_data->route_ovl, 0, 255, 0, 255);
35 _name_loaded(void *data, Evas_Object *obj, void *ev)
37 Example_Data *exam_data = data;
38 Evas_Object *map = obj;
41 elm_map_route_del(exam_data->route);
43 elm_map_name_region_get(exam_data->name, &(exam_data->dest_lon),
44 &(exam_data->dest_lat));
46 exam_data->route = elm_map_route_add(map, ELM_MAP_ROUTE_TYPE_FOOT,
47 ELM_MAP_ROUTE_METHOD_SHORTEST,
48 exam_data->start_lon, exam_data->start_lat,
49 exam_data->dest_lon, exam_data->dest_lat,
54 _bt_route(void *data, Evas_Object *obj, void *ev)
56 Example_Data *exam_data = data;
61 address = (char *)elm_object_text_get(exam_data->entry);
63 exam_data->name = elm_map_name_add(map, address, 0, 0, NULL, NULL);
65 evas_object_smart_callback_add(map, "name,loaded", _name_loaded, data);
66 evas_object_smart_callback_add(map, "route,loaded", _route_loaded, data);
70 _bt_zoom_in(void *data, Evas_Object *obj, void *ev)
73 elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
74 zoom = elm_map_zoom_get(data);
75 elm_map_zoom_set(data, zoom + 1);
79 _bt_zoom_out(void *data, Evas_Object *obj, void *ev)
82 elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
83 zoom = elm_map_zoom_get(data);
84 elm_map_zoom_set(data, zoom - 1);
88 _bt_zoom_fit(void *data, Evas_Object *obj, void *event_info)
90 elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FIT);
94 _bt_zoom_fill(void *data, Evas_Object *obj, void *event_info)
96 elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FILL);
100 _on_done(void *data, Evas_Object *obj, void *event_info)
105 /* FIXME: it shouldn't be required. For unknown reason map won't call
106 * pan_calculate until shot delay time, but then it will take a screenshot
107 * when the map isn't loaded yet (actually it won't be downloaded, because
108 * after the SS it will kill the example). */
110 _nasty_hack(void *data)
112 Evas_Object *o = data;
113 Evas *e = evas_object_evas_get(o);
114 evas_smart_objects_calculate(e);
115 return ECORE_CALLBACK_CANCEL;
119 elm_main(int argc, char **argv)
121 Evas_Object *win, *bg, *map, *box, *bt, *entry;
123 win = elm_win_add(NULL, "map", ELM_WIN_BASIC);
124 elm_win_title_set(win, "Map Route Example");
125 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
127 bg = elm_bg_add(win);
128 elm_win_resize_object_add(win, bg);
129 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 evas_object_show(bg);
132 map = elm_map_add(win);
133 elm_win_resize_object_add(win, map);
134 evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135 evas_object_show(map);
137 box = elm_box_add(win);
138 evas_object_show(box);
140 bt = elm_button_add(win);
141 elm_object_text_set(bt, "+");
142 elm_box_pack_end(box, bt);
143 evas_object_show(bt);
144 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_in, map);
145 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
147 bt = elm_button_add(win);
148 elm_object_text_set(bt, "-");
149 elm_box_pack_end(box, bt);
150 evas_object_show(bt);
151 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_out, map);
152 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
154 bt = elm_button_add(win);
155 elm_object_text_set(bt, "X");
156 elm_box_pack_end(box, bt);
157 evas_object_show(bt);
158 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fit, map);
159 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
161 bt = elm_button_add(win);
162 elm_object_text_set(bt, "#");
163 elm_box_pack_end(box, bt);
164 evas_object_show(bt);
165 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map);
166 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
168 elm_box_horizontal_set(box, EINA_TRUE);
169 elm_win_resize_object_add(win, box);
170 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
171 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0);
173 entry = elm_entry_add(win);
174 elm_entry_scrollable_set(entry, EINA_TRUE);
175 elm_entry_single_line_set(entry, EINA_TRUE);
176 elm_object_text_set(entry, "Jockey Club Brasileiro");
177 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
178 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0);
179 elm_box_pack_end(box, entry);
180 evas_object_show(entry);
182 bt = elm_button_add(win);
183 elm_object_text_set(bt, "Route");
184 elm_box_pack_end(box, bt);
185 evas_object_show(bt);
186 evas_object_smart_callback_add(bt, "clicked", _bt_route, &example_data);
187 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
189 example_data.map = map;
190 example_data.entry = entry;
191 example_data.route = NULL;
192 example_data.start_lon = -43.175;
193 example_data.start_lat = -22.97;
195 elm_map_zoom_set(map, 12);
196 elm_map_region_show(map, example_data.start_lon, example_data.start_lat);
198 evas_object_resize(win, 512, 512);
199 evas_object_show(win);
201 ecore_timer_add(0.5, _nasty_hack, win);