3 * Simple Elementary's <b>map widget</b> example, illustrating markers
5 * Simple Elementary's <b>map widget</b> example, illustrating overlays
6 >>>>>>> remotes/origin/upstream
9 * See stdout/stderr for output. Compile with:
12 * gcc -g `pkg-config --cflags --libs elementary` map_example_02.c -o map_example_02
16 #include <Elementary.h>
18 # include "elementary_config.h"
24 typedef struct _Marker_Data
30 Marker_Data data_argentina = {"Argentina",
31 PACKAGE_DATA_DIR"/images/rock_01.jpg"};
32 Marker_Data data_chile = {"Chile",
33 PACKAGE_DATA_DIR"/images/rock_02.jpg"};
34 Marker_Data data_sampa = {"São Paulo",
35 PACKAGE_DATA_DIR"/images/sky_01.jpg"};
36 Marker_Data data_rio = {"Rio de Janeiro",
37 PACKAGE_DATA_DIR"/images/sky_02.jpg"};
38 Marker_Data data_brasilia = {"Brasília",
39 PACKAGE_DATA_DIR"/images/sky_03.jpg"};
42 _marker_get(Evas_Object *obj, Elm_Map_Marker *marker __UNUSED__, void *data)
44 Evas_Object *bx, *im, *lbl;
45 Marker_Data *md = data;
47 bx = elm_box_add(obj);
50 im = elm_image_add(obj);
51 elm_image_file_set(im, md->file, NULL);
52 evas_object_size_hint_min_set(im, 64, 64);
54 elm_box_pack_end(bx, im);
56 lbl = elm_label_add(obj);
57 elm_object_text_set(lbl, md->name);
58 evas_object_show(lbl);
59 elm_box_pack_end(bx, lbl);
65 _marker_city_content_get(Evas_Object *obj, Elm_Map_Marker *marker __UNUSED__, void *data __UNUSED__)
67 Evas_Object *icon = elm_icon_add(obj);
68 elm_icon_file_set(icon, PACKAGE_DATA_DIR"/images/icon_07.png", NULL);
69 evas_object_show(icon);
75 _group_city_content_get(Evas_Object *obj, void *data __UNUSED__)
77 Evas_Object *icon = elm_icon_add(obj);
78 elm_icon_file_set(icon, PACKAGE_DATA_DIR"/images/icon_05.png", NULL);
79 evas_object_show(icon);
84 _marker_country_content_get(Evas_Object *obj, Elm_Map_Marker *marker __UNUSED__, void *data __UNUSED__)
86 Evas_Object *icon = elm_icon_add(obj);
87 elm_icon_file_set(icon, PACKAGE_DATA_DIR"/images/icon_06.png", NULL);
88 evas_object_show(icon);
93 _group_country_content_get(Evas_Object *obj, void *data __UNUSED__)
95 Evas_Object *icon = elm_icon_add(obj);
96 elm_icon_file_set(icon, PACKAGE_DATA_DIR"/images/icon_04.png", NULL);
97 evas_object_show(icon);
102 _map_downloaded(void *data __UNUSED__, Evas_Object *obj, void *ev __UNUSED__)
104 elm_map_zoom_set(obj, 3);
105 evas_object_smart_callback_del(obj, "downloaded", _map_downloaded);
107 typedef struct _Overlay_Data
113 Overlay_Data data_argentina = {"Argentina",
114 PACKAGE_DATA_DIR"/images/rock_01.jpg"};
115 Overlay_Data data_chile = {"Chile",
116 PACKAGE_DATA_DIR"/images/rock_02.jpg"};
117 Overlay_Data data_sampa = {"São Paulo",
118 PACKAGE_DATA_DIR"/images/sky_01.jpg"};
119 Overlay_Data data_rio = {"Rio de Janeiro",
120 PACKAGE_DATA_DIR"/images/sky_02.jpg"};
121 Overlay_Data data_brasilia = {"Brasília",
122 PACKAGE_DATA_DIR"/images/sky_03.jpg"};
124 static Elm_Map_Overlay *bubble;
127 _icon_get(Evas_Object *obj, const char *file)
129 Evas_Object *icon = elm_icon_add(obj);
130 elm_icon_file_set(icon, file, NULL);
131 evas_object_show(icon);
136 _city_icon_get(Evas_Object *obj)
138 return _icon_get(obj, PACKAGE_DATA_DIR"/images/icon_07.png");
142 _clas_city_icon_get(Evas_Object *obj)
144 return _icon_get(obj, PACKAGE_DATA_DIR"/images/icon_05.png");
148 _country_icon_get(Evas_Object *obj)
150 return _icon_get(obj, PACKAGE_DATA_DIR"/images/icon_06.png");
154 _clas_country_icon_get(Evas_Object *obj)
156 return _icon_get(obj, PACKAGE_DATA_DIR"/images/icon_04.png");
160 _box_get(Evas_Object *obj, Overlay_Data *data)
162 Evas_Object *bx, *img, *label;
163 bx = elm_box_add(obj);
164 evas_object_show(bx);
166 img = evas_object_image_add(evas_object_evas_get(obj));
167 evas_object_image_file_set(img, data->file, NULL);
168 evas_object_image_filled_set(img, EINA_TRUE);
169 evas_object_size_hint_min_set(img, 64, 64);
170 evas_object_show(img);
171 elm_box_pack_end(bx, img);
173 label = elm_label_add(obj);
174 elm_object_text_set(label, data->name);
175 evas_object_show(label);
176 elm_box_pack_end(bx, label);
181 _overlay_cb(void *data __UNUSED__, Evas_Object *map, void *ev)
183 printf("Overlay clicked\n");
184 Elm_Map_Overlay *overlay = ev;
187 // prevent duplication
188 if (!bubble) bubble = elm_map_overlay_bubble_add(map);
190 elm_map_overlay_bubble_follow(bubble, overlay);
191 elm_map_overlay_bubble_content_clear(bubble);
192 bx = _box_get(map, elm_map_overlay_data_get(overlay));
193 elm_map_overlay_bubble_content_append(bubble, bx);
194 >>>>>>> remotes/origin/upstream
198 _bt_zoom_in(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
200 Evas_Object *map = data;
203 elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_MANUAL);
204 zoom = elm_map_zoom_get(map);
205 elm_map_zoom_set(map, zoom + 1);
209 _bt_zoom_out(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
211 Evas_Object *map = data;
214 elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_MANUAL);
215 zoom = elm_map_zoom_get(map);
216 elm_map_zoom_set(map, zoom - 1);
220 _bt_zoom_fit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
222 Evas_Object *map = data;
223 elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_AUTO_FIT);
227 _bt_zoom_fill(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
229 Evas_Object *map = data;
230 elm_map_zoom_mode_set(map, ELM_MAP_ZOOM_MODE_AUTO_FILL);
234 _on_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
239 /* FIXME: it shouldn't be required. For unknown reason map won't call
240 * pan_calculate until shot delay time, but then it will take a screenshot
241 * when the map isn't loaded yet (actually it won't be downloaded, because
242 * after the SS it will kill the example). */
244 _nasty_hack(void *data)
246 Evas_Object *o = data;
247 Evas *e = evas_object_evas_get(o);
248 evas_smart_objects_calculate(e);
249 return ECORE_CALLBACK_CANCEL;
253 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
255 Evas_Object *win, *bg, *map, *box, *bt;
257 static Elm_Map_Marker_Class *mc_city, *mc_country;
258 static Elm_Map_Group_Class *gc_city, *gc_country;
259 Eina_List *markers = NULL;
262 win = elm_win_add(NULL, "map", ELM_WIN_BASIC);
263 elm_win_title_set(win, "Map Markers Example");
265 Eina_List *ovls = NULL;
266 Elm_Map_Overlay *ovl, *city_clas, *country_clas;
268 win = elm_win_add(NULL, "map", ELM_WIN_BASIC);
269 elm_win_title_set(win, "Map Overlay Example");
270 >>>>>>> remotes/origin/upstream
271 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
273 bg = elm_bg_add(win);
274 elm_win_resize_object_add(win, bg);
275 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
276 evas_object_show(bg);
278 map = elm_map_add(win);
279 elm_win_resize_object_add(win, map);
280 evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
281 evas_object_show(map);
283 box = elm_box_add(win);
284 evas_object_show(box);
286 bt = elm_button_add(win);
287 elm_object_text_set(bt, "+");
288 elm_box_pack_end(box, bt);
289 evas_object_show(bt);
290 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_in, map);
292 bt = elm_button_add(win);
293 elm_object_text_set(bt, "-");
294 elm_box_pack_end(box, bt);
295 evas_object_show(bt);
296 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_out, map);
298 bt = elm_button_add(win);
299 elm_object_text_set(bt, "X");
300 elm_box_pack_end(box, bt);
301 evas_object_show(bt);
302 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fit, map);
304 bt = elm_button_add(win);
305 elm_object_text_set(bt, "#");
306 elm_box_pack_end(box, bt);
307 evas_object_show(bt);
308 evas_object_smart_callback_add(bt, "clicked", _bt_zoom_fill, map);
311 mc_city = elm_map_marker_class_new(map);
312 elm_map_marker_class_get_cb_set(mc_city, _marker_get);
313 elm_map_marker_class_icon_cb_set(mc_city, _marker_city_content_get);
314 elm_map_marker_class_style_set(mc_city, "radio");
316 gc_city = elm_map_group_class_new(map);
317 elm_map_group_class_style_set(gc_city, "radio2");
318 elm_map_group_class_icon_cb_set(gc_city, _group_city_content_get);
319 elm_map_group_class_zoom_displayed_set(gc_city, 3);
321 mc_country = elm_map_marker_class_new(map);
322 elm_map_marker_class_get_cb_set(mc_country, _marker_get);
323 elm_map_marker_class_icon_cb_set(mc_country, _marker_country_content_get);
324 elm_map_marker_class_style_set(mc_country, "empty");
326 gc_country = elm_map_group_class_new(map);
327 elm_map_group_class_style_set(gc_country, "empty");
328 elm_map_group_class_icon_cb_set(gc_country, _group_country_content_get);
329 elm_map_group_class_zoom_displayed_set(gc_country, 1);
331 m = elm_map_marker_add(map, -43.2, -22.9, mc_city, gc_city, &data_rio);
332 markers = eina_list_append(markers, m);
333 m = elm_map_marker_add(map, -46.63, -23.55, mc_city, gc_city, &data_sampa);
334 markers = eina_list_append(markers, m);
335 m = elm_map_marker_add(map, -47.88, -15.78, mc_city, gc_city,
337 markers = eina_list_append(markers, m);
339 m = elm_map_marker_add(map, -65.23, -35.1, mc_country, gc_country,
341 markers = eina_list_append(markers, m);
342 m = elm_map_marker_add(map, -71.3, -31.75, mc_country, gc_country,
344 markers = eina_list_append(markers, m);
346 elm_map_markers_list_show(markers);
347 evas_object_smart_callback_add(map, "downloaded", _map_downloaded, NULL);
349 evas_object_smart_callback_add(map, "overlay,clicked", _overlay_cb, NULL);
351 city_clas = elm_map_overlay_class_add(map);
352 elm_map_overlay_displayed_zoom_min_set(city_clas, 3);
353 elm_map_overlay_icon_set(city_clas, _clas_city_icon_get(map));
355 country_clas = elm_map_overlay_class_add(map);
356 elm_map_overlay_displayed_zoom_min_set(country_clas, 1);
357 elm_map_overlay_icon_set(country_clas, _clas_country_icon_get(map));
359 ovl = elm_map_overlay_add(map, -43.2, -22.9);
360 elm_map_overlay_icon_set(ovl, _city_icon_get(map));
361 elm_map_overlay_data_set(ovl, &data_rio);
362 elm_map_overlay_class_append(city_clas, ovl);
363 ovls = eina_list_append(ovls, ovl);
365 ovl = elm_map_overlay_add(map, -46.63, -23.55);
366 elm_map_overlay_icon_set(ovl, _city_icon_get(map));
367 elm_map_overlay_data_set(ovl, &data_sampa);
368 elm_map_overlay_class_append(city_clas, ovl);
369 ovls = eina_list_append(ovls, ovl);
371 ovl = elm_map_overlay_add(map, -47.88, -15.78);
372 elm_map_overlay_icon_set(ovl, _city_icon_get(map));
373 elm_map_overlay_data_set(ovl, &data_brasilia);
374 elm_map_overlay_class_append(city_clas, ovl);
375 ovls = eina_list_append(ovls, ovl);
377 ovl = elm_map_overlay_add(map, -65.23, -35.1);
378 elm_map_overlay_icon_set(ovl, _country_icon_get(map));
379 elm_map_overlay_data_set(ovl, &data_argentina);
380 elm_map_overlay_class_append(country_clas, ovl);
381 ovls = eina_list_append(ovls, ovl);
383 ovl = elm_map_overlay_add(map, -71.3, -31.75);
384 elm_map_overlay_icon_set(ovl, _country_icon_get(map));
385 elm_map_overlay_data_set(ovl, &data_chile);
386 elm_map_overlay_class_append(country_clas, ovl);
387 ovls = eina_list_append(ovls, ovl);
389 elm_map_overlays_show(ovls);
390 >>>>>>> remotes/origin/upstream
392 evas_object_resize(win, 512, 512);
393 evas_object_show(win);
395 ecore_timer_add(1, _nasty_hack, win);