1 #include <Elementary.h>
10 * This is a widget specifically for displaying the map. It uses basically
11 * OpenStreetMap provider. but it can be added custom providers.
13 * Signals that you can add callbacks for are:
15 * "clicked" - This is called when a user has clicked the map without dragging
17 * "press" - This is called when a user has pressed down on the map.
18 * "longpressed" - This is called when a user has pressed down on the map for
19 * a long time without dragging around.
20 * "clicked,double" - This is called when a user has double-clicked the photo.
21 * "load,detail" - Map detailed data load begins.
22 * "loaded,detail" - This is called when all parts of the map are loaded.
23 * "zoom,start" - Zoom animation started.
24 * "zoom,stop" - Zoom animation stopped.
25 * "zoom,change" - Zoom changed when using an auto zoom mode.
26 * "scroll" - the content has been scrolled (moved)
27 * "scroll,anim,start" - scrolling animation has started
28 * "scroll,anim,stop" - scrolling animation has stopped
29 * "scroll,drag,start" - dragging the contents around has started
30 * "scroll,drag,stop" - dragging the contents around has stopped
31 * "downloaded" - This is called when map images are downloaded
32 * "route,load" - This is called when route request begins
33 * "route,loaded" - This is called when route request ends
39 typedef struct _Widget_Data Widget_Data;
40 typedef struct _Pan Pan;
41 typedef struct _Grid Grid;
42 typedef struct _Grid_Item Grid_Item;
43 typedef struct _Marker_Group Marker_Group;
44 typedef struct _Mod_Api Mod_Api;
45 typedef struct _Event Event;
46 typedef struct _Route_Node Route_Node;
47 typedef struct _Route_Waypoint Route_Waypoint;
48 typedef struct _Url_Data Url_Data;
49 typedef struct _Route_Dump Route_Dump;
51 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
52 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
53 #define DEST_FILE_PATH "%s%d.png"
54 #define DEST_XML_FILE "/tmp/elm_map-XXXXXX"
56 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
57 #define ROUTE_TYPE_MOTORCAR "motocar"
58 #define ROUTE_TYPE_BICYCLE "bicycle"
59 #define ROUTE_TYPE_FOOT "foot"
60 #define YOURS_DISTANCE "distance"
61 #define YOURS_DESCRIPTION "description"
62 #define YOURS_COORDINATES "coordinates"
64 // TODO: fix monav & ors url
65 #define ROUTE_MONAV_URL "http://"
66 #define ROUTE_ORS_URL "http:///"
69 // Currently the size of a tile must be 256*256
70 // and the size of the map must be pow(2.0, z)*tile_size
71 typedef struct _Map_Sources_Tab
73 Elm_Map_Sources source;
77 ElmMapSourceURLFunc url_cb;
78 Elm_Map_Route_Sources route_source;
79 ElmMapRouteSourceURLFunc route_url_cb;
84 //Zemm min is supposed to be 0
85 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
86 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
87 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
88 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
89 static char *_module_url_cb(Evas_Object *obj, int x, int y, int zoom);
90 static char * _custom1_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
91 static char * _custom2_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
92 static char * _custom3_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
93 static char * _custom4_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
94 static char * _custom5_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
95 static char * _custom6_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
97 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
99 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
100 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
102 static char *_route_custom1_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
103 static char *_route_custom2_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
104 static char *_route_custom3_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
105 static char *_route_custom4_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
106 static char *_route_custom5_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
107 static char *_route_custom6_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
109 static char *_route_module_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
112 static Map_Sources_Tab map_sources_tab[] =
114 {ELM_MAP_SOURCE_MAPNIK, "Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb},
115 {ELM_MAP_SOURCE_OSMARENDER, "Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb},
116 {ELM_MAP_SOURCE_CYCLEMAP, "Cycle Map", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb},
117 {ELM_MAP_SOURCE_MAPLINT, "Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb},
118 {ELM_MAP_SOURCE_CUSTOM_1, "Custom 1", 0, 18, _custom1_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_1, _route_custom1_url_cb},
119 {ELM_MAP_SOURCE_CUSTOM_2, "Custom 2", 0, 18, _custom2_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_2, _route_custom2_url_cb},
120 {ELM_MAP_SOURCE_CUSTOM_3, "Custom 3", 0, 18, _custom3_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_3, _route_custom3_url_cb},
121 {ELM_MAP_SOURCE_CUSTOM_4, "Custom 4", 0, 18, _custom4_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_4, _route_custom4_url_cb},
122 {ELM_MAP_SOURCE_CUSTOM_5, "Custom 5", 0, 18, _custom5_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_5, _route_custom5_url_cb},
123 {ELM_MAP_SOURCE_CUSTOM_6, "Custom 6", 0, 18, _custom6_url_cb, ELM_MAP_ROUTE_SOURCE_CUSTOM_6, _route_custom6_url_cb},
124 {ELM_MAP_SOURCE_MODULE, "Module", 0, 18, _module_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb}
129 Ecore_Con_Url *con_url;
135 struct _Elm_Map_Marker_Class
140 struct _Elm_Map_Marker_Class_Func {
141 ElmMapMarkerGetFunc get;
142 ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
143 ElmMapMarkerIconGetFunc icon_get;
146 struct { //this part is private, do not modify these values
148 Evas_Coord edje_w, edje_h;
152 struct _Elm_Map_Marker
155 Elm_Map_Marker_Class *clas;
156 Elm_Map_Group_Class *clas_group;
157 double longitude, latitude;
160 Evas_Coord x[ZOOM_MAX+1], y[ZOOM_MAX+1];
163 Marker_Group *groups[ZOOM_MAX+1];
165 Evas_Object *content;
168 struct _Elm_Map_Group_Class
172 int zoom_displayed; // display the group if the zoom is >= to zoom_display
173 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
177 ElmMapGroupIconGetFunc icon_get;
180 struct { //this part is private, do not modify these values
182 Evas_Coord edje_w, edje_h;
183 Evas_Coord edje_max_w, edje_max_h;
185 Eina_List *objs_used;
186 Eina_List *objs_notused;
193 Eina_Matrixsparse_Cell *cell;
194 Elm_Map_Group_Class *clas;
197 long long sum_x, sum_y;
201 Evas_Object *obj, *bubble, *sc, *bx, *rect;
203 Eina_Bool bringin : 1;
204 Eina_Bool update_nbelems : 1;
205 Eina_Bool update_resize : 1;
206 Eina_Bool update_raise : 1;
207 Eina_Bool delete_object : 1;
210 struct _Elm_Map_Route
216 Ecore_Con_Url *con_url;
221 double flon, flat, tlon, tlat;
223 Eina_List *nodes, *path;
230 const char *waypoints;
231 double distance; /* unit : km */
244 Eina_Bool inbound : 1;
258 struct _Route_Waypoint
275 Eina_Bool download : 1;
277 Ecore_File_Download_Job *job;
284 int tsize; // size of tile (tsize x tsize pixels)
285 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
286 int iw, ih; // size of image in pixels
287 int w, h; // size of grid image in pixels (represented by grid)
288 int gw, gh; // size of grid in tiles
289 Eina_Matrixsparse *grid;
296 Evas_Object *pan_smart;
298 Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
300 Evas_Coord pan_x, pan_y, minw, minh;
305 Elm_Map_Zoom_Mode mode;
308 Ecore_Timer *scr_timer;
309 Ecore_Timer *long_timer;
310 Ecore_Animator *zoom_animator;
311 double t_start, t_end;
321 Evas_Coord x, y ,w ,h;
327 Eina_Bool resized : 1;
328 Eina_Bool longpressed : 1;
329 Eina_Bool on_hold : 1;
330 Eina_Bool paused : 1;
331 Eina_Bool paused_markers : 1;
332 Eina_Bool pinch_zoom : 1;
339 Ecore_Job *markers_place_job;
340 Eina_Matrixsparse *markers[ZOOM_MAX+1];
341 Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
342 Evas_Coord markers_max_num;
343 int marker_max_w, marker_max_h;
345 Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
347 Eina_List *groups_clas; // list of Elm_Map_Group_Class*
348 Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
350 Elm_Map_Sources source;
351 Elm_Map_Route_Sources route_source;
353 Eina_List *s_event_list;
358 const char *user_agent;
364 Eina_Bool (*obj_hook) (Evas_Object *obj);
365 Eina_Bool (*obj_unhook) (Evas_Object *obj);
366 char * (*obj_url_request) (Evas_Object *obj, int x, int y, int zoom);
367 Eina_Bool (*obj_convert_coord_into_geo) (const Evas_Object *obj, int zoom, int x, int y, int size, double *lon, double *lat);
368 Eina_Bool (*obj_convert_geo_into_coord) (const Evas_Object *obj, int zoom, double lon, double lat, int size, int *x, int *y);
372 Evas_Object_Smart_Clipped_Data __clipped_data;
384 Evas_Coord x, y, w, h;
387 Ecore_Timer *hold_timer;
401 enum _Route_Xml_Attribute
405 ROUTE_XML_DESCRIPTION,
406 ROUTE_XML_COORDINATES,
408 } Route_Xml_Attibute;
410 static int dis_old = 0;
411 static const char *widtype = NULL;
413 static const char SIG_CHANGED[] = "changed";
414 static const char SIG_CLICKED[] = "clicked";
415 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
416 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
417 static const char SIG_LOAD_DETAIL[] = "load,detail";
418 static const char SIG_LONGPRESSED[] = "longpressed";
419 static const char SIG_PRESS[] = "press";
420 static const char SIG_SCROLL[] = "scroll";
421 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
422 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
423 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
424 static const char SIG_ZOOM_START[] = "zoom,start";
425 static const char SIG_ZOOM_STOP[] = "zoom,stop";
426 static const char SIG_DOWNLOADED[] = "downloaded";
427 static const char SIG_ROUTE_LOAD[] = "route,load";
428 static const char SIG_ROUTE_LOADED[] = "route,loaded";
429 static const Evas_Smart_Cb_Description _signals[] = {
432 {SIG_CLICKED_DOUBLE, ""},
433 {SIG_LOADED_DETAIL, ""},
434 {SIG_LOAD_DETAIL, ""},
435 {SIG_LONGPRESSED, ""},
438 {SIG_SCROLL_DRAG_START, ""},
439 {SIG_SCROLL_DRAG_STOP, ""},
440 {SIG_ZOOM_CHANGE, ""},
441 {SIG_ZOOM_START, ""},
443 {SIG_DOWNLOADED, ""},
444 {SIG_ROUTE_LOAD, ""},
445 {SIG_ROUTE_LOADED, ""},
449 static void _pan_calculate(Evas_Object *obj);
451 static Eina_Bool _hold_timer_cb(void *data);
452 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
453 static void _del_hook(Evas_Object *obj);
454 static void _theme_hook(Evas_Object *obj);
455 static void _on_focus_hook(void *data, Evas_Object *obj);
456 static void _sizing_eval(Evas_Object *obj);
457 static void _calc_job(void *data);
458 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
459 Evas_Callback_Type type, void *event_info);
460 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);
461 static void grid_clear(Evas_Object *obj, Grid *g);
462 static Grid *grid_create(Evas_Object *obj);
463 static void grid_load(Evas_Object *obj, Grid *g);
466 static void _group_object_create(Marker_Group *group);
467 static void _group_object_free(Marker_Group *group);
468 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
469 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
470 static void _group_bubble_create(Marker_Group *group);
471 static void _group_bubble_free(Marker_Group *group);
472 static void _group_bubble_place(Marker_Group *group);
474 static int _group_bubble_content_update(Marker_Group *group);
475 static void _group_bubble_content_free(Marker_Group *group);
476 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);
477 static void _bubble_sc_hits_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
479 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
480 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
481 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
483 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
484 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
485 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
487 static void route_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
490 get_multi_device(Evas_Object *obj)
492 Widget_Data *wd = elm_widget_data_get(obj);
496 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
498 if (ev->device) return ev->device;
504 get_distance(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
508 return sqrt((dx * dx) + (dy * dy));
512 create_event_object(void *data, Evas_Object *obj, int device)
514 Widget_Data *wd = elm_widget_data_get(data);
515 Event *ev = calloc(1, sizeof(Event));
517 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
521 evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
522 wd->s_event_list = eina_list_append(wd->s_event_list, ev);
527 get_event_object(void *data, int device)
529 Widget_Data *wd = elm_widget_data_get(data);
533 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
535 if (ev->device == device) break;
542 destroy_event_object(void *data, Event *ev)
544 Widget_Data *wd = elm_widget_data_get(data);
545 EINA_SAFETY_ON_NULL_RETURN(ev);
547 wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
550 ecore_timer_del(ev->hold_timer);
551 ev->hold_timer = NULL;
557 module(Evas_Object *obj __UNUSED__)
559 static Elm_Module *m = NULL;
561 if (!(m = _elm_module_find_as("map/api"))) return NULL;
563 m->api = malloc(sizeof(Mod_Api));
564 if (!m->api) return NULL;
565 ((Mod_Api *)(m->api) )->obj_hook =
566 _elm_module_symbol_get(m, "obj_hook");
567 ((Mod_Api *)(m->api) )->obj_unhook =
568 _elm_module_symbol_get(m, "obj_unhook");
569 ((Mod_Api *)(m->api) )->obj_url_request =
570 _elm_module_symbol_get(m, "obj_url_request");
571 ((Mod_Api *)(m->api) )->obj_convert_coord_into_geo =
572 _elm_module_symbol_get(m, "obj_convert_coord_into_geo");
573 ((Mod_Api *)(m->api) )->obj_convert_geo_into_coord =
574 _elm_module_symbol_get(m, "obj_convert_geo_into_coord");
580 route_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
582 ELM_CHECK_WIDTYPE(obj, widtype);
583 Widget_Data *wd = elm_widget_data_get(obj);
586 Eina_List *lr, *lp, *ln;
592 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
594 EINA_LIST_FOREACH(wd->route, lr, r)
596 EINA_LIST_FOREACH(r->path, lp, p)
601 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
602 nodes = eina_list_count(r->nodes);
604 EINA_LIST_FOREACH(r->nodes, ln, n)
606 if ((!wd->zoom) || ((n->idx) &&
607 ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
610 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
611 if ((x >= px - ow) && (x <= (px + ow*2)) &&
612 (y >= py - oh) && (y <= (py + oh*2)))
617 p = eina_list_nth(r->path, n->idx);
618 evas_object_line_xy_set(p, r->x, r->y, x, y);
619 evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
620 evas_object_raise(p);
625 else r->inbound = EINA_FALSE;
629 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
630 if ((x >= px - ow) && (x <= (px + ow*2)) &&
631 (y >= py - oh) && (y <= (py + oh*2)))
635 r->inbound = EINA_TRUE;
637 else r->inbound = EINA_FALSE;
640 r->inbound = EINA_FALSE;
645 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
647 Widget_Data *wd = elm_widget_data_get(obj);
648 Evas_Coord ax, ay, gw, gh, hh, ww;
650 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
657 if ((ww == gw) && (hh == gh)) return;
659 if (ow > gw) ax = (ow - gw) / 2;
660 if (oh > gh) ay = (oh - gh) / 2;
661 evas_object_move(wd->rect,
664 evas_object_resize(wd->rect, gw, gh);
668 wd->show.show = EINA_FALSE;
669 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
674 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)
676 Widget_Data *wd = elm_widget_data_get(obj);
677 Evas_Coord ax, ay, gw, gh, tx, ty;
678 Eina_List *l, *markers;
679 Eina_Matrixsparse_Cell *cell;
684 int g_xx, g_yy, g_hh, g_ww;
687 if (g != eina_list_data_get(wd->grids)) return;
693 if (ow > gw) ax = (ow - gw) / 2;
694 if (oh > gh) ay = (oh - gh) / 2;
696 if (wd->zoom != wd->marker_zoom)
698 EINA_LIST_FREE(wd->cells_displayed, cell)
700 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
702 if (group->obj) _group_object_free(group);
706 wd->marker_zoom = wd->zoom;
708 if ((wd->paused_markers)
709 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
712 g_xx = wd->pan_x / wd->tsize;
713 if (g_xx < 0) g_xx = 0;
714 g_yy = wd->pan_y / wd->tsize;
715 if (g_yy < 0) g_yy = 0;
716 g_ww = ow / wd->tsize + 1;
717 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
718 g_hh = oh / wd->tsize + 1;
719 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
721 //hide groups no more displayed
722 EINA_LIST_FREE(wd->cells_displayed, cell)
724 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
725 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
727 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
729 if (group->obj) _group_object_free(group);
734 for (y = g_yy; y <= g_yy + g_hh; y++)
736 for (x = g_xx; x <= g_xx + g_ww; x++)
738 if (!wd->markers[wd->zoom]) continue;
739 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
741 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
742 markers = eina_matrixsparse_cell_data_get(cell);
743 EINA_LIST_FOREACH(markers, l, group)
745 if (!group->markers) continue;
746 if (group->clas->zoom_displayed > wd->zoom) continue;
753 if (eina_list_count(group->markers) == 1)
755 Elm_Map_Marker *m = eina_list_data_get(group->markers);
756 ww = m->clas->priv.edje_w;
757 hh = m->clas->priv.edje_h;
763 if ((gw != g->w) && (g->w > 0))
766 xx = ((long long )gw * xx) / g->w;
767 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
769 if ((gh != g->h) && (g->h > 0))
772 yy = ((long long)gh * yy) / g->h;
773 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
776 if ((!group->clas->hide)
777 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
778 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
780 if (!group->obj) _group_object_create(group);
782 if (group->update_nbelems)
784 group->update_nbelems = EINA_FALSE;
785 if (eina_list_count(group->markers) > 1)
787 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
788 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
791 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
793 evas_object_move(group->obj,
794 xx - px + ax + ox - ww/2,
795 yy - py + ay + oy - hh/2);
796 if ((!wd->paused_markers) || (group->update_resize))
798 group->update_resize = EINA_FALSE;
799 evas_object_resize(group->obj, ww, hh);
801 if (group->update_raise)
803 group->update_raise = EINA_FALSE;
804 evas_object_raise(group->obj);
805 evas_object_show(group->obj);
807 if (group->bubble) _group_bubble_place(group);
811 _group_object_free(group);
819 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)
821 Widget_Data *wd = elm_widget_data_get(obj);
822 Evas_Coord ax, ay, gw, gh, tx, ty;
831 if (ow > gw) ax = (ow - gw) / 2;
832 if (oh > gh) ay = (oh - gh) / 2;
834 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
835 Eina_Matrixsparse_Cell *cell;
837 EINA_ITERATOR_FOREACH(it, cell)
839 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
845 if ((gw != g->w) && (g->w > 0))
848 xx = ((long long )gw * xx) / g->w;
849 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
851 if ((gh != g->h) && (g->h > 0))
854 yy = ((long long)gh * yy) / g->h;
855 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
857 evas_object_move(gi->img,
861 evas_object_resize(gi->img, ww, hh);
863 /*evas_object_move(gi->txt,
867 evas_object_resize(gi->txt, ww, hh);
870 eina_iterator_free(it);
874 grid_clear(Evas_Object *obj, Grid *g)
876 Widget_Data *wd = elm_widget_data_get(obj);
880 if (!g->grid) return;
882 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
883 Eina_Matrixsparse_Cell *cell;
885 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
886 ecore_file_recursive_rm(buf);
888 EINA_ITERATOR_FOREACH(it, cell)
890 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
891 evas_object_del(gi->img);
892 //evas_object_del(gi->txt);
896 gi->want = EINA_FALSE;
898 if (!wd->preload_num)
900 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
901 "elm,state,busy,stop", "elm");
902 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
908 DBG("DOWNLOAD abort %s", gi->file);
909 ecore_file_download_abort(gi->job);
910 ecore_file_remove(gi->file);
915 eina_stringshare_del(gi->file);
919 eina_matrixsparse_free(g->grid);
920 eina_iterator_free(it);
927 _tile_update(Grid_Item *gi)
929 gi->want = EINA_FALSE;
930 gi->download = EINA_FALSE;
931 evas_object_image_file_set(gi->img, gi->file, NULL);
932 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
933 ecore_file_remove(gi->file);
935 evas_object_show(gi->img);
937 //evas_object_text_text_set(gi->txt, gi->file);
938 //evas_object_show(gi->txt);
940 gi->have = EINA_TRUE;
941 gi->wd->preload_num--;
942 if (!gi->wd->preload_num)
944 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
945 "elm,state,busy,stop", "elm");
946 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
952 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
954 Grid_Item *gi = data;
956 gi->download = EINA_FALSE;
959 DBG("DOWNLOAD done %s", gi->file);
960 if ((gi->want) && (!status)) _tile_update(gi);
964 DBG("Download failed %s (%d) ", gi->file, status);
965 ecore_file_remove(gi->file);
968 gi->wd->finish_num++;
970 evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
974 grid_create(Evas_Object *obj)
976 Widget_Data *wd = elm_widget_data_get(obj);
979 g = calloc(1, sizeof(Grid));
982 g->tsize = wd->tsize;
985 if (g->zoom > map_sources_tab[wd->source].zoom_max) return NULL;
986 if (g->zoom < map_sources_tab[wd->source].zoom_min) return NULL;
988 int size = pow(2.0, wd->zoom);
992 g->w = g->tsize * g->gw;
993 g->h = g->tsize * g->gh;
995 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1001 grid_load(Evas_Object *obj, Grid *g)
1003 Widget_Data *wd = elm_widget_data_get(obj);
1006 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1008 Eina_Matrixsparse_Cell *cell;
1012 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1013 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1018 if ((gw <= 0) || (gh <= 0)) return;
1021 if ((gw != g->w) && (g->w > 0))
1022 size = ((long long)gw * size) / g->w;
1023 if (size < (g->tsize / 2)) return; // else we will load to much tiles
1025 it = eina_matrixsparse_iterator_new(g->grid);
1027 EINA_ITERATOR_FOREACH(it, cell)
1029 gi = eina_matrixsparse_cell_data_get(cell);
1036 if ((gw != g->w) && (g->w > 0))
1039 xx = ((long long )gw * xx) / g->w;
1040 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1042 if ((gh != g->h) && (g->h > 0))
1045 yy = ((long long)gh * yy) / g->h;
1046 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1049 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1050 yy - wd->pan_y + oy,
1052 cvx, cvy, cvw, cvh))
1056 evas_object_hide(gi->img);
1057 //evas_object_hide(gi->txt);
1058 evas_object_image_file_set(gi->img, NULL, NULL);
1059 gi->want = EINA_FALSE;
1060 gi->have = EINA_FALSE;
1064 DBG("DOWNLOAD abort %s", gi->file);
1065 ecore_file_download_abort(gi->job);
1066 ecore_file_remove(gi->file);
1070 gi->download = EINA_FALSE;
1072 if (!wd->preload_num)
1074 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1075 "elm,state,busy,stop", "elm");
1076 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
1083 evas_object_hide(gi->img);
1084 //evas_object_hide(gi->txt);
1085 evas_object_image_preload(gi->img, 1);
1086 evas_object_image_file_set(gi->img, NULL, NULL);
1087 gi->have = EINA_FALSE;
1088 gi->want = EINA_FALSE;
1092 eina_iterator_free(it);
1094 xx = wd->pan_x / size;
1097 yy = wd->pan_y / size;
1101 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1104 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1106 for (y = yy; y <= yy + hh; y++)
1108 for (x = xx; x <= xx + ww; x++)
1110 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1112 if ((!gi) && (g != eina_list_data_get(wd->grids)))
1117 gi = calloc(1, sizeof(Grid_Item));
1118 gi->src.x = x * g->tsize;
1119 gi->src.y = y * g->tsize;
1120 gi->src.w = g->tsize;
1121 gi->src.h = g->tsize;
1123 gi->out.x = gi->src.x;
1124 gi->out.y = gi->src.y;
1125 gi->out.w = gi->src.w;
1126 gi->out.h = gi->src.h;
1130 gi->img = evas_object_image_add(evas_object_evas_get(obj));
1131 evas_object_image_scale_hint_set
1132 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1133 evas_object_image_filled_set(gi->img, 1);
1135 evas_object_smart_member_add(gi->img, wd->pan_smart);
1136 elm_widget_sub_object_add(obj, gi->img);
1137 evas_object_pass_events_set(gi->img, EINA_TRUE);
1138 evas_object_stack_below(gi->img, wd->sep_maps_markers);
1140 /* gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1141 evas_object_text_font_set(gi->txt, "Vera", 12);
1142 evas_object_color_set(gi->txt, 100, 100, 100, 255);
1143 evas_object_smart_member_add(gi->txt,
1145 elm_widget_sub_object_add(obj, gi->txt);
1146 evas_object_pass_events_set(gi->txt, EINA_TRUE);
1148 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1151 if ((!gi->have) && (!gi->download))
1153 char buf[PATH_MAX], buf2[PATH_MAX];
1156 gi->want = EINA_TRUE;
1158 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1159 if (!ecore_file_exists(buf))
1160 ecore_file_mkpath(buf);
1162 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1164 source = map_sources_tab[wd->source].url_cb(obj, x, y, g->zoom);
1165 if ((!source) || (strlen(source)==0)) continue;
1167 eina_stringshare_replace(&gi->file, buf2);
1169 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1171 gi->download = EINA_TRUE;
1173 if (wd->preload_num == 1)
1175 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1176 "elm,state,busy,start", "elm");
1177 evas_object_smart_callback_call(obj,
1182 if (ecore_file_exists(buf2))
1186 DBG("DOWNLOAD %s \t in %s", source, buf2);
1187 ecore_file_download_full(source, buf2, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1189 DBG("Can't start to download %s", buf);
1194 if (source) free(source);
1197 evas_object_show(gi->img);
1203 grid_clearall(Evas_Object *obj)
1205 Widget_Data *wd = elm_widget_data_get(obj);
1209 EINA_LIST_FREE(wd->grids, g)
1217 _smooth_update(Evas_Object *obj)
1219 Widget_Data *wd = elm_widget_data_get(obj);
1224 EINA_LIST_FOREACH(wd->grids, l, g)
1226 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1227 Eina_Matrixsparse_Cell *cell;
1229 EINA_ITERATOR_FOREACH(it, cell)
1231 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1232 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1234 eina_iterator_free(it);
1239 _grid_raise(Grid *g)
1241 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1242 Eina_Matrixsparse_Cell *cell;
1244 g->wd->size.w = g->w;
1245 g->wd->size.h = g->h;
1247 EINA_ITERATOR_FOREACH(it, cell)
1249 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1250 evas_object_raise(gi->img);
1251 //evas_object_raise(gi->txt);
1253 eina_iterator_free(it);
1257 _scr_timeout(void *data)
1259 Widget_Data *wd = elm_widget_data_get(data);
1260 if (!wd) return ECORE_CALLBACK_CANCEL;
1262 if (!wd->nosmooth) _smooth_update(data);
1263 wd->scr_timer = NULL;
1264 return ECORE_CALLBACK_CANCEL;
1268 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1270 Widget_Data *wd = elm_widget_data_get(data);
1275 if (wd->nosmooth == 1) _smooth_update(data);
1277 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1278 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1282 zoom_do(Evas_Object *obj, double t)
1284 Widget_Data *wd = elm_widget_data_get(obj);
1285 Evas_Coord xx, yy, ow, oh;
1288 if (t > 1.0) t = 1.0;
1290 wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
1291 wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
1293 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1295 if (wd->center_on.enabled)
1297 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1303 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1304 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1308 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1310 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1312 wd->show.show = EINA_TRUE;
1318 if (wd->calc_job) ecore_job_del(wd->calc_job);
1319 wd->calc_job = ecore_job_add(_calc_job, wd);
1322 return ECORE_CALLBACK_CANCEL;
1324 return ECORE_CALLBACK_RENEW;
1328 _zoom_anim(void *data)
1330 Evas_Object *obj = data;
1331 Widget_Data *wd = elm_widget_data_get(obj);
1335 if (!wd) return ECORE_CALLBACK_CANCEL;
1336 t = ecore_loop_time_get();
1339 else if (wd->t_end > wd->t_start)
1340 t = (t - wd->t_start) / (wd->t_end - wd->t_start);
1345 go = zoom_do(obj, t);
1349 if (!wd->nosmooth) _smooth_update(data);
1350 wd->zoom_animator = NULL;
1351 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1357 _long_press(void *data)
1359 Widget_Data *wd = elm_widget_data_get(data);
1360 if (!wd) return ECORE_CALLBACK_CANCEL;
1361 wd->long_timer = NULL;
1362 wd->longpressed = EINA_TRUE;
1363 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1364 return ECORE_CALLBACK_CANCEL;
1368 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1370 Widget_Data *wd = elm_widget_data_get(data);
1371 Evas_Event_Mouse_Down *ev = event_info;
1374 ev0 = get_event_object(data, 0);
1376 ev0 = create_event_object(data, obj, 0);
1379 ev0->hold_timer = NULL;
1380 ev0->prev.x = ev->output.x;
1381 ev0->prev.y = ev->output.y;
1384 if (ev->button != 1) return;
1385 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1386 else wd->on_hold = EINA_FALSE;
1387 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1388 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1390 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1391 wd->longpressed = EINA_FALSE;
1392 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1393 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1397 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1399 Widget_Data *wd = elm_widget_data_get(data);
1400 Evas_Event_Mouse_Move *move = event_info;
1403 if (wd->pinch_zoom) return;
1404 ev0 = get_event_object(data, 0);
1406 ev0->prev.x = move->cur.output.x;
1407 ev0->prev.y = move->cur.output.y;
1411 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1413 Widget_Data *wd = elm_widget_data_get(data);
1414 Evas_Event_Mouse_Up *ev = event_info;
1419 ev0 = get_event_object(data, 0);
1422 mdevice = get_multi_device(data);
1425 if (ev0->hold_timer)
1427 ecore_timer_del(ev0->hold_timer);
1428 ev0->hold_timer = NULL;
1430 elm_smart_scroller_hold_set(wd->scr, 0);
1431 elm_smart_scroller_freeze_set(wd->scr, 0);
1432 wd->pinch_zoom = EINA_FALSE;
1436 ev1 = get_event_object(data, mdevice);
1438 ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1440 destroy_event_object(data, ev0);
1444 if (ev->button != 1) return;
1445 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1446 else wd->on_hold = EINA_FALSE;
1449 ecore_timer_del(wd->long_timer);
1450 wd->long_timer = NULL;
1452 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1453 wd->on_hold = EINA_FALSE;
1457 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1459 Widget_Data *wd = elm_widget_data_get(data);
1461 Evas_Event_Multi_Down *down = event_info;
1463 elm_smart_scroller_hold_set(wd->scr, 1);
1464 elm_smart_scroller_freeze_set(wd->scr, 1);
1466 ev = get_event_object(data, down->device);
1469 ev = create_event_object(data, obj, down->device);
1472 DBG("Failed : create_event_object");
1476 wd->pinch_zoom = EINA_FALSE;
1478 ev->hold_timer = NULL;
1479 ev->prev.x = down->output.x;
1480 ev->prev.y = down->output.y;
1487 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1489 Widget_Data *wd = elm_widget_data_get(data);
1490 Evas_Event_Multi_Move *move = event_info;
1495 if (wd->pinch_zoom) return;
1496 ev = get_event_object(data, move->device);
1499 ev->prev.x = move->cur.output.x;
1500 ev->prev.y = move->cur.output.y;
1502 ev0 = get_event_object(data, 0);
1505 dis_new = get_distance(ev0->prev.x, ev0->prev.y, ev->prev.x, ev->prev.y);
1510 if (((dis_old - dis_new) > 0) &&
1511 (ev->pinch_dis > elm_finger_size_get()))
1513 wd->pinch_zoom = EINA_TRUE;
1515 elm_map_zoom_set(data, zoom);
1518 else if (((dis_old - dis_new) < 0) &&
1519 (ev->pinch_dis < -elm_finger_size_get()))
1521 wd->pinch_zoom = EINA_TRUE;
1523 elm_map_zoom_set(data, zoom);
1526 ev->pinch_dis += (dis_old - dis_new);
1532 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1534 Evas_Event_Multi_Up *up = event_info;
1538 ev = get_event_object(data, up->device);
1541 DBG("Cannot get multi device");
1546 ev0 = get_event_object(data, 0);
1548 ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1553 ecore_timer_del(ev->hold_timer);
1554 ev->hold_timer = NULL;
1557 destroy_event_object(data, ev);
1560 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
1563 _hold_timer_cb(void *data)
1567 ev0->hold_timer = NULL;
1568 return ECORE_CALLBACK_CANCEL;
1572 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1574 Widget_Data *wd = elm_widget_data_get(data);
1577 evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
1578 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
1579 evas_object_resize(wd->rect, w, h);
1580 evas_object_move(wd->rect, x, y);
1584 _del_hook(Evas_Object *obj)
1586 Elm_Map_Group_Class *group_clas;
1587 Elm_Map_Marker_Class *marker_clas;
1588 Widget_Data *wd = elm_widget_data_get(obj);
1594 Ecore_Event_Handler *h;
1599 EINA_LIST_FREE(wd->groups_clas, group_clas)
1601 if (group_clas->style)
1602 eina_stringshare_del(group_clas->style);
1606 EINA_LIST_FREE(wd->markers_clas, marker_clas)
1608 if (marker_clas->style)
1609 eina_stringshare_del(marker_clas->style);
1613 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
1615 destroy_event_object(obj, ev);
1618 EINA_LIST_FOREACH(wd->route, l, r)
1620 EINA_LIST_FREE(r->path, p)
1625 EINA_LIST_FREE(r->waypoint, w)
1627 if (w->point) eina_stringshare_del(w->point);
1631 EINA_LIST_FREE(r->nodes, n)
1633 if (n->pos.address) eina_stringshare_del(n->pos.address);
1637 EINA_LIST_FREE(r->handlers, h)
1639 ecore_event_handler_del(h);
1642 if (r->con_url) ecore_con_url_free(r->con_url);
1643 if (r->info.nodes) eina_stringshare_del(r->info.nodes);
1644 if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
1646 if (wd->calc_job) ecore_job_del(wd->calc_job);
1647 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1648 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
1649 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1650 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj);
1651 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
1652 if (wd->ua) eina_hash_free(wd->ua);
1658 _del_pre_hook(Evas_Object *obj)
1660 Marker_Group *group;
1661 Elm_Map_Marker *marker;
1663 Eina_Bool free_marker = EINA_TRUE;
1665 Widget_Data *wd = elm_widget_data_get(obj);
1669 for (i = 0; i < ZOOM_MAX + 1; i++)
1671 if (!wd->markers[i]) continue;
1672 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
1673 Eina_Matrixsparse_Cell *cell;
1675 EINA_ITERATOR_FOREACH(it, cell)
1677 l = eina_matrixsparse_cell_data_get(cell);
1678 EINA_LIST_FREE(l, group)
1680 EINA_LIST_FREE(group->markers, marker)
1682 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1683 _bubble_sc_hits_changed_cb, group);
1684 if (free_marker) free(marker);
1688 free_marker = EINA_FALSE;
1690 eina_iterator_free(it);
1691 eina_matrixsparse_free(wd->markers[i]);
1694 evas_object_del(wd->sep_maps_markers);
1695 evas_object_del(wd->pan_smart);
1696 wd->pan_smart = NULL;
1700 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
1702 Widget_Data *wd = elm_widget_data_get(obj);
1704 if (elm_widget_focus_get(obj))
1706 edje_object_signal_emit(wd->obj, "elm,action,focus", "elm");
1707 evas_object_focus_set(wd->obj, EINA_TRUE);
1711 edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
1712 evas_object_focus_set(wd->obj, EINA_FALSE);
1717 _theme_hook(Evas_Object *obj)
1719 Widget_Data *wd = elm_widget_data_get(obj);
1721 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
1722 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
1727 _sizing_eval(Evas_Object *obj)
1729 Widget_Data *wd = elm_widget_data_get(obj);
1730 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
1732 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
1733 evas_object_size_hint_min_set(obj, minw, minh);
1734 evas_object_size_hint_max_set(obj, maxw, maxh);
1738 _calc_job(void *data)
1740 Widget_Data *wd = data;
1741 Evas_Coord minw, minh;
1748 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
1750 double tz = wd->zoom;
1752 elm_map_zoom_set(wd->obj, tz);
1755 if ((minw != wd->minw) || (minh != wd->minh))
1759 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
1760 _sizing_eval(wd->obj);
1762 wd->calc_job = NULL;
1763 evas_object_smart_changed(wd->pan_smart);
1767 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1769 Pan *sd = evas_object_smart_data_get(obj);
1771 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1774 evas_object_smart_changed(obj);
1778 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1780 Pan *sd = evas_object_smart_data_get(obj);
1782 if (x) *x = sd->wd->pan_x;
1783 if (y) *y = sd->wd->pan_y;
1787 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1789 Pan *sd = evas_object_smart_data_get(obj);
1792 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1793 ow = sd->wd->minw - ow;
1795 oh = sd->wd->minh - oh;
1802 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
1809 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1811 Pan *sd = evas_object_smart_data_get(obj);
1813 if (w) *w = sd->wd->minw;
1814 if (h) *h = sd->wd->minh;
1818 _pan_add(Evas_Object *obj)
1821 Evas_Object_Smart_Clipped_Data *cd;
1823 cd = evas_object_smart_data_get(obj);
1825 sd = calloc(1, sizeof(Pan));
1827 sd->__clipped_data = *cd;
1829 evas_object_smart_data_set(obj, sd);
1833 _pan_del(Evas_Object *obj)
1835 Pan *sd = evas_object_smart_data_get(obj);
1841 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
1843 Pan *sd = evas_object_smart_data_get(obj);
1846 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1847 if ((ow == w) && (oh == h)) return;
1848 sd->wd->resized = 1;
1849 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1850 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1854 _pan_calculate(Evas_Object *obj)
1856 Pan *sd = evas_object_smart_data_get(obj);
1857 Evas_Coord ox, oy, ow, oh;
1861 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
1862 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1863 EINA_LIST_FOREACH(sd->wd->grids, l, g)
1865 grid_load(sd->wd->obj, g);
1866 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1867 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1868 if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
1873 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
1875 Pan *sd = evas_object_smart_data_get(obj);
1877 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1878 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1882 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1884 Widget_Data *wd = elm_widget_data_get(obj);
1886 elm_smart_scroller_hold_set(wd->scr, 1);
1890 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1892 Widget_Data *wd = elm_widget_data_get(obj);
1894 elm_smart_scroller_hold_set(wd->scr, 0);
1898 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1900 Widget_Data *wd = elm_widget_data_get(obj);
1902 elm_smart_scroller_freeze_set(wd->scr, 1);
1906 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1908 Widget_Data *wd = elm_widget_data_get(obj);
1910 elm_smart_scroller_freeze_set(wd->scr, 0);
1914 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1916 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
1920 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1922 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
1926 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1928 Widget_Data *wd = elm_widget_data_get(data);
1929 wd->center_on.enabled = EINA_FALSE;
1930 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1934 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1936 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1940 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1942 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1947 _group_object_create(Marker_Group *group)
1949 const char *style = "radio";
1950 Evas_Object *icon = NULL;
1952 if (group->obj) return;
1953 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
1955 //set icon and style
1956 if (eina_list_count(group->markers) == 1)
1958 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1960 style = m->clas->style;
1962 if (m->clas->func.icon_get)
1963 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
1965 group->delete_object = EINA_TRUE;
1969 if (group->clas->style)
1970 style = group->clas->style;
1972 if (group->clas->func.icon_get)
1973 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
1975 group->delete_object = EINA_FALSE;
1978 group->obj = elm_layout_add(group->wd->obj);
1979 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
1981 if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
1983 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
1984 elm_widget_sub_object_add(group->wd->obj, group->obj);
1985 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
1987 if (!group->delete_object)
1988 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
1992 group->delete_object = EINA_FALSE;
1994 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
1995 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
1996 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
1997 evas_object_show(group->obj);
2000 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2001 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2003 group->update_nbelems = EINA_TRUE;
2004 group->update_resize = EINA_TRUE;
2005 group->update_raise = EINA_TRUE;
2007 if (group->open) _group_bubble_create(group);
2011 _group_object_free(Marker_Group *group)
2013 if (!group->obj) return;
2014 if (!group->delete_object)
2016 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2017 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2018 evas_object_hide(group->obj);
2020 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2021 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2024 evas_object_del(group->obj);
2027 _group_bubble_free(group);
2031 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2033 Marker_Group *group = data;
2035 if (!evas_object_above_get(group->rect)) return;
2036 evas_object_raise(group->bubble);
2037 evas_object_raise(group->sc);
2038 evas_object_raise(group->rect);
2042 _group_bubble_create(Marker_Group *group)
2044 if (group->bubble) return;
2046 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2047 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2048 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2049 elm_widget_style_get(group->wd->obj));
2050 evas_object_smart_member_add(group->bubble,
2052 elm_widget_sub_object_add(group->wd->obj, group->bubble);
2054 _group_bubble_content_free(group);
2055 if (!_group_bubble_content_update(group))
2057 //no content, we can delete the bubble
2058 _group_bubble_free(group);
2062 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2063 evas_object_color_set(group->rect, 0, 0, 0, 0);
2064 evas_object_repeat_events_set(group->rect, EINA_TRUE);
2065 evas_object_smart_member_add(group->rect, group->wd->obj);
2066 elm_widget_sub_object_add(group->wd->obj, group->rect);
2068 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2070 _group_bubble_place(group);
2073 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2075 _group_bubble_place(data);
2079 _group_bubble_content_update(Marker_Group *group)
2082 Elm_Map_Marker *marker;
2085 if (!group->bubble) return 1;
2089 group->sc = elm_scroller_add(group->bubble);
2090 elm_widget_style_set(group->sc, "map_bubble");
2091 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2092 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2093 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2094 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2095 evas_object_show(group->sc);
2096 evas_object_smart_member_add(group->sc,
2098 elm_widget_sub_object_add(group->wd->obj, group->sc);
2100 group->bx = elm_box_add(group->bubble);
2101 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2102 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2103 elm_box_horizontal_set(group->bx, EINA_TRUE);
2104 evas_object_show(group->bx);
2106 elm_scroller_content_set(group->sc, group->bx);
2108 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
2109 _bubble_sc_hits_changed_cb, group);
2112 EINA_LIST_FOREACH(group->markers, l, marker)
2114 if (i >= group->wd->markers_max_num) break;
2115 if ((!marker->content) && (marker->clas->func.get))
2116 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2117 else if (marker->content)
2118 elm_box_unpack(group->bx, marker->content);
2119 if (marker->content)
2121 elm_box_pack_end(group->bx, marker->content);
2129 _group_bubble_content_free(Marker_Group *group)
2132 Elm_Map_Marker *marker;
2134 if (!group->sc) return;
2135 EINA_LIST_FOREACH(group->markers, l, marker)
2137 if ((marker->content) && (marker->clas->func.del))
2138 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2139 else if (marker->content)
2140 evas_object_del(marker->content);
2141 marker->content = NULL;
2143 evas_object_del(group->sc);
2148 _group_bubble_free(Marker_Group *group)
2150 if (!group->bubble) return;
2151 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2152 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2153 _bubble_sc_hits_changed_cb, group);
2154 evas_object_del(group->bubble);
2155 evas_object_del(group->rect);
2156 group->bubble = NULL;
2157 _group_bubble_content_free(group);
2161 _group_bubble_place(Marker_Group *group)
2164 Evas_Coord xx, yy, ww, hh;
2167 if ((!group->bubble) || (!group->obj)) return;
2169 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2170 edje_object_size_min_calc(group->bubble, NULL, &hh);
2172 s = edje_object_data_get(group->bubble, "size_w");
2173 if (s) ww = atoi(s);
2175 xx = x + w / 2 - ww / 2;
2178 evas_object_move(group->bubble, xx, yy);
2179 evas_object_resize(group->bubble, ww, hh);
2180 evas_object_show(group->bubble);
2182 evas_object_move(group->rect, xx, yy);
2183 evas_object_resize(group->rect, ww, hh);
2184 evas_object_show(group->rect);
2188 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2190 Marker_Group *group = data;
2191 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2192 if (!marker) return;
2193 group->bringin = EINA_TRUE;
2194 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2198 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2200 Marker_Group *group = data;
2204 group->bringin = EINA_FALSE;
2210 group->open = EINA_FALSE;
2211 _group_bubble_free(group);
2214 group->open = EINA_TRUE;
2215 _group_bubble_create(group);
2219 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2224 Evas_Coord step_x = 0;
2225 Evas_Coord step_y = 0;
2228 Evas_Coord page_x = 0;
2229 Evas_Coord page_y = 0;
2231 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2232 Evas_Event_Key_Down *ev = event_info;
2233 Widget_Data *wd = elm_widget_data_get(obj);
2234 if (!wd) return EINA_FALSE;
2235 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2237 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2238 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2239 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2240 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2242 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2246 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2250 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2254 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2258 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2261 y -= -(page_y * v_h) / 100;
2265 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2268 y += -(page_y * v_h) / 100;
2272 else if (!strcmp(ev->keyname, "KP_Add"))
2274 zoom = elm_map_zoom_get(obj);
2276 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2277 elm_map_zoom_set(obj, zoom);
2280 else if (!strcmp(ev->keyname, "KP_Subtract"))
2282 zoom = elm_map_zoom_get(obj);
2284 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2285 elm_map_zoom_set(obj, zoom);
2288 else return EINA_FALSE;
2290 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2291 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2297 cb_dump_attrs(void *data __UNUSED__, const char *key __UNUSED__, const char *value __UNUSED__)
2304 cb_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2306 Route_Dump *dump = data;
2310 case EINA_SIMPLE_XML_OPEN:
2311 case EINA_SIMPLE_XML_OPEN_EMPTY:
2315 attrs = eina_simple_xml_tag_attributes_find(value, length);
2318 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2319 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2320 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2321 else dump->id = ROUTE_XML_NONE;
2325 eina_simple_xml_attributes_parse
2326 (attrs, length - (attrs - value), cb_dump_attrs, dump);
2330 case EINA_SIMPLE_XML_DATA:
2332 char *buf = malloc(length);
2333 if (!buf) return EINA_FALSE;
2334 snprintf(buf, length, "%s", value);
2335 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2336 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2337 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2349 _parse_kml(void *data)
2351 Elm_Map_Route *r = (Elm_Map_Route*)data;
2352 if (!r && !r->ud.fname) return;
2356 unsigned int ele, idx;
2360 Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2362 f = fopen(r->ud.fname, "rb");
2367 fseek(f, 0, SEEK_END);
2373 fseek(f, 0, SEEK_SET);
2377 if (fread(buf, 1, sz, f))
2379 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_dump, &dump);
2386 if (dump.distance) r->info.distance = dump.distance;
2387 if (dump.description)
2389 eina_stringshare_replace(&r->info.waypoints, dump.description);
2390 str = eina_str_split_full(dump.description, "\n", 0, &ele);
2391 r->info.waypoint_count = ele;
2392 for (idx = 0 ; idx < ele ; idx++)
2394 Route_Waypoint *wp = ELM_NEW(Route_Waypoint);
2398 wp->point = eina_stringshare_add(str[idx]);
2399 DBG("%s", str[idx]);
2400 r->waypoint = eina_list_append(r->waypoint, wp);
2409 else WRN("description is not found !");
2411 if (dump.coordinates)
2413 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2414 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2415 r->info.node_count = ele;
2416 for (idx = 0 ; idx < ele ; idx++)
2418 sscanf(str[idx], "%lf,%lf", &lon, &lat);
2419 Route_Node *n = ELM_NEW(Route_Node);
2426 DBG("%lf:%lf", lon, lat);
2427 n->pos.address = NULL;
2428 r->nodes = eina_list_append(r->nodes, n);
2430 path = evas_object_line_add(evas_object_evas_get(r->wd->obj));
2431 evas_object_smart_member_add(path, r->wd->pan_smart);
2432 r->path = eina_list_append(r->path, path);
2445 _common_complete_cb(void *data, int ev_type __UNUSED__, void *event)
2447 Ecore_Con_Event_Url_Complete *ev = event;
2448 Elm_Map_Route *r = (Elm_Map_Route*)data;
2449 Widget_Data *wd = r->wd;
2451 if ((!r) || (!ev)) return EINA_TRUE;
2452 Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
2453 ecore_con_url_data_set(r->con_url, NULL);
2454 if (r!=rr) return EINA_TRUE;
2456 if (r->ud.fd) fclose(r->ud.fd);
2461 Evas_Coord ox, oy, ow, oh;
2462 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
2463 route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
2465 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
2466 "elm,state,busy,stop", "elm");
2467 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
2471 static int idnum = 1;
2474 * Add a new Map object
2476 * @param parent The parent object
2477 * @return The new object or NULL if it cannot be created
2482 elm_map_add(Evas_Object *parent)
2486 Evas_Coord minw, minh;
2488 static Evas_Smart *smart = NULL;
2489 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
2491 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2493 ELM_SET_WIDTYPE(widtype, "map");
2494 elm_widget_type_set(obj, "map");
2495 elm_widget_sub_object_add(parent, obj);
2496 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2497 elm_widget_data_set(obj, wd);
2498 elm_widget_del_hook_set(obj, _del_hook);
2499 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2500 elm_widget_theme_hook_set(obj, _theme_hook);
2501 elm_widget_can_focus_set(obj, EINA_TRUE);
2502 elm_widget_event_hook_set(obj, _event_hook);
2504 wd->scr = elm_smart_scroller_add(e);
2505 elm_smart_scroller_widget_set(wd->scr, obj);
2506 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
2507 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
2508 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
2509 elm_widget_resize_object_set(obj, wd->scr);
2511 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
2512 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
2513 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
2514 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
2515 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
2517 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
2519 wd->api = module(obj);
2520 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2524 wd->markers_max_num = 30;
2525 wd->source = ELM_MAP_SOURCE_MAPNIK;
2527 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2528 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2529 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2530 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2534 static Evas_Smart_Class sc;
2536 evas_object_smart_clipped_smart_set(&_pan_sc);
2538 sc.name = "elm_map_pan";
2539 sc.version = EVAS_SMART_CLASS_VERSION;
2542 sc.resize = _pan_resize;
2543 sc.move = _pan_move;
2544 sc.calculate = _pan_calculate;
2545 smart = evas_smart_class_new(&sc);
2549 wd->pan_smart = evas_object_smart_add(e, smart);
2550 wd->pan = evas_object_smart_data_get(wd->pan_smart);
2554 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2555 _pan_set, _pan_get, _pan_max_get,
2556 _pan_min_get, _pan_child_size_get);
2558 wd->rect = evas_object_rectangle_add(e);
2559 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
2560 _rect_resize_cb, obj);
2561 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
2563 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
2565 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
2567 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
2568 _mouse_multi_down, obj);
2569 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
2570 _mouse_multi_move, obj);
2571 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
2572 _mouse_multi_up, obj);
2574 evas_object_smart_member_add(wd->rect, wd->pan_smart);
2575 elm_widget_sub_object_add(obj, wd->rect);
2576 evas_object_show(wd->rect);
2577 evas_object_color_set(wd->rect, 0, 0, 0, 0);
2580 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2582 wd->id = ((int)getpid() << 16) | idnum;
2587 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
2589 evas_object_size_hint_min_set(obj, minw, minh);
2591 wd->paused = EINA_TRUE;
2592 elm_map_zoom_set(obj, 0);
2593 wd->paused = EINA_FALSE;
2597 wd->calc_job = ecore_job_add(_calc_job, wd);
2599 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
2600 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
2602 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2603 // TODO: and save some bytes, making descriptions per-class and not instance!
2604 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2606 if (!ecore_file_download_protocol_available("http://"))
2608 ERR("Ecore must be built with curl support for the map widget!");
2614 * Set the zoom level of the map
2616 * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
2618 * @param obj The map object
2619 * @param zoom The zoom level to set
2624 elm_map_zoom_set(Evas_Object *obj, int zoom)
2626 ELM_CHECK_WIDTYPE(obj, widtype);
2627 Widget_Data *wd = elm_widget_data_get(obj);
2629 Grid *g, *g_zoom = NULL;
2630 Evas_Coord rx, ry, rw, rh;
2634 int zoom_changed = 0, started = 0;
2637 if (zoom < 0 ) zoom = 0;
2638 if (zoom > map_sources_tab[wd->source].zoom_max)
2639 zoom = map_sources_tab[wd->source].zoom_max;
2640 if (zoom < map_sources_tab[wd->source].zoom_min)
2641 zoom = map_sources_tab[wd->source].zoom_min;
2642 if (zoom == wd->zoom) return;
2645 wd->size.ow = wd->size.w;
2646 wd->size.oh = wd->size.h;
2647 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
2648 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2650 EINA_LIST_FOREACH(wd->route, lr, r)
2654 EINA_LIST_FOREACH(r->path, l, p)
2656 evas_object_hide(p);
2661 if (wd->mode == ELM_MAP_ZOOM_MODE_MANUAL)
2663 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2664 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2666 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
2673 while (cumulw <= rw)
2682 while (cumulh <= rh)
2695 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2696 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2698 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
2705 while (cumulw <= rw)
2714 while (cumulh <= rh)
2727 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
2728 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
2731 EINA_LIST_FOREACH(wd->grids, l, g)
2733 if (g->zoom == wd->zoom)
2735 wd->grids = eina_list_remove(wd->grids, g);
2736 wd->grids = eina_list_prepend(wd->grids, g);
2741 g = grid_create(obj);
2744 if (eina_list_count(wd->grids) > 1)
2746 g_zoom = eina_list_last(wd->grids)->data;
2747 wd->grids = eina_list_remove(wd->grids, g_zoom);
2748 grid_clear(obj, g_zoom);
2751 wd->grids = eina_list_prepend(wd->grids, g);
2755 EINA_LIST_FREE(wd->grids, g)
2763 wd->t_start = ecore_loop_time_get();
2764 wd->t_end = wd->t_start + _elm_config->zoom_friction;
2765 if ((wd->size.w > 0) && (wd->size.h > 0))
2767 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
2768 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
2772 wd->size.spos.x = 0.5;
2773 wd->size.spos.y = 0.5;
2775 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
2776 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
2777 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
2778 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
2785 if (!wd->zoom_animator)
2787 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
2789 if (wd->nosmooth == 1) _smooth_update(obj);
2793 if (wd->zoom_animator)
2795 if (!_zoom_anim(obj))
2797 ecore_animator_del(wd->zoom_animator);
2798 wd->zoom_animator = NULL;
2801 if (wd->calc_job) ecore_job_del(wd->calc_job);
2802 wd->calc_job = ecore_job_add(_calc_job, wd);
2806 evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
2807 if (!wd->zoom_animator)
2808 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2812 evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
2816 * Get the zoom level of the photo
2818 * This returns the current zoom level of the map object. Note that if
2819 * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
2820 * (which is the default), the zoom level may be changed at any time by the
2821 * map object itself to account for map size and map viewpoer size
2823 * @param obj The map object
2824 * @return The current zoom level
2829 elm_map_zoom_get(const Evas_Object *obj)
2831 ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
2832 Widget_Data *wd = elm_widget_data_get(obj);
2833 if (!wd) return 1.0;
2840 * This sets the zoom mode to manual or one of several automatic levels.
2841 * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
2842 * elm_map_zoom_set() and will stay at that level until changed by code
2843 * or until zoom mode is changed. This is the default mode.
2844 * The Automatic modes will allow the map object to automatically
2845 * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT) will
2846 * adjust zoom so the photo fits inside the scroll frame with no pixels
2847 * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
2848 * 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.
2850 * @param obj The map object
2851 * @param mode The desired mode
2856 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
2858 ELM_CHECK_WIDTYPE(obj, widtype);
2859 Widget_Data *wd = elm_widget_data_get(obj);
2861 if (wd->mode == mode) return;
2864 double tz = wd->zoom;
2866 elm_map_zoom_set(wd->obj, tz);
2873 * This gets the current zoom mode of the map object
2875 * @param obj The map object
2876 * @return The current zoom mode
2880 EAPI Elm_Map_Zoom_Mode
2881 elm_map_zoom_mode_get(const Evas_Object *obj)
2883 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
2884 Widget_Data *wd = elm_widget_data_get(obj);
2885 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
2890 * Centers the map at @p lon @p lat using an animation to scroll.
2892 * @param obj The map object
2893 * @param lon Longitude to center at
2894 * @param lon Latitude to center at
2899 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
2901 ELM_CHECK_WIDTYPE(obj, widtype);
2902 Widget_Data *wd = elm_widget_data_get(obj);
2906 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
2907 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2912 if (wd->zoom_animator)
2915 if (!wd->nosmooth) _smooth_update(obj);
2916 ecore_animator_del(wd->zoom_animator);
2917 wd->zoom_animator = NULL;
2919 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2921 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
2923 wd->center_on.enabled = EINA_TRUE;
2924 wd->center_on.lon = lon;
2925 wd->center_on.lat = lat;
2929 * Move the map to the current coordinates.
2931 * This move the map to the current coordinates. The map will be centered on these coordinates.
2933 * @param obj The map object
2934 * @param lat The latitude.
2935 * @param lon The longitude.
2940 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
2942 ELM_CHECK_WIDTYPE(obj, widtype);
2943 Widget_Data *wd = elm_widget_data_get(obj);
2947 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
2948 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
2953 if (wd->zoom_animator)
2956 ecore_animator_del(wd->zoom_animator);
2957 wd->zoom_animator = NULL;
2959 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
2961 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
2963 wd->center_on.enabled = EINA_TRUE;
2964 wd->center_on.lon = lon;
2965 wd->center_on.lat = lat;
2969 * Get the current coordinates of the map.
2971 * This gets the current coordinates of the map object.
2973 * @param obj The map object
2974 * @param lat The latitude.
2975 * @param lon The longitude.
2980 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
2982 ELM_CHECK_WIDTYPE(obj, widtype);
2983 Widget_Data *wd = elm_widget_data_get(obj);
2984 Evas_Coord sx, sy, sw, sh;
2987 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
2988 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
2992 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
2996 * Set the paused state for map
2998 * This sets the paused state to on (1) or off (0) for map. The default
2999 * is off. This will stop zooming using animation change zoom levels and
3000 * change instantly. This will stop any existing animations that are running.
3002 * @param obj The map object
3003 * @param paused The pause state to set
3008 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3010 ELM_CHECK_WIDTYPE(obj, widtype);
3011 Widget_Data *wd = elm_widget_data_get(obj);
3013 if (wd->paused == !!paused) return;
3014 wd->paused = paused;
3017 if (wd->zoom_animator)
3019 ecore_animator_del(wd->zoom_animator);
3020 wd->zoom_animator = NULL;
3022 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3028 * Set the paused state for the markers
3030 * This sets the paused state to on (1) or off (0) for the markers. The default
3031 * is off. This will stop displaying the markers during change zoom levels. Set
3032 * to on if you have a large number of markers.
3034 * @param obj The map object
3035 * @param paused The pause state to set
3040 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3042 ELM_CHECK_WIDTYPE(obj, widtype);
3043 Widget_Data *wd = elm_widget_data_get(obj);
3045 if (wd->paused_markers == !!paused) return;
3046 wd->paused_markers = paused;
3050 * Get the paused state for map
3052 * This gets the current paused state for the map object.
3054 * @param obj The map object
3055 * @return The current paused state
3060 elm_map_paused_get(const Evas_Object *obj)
3062 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3063 Widget_Data *wd = elm_widget_data_get(obj);
3064 if (!wd) return EINA_FALSE;
3069 * Get the paused state for the markers
3071 * This gets the current paused state for the markers object.
3073 * @param obj The map object
3074 * @return The current paused state
3079 elm_map_paused_markers_get(const Evas_Object *obj)
3081 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3082 Widget_Data *wd = elm_widget_data_get(obj);
3083 if (!wd) return EINA_FALSE;
3084 return wd->paused_markers;
3088 * Get the information of downloading status
3090 * This gets the current downloading status for the map object.
3092 * @param obj The map object
3093 * @param try_num the number of download trying map
3094 * @param finish_num the number of downloaded map
3100 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3102 ELM_CHECK_WIDTYPE(obj, widtype);
3103 Widget_Data *wd = elm_widget_data_get(obj);
3108 *try_num = wd->try_num;
3113 *finish_num = wd->finish_num;
3117 * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
3119 * @param obj The map object
3120 * @param x the coordinate
3121 * @param y the coordinate
3122 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3123 * @param lon the longitude correspond to x
3124 * @param lat the latitude correspond to y
3129 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3131 Widget_Data *wd = elm_widget_data_get(obj);
3132 int zoom = floor(log(size/256) / log(2));
3134 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
3135 if ((wd->api) && (wd->api->obj_convert_coord_into_geo))
3136 if (wd->api->obj_convert_coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3140 *lon = x / (double)size * 360.0 - 180;
3144 double n = ELM_PI - 2.0 * ELM_PI * y / size;
3145 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3150 * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
3152 * @param obj The map object
3153 * @param lon the longitude
3154 * @param lat the latitude
3155 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3156 * @param x the coordinate correspond to the longitude
3157 * @param y the coordinate correspond to the latitude
3162 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3164 Widget_Data *wd = elm_widget_data_get(obj);
3165 int zoom = floor(log(size/256) / log(2));
3167 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
3168 if ((wd->api) && (wd->api->obj_convert_geo_into_coord))
3169 if (wd->api->obj_convert_geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3172 *x = floor((lon + 180.0) / 360.0 * size);
3174 *y = floor((1.0 - log( tan(lat * ELM_PI/180.0) + 1.0 / cos(lat * ELM_PI/180.0)) / ELM_PI) / 2.0 * size);
3180 * Add a marker on the map
3182 * @param obj The map object
3183 * @param lon the longitude
3184 * @param lat the latitude
3185 * @param clas the class to use
3186 * @param data the data passed to the callbacks
3188 * @return The marker object
3192 EAPI Elm_Map_Marker *
3193 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3197 Marker_Group *group;
3198 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3199 Widget_Data *wd = elm_widget_data_get(obj);
3207 if (!wd) return NULL;
3208 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3209 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3211 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3214 marker->clas = clas;
3215 marker->clas_group = clas_group;
3216 marker->longitude = lon;
3217 marker->latitude = lat;
3218 marker->data = data;
3220 tabi[1] = tabi[4] = tabi[6] = -1;
3221 tabi[2] = tabi[0] = tabi[7] = 0;
3222 tabi[3] = tabi[5] = tabi[8] = 1;
3224 tabj[1] = tabj[2] = tabj[3] = -1;
3225 tabj[4] = tabj[0] = tabj[5] = 0;
3226 tabj[6] = tabj[7] = tabj[8] = 1;
3228 if (!clas_group->priv.set)
3231 if (marker->clas_group && marker->clas_group->style)
3232 style = marker->clas_group->style;
3234 o = edje_object_add(evas_object_evas_get(obj));
3235 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3236 s = edje_object_data_get(o, "size_w");
3237 if (s) clas_group->priv.edje_w = atoi(s);
3238 else clas_group->priv.edje_w = 0;
3239 s = edje_object_data_get(o, "size_h");
3240 if (s) clas_group->priv.edje_h = atoi(s);
3241 else clas_group->priv.edje_h = 0;
3242 s = edje_object_data_get(o, "size_max_w");
3243 if (s) clas_group->priv.edje_max_w = atoi(s);
3244 else clas_group->priv.edje_max_w = 0;
3245 s = edje_object_data_get(o, "size_max_h");
3246 if (s) clas_group->priv.edje_max_h = atoi(s);
3247 else clas_group->priv.edje_max_h = 0;
3250 clas_group->priv.set = EINA_TRUE;
3253 if (!clas->priv.set)
3256 if (marker->clas && marker->clas->style)
3257 style = marker->clas->style;
3259 o = edje_object_add(evas_object_evas_get(obj));
3260 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3261 s = edje_object_data_get(o, "size_w");
3262 if (s) clas->priv.edje_w = atoi(s);
3263 else clas->priv.edje_w = 0;
3264 s = edje_object_data_get(o, "size_h");
3265 if (s) clas->priv.edje_h = atoi(s);
3266 else clas->priv.edje_h = 0;
3269 clas->priv.set = EINA_TRUE;
3272 for (i = clas_group->zoom_displayed; i <= ZOOM_MAX; i++)
3274 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3275 &(marker->x[i]), &(marker->y[i]));
3277 //search in the matrixsparse the region where the marker will be
3278 mpi = marker->x[i] / wd->tsize;
3279 mpj = marker->y[i] / wd->tsize;
3281 if (!wd->markers[i])
3283 int size = pow(2.0, i);
3284 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
3288 if (i <= clas_group->zoom_grouped)
3290 for (j = 0, group = NULL; j < 9 && !group; j++)
3292 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
3295 if (group->clas == marker->clas_group
3296 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
3297 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
3298 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
3300 group->markers = eina_list_append(group->markers, marker);
3301 group->update_nbelems = EINA_TRUE;
3302 group->update_resize = EINA_TRUE;
3304 group->sum_x += marker->x[i];
3305 group->sum_y += marker->y[i];
3306 group->x = group->sum_x / eina_list_count(group->markers);
3307 group->y = group->sum_y / eina_list_count(group->markers);
3309 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
3310 * eina_list_count(group->markers);
3311 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
3312 * eina_list_count(group->markers);
3313 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
3314 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
3316 if (group->obj && eina_list_count(group->markers) == 2)
3318 _group_object_free(group);
3319 _group_object_create(group);
3322 _group_bubble_content_update(group);
3331 group = calloc(1, sizeof(Marker_Group));
3333 group->sum_x = marker->x[i];
3334 group->sum_y = marker->y[i];
3335 group->x = marker->x[i];
3336 group->y = marker->y[i];
3337 group->w = clas_group->priv.edje_w;
3338 group->h = clas_group->priv.edje_h;
3339 group->clas = clas_group;
3341 group->markers = eina_list_append(group->markers, marker);
3342 group->update_nbelems = EINA_TRUE;
3343 group->update_resize = EINA_TRUE;
3345 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3349 l = eina_list_append(NULL, group);
3350 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
3351 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3355 l = eina_matrixsparse_cell_data_get(group->cell);
3356 l = eina_list_append(l, group);
3357 eina_matrixsparse_cell_data_set(group->cell, l);
3360 marker->groups[i] = group;
3365 Evas_Coord ox, oy, ow, oh;
3366 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3367 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3374 * Remove a marker from the map
3376 * @param marker The marker to remove
3381 elm_map_marker_remove(Elm_Map_Marker *marker)
3387 EINA_SAFETY_ON_NULL_RETURN(marker);
3390 for (i = marker->clas_group->zoom_displayed; i <= ZOOM_MAX; i++)
3392 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
3393 if (!eina_list_count(marker->groups[i]->markers))
3395 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
3396 groups = eina_list_remove(groups, marker->groups[i]);
3397 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
3399 _group_object_free(marker->groups[i]);
3400 _group_bubble_free(marker->groups[i]);
3401 free(marker->groups[i]);
3405 marker->groups[i]->sum_x -= marker->x[i];
3406 marker->groups[i]->sum_y -= marker->y[i];
3408 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
3409 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
3411 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
3412 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
3413 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
3414 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
3415 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
3416 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
3417 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
3418 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
3420 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
3422 _group_object_free(marker->groups[i]);
3423 _group_object_create(marker->groups[i]);
3428 if ((marker->content) && (marker->clas->func.del))
3429 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
3430 else if (marker->content)
3431 evas_object_del(marker->content);
3437 Evas_Coord ox, oy, ow, oh;
3438 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3439 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3444 * Get the current coordinates of the marker.
3446 * @param marker marker.
3447 * @param lat The latitude.
3448 * @param lon The longitude.
3453 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
3455 EINA_SAFETY_ON_NULL_RETURN(marker);
3456 if (lon) *lon = marker->longitude;
3457 if (lat) *lat = marker->latitude;
3461 * Move the map to the coordinate of the marker.
3463 * @param marker The marker where the map will be center.
3468 elm_map_marker_bring_in(Elm_Map_Marker *marker)
3470 EINA_SAFETY_ON_NULL_RETURN(marker);
3471 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
3475 * Move the map to the coordinate of the marker.
3477 * @param marker The marker where the map will be center.
3482 elm_map_marker_show(Elm_Map_Marker *marker)
3484 EINA_SAFETY_ON_NULL_RETURN(marker);
3485 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
3489 * Move and zoom the map to display a list of markers.
3491 * The map will be centered on the center point of the markers in the list. Then
3492 * the map will be zoomed in order to fit the markers using the maximum zoom which
3493 * allows display of all the markers.
3495 * @param markers The list of markers (list of Elm_Map_Marker *)
3500 elm_map_markers_list_show(Eina_List *markers)
3505 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
3506 Evas_Coord rw, rh, xc, yc;
3509 EINA_SAFETY_ON_NULL_RETURN(markers);
3511 EINA_LIST_FOREACH(markers, l, marker)
3515 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
3518 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
3521 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
3524 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
3528 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
3529 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
3531 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3532 for (zoom = map_sources_tab[wd->source].zoom_max; zoom>map_sources_tab[wd->source].zoom_min; zoom--)
3534 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
3535 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
3537 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
3538 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
3539 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
3540 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
3544 elm_map_geo_region_show(wd->obj, lon, lat);
3545 elm_map_zoom_set(wd->obj, zoom);
3549 * Set the maximum numbers of markers display in a group.
3551 * A group can have a long list of markers, consequently the creation of the content
3552 * of the bubble can be very slow. In order to avoid this, a maximum number of items
3553 * is displayed in a bubble. By default this number is 30.
3555 * @param obj The map object.
3556 * @param max The maximum numbers of items displayed in a bubble.
3561 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
3563 ELM_CHECK_WIDTYPE(obj, widtype);
3564 Widget_Data *wd = elm_widget_data_get(obj);
3566 wd->markers_max_num = max;
3570 * Return the evas object getting from the ElmMapMarkerGetFunc callback
3572 * @param marker The marker.
3573 * @return Return the evas object if it exists, else NULL.
3578 elm_map_marker_object_get(const Elm_Map_Marker *marker)
3580 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
3581 return marker->content;
3587 * @param marker The marker.
3592 elm_map_marker_update(Elm_Map_Marker *marker)
3594 EINA_SAFETY_ON_NULL_RETURN(marker);
3595 if (marker->content)
3597 if (marker->clas->func.del)
3598 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
3600 evas_object_del(marker->content);
3601 marker->content = NULL;
3602 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
3607 * Close all opened bubbles
3609 * @param obj The map object
3614 elm_map_bubbles_close(Evas_Object *obj)
3616 ELM_CHECK_WIDTYPE(obj, widtype);
3617 Widget_Data *wd = elm_widget_data_get(obj);
3618 Marker_Group *group;
3619 Eina_List *l, *l_next;
3621 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
3622 _group_bubble_free(group);
3627 * Create a group class.
3629 * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
3630 * The group class defines the style of the marker when a marker is grouped to others markers.
3632 * @param obj The map object
3633 * @return Returns the new group class
3637 EAPI Elm_Map_Group_Class *
3638 elm_map_group_class_new(Evas_Object *obj)
3640 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3641 Widget_Data *wd = elm_widget_data_get(obj);
3642 if (!wd) return NULL;
3643 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
3644 clas->zoom_grouped = ZOOM_MAX;
3645 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
3650 * Set the style of a group class (radio, radio2 or empty)
3652 * @param clas the group class
3653 * @param style the new style
3658 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
3660 EINA_SAFETY_ON_NULL_RETURN(clas);
3661 eina_stringshare_replace(&clas->style, style);
3665 * Set the icon callback of a group class.
3667 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
3669 * @param clas the group class
3670 * @param icon_get the callback to create the icon
3675 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
3677 EINA_SAFETY_ON_NULL_RETURN(clas);
3678 clas->func.icon_get = icon_get;
3682 * Set the data associated to the group class (radio, radio2 or empty)
3684 * @param clas the group class
3685 * @param data the new user data
3690 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
3692 EINA_SAFETY_ON_NULL_RETURN(clas);
3697 * Set the zoom from where the markers are displayed.
3699 * Markers will not be displayed for a zoom less than @ref zoom
3701 * @param clas the group class
3702 * @param zoom the zoom
3707 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
3709 EINA_SAFETY_ON_NULL_RETURN(clas);
3710 clas->zoom_displayed = zoom;
3714 * Set the zoom from where the markers are no more grouped.
3716 * @param clas the group class
3717 * @param zoom the zoom
3722 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
3724 EINA_SAFETY_ON_NULL_RETURN(clas);
3725 clas->zoom_grouped = zoom;
3729 * Set if the markers associated to the group class @clas are hidden or not.
3730 * If @ref hide is true the markers will be hidden.
3732 * @param clas the group class
3733 * @param hide if true the markers will be hidden, else they will be displayed.
3738 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
3740 ELM_CHECK_WIDTYPE(obj, widtype);
3741 Widget_Data *wd = elm_widget_data_get(obj);
3743 EINA_SAFETY_ON_NULL_RETURN(clas);
3744 if (clas->hide == hide) return;
3748 Evas_Coord ox, oy, ow, oh;
3749 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3750 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3756 * Create a marker class.
3758 * Each marker must be associated to a class.
3759 * The class defines the style of the marker when a marker is displayed alone (not grouped).
3761 * @param obj The map object
3762 * @return Returns the new class
3766 EAPI Elm_Map_Marker_Class *
3767 elm_map_marker_class_new(Evas_Object *obj)
3769 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3770 Widget_Data *wd = elm_widget_data_get(obj);
3771 if (!wd) return NULL;
3772 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
3773 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
3778 * Set the style of a class (radio, radio2 or empty)
3780 * @param clas the group class
3781 * @param style the new style
3786 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
3788 EINA_SAFETY_ON_NULL_RETURN(clas);
3789 eina_stringshare_replace(&clas->style, style);
3793 * Set the icon callback of a class.
3795 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
3797 * @param clas the group class
3798 * @param icon_get the callback to create the icon
3803 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
3805 EINA_SAFETY_ON_NULL_RETURN(clas);
3806 clas->func.icon_get = icon_get;
3811 * Set the callback of the content of the bubble.
3813 * When the user click on a marker, a bubble is displayed with a content.
3814 * The callback @ref get musst return this content. It can be NULL.
3816 * @param clas the group class
3817 * @param get the callback to create the content
3822 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
3824 EINA_SAFETY_ON_NULL_RETURN(clas);
3825 clas->func.get = get;
3829 * Set the callback of the content of delete the object created by the callback "get".
3831 * If this callback is defined the user will have to delete (or not) the object inside.
3832 * If the callback is not defined the object will be destroyed with evas_object_del()
3834 * @param clas the group class
3835 * @param del the callback to delete the content
3840 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
3842 EINA_SAFETY_ON_NULL_RETURN(clas);
3843 clas->func.del = del;
3847 * Set the source of the map.
3849 * Elm_Map retrieves the image which composed the map from a web service. This web service can
3850 * be set with this method. A different service can return a different maps with different
3851 * information and it can use different zoom value.
3853 * @param clas the group class
3854 * @param source the new source
3859 elm_map_source_set(Evas_Object *obj, Elm_Map_Sources source)
3861 ELM_CHECK_WIDTYPE(obj, widtype);
3862 Widget_Data *wd = elm_widget_data_get(obj);
3866 if (wd->source == source ) return;
3867 if (!map_sources_tab[source].url_cb) return;
3869 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
3871 wd->source = source;
3875 if (map_sources_tab[wd->source].zoom_max < zoom)
3876 zoom = map_sources_tab[wd->source].zoom_max;
3877 if (map_sources_tab[wd->source].zoom_min > zoom)
3878 zoom = map_sources_tab[wd->source].zoom_min;
3880 elm_map_zoom_set(obj, zoom);
3884 * Set the source of the route.
3886 * @param clas the group class
3887 * @param source the new source
3892 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source __UNUSED__)
3894 ELM_CHECK_WIDTYPE(obj, widtype);
3898 * Get the current source
3900 * @param obj the map object
3901 * @return Returns the maximum zoom of the source
3905 EAPI Elm_Map_Sources
3906 elm_map_source_get(const Evas_Object *obj)
3908 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_SOURCE_MAPNIK;
3909 Widget_Data *wd = elm_widget_data_get(obj);
3910 if (!wd) return ELM_MAP_SOURCE_MAPNIK;
3915 * Get the current route source
3917 * @param obj the map object
3918 * @return Returns the source of the route
3922 EAPI Elm_Map_Route_Sources
3923 elm_map_route_source_get(const Evas_Object *obj)
3925 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
3926 Widget_Data *wd = elm_widget_data_get(obj);
3927 if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
3928 return wd->route_source;
3932 * Set the API of a custom source.
3934 * A custom web service can be associated to the source ELM_MAP_SOURCE_CUSTOM_(1..7).
3936 * @param source the source ID (ELM_MAP_SOURCE_CUSTOM_(1..7))
3937 * @param name the name of the source
3938 * @param zoom_min the minimum zoom of the source, must be >= 0
3939 * @param zoom_max the maximum zoom of the source, must be <= ZOOM_MAX
3940 * @param url_cb the callback used to create the url from where a tile (png or jpeg file) is downloaded.
3945 elm_map_source_custom_api_set(Elm_Map_Sources source, const char *name, int zoom_min, int zoom_max, ElmMapSourceURLFunc url_cb, ElmMapRouteSourceURLFunc route_url_cb)
3947 EINA_SAFETY_ON_NULL_RETURN(name);
3948 EINA_SAFETY_ON_NULL_RETURN(url_cb);
3949 map_sources_tab[source].name = name;
3950 map_sources_tab[source].zoom_min = zoom_min;
3951 map_sources_tab[source].zoom_max = zoom_max;
3952 map_sources_tab[source].url_cb = url_cb;
3953 map_sources_tab[source].route_url_cb = route_url_cb;
3957 * Get the maximum zoom of the source.
3959 * @param source the source
3960 * @return Returns the maximum zoom of the source
3965 elm_map_source_zoom_max_get(Elm_Map_Sources source)
3967 return map_sources_tab[source].zoom_max;
3971 * Get the minimum zoom of the source.
3973 * @param source the source
3974 * @return Returns the minimum zoom of the source
3979 elm_map_source_zoom_min_get(Elm_Map_Sources source)
3981 return map_sources_tab[source].zoom_min;
3985 * Get the name of a source.
3987 * @param source the source
3988 * @return Returns the name of the source
3993 elm_map_source_name_get(Elm_Map_Sources source)
3995 return map_sources_tab[source].name;
3999 * Set the user agent of the widget map.
4001 * @param obj The map object
4002 * @param user_agent the user agent of the widget map
4007 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4009 ELM_CHECK_WIDTYPE(obj, widtype);
4010 Widget_Data *wd = elm_widget_data_get(obj);
4013 if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4014 else eina_stringshare_replace(&wd->user_agent, user_agent);
4016 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4017 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4021 * Get the user agent of the widget map.
4023 * @param obj The map object
4024 * @return The user agent of the widget map
4029 elm_map_user_agent_get(Evas_Object *obj)
4031 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4032 Widget_Data *wd = elm_widget_data_get(obj);
4034 if (!wd) return NULL;
4035 return wd->user_agent;
4039 * Add a route on the map
4041 * @param obj The map object
4042 * @param type the type if transport
4043 * @param method the routing method
4044 * @param flon the start longitude
4045 * @param flat the start latitude
4046 * @param tlon the destination longitude
4047 * @param tlat the destination latitude
4049 * @return The Route object
4053 EAPI Elm_Map_Route *
4054 elm_map_route_add(Evas_Object *obj,
4055 Elm_Map_Route_Type type,
4056 Elm_Map_Route_Method method,
4062 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4063 Widget_Data *wd = elm_widget_data_get(obj);
4064 if (!wd) return EINA_FALSE;
4067 char *type_name = NULL;
4069 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4070 if (!route) return NULL;
4072 snprintf(buf, sizeof(buf), DEST_XML_FILE);
4080 route->con_url = ecore_con_url_new(NULL);
4081 route->ud.fname = strdup(buf);
4082 INF("xml file : %s", route->ud.fname);
4085 route->ud.fd = fdopen(fd, "w+");
4086 if ((!route->con_url) || (!route->ud.fd))
4088 ecore_con_url_free(route->con_url);
4094 route->color.r = 255;
4097 route->color.a = 255;
4098 route->handlers = eina_list_append
4099 (route->handlers, (void *)ecore_event_handler_add
4100 (ECORE_CON_EVENT_URL_COMPLETE, _common_complete_cb, route));
4102 route->inbound = EINA_FALSE;
4104 route->method = method;
4112 case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4113 type_name = strdup(ROUTE_TYPE_MOTORCAR);
4115 case ELM_MAP_ROUTE_TYPE_BICYCLE:
4116 type_name = strdup(ROUTE_TYPE_BICYCLE);
4118 case ELM_MAP_ROUTE_TYPE_FOOT:
4119 type_name = strdup(ROUTE_TYPE_FOOT);
4125 source = map_sources_tab[wd->source].route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4126 INF("route url = %s", source);
4128 wd->route = eina_list_append(wd->route, route);
4130 ecore_con_url_url_set(route->con_url, source);
4131 ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4132 ecore_con_url_data_set(route->con_url, route);
4133 ecore_con_url_get(route->con_url);
4134 if (type_name) free(type_name);
4135 if (source) free(source);
4137 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4138 "elm,state,busy,start", "elm");
4139 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4144 * Remove a route from the map
4146 * @param route The route to remove
4152 elm_map_route_remove(Elm_Map_Route *route)
4154 EINA_SAFETY_ON_NULL_RETURN(route);
4159 Ecore_Event_Handler *h;
4161 EINA_LIST_FREE(route->path, p)
4166 EINA_LIST_FREE(route->waypoint, w)
4168 if (w->point) eina_stringshare_del(w->point);
4172 EINA_LIST_FREE(route->nodes, n)
4174 if (n->pos.address) eina_stringshare_del(n->pos.address);
4178 EINA_LIST_FREE(route->handlers, h)
4180 ecore_event_handler_del(h);
4183 if (route->ud.fname)
4185 ecore_file_remove(route->ud.fname);
4186 free(route->ud.fname);
4187 route->ud.fname = NULL;
4192 * Set the option used for the background color
4194 * @param route The route object
4200 * This sets the color used for the route
4205 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4207 EINA_SAFETY_ON_NULL_RETURN(route);
4215 * Get the option used for the background color
4217 * @param route The route object
4226 elm_map_route_color_get(Elm_Map_Route *route, int *r, int *g , int *b, int *a)
4228 EINA_SAFETY_ON_NULL_RETURN(route);
4229 if (*r) *r = route->color.r;
4230 if (*g) *g = route->color.g;
4231 if (*b) *b = route->color.b;
4232 if (*a) *a = route->color.a;
4236 * Get the information of route distance
4238 * @param route the route object
4239 * @return Returns the distance of route (unit : km)
4244 elm_map_route_distance_get(Elm_Map_Route *route)
4246 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
4247 return route->info.distance;
4251 * Get the information of route nodes
4253 * @param route the route object
4254 * @return Returns the nodes of route
4260 elm_map_route_node_get(Elm_Map_Route *route)
4262 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4263 return route->info.nodes;
4267 * Get the information of route waypoint
4269 * @param route the route object
4270 * @return Returns the waypoint of route
4276 elm_map_route_waypoint_get(Elm_Map_Route *route)
4278 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4279 return route->info.waypoints;
4283 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4286 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
4292 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4295 snprintf(buf, sizeof(buf),
4296 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
4302 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4305 snprintf(buf, sizeof(buf),
4306 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
4312 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4315 snprintf(buf, sizeof(buf),
4316 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
4322 _custom1_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4328 _custom2_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4334 _custom3_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4340 _custom4_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4346 _custom5_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4352 _custom6_url_cb(Evas_Object *obj __UNUSED__, int x __UNUSED__, int y __UNUSED__, int zoom __UNUSED__)
4358 _module_url_cb(Evas_Object *obj, int x, int y, int zoom)
4361 Widget_Data *wd = elm_widget_data_get(obj);
4362 if (elm_map_source_get(obj) == ELM_MAP_SOURCE_MODULE)
4363 if ((wd->api) && (wd->api->obj_url_request))
4364 buf = wd->api->obj_url_request(obj, x, y, zoom);
4366 if (!buf) buf = strdup("");
4371 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4374 snprintf(buf, sizeof(buf),
4375 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
4376 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
4381 // TODO: fix monav api
4383 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4386 snprintf(buf, sizeof(buf),
4387 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
4388 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
4394 // TODO: fix ors api
4396 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4399 snprintf(buf, sizeof(buf),
4400 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
4401 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
4407 static char *_route_custom1_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4412 static char *_route_custom2_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4417 static char *_route_custom3_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4422 static char *_route_custom4_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4427 static char *_route_custom5_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4432 static char *_route_custom6_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4437 static char *_route_module_url_cb(Evas_Object *obj __UNUSED__, char *type_name __UNUSED__, int method __UNUSED__, double flon __UNUSED__, double flat __UNUSED__, double tlon __UNUSED__, double tlat __UNUSED__)
4439 // TODO: make example route module