1 #include <Elementary.h>
8 * This is a widget specifically for displaying the free map OpenStreetMap.
10 * Signals that you can add callbacks for are:
12 * clicked - This is called when a user has clicked the map without dragging
15 * press - This is called when a user has pressed down on the map.
17 * longpressed - This is called when a user has pressed down on the map for
18 * a long time without dragging around.
20 * clicked,double - This is called when a user has double-clicked the photo.
22 * load,detail - Map detailed data load begins.
24 * loading,detail - Map detailed data loading.
26 * loaded,detail - This is called when all parts of the map are loaded.
28 * zoom,start - Zoom animation started.
30 * zoom,stop - Zoom animation stopped.
32 * zoom,change - Zoom changed when using an auto zoom mode.
34 * scroll - the content has been scrolled (moved)
36 * scroll,anim,start - scrolling animation has started
38 * scroll,anim,stop - scrolling animation has stopped
40 * scroll,drag,start - dragging the contents around has started
42 * scroll,drag,stop - dragging the contents around has stopped
48 typedef struct _Widget_Data Widget_Data;
49 typedef struct _Pan Pan;
50 typedef struct _Grid Grid;
51 typedef struct _Grid_Item Grid_Item;
52 typedef struct _Marker_Group Marker_Group;
53 typedef struct _Mod_Api Mod_Api;
55 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
56 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
57 #define DEST_FILE_PATH "%s%d.png"
60 // Currently the size of a tile must be 256*256
61 // and the size of the map must be pow(2.0, z)*tile_size
62 typedef struct _Map_Sources_Tab
64 Elm_Map_Sources source;
68 ElmMapSourceURLFunc url_cb;
72 #define TOUCH_HOLD_RANGE 40
73 //Zemm min is supposed to be 0
74 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
75 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
76 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
77 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
78 static char *_module_url_cb(Evas_Object *obj, int x, int y, int zoom);
79 static char * _custom1_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
80 static char * _custom2_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
81 static char * _custom3_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
82 static char * _custom4_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
83 static char * _custom5_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
84 static char * _custom6_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
86 static Map_Sources_Tab map_sources_tab[] =
88 {ELM_MAP_SOURCE_MAPNIK, "Mapnik", 0, 18, _mapnik_url_cb},
89 {ELM_MAP_SOURCE_OSMARENDER, "Osmarender", 0, 17, _osmarender_url_cb},
90 {ELM_MAP_SOURCE_CYCLEMAP, "Cycle Map", 0, 17, _cyclemap_url_cb},
91 {ELM_MAP_SOURCE_MAPLINT, "Maplint", 12, 16, _maplint_url_cb},
92 {ELM_MAP_SOURCE_CUSTOM_1, "Custom 1", 0, 18, _custom1_url_cb},
93 {ELM_MAP_SOURCE_CUSTOM_2, "Custom 2", 0, 18, _custom2_url_cb},
94 {ELM_MAP_SOURCE_CUSTOM_3, "Custom 3", 0, 18, _custom3_url_cb},
95 {ELM_MAP_SOURCE_CUSTOM_4, "Custom 4", 0, 18, _custom4_url_cb},
96 {ELM_MAP_SOURCE_CUSTOM_5, "Custom 5", 0, 18, _custom5_url_cb},
97 {ELM_MAP_SOURCE_CUSTOM_6, "Custom 6", 0, 18, _custom6_url_cb},
98 {ELM_MAP_SOURCE_MODULE, "Module", 0, 18, _module_url_cb}
101 struct _Elm_Map_Marker_Class
106 struct _Elm_Map_Marker_Class_Func {
107 ElmMapMarkerGetFunc get;
108 ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
109 ElmMapMarkerIconGetFunc icon_get;
112 struct { //this part is private, do not modify these values
114 Evas_Coord edje_w, edje_h;
118 struct _Elm_Map_Marker
121 Elm_Map_Marker_Class *clas;
122 Elm_Map_Group_Class *clas_group;
123 double longitude, latitude;
126 Evas_Coord x[ZOOM_MAX+1], y[ZOOM_MAX+1];
129 Marker_Group *groups[ZOOM_MAX+1];
131 Evas_Object *content;
134 struct _Elm_Map_Group_Class
138 int zoom_displayed; // display the group if the zoom is >= to zoom_display
139 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
143 ElmMapGroupIconGetFunc icon_get;
146 struct { //this part is private, do not modify these values
148 Evas_Coord edje_w, edje_h;
149 Evas_Coord edje_max_w, edje_max_h;
151 Eina_List *objs_used;
152 Eina_List *objs_notused;
159 Eina_Matrixsparse_Cell *cell;
160 Elm_Map_Group_Class *clas;
163 long long sum_x, sum_y;
167 Evas_Object *obj, *bubble, *sc, *bx, *rect;
169 Eina_Bool bringin : 1;
170 Eina_Bool update_nbelems : 1;
171 Eina_Bool update_resize : 1;
172 Eina_Bool update_raise : 1;
173 Eina_Bool delete_object : 1;
186 Eina_Bool download : 1;
188 Ecore_File_Download_Job *job;
194 int tsize; // size of tile (tsize x tsize pixels)
195 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
196 int iw, ih; // size of image in pixels
197 int w, h; // size of grid image in pixels (represented by grid)
198 int gw, gh; // size of grid in tiles
199 Eina_Matrixsparse *grid;
206 Evas_Object *pan_smart;
208 Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
210 Evas_Coord pan_x, pan_y, minw, minh;
214 Elm_Map_Zoom_Mode mode;
217 Ecore_Timer *scr_timer;
218 Ecore_Timer *long_timer;
219 Ecore_Animator *zoom_animator;
220 double t_start, t_end;
230 Evas_Coord x, y ,w ,h;
236 Eina_Bool resized : 1;
237 Eina_Bool longpressed : 1;
238 Eina_Bool on_hold : 1;
239 Eina_Bool paused : 1;
240 Eina_Bool paused_markers : 1;
241 Eina_Bool pinch_zoom : 1;
248 Ecore_Job *markers_place_job;
249 Eina_Matrixsparse *markers[ZOOM_MAX+1];
250 Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
251 Evas_Coord markers_max_num;
252 int marker_max_w, marker_max_h;
254 Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
256 Eina_List *groups_clas; // list of Elm_Map_Group_Class*
257 Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
259 Elm_Map_Sources source;
267 Eina_Bool (*obj_hook) (Evas_Object *obj);
268 Eina_Bool (*obj_unhook) (Evas_Object *obj);
269 char * (*obj_url_request) (Evas_Object *obj, int x, int y, int zoom);
270 Eina_Bool (*obj_convert_coord_into_geo) (const Evas_Object *obj, int zoom, int x, int y, int size, double *lon, double *lat);
271 Eina_Bool (*obj_convert_geo_into_coord) (const Evas_Object *obj, int zoom, double lon, double lat, int size, int *x, int *y);
275 Evas_Object_Smart_Clipped_Data __clipped_data;
287 Evas_Coord x, y, w, h;
290 Ecore_Timer *hold_timer;
294 static int dis_old = 0;
295 static Eina_List *s_event_list;
297 static const char *widtype = NULL;
299 static const char SIG_CHANGED[] = "changed";
300 static const char SIG_CLICKED[] = "clicked";
301 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
302 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
303 static const char SIG_LOADING_DETAIL[] = "loading,detail";
304 static const char SIG_LOAD_DETAIL[] = "load,detail";
305 static const char SIG_LONGPRESSED[] = "longpressed";
306 static const char SIG_PRESS[] = "press";
307 static const char SIG_SCROLL[] = "scroll";
308 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
309 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
310 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
311 static const char SIG_ZOOM_START[] = "zoom,start";
312 static const char SIG_ZOOM_STOP[] = "zoom,stop";
313 static const Evas_Smart_Cb_Description _signals[] = {
316 {SIG_CLICKED_DOUBLE, ""},
317 {SIG_LOADED_DETAIL, ""},
318 {SIG_LOADING_DETAIL, ""},
319 {SIG_LOAD_DETAIL, ""},
320 {SIG_LONGPRESSED, ""},
323 {SIG_SCROLL_DRAG_START, ""},
324 {SIG_SCROLL_DRAG_STOP, ""},
325 {SIG_ZOOM_CHANGE, ""},
326 {SIG_ZOOM_START, ""},
331 static void _pan_calculate(Evas_Object *obj);
333 static Eina_Bool _hold_timer_cb(void *data);
334 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
335 static void _del_hook(Evas_Object *obj);
336 static void _theme_hook(Evas_Object *obj);
337 static void _on_focus_hook(void *data, Evas_Object *obj);
338 static void _sizing_eval(Evas_Object *obj);
339 static void _calc_job(void *data);
340 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
341 Evas_Callback_Type type, void *event_info);
342 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
343 static void grid_clear(Evas_Object *obj, Grid *g);
344 static Grid *grid_create(Evas_Object *obj);
345 static void grid_load(Evas_Object *obj, Grid *g);
348 static void _group_object_create(Marker_Group *group);
349 static void _group_object_free(Marker_Group *group);
350 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
351 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
352 static void _group_bubble_create(Marker_Group *group);
353 static void _group_bubble_free(Marker_Group *group);
354 static void _group_bubble_place(Marker_Group *group);
356 static int _group_bubble_content_update(Marker_Group *group);
357 static void _group_bubble_content_free(Marker_Group *group);
358 static void marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
359 static void _bubble_sc_hits_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
361 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
362 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
363 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
365 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
366 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
367 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
370 get_multi_device(void)
373 struct event_t *ev = NULL;
375 EINA_LIST_FOREACH(s_event_list, l, ev)
377 if (ev->device) return ev->device;
384 get_distance(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
391 dis = (int)sqrt(dx * dx + dy * dy);
395 static struct event_t*
396 get_event_object(int device)
399 struct event_t *ev = NULL;
401 EINA_LIST_FOREACH(s_event_list, l, ev)
403 if (ev->device == device) break;
409 static struct event_t *
410 create_event_object(Evas_Object *object, int device)
414 ev = calloc(1, sizeof(struct event_t));
415 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
420 evas_object_geometry_get(object, &ev->x, &ev->y, &ev->w, &ev->h);
422 s_event_list = eina_list_append(s_event_list, ev);
428 destroy_event_object(struct event_t *ev)
430 EINA_SAFETY_ON_NULL_RETURN(ev);
434 s_event_list = eina_list_remove(s_event_list, ev);
438 ecore_timer_del(ev->hold_timer);
439 ev->hold_timer = NULL;
445 module(Evas_Object *obj __UNUSED__)
447 static Elm_Module *m = NULL;
449 if (!(m = _elm_module_find_as("map/api"))) return NULL;
451 m->api = malloc(sizeof(Mod_Api));
452 if (!m->api) return NULL;
453 ((Mod_Api *)(m->api) )->obj_hook =
454 _elm_module_symbol_get(m, "obj_hook");
455 ((Mod_Api *)(m->api) )->obj_unhook =
456 _elm_module_symbol_get(m, "obj_unhook");
457 ((Mod_Api *)(m->api) )->obj_url_request =
458 _elm_module_symbol_get(m, "obj_url_request");
459 ((Mod_Api *)(m->api) )->obj_convert_coord_into_geo =
460 _elm_module_symbol_get(m, "obj_convert_coord_into_geo");
461 ((Mod_Api *)(m->api) )->obj_convert_geo_into_coord =
462 _elm_module_symbol_get(m, "obj_convert_geo_into_coord");
468 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
470 Widget_Data *wd = elm_widget_data_get(obj);
471 Evas_Coord ax, ay, gw, gh, hh, ww;
473 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
480 if ((ww == gw) && (hh == gh)) return;
482 if (ow > gw) ax = (ow - gw) / 2;
483 if (oh > gh) ay = (oh - gh) / 2;
484 evas_object_move(wd->rect,
487 evas_object_resize(wd->rect, gw, gh);
491 wd->show.show = EINA_FALSE;
492 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
497 marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
499 Widget_Data *wd = elm_widget_data_get(obj);
500 Evas_Coord ax, ay, gw, gh, tx, ty;
501 Eina_List *l, *markers;
502 Eina_Matrixsparse_Cell *cell;
507 int g_xx, g_yy, g_hh, g_ww;
510 if (g != eina_list_data_get(wd->grids)) return;
516 if (ow > gw) ax = (ow - gw) / 2;
517 if (oh > gh) ay = (oh - gh) / 2;
519 if (wd->zoom != wd->marker_zoom)
521 EINA_LIST_FREE(wd->cells_displayed, cell)
523 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
525 if (group->obj) _group_object_free(group);
529 wd->marker_zoom = wd->zoom;
531 if ((wd->paused_markers)
532 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
535 g_xx = wd->pan_x / wd->tsize;
536 if (g_xx < 0) g_xx = 0;
537 g_yy = wd->pan_y / wd->tsize;
538 if (g_yy < 0) g_yy = 0;
539 g_ww = ow / wd->tsize + 1;
540 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
541 g_hh = oh / wd->tsize + 1;
542 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
544 //hide groups no more displayed
545 EINA_LIST_FREE(wd->cells_displayed, cell)
547 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
548 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
550 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
552 if (group->obj) _group_object_free(group);
557 for (y = g_yy; y <= g_yy + g_hh; y++)
559 for (x = g_xx; x <= g_xx + g_ww; x++)
561 if (!wd->markers[wd->zoom]) continue;
562 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
564 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
565 markers = eina_matrixsparse_cell_data_get(cell);
566 EINA_LIST_FOREACH(markers, l, group)
568 if (!group->markers) continue;
569 if (group->clas->zoom_displayed > wd->zoom) continue;
576 if (eina_list_count(group->markers) == 1)
578 Elm_Map_Marker *m = eina_list_data_get(group->markers);
579 ww = m->clas->priv.edje_w;
580 hh = m->clas->priv.edje_h;
586 if ((gw != g->w) && (g->w > 0))
589 xx = ((long long )gw * xx) / g->w;
590 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
592 if ((gh != g->h) && (g->h > 0))
595 yy = ((long long)gh * yy) / g->h;
596 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
599 if ((!group->clas->hide)
600 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
601 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
603 if (!group->obj) _group_object_create(group);
605 if (group->update_nbelems)
607 group->update_nbelems = EINA_FALSE;
608 if (eina_list_count(group->markers) > 1)
610 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
611 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
614 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
616 evas_object_move(group->obj,
617 xx - px + ax + ox - ww/2,
618 yy - py + ay + oy - hh/2);
619 if ((!wd->paused_markers) || (group->update_resize))
621 group->update_resize = EINA_FALSE;
622 evas_object_resize(group->obj, ww, hh);
624 if (group->update_raise)
626 group->update_raise = EINA_FALSE;
627 evas_object_raise(group->obj);
628 evas_object_show(group->obj);
630 if (group->bubble) _group_bubble_place(group);
634 _group_object_free(group);
642 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
644 Widget_Data *wd = elm_widget_data_get(obj);
645 Evas_Coord ax, ay, gw, gh, tx, ty;
654 if (ow > gw) ax = (ow - gw) / 2;
655 if (oh > gh) ay = (oh - gh) / 2;
657 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
658 Eina_Matrixsparse_Cell *cell;
660 EINA_ITERATOR_FOREACH(it, cell)
662 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
668 if ((gw != g->w) && (g->w > 0))
671 xx = ((long long )gw * xx) / g->w;
672 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
674 if ((gh != g->h) && (g->h > 0))
677 yy = ((long long)gh * yy) / g->h;
678 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
680 evas_object_move(gi->img,
684 evas_object_resize(gi->img, ww, hh);
686 /*evas_object_move(gi->txt,
690 evas_object_resize(gi->txt, ww, hh);
693 eina_iterator_free(it);
697 grid_clear(Evas_Object *obj, Grid *g)
699 Widget_Data *wd = elm_widget_data_get(obj);
703 if (!g->grid) return;
705 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
706 Eina_Matrixsparse_Cell *cell;
708 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
709 ecore_file_recursive_rm(buf);
711 EINA_ITERATOR_FOREACH(it, cell)
713 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
714 evas_object_del(gi->img);
715 //evas_object_del(gi->txt);
719 gi->want = EINA_FALSE;
721 if (!wd->preload_num)
723 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
724 "elm,state,busy,stop", "elm");
725 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
731 DBG("DOWNLOAD abort %s", gi->file);
732 ecore_file_download_abort(gi->job);
733 ecore_file_remove(gi->file);
738 eina_stringshare_del(gi->file);
742 eina_matrixsparse_free(g->grid);
743 eina_iterator_free(it);
750 _tile_update(Grid_Item *gi)
752 gi->want = EINA_FALSE;
753 gi->download = EINA_FALSE;
754 evas_object_image_file_set(gi->img, gi->file, NULL);
755 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
756 ecore_file_remove(gi->file);
758 evas_object_show(gi->img);
760 //evas_object_text_text_set(gi->txt, gi->file);
761 //evas_object_show(gi->txt);
763 gi->have = EINA_TRUE;
764 gi->wd->preload_num--;
765 if (!gi->wd->preload_num)
767 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
768 "elm,state,busy,stop", "elm");
769 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
775 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
777 Grid_Item *gi = data;
779 gi->download = EINA_FALSE;
782 DBG("DOWNLOAD done %s", gi->file);
783 if ((gi->want) && (!status)) _tile_update(gi);
787 DBG("Download failed %s (%d) ", gi->file, status);
788 ecore_file_remove(gi->file);
791 gi->wd->finish_num++;
795 _tile_downloading(void *data, const char *file, long int dltotal, long int dlnow, long int ultotal, long int ulnow)
797 Grid_Item *gi = data;
798 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADING_DETAIL, NULL);
803 grid_create(Evas_Object *obj)
805 Widget_Data *wd = elm_widget_data_get(obj);
808 g = calloc(1, sizeof(Grid));
811 g->tsize = wd->tsize;
814 if (g->zoom > map_sources_tab[wd->source].zoom_max) return NULL;
815 if (g->zoom < map_sources_tab[wd->source].zoom_min) return NULL;
817 int size = pow(2.0, wd->zoom);
821 g->w = g->tsize * g->gw;
822 g->h = g->tsize * g->gh;
824 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
830 grid_load(Evas_Object *obj, Grid *g)
832 Widget_Data *wd = elm_widget_data_get(obj);
835 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
837 Eina_Matrixsparse_Cell *cell;
841 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
842 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
847 if ((gw <= 0) || (gh <= 0)) return;
850 if ((gw != g->w) && (g->w > 0))
851 size = ((long long)gw * size) / g->w;
852 if (size < (g->tsize / 2)) return; // else we will load to much tiles
854 it = eina_matrixsparse_iterator_new(g->grid);
856 EINA_ITERATOR_FOREACH(it, cell)
858 gi = eina_matrixsparse_cell_data_get(cell);
865 if ((gw != g->w) && (g->w > 0))
868 xx = ((long long )gw * xx) / g->w;
869 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
871 if ((gh != g->h) && (g->h > 0))
874 yy = ((long long)gh * yy) / g->h;
875 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
878 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
886 if (!wd->preload_num)
888 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
889 "elm,state,busy,stop", "elm");
890 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
893 evas_object_hide(gi->img);
894 //evas_object_hide(gi->txt);
895 evas_object_image_file_set(gi->img, NULL, NULL);
896 gi->want = EINA_FALSE;
897 gi->have = EINA_FALSE;
901 DBG("DOWNLOAD abort %s", gi->file);
902 ecore_file_download_abort(gi->job);
903 ecore_file_remove(gi->file);
907 gi->download = EINA_FALSE;
911 evas_object_hide(gi->img);
912 //evas_object_hide(gi->txt);
913 evas_object_image_preload(gi->img, 1);
914 evas_object_image_file_set(gi->img, NULL, NULL);
915 gi->have = EINA_FALSE;
916 gi->want = EINA_FALSE;
920 eina_iterator_free(it);
922 xx = wd->pan_x / size;
925 yy = wd->pan_y / size;
929 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
932 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
934 for (y = yy; y <= yy + hh; y++)
936 for (x = xx; x <= xx + ww; x++)
938 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
940 if ((!gi) && (g != eina_list_data_get(wd->grids)))
945 gi = calloc(1, sizeof(Grid_Item));
946 gi->src.x = x * g->tsize;
947 gi->src.y = y * g->tsize;
948 gi->src.w = g->tsize;
949 gi->src.h = g->tsize;
951 gi->out.x = gi->src.x;
952 gi->out.y = gi->src.y;
953 gi->out.w = gi->src.w;
954 gi->out.h = gi->src.h;
958 gi->img = evas_object_image_add(evas_object_evas_get(obj));
959 evas_object_image_scale_hint_set
960 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
961 evas_object_image_filled_set(gi->img, 1);
963 evas_object_smart_member_add(gi->img, wd->pan_smart);
964 elm_widget_sub_object_add(obj, gi->img);
965 evas_object_pass_events_set(gi->img, EINA_TRUE);
966 evas_object_stack_below(gi->img, wd->sep_maps_markers);
968 /*gi->txt = evas_object_text_add(evas_object_evas_get(obj));
969 evas_object_text_font_set(gi->txt, "Vera", 12);
970 evas_object_color_set(gi->txt, 100, 100, 100, 255);
971 evas_object_smart_member_add(gi->txt,
973 elm_widget_sub_object_add(obj, gi->txt);
974 evas_object_pass_events_set(gi->txt, EINA_TRUE);
976 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
979 if ((!gi->have) && (!gi->download))
981 char buf[PATH_MAX], buf2[PATH_MAX];
984 gi->want = EINA_TRUE;
986 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
987 if (!ecore_file_exists(buf))
988 ecore_file_mkpath(buf);
990 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
991 if((!source) || (strlen(source)==0)) continue;
993 source = map_sources_tab[wd->source].url_cb(obj, x, y, g->zoom);
995 eina_stringshare_replace(&gi->file, buf2);
997 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
999 gi->download = EINA_TRUE;
1001 if (wd->preload_num == 1)
1003 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1004 "elm,state,busy,start", "elm");
1005 evas_object_smart_callback_call(obj,
1010 if (ecore_file_exists(buf2))
1014 DBG("DOWNLOAD %s \t in %s", source, buf2);
1015 ecore_file_download(source, buf2, _tile_downloaded, _tile_downloading, gi, &(gi->job));
1016 if (!gi->job) DBG("Can't start to download %s", buf);
1021 if (source) free(source);
1024 evas_object_show(gi->img);
1030 grid_clearall(Evas_Object *obj)
1032 Widget_Data *wd = elm_widget_data_get(obj);
1036 EINA_LIST_FREE(wd->grids, g)
1044 _smooth_update(Evas_Object *obj)
1046 Widget_Data *wd = elm_widget_data_get(obj);
1051 EINA_LIST_FOREACH(wd->grids, l, g)
1053 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1054 Eina_Matrixsparse_Cell *cell;
1056 EINA_ITERATOR_FOREACH(it, cell)
1058 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1059 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1061 eina_iterator_free(it);
1066 _grid_raise(Grid *g)
1068 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1069 Eina_Matrixsparse_Cell *cell;
1071 g->wd->size.w = g->w;
1072 g->wd->size.h = g->h;
1074 EINA_ITERATOR_FOREACH(it, cell)
1076 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1077 evas_object_raise(gi->img);
1078 //evas_object_raise(gi->txt);
1080 eina_iterator_free(it);
1084 _scr_timeout(void *data)
1086 Widget_Data *wd = elm_widget_data_get(data);
1087 if (!wd) return ECORE_CALLBACK_CANCEL;
1089 if (!wd->nosmooth) _smooth_update(data);
1090 wd->scr_timer = NULL;
1091 return ECORE_CALLBACK_CANCEL;
1095 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1097 Widget_Data *wd = elm_widget_data_get(data);
1102 if (wd->nosmooth == 1) _smooth_update(data);
1104 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1105 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1109 zoom_do(Evas_Object *obj, double t)
1111 Widget_Data *wd = elm_widget_data_get(obj);
1112 Evas_Coord xx, yy, ow, oh;
1115 if (t > 1.0) t = 1.0;
1117 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
1118 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
1120 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1122 if (wd->center_on.enabled)
1124 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1130 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1131 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1135 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1137 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1139 wd->show.show = EINA_TRUE;
1145 if (wd->calc_job) ecore_job_del(wd->calc_job);
1146 wd->calc_job = ecore_job_add(_calc_job, wd);
1149 return ECORE_CALLBACK_CANCEL;
1151 return ECORE_CALLBACK_RENEW;
1155 _zoom_anim(void *data)
1157 Evas_Object *obj = data;
1158 Widget_Data *wd = elm_widget_data_get(obj);
1162 if (!wd) return ECORE_CALLBACK_CANCEL;
1163 t = ecore_loop_time_get();
1166 else if (wd->t_end > wd->t_start)
1167 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
1172 go = zoom_do(obj, t);
1176 if (!wd->nosmooth) _smooth_update(data);
1177 wd->zoom_animator = NULL;
1178 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1184 _long_press(void *data)
1186 Widget_Data *wd = elm_widget_data_get(data);
1187 if (!wd) return ECORE_CALLBACK_CANCEL;
1188 wd->long_timer = NULL;
1189 wd->longpressed = EINA_TRUE;
1190 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1191 return ECORE_CALLBACK_CANCEL;
1195 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1197 Widget_Data *wd = elm_widget_data_get(data);
1198 Evas_Event_Mouse_Down *ev = event_info;
1199 struct event_t *ev0;
1201 ev0 = get_event_object(0);
1203 ev0 = create_event_object(obj, 0);
1206 ev0->hold_timer = NULL;
1207 ev0->prev.x = ev->output.x;
1208 ev0->prev.y = ev->output.y;
1211 if (ev->button != 1) return;
1212 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1213 else wd->on_hold = EINA_FALSE;
1214 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1215 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1217 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1218 wd->longpressed = EINA_FALSE;
1219 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1220 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1224 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1226 Widget_Data *wd = elm_widget_data_get(data);
1227 Evas_Event_Mouse_Move *move = (Evas_Event_Mouse_Move *)event_info;
1228 struct event_t *ev0;
1229 if (wd->pinch_zoom) return;
1230 ev0 = get_event_object(0);
1233 ev0->prev.x = move->cur.output.x;
1234 ev0->prev.y = move->cur.output.y;
1238 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1240 Widget_Data *wd = elm_widget_data_get(data);
1241 Evas_Event_Mouse_Up *ev = event_info;
1244 struct event_t *ev0;
1245 struct event_t *ev1;
1247 ev0 = get_event_object(0);
1250 mdevice = get_multi_device();
1253 if (ev0->hold_timer)
1255 ecore_timer_del(ev0->hold_timer);
1256 ev0->hold_timer = NULL;
1258 elm_smart_scroller_hold_set(wd->scr, 0);
1259 elm_smart_scroller_freeze_set(wd->scr, 0);
1260 wd->pinch_zoom = EINA_FALSE;
1264 ev1 = get_event_object(mdevice);
1265 if (ev1) ev1->hold_timer = ecore_timer_add(0.35f, _hold_timer_cb, ev1);
1267 destroy_event_object(ev0);
1271 if (ev->button != 1) return;
1272 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1273 else wd->on_hold = EINA_FALSE;
1276 ecore_timer_del(wd->long_timer);
1277 wd->long_timer = NULL;
1279 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1280 wd->on_hold = EINA_FALSE;
1284 _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1286 Widget_Data *wd = elm_widget_data_get(data);
1288 Evas_Event_Multi_Down *down = event_info;
1290 elm_smart_scroller_hold_set(wd->scr, 1);
1291 elm_smart_scroller_freeze_set(wd->scr, 1);
1293 ev = get_event_object(down->device);
1296 ev = create_event_object(obj, down->device);
1299 DBG("Failed : create_event_object");
1303 wd->pinch_zoom = EINA_FALSE;
1305 ev->hold_timer = NULL;
1306 ev->prev.x = down->output.x;
1307 ev->prev.y = down->output.y;
1314 _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1316 Widget_Data *wd = elm_widget_data_get(data);
1317 Evas_Event_Multi_Move *move = (Evas_Event_Multi_Move *)event_info;
1319 struct event_t *ev0;
1322 if (wd->pinch_zoom) return;
1323 ev = get_event_object(move->device);
1326 ev->prev.x = move->cur.output.x;
1327 ev->prev.y = move->cur.output.y;
1329 ev0 = get_event_object(0);
1332 dis_new = get_distance(ev0->prev.x, ev0->prev.y, ev->prev.x, ev->prev.y);
1333 int zoom = wd->zoom;
1337 if (dis_old - dis_new > 0 && ev->pinch_dis > TOUCH_HOLD_RANGE)
1339 wd->pinch_zoom = EINA_TRUE;
1341 elm_map_zoom_set(data, zoom);
1344 else if (dis_old - dis_new < 0 && ev->pinch_dis < -TOUCH_HOLD_RANGE)
1346 wd->pinch_zoom = EINA_TRUE;
1348 elm_map_zoom_set(data, zoom);
1351 ev->pinch_dis += (dis_old - dis_new);
1357 _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1359 Evas_Event_Multi_Up *up = (Evas_Event_Multi_Up *)event_info;
1360 struct event_t *ev0;
1363 ev = get_event_object(up->device);
1366 DBG("Cannot get multi device");
1371 ev0 = get_event_object(0);
1374 ev0->hold_timer = ecore_timer_add(0.35f, _hold_timer_cb, ev0);
1380 ecore_timer_del(ev->hold_timer);
1381 ev->hold_timer = NULL;
1384 destroy_event_object(ev);
1387 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
1390 _hold_timer_cb(void *data)
1392 struct event_t *ev0 = (struct event_t *)data;
1393 ev0->hold_timer = NULL;
1395 return ECORE_CALLBACK_CANCEL;
1399 _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1401 Widget_Data *wd = elm_widget_data_get(data);
1404 evas_object_geometry_get(wd->rect,&x,&y,&w,&h);
1405 evas_object_geometry_get(wd->pan_smart,&x,&y,&w,&h);
1406 evas_object_resize(wd->rect,w,h);
1407 evas_object_move(wd->rect,x,y);
1411 _del_hook(Evas_Object *obj)
1413 Elm_Map_Group_Class *group_clas;
1414 Elm_Map_Marker_Class *marker_clas;
1415 Widget_Data *wd = elm_widget_data_get(obj);
1419 EINA_LIST_FREE(wd->groups_clas, group_clas)
1421 if (group_clas->style)
1422 eina_stringshare_del(group_clas->style);
1426 EINA_LIST_FREE(wd->markers_clas, marker_clas)
1428 if (marker_clas->style)
1429 eina_stringshare_del(marker_clas->style);
1433 if (wd->calc_job) ecore_job_del(wd->calc_job);
1434 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1435 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
1436 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1437 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj);
1443 _del_pre_hook(Evas_Object *obj)
1445 Marker_Group *group;
1446 Elm_Map_Marker *marker;
1448 Eina_Bool free_marker = EINA_TRUE;
1450 Widget_Data *wd = elm_widget_data_get(obj);
1454 for (i = 0; i < ZOOM_MAX + 1; i++)
1456 if (!wd->markers[i]) continue;
1457 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
1458 Eina_Matrixsparse_Cell *cell;
1460 EINA_ITERATOR_FOREACH(it, cell)
1462 l = eina_matrixsparse_cell_data_get(cell);
1463 EINA_LIST_FREE(l, group)
1465 EINA_LIST_FREE(group->markers, marker)
1467 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1468 _bubble_sc_hits_changed_cb, group);
1469 if (free_marker) free(marker);
1473 free_marker = EINA_FALSE;
1475 eina_iterator_free(it);
1476 eina_matrixsparse_free(wd->markers[i]);
1479 evas_object_del(wd->sep_maps_markers);
1480 evas_object_del(wd->pan_smart);
1481 wd->pan_smart = NULL;
1485 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
1487 Widget_Data *wd = elm_widget_data_get(obj);
1489 if (elm_widget_focus_get(obj))
1491 edje_object_signal_emit(wd->obj, "elm,action,focus", "elm");
1492 evas_object_focus_set(wd->obj, EINA_TRUE);
1496 edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
1497 evas_object_focus_set(wd->obj, EINA_FALSE);
1502 _theme_hook(Evas_Object *obj)
1504 Widget_Data *wd = elm_widget_data_get(obj);
1506 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
1507 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
1512 _sizing_eval(Evas_Object *obj)
1514 Widget_Data *wd = elm_widget_data_get(obj);
1515 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
1517 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
1518 evas_object_size_hint_min_set(obj, minw, minh);
1519 evas_object_size_hint_max_set(obj, maxw, maxh);
1523 _calc_job(void *data)
1525 Widget_Data *wd = data;
1526 Evas_Coord minw, minh;
1533 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
1535 double tz = wd->zoom;
1537 elm_map_zoom_set(wd->obj, tz);
1540 if ((minw != wd->minw) || (minh != wd->minh))
1544 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
1545 _sizing_eval(wd->obj);
1547 wd->calc_job = NULL;
1548 evas_object_smart_changed(wd->pan_smart);
1552 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1554 Pan *sd = evas_object_smart_data_get(obj);
1556 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1559 evas_object_smart_changed(obj);
1563 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1565 Pan *sd = evas_object_smart_data_get(obj);
1567 if (x) *x = sd->wd->pan_x;
1568 if (y) *y = sd->wd->pan_y;
1572 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1574 Pan *sd = evas_object_smart_data_get(obj);
1577 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1578 ow = sd->wd->minw - ow;
1580 oh = sd->wd->minh - oh;
1587 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
1594 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1596 Pan *sd = evas_object_smart_data_get(obj);
1598 if (w) *w = sd->wd->minw;
1599 if (h) *h = sd->wd->minh;
1603 _pan_add(Evas_Object *obj)
1606 Evas_Object_Smart_Clipped_Data *cd;
1608 cd = evas_object_smart_data_get(obj);
1610 sd = calloc(1, sizeof(Pan));
1612 sd->__clipped_data = *cd;
1614 evas_object_smart_data_set(obj, sd);
1618 _pan_del(Evas_Object *obj)
1620 Pan *sd = evas_object_smart_data_get(obj);
1626 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
1628 Pan *sd = evas_object_smart_data_get(obj);
1631 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1632 if ((ow == w) && (oh == h)) return;
1633 sd->wd->resized = 1;
1634 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1635 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1639 _pan_calculate(Evas_Object *obj)
1641 Pan *sd = evas_object_smart_data_get(obj);
1642 Evas_Coord ox, oy, ow, oh;
1646 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
1647 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1648 EINA_LIST_FOREACH(sd->wd->grids, l, g)
1650 grid_load(sd->wd->obj, g);
1651 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1652 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1657 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
1659 Pan *sd = evas_object_smart_data_get(obj);
1661 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1662 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1666 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1668 Widget_Data *wd = elm_widget_data_get(obj);
1670 elm_smart_scroller_hold_set(wd->scr, 1);
1674 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1676 Widget_Data *wd = elm_widget_data_get(obj);
1678 elm_smart_scroller_hold_set(wd->scr, 0);
1682 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1684 Widget_Data *wd = elm_widget_data_get(obj);
1686 elm_smart_scroller_freeze_set(wd->scr, 1);
1690 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1692 Widget_Data *wd = elm_widget_data_get(obj);
1694 elm_smart_scroller_freeze_set(wd->scr, 0);
1698 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1700 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
1704 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1706 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
1710 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1712 Widget_Data *wd = elm_widget_data_get(data);
1713 wd->center_on.enabled = EINA_FALSE;
1714 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1718 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1720 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1724 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1726 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1731 _group_object_create(Marker_Group *group)
1733 const char *style = "radio";
1734 Evas_Object *icon = NULL;
1736 if (group->obj) return;
1737 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
1739 //set icon and style
1740 if (eina_list_count(group->markers) == 1)
1742 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1744 style = m->clas->style;
1746 if (m->clas->func.icon_get)
1747 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
1749 group->delete_object = EINA_TRUE;
1753 if (group->clas->style)
1754 style = group->clas->style;
1756 if (group->clas->func.icon_get)
1757 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
1759 group->delete_object = EINA_FALSE;
1762 group->obj = elm_layout_add(group->wd->obj);
1763 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
1765 if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
1767 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
1768 elm_widget_sub_object_add(group->wd->obj, group->obj);
1769 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
1771 if (!group->delete_object)
1772 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
1776 group->delete_object = EINA_FALSE;
1778 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
1779 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
1780 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
1781 evas_object_show(group->obj);
1784 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
1785 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
1787 group->update_nbelems = EINA_TRUE;
1788 group->update_resize = EINA_TRUE;
1789 group->update_raise = EINA_TRUE;
1791 if (group->open) _group_bubble_create(group);
1795 _group_object_free(Marker_Group *group)
1797 if (!group->obj) return;
1798 if (!group->delete_object)
1800 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
1801 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
1802 evas_object_hide(group->obj);
1804 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
1805 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
1808 evas_object_del(group->obj);
1811 _group_bubble_free(group);
1815 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1817 Marker_Group *group = data;
1819 if (!evas_object_above_get(group->rect)) return;
1820 evas_object_raise(group->bubble);
1821 evas_object_raise(group->sc);
1822 evas_object_raise(group->rect);
1826 _group_bubble_create(Marker_Group *group)
1828 if (group->bubble) return;
1830 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
1831 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
1832 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
1833 elm_widget_style_get(group->wd->obj));
1834 evas_object_smart_member_add(group->bubble,
1836 elm_widget_sub_object_add(group->wd->obj, group->bubble);
1838 _group_bubble_content_free(group);
1839 if (!_group_bubble_content_update(group))
1841 //no content, we can delete the bubble
1842 _group_bubble_free(group);
1846 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
1847 evas_object_color_set(group->rect, 0, 0, 0, 0);
1848 evas_object_repeat_events_set(group->rect, EINA_TRUE);
1849 evas_object_smart_member_add(group->rect, group->wd->obj);
1850 elm_widget_sub_object_add(group->wd->obj, group->rect);
1852 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
1854 _group_bubble_place(group);
1857 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1859 _group_bubble_place(data);
1863 _group_bubble_content_update(Marker_Group *group)
1866 Elm_Map_Marker *marker;
1869 if (!group->bubble) return 1;
1873 group->sc = elm_scroller_add(group->bubble);
1874 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
1875 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
1876 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
1877 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
1878 evas_object_show(group->sc);
1879 evas_object_smart_member_add(group->sc,
1881 elm_widget_sub_object_add(group->wd->obj, group->sc);
1883 group->bx = elm_box_add(group->bubble);
1884 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
1885 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
1886 elm_box_horizontal_set(group->bx, EINA_TRUE);
1887 evas_object_show(group->bx);
1889 elm_scroller_content_set(group->sc, group->bx);
1891 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
1892 _bubble_sc_hits_changed_cb, group);
1895 EINA_LIST_FOREACH(group->markers, l, marker)
1897 if (i >= group->wd->markers_max_num) break;
1898 if ((!marker->content) && (marker->clas->func.get))
1899 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
1900 else if (marker->content)
1901 elm_box_unpack(group->bx, marker->content);
1902 if (marker->content)
1904 elm_box_pack_end(group->bx, marker->content);
1912 _group_bubble_content_free(Marker_Group *group)
1915 Elm_Map_Marker *marker;
1917 if (!group->sc) return;
1918 EINA_LIST_FOREACH(group->markers, l, marker)
1920 if ((marker->content) && (marker->clas->func.del))
1921 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
1922 else if (marker->content)
1923 evas_object_del(marker->content);
1924 marker->content = NULL;
1926 evas_object_del(group->sc);
1931 _group_bubble_free(Marker_Group *group)
1933 if (!group->bubble) return;
1934 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
1935 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1936 _bubble_sc_hits_changed_cb, group);
1937 evas_object_del(group->bubble);
1938 evas_object_del(group->rect);
1939 group->bubble = NULL;
1940 _group_bubble_content_free(group);
1944 _group_bubble_place(Marker_Group *group)
1947 Evas_Coord xx, yy, ww, hh;
1950 if ((!group->bubble) || (!group->obj)) return;
1952 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
1953 edje_object_size_min_calc(group->bubble, NULL, &hh);
1955 s = edje_object_data_get(group->bubble, "size_w");
1957 xx = x + w / 2 - ww / 2;
1960 evas_object_move(group->bubble, xx, yy);
1961 evas_object_resize(group->bubble, ww, hh);
1962 evas_object_show(group->bubble);
1964 evas_object_move(group->rect, xx, yy);
1965 evas_object_resize(group->rect, ww, hh);
1966 evas_object_show(group->rect);
1970 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
1972 Marker_Group *group = data;
1973 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
1974 if (!marker) return;
1975 group->bringin = EINA_TRUE;
1976 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
1980 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
1982 Marker_Group *group = data;
1986 group->bringin = EINA_FALSE;
1992 group->open = EINA_FALSE;
1993 _group_bubble_free(group);
1996 group->open = EINA_TRUE;
1997 _group_bubble_create(group);
2001 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2006 Evas_Coord step_x = 0;
2007 Evas_Coord step_y = 0;
2010 Evas_Coord page_x = 0;
2011 Evas_Coord page_y = 0;
2013 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2014 Evas_Event_Key_Down *ev = event_info;
2015 Widget_Data *wd = elm_widget_data_get(obj);
2016 if (!wd) return EINA_FALSE;
2017 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2019 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2020 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2021 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2022 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2024 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2028 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2032 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2036 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2040 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2043 y -= -(page_y * v_h) / 100;
2047 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2050 y += -(page_y * v_h) / 100;
2054 else if (!strcmp(ev->keyname, "KP_Add"))
2056 zoom = elm_map_zoom_get(obj);
2058 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2059 elm_map_zoom_set(obj, zoom);
2062 else if (!strcmp(ev->keyname, "KP_Subtract"))
2064 zoom = elm_map_zoom_get(obj);
2066 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2067 elm_map_zoom_set(obj, zoom);
2070 else return EINA_FALSE;
2072 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2073 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2078 static int idnum = 1;
2081 * Add a new Map object
2083 * @param parent The parent object
2084 * @return The new object or NULL if it cannot be created
2089 elm_map_add(Evas_Object *parent)
2093 Evas_Coord minw, minh;
2095 static Evas_Smart *smart = NULL;
2096 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
2098 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2100 if (!ecore_file_download_protocol_available("http://"))
2102 ERR("Ecore must be built with the support of HTTP for the widget map !");
2106 wd = ELM_NEW(Widget_Data);
2109 e = evas_object_evas_get(parent);
2110 if (!e) return NULL;
2111 obj = elm_widget_add(e);
2112 ELM_SET_WIDTYPE(widtype, "map");
2113 elm_widget_type_set(obj, "map");
2114 elm_widget_sub_object_add(parent, obj);
2115 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2116 elm_widget_data_set(obj, wd);
2117 elm_widget_del_hook_set(obj, _del_hook);
2118 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2119 elm_widget_theme_hook_set(obj, _theme_hook);
2120 elm_widget_can_focus_set(obj, EINA_TRUE);
2121 elm_widget_event_hook_set(obj, _event_hook);
2123 wd->scr = elm_smart_scroller_add(e);
2124 elm_smart_scroller_widget_set(wd->scr, obj);
2125 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
2126 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
2127 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
2128 elm_widget_resize_object_set(obj, wd->scr);
2130 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
2131 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
2132 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
2133 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
2134 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
2136 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
2138 wd->api = module(obj);
2139 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2143 wd->markers_max_num = 30;
2144 wd->source = ELM_MAP_SOURCE_MAPNIK;
2146 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2147 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2148 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2149 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2153 static Evas_Smart_Class sc;
2155 evas_object_smart_clipped_smart_set(&_pan_sc);
2157 sc.name = "elm_map_pan";
2158 sc.version = EVAS_SMART_CLASS_VERSION;
2161 sc.resize = _pan_resize;
2162 sc.move = _pan_move;
2163 sc.calculate = _pan_calculate;
2164 smart = evas_smart_class_new(&sc);
2168 wd->pan_smart = evas_object_smart_add(e, smart);
2169 wd->pan = evas_object_smart_data_get(wd->pan_smart);
2173 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2174 _pan_set, _pan_get, _pan_max_get,
2175 _pan_min_get, _pan_child_size_get);
2177 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
2178 _rect_resize_cb, obj);
2179 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
2181 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
2183 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
2185 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
2186 _mouse_multi_down, obj);
2187 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
2188 _mouse_multi_move, obj);
2189 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
2190 _mouse_multi_up, obj);
2192 evas_object_smart_member_add(wd->rect, wd->pan_smart);
2193 elm_widget_sub_object_add(obj, wd->rect);
2194 evas_object_show(wd->rect);
2195 evas_object_color_set(wd->rect, 0, 0, 0, 0);
2198 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2199 wd->id = ((int)getpid() << 16) | idnum;
2204 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
2206 evas_object_size_hint_min_set(obj, minw, minh);
2208 wd->paused = EINA_TRUE;
2209 elm_map_zoom_set(obj, 0);
2210 wd->paused = EINA_FALSE;
2214 wd->calc_job = ecore_job_add(_calc_job, wd);
2216 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
2217 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
2219 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2220 // TODO: and save some bytes, making descriptions per-class and not instance!
2221 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2226 * Set the zoom level of the map
2228 * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
2230 * @param obj The map object
2231 * @param zoom The zoom level to set
2236 elm_map_zoom_set(Evas_Object *obj, int zoom)
2238 ELM_CHECK_WIDTYPE(obj, widtype);
2239 Widget_Data *wd = elm_widget_data_get(obj);
2241 Grid *g, *g_zoom = NULL;
2242 Evas_Coord rx, ry, rw, rh;
2244 int zoom_changed = 0, started = 0;
2247 if (zoom < 0 ) zoom = 0;
2248 if (zoom > map_sources_tab[wd->source].zoom_max)
2249 zoom = map_sources_tab[wd->source].zoom_max;
2250 if (zoom < map_sources_tab[wd->source].zoom_min)
2251 zoom = map_sources_tab[wd->source].zoom_min;
2252 if (zoom == wd->zoom) return;
2255 wd->size.ow = wd->size.w;
2256 wd->size.oh = wd->size.h;
2257 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
2258 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2260 if (wd->mode == ELM_MAP_ZOOM_MODE_MANUAL)
2262 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2263 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2265 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
2272 while (cumulw <= rw)
2281 while (cumulh <= rh)
2294 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2295 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2297 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
2304 while (cumulw <= rw)
2313 while (cumulh <= rh)
2326 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2327 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2330 EINA_LIST_FOREACH(wd->grids, l, g)
2332 if (g->zoom == wd->zoom)
2334 wd->grids = eina_list_remove(wd->grids, g);
2335 wd->grids = eina_list_prepend(wd->grids, g);
2340 g = grid_create(obj);
2343 if (eina_list_count(wd->grids) > 1)
2345 g_zoom = eina_list_last(wd->grids)->data;
2346 wd->grids = eina_list_remove(wd->grids, g_zoom);
2347 grid_clear(obj, g_zoom);
2350 wd->grids = eina_list_prepend(wd->grids, g);
2354 EINA_LIST_FREE(wd->grids, g)
2362 wd->t_start = ecore_loop_time_get();
2363 wd->t_end = wd->t_start + _elm_config->zoom_friction;
2364 if ((wd->size.w > 0) && (wd->size.h > 0))
2366 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
2367 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
2371 wd->size.spos.x = 0.5;
2372 wd->size.spos.y = 0.5;
2374 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
2375 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
2376 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
2377 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
2384 if (!wd->zoom_animator)
2386 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
2388 if (wd->nosmooth == 1) _smooth_update(obj);
2392 if (wd->zoom_animator)
2394 if (!_zoom_anim(obj))
2396 ecore_animator_del(wd->zoom_animator);
2397 wd->zoom_animator = NULL;
2400 if (wd->calc_job) ecore_job_del(wd->calc_job);
2401 wd->calc_job = ecore_job_add(_calc_job, wd);
2405 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
2406 if (!wd->zoom_animator)
2407 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2411 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
2415 * Get the zoom level of the photo
2417 * This returns the current zoom level of the map object. Note that if
2418 * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
2419 * (which is the default), the zoom level may be changed at any time by the
2420 * map object itself to account for map size and map viewpoer size
2422 * @param obj The map object
2423 * @return The current zoom level
2428 elm_map_zoom_get(const Evas_Object *obj)
2430 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
2431 Widget_Data *wd = elm_widget_data_get(obj);
2432 if (!wd) return 1.0;
2439 * This sets the zoom mode to manual or one of several automatic levels.
2440 * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
2441 * elm_map_zoom_set() and will stay at that level until changed by code
2442 * or until zoom mode is changed. This is the default mode.
2443 * The Automatic modes will allow the map object to automatically
2444 * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT) will
2445 * adjust zoom so the photo fits inside the scroll frame with no pixels
2446 * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
2447 * ensure no pixels within the frame are left unfilled. Do not forget that the valid sizes are 2^zoom, consequently the map may be smaller than the scroller view.
2449 * @param obj The map object
2450 * @param mode The desired mode
2455 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
2457 ELM_CHECK_WIDTYPE(obj, widtype);
2458 Widget_Data *wd = elm_widget_data_get(obj);
2460 if (wd->mode == mode) return;
2463 double tz = wd->zoom;
2465 elm_map_zoom_set(wd->obj, tz);
2472 * This gets the current zoom mode of the map object
2474 * @param obj The map object
2475 * @return The current zoom mode
2479 EAPI Elm_Map_Zoom_Mode
2480 elm_map_zoom_mode_get(const Evas_Object *obj)
2482 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
2483 Widget_Data *wd = elm_widget_data_get(obj);
2484 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
2489 * Centers the map at @p lon @p lat using an animation to scroll.
2491 * @param obj The map object
2492 * @param lon Longitude to center at
2493 * @param lon Latitude to center at
2498 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
2500 ELM_CHECK_WIDTYPE(obj, widtype);
2501 Widget_Data *wd = elm_widget_data_get(obj);
2505 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
2506 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2511 if (wd->zoom_animator)
2514 if (!wd->nosmooth) _smooth_update(obj);
2515 ecore_animator_del(wd->zoom_animator);
2516 wd->zoom_animator = NULL;
2518 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2520 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
2522 wd->center_on.enabled = EINA_TRUE;
2523 wd->center_on.lon = lon;
2524 wd->center_on.lat = lat;
2528 * Move the map to the current coordinates.
2530 * This move the map to the current coordinates. The map will be centered on these coordinates.
2532 * @param obj The map object
2533 * @param lat The latitude.
2534 * @param lon The longitude.
2539 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
2541 ELM_CHECK_WIDTYPE(obj, widtype);
2542 Widget_Data *wd = elm_widget_data_get(obj);
2546 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
2547 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2552 if (wd->zoom_animator)
2555 ecore_animator_del(wd->zoom_animator);
2556 wd->zoom_animator = NULL;
2558 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2560 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
2562 wd->center_on.enabled = EINA_TRUE;
2563 wd->center_on.lon = lon;
2564 wd->center_on.lat = lat;
2568 * Get the current coordinates of the map.
2570 * This gets the current coordinates of the map object.
2572 * @param obj The map object
2573 * @param lat The latitude.
2574 * @param lon The longitude.
2579 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
2581 ELM_CHECK_WIDTYPE(obj, widtype);
2582 Widget_Data *wd = elm_widget_data_get(obj);
2583 Evas_Coord sx, sy, sw, sh;
2586 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
2587 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
2591 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
2595 * Set the paused state for map
2597 * This sets the paused state to on (1) or off (0) for map. The default
2598 * is off. This will stop zooming using animation change zoom levels and
2599 * change instantly. This will stop any existing animations that are running.
2601 * @param obj The map object
2602 * @param paused The pause state to set
2607 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
2609 ELM_CHECK_WIDTYPE(obj, widtype);
2610 Widget_Data *wd = elm_widget_data_get(obj);
2612 if (wd->paused == !!paused) return;
2613 wd->paused = paused;
2616 if (wd->zoom_animator)
2618 ecore_animator_del(wd->zoom_animator);
2619 wd->zoom_animator = NULL;
2621 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2627 * Set the paused state for the markers
2629 * This sets the paused state to on (1) or off (0) for the markers. The default
2630 * is off. This will stop displaying the markers during change zoom levels. Set
2631 * to on if you have a large number of markers.
2633 * @param obj The map object
2634 * @param paused The pause state to set
2639 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
2641 ELM_CHECK_WIDTYPE(obj, widtype);
2642 Widget_Data *wd = elm_widget_data_get(obj);
2644 if (wd->paused_markers == !!paused) return;
2645 wd->paused_markers = paused;
2649 * Get the paused state for map
2651 * This gets the current paused state for the map object.
2653 * @param obj The map object
2654 * @return The current paused state
2659 elm_map_paused_get(const Evas_Object *obj)
2661 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2662 Widget_Data *wd = elm_widget_data_get(obj);
2663 if (!wd) return EINA_FALSE;
2668 * Get the paused state for the markers
2670 * This gets the current paused state for the markers object.
2672 * @param obj The map object
2673 * @return The current paused state
2678 elm_map_paused_markers_get(const Evas_Object *obj)
2680 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2681 Widget_Data *wd = elm_widget_data_get(obj);
2682 if (!wd) return EINA_FALSE;
2683 return wd->paused_markers;
2687 * Get the information of downloading status
2689 * This gets the current downloading status for the map object.
2691 * @param obj The map object
2692 * @param try_num the number of download trying map
2693 * @param finish_num the number of downloaded map
2698 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
2700 Widget_Data *wd = elm_widget_data_get(obj);
2704 *try_num = wd->try_num;
2709 *finish_num = wd->finish_num;
2714 * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
2716 * @param obj The map object
2717 * @param x the coordinate
2718 * @param y the coordinate
2719 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
2720 * @param lon the longitude correspond to x
2721 * @param lat the latitude correspond to y
2726 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
2728 Widget_Data *wd = elm_widget_data_get(obj);
2729 int zoom = floor(log2(size/256));
2731 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
2732 if ((wd->api) && (wd->api->obj_convert_coord_into_geo))
2733 if (wd->api->obj_convert_coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
2737 *lon = x / (double)size * 360.0 - 180;
2741 double n = ELM_PI - 2.0 * ELM_PI * y / size;
2742 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
2747 * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
2749 * @param obj The map object
2750 * @param lon the longitude
2751 * @param lat the latitude
2752 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
2753 * @param x the coordinate correspond to the longitude
2754 * @param y the coordinate correspond to the latitude
2759 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
2761 Widget_Data *wd = elm_widget_data_get(obj);
2762 int zoom = floor(log2(size/256));
2764 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
2765 if ((wd->api) && (wd->api->obj_convert_geo_into_coord))
2766 if (wd->api->obj_convert_geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
2769 *x = floor((lon + 180.0) / 360.0 * size);
2771 *y = floor((1.0 - log( tan(lat * ELM_PI/180.0) + 1.0 / cos(lat * ELM_PI/180.0)) / ELM_PI) / 2.0 * size);
2777 * Add a marker on the map
2779 * @param obj The map object
2780 * @param lon the longitude
2781 * @param lat the latitude
2782 * @param clas the class to use
2783 * @param data the data passed to the callbacks
2785 * @return The marker object
2789 EAPI Elm_Map_Marker *
2790 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
2794 Marker_Group *group;
2795 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2796 Widget_Data *wd = elm_widget_data_get(obj);
2804 if (!wd) return NULL;
2805 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
2806 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
2808 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
2811 marker->clas = clas;
2812 marker->clas_group = clas_group;
2813 marker->longitude = lon;
2814 marker->latitude = lat;
2815 marker->data = data;
2817 tabi[1] = tabi[4] = tabi[6] = -1;
2818 tabi[2] = tabi[0] = tabi[7] = 0;
2819 tabi[3] = tabi[5] = tabi[8] = 1;
2821 tabj[1] = tabj[2] = tabj[3] = -1;
2822 tabj[4] = tabj[0] = tabj[5] = 0;
2823 tabj[6] = tabj[7] = tabj[8] = 1;
2825 if (!clas_group->priv.set)
2828 if (marker->clas_group && marker->clas_group->style)
2829 style = marker->clas_group->style;
2831 o = edje_object_add(evas_object_evas_get(obj));
2832 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
2833 s = edje_object_data_get(o, "size_w");
2834 clas_group->priv.edje_w = atoi(s);
2835 s = edje_object_data_get(o, "size_h");
2836 clas_group->priv.edje_h = atoi(s);
2837 s = edje_object_data_get(o, "size_max_w");
2838 clas_group->priv.edje_max_w = atoi(s);
2839 s = edje_object_data_get(o, "size_max_h");
2840 clas_group->priv.edje_max_h = atoi(s);
2843 clas_group->priv.set = EINA_TRUE;
2846 if (!clas->priv.set)
2849 if (marker->clas && marker->clas->style)
2850 style = marker->clas->style;
2852 o = edje_object_add(evas_object_evas_get(obj));
2853 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
2854 s = edje_object_data_get(o, "size_w");
2855 clas->priv.edje_w = atoi(s);
2856 s = edje_object_data_get(o, "size_h");
2857 clas->priv.edje_h = atoi(s);
2860 clas->priv.set = EINA_TRUE;
2863 for (i = clas_group->zoom_displayed; i <= ZOOM_MAX; i++)
2865 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
2866 &(marker->x[i]), &(marker->y[i]));
2868 //search in the matrixsparse the region where the marker will be
2869 mpi = marker->x[i] / wd->tsize;
2870 mpj = marker->y[i] / wd->tsize;
2872 if (!wd->markers[i])
2874 int size = pow(2.0, i);
2875 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
2879 if (i <= clas_group->zoom_grouped)
2881 for (j = 0, group = NULL; j < 9 && !group; j++)
2883 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
2886 if (group->clas == marker->clas_group
2887 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
2888 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
2889 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
2891 group->markers = eina_list_append(group->markers, marker);
2892 group->update_nbelems = EINA_TRUE;
2893 group->update_resize = EINA_TRUE;
2895 group->sum_x += marker->x[i];
2896 group->sum_y += marker->y[i];
2897 group->x = group->sum_x / eina_list_count(group->markers);
2898 group->y = group->sum_y / eina_list_count(group->markers);
2900 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
2901 * eina_list_count(group->markers);
2902 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
2903 * eina_list_count(group->markers);
2904 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
2905 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
2907 if (group->obj && eina_list_count(group->markers) == 2)
2909 _group_object_free(group);
2910 _group_object_create(group);
2913 _group_bubble_content_update(group);
2922 group = calloc(1, sizeof(Marker_Group));
2924 group->sum_x = marker->x[i];
2925 group->sum_y = marker->y[i];
2926 group->x = marker->x[i];
2927 group->y = marker->y[i];
2928 group->w = clas_group->priv.edje_w;
2929 group->h = clas_group->priv.edje_h;
2930 group->clas = clas_group;
2932 group->markers = eina_list_append(group->markers, marker);
2933 group->update_nbelems = EINA_TRUE;
2934 group->update_resize = EINA_TRUE;
2936 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
2940 l = eina_list_append(NULL, group);
2941 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
2942 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
2946 l = eina_matrixsparse_cell_data_get(group->cell);
2947 l = eina_list_append(l, group);
2948 eina_matrixsparse_cell_data_set(group->cell, l);
2951 marker->groups[i] = group;
2956 Evas_Coord ox, oy, ow, oh;
2957 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2958 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
2965 * Remove a marker from the map
2967 * @param marker The marker to remove
2972 elm_map_marker_remove(Elm_Map_Marker *marker)
2978 EINA_SAFETY_ON_NULL_RETURN(marker);
2981 for (i = 0; i <= ZOOM_MAX; i++)
2983 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
2984 if (!eina_list_count(marker->groups[i]->markers))
2986 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
2987 groups = eina_list_remove(groups, marker->groups[i]);
2988 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
2990 _group_object_free(marker->groups[i]);
2991 _group_bubble_free(marker->groups[i]);
2992 free(marker->groups[i]);
2996 marker->groups[i]->sum_x -= marker->x[i];
2997 marker->groups[i]->sum_y -= marker->y[i];
2999 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
3000 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
3002 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
3003 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
3004 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
3005 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
3006 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
3007 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
3008 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
3009 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
3011 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
3013 _group_object_free(marker->groups[i]);
3014 _group_object_create(marker->groups[i]);
3018 if ((marker->content) && (marker->clas->func.del))
3019 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
3020 else if (marker->content)
3021 evas_object_del(marker->content);
3027 Evas_Coord ox, oy, ow, oh;
3028 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3029 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3034 * Move the map to the coordinate of the marker.
3036 * @param marker The marker where the map will be center.
3041 elm_map_marker_bring_in(Elm_Map_Marker *marker)
3043 EINA_SAFETY_ON_NULL_RETURN(marker);
3044 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
3049 * Move the map to the coordinate of the marker.
3051 * @param marker The marker where the map will be center.
3056 elm_map_marker_show(Elm_Map_Marker *marker)
3058 EINA_SAFETY_ON_NULL_RETURN(marker);
3059 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
3063 * Move and zoom the map to display a list of markers.
3065 * The map will be centered on the center point of the markers in the list. Then
3066 * the map will be zoomed in order to fit the markers using the maximum zoom which
3067 * allows display of all the markers.
3069 * @param markers The list of markers (list of Elm_Map_Marker *)
3074 elm_map_markers_list_show(Eina_List *markers)
3079 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
3080 Evas_Coord rw, rh, xc, yc;
3083 EINA_SAFETY_ON_NULL_RETURN(markers);
3085 EINA_LIST_FOREACH(markers, l, marker)
3089 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
3092 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
3095 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
3098 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
3102 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
3103 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
3105 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3106 for (zoom = map_sources_tab[wd->source].zoom_max; zoom>map_sources_tab[wd->source].zoom_min; zoom--)
3108 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
3109 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
3111 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
3112 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
3113 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
3114 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
3118 elm_map_geo_region_show(wd->obj, lon, lat);
3119 elm_map_zoom_set(wd->obj, zoom);
3123 * Set the maximum numbers of markers display in a group.
3125 * A group can have a long list of markers, consequently the creation of the content
3126 * of the bubble can be very slow. In order to avoid this, a maximum number of items
3127 * is displayed in a bubble. By default this number is 30.
3129 * @param obj The map object.
3130 * @param max The maximum numbers of items displayed in a bubble.
3135 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
3137 ELM_CHECK_WIDTYPE(obj, widtype);
3138 Widget_Data *wd = elm_widget_data_get(obj);
3140 wd->markers_max_num = max;
3144 * Return the evas object getting from the ElmMapMarkerGetFunc callback
3146 * @param marker The marker.
3147 * @return Return the evas object if it exists, else NULL.
3152 elm_map_marker_object_get(const Elm_Map_Marker *marker)
3154 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
3155 return marker->content;
3161 * @param marker The marker.
3166 elm_map_marker_update(Elm_Map_Marker *marker)
3168 EINA_SAFETY_ON_NULL_RETURN(marker);
3169 if (marker->content)
3171 if (marker->clas->func.del)
3172 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
3174 evas_object_del(marker->content);
3175 marker->content = NULL;
3176 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
3181 * Close all opened bubbles
3183 * @param obj The map object
3188 elm_map_bubbles_close(Evas_Object *obj)
3190 ELM_CHECK_WIDTYPE(obj, widtype);
3191 Widget_Data *wd = elm_widget_data_get(obj);
3192 Marker_Group *group;
3193 Eina_List *l, *l_next;
3195 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
3196 _group_bubble_free(group);
3201 * Create a group class.
3203 * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
3204 * The group class defines the style of the marker when a marker is grouped to others markers.
3206 * @param obj The map object
3207 * @return Returns the new group class
3211 EAPI Elm_Map_Group_Class *
3212 elm_map_group_class_new(Evas_Object *obj)
3214 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3215 Widget_Data *wd = elm_widget_data_get(obj);
3216 if (!wd) return NULL;
3217 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
3218 clas->zoom_grouped = ZOOM_MAX;
3219 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
3224 * Set the style of a group class (radio, radio2 or empty)
3226 * @param clas the group class
3227 * @param style the new style
3232 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
3234 EINA_SAFETY_ON_NULL_RETURN(clas);
3235 eina_stringshare_replace(&clas->style, style);
3239 * Set the icon callback of a group class.
3241 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
3243 * @param clas the group class
3244 * @param icon_get the callback to create the icon
3249 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
3251 EINA_SAFETY_ON_NULL_RETURN(clas);
3252 clas->func.icon_get = icon_get;
3256 * Set the data associated to the group class (radio, radio2 or empty)
3258 * @param clas the group class
3259 * @param data the new user data
3264 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
3266 EINA_SAFETY_ON_NULL_RETURN(clas);
3271 * Set the zoom from where the markers are displayed.
3273 * Markers will not be displayed for a zoom less than @ref zoom
3275 * @param clas the group class
3276 * @param zoom the zoom
3281 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
3283 EINA_SAFETY_ON_NULL_RETURN(clas);
3284 clas->zoom_displayed = zoom;
3288 * Set the zoom from where the markers are no more grouped.
3290 * @param clas the group class
3291 * @param zoom the zoom
3296 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
3298 EINA_SAFETY_ON_NULL_RETURN(clas);
3299 clas->zoom_grouped = zoom;
3303 * Set if the markers associated to the group class @clas are hidden or not.
3304 * If @ref hide is true the markers will be hidden.
3306 * @param clas the group class
3307 * @param hide if true the markers will be hidden, else they will be displayed.
3312 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
3314 ELM_CHECK_WIDTYPE(obj, widtype);
3315 Widget_Data *wd = elm_widget_data_get(obj);
3317 EINA_SAFETY_ON_NULL_RETURN(clas);
3318 if (clas->hide == hide) return;
3322 Evas_Coord ox, oy, ow, oh;
3323 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3324 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3330 * Create a marker class.
3332 * Each marker must be associated to a class.
3333 * The class defines the style of the marker when a marker is displayed alone (not grouped).
3335 * @param obj The map object
3336 * @return Returns the new class
3340 EAPI Elm_Map_Marker_Class *
3341 elm_map_marker_class_new(Evas_Object *obj)
3343 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3344 Widget_Data *wd = elm_widget_data_get(obj);
3345 if (!wd) return NULL;
3346 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
3347 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
3352 * Set the style of a class (radio, radio2 or empty)
3354 * @param clas the group class
3355 * @param style the new style
3360 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
3362 EINA_SAFETY_ON_NULL_RETURN(clas);
3363 eina_stringshare_replace(&clas->style, style);
3367 * Set the icon callback of a class.
3369 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
3371 * @param clas the group class
3372 * @param icon_get the callback to create the icon
3377 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
3379 EINA_SAFETY_ON_NULL_RETURN(clas);
3380 clas->func.icon_get = icon_get;
3385 * Set the callback of the content of the bubble.
3387 * When the user click on a marker, a bubble is displayed with a content.
3388 * The callback @ref get musst return this content. It can be NULL.
3390 * @param clas the group class
3391 * @param get the callback to create the content
3396 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
3398 EINA_SAFETY_ON_NULL_RETURN(clas);
3399 clas->func.get = get;
3403 * Set the callback of the content of delete the object created by the callback "get".
3405 * If this callback is defined the user will have to delete (or not) the object inside.
3406 * If the callback is not defined the object will be destroyed with evas_object_del()
3408 * @param clas the group class
3409 * @param del the callback to delete the content
3414 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
3416 EINA_SAFETY_ON_NULL_RETURN(clas);
3417 clas->func.del = del;
3421 * Set the source of the map.
3423 * Elm_Map retrieves the image which composed the map from a web service. This web service can
3424 * be set with this method. A different service can return a different maps with different
3425 * information and it can use different zoom value.
3427 * @param clas the group class
3428 * @param source the new source
3433 elm_map_source_set(Evas_Object *obj, Elm_Map_Sources source)
3435 ELM_CHECK_WIDTYPE(obj, widtype);
3436 Widget_Data *wd = elm_widget_data_get(obj);
3440 if (wd->source == source ) return;
3441 if (!map_sources_tab[source].url_cb) return;
3443 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
3445 wd->source = source;
3449 if (map_sources_tab[wd->source].zoom_max < zoom)
3450 zoom = map_sources_tab[wd->source].zoom_max;
3451 if (map_sources_tab[wd->source].zoom_min > zoom)
3452 zoom = map_sources_tab[wd->source].zoom_min;
3454 elm_map_zoom_set(obj, zoom);
3458 * Get the current source
3460 * @param obj the map object
3461 * @return Returns the maximum zoom of the source
3465 EAPI Elm_Map_Sources
3466 elm_map_source_get(const Evas_Object *obj)
3468 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_SOURCE_MAPNIK;
3469 Widget_Data *wd = elm_widget_data_get(obj);
3470 if (!wd) return ELM_MAP_SOURCE_MAPNIK;
3475 * Set the API of a custom source.
3477 * A custom web service can be associated to the source ELM_MAP_SOURCE_CUSTOM_(1..7).
3479 * @param source the source ID (ELM_MAP_SOURCE_CUSTOM_(1..7))
3480 * @param name the name of the source
3481 * @param zoom_min the minimum zoom of the source, must be >= 0
3482 * @param zoom_max the maximum zoom of the source, must be <= ZOOM_MAX
3483 * @param url_cb the callback used to create the url from where a tile (png or jpeg file) is downloaded.
3488 elm_map_source_custom_api_set(Elm_Map_Sources source, const char *name, int zoom_min, int zoom_max, ElmMapSourceURLFunc url_cb)
3490 EINA_SAFETY_ON_NULL_RETURN(name);
3491 EINA_SAFETY_ON_NULL_RETURN(url_cb);
3492 map_sources_tab[source].name = name;
3493 map_sources_tab[source].zoom_min = zoom_min;
3494 map_sources_tab[source].zoom_max = zoom_max;
3495 map_sources_tab[source].url_cb = url_cb;
3499 * Get the maximum zoom of the source.
3501 * @param source the source
3502 * @return Returns the maximum zoom of the source
3507 elm_map_source_zoom_max_get(Elm_Map_Sources source)
3509 return map_sources_tab[source].zoom_max;
3513 * Get the minimum zoom of the source.
3515 * @param source the source
3516 * @return Returns the minimum zoom of the source
3521 elm_map_source_zoom_min_get(Elm_Map_Sources source)
3523 return map_sources_tab[source].zoom_min;
3527 * Get the name of a source.
3529 * @param source the source
3530 * @return Returns the name of the source
3535 elm_map_source_name_get(Elm_Map_Sources source)
3537 return map_sources_tab[source].name;
3542 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3545 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
3551 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3554 snprintf(buf, sizeof(buf),
3555 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
3561 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3564 snprintf(buf, sizeof(buf),
3565 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
3571 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3574 snprintf(buf, sizeof(buf),
3575 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
3581 _custom1_url_cb(Evas_Object *obj, int x, int y, int zoom)
3587 _custom2_url_cb(Evas_Object *obj, int x, int y, int zoom)
3593 _custom3_url_cb(Evas_Object *obj, int x, int y, int zoom)
3599 _custom4_url_cb(Evas_Object *obj, int x, int y, int zoom)
3605 _custom5_url_cb(Evas_Object *obj, int x, int y, int zoom)
3611 _custom6_url_cb(Evas_Object *obj, int x, int y, int zoom)
3617 _module_url_cb(Evas_Object *obj, int x, int y, int zoom)
3620 Widget_Data *wd = elm_widget_data_get(obj);
3621 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
3622 if ((wd->api) && (wd->api->obj_url_request))
3623 buf = wd->api->obj_url_request(obj, x, y, zoom);
3625 if (!buf) buf = strdup("");