2 #include "Elementary.h"
9 * This is a widget specifically for displaying the map. It uses basically
10 * OpenStreetMap provider. but it can be added custom providers.
12 * Signals that you can add callbacks for are:
14 * "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.
19 * "longpressed" - This is called when a user has pressed down on the map for
20 * a long time without dragging around.
22 * "clicked,double" - This is called when a user has double-clicked the map.
24 * "load,detail" - Map detailed data load begins.
26 * "loaded,detail" - This is called when all parts of the map are loaded.
28 * "zoom,start" - Zoom animation started.
30 * "zoom,stop" - Zoom animation stopped.
32 * "zoom,change" - Zoom changed when using an auto zoom mode.
34 * "scroll" - the content has been scrolled (moved)
36 * "scroll,anim,start" - scrolling animation has started
38 * "scroll,anim,stop" - scrolling animation has stopped
40 * "scroll,drag,start" - dragging the contents around has started
42 * "scroll,drag,stop" - dragging the contents around has stopped
44 * "downloaded" - This is called when map images are downloaded
46 * "route,load" - This is called when route request begins
48 * "route,loaded" - This is called when route request ends
50 * "name,load" - This is called when name request begins
52 * "name,loaded- This is called when name request ends
58 typedef struct _Widget_Data Widget_Data;
59 typedef struct _Pan Pan;
60 typedef struct _Grid Grid;
61 typedef struct _Grid_Item Grid_Item;
62 typedef struct _Marker_Group Marker_Group;
63 typedef struct _Event Event;
64 typedef struct _Path_Node Path_Node;
65 typedef struct _Path_Waypoint Path_Waypoint;
66 typedef struct _Url_Data Url_Data;
67 typedef struct _Route_Dump Route_Dump;
68 typedef struct _Name_Dump Name_Dump;
69 typedef struct _Track_Dump Track_Dump;
71 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
72 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
73 #define DEST_FILE_PATH "%s%d.png"
74 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
75 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
77 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
78 #define ROUTE_TYPE_MOTORCAR "motocar"
79 #define ROUTE_TYPE_BICYCLE "bicycle"
80 #define ROUTE_TYPE_FOOT "foot"
81 #define YOURS_DISTANCE "distance"
82 #define YOURS_DESCRIPTION "description"
83 #define YOURS_COORDINATES "coordinates"
85 // TODO: fix monav & ors url
86 #define ROUTE_MONAV_URL "http://"
87 #define ROUTE_ORS_URL "http:///"
89 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
90 #define NOMINATIM_RESULT "result"
91 #define NOMINATIM_PLACE "place"
92 #define NOMINATIM_ATTR_LON "lon"
93 #define NOMINATIM_ATTR_LAT "lat"
95 #define PINCH_ZOOM_MIN 0.1
96 #define PINCH_ZOOM_MAX 5.0
98 #define GPX_NAME "name>"
99 #define GPX_COORDINATES "trkpt "
100 #define GPX_LON "lon"
101 #define GPX_LAT "lat"
102 #define GPX_ELE "ele>"
103 #define GPX_TIME "time>"
106 // Currently the size of a tile must be 256*256
107 // and the size of the map must be pow(2.0, z)*tile_size
108 typedef struct _Map_Sources_Tab
113 ElmMapModuleUrlFunc url_cb;
114 Elm_Map_Route_Sources route_source;
115 ElmMapModuleRouteUrlFunc route_url_cb;
116 ElmMapModuleNameUrlFunc name_url_cb;
117 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
118 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
121 //Zemm min is supposed to be 0
122 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
123 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
124 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
125 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
127 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
129 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
130 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
132 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
134 static Map_Sources_Tab default_map_sources_tab[] =
136 {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
137 {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
138 {"CycleMap", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
139 {"Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
144 Ecore_Con_Url *con_url;
150 struct _Elm_Map_Marker_Class
155 struct _Elm_Map_Marker_Class_Func {
156 ElmMapMarkerGetFunc get;
157 ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
158 ElmMapMarkerIconGetFunc icon_get;
161 struct { //this part is private, do not modify these values
163 Evas_Coord edje_w, edje_h;
167 struct _Elm_Map_Marker
170 Elm_Map_Marker_Class *clas;
171 Elm_Map_Group_Class *clas_group;
172 double longitude, latitude;
177 Marker_Group **groups;
178 Evas_Object *content;
181 struct _Elm_Map_Group_Class
185 int zoom_displayed; // display the group if the zoom is >= to zoom_display
186 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
190 ElmMapGroupIconGetFunc icon_get;
193 struct { //this part is private, do not modify these values
195 Evas_Coord edje_w, edje_h;
196 Evas_Coord edje_max_w, edje_max_h;
198 Eina_List *objs_used;
199 Eina_List *objs_notused;
206 Eina_Matrixsparse_Cell *cell;
207 Elm_Map_Group_Class *clas;
210 long long sum_x, sum_y;
214 Evas_Object *obj, *bubble, *sc, *bx, *rect;
216 Eina_Bool bringin : 1;
217 Eina_Bool update_nbelems : 1;
218 Eina_Bool update_resize : 1;
219 Eina_Bool update_raise : 1;
220 Eina_Bool delete_object : 1;
223 struct _Elm_Map_Route
229 Ecore_Con_Url *con_url;
234 double flon, flat, tlon, tlat;
236 Eina_List *nodes, *path;
243 const char *waypoints;
244 double distance; /* unit : km */
257 Eina_Bool inbound : 1;
271 struct _Path_Waypoint
282 Ecore_Con_Url *con_url;
287 Ecore_Event_Handler *handler;
290 struct _Elm_Map_Track
298 double flon, flat, tlon, tlat;
300 Eina_List *nodes, *path;
307 const char *waypoints;
308 double distance; /* unit : km */
318 Eina_Bool inbound : 1;
331 Eina_Bool download : 1;
333 Ecore_File_Download_Job *job;
340 int tsize; // size of tile (tsize x tsize pixels)
341 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
342 int iw, ih; // size of image in pixels
343 int w, h; // size of grid image in pixels (represented by grid)
344 int gw, gh; // size of grid in tiles
345 Eina_Matrixsparse *grid;
352 Evas_Object *pan_smart;
354 Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
356 Evas_Coord pan_x, pan_y, minw, minh;
361 Elm_Map_Zoom_Mode mode;
364 Ecore_Timer *scr_timer;
365 Ecore_Timer *long_timer;
366 Ecore_Animator *zoom_animator;
377 Evas_Coord x, y ,w ,h;
383 Eina_Bool resized : 1;
384 Eina_Bool on_hold : 1;
385 Eina_Bool paused : 1;
386 Eina_Bool paused_markers : 1;
393 Ecore_Job *markers_place_job;
394 Eina_Matrixsparse **markers;
395 Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
396 Evas_Coord markers_max_num;
397 int marker_max_w, marker_max_h;
399 Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
401 Eina_List *groups_clas; // list of Elm_Map_Group_Class*
402 Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
404 Elm_Map_Route_Sources route_source;
405 Eina_List *s_event_list;
410 const char *user_agent;
413 Evas_Event_Mouse_Down ev;
434 Ecore_Timer *wheel_timer;
435 Eina_Bool wheel_disabled : 1;
438 Eina_List *map_sources_tab;
439 const char **source_names;
441 Ecore_Timer *zoom_timer;
442 Map_Sources_Tab *src;
443 const char *gpx_file;
444 int zoom_min, zoom_max;
449 Evas_Object_Smart_Clipped_Data __clipped_data;
465 Evas_Coord x, y, w, h;
468 Ecore_Timer *hold_timer;
483 enum _Route_Xml_Attribute
487 ROUTE_XML_DESCRIPTION,
488 ROUTE_XML_COORDINATES,
490 } Route_Xml_Attibute;
500 enum _Name_Xml_Attribute
519 Elm_Map_Track *track;
525 enum _Track_Xml_Attribute
528 TRACK_XML_COORDINATES,
530 } Track_Xml_Attibute;
533 static const char *widtype = NULL;
535 static const char SIG_CHANGED[] = "changed";
536 static const char SIG_CLICKED[] = "clicked";
537 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
538 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
539 static const char SIG_LOAD_DETAIL[] = "load,detail";
540 static const char SIG_LONGPRESSED[] = "longpressed";
541 static const char SIG_PRESS[] = "press";
542 static const char SIG_SCROLL[] = "scroll";
543 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
544 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
545 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
546 static const char SIG_ZOOM_START[] = "zoom,start";
547 static const char SIG_ZOOM_STOP[] = "zoom,stop";
548 static const char SIG_DOWNLOADED[] = "downloaded";
549 static const char SIG_ROUTE_LOAD[] = "route,load";
550 static const char SIG_ROUTE_LOADED[] = "route,loaded";
551 static const char SIG_NAME_LOAD[] = "name,load";
552 static const char SIG_NAME_LOADED[] = "name,loaded";
553 static const Evas_Smart_Cb_Description _signals[] = {
556 {SIG_CLICKED_DOUBLE, ""},
557 {SIG_LOADED_DETAIL, ""},
558 {SIG_LOAD_DETAIL, ""},
559 {SIG_LONGPRESSED, ""},
562 {SIG_SCROLL_DRAG_START, ""},
563 {SIG_SCROLL_DRAG_STOP, ""},
564 {SIG_ZOOM_CHANGE, ""},
565 {SIG_ZOOM_START, ""},
567 {SIG_DOWNLOADED, ""},
568 {SIG_ROUTE_LOAD, ""},
569 {SIG_ROUTE_LOADED, ""},
571 {SIG_NAME_LOADED, ""},
575 static void _pan_calculate(Evas_Object *obj);
577 static Eina_Bool _hold_timer_cb(void *data);
578 static Eina_Bool _wheel_timer_cb(void *data);
579 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
580 static void _del_hook(Evas_Object *obj);
581 static void _theme_hook(Evas_Object *obj);
582 static void _on_focus_hook(void *data, Evas_Object *obj);
583 static void _sizing_eval(Evas_Object *obj);
584 static void _calc_job(void *data);
585 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
586 Evas_Callback_Type type, void *event_info);
587 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);
588 static void grid_clear(Evas_Object *obj, Grid *g);
589 static Grid *grid_create(Evas_Object *obj);
590 static void grid_load(Evas_Object *obj, Grid *g);
593 static void _group_object_create(Marker_Group *group);
594 static void _group_object_free(Marker_Group *group);
595 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
596 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
597 static void _group_bubble_create(Marker_Group *group);
598 static void _group_bubble_free(Marker_Group *group);
599 static void _group_bubble_place(Marker_Group *group);
601 static int _group_bubble_content_update(Marker_Group *group);
602 static void _group_bubble_content_free(Marker_Group *group);
603 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);
604 static void _bubble_sc_hits_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
606 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
607 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
608 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
610 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
611 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
612 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
614 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);
615 static void track_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
618 get_multi_device(Evas_Object *obj)
620 Widget_Data *wd = elm_widget_data_get(obj);
624 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
626 if (ev->device) return ev->device;
632 create_event_object(void *data, Evas_Object *obj, int device)
634 Widget_Data *wd = elm_widget_data_get(data);
635 Event *ev = calloc(1, sizeof(Event));
637 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
641 evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
642 wd->s_event_list = eina_list_append(wd->s_event_list, ev);
647 get_event_object(void *data, int device)
649 Widget_Data *wd = elm_widget_data_get(data);
653 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
655 if (ev->device == device) break;
662 destroy_event_object(void *data, Event *ev)
664 Widget_Data *wd = elm_widget_data_get(data);
665 EINA_SAFETY_ON_NULL_RETURN(ev);
667 wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
670 ecore_timer_del(ev->hold_timer);
671 ev->hold_timer = NULL;
677 module_list_cb(Eina_Module *m, void *data)
679 ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
680 Widget_Data *wd = elm_widget_data_get(data);
682 ElmMapModuleSourceFunc source;
683 ElmMapModuleZoomMinFunc zoom_min;
684 ElmMapModuleZoomMaxFunc zoom_max;
685 ElmMapModuleUrlFunc url;
686 ElmMapModuleRouteSourceFunc route_source;
687 ElmMapModuleRouteUrlFunc route_url;
688 ElmMapModuleNameUrlFunc name_url;
689 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
690 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
693 if (!wd) return EINA_FALSE;
695 file = eina_module_file_get(m);
696 if (!eina_module_load(m))
698 ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
702 source = eina_module_symbol_get(m, "map_module_source_get");
703 zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
704 zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
705 url = eina_module_symbol_get(m, "map_module_url_get");
706 route_source = eina_module_symbol_get(m, "map_module_route_source_get");
707 route_url = eina_module_symbol_get(m, "map_module_route_url_get");
708 name_url = eina_module_symbol_get(m, "map_module_name_url_get");
709 geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
710 coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
711 if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
713 ERR("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
714 eina_module_unload(m);
717 s = calloc(1, sizeof(Map_Sources_Tab));
718 EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
720 s->zoom_min = zoom_min();
721 s->zoom_max = zoom_max();
723 s->route_source = route_source();
724 s->route_url_cb = route_url;
725 s->name_url_cb = name_url;
726 s->geo_into_coord = geo_into_coord;
727 s->coord_into_geo = coord_into_geo;
728 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
734 module_init(void *data)
736 ELM_CHECK_WIDTYPE(data, widtype);
737 Widget_Data *wd = elm_widget_data_get(data);
740 wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
744 source_init(void *data)
746 ELM_CHECK_WIDTYPE(data, widtype);
747 Widget_Data *wd = elm_widget_data_get(data);
753 for (idx = 0; idx < 4; idx++)
755 s = calloc(1, sizeof(Map_Sources_Tab));
756 EINA_SAFETY_ON_NULL_RETURN(s);
757 s->name = default_map_sources_tab[idx].name;
758 s->zoom_min = default_map_sources_tab[idx].zoom_min;
759 s->zoom_max = default_map_sources_tab[idx].zoom_max;
760 s->url_cb = default_map_sources_tab[idx].url_cb;
761 s->route_source = default_map_sources_tab[idx].route_source;
762 s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
763 s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
764 s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
765 s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
766 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
767 if (!idx) wd->src = s;
771 int n = eina_list_count(wd->map_sources_tab);
772 wd->source_names = malloc(sizeof(char *) * (n + 1));
773 if (!wd->source_names)
775 ERR("init source names failed.");
779 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
781 wd->source_names[idx] = strdup(s->name);
782 INF("source : %s", wd->source_names[idx]);
785 wd->source_names[idx] = NULL;
789 zoom_min_get(void *data)
791 ELM_CHECK_WIDTYPE(data, widtype);
792 Widget_Data *wd = elm_widget_data_get(data);
798 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
801 if (tz < wd->zoom_min) wd->zoom_min = tz;
806 zoom_max_get(void *data)
808 ELM_CHECK_WIDTYPE(data, widtype);
809 Widget_Data *wd = elm_widget_data_get(data);
815 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
818 if (tz > wd->zoom_max) wd->zoom_max = tz;
823 obj_rotate_zoom(void *data, Evas_Object *obj)
825 ELM_CHECK_WIDTYPE(data, widtype);
826 Widget_Data *wd = elm_widget_data_get(data);
827 if ((!wd->pinch.cx) && (!wd->pinch.cy))
829 wd->pinch.cx = wd->rotate.cx;
830 wd->pinch.cy = wd->rotate.cy;
833 evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
834 evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
835 evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
836 evas_object_map_enable_set(obj, EINA_TRUE);
837 evas_object_map_set(obj, wd->map);
841 track_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)
843 ELM_CHECK_WIDTYPE(obj, widtype);
844 Widget_Data *wd = elm_widget_data_get(obj);
845 Eina_List *lr, *lp, *ln;
854 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
856 EINA_LIST_FOREACH(wd->track, lr, t)
858 EINA_LIST_FOREACH(t->path, lp, p)
860 evas_object_polygon_points_clear(p);
863 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
864 nodes = eina_list_count(t->nodes);
866 EINA_LIST_FOREACH(t->nodes, ln, n)
870 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
871 if ((x >= px - ow) && (x <= (px + ow*2)) &&
872 (y >= py - oh) && (y <= (py + oh*2)))
877 p = eina_list_nth(t->path, n->idx);
878 a = (double)(y - t->y) / (double)(x - t->x);
879 if ((abs(a) >= 1) || (t->x == x))
881 evas_object_polygon_point_add(p, t->x - 3, t->y);
882 evas_object_polygon_point_add(p, t->x + 3, t->y);
883 evas_object_polygon_point_add(p, x + 3, y);
884 evas_object_polygon_point_add(p, x - 3, y);
888 evas_object_polygon_point_add(p, t->x, t->y - 3);
889 evas_object_polygon_point_add(p, t->x, t->y + 3);
890 evas_object_polygon_point_add(p, x, y + 3);
891 evas_object_polygon_point_add(p, x, y - 3);
894 evas_object_color_set(p, t->color.r, t->color.g, t->color.b, t->color.a);
895 evas_object_raise(p);
896 obj_rotate_zoom(obj, p);
901 else t->inbound = EINA_FALSE;
905 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
906 if ((x >= px - ow) && (x <= (px + ow*2)) &&
907 (y >= py - oh) && (y <= (py + oh*2)))
911 t->inbound = EINA_TRUE;
913 else t->inbound = EINA_FALSE;
916 t->inbound = EINA_FALSE;
920 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)
922 ELM_CHECK_WIDTYPE(obj, widtype);
923 Widget_Data *wd = elm_widget_data_get(obj);
924 Eina_List *lr, *lp, *ln;
933 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
935 EINA_LIST_FOREACH(wd->route, lr, r)
937 EINA_LIST_FOREACH(r->path, lp, p)
939 evas_object_polygon_points_clear(p);
942 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
943 nodes = eina_list_count(r->nodes);
945 EINA_LIST_FOREACH(r->nodes, ln, n)
947 if ((!wd->zoom) || ((n->idx) &&
948 ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
951 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
952 if ((x >= px - ow) && (x <= (px + ow*2)) &&
953 (y >= py - oh) && (y <= (py + oh*2)))
958 p = eina_list_nth(r->path, n->idx);
959 a = (double)(y - r->y) / (double)(x - r->x);
960 if ((abs(a) >= 1) || (r->x == x))
962 evas_object_polygon_point_add(p, r->x - 3, r->y);
963 evas_object_polygon_point_add(p, r->x + 3, r->y);
964 evas_object_polygon_point_add(p, x + 3, y);
965 evas_object_polygon_point_add(p, x - 3, y);
969 evas_object_polygon_point_add(p, r->x, r->y - 3);
970 evas_object_polygon_point_add(p, r->x, r->y + 3);
971 evas_object_polygon_point_add(p, x, y + 3);
972 evas_object_polygon_point_add(p, x, y - 3);
975 evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
976 evas_object_raise(p);
977 obj_rotate_zoom(obj, p);
982 else r->inbound = EINA_FALSE;
986 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
987 if ((x >= px - ow) && (x <= (px + ow*2)) &&
988 (y >= py - oh) && (y <= (py + oh*2)))
992 r->inbound = EINA_TRUE;
994 else r->inbound = EINA_FALSE;
997 r->inbound = EINA_FALSE;
1002 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1004 ELM_CHECK_WIDTYPE(obj, widtype);
1005 Widget_Data *wd = elm_widget_data_get(obj);
1006 Evas_Coord ax, ay, gw, gh, hh, ww;
1009 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
1016 if ((ww == gw) && (hh == gh)) return;
1018 if (ow > gw) ax = (ow - gw) / 2;
1019 if (oh > gh) ay = (oh - gh) / 2;
1020 evas_object_move(wd->rect,
1023 evas_object_resize(wd->rect, gw, gh);
1027 wd->show.show = EINA_FALSE;
1028 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
1033 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)
1035 ELM_CHECK_WIDTYPE(obj, widtype);
1036 Widget_Data *wd = elm_widget_data_get(obj);
1037 Evas_Coord ax, ay, gw, gh, tx, ty;
1038 Eina_List *l, *markers;
1039 Eina_Matrixsparse_Cell *cell;
1040 Marker_Group *group;
1044 int g_xx, g_yy, g_hh, g_ww;
1047 if (g != eina_list_data_get(wd->grids)) return;
1053 if (ow > gw) ax = (ow - gw) / 2;
1054 if (oh > gh) ay = (oh - gh) / 2;
1056 if (wd->zoom != wd->marker_zoom)
1058 EINA_LIST_FREE(wd->cells_displayed, cell)
1060 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1062 if (group->obj) _group_object_free(group);
1066 wd->marker_zoom = wd->zoom;
1068 if ((wd->paused_markers)
1069 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
1072 g_xx = wd->pan_x / wd->tsize;
1073 if (g_xx < 0) g_xx = 0;
1074 g_yy = wd->pan_y / wd->tsize;
1075 if (g_yy < 0) g_yy = 0;
1076 g_ww = (ow / wd->tsize) + 1;
1077 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
1078 g_hh = (oh / wd->tsize) + 1;
1079 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
1081 //hide groups no more displayed
1082 EINA_LIST_FREE(wd->cells_displayed, cell)
1084 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
1085 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
1087 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1089 if (group->obj) _group_object_free(group);
1094 if (!wd->marker_zoom)
1100 for (y = g_yy; y <= g_yy + g_hh; y++)
1102 for (x = g_xx; x <= g_xx + g_ww; x++)
1104 if (!wd->markers[wd->zoom]) continue;
1105 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1106 if (!cell) continue;
1107 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1108 markers = eina_matrixsparse_cell_data_get(cell);
1109 EINA_LIST_FOREACH(markers, l, group)
1111 if (!group->markers) continue;
1112 if (group->clas->zoom_displayed > wd->zoom) continue;
1119 if (eina_list_count(group->markers) == 1)
1121 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1122 ww = m->clas->priv.edje_w;
1123 hh = m->clas->priv.edje_h;
1126 if (ww <= 0) ww = 1;
1127 if (hh <= 0) hh = 1;
1129 if ((gw != g->w) && (g->w > 0))
1132 xx = ((long long )gw * xx) / g->w;
1133 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1135 if ((gh != g->h) && (g->h > 0))
1138 yy = ((long long)gh * yy) / g->h;
1139 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1142 if ((!group->clas->hide)
1143 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1144 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1146 if (!group->obj) _group_object_create(group);
1148 if (group->update_nbelems)
1150 group->update_nbelems = EINA_FALSE;
1151 if (eina_list_count(group->markers) > 1)
1153 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1154 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1157 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1159 evas_object_move(group->obj,
1160 xx - px + ax + ox - ww/2,
1161 yy - py + ay + oy - hh/2);
1162 if ((!wd->paused_markers) || (group->update_resize))
1164 group->update_resize = EINA_FALSE;
1165 evas_object_resize(group->obj, ww, hh);
1166 obj_rotate_zoom(obj, group->obj);
1168 if (group->update_raise)
1170 group->update_raise = EINA_FALSE;
1171 evas_object_raise(group->obj);
1172 obj_rotate_zoom(obj, group->obj);
1173 evas_object_show(group->obj);
1175 if (group->bubble) _group_bubble_place(group);
1177 else if (group->obj)
1179 _group_object_free(group);
1187 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)
1189 ELM_CHECK_WIDTYPE(obj, widtype);
1190 Widget_Data *wd = elm_widget_data_get(obj);
1191 Evas_Coord ax, ay, gw, gh, tx, ty;
1199 if (ow > gw) ax = (ow - gw) / 2;
1200 if (oh > gh) ay = (oh - gh) / 2;
1202 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1203 Eina_Matrixsparse_Cell *cell;
1205 EINA_ITERATOR_FOREACH(it, cell)
1207 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1213 if ((gw != g->w) && (g->w > 0))
1216 xx = ((long long )gw * xx) / g->w;
1217 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1219 if ((gh != g->h) && (g->h > 0))
1222 yy = ((long long)gh * yy) / g->h;
1223 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1225 evas_object_move(gi->img,
1229 evas_object_resize(gi->img, ww, hh);
1231 obj_rotate_zoom(obj, gi->img);
1232 /*evas_object_move(gi->txt,
1236 evas_object_resize(gi->txt, ww, hh);
1239 eina_iterator_free(it);
1243 grid_clear(Evas_Object *obj, Grid *g)
1245 ELM_CHECK_WIDTYPE(obj, widtype);
1246 Widget_Data *wd = elm_widget_data_get(obj);
1250 if (!g->grid) return;
1252 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1253 Eina_Matrixsparse_Cell *cell;
1255 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1256 ecore_file_recursive_rm(buf);
1258 EINA_ITERATOR_FOREACH(it, cell)
1260 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1261 evas_object_del(gi->img);
1262 //evas_object_del(gi->txt);
1266 gi->want = EINA_FALSE;
1268 if (!wd->preload_num)
1270 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1271 "elm,state,busy,stop", "elm");
1272 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
1278 DBG("DOWNLOAD abort %s", gi->file);
1279 ecore_file_download_abort(gi->job);
1280 ecore_file_remove(gi->file);
1285 eina_stringshare_del(gi->file);
1289 eina_matrixsparse_free(g->grid);
1290 eina_iterator_free(it);
1297 _tile_update(Grid_Item *gi)
1299 gi->want = EINA_FALSE;
1300 gi->download = EINA_FALSE;
1301 evas_object_image_file_set(gi->img, gi->file, NULL);
1302 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1303 ecore_file_remove(gi->file);
1305 obj_rotate_zoom(gi->wd->obj, gi->img);
1306 evas_object_show(gi->img);
1308 //evas_object_text_text_set(gi->txt, gi->file);
1309 //evas_object_show(gi->txt);
1311 gi->have = EINA_TRUE;
1312 gi->wd->preload_num--;
1313 if (!gi->wd->preload_num)
1315 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1316 "elm,state,busy,stop", "elm");
1317 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1323 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1325 Grid_Item *gi = data;
1327 gi->download = EINA_FALSE;
1330 DBG("DOWNLOAD done %s", gi->file);
1331 if ((gi->want) && (!status)) _tile_update(gi);
1335 DBG("Download failed %s (%d) ", gi->file, status);
1336 ecore_file_remove(gi->file);
1339 gi->wd->finish_num++;
1341 evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1345 grid_create(Evas_Object *obj)
1347 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1348 Widget_Data *wd = elm_widget_data_get(obj);
1351 if ((!wd) || (!wd->src)) return NULL;
1352 g = calloc(1, sizeof(Grid));
1355 g->tsize = wd->tsize;
1358 if (g->zoom > wd->src->zoom_max) return NULL;
1359 if (g->zoom < wd->src->zoom_min) return NULL;
1361 int size = pow(2.0, wd->zoom);
1365 g->w = g->tsize * g->gw;
1366 g->h = g->tsize * g->gh;
1368 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1374 grid_load(Evas_Object *obj, Grid *g)
1376 ELM_CHECK_WIDTYPE(obj, widtype);
1377 Widget_Data *wd = elm_widget_data_get(obj);
1380 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1382 Eina_Matrixsparse_Cell *cell;
1385 if ((!wd) || (!wd->src)) return;
1386 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1387 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1392 if ((gw <= 0) || (gh <= 0)) return;
1395 if ((gw != g->w) && (g->w > 0))
1396 size = ((long long)gw * size) / g->w;
1397 if (size < (g->tsize / 2)) return; // else we will load to much tiles
1399 it = eina_matrixsparse_iterator_new(g->grid);
1401 EINA_ITERATOR_FOREACH(it, cell)
1403 gi = eina_matrixsparse_cell_data_get(cell);
1410 if ((gw != g->w) && (g->w > 0))
1413 xx = ((long long )gw * xx) / g->w;
1414 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1416 if ((gh != g->h) && (g->h > 0))
1419 yy = ((long long)gh * yy) / g->h;
1420 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1423 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1424 yy - wd->pan_y + oy,
1426 cvx, cvy, cvw, cvh))
1430 evas_object_hide(gi->img);
1431 //evas_object_hide(gi->txt);
1432 evas_object_image_file_set(gi->img, NULL, NULL);
1433 gi->want = EINA_FALSE;
1434 gi->have = EINA_FALSE;
1438 DBG("DOWNLOAD abort %s", gi->file);
1439 ecore_file_download_abort(gi->job);
1440 ecore_file_remove(gi->file);
1444 gi->download = EINA_FALSE;
1446 if (!wd->preload_num)
1448 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1449 "elm,state,busy,stop", "elm");
1450 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
1457 evas_object_hide(gi->img);
1458 //evas_object_hide(gi->txt);
1459 evas_object_image_preload(gi->img, 1);
1460 evas_object_image_file_set(gi->img, NULL, NULL);
1461 gi->have = EINA_FALSE;
1462 gi->want = EINA_FALSE;
1466 eina_iterator_free(it);
1468 xx = wd->pan_x / size - 1;
1471 yy = wd->pan_y / size - 1;
1475 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1478 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1480 for (y = yy; y <= yy + hh; y++)
1482 for (x = xx; x <= xx + ww; x++)
1484 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1486 if ((!gi) && (g != eina_list_data_get(wd->grids)))
1491 gi = calloc(1, sizeof(Grid_Item));
1492 gi->src.x = x * g->tsize;
1493 gi->src.y = y * g->tsize;
1494 gi->src.w = g->tsize;
1495 gi->src.h = g->tsize;
1497 gi->out.x = gi->src.x;
1498 gi->out.y = gi->src.y;
1499 gi->out.w = gi->src.w;
1500 gi->out.h = gi->src.h;
1504 gi->img = evas_object_image_add(evas_object_evas_get(obj));
1505 evas_object_image_scale_hint_set
1506 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1507 evas_object_image_filled_set(gi->img, 1);
1509 evas_object_smart_member_add(gi->img, wd->pan_smart);
1510 elm_widget_sub_object_add(obj, gi->img);
1511 evas_object_pass_events_set(gi->img, EINA_TRUE);
1512 evas_object_stack_below(gi->img, wd->sep_maps_markers);
1514 /* gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1515 evas_object_text_font_set(gi->txt, "Vera", 12);
1516 evas_object_color_set(gi->txt, 100, 100, 100, 255);
1517 evas_object_smart_member_add(gi->txt,
1519 elm_widget_sub_object_add(obj, gi->txt);
1520 evas_object_pass_events_set(gi->txt, EINA_TRUE);
1522 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1525 if ((!gi->have) && (!gi->download))
1527 char buf[PATH_MAX], buf2[PATH_MAX];
1530 gi->want = EINA_TRUE;
1532 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1533 if (!ecore_file_exists(buf))
1534 ecore_file_mkpath(buf);
1536 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1538 source = wd->src->url_cb(obj, x, y, g->zoom);
1539 if ((!source) || (strlen(source)==0)) continue;
1541 eina_stringshare_replace(&gi->file, buf2);
1543 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1545 gi->download = EINA_TRUE;
1547 if (wd->preload_num == 1)
1549 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1550 "elm,state,busy,start", "elm");
1551 evas_object_smart_callback_call(obj,
1556 if (ecore_file_exists(buf2))
1560 DBG("DOWNLOAD %s \t in %s", source, buf2);
1561 ecore_file_download_full(source, buf2, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1563 DBG("Can't start to download %s", buf);
1568 if (source) free(source);
1572 obj_rotate_zoom(obj, gi->img);
1573 evas_object_show(gi->img);
1580 grid_clearall(Evas_Object *obj)
1582 ELM_CHECK_WIDTYPE(obj, widtype);
1583 Widget_Data *wd = elm_widget_data_get(obj);
1587 EINA_LIST_FREE(wd->grids, g)
1595 _smooth_update(Evas_Object *obj)
1597 ELM_CHECK_WIDTYPE(obj, widtype);
1598 Widget_Data *wd = elm_widget_data_get(obj);
1603 EINA_LIST_FOREACH(wd->grids, l, g)
1605 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1606 Eina_Matrixsparse_Cell *cell;
1608 EINA_ITERATOR_FOREACH(it, cell)
1610 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1611 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1613 eina_iterator_free(it);
1618 _scr_timeout(void *data)
1620 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1621 Widget_Data *wd = elm_widget_data_get(data);
1623 if (!wd) return ECORE_CALLBACK_CANCEL;
1625 if (!wd->nosmooth) _smooth_update(data);
1626 wd->scr_timer = NULL;
1627 return ECORE_CALLBACK_CANCEL;
1631 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1633 ELM_CHECK_WIDTYPE(data, widtype);
1634 Widget_Data *wd = elm_widget_data_get(data);
1640 if (wd->nosmooth == 1) _smooth_update(data);
1642 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1643 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1647 zoom_do(Evas_Object *obj)
1649 ELM_CHECK_WIDTYPE(obj, widtype);
1650 Widget_Data *wd = elm_widget_data_get(obj);
1651 Evas_Coord xx, yy, ow, oh;
1654 wd->size.w = wd->size.nw;
1655 wd->size.h = wd->size.nh;
1657 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1659 if (wd->center_on.enabled)
1661 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1667 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1668 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1673 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1675 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1677 wd->show.show = EINA_TRUE;
1683 if (wd->calc_job) ecore_job_del(wd->calc_job);
1684 wd->calc_job = ecore_job_add(_calc_job, wd);
1688 _zoom_timeout(void *data)
1690 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1691 Widget_Data *wd = elm_widget_data_get(data);
1693 if (!wd) return ECORE_CALLBACK_CANCEL;
1694 wd->zoom_timer = NULL;
1695 wd->pinch.level = 1.0;
1697 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1698 return ECORE_CALLBACK_CANCEL;
1702 _zoom_anim(void *data)
1704 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1705 Evas_Object *obj = data;
1706 Widget_Data *wd = elm_widget_data_get(obj);
1708 if (!wd) return ECORE_CALLBACK_CANCEL;
1709 if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1710 else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1713 wd->zoom_animator = NULL;
1715 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1716 return ECORE_CALLBACK_CANCEL;
1721 wd->zoom_animator = NULL;
1722 wd->pinch.level = 2.0;
1723 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1724 wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1725 return ECORE_CALLBACK_CANCEL;
1727 else if (wd->t <= 0.5)
1729 wd->zoom_animator = NULL;
1730 wd->pinch.level = 0.5;
1731 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1732 wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1733 return ECORE_CALLBACK_CANCEL;
1735 else if (wd->t != 1.0)
1737 Evas_Coord x, y, w, h;
1738 float half_w, half_h;
1739 evas_object_geometry_get(data, &x, &y, &w, &h);
1740 half_w = (float)w * 0.5;
1741 half_h = (float)h * 0.5;
1742 wd->pinch.cx = x + half_w;
1743 wd->pinch.cy = y + half_h;
1744 wd->pinch.level = wd->t;
1745 if (wd->calc_job) ecore_job_del(wd->calc_job);
1746 wd->calc_job = ecore_job_add(_calc_job, wd);
1748 return ECORE_CALLBACK_RENEW;
1752 _long_press(void *data)
1754 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1755 Widget_Data *wd = elm_widget_data_get(data);
1757 if (!wd) return ECORE_CALLBACK_CANCEL;
1758 wd->long_timer = NULL;
1759 evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1760 return ECORE_CALLBACK_CANCEL;
1764 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1766 ELM_CHECK_WIDTYPE(data, widtype);
1767 Widget_Data *wd = elm_widget_data_get(data);
1768 Evas_Event_Mouse_Down *ev = event_info;
1772 ev0 = get_event_object(data, 0);
1774 ev0 = create_event_object(data, obj, 0);
1777 ev0->hold_timer = NULL;
1778 ev0->prev.x = ev->canvas.x;
1779 ev0->prev.y = ev->canvas.y;
1781 if (ev->button != 1) return;
1782 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1783 else wd->on_hold = EINA_FALSE;
1784 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1785 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1787 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1788 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1789 wd->ev.canvas.x = ev->output.x;
1790 wd->ev.canvas.y = ev->output.y;
1791 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1795 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1797 Evas_Event_Mouse_Move *move = event_info;
1800 ev0 = get_event_object(data, 0);
1802 ev0->prev.x = move->cur.canvas.x;
1803 ev0->prev.y = move->cur.canvas.y;
1807 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1809 ELM_CHECK_WIDTYPE(data, widtype);
1810 Widget_Data *wd = elm_widget_data_get(data);
1813 Evas_Event_Mouse_Up *ev = event_info;
1818 ev0 = get_event_object(data, 0);
1821 mdevice = get_multi_device(data);
1824 if (ev0->hold_timer)
1826 ecore_timer_del(ev0->hold_timer);
1827 ev0->hold_timer = NULL;
1829 elm_smart_scroller_hold_set(wd->scr, 0);
1830 elm_smart_scroller_freeze_set(wd->scr, 0);
1834 ev1 = get_event_object(data, mdevice);
1836 ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1838 destroy_event_object(data, ev0);
1841 if (ev->button != 1) return;
1842 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1843 else wd->on_hold = EINA_FALSE;
1846 ecore_timer_del(wd->long_timer);
1847 wd->long_timer = NULL;
1849 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1850 wd->on_hold = EINA_FALSE;
1854 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1856 ELM_CHECK_WIDTYPE(data, widtype);
1857 Widget_Data *wd = elm_widget_data_get(data);
1859 Evas_Event_Multi_Down *down = event_info;
1861 elm_smart_scroller_hold_set(wd->scr, 1);
1862 elm_smart_scroller_freeze_set(wd->scr, 1);
1864 ev = create_event_object(data, obj, down->device);
1867 DBG("Failed : create_event_object");
1872 ev->hold_timer = NULL;
1873 ev->start.x = ev->prev.x = down->canvas.x;
1874 ev->start.y = ev->prev.y = down->canvas.y;
1875 ev->pinch_start_dis = 0;
1876 wd->pinch.level = 1.0;
1877 wd->pinch.diff = 1.0;
1882 ecore_timer_del(wd->long_timer);
1883 wd->long_timer = NULL;
1889 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1891 ELM_CHECK_WIDTYPE(data, widtype);
1892 Widget_Data *wd = elm_widget_data_get(data);
1893 Evas_Event_Multi_Move *move = event_info;
1894 int dis_new, dx, dy;
1895 double t, tt, a, a_diff;
1899 if ((!wd) || (!wd->src)) return;
1900 ev = get_event_object(data, move->device);
1903 ev0 = get_event_object(data, 0);
1906 if (wd->multi_count >= 1)
1908 Evas_Coord x, y, w, h;
1909 float half_w, half_h;
1911 evas_object_geometry_get(data, &x, &y, &w, &h);
1912 half_w = (float)w * 0.5;
1913 half_h = (float)h * 0.5;
1914 dx = ev0->prev.x - ev->prev.x;
1915 dy = ev0->prev.y - ev->prev.y;
1916 dis_new = sqrt((dx * dx) + (dy * dy));
1918 if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1921 ev->pinch_dis = dis_new;
1922 tt = wd->pinch.diff;
1923 wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1924 t = (wd->pinch.diff * 0.01) + 1.0;
1925 if ((t > 1.1) || (wd->rotate.doing))
1927 if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1928 ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1929 (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1931 wd->pinch.diff = tt;
1936 wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1937 wd->pinch.cx = x + half_w;
1938 wd->pinch.cy = y + half_h;
1939 wd->pinch.doing = EINA_TRUE;
1940 if (!wd->rotate.doing) goto do_zoom_only;
1945 if (wd->pinch.doing) goto do_nothing;
1948 a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1949 if (!wd->rotate.a) wd->rotate.a = a;
1952 a_diff = wd->rotate.a - a;
1953 if (a_diff > 0) wd->rotate.d -= 1.0;
1954 else if (a_diff < 0) wd->rotate.d += 1.0;
1956 wd->rotate.cx = x + half_w;
1957 wd->rotate.cy = y + half_h;
1958 wd->rotate.doing = EINA_TRUE;
1961 if (wd->calc_job) ecore_job_del(wd->calc_job);
1962 wd->calc_job = ecore_job_add(_calc_job, wd);
1966 ev->prev.x = move->cur.canvas.x;
1967 ev->prev.y = move->cur.canvas.y;
1971 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1973 ELM_CHECK_WIDTYPE(data, widtype);
1974 Widget_Data *wd = elm_widget_data_get(data);
1975 Evas_Event_Multi_Up *up = event_info;
1982 if (wd->calc_job) ecore_job_del(wd->calc_job);
1983 if (wd->zoom_animator)
1985 ecore_animator_del(wd->zoom_animator);
1986 wd->zoom_animator = NULL;
1989 wd->paused = EINA_TRUE;
1990 if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1991 else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1992 elm_map_zoom_set(data, wd->zoom + zoom);
1993 wd->pinch.level = 1.0;
1994 wd->pinch.doing = EINA_FALSE;
1997 wd->rotate.doing = EINA_FALSE;
1999 ev = get_event_object(data, up->device);
2002 DBG("Cannot get multi device");
2006 ev0 = get_event_object(data, 0);
2008 ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
2013 ecore_timer_del(ev->hold_timer);
2014 ev->hold_timer = NULL;
2017 destroy_event_object(data, ev);
2021 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2023 ELM_CHECK_WIDTYPE(data, widtype);
2024 Widget_Data *wd = elm_widget_data_get(data);
2025 Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
2026 Evas_Coord x, y, w, h;
2027 float half_w, half_h;
2030 evas_object_geometry_get(data, &x, &y, &w, &h);
2031 half_w = (float)w * 0.5;
2032 half_h = (float)h * 0.5;
2034 if (!wd->wheel_zoom) wd->wheel_zoom = 1.0;
2037 wd->zoom_method = ZOOM_METHOD_OUT;
2038 wd->wheel_zoom -= 0.05;
2039 if (wd->wheel_zoom <= PINCH_ZOOM_MIN) wd->wheel_zoom = PINCH_ZOOM_MIN;
2043 wd->zoom_method = ZOOM_METHOD_IN;
2044 wd->wheel_zoom += 0.2;
2045 if (wd->wheel_zoom >= PINCH_ZOOM_MAX) wd->wheel_zoom = PINCH_ZOOM_MAX;
2050 wd->pinch.level = wd->wheel_zoom;
2051 wd->pinch.cx = x + half_w;
2052 wd->pinch.cy = y + half_h;
2053 if (wd->calc_job) ecore_job_del(wd->calc_job);
2054 wd->calc_job = ecore_job_add(_calc_job, wd);
2057 if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
2058 wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
2062 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
2065 _hold_timer_cb(void *data)
2069 ev0->hold_timer = NULL;
2070 return ECORE_CALLBACK_CANCEL;
2074 _wheel_timer_cb(void *data)
2076 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2077 Widget_Data *wd = elm_widget_data_get(data);
2082 wd->wheel_timer = NULL;
2083 return ECORE_CALLBACK_CANCEL;
2085 if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom - 1.0);
2086 else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor((-1.0 / wd->wheel_zoom) + 1.0);
2089 wd->wheel_timer = NULL;
2090 return ECORE_CALLBACK_CANCEL;
2092 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2093 elm_map_zoom_set(data, wd->zoom + zoom);
2094 wd->wheel_zoom = 0.0;
2095 wd->wheel_timer = NULL;
2096 return ECORE_CALLBACK_CANCEL;
2100 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2102 ELM_CHECK_WIDTYPE(data, widtype);
2103 Widget_Data *wd = elm_widget_data_get(data);
2106 evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2107 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2108 evas_object_resize(wd->rect, w, h);
2109 evas_object_move(wd->rect, x, y);
2113 _del_hook(Evas_Object *obj)
2115 ELM_CHECK_WIDTYPE(obj, widtype);
2116 Widget_Data *wd = elm_widget_data_get(obj);
2117 Elm_Map_Group_Class *group_clas;
2118 Elm_Map_Marker_Class *marker_clas;
2124 Ecore_Event_Handler *h;
2130 EINA_LIST_FREE(wd->groups_clas, group_clas)
2132 if (group_clas->style)
2133 eina_stringshare_del(group_clas->style);
2137 EINA_LIST_FREE(wd->markers_clas, marker_clas)
2139 if (marker_clas->style)
2140 eina_stringshare_del(marker_clas->style);
2144 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2146 destroy_event_object(obj, ev);
2149 EINA_LIST_FOREACH(wd->route, l, r)
2151 EINA_LIST_FREE(r->path, p)
2156 EINA_LIST_FREE(r->waypoint, w)
2158 if (w->point) eina_stringshare_del(w->point);
2162 EINA_LIST_FREE(r->nodes, n)
2164 if (n->pos.address) eina_stringshare_del(n->pos.address);
2168 EINA_LIST_FREE(r->handlers, h)
2170 ecore_event_handler_del(h);
2173 if (r->con_url) ecore_con_url_free(r->con_url);
2174 if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2175 if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2178 EINA_LIST_FREE(wd->names, na)
2180 if (na->address) free(na->address);
2181 if (na->handler) ecore_event_handler_del(na->handler);
2184 ecore_file_remove(na->ud.fname);
2186 na->ud.fname = NULL;
2190 EINA_LIST_FOREACH(wd->track, l, t)
2192 EINA_LIST_FREE(t->path, p)
2197 EINA_LIST_FREE(t->nodes, n)
2199 if (n->pos.address) eina_stringshare_del(n->pos.address);
2204 if (wd->map) evas_map_free(wd->map);
2205 if (wd->source_names) free(wd->source_names);
2206 if (wd->calc_job) ecore_job_del(wd->calc_job);
2207 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2208 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2209 if (wd->long_timer) ecore_timer_del(wd->long_timer);
2210 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2211 if (wd->ua) eina_hash_free(wd->ua);
2212 if (wd->markers) free(wd->markers);
2218 _del_pre_hook(Evas_Object *obj)
2220 ELM_CHECK_WIDTYPE(obj, widtype);
2221 Widget_Data *wd = elm_widget_data_get(obj);
2222 Marker_Group *group;
2223 Elm_Map_Marker *marker;
2225 Eina_Bool free_marker = EINA_TRUE;
2230 for (i = 0; i <= wd->zoom_max; i++)
2232 if (!wd->markers[i]) continue;
2233 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2234 Eina_Matrixsparse_Cell *cell;
2236 EINA_ITERATOR_FOREACH(it, cell)
2238 l = eina_matrixsparse_cell_data_get(cell);
2239 EINA_LIST_FREE(l, group)
2241 EINA_LIST_FREE(group->markers, marker)
2243 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2244 _bubble_sc_hits_changed_cb, group);
2245 if (free_marker) free(marker);
2249 free_marker = EINA_FALSE;
2251 eina_iterator_free(it);
2252 eina_matrixsparse_free(wd->markers[i]);
2255 evas_object_del(wd->sep_maps_markers);
2256 evas_object_del(wd->pan_smart);
2257 wd->pan_smart = NULL;
2261 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2263 ELM_CHECK_WIDTYPE(obj, widtype);
2264 Widget_Data *wd = elm_widget_data_get(obj);
2267 if (elm_widget_focus_get(obj))
2269 edje_object_signal_emit(wd->obj, "elm,action,focus", "elm");
2270 evas_object_focus_set(wd->obj, EINA_TRUE);
2274 edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
2275 evas_object_focus_set(wd->obj, EINA_FALSE);
2280 _theme_hook(Evas_Object *obj)
2282 ELM_CHECK_WIDTYPE(obj, widtype);
2283 Widget_Data *wd = elm_widget_data_get(obj);
2286 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2287 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2292 _sizing_eval(Evas_Object *obj)
2294 ELM_CHECK_WIDTYPE(obj, widtype);
2295 Widget_Data *wd = elm_widget_data_get(obj);
2296 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2299 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2300 evas_object_size_hint_min_set(obj, minw, minh);
2301 evas_object_size_hint_max_set(obj, maxw, maxh);
2305 _calc_job(void *data)
2307 Widget_Data *wd = data;
2308 Evas_Coord minw, minh;
2315 wd->resized = EINA_FALSE;
2316 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2318 double tz = wd->zoom;
2320 elm_map_zoom_set(wd->obj, tz);
2323 if ((minw != wd->minw) || (minh != wd->minh))
2327 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2328 _sizing_eval(wd->obj);
2330 wd->calc_job = NULL;
2331 evas_object_smart_changed(wd->pan_smart);
2335 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2337 Pan *sd = evas_object_smart_data_get(obj);
2339 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2342 evas_object_smart_changed(obj);
2346 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2348 Pan *sd = evas_object_smart_data_get(obj);
2350 if (x) *x = sd->wd->pan_x;
2351 if (y) *y = sd->wd->pan_y;
2355 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2357 Pan *sd = evas_object_smart_data_get(obj);
2360 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2361 ow = sd->wd->minw - ow;
2363 oh = sd->wd->minh - oh;
2370 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2377 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2379 Pan *sd = evas_object_smart_data_get(obj);
2381 if (w) *w = sd->wd->minw;
2382 if (h) *h = sd->wd->minh;
2386 _pan_add(Evas_Object *obj)
2389 Evas_Object_Smart_Clipped_Data *cd;
2391 cd = evas_object_smart_data_get(obj);
2393 sd = calloc(1, sizeof(Pan));
2395 sd->__clipped_data = *cd;
2397 evas_object_smart_data_set(obj, sd);
2401 _pan_del(Evas_Object *obj)
2403 Pan *sd = evas_object_smart_data_get(obj);
2409 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2411 Pan *sd = evas_object_smart_data_get(obj);
2414 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2415 if ((ow == w) && (oh == h)) return;
2416 sd->wd->resized = EINA_TRUE;
2417 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2418 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2422 _pan_calculate(Evas_Object *obj)
2424 Pan *sd = evas_object_smart_data_get(obj);
2425 Evas_Coord ox, oy, ow, oh;
2429 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2430 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2431 EINA_LIST_FOREACH(sd->wd->grids, l, g)
2433 if ((sd->wd->pinch.level == 1.0) || (sd->wd->pinch.level == 0.5)) grid_load(sd->wd->obj, g);
2434 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2435 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2436 if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2437 if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2442 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2444 Pan *sd = evas_object_smart_data_get(obj);
2446 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2447 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2451 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2453 ELM_CHECK_WIDTYPE(obj, widtype);
2454 Widget_Data *wd = elm_widget_data_get(obj);
2457 elm_smart_scroller_hold_set(wd->scr, 1);
2461 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2463 ELM_CHECK_WIDTYPE(obj, widtype);
2464 Widget_Data *wd = elm_widget_data_get(obj);
2467 elm_smart_scroller_hold_set(wd->scr, 0);
2471 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2473 ELM_CHECK_WIDTYPE(obj, widtype);
2474 Widget_Data *wd = elm_widget_data_get(obj);
2477 elm_smart_scroller_freeze_set(wd->scr, 1);
2481 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2483 ELM_CHECK_WIDTYPE(obj, widtype);
2484 Widget_Data *wd = elm_widget_data_get(obj);
2487 elm_smart_scroller_freeze_set(wd->scr, 0);
2491 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2493 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2497 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2499 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2503 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2505 Widget_Data *wd = elm_widget_data_get(data);
2506 wd->center_on.enabled = EINA_FALSE;
2507 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2511 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2513 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2517 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2519 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2524 _group_object_create(Marker_Group *group)
2526 const char *style = "radio";
2527 Evas_Object *icon = NULL;
2529 if (group->obj) return;
2530 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2532 //set icon and style
2533 if (eina_list_count(group->markers) == 1)
2535 Elm_Map_Marker *m = eina_list_data_get(group->markers);
2537 style = m->clas->style;
2539 if (m->clas->func.icon_get)
2540 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2542 group->delete_object = EINA_TRUE;
2546 if (group->clas->style)
2547 style = group->clas->style;
2549 if (group->clas->func.icon_get)
2550 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2552 group->delete_object = EINA_FALSE;
2555 group->obj = elm_layout_add(group->wd->obj);
2556 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2558 if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
2560 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2561 elm_widget_sub_object_add(group->wd->obj, group->obj);
2562 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2564 if (!group->delete_object)
2565 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2569 group->delete_object = EINA_FALSE;
2571 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2572 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2573 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2574 evas_object_show(group->obj);
2577 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2578 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2580 group->update_nbelems = EINA_TRUE;
2581 group->update_resize = EINA_TRUE;
2582 group->update_raise = EINA_TRUE;
2584 if (group->open) _group_bubble_create(group);
2588 _group_object_free(Marker_Group *group)
2590 if (!group->obj) return;
2591 if (!group->delete_object)
2593 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2594 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2595 evas_object_hide(group->obj);
2597 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2598 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2601 evas_object_del(group->obj);
2604 _group_bubble_free(group);
2608 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2610 Marker_Group *group = data;
2612 if (!evas_object_above_get(group->rect)) return;
2613 evas_object_raise(group->bubble);
2614 evas_object_raise(group->sc);
2615 evas_object_raise(group->rect);
2619 _group_bubble_create(Marker_Group *group)
2621 if (group->bubble) return;
2623 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2624 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2625 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2626 elm_widget_style_get(group->wd->obj));
2627 evas_object_smart_member_add(group->bubble,
2629 elm_widget_sub_object_add(group->wd->obj, group->bubble);
2631 _group_bubble_content_free(group);
2632 if (!_group_bubble_content_update(group))
2634 //no content, we can delete the bubble
2635 _group_bubble_free(group);
2639 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2640 evas_object_color_set(group->rect, 0, 0, 0, 0);
2641 evas_object_repeat_events_set(group->rect, EINA_TRUE);
2642 evas_object_smart_member_add(group->rect, group->wd->obj);
2643 elm_widget_sub_object_add(group->wd->obj, group->rect);
2645 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2647 _group_bubble_place(group);
2650 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2652 _group_bubble_place(data);
2656 _group_bubble_content_update(Marker_Group *group)
2659 Elm_Map_Marker *marker;
2662 if (!group->bubble) return 1;
2666 group->sc = elm_scroller_add(group->bubble);
2667 elm_widget_style_set(group->sc, "map_bubble");
2668 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2669 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2670 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2671 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2672 evas_object_show(group->sc);
2673 evas_object_smart_member_add(group->sc,
2675 elm_widget_sub_object_add(group->wd->obj, group->sc);
2677 group->bx = elm_box_add(group->bubble);
2678 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2679 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2680 elm_box_horizontal_set(group->bx, EINA_TRUE);
2681 evas_object_show(group->bx);
2683 elm_scroller_content_set(group->sc, group->bx);
2685 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
2686 _bubble_sc_hits_changed_cb, group);
2689 EINA_LIST_FOREACH(group->markers, l, marker)
2691 if (i >= group->wd->markers_max_num) break;
2692 if ((!marker->content) && (marker->clas->func.get))
2693 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2694 else if (marker->content)
2695 elm_box_unpack(group->bx, marker->content);
2696 if (marker->content)
2698 elm_box_pack_end(group->bx, marker->content);
2706 _group_bubble_content_free(Marker_Group *group)
2709 Elm_Map_Marker *marker;
2711 if (!group->sc) return;
2712 EINA_LIST_FOREACH(group->markers, l, marker)
2714 if ((marker->content) && (marker->clas->func.del))
2715 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2716 else if (marker->content)
2717 evas_object_del(marker->content);
2718 marker->content = NULL;
2720 evas_object_del(group->sc);
2725 _group_bubble_free(Marker_Group *group)
2727 if (!group->bubble) return;
2728 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2729 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2730 _bubble_sc_hits_changed_cb, group);
2731 evas_object_del(group->bubble);
2732 evas_object_del(group->rect);
2733 group->bubble = NULL;
2734 _group_bubble_content_free(group);
2738 _group_bubble_place(Marker_Group *group)
2741 Evas_Coord xx, yy, ww, hh;
2744 if ((!group->bubble) || (!group->obj)) return;
2746 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2747 edje_object_size_min_calc(group->bubble, NULL, &hh);
2749 s = edje_object_data_get(group->bubble, "size_w");
2750 if (s) ww = atoi(s);
2752 xx = x + w / 2 - ww / 2;
2755 evas_object_move(group->bubble, xx, yy);
2756 evas_object_resize(group->bubble, ww, hh);
2757 obj_rotate_zoom(group->wd, group->bubble);
2758 evas_object_show(group->bubble);
2760 evas_object_move(group->rect, xx, yy);
2761 evas_object_resize(group->rect, ww, hh);
2762 obj_rotate_zoom(group->wd, group->rect);
2763 evas_object_show(group->rect);
2767 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2769 Marker_Group *group = data;
2770 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2771 if (!marker) return;
2772 group->bringin = EINA_TRUE;
2773 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2777 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2779 Marker_Group *group = data;
2783 group->bringin = EINA_FALSE;
2789 group->open = EINA_FALSE;
2790 _group_bubble_free(group);
2793 group->open = EINA_TRUE;
2794 _group_bubble_create(group);
2798 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2800 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2801 Widget_Data *wd = elm_widget_data_get(obj);
2805 Evas_Coord step_x = 0;
2806 Evas_Coord step_y = 0;
2809 Evas_Coord page_x = 0;
2810 Evas_Coord page_y = 0;
2812 if (!wd) return EINA_FALSE;
2813 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2814 Evas_Event_Key_Down *ev = event_info;
2815 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2817 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2818 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2819 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2820 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2822 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2826 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2830 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2834 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2838 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2841 y -= -(page_y * v_h) / 100;
2845 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2848 y += -(page_y * v_h) / 100;
2852 else if (!strcmp(ev->keyname, "KP_Add"))
2854 zoom = elm_map_zoom_get(obj) + 1;
2855 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2856 elm_map_zoom_set(obj, zoom);
2859 else if (!strcmp(ev->keyname, "KP_Subtract"))
2861 zoom = elm_map_zoom_get(obj) - 1;
2862 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2863 elm_map_zoom_set(obj, zoom);
2866 else return EINA_FALSE;
2868 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2869 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2875 cb_dump_name_attrs(void *data, const char *key, const char *value)
2877 Name_Dump *dump = (Name_Dump*)data;
2878 if (!dump) return EINA_FALSE;
2880 if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2881 else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2888 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2890 Route_Dump *dump = data;
2891 if (!dump) return EINA_FALSE;
2895 case EINA_SIMPLE_XML_OPEN:
2896 case EINA_SIMPLE_XML_OPEN_EMPTY:
2900 attrs = eina_simple_xml_tag_attributes_find(value, length);
2903 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2904 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2905 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2906 else dump->id = ROUTE_XML_NONE;
2910 case EINA_SIMPLE_XML_DATA:
2912 char *buf = malloc(length);
2913 if (!buf) return EINA_FALSE;
2914 snprintf(buf, length, "%s", value);
2915 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2916 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2917 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2929 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2931 Name_Dump *dump = data;
2932 if (!dump) return EINA_FALSE;
2936 case EINA_SIMPLE_XML_OPEN:
2937 case EINA_SIMPLE_XML_OPEN_EMPTY:
2940 attrs = eina_simple_xml_tag_attributes_find(value, length);
2943 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2944 else dump->id = NAME_XML_NONE;
2946 eina_simple_xml_attributes_parse
2947 (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2951 case EINA_SIMPLE_XML_DATA:
2953 char *buf = malloc(length + 1);
2954 if (!buf) return EINA_FALSE;
2955 snprintf(buf, length + 1, "%s", value);
2956 if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2968 _parse_kml(void *data)
2970 Elm_Map_Route *r = (Elm_Map_Route*)data;
2971 if (!r && !r->ud.fname) return;
2975 unsigned int ele, idx;
2979 Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2981 f = fopen(r->ud.fname, "rb");
2986 fseek(f, 0, SEEK_END);
2992 fseek(f, 0, SEEK_SET);
2996 if (fread(buf, 1, sz, f))
2998 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
3005 if (dump.distance) r->info.distance = dump.distance;
3006 if (dump.description)
3008 eina_stringshare_replace(&r->info.waypoints, dump.description);
3009 str = eina_str_split_full(dump.description, "\n", 0, &ele);
3010 r->info.waypoint_count = ele;
3011 for (idx = 0 ; idx < ele ; idx++)
3013 Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
3017 wp->point = eina_stringshare_add(str[idx]);
3018 DBG("%s", str[idx]);
3019 r->waypoint = eina_list_append(r->waypoint, wp);
3028 else WRN("description is not found !");
3030 if (dump.coordinates)
3032 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
3033 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
3034 r->info.node_count = ele;
3035 for (idx = 0 ; idx < ele ; idx++)
3037 sscanf(str[idx], "%lf,%lf", &lon, &lat);
3038 Path_Node *n = ELM_NEW(Path_Node);
3045 DBG("%lf:%lf", lon, lat);
3046 n->pos.address = NULL;
3047 r->nodes = eina_list_append(r->nodes, n);
3049 path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
3050 evas_object_smart_member_add(path, r->wd->pan_smart);
3051 r->path = eina_list_append(r->path, path);
3064 _parse_name(void *data)
3066 Elm_Map_Name *n = (Elm_Map_Name*)data;
3067 if (!n && !n->ud.fname) return;
3071 Name_Dump dump = {0, NULL, 0.0, 0.0};
3073 f = fopen(n->ud.fname, "rb");
3078 fseek(f, 0, SEEK_END);
3084 fseek(f, 0, SEEK_SET);
3088 if (fread(buf, 1, sz, f))
3090 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3099 INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3100 n->address = strdup(dump.address);
3108 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3110 Ecore_Con_Event_Url_Complete *ev = event;
3111 Elm_Map_Route *r = (Elm_Map_Route*)data;
3112 Widget_Data *wd = r->wd;
3114 if ((!r) || (!ev)) return EINA_TRUE;
3115 Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3116 ecore_con_url_data_set(r->con_url, NULL);
3117 if (r!=rr) return EINA_TRUE;
3119 if (r->ud.fd) fclose(r->ud.fd);
3124 Evas_Coord ox, oy, ow, oh;
3125 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3126 route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3128 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3129 "elm,state,busy,stop", "elm");
3130 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3135 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3137 Ecore_Con_Event_Url_Complete *ev = event;
3138 Elm_Map_Name *n = (Elm_Map_Name*)data;
3139 Widget_Data *wd = n->wd;
3141 if ((!n) || (!ev)) return EINA_TRUE;
3142 Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3143 ecore_con_url_data_set(n->con_url, NULL);
3144 if (n!=nn) return EINA_TRUE;
3146 if (n->ud.fd) fclose(n->ud.fd);
3149 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3150 "elm,state,busy,stop", "elm");
3151 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3155 static Elm_Map_Name *
3156 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3158 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3159 Widget_Data *wd = elm_widget_data_get(obj);
3164 if ((!wd) || (!wd->src)) return NULL;
3165 Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3166 if (!name) return NULL;
3168 snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3176 name->con_url = ecore_con_url_new(NULL);
3177 name->ud.fname = strdup(buf);
3178 INF("xml file : %s", name->ud.fname);
3180 name->ud.fd = fdopen(fd, "w+");
3181 if ((!name->con_url) || (!name->ud.fd))
3183 ecore_con_url_free(name->con_url);
3189 name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3190 name->method = method;
3191 if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3192 else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3196 source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3197 INF("name url = %s", source);
3199 wd->names = eina_list_append(wd->names, name);
3200 ecore_con_url_url_set(name->con_url, source);
3201 ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3202 ecore_con_url_data_set(name->con_url, name);
3204 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3205 "elm,state,busy,start", "elm");
3206 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3207 ecore_con_url_get(name->con_url);
3208 if (source) free(source);
3215 cb_dump_track_attr(void *data, const char *key, const char *value)
3217 Track_Dump *dump = data;
3221 if (!dump) return EINA_FALSE;
3222 if (!strcmp(GPX_LON, key))
3224 sscanf(value, "%lf", &d);
3227 else if (!strcmp(GPX_LAT, key))
3229 sscanf(value, "%lf", &d);
3233 if ((dump->lon) && (dump->lat))
3235 Path_Node *n = ELM_NEW(Path_Node);
3238 n->wd = dump->track->wd;
3239 n->pos.lon = dump->lon;
3240 n->pos.lat = dump->lat;
3241 n->idx = dump->idx++;
3242 INF("[%d] %lf:%lf", n->idx, dump->lon, dump->lat);
3243 n->pos.address = NULL;
3244 dump->track->nodes = eina_list_append(dump->track->nodes, n);
3246 path = evas_object_polygon_add(evas_object_evas_get(dump->track->wd->obj));
3247 evas_object_smart_member_add(path, dump->track->wd->pan_smart);
3248 dump->track->path = eina_list_append(dump->track->path, path);
3258 cb_track_dump(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset __UNUSED__, unsigned length __UNUSED__)
3260 Track_Dump *d = data;
3262 if (!d) return EINA_FALSE;
3263 if (type == EINA_SIMPLE_XML_OPEN)
3265 if (!strncmp(GPX_COORDINATES, content, strlen(GPX_COORDINATES)))
3267 const char *tags = eina_simple_xml_tag_attributes_find(content, length);
3268 eina_simple_xml_attributes_parse(tags, length - (tags - content), cb_dump_track_attr, d);
3274 static int idnum = 1;
3277 * Add a new Map object
3279 * @param parent The parent object
3280 * @return The new object or NULL if it cannot be created
3285 elm_map_add(Evas_Object *parent)
3289 Evas_Coord minw, minh;
3291 static Evas_Smart *smart = NULL;
3292 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3294 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3296 ELM_SET_WIDTYPE(widtype, "map");
3297 elm_widget_type_set(obj, "map");
3298 elm_widget_sub_object_add(parent, obj);
3299 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3300 elm_widget_data_set(obj, wd);
3301 elm_widget_del_hook_set(obj, _del_hook);
3302 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3303 elm_widget_theme_hook_set(obj, _theme_hook);
3304 elm_widget_can_focus_set(obj, EINA_TRUE);
3305 elm_widget_event_hook_set(obj, _event_hook);
3307 wd->scr = elm_smart_scroller_add(e);
3308 elm_smart_scroller_widget_set(wd->scr, obj);
3309 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3310 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3311 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3312 elm_widget_resize_object_set(obj, wd->scr);
3313 elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3315 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3316 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3317 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3318 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3319 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3321 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3325 wd->map = evas_map_new(4);
3326 if (!wd->map) return NULL;
3328 wd->zoom_min = 0xFF;
3329 wd->zoom_max = 0X00;
3330 wd->markers_max_num = 30;
3331 wd->pinch.level = 1.0;
3334 wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3336 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3337 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3338 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3339 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3343 static Evas_Smart_Class sc;
3345 evas_object_smart_clipped_smart_set(&_pan_sc);
3347 sc.name = "elm_map_pan";
3348 sc.version = EVAS_SMART_CLASS_VERSION;
3351 sc.resize = _pan_resize;
3352 sc.move = _pan_move;
3353 sc.calculate = _pan_calculate;
3354 smart = evas_smart_class_new(&sc);
3358 wd->pan_smart = evas_object_smart_add(e, smart);
3359 wd->pan = evas_object_smart_data_get(wd->pan_smart);
3363 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3364 _pan_set, _pan_get, _pan_max_get,
3365 _pan_min_get, _pan_child_size_get);
3367 wd->rect = evas_object_rectangle_add(e);
3368 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3369 _rect_resize_cb, obj);
3370 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3372 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3374 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3376 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3377 _mouse_multi_down, obj);
3378 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3379 _mouse_multi_move, obj);
3380 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3381 _mouse_multi_up, obj);
3382 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3383 _mouse_wheel_cb, obj);
3385 evas_object_smart_member_add(wd->rect, wd->pan_smart);
3386 elm_widget_sub_object_add(obj, wd->rect);
3387 evas_object_show(wd->rect);
3388 evas_object_color_set(wd->rect, 0, 0, 0, 0);
3390 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3391 wd->id = ((int)getpid() << 16) | idnum;
3395 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3397 evas_object_size_hint_min_set(obj, minw, minh);
3399 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3400 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3402 wd->paused = EINA_TRUE;
3403 elm_map_zoom_set(obj, 0);
3404 wd->paused = EINA_FALSE;
3407 // TODO: convert Elementary to subclassing of Evas_Smart_Class
3408 // TODO: and save some bytes, making descriptions per-class and not instance!
3409 evas_object_smart_callbacks_descriptions_set(obj, _signals);
3411 if (!ecore_file_download_protocol_available("http://"))
3413 ERR("Ecore must be built with curl support for the map widget!");
3420 * Set the zoom level of the map
3422 * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
3424 * @param obj The map object
3425 * @param zoom The zoom level to set
3430 elm_map_zoom_set(Evas_Object *obj, int zoom)
3432 ELM_CHECK_WIDTYPE(obj, widtype);
3433 Widget_Data *wd = elm_widget_data_get(obj);
3435 Grid *g, *g_zoom = NULL;
3436 Evas_Coord rx, ry, rw, rh;
3440 int z = 0, zoom_changed = 0, started = 0;
3442 if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3443 if (zoom < 0 ) zoom = 0;
3444 if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3445 if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3447 if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3448 else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3449 else wd->zoom_method = ZOOM_METHOD_NONE;
3450 if (wd->zoom != zoom ) zoom_changed = 1;
3452 wd->size.ow = wd->size.w;
3453 wd->size.oh = wd->size.h;
3454 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3455 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3457 EINA_LIST_FOREACH(wd->route, l, r)
3461 EINA_LIST_FOREACH(r->path, l, p)
3463 evas_object_polygon_points_clear(p);
3468 EINA_LIST_FOREACH(wd->track, l, t)
3472 EINA_LIST_FOREACH(t->path, l, p)
3474 evas_object_polygon_points_clear(p);
3479 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3486 while (cumulw <= rw)
3495 while (cumulh <= rh)
3502 if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3504 if (p2w < p2h) z = p2w;
3507 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3509 if (p2w > p2h) z = p2w;
3514 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3515 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3517 g = grid_create(obj);
3520 if (eina_list_count(wd->grids) > 1)
3522 g_zoom = eina_list_last(wd->grids)->data;
3523 wd->grids = eina_list_remove(wd->grids, g_zoom);
3524 grid_clear(obj, g_zoom);
3527 wd->grids = eina_list_prepend(wd->grids, g);
3531 EINA_LIST_FREE(wd->grids, g)
3539 if ((wd->size.w > 0) && (wd->size.h > 0))
3541 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3542 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3546 wd->size.spos.x = 0.5;
3547 wd->size.spos.y = 0.5;
3550 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3551 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3552 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3553 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3558 if (wd->calc_job) ecore_job_del(wd->calc_job);
3559 wd->calc_job = ecore_job_add(_calc_job, wd);
3563 if (!wd->zoom_animator)
3565 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3567 if (wd->nosmooth == 1) _smooth_update(obj);
3574 if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3575 if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3578 if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3582 * Get the zoom level of the map
3584 * This returns the current zoom level of the map object. Note that if
3585 * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
3586 * (which is the default), the zoom level may be changed at any time by the
3587 * map object itself to account for map size and map viewpoer size
3589 * @param obj The map object
3590 * @return The current zoom level
3595 elm_map_zoom_get(const Evas_Object *obj)
3597 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3598 Widget_Data *wd = elm_widget_data_get(obj);
3607 * This sets the zoom mode to manual or one of several automatic levels.
3608 * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
3609 * elm_map_zoom_set() and will stay at that level until changed by code
3610 * or until zoom mode is changed. This is the default mode.
3611 * The Automatic modes will allow the map object to automatically
3612 * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT will
3613 * adjust zoom so the map fits inside the scroll frame with no pixels
3614 * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
3615 * 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.
3617 * @param obj The map object
3618 * @param mode The desired mode
3623 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3625 ELM_CHECK_WIDTYPE(obj, widtype);
3626 Widget_Data *wd = elm_widget_data_get(obj);
3629 if (wd->mode == mode) return;
3632 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3636 elm_map_zoom_set(wd->obj, tz);
3643 * This gets the current zoom mode of the map object
3645 * @param obj The map object
3646 * @return The current zoom mode
3650 EAPI Elm_Map_Zoom_Mode
3651 elm_map_zoom_mode_get(const Evas_Object *obj)
3653 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3654 Widget_Data *wd = elm_widget_data_get(obj);
3656 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3661 * Centers the map at @p lon @p lat using an animation to scroll.
3663 * @param obj The map object
3664 * @param lon Longitude to center at
3665 * @param lon Latitude to center at
3670 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3672 ELM_CHECK_WIDTYPE(obj, widtype);
3673 Widget_Data *wd = elm_widget_data_get(obj);
3677 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3678 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3683 if (wd->zoom_animator)
3686 if (!wd->nosmooth) _smooth_update(obj);
3687 ecore_animator_del(wd->zoom_animator);
3688 wd->zoom_animator = NULL;
3690 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3692 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3694 wd->center_on.enabled = EINA_TRUE;
3695 wd->center_on.lon = lon;
3696 wd->center_on.lat = lat;
3700 * Move the map to the current coordinates.
3702 * This move the map to the current coordinates. The map will be centered on these coordinates.
3704 * @param obj The map object
3705 * @param lat The latitude.
3706 * @param lon The longitude.
3711 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3713 ELM_CHECK_WIDTYPE(obj, widtype);
3714 Widget_Data *wd = elm_widget_data_get(obj);
3718 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3719 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3724 if (wd->zoom_animator)
3727 ecore_animator_del(wd->zoom_animator);
3728 wd->zoom_animator = NULL;
3730 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3732 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3734 wd->center_on.enabled = EINA_TRUE;
3735 wd->center_on.lon = lon;
3736 wd->center_on.lat = lat;
3740 * Get the current coordinates of the map.
3742 * This gets the current coordinates of the map object.
3744 * @param obj The map object
3745 * @param lat The latitude.
3746 * @param lon The longitude.
3751 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3753 ELM_CHECK_WIDTYPE(obj, widtype);
3754 Widget_Data *wd = elm_widget_data_get(obj);
3755 Evas_Coord sx, sy, sw, sh;
3758 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3759 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3763 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3767 * Set the paused state for map
3769 * This sets the paused state to on (1) or off (0) for map. The default
3770 * is off. This will stop zooming using animation change zoom levels and
3771 * change instantly. This will stop any existing animations that are running.
3773 * @param obj The map object
3774 * @param paused The pause state to set
3779 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3781 ELM_CHECK_WIDTYPE(obj, widtype);
3782 Widget_Data *wd = elm_widget_data_get(obj);
3785 if (wd->paused == !!paused) return;
3786 wd->paused = paused;
3789 if (wd->zoom_animator)
3791 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3792 wd->zoom_animator = NULL;
3794 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3800 * Set the paused state for the markers
3802 * This sets the paused state to on (1) or off (0) for the markers. The default
3803 * is off. This will stop displaying the markers during change zoom levels. Set
3804 * to on if you have a large number of markers.
3806 * @param obj The map object
3807 * @param paused The pause state to set
3812 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3814 ELM_CHECK_WIDTYPE(obj, widtype);
3815 Widget_Data *wd = elm_widget_data_get(obj);
3818 if (wd->paused_markers == !!paused) return;
3819 wd->paused_markers = paused;
3823 * Get the paused state for map
3825 * This gets the current paused state for the map object.
3827 * @param obj The map object
3828 * @return The current paused state
3833 elm_map_paused_get(const Evas_Object *obj)
3835 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3836 Widget_Data *wd = elm_widget_data_get(obj);
3838 if (!wd) return EINA_FALSE;
3843 * Get the paused state for the markers
3845 * This gets the current paused state for the markers object.
3847 * @param obj The map object
3848 * @return The current paused state
3853 elm_map_paused_markers_get(const Evas_Object *obj)
3855 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3856 Widget_Data *wd = elm_widget_data_get(obj);
3858 if (!wd) return EINA_FALSE;
3859 return wd->paused_markers;
3863 * Get the information of downloading status
3865 * This gets the current downloading status for the map object.
3867 * @param obj The map object
3868 * @param try_num the number of download trying map
3869 * @param finish_num the number of downloaded map
3875 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3877 ELM_CHECK_WIDTYPE(obj, widtype);
3878 Widget_Data *wd = elm_widget_data_get(obj);
3883 *try_num = wd->try_num;
3888 *finish_num = wd->finish_num;
3892 * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
3894 * @param obj The map object
3895 * @param x the coordinate
3896 * @param y the coordinate
3897 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3898 * @param lon the longitude correspond to x
3899 * @param lat the latitude correspond to y
3904 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3906 ELM_CHECK_WIDTYPE(obj, widtype);
3907 Widget_Data *wd = elm_widget_data_get(obj);
3910 int zoom = floor(log(size / 256) / log(2));
3911 if ((wd->src) && (wd->src->coord_into_geo))
3913 if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3918 *lon = x / (double)size * 360.0 - 180;
3922 double n = ELM_PI - 2.0 * ELM_PI * y / size;
3923 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3928 * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
3930 * @param obj The map object
3931 * @param lon the longitude
3932 * @param lat the latitude
3933 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3934 * @param x the coordinate correspond to the longitude
3935 * @param y the coordinate correspond to the latitude
3940 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3942 ELM_CHECK_WIDTYPE(obj, widtype);
3943 Widget_Data *wd = elm_widget_data_get(obj);
3946 int zoom = floor(log(size / 256) / log(2));
3947 if ((wd->src) && (wd->src->geo_into_coord))
3949 if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3953 *x = floor((lon + 180.0) / 360.0 * size);
3955 *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3959 * Convert a geographic coordinate (longitude, latitude) into a name (address).
3961 * @param obj The map object
3962 * @param lon the longitude
3963 * @param lat the latitude
3965 * @return name the address
3970 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3972 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3973 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3977 * Convert a name (address) into a geographic coordinate (longitude, latitude).
3979 * @param obj The map object
3980 * @param name the address
3981 * @param lat the latitude correspond to y
3983 * @return name the address
3988 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3990 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3991 if (!address) return NULL;
3992 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3996 * Convert a pixel coordinate into a roated pixcel coordinate.
3998 * @param obj The map object
3999 * @param x x to rotate.
4000 * @param y y to rotate.
4001 * @param cx rotation's center horizontal position.
4002 * @param cy rotation's center vertical position.
4003 * @param degree amount of degrees from 0.0 to 360.0 to rotate arount Z axis.
4004 * @param xx rotated x.
4005 * @param yy rotated y.
4010 elm_map_utils_rotate_coord(const Evas_Object *obj __UNUSED__, const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
4012 if ((!xx) || (!yy)) return;
4014 double r = (degree * M_PI) / 180.0;
4015 double tx, ty, ttx, tty;
4022 tx = ttx + (ty * cos(r + M_PI_2));
4023 ty = tty + (ty * sin(r + M_PI_2));
4030 * Add a marker on the map
4032 * @param obj The map object
4033 * @param lon the longitude
4034 * @param lat the latitude
4035 * @param clas the class to use
4036 * @param clas_group the class group
4037 * @param data the data passed to the callbacks
4039 * @return The marker object
4043 EAPI Elm_Map_Marker *
4044 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
4046 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4047 Widget_Data *wd = elm_widget_data_get(obj);
4050 Marker_Group *group;
4058 if (!wd) return NULL;
4059 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
4060 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
4062 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
4065 marker->clas = clas;
4066 marker->clas_group = clas_group;
4067 marker->longitude = lon;
4068 marker->latitude = lat;
4069 marker->data = data;
4070 marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
4071 marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
4072 marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
4074 tabi[1] = tabi[4] = tabi[6] = -1;
4075 tabi[2] = tabi[0] = tabi[7] = 0;
4076 tabi[3] = tabi[5] = tabi[8] = 1;
4078 tabj[1] = tabj[2] = tabj[3] = -1;
4079 tabj[4] = tabj[0] = tabj[5] = 0;
4080 tabj[6] = tabj[7] = tabj[8] = 1;
4082 if (!clas_group->priv.set)
4085 if (marker->clas_group && marker->clas_group->style)
4086 style = marker->clas_group->style;
4088 o = edje_object_add(evas_object_evas_get(obj));
4089 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
4090 s = edje_object_data_get(o, "size_w");
4091 if (s) clas_group->priv.edje_w = atoi(s);
4092 else clas_group->priv.edje_w = 0;
4093 s = edje_object_data_get(o, "size_h");
4094 if (s) clas_group->priv.edje_h = atoi(s);
4095 else clas_group->priv.edje_h = 0;
4096 s = edje_object_data_get(o, "size_max_w");
4097 if (s) clas_group->priv.edje_max_w = atoi(s);
4098 else clas_group->priv.edje_max_w = 0;
4099 s = edje_object_data_get(o, "size_max_h");
4100 if (s) clas_group->priv.edje_max_h = atoi(s);
4101 else clas_group->priv.edje_max_h = 0;
4104 clas_group->priv.set = EINA_TRUE;
4107 if (!clas->priv.set)
4110 if (marker->clas && marker->clas->style)
4111 style = marker->clas->style;
4113 o = edje_object_add(evas_object_evas_get(obj));
4114 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
4115 s = edje_object_data_get(o, "size_w");
4116 if (s) clas->priv.edje_w = atoi(s);
4117 else clas->priv.edje_w = 0;
4118 s = edje_object_data_get(o, "size_h");
4119 if (s) clas->priv.edje_h = atoi(s);
4120 else clas->priv.edje_h = 0;
4123 clas->priv.set = EINA_TRUE;
4126 for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4128 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
4129 &(marker->x[i]), &(marker->y[i]));
4131 //search in the matrixsparse the region where the marker will be
4132 mpi = marker->x[i] / wd->tsize;
4133 mpj = marker->y[i] / wd->tsize;
4135 if (!wd->markers[i])
4137 int size = pow(2.0, i);
4138 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
4142 if (i <= clas_group->zoom_grouped)
4144 for (j = 0, group = NULL; j < 9 && !group; j++)
4146 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
4149 if (group->clas == marker->clas_group
4150 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
4151 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
4152 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
4154 group->markers = eina_list_append(group->markers, marker);
4155 group->update_nbelems = EINA_TRUE;
4156 group->update_resize = EINA_TRUE;
4158 group->sum_x += marker->x[i];
4159 group->sum_y += marker->y[i];
4160 group->x = group->sum_x / eina_list_count(group->markers);
4161 group->y = group->sum_y / eina_list_count(group->markers);
4163 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
4164 * eina_list_count(group->markers);
4165 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
4166 * eina_list_count(group->markers);
4167 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
4168 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
4170 if (group->obj && eina_list_count(group->markers) == 2)
4172 _group_object_free(group);
4173 _group_object_create(group);
4176 _group_bubble_content_update(group);
4185 group = calloc(1, sizeof(Marker_Group));
4187 group->sum_x = marker->x[i];
4188 group->sum_y = marker->y[i];
4189 group->x = marker->x[i];
4190 group->y = marker->y[i];
4191 group->w = clas_group->priv.edje_w;
4192 group->h = clas_group->priv.edje_h;
4193 group->clas = clas_group;
4195 group->markers = eina_list_append(group->markers, marker);
4196 group->update_nbelems = EINA_TRUE;
4197 group->update_resize = EINA_TRUE;
4199 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4203 l = eina_list_append(NULL, group);
4204 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
4205 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4209 l = eina_matrixsparse_cell_data_get(group->cell);
4210 l = eina_list_append(l, group);
4211 eina_matrixsparse_cell_data_set(group->cell, l);
4214 marker->groups[i] = group;
4219 Evas_Coord ox, oy, ow, oh;
4220 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4221 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4228 * Remove a marker from the map
4230 * @param marker The marker to remove
4235 elm_map_marker_remove(Elm_Map_Marker *marker)
4241 EINA_SAFETY_ON_NULL_RETURN(marker);
4244 for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4246 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
4247 if (!eina_list_count(marker->groups[i]->markers))
4249 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
4250 groups = eina_list_remove(groups, marker->groups[i]);
4251 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
4253 _group_object_free(marker->groups[i]);
4254 _group_bubble_free(marker->groups[i]);
4255 free(marker->groups[i]);
4259 marker->groups[i]->sum_x -= marker->x[i];
4260 marker->groups[i]->sum_y -= marker->y[i];
4262 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
4263 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
4265 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
4266 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
4267 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
4268 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
4269 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
4270 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
4271 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
4272 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
4274 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
4276 _group_object_free(marker->groups[i]);
4277 _group_object_create(marker->groups[i]);
4282 if ((marker->content) && (marker->clas->func.del))
4283 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4284 else if (marker->content)
4285 evas_object_del(marker->content);
4287 if (marker->x) free(marker->x);
4288 if (marker->y) free(marker->y);
4289 if (marker->groups) free(marker->groups);
4295 Evas_Coord ox, oy, ow, oh;
4296 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4297 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4302 * Get the current coordinates of the marker.
4304 * @param marker marker.
4305 * @param lat The latitude.
4306 * @param lon The longitude.
4311 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
4313 EINA_SAFETY_ON_NULL_RETURN(marker);
4314 if (lon) *lon = marker->longitude;
4315 if (lat) *lat = marker->latitude;
4319 * Move the map to the coordinate of the marker.
4321 * @param marker The marker where the map will be center.
4326 elm_map_marker_bring_in(Elm_Map_Marker *marker)
4328 EINA_SAFETY_ON_NULL_RETURN(marker);
4329 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
4333 * Move the map to the coordinate of the marker.
4335 * @param marker The marker where the map will be center.
4340 elm_map_marker_show(Elm_Map_Marker *marker)
4342 EINA_SAFETY_ON_NULL_RETURN(marker);
4343 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
4347 * Move and zoom the map to display a list of markers.
4349 * The map will be centered on the center point of the markers in the list. Then
4350 * the map will be zoomed in order to fit the markers using the maximum zoom which
4351 * allows display of all the markers.
4353 * @param markers The list of markers (list of Elm_Map_Marker *)
4358 elm_map_markers_list_show(Eina_List *markers)
4363 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
4364 Evas_Coord rw, rh, xc, yc;
4367 EINA_SAFETY_ON_NULL_RETURN(markers);
4368 EINA_LIST_FOREACH(markers, l, marker)
4372 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
4375 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
4378 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
4381 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
4385 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
4386 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
4388 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
4389 for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
4391 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4392 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4394 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4395 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4396 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4397 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4401 elm_map_geo_region_show(wd->obj, lon, lat);
4402 elm_map_zoom_set(wd->obj, zoom);
4406 * Set the maximum numbers of markers display in a group.
4408 * A group can have a long list of markers, consequently the creation of the content
4409 * of the bubble can be very slow. In order to avoid this, a maximum number of items
4410 * is displayed in a bubble. By default this number is 30.
4412 * @param obj The map object.
4413 * @param max The maximum numbers of items displayed in a bubble.
4418 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4420 ELM_CHECK_WIDTYPE(obj, widtype);
4421 Widget_Data *wd = elm_widget_data_get(obj);
4424 wd->markers_max_num = max;
4428 * Return the evas object getting from the ElmMapMarkerGetFunc callback
4430 * @param marker The marker.
4431 * @return Return the evas object if it exists, else NULL.
4436 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4438 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4439 return marker->content;
4445 * @param marker The marker.
4450 elm_map_marker_update(Elm_Map_Marker *marker)
4452 EINA_SAFETY_ON_NULL_RETURN(marker);
4453 if (marker->content)
4455 if (marker->clas->func.del)
4456 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4458 evas_object_del(marker->content);
4459 marker->content = NULL;
4460 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4465 * Close all opened bubbles
4467 * @param obj The map object
4472 elm_map_bubbles_close(Evas_Object *obj)
4474 ELM_CHECK_WIDTYPE(obj, widtype);
4475 Widget_Data *wd = elm_widget_data_get(obj);
4476 Marker_Group *group;
4477 Eina_List *l, *l_next;
4480 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4481 _group_bubble_free(group);
4485 * Create a group class.
4487 * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
4488 * The group class defines the style of the marker when a marker is grouped to others markers.
4490 * @param obj The map object
4491 * @return Returns the new group class
4495 EAPI Elm_Map_Group_Class *
4496 elm_map_group_class_new(Evas_Object *obj)
4498 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4499 Widget_Data *wd = elm_widget_data_get(obj);
4501 if (!wd) return NULL;
4502 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4503 clas->zoom_grouped = wd->zoom_max;
4504 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4509 * Set the style of a group class (radio, radio2 or empty)
4511 * @param clas the group class
4512 * @param style the new style
4517 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4519 EINA_SAFETY_ON_NULL_RETURN(clas);
4520 eina_stringshare_replace(&clas->style, style);
4524 * Set the icon callback of a group class.
4526 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4528 * @param clas the group class
4529 * @param icon_get the callback to create the icon
4534 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4536 EINA_SAFETY_ON_NULL_RETURN(clas);
4537 clas->func.icon_get = icon_get;
4541 * Set the data associated to the group class (radio, radio2 or empty)
4543 * @param clas the group class
4544 * @param data the new user data
4549 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4551 EINA_SAFETY_ON_NULL_RETURN(clas);
4556 * Set the zoom from where the markers are displayed.
4558 * Markers will not be displayed for a zoom less than @ref zoom
4560 * @param clas the group class
4561 * @param zoom the zoom
4566 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4568 EINA_SAFETY_ON_NULL_RETURN(clas);
4569 clas->zoom_displayed = zoom;
4573 * Set the zoom from where the markers are no more grouped.
4575 * @param clas the group class
4576 * @param zoom the zoom
4581 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4583 EINA_SAFETY_ON_NULL_RETURN(clas);
4584 clas->zoom_grouped = zoom;
4588 * Set if the markers associated to the group class @clas are hidden or not.
4589 * If @ref hide is true the markers will be hidden.
4591 * @param clas the group class
4592 * @param hide if true the markers will be hidden, else they will be displayed.
4597 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4599 ELM_CHECK_WIDTYPE(obj, widtype);
4600 Widget_Data *wd = elm_widget_data_get(obj);
4603 EINA_SAFETY_ON_NULL_RETURN(clas);
4604 if (clas->hide == hide) return;
4608 Evas_Coord ox, oy, ow, oh;
4609 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4610 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4616 * Create a marker class.
4618 * Each marker must be associated to a class.
4619 * The class defines the style of the marker when a marker is displayed alone (not grouped).
4621 * @param obj The map object
4622 * @return Returns the new class
4626 EAPI Elm_Map_Marker_Class *
4627 elm_map_marker_class_new(Evas_Object *obj)
4629 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4630 Widget_Data *wd = elm_widget_data_get(obj);
4632 if (!wd) return NULL;
4633 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4634 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4639 * Set the style of a class (radio, radio2 or empty)
4641 * @param clas the group class
4642 * @param style the new style
4647 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
4649 EINA_SAFETY_ON_NULL_RETURN(clas);
4650 eina_stringshare_replace(&clas->style, style);
4654 * Set the icon callback of a class.
4656 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4658 * @param clas the group class
4659 * @param icon_get the callback to create the icon
4664 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4666 EINA_SAFETY_ON_NULL_RETURN(clas);
4667 clas->func.icon_get = icon_get;
4672 * Set the callback of the content of the bubble.
4674 * When the user click on a marker, a bubble is displayed with a content.
4675 * The callback @ref get musst return this content. It can be NULL.
4677 * @param clas the group class
4678 * @param get the callback to create the content
4683 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4685 EINA_SAFETY_ON_NULL_RETURN(clas);
4686 clas->func.get = get;
4690 * Set the callback of the content of delete the object created by the callback "get".
4692 * If this callback is defined the user will have to delete (or not) the object inside.
4693 * If the callback is not defined the object will be destroyed with evas_object_del()
4695 * @param clas the group class
4696 * @param del the callback to delete the content
4701 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4703 EINA_SAFETY_ON_NULL_RETURN(clas);
4704 clas->func.del = del;
4708 * Get the list of the sources.
4710 * @param obj The map object
4711 * @return sources the source list
4717 elm_map_source_names_get(const Evas_Object *obj)
4719 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4720 Widget_Data *wd = elm_widget_data_get(obj);
4722 if (!wd) return NULL;
4723 return wd->source_names;
4727 * Set the source of the map.
4729 * Elm_Map retrieves the image which composed the map from a web service. This web service can
4730 * be set with this method. A different service can return a different maps with different
4731 * information and it can use different zoom value.
4733 * @param obj the map object
4734 * @param source the new source
4739 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4741 ELM_CHECK_WIDTYPE(obj, widtype);
4742 Widget_Data *wd = elm_widget_data_get(obj);
4749 if ((wd->src) && (!strcmp(wd->src->name, source_name))) return;
4750 if ((wd->src) && (!wd->src->url_cb)) return;
4752 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4753 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4755 if (!strcmp(s->name, source_name))
4764 if (wd->src->zoom_max < zoom)
4765 zoom = wd->src->zoom_max;
4766 if (wd->src->zoom_min > zoom)
4767 zoom = wd->src->zoom_min;
4769 elm_map_zoom_set(obj, zoom);
4773 * Get the name of a source.
4775 * @param source the source
4776 * @return Returns the name of the source
4781 elm_map_source_name_get(const Evas_Object *obj)
4783 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4784 Widget_Data *wd = elm_widget_data_get(obj);
4786 if ((!wd) || (!wd->src)) return NULL;
4787 return wd->src->name;
4791 * Set the source of the route.
4793 * @param clas the group class
4794 * @param source the new source
4799 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4801 ELM_CHECK_WIDTYPE(obj, widtype);
4802 Widget_Data *wd = elm_widget_data_get(obj);
4805 wd->route_source = source;
4809 * Get the current route source
4811 * @param obj the map object
4812 * @return Returns the source of the route
4816 EAPI Elm_Map_Route_Sources
4817 elm_map_route_source_get(const Evas_Object *obj)
4819 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4820 Widget_Data *wd = elm_widget_data_get(obj);
4822 if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4823 return wd->route_source;
4827 * Set the maximum zoom of the source.
4829 * @param source the source
4834 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4836 ELM_CHECK_WIDTYPE(obj, widtype);
4837 Widget_Data *wd = elm_widget_data_get(obj);
4839 if ((!wd) || (!wd->src)) return;
4840 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4841 wd->src->zoom_max = zoom;
4845 * Get the maximum zoom of the source.
4847 * @param source the source
4848 * @return Returns the maximum zoom of the source
4853 elm_map_source_zoom_max_get(const Evas_Object *obj)
4855 ELM_CHECK_WIDTYPE(obj, widtype) 18;
4856 Widget_Data *wd = elm_widget_data_get(obj);
4858 if ((!wd) || (!wd->src)) return 18;
4859 return wd->src->zoom_max;
4863 * Set the minimum zoom of the source.
4865 * @param source the source
4870 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4872 ELM_CHECK_WIDTYPE(obj, widtype);
4873 Widget_Data *wd = elm_widget_data_get(obj);
4875 if ((!wd) || (!wd->src)) return;
4876 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4877 wd->src->zoom_min = zoom;
4882 * Get the minimum zoom of the source.
4884 * @param source the source
4885 * @return Returns the minimum zoom of the source
4890 elm_map_source_zoom_min_get(const Evas_Object *obj)
4892 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4893 Widget_Data *wd = elm_widget_data_get(obj);
4895 if ((!wd) || (!wd->src)) return 0;
4896 return wd->src->zoom_min;
4900 * Set the user agent of the widget map.
4902 * @param obj The map object
4903 * @param user_agent the user agent of the widget map
4908 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4910 ELM_CHECK_WIDTYPE(obj, widtype);
4911 Widget_Data *wd = elm_widget_data_get(obj);
4914 if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4915 else eina_stringshare_replace(&wd->user_agent, user_agent);
4917 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4918 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4922 * Get the user agent of the widget map.
4924 * @param obj The map object
4925 * @return The user agent of the widget map
4930 elm_map_user_agent_get(const Evas_Object *obj)
4932 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4933 Widget_Data *wd = elm_widget_data_get(obj);
4935 if (!wd) return NULL;
4936 return wd->user_agent;
4940 * Add a route on the map
4942 * @param obj The map object
4943 * @param type the type if transport
4944 * @param method the routing method
4945 * @param flon the start longitude
4946 * @param flat the start latitude
4947 * @param tlon the destination longitude
4948 * @param tlat the destination latitude
4950 * @return The Route object
4954 EAPI Elm_Map_Route *
4955 elm_map_route_add(Evas_Object *obj,
4956 Elm_Map_Route_Type type,
4957 Elm_Map_Route_Method method,
4963 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4964 Widget_Data *wd = elm_widget_data_get(obj);
4967 char *type_name = NULL;
4970 if ((!wd) || (!wd->src)) return NULL;
4972 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4973 if (!route) return NULL;
4975 snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4983 route->con_url = ecore_con_url_new(NULL);
4984 route->ud.fname = strdup(buf);
4985 INF("xml file : %s", route->ud.fname);
4987 route->ud.fd = fdopen(fd, "w+");
4988 if ((!route->con_url) || (!route->ud.fd))
4990 ecore_con_url_free(route->con_url);
4996 route->color.r = 255;
4999 route->color.a = 255;
5000 route->handlers = eina_list_append
5001 (route->handlers, (void *)ecore_event_handler_add
5002 (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
5004 route->inbound = EINA_FALSE;
5006 route->method = method;
5014 case ELM_MAP_ROUTE_TYPE_MOTOCAR:
5015 type_name = strdup(ROUTE_TYPE_MOTORCAR);
5017 case ELM_MAP_ROUTE_TYPE_BICYCLE:
5018 type_name = strdup(ROUTE_TYPE_BICYCLE);
5020 case ELM_MAP_ROUTE_TYPE_FOOT:
5021 type_name = strdup(ROUTE_TYPE_FOOT);
5027 source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
5028 INF("route url = %s", source);
5030 wd->route = eina_list_append(wd->route, route);
5032 ecore_con_url_url_set(route->con_url, source);
5033 ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
5034 ecore_con_url_data_set(route->con_url, route);
5035 ecore_con_url_get(route->con_url);
5036 if (type_name) free(type_name);
5037 if (source) free(source);
5039 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
5040 "elm,state,busy,start", "elm");
5041 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
5046 * Remove a route from the map
5048 * @param route The route to remove
5054 elm_map_route_remove(Elm_Map_Route *route)
5056 EINA_SAFETY_ON_NULL_RETURN(route);
5061 Ecore_Event_Handler *h;
5063 EINA_LIST_FREE(route->path, p)
5068 EINA_LIST_FREE(route->waypoint, w)
5070 if (w->point) eina_stringshare_del(w->point);
5074 EINA_LIST_FREE(route->nodes, n)
5076 if (n->pos.address) eina_stringshare_del(n->pos.address);
5080 EINA_LIST_FREE(route->handlers, h)
5082 ecore_event_handler_del(h);
5085 if (route->ud.fname)
5087 ecore_file_remove(route->ud.fname);
5088 free(route->ud.fname);
5089 route->ud.fname = NULL;
5094 * Set the option used for the background color
5096 * @param route The route object
5102 * This sets the color used for the route
5107 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
5109 EINA_SAFETY_ON_NULL_RETURN(route);
5117 * Get the option used for the background color
5119 * @param route The route object
5128 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
5130 EINA_SAFETY_ON_NULL_RETURN(route);
5131 if (r) *r = route->color.r;
5132 if (g) *g = route->color.g;
5133 if (b) *b = route->color.b;
5134 if (a) *a = route->color.a;
5138 * Get the information of route distance
5140 * @param route the route object
5141 * @return Returns the distance of route (unit : km)
5146 elm_map_route_distance_get(const Elm_Map_Route *route)
5148 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
5149 return route->info.distance;
5153 * Get the information of route nodes
5155 * @param route the route object
5156 * @return Returns the nodes of route
5162 elm_map_route_node_get(const Elm_Map_Route *route)
5164 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5165 return route->info.nodes;
5169 * Get the information of route waypoint
5171 * @param route the route object
5172 * @return Returns the waypoint of route
5178 elm_map_route_waypoint_get(const Elm_Map_Route *route)
5180 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5181 return route->info.waypoints;
5185 * Get the information of address
5187 * @param name the name object
5188 * @return Returns the address of name
5193 elm_map_name_address_get(const Elm_Map_Name *name)
5195 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
5196 return name->address;
5200 * Get the current coordinates of the name.
5202 * This gets the current coordinates of the name object.
5204 * @param obj The name object
5205 * @param lat The latitude
5206 * @param lon The longitude
5211 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
5213 EINA_SAFETY_ON_NULL_RETURN(name);
5214 if (lon) *lon = name->lon;
5215 if (lat) *lat = name->lat;
5219 * Remove a name from the map
5221 * @param name The name to remove
5226 elm_map_name_remove(Elm_Map_Name *name)
5228 EINA_SAFETY_ON_NULL_RETURN(name);
5231 free(name->address);
5232 name->address = NULL;
5236 ecore_event_handler_del(name->handler);
5237 name->handler = NULL;
5241 ecore_file_remove(name->ud.fname);
5242 free(name->ud.fname);
5243 name->ud.fname = NULL;
5248 * Set the rotate degree of the map
5250 * @param obj The map object
5251 * @param angle amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5252 * @param cx rotation's center horizontal position
5253 * @param cy rotation's center vertical position
5258 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
5260 ELM_CHECK_WIDTYPE(obj, widtype);
5261 Widget_Data *wd = elm_widget_data_get(obj);
5264 wd->rotate.d = degree;
5267 wd->calc_job = ecore_job_add(_calc_job, wd);
5271 * Get the rotate degree of the map
5273 * @param obj The map object
5274 * @return amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5275 * @param cx rotation's center horizontal position
5276 * @param cy rotation's center vertical position
5281 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
5283 ELM_CHECK_WIDTYPE(obj, widtype);
5284 Widget_Data *wd = elm_widget_data_get(obj);
5287 if (degree) *degree = wd->rotate.d;
5288 if (cx) *cx = wd->rotate.cx;
5289 if (cy) *cy = wd->rotate.cy;
5293 * Set the wheel control state of the map
5295 * @param obj The map object
5296 * @param disabled status of wheel control
5301 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
5303 ELM_CHECK_WIDTYPE(obj, widtype);
5304 Widget_Data *wd = elm_widget_data_get(obj);
5307 if ((!wd->wheel_disabled) && (disabled))
5308 evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5309 else if ((wd->wheel_disabled) && (!disabled))
5310 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5311 wd->wheel_disabled = !!disabled;
5315 * Get the wheel control state of the map
5317 * @param obj The map object
5318 * @return Returns the status of wheel control
5323 elm_map_wheel_disabled_get(const Evas_Object *obj)
5325 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5326 Widget_Data *wd = elm_widget_data_get(obj);
5328 if (!wd) return EINA_FALSE;
5329 return wd->wheel_disabled;
5333 * Add a track on the map
5335 * @param obj The map object
5336 * @param gpx_file the name of the gpx file
5338 * @return The Track object
5342 EAPI Elm_Map_Track *
5343 elm_map_track_add(Evas_Object *obj, const char *gpx_file)
5345 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5346 Widget_Data *wd = elm_widget_data_get(obj);
5349 if (!wd) return EINA_FALSE;
5351 Elm_Map_Track *track = ELM_NEW(Elm_Map_Track);
5352 if (!track) return NULL;
5354 track->inbound = EINA_FALSE;
5357 track->color.b = 255;
5358 track->color.a = 255;
5360 Track_Dump dump = {track, 0, 0.0, 0.0};
5361 if (!wd->gpx_file) wd->gpx_file = eina_stringshare_add(gpx_file);
5362 else eina_stringshare_replace(&wd->gpx_file, gpx_file);
5364 f = fopen(gpx_file, "rb");
5369 fseek(f, 0, SEEK_END);
5375 fseek(f, 0, SEEK_SET);
5379 if (fread(buf, 1, sz, f))
5381 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_track_dump, &dump);
5390 ERR("can't open the file %s", gpx_file);
5393 DBG("[Done] Load GPX file %s", gpx_file);
5395 wd->track = eina_list_append(wd->track, track);
5398 Evas_Coord ox, oy, ow, oh;
5399 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
5400 track_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
5407 * Remove a track from the map
5409 * @param track The track to remove
5415 elm_map_track_remove(Elm_Map_Track *track)
5417 EINA_SAFETY_ON_NULL_RETURN(track);
5422 EINA_LIST_FREE(track->path, p)
5427 EINA_LIST_FREE(track->nodes, n)
5429 if (n->pos.address) eina_stringshare_del(n->pos.address);
5435 * Set the option used for the background color
5437 * @param track The track object
5443 * This sets the color used for the track
5448 elm_map_track_color_set(Elm_Map_Track *track, int r, int g , int b, int a)
5450 EINA_SAFETY_ON_NULL_RETURN(track);
5458 * Get the option used for the background color
5460 * @param track The track object
5469 elm_map_track_color_get(const Elm_Map_Track *track, int *r, int *g , int *b, int *a)
5471 EINA_SAFETY_ON_NULL_RETURN(track);
5472 if (r) *r = track->color.r;
5473 if (g) *g = track->color.g;
5474 if (b) *b = track->color.b;
5475 if (a) *a = track->color.a;
5479 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5482 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
5488 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5491 snprintf(buf, sizeof(buf),
5492 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
5498 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5501 snprintf(buf, sizeof(buf),
5502 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
5508 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5511 snprintf(buf, sizeof(buf),
5512 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
5517 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5520 snprintf(buf, sizeof(buf),
5521 "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
5522 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
5527 // TODO: fix monav api
5529 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5532 snprintf(buf, sizeof(buf),
5533 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5534 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
5540 // TODO: fix ors api
5542 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5545 snprintf(buf, sizeof(buf),
5546 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5547 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
5554 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
5556 ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
5557 Widget_Data *wd = elm_widget_data_get(obj);
5559 unsigned int ele, idx;
5560 char search_url[PATH_MAX];
5563 if (!wd) return strdup("");
5564 if (method == ELM_MAP_NAME_METHOD_SEARCH)
5566 search_url[0] = '\0';
5567 str = eina_str_split_full(name, " ", 0, &ele);
5568 for (idx = 0 ; idx < ele ; idx++)
5570 eina_strlcat(search_url, str[idx], sizeof(search_url));
5571 if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
5573 snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
5575 else if (method == ELM_MAP_NAME_METHOD_REVERSE) snprintf(buf, sizeof(buf), "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0", NAME_NOMINATIM_URL, lat, lon, wd->zoom);
5576 else strcpy(buf, "");