4 # include "elementary_config.h"
8 # include <Ecore_Con.h>
11 #include "Elementary.h"
18 * This is a widget specifically for displaying the map. It uses basically
19 * OpenStreetMap provider. but it can be added custom providers.
21 * Signals that you can add callbacks for are:
23 * "clicked" - This is called when a user has clicked the map without dragging
26 * "press" - This is called when a user has pressed down on the map.
28 * "longpressed" - This is called when a user has pressed down on the map for
29 * a long time without dragging around.
31 * "clicked,double" - This is called when a user has double-clicked the map.
33 * "load,detail" - Map detailed data load begins.
35 * "loaded,detail" - This is called when all parts of the map are loaded.
37 * "zoom,start" - Zoom animation started.
39 * "zoom,stop" - Zoom animation stopped.
41 * "zoom,change" - Zoom changed when using an auto zoom mode.
43 * "scroll" - the content has been scrolled (moved)
45 * "scroll,anim,start" - scrolling animation has started
47 * "scroll,anim,stop" - scrolling animation has stopped
49 * "scroll,drag,start" - dragging the contents around has started
51 * "scroll,drag,stop" - dragging the contents around has stopped
53 * "downloaded" - This is called when map images are downloaded
55 * "route,load" - This is called when route request begins
57 * "route,loaded" - This is called when route request ends
59 * "name,load" - This is called when name request begins
61 * "name,loaded- This is called when name request ends
67 typedef struct _Widget_Data Widget_Data;
68 typedef struct _Pan Pan;
69 typedef struct _Grid Grid;
70 typedef struct _Grid_Item Grid_Item;
71 typedef struct _Marker_Group Marker_Group;
72 typedef struct _Event Event;
73 typedef struct _Path_Node Path_Node;
74 typedef struct _Path_Waypoint Path_Waypoint;
75 typedef struct _Url_Data Url_Data;
76 typedef struct _Route_Dump Route_Dump;
77 typedef struct _Name_Dump Name_Dump;
78 typedef struct _Track_Dump Track_Dump;
80 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
81 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
82 #define DEST_FILE_PATH "%s%d.png"
83 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
84 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
86 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
87 #define ROUTE_TYPE_MOTORCAR "motocar"
88 #define ROUTE_TYPE_BICYCLE "bicycle"
89 #define ROUTE_TYPE_FOOT "foot"
90 #define YOURS_DISTANCE "distance"
91 #define YOURS_DESCRIPTION "description"
92 #define YOURS_COORDINATES "coordinates"
94 // TODO: fix monav & ors url
95 #define ROUTE_MONAV_URL "http://"
96 #define ROUTE_ORS_URL "http:///"
98 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
99 #define NOMINATIM_RESULT "result"
100 #define NOMINATIM_PLACE "place"
101 #define NOMINATIM_ATTR_LON "lon"
102 #define NOMINATIM_ATTR_LAT "lat"
104 #define PINCH_ZOOM_MIN 0.25
105 #define PINCH_ZOOM_MAX 4.0
107 #define GPX_NAME "name>"
108 #define GPX_COORDINATES "trkpt "
109 #define GPX_LON "lon"
110 #define GPX_LAT "lat"
111 #define GPX_ELE "ele>"
112 #define GPX_TIME "time>"
115 // Currently the size of a tile must be 256*256
116 // and the size of the map must be pow(2.0, z)*tile_size
117 typedef struct _Map_Sources_Tab
122 ElmMapModuleUrlFunc url_cb;
123 Elm_Map_Route_Sources route_source;
124 ElmMapModuleRouteUrlFunc route_url_cb;
125 ElmMapModuleNameUrlFunc name_url_cb;
126 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
127 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
130 //Zemm min is supposed to be 0
131 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
132 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
133 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
134 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
136 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
138 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
139 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
141 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
143 static Map_Sources_Tab default_map_sources_tab[] =
145 {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
146 {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
147 {"CycleMap", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
148 {"Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
153 Ecore_Con_Url *con_url;
159 struct _Elm_Map_Marker_Class
164 struct _Elm_Map_Marker_Class_Func {
165 ElmMapMarkerGetFunc get;
166 ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
167 ElmMapMarkerIconGetFunc icon_get;
170 struct { //this part is private, do not modify these values
172 Evas_Coord edje_w, edje_h;
176 struct _Elm_Map_Marker
179 Elm_Map_Marker_Class *clas;
180 Elm_Map_Group_Class *clas_group;
181 double longitude, latitude;
186 Marker_Group **groups;
187 Evas_Object *content;
190 struct _Elm_Map_Group_Class
194 int zoom_displayed; // display the group if the zoom is >= to zoom_display
195 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
199 ElmMapGroupIconGetFunc icon_get;
202 struct { //this part is private, do not modify these values
204 Evas_Coord edje_w, edje_h;
205 Evas_Coord edje_max_w, edje_max_h;
207 Eina_List *objs_used;
208 Eina_List *objs_notused;
215 Eina_Matrixsparse_Cell *cell;
216 Elm_Map_Group_Class *clas;
219 long long sum_x, sum_y;
223 Evas_Object *obj, *bubble, *sc, *bx, *rect;
225 Eina_Bool bringin : 1;
226 Eina_Bool update_nbelems : 1;
227 Eina_Bool update_resize : 1;
228 Eina_Bool update_raise : 1;
229 Eina_Bool delete_object : 1;
232 struct _Elm_Map_Route
238 Ecore_Con_Url *con_url;
243 double flon, flat, tlon, tlat;
245 Eina_List *nodes, *path;
252 const char *waypoints;
253 double distance; /* unit : km */
266 Eina_Bool inbound : 1;
280 struct _Path_Waypoint
291 Ecore_Con_Url *con_url;
296 Ecore_Event_Handler *handler;
309 Eina_Bool download : 1;
311 Ecore_File_Download_Job *job;
318 int tsize; // size of tile (tsize x tsize pixels)
319 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
320 int iw, ih; // size of image in pixels
321 int w, h; // size of grid image in pixels (represented by grid)
322 int gw, gh; // size of grid in tiles
323 Eina_Matrixsparse *grid;
330 Evas_Object *pan_smart;
332 Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
334 Evas_Coord pan_x, pan_y, minw, minh;
339 Elm_Map_Zoom_Mode mode;
342 Ecore_Timer *scr_timer;
343 Ecore_Timer *long_timer;
344 Ecore_Animator *zoom_animator;
355 Evas_Coord x, y ,w ,h;
361 Eina_Bool resized : 1;
362 Eina_Bool on_hold : 1;
363 Eina_Bool paused : 1;
364 Eina_Bool paused_markers : 1;
371 Ecore_Job *markers_place_job;
372 Eina_Matrixsparse **markers;
373 Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
374 Evas_Coord markers_max_num;
375 int marker_max_w, marker_max_h;
377 Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
379 Eina_List *groups_clas; // list of Elm_Map_Group_Class*
380 Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
382 Elm_Map_Route_Sources route_source;
383 Eina_List *s_event_list;
388 const char *user_agent;
391 Evas_Event_Mouse_Down ev;
412 Ecore_Timer *wheel_timer;
413 Eina_Bool wheel_disabled : 1;
416 Eina_List *map_sources_tab;
417 const char **source_names;
419 Ecore_Timer *zoom_timer;
420 Map_Sources_Tab *src;
421 const char *gpx_file;
422 int zoom_min, zoom_max;
427 Evas_Object_Smart_Clipped_Data __clipped_data;
443 Evas_Coord x, y, w, h;
446 Ecore_Timer *hold_timer;
461 enum _Route_Xml_Attribute
465 ROUTE_XML_DESCRIPTION,
466 ROUTE_XML_COORDINATES,
468 } Route_Xml_Attibute;
478 enum _Name_Xml_Attribute
495 enum _Track_Xml_Attribute
498 TRACK_XML_COORDINATES,
500 } Track_Xml_Attibute;
503 static const char *widtype = NULL;
505 static const char SIG_CHANGED[] = "changed";
506 static const char SIG_CLICKED[] = "clicked";
507 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
508 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
509 static const char SIG_LOAD_DETAIL[] = "load,detail";
510 static const char SIG_LONGPRESSED[] = "longpressed";
511 static const char SIG_PRESS[] = "press";
512 static const char SIG_SCROLL[] = "scroll";
513 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
514 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
515 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
516 static const char SIG_ZOOM_START[] = "zoom,start";
517 static const char SIG_ZOOM_STOP[] = "zoom,stop";
518 static const char SIG_DOWNLOADED[] = "downloaded";
519 static const char SIG_ROUTE_LOAD[] = "route,load";
520 static const char SIG_ROUTE_LOADED[] = "route,loaded";
521 static const char SIG_NAME_LOAD[] = "name,load";
522 static const char SIG_NAME_LOADED[] = "name,loaded";
523 static const Evas_Smart_Cb_Description _signals[] = {
526 {SIG_CLICKED_DOUBLE, ""},
527 {SIG_LOADED_DETAIL, ""},
528 {SIG_LOAD_DETAIL, ""},
529 {SIG_LONGPRESSED, ""},
532 {SIG_SCROLL_DRAG_START, ""},
533 {SIG_SCROLL_DRAG_STOP, ""},
534 {SIG_ZOOM_CHANGE, ""},
535 {SIG_ZOOM_START, ""},
537 {SIG_DOWNLOADED, ""},
538 {SIG_ROUTE_LOAD, ""},
539 {SIG_ROUTE_LOADED, ""},
541 {SIG_NAME_LOADED, ""},
545 static void _pan_calculate(Evas_Object *obj);
547 static Eina_Bool _hold_timer_cb(void *data);
548 static Eina_Bool _wheel_timer_cb(void *data);
549 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
550 static void _del_hook(Evas_Object *obj);
551 static void _theme_hook(Evas_Object *obj);
552 static void _on_focus_hook(void *data, Evas_Object *obj);
553 static void _sizing_eval(Evas_Object *obj);
554 static void _calc_job(void *data);
555 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
556 Evas_Callback_Type type, void *event_info);
557 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);
558 static void grid_clear(Evas_Object *obj, Grid *g);
559 static Grid *grid_create(Evas_Object *obj);
560 static void grid_load(Evas_Object *obj, Grid *g);
563 static void _group_object_create(Marker_Group *group);
564 static void _group_object_free(Marker_Group *group);
565 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
566 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
567 static void _group_bubble_create(Marker_Group *group);
568 static void _group_bubble_free(Marker_Group *group);
569 static void _group_bubble_place(Marker_Group *group);
571 static int _group_bubble_content_update(Marker_Group *group);
572 static void _group_bubble_content_free(Marker_Group *group);
573 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);
574 static void _bubble_sc_hits_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
576 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
577 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
578 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
580 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
581 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
582 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
584 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);
585 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);
588 get_multi_device(Evas_Object *obj)
590 Widget_Data *wd = elm_widget_data_get(obj);
594 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
596 if (ev->device) return ev->device;
602 create_event_object(void *data, Evas_Object *obj, int device)
604 Widget_Data *wd = elm_widget_data_get(data);
605 Event *ev = calloc(1, sizeof(Event));
607 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
611 evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
612 wd->s_event_list = eina_list_append(wd->s_event_list, ev);
617 get_event_object(void *data, int device)
619 Widget_Data *wd = elm_widget_data_get(data);
623 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
625 if (ev->device == device) break;
632 destroy_event_object(void *data, Event *ev)
634 Widget_Data *wd = elm_widget_data_get(data);
635 EINA_SAFETY_ON_NULL_RETURN(ev);
637 wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
640 ecore_timer_del(ev->hold_timer);
641 ev->hold_timer = NULL;
647 module_list_cb(Eina_Module *m, void *data)
649 ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
650 Widget_Data *wd = elm_widget_data_get(data);
652 ElmMapModuleSourceFunc source;
653 ElmMapModuleZoomMinFunc zoom_min;
654 ElmMapModuleZoomMaxFunc zoom_max;
655 ElmMapModuleUrlFunc url;
656 ElmMapModuleRouteSourceFunc route_source;
657 ElmMapModuleRouteUrlFunc route_url;
658 ElmMapModuleNameUrlFunc name_url;
659 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
660 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
663 if (!wd) return EINA_FALSE;
665 file = eina_module_file_get(m);
666 if (!eina_module_load(m))
668 ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
672 source = eina_module_symbol_get(m, "map_module_source_get");
673 zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
674 zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
675 url = eina_module_symbol_get(m, "map_module_url_get");
676 route_source = eina_module_symbol_get(m, "map_module_route_source_get");
677 route_url = eina_module_symbol_get(m, "map_module_route_url_get");
678 name_url = eina_module_symbol_get(m, "map_module_name_url_get");
679 geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
680 coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
681 if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
683 ERR("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
684 eina_module_unload(m);
687 s = calloc(1, sizeof(Map_Sources_Tab));
688 EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
690 s->zoom_min = zoom_min();
691 s->zoom_max = zoom_max();
693 s->route_source = route_source();
694 s->route_url_cb = route_url;
695 s->name_url_cb = name_url;
696 s->geo_into_coord = geo_into_coord;
697 s->coord_into_geo = coord_into_geo;
698 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
704 module_init(void *data)
706 ELM_CHECK_WIDTYPE(data, widtype);
707 Widget_Data *wd = elm_widget_data_get(data);
710 wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
714 source_init(void *data)
716 ELM_CHECK_WIDTYPE(data, widtype);
717 Widget_Data *wd = elm_widget_data_get(data);
723 for (idx = 0; idx < 4; idx++)
725 s = calloc(1, sizeof(Map_Sources_Tab));
726 EINA_SAFETY_ON_NULL_RETURN(s);
727 s->name = default_map_sources_tab[idx].name;
728 s->zoom_min = default_map_sources_tab[idx].zoom_min;
729 s->zoom_max = default_map_sources_tab[idx].zoom_max;
730 s->url_cb = default_map_sources_tab[idx].url_cb;
731 s->route_source = default_map_sources_tab[idx].route_source;
732 s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
733 s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
734 s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
735 s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
736 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
737 if (!idx) wd->src = s;
741 int n = eina_list_count(wd->map_sources_tab);
742 wd->source_names = malloc(sizeof(char *) * (n + 1));
743 if (!wd->source_names)
745 ERR("init source names failed.");
749 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
751 wd->source_names[idx] = strdup(s->name);
752 INF("source : %s", wd->source_names[idx]);
755 wd->source_names[idx] = NULL;
759 zoom_min_get(void *data)
761 ELM_CHECK_WIDTYPE(data, widtype);
762 Widget_Data *wd = elm_widget_data_get(data);
768 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
771 if (tz < wd->zoom_min) wd->zoom_min = tz;
776 zoom_max_get(void *data)
778 ELM_CHECK_WIDTYPE(data, widtype);
779 Widget_Data *wd = elm_widget_data_get(data);
785 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
788 if (tz > wd->zoom_max) wd->zoom_max = tz;
793 obj_rotate_zoom(void *data, Evas_Object *obj)
795 ELM_CHECK_WIDTYPE(data, widtype);
796 Widget_Data *wd = elm_widget_data_get(data);
797 if ((!wd->pinch.cx) && (!wd->pinch.cy))
799 wd->pinch.cx = wd->rotate.cx;
800 wd->pinch.cy = wd->rotate.cy;
803 evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
805 evas_object_image_size_get(obj, &iw, &ih);
806 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
807 if (ow < iw || oh < ih)
809 ow *= (double)iw / ow;
810 oh *= (double)ih / oh;
811 evas_map_point_image_uv_set(wd->map, 1, ow, 0);
812 evas_map_point_image_uv_set(wd->map, 2, ow, oh);
813 evas_map_point_image_uv_set(wd->map, 3, 0, oh);
815 evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
816 evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
817 evas_object_map_enable_set(obj, EINA_TRUE);
818 evas_object_map_set(obj, wd->map);
823 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)
825 track_place(Evas_Object *obj __UNUSED__, Grid *g __UNUSED__, Evas_Coord px __UNUSED__, Evas_Coord py __UNUSED__, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow __UNUSED__, Evas_Coord oh __UNUSED__)
829 ELM_CHECK_WIDTYPE(obj, widtype);
830 Widget_Data *wd = elm_widget_data_get(obj);
833 int xmin, xmax, ymin, ymax;
836 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
838 EINA_LIST_FOREACH(wd->track, l, route)
840 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
841 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
843 if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
845 if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
848 evas_object_move(route, xmin - px + ox, ymin - py + oy);
849 evas_object_resize(route, xmax - xmin, ymax - ymin);
851 evas_object_raise(route);
852 obj_rotate_zoom(obj, route);
853 evas_object_show(route);
858 //the route is not display
859 evas_object_hide(route);
864 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)
866 ELM_CHECK_WIDTYPE(obj, widtype);
867 Widget_Data *wd = elm_widget_data_get(obj);
868 Eina_List *lr, *lp, *ln;
877 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
879 EINA_LIST_FOREACH(wd->route, lr, r)
881 EINA_LIST_FOREACH(r->path, lp, p)
883 evas_object_polygon_points_clear(p);
886 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
887 nodes = eina_list_count(r->nodes);
889 EINA_LIST_FOREACH(r->nodes, ln, n)
891 if ((!wd->zoom) || ((n->idx) &&
892 ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
895 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
896 if ((x >= px - ow) && (x <= (px + ow*2)) &&
897 (y >= py - oh) && (y <= (py + oh*2)))
902 p = eina_list_nth(r->path, n->idx);
903 a = (double)(y - r->y) / (double)(x - r->x);
904 if ((abs(a) >= 1) || (r->x == x))
906 evas_object_polygon_point_add(p, r->x - 3, r->y);
907 evas_object_polygon_point_add(p, r->x + 3, r->y);
908 evas_object_polygon_point_add(p, x + 3, y);
909 evas_object_polygon_point_add(p, x - 3, y);
913 evas_object_polygon_point_add(p, r->x, r->y - 3);
914 evas_object_polygon_point_add(p, r->x, r->y + 3);
915 evas_object_polygon_point_add(p, x, y + 3);
916 evas_object_polygon_point_add(p, x, y - 3);
919 evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
920 evas_object_raise(p);
921 obj_rotate_zoom(obj, p);
926 else r->inbound = EINA_FALSE;
930 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
931 if ((x >= px - ow) && (x <= (px + ow*2)) &&
932 (y >= py - oh) && (y <= (py + oh*2)))
936 r->inbound = EINA_TRUE;
938 else r->inbound = EINA_FALSE;
941 r->inbound = EINA_FALSE;
946 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
948 ELM_CHECK_WIDTYPE(obj, widtype);
949 Widget_Data *wd = elm_widget_data_get(obj);
950 Evas_Coord ax, ay, gw, gh, hh, ww;
953 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
960 if ((ww == gw) && (hh == gh)) return;
962 if (ow > gw) ax = (ow - gw) / 2;
963 if (oh > gh) ay = (oh - gh) / 2;
964 evas_object_move(wd->rect,
967 evas_object_resize(wd->rect, gw, gh);
971 wd->show.show = EINA_FALSE;
972 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
977 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)
979 ELM_CHECK_WIDTYPE(obj, widtype);
980 Widget_Data *wd = elm_widget_data_get(obj);
981 Evas_Coord ax, ay, gw, gh, tx, ty;
982 Eina_List *l, *markers;
983 Eina_Matrixsparse_Cell *cell;
988 int g_xx, g_yy, g_hh, g_ww;
991 if (g != eina_list_data_get(wd->grids)) return;
997 if (ow > gw) ax = (ow - gw) / 2;
998 if (oh > gh) ay = (oh - gh) / 2;
1000 if (wd->zoom != wd->marker_zoom)
1002 EINA_LIST_FREE(wd->cells_displayed, cell)
1004 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1006 if (group->obj) _group_object_free(group);
1010 wd->marker_zoom = wd->zoom;
1012 if ((wd->paused_markers)
1013 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
1016 g_xx = wd->pan_x / wd->tsize;
1017 if (g_xx < 0) g_xx = 0;
1018 g_yy = wd->pan_y / wd->tsize;
1019 if (g_yy < 0) g_yy = 0;
1020 g_ww = (ow / wd->tsize) + 1;
1021 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
1022 g_hh = (oh / wd->tsize) + 1;
1023 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
1025 //hide groups no more displayed
1026 EINA_LIST_FREE(wd->cells_displayed, cell)
1028 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
1029 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
1031 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1033 if (group->obj) _group_object_free(group);
1038 if (!wd->marker_zoom)
1044 for (y = g_yy; y <= g_yy + g_hh; y++)
1046 for (x = g_xx; x <= g_xx + g_ww; x++)
1048 if (!wd->markers[wd->zoom]) continue;
1049 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1050 if (!cell) continue;
1051 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1052 markers = eina_matrixsparse_cell_data_get(cell);
1053 EINA_LIST_FOREACH(markers, l, group)
1055 if (!group->markers) continue;
1056 if (group->clas->zoom_displayed > wd->zoom) continue;
1063 if (eina_list_count(group->markers) == 1)
1065 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1066 ww = m->clas->priv.edje_w;
1067 hh = m->clas->priv.edje_h;
1070 if (ww <= 0) ww = 1;
1071 if (hh <= 0) hh = 1;
1073 if ((gw != g->w) && (g->w > 0))
1076 xx = ((long long )gw * xx) / g->w;
1077 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1079 if ((gh != g->h) && (g->h > 0))
1082 yy = ((long long)gh * yy) / g->h;
1083 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1086 if ((!group->clas->hide)
1087 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1088 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1090 if (!group->obj) _group_object_create(group);
1092 if (group->update_nbelems)
1094 group->update_nbelems = EINA_FALSE;
1095 if (eina_list_count(group->markers) > 1)
1097 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1098 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1101 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1103 evas_object_move(group->obj,
1104 xx - px + ax + ox - ww/2,
1105 yy - py + ay + oy - hh/2);
1106 if ((!wd->paused_markers) || (group->update_resize))
1108 group->update_resize = EINA_FALSE;
1109 evas_object_resize(group->obj, ww, hh);
1110 obj_rotate_zoom(obj, group->obj);
1112 if (group->update_raise)
1114 group->update_raise = EINA_FALSE;
1115 evas_object_raise(group->obj);
1116 obj_rotate_zoom(obj, group->obj);
1117 evas_object_show(group->obj);
1119 if (group->bubble) _group_bubble_place(group);
1121 else if (group->obj)
1123 _group_object_free(group);
1131 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)
1133 ELM_CHECK_WIDTYPE(obj, widtype);
1134 Widget_Data *wd = elm_widget_data_get(obj);
1135 Evas_Coord ax, ay, gw, gh, tx, ty;
1143 if (ow > gw) ax = (ow - gw) / 2;
1144 if (oh > gh) ay = (oh - gh) / 2;
1146 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1147 Eina_Matrixsparse_Cell *cell;
1149 EINA_ITERATOR_FOREACH(it, cell)
1151 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1157 if ((gw != g->w) && (g->w > 0))
1160 xx = ((long long )gw * xx) / g->w;
1161 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1163 if ((gh != g->h) && (g->h > 0))
1166 yy = ((long long)gh * yy) / g->h;
1167 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1169 evas_object_move(gi->img,
1173 evas_object_resize(gi->img, ww, hh);
1175 obj_rotate_zoom(obj, gi->img);
1176 /*evas_object_move(gi->txt,
1180 evas_object_resize(gi->txt, ww, hh);
1183 eina_iterator_free(it);
1187 grid_clear(Evas_Object *obj, Grid *g)
1189 ELM_CHECK_WIDTYPE(obj, widtype);
1190 Widget_Data *wd = elm_widget_data_get(obj);
1194 if (!g->grid) return;
1196 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1197 Eina_Matrixsparse_Cell *cell;
1199 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1200 ecore_file_recursive_rm(buf);
1202 EINA_ITERATOR_FOREACH(it, cell)
1204 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1205 evas_object_del(gi->img);
1206 //evas_object_del(gi->txt);
1210 gi->want = EINA_FALSE;
1212 if (!wd->preload_num)
1214 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1215 "elm,state,busy,stop", "elm");
1216 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
1222 DBG("DOWNLOAD abort %s", gi->file);
1223 ecore_file_download_abort(gi->job);
1224 ecore_file_remove(gi->file);
1229 eina_stringshare_del(gi->file);
1233 eina_matrixsparse_free(g->grid);
1234 eina_iterator_free(it);
1241 _tile_update(Grid_Item *gi)
1243 gi->want = EINA_FALSE;
1244 gi->download = EINA_FALSE;
1245 evas_object_image_file_set(gi->img, gi->file, NULL);
1246 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1247 ecore_file_remove(gi->file);
1249 obj_rotate_zoom(gi->wd->obj, gi->img);
1250 evas_object_show(gi->img);
1252 //evas_object_text_text_set(gi->txt, gi->file);
1253 //evas_object_show(gi->txt);
1255 gi->have = EINA_TRUE;
1256 gi->wd->preload_num--;
1257 if (!gi->wd->preload_num)
1259 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1260 "elm,state,busy,stop", "elm");
1261 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1266 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1268 Grid_Item *gi = data;
1270 gi->download = EINA_FALSE;
1273 if ((gi->want) && (status == 200)) _tile_update(gi);
1277 DBG("Download failed %s (%d) ", gi->file, status);
1278 ecore_file_remove(gi->file);
1281 gi->wd->finish_num++;
1283 evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1284 DBG("DOWNLOAD done %s", gi->file);
1288 grid_create(Evas_Object *obj)
1290 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1291 Widget_Data *wd = elm_widget_data_get(obj);
1294 if ((!wd) || (!wd->src)) return NULL;
1295 g = calloc(1, sizeof(Grid));
1298 g->tsize = wd->tsize;
1301 if (g->zoom > wd->src->zoom_max) return NULL;
1302 if (g->zoom < wd->src->zoom_min) return NULL;
1304 int size = pow(2.0, wd->zoom);
1308 g->w = g->tsize * g->gw;
1309 g->h = g->tsize * g->gh;
1311 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1317 grid_load(Evas_Object *obj, Grid *g)
1319 ELM_CHECK_WIDTYPE(obj, widtype);
1320 Widget_Data *wd = elm_widget_data_get(obj);
1323 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1325 Eina_Matrixsparse_Cell *cell;
1328 if ((!wd) || (!wd->src)) return;
1329 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1330 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1335 if ((gw <= 0) || (gh <= 0)) return;
1338 if ((gw != g->w) && (g->w > 0))
1339 size = ((long long)gw * size) / g->w;
1340 if (size < (g->tsize / 2)) return; // else we will load to much tiles
1342 it = eina_matrixsparse_iterator_new(g->grid);
1344 EINA_ITERATOR_FOREACH(it, cell)
1346 gi = eina_matrixsparse_cell_data_get(cell);
1353 if ((gw != g->w) && (g->w > 0))
1356 xx = ((long long )gw * xx) / g->w;
1357 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1359 if ((gh != g->h) && (g->h > 0))
1362 yy = ((long long)gh * yy) / g->h;
1363 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1366 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1367 yy - wd->pan_y + oy,
1369 cvx, cvy, cvw, cvh))
1373 evas_object_hide(gi->img);
1374 //evas_object_hide(gi->txt);
1375 evas_object_image_file_set(gi->img, NULL, NULL);
1376 gi->want = EINA_FALSE;
1377 gi->have = EINA_FALSE;
1381 DBG("DOWNLOAD abort %s", gi->file);
1382 ecore_file_download_abort(gi->job);
1383 ecore_file_remove(gi->file);
1387 gi->download = EINA_FALSE;
1389 if (!wd->preload_num)
1391 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1392 "elm,state,busy,stop", "elm");
1393 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
1400 evas_object_hide(gi->img);
1401 //evas_object_hide(gi->txt);
1402 evas_object_image_preload(gi->img, 1);
1403 evas_object_image_file_set(gi->img, NULL, NULL);
1404 gi->have = EINA_FALSE;
1405 gi->want = EINA_FALSE;
1409 eina_iterator_free(it);
1411 xx = wd->pan_x / size - 1;
1414 yy = wd->pan_y / size - 1;
1418 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1421 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1423 for (y = yy; y <= yy + hh; y++)
1425 for (x = xx; x <= xx + ww; x++)
1427 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1429 if ((!gi) && (g != eina_list_data_get(wd->grids)))
1434 gi = calloc(1, sizeof(Grid_Item));
1435 gi->src.x = x * g->tsize;
1436 gi->src.y = y * g->tsize;
1437 gi->src.w = g->tsize;
1438 gi->src.h = g->tsize;
1440 gi->out.x = gi->src.x;
1441 gi->out.y = gi->src.y;
1442 gi->out.w = gi->src.w;
1443 gi->out.h = gi->src.h;
1447 gi->img = evas_object_image_add(evas_object_evas_get(obj));
1448 evas_object_image_scale_hint_set
1449 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1450 evas_object_image_filled_set(gi->img, 1);
1452 evas_object_smart_member_add(gi->img, wd->pan_smart);
1453 elm_widget_sub_object_add(obj, gi->img);
1454 evas_object_pass_events_set(gi->img, EINA_TRUE);
1455 evas_object_stack_below(gi->img, wd->sep_maps_markers);
1457 /* gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1458 evas_object_text_font_set(gi->txt, "Vera", 12);
1459 evas_object_color_set(gi->txt, 100, 100, 100, 255);
1460 evas_object_smart_member_add(gi->txt,
1462 elm_widget_sub_object_add(obj, gi->txt);
1463 evas_object_pass_events_set(gi->txt, EINA_TRUE);
1465 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1468 if ((!gi->have) && (!gi->download))
1470 char buf[PATH_MAX], buf2[PATH_MAX];
1473 gi->want = EINA_TRUE;
1475 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1476 if (!ecore_file_exists(buf))
1477 ecore_file_mkpath(buf);
1479 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1481 source = wd->src->url_cb(obj, x, y, g->zoom);
1482 if ((!source) || (strlen(source)==0)) continue;
1484 eina_stringshare_replace(&gi->file, buf2);
1486 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1488 gi->download = EINA_TRUE;
1490 if (wd->preload_num == 1)
1492 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1493 "elm,state,busy,start", "elm");
1494 evas_object_smart_callback_call(obj,
1499 if (ecore_file_exists(buf2))
1503 DBG("DOWNLOAD %s \t in %s", source, buf2);
1504 ecore_file_download_full(source, buf2, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1506 DBG("Can't start to download %s", buf);
1511 if (source) free(source);
1515 obj_rotate_zoom(obj, gi->img);
1516 evas_object_show(gi->img);
1523 grid_clearall(Evas_Object *obj)
1525 ELM_CHECK_WIDTYPE(obj, widtype);
1526 Widget_Data *wd = elm_widget_data_get(obj);
1530 EINA_LIST_FREE(wd->grids, g)
1538 _smooth_update(Evas_Object *obj)
1540 ELM_CHECK_WIDTYPE(obj, widtype);
1541 Widget_Data *wd = elm_widget_data_get(obj);
1546 EINA_LIST_FOREACH(wd->grids, l, g)
1548 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1549 Eina_Matrixsparse_Cell *cell;
1551 EINA_ITERATOR_FOREACH(it, cell)
1553 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1554 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1556 eina_iterator_free(it);
1561 _scr_timeout(void *data)
1563 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1564 Widget_Data *wd = elm_widget_data_get(data);
1566 if (!wd) return ECORE_CALLBACK_CANCEL;
1568 if (!wd->nosmooth) _smooth_update(data);
1569 wd->scr_timer = NULL;
1570 return ECORE_CALLBACK_CANCEL;
1574 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1576 ELM_CHECK_WIDTYPE(data, widtype);
1577 Widget_Data *wd = elm_widget_data_get(data);
1583 if (wd->nosmooth == 1) _smooth_update(data);
1585 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1586 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1590 zoom_do(Evas_Object *obj)
1592 ELM_CHECK_WIDTYPE(obj, widtype);
1593 Widget_Data *wd = elm_widget_data_get(obj);
1594 Evas_Coord xx, yy, ow, oh;
1597 wd->size.w = wd->size.nw;
1598 wd->size.h = wd->size.nh;
1600 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1602 if (wd->center_on.enabled)
1604 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1610 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1611 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1616 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1618 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1620 wd->show.show = EINA_TRUE;
1626 if (wd->calc_job) ecore_job_del(wd->calc_job);
1627 wd->calc_job = ecore_job_add(_calc_job, wd);
1631 _zoom_timeout(void *data)
1633 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1634 Widget_Data *wd = elm_widget_data_get(data);
1636 if (!wd) return ECORE_CALLBACK_CANCEL;
1637 wd->zoom_timer = NULL;
1638 wd->pinch.level = 1.0;
1640 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1641 return ECORE_CALLBACK_CANCEL;
1645 _zoom_anim(void *data)
1647 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1648 Evas_Object *obj = data;
1649 Widget_Data *wd = elm_widget_data_get(obj);
1651 if (!wd) return ECORE_CALLBACK_CANCEL;
1652 if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1653 else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1656 wd->zoom_animator = NULL;
1658 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1659 return ECORE_CALLBACK_CANCEL;
1664 wd->zoom_animator = NULL;
1665 wd->pinch.level = 2.0;
1666 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1667 wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1668 return ECORE_CALLBACK_CANCEL;
1670 else if (wd->t <= 0.5)
1672 wd->zoom_animator = NULL;
1673 wd->pinch.level = 0.5;
1674 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1675 wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1676 return ECORE_CALLBACK_CANCEL;
1678 else if (wd->t != 1.0)
1680 Evas_Coord x, y, w, h;
1681 float half_w, half_h;
1682 evas_object_geometry_get(data, &x, &y, &w, &h);
1683 half_w = (float)w * 0.5;
1684 half_h = (float)h * 0.5;
1685 wd->pinch.cx = x + half_w;
1686 wd->pinch.cy = y + half_h;
1687 wd->pinch.level = wd->t;
1688 if (wd->calc_job) ecore_job_del(wd->calc_job);
1689 wd->calc_job = ecore_job_add(_calc_job, wd);
1691 return ECORE_CALLBACK_RENEW;
1695 _long_press(void *data)
1697 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1698 Widget_Data *wd = elm_widget_data_get(data);
1700 if (!wd) return ECORE_CALLBACK_CANCEL;
1701 wd->long_timer = NULL;
1702 evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1703 return ECORE_CALLBACK_CANCEL;
1707 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1709 ELM_CHECK_WIDTYPE(data, widtype);
1710 Widget_Data *wd = elm_widget_data_get(data);
1711 Evas_Event_Mouse_Down *ev = event_info;
1715 ev0 = get_event_object(data, 0);
1717 ev0 = create_event_object(data, obj, 0);
1720 ev0->hold_timer = NULL;
1721 ev0->prev.x = ev->canvas.x;
1722 ev0->prev.y = ev->canvas.y;
1724 if (ev->button != 1) return;
1725 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1726 else wd->on_hold = EINA_FALSE;
1727 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1728 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1730 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1731 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1732 wd->ev.canvas.x = ev->output.x;
1733 wd->ev.canvas.y = ev->output.y;
1734 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1738 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1740 Evas_Event_Mouse_Move *move = event_info;
1743 ev0 = get_event_object(data, 0);
1745 ev0->prev.x = move->cur.canvas.x;
1746 ev0->prev.y = move->cur.canvas.y;
1750 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1752 ELM_CHECK_WIDTYPE(data, widtype);
1753 Widget_Data *wd = elm_widget_data_get(data);
1756 Evas_Event_Mouse_Up *ev = event_info;
1761 ev0 = get_event_object(data, 0);
1764 mdevice = get_multi_device(data);
1767 if (ev0->hold_timer)
1769 ecore_timer_del(ev0->hold_timer);
1770 ev0->hold_timer = NULL;
1772 elm_smart_scroller_hold_set(wd->scr, 0);
1773 elm_smart_scroller_freeze_set(wd->scr, 0);
1777 ev1 = get_event_object(data, mdevice);
1779 ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1781 destroy_event_object(data, ev0);
1784 if (ev->button != 1) return;
1785 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1786 else wd->on_hold = EINA_FALSE;
1789 ecore_timer_del(wd->long_timer);
1790 wd->long_timer = NULL;
1792 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1793 wd->on_hold = EINA_FALSE;
1797 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1799 ELM_CHECK_WIDTYPE(data, widtype);
1800 Widget_Data *wd = elm_widget_data_get(data);
1802 Evas_Event_Multi_Down *down = event_info;
1804 elm_smart_scroller_hold_set(wd->scr, 1);
1805 elm_smart_scroller_freeze_set(wd->scr, 1);
1807 ev = create_event_object(data, obj, down->device);
1810 DBG("Failed : create_event_object");
1815 ev->hold_timer = NULL;
1816 ev->start.x = ev->prev.x = down->canvas.x;
1817 ev->start.y = ev->prev.y = down->canvas.y;
1818 ev->pinch_start_dis = 0;
1819 wd->pinch.level = 1.0;
1820 wd->pinch.diff = 1.0;
1825 ecore_timer_del(wd->long_timer);
1826 wd->long_timer = NULL;
1832 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1834 ELM_CHECK_WIDTYPE(data, widtype);
1835 Widget_Data *wd = elm_widget_data_get(data);
1836 Evas_Event_Multi_Move *move = event_info;
1837 int dis_new, dx, dy;
1838 double t, tt, a, a_diff;
1842 if ((!wd) || (!wd->src)) return;
1843 ev = get_event_object(data, move->device);
1846 ev0 = get_event_object(data, 0);
1849 if (wd->multi_count >= 1)
1851 Evas_Coord x, y, w, h;
1852 float half_w, half_h;
1854 evas_object_geometry_get(data, &x, &y, &w, &h);
1855 half_w = (float)w * 0.5;
1856 half_h = (float)h * 0.5;
1857 dx = ev0->prev.x - ev->prev.x;
1858 dy = ev0->prev.y - ev->prev.y;
1859 dis_new = sqrt((dx * dx) + (dy * dy));
1861 if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1864 ev->pinch_dis = dis_new;
1865 tt = wd->pinch.diff;
1866 wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1867 t = (wd->pinch.diff * 0.01) + 1.0;
1868 if ((t > 1.1) || (wd->rotate.doing))
1870 if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1871 ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1872 (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1874 wd->pinch.diff = tt;
1879 wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1880 wd->pinch.cx = x + half_w;
1881 wd->pinch.cy = y + half_h;
1882 wd->pinch.doing = EINA_TRUE;
1883 if (!wd->rotate.doing) goto do_zoom_only;
1888 if (wd->pinch.doing) goto do_nothing;
1891 a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1892 if (!wd->rotate.a) wd->rotate.a = a;
1895 a_diff = wd->rotate.a - a;
1896 if (a_diff > 0) wd->rotate.d -= 1.0;
1897 else if (a_diff < 0) wd->rotate.d += 1.0;
1899 wd->rotate.cx = x + half_w;
1900 wd->rotate.cy = y + half_h;
1901 wd->rotate.doing = EINA_TRUE;
1904 if (wd->calc_job) ecore_job_del(wd->calc_job);
1905 wd->calc_job = ecore_job_add(_calc_job, wd);
1909 ev->prev.x = move->cur.canvas.x;
1910 ev->prev.y = move->cur.canvas.y;
1914 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1916 ELM_CHECK_WIDTYPE(data, widtype);
1917 Widget_Data *wd = elm_widget_data_get(data);
1918 Evas_Event_Multi_Up *up = event_info;
1925 if (wd->calc_job) ecore_job_del(wd->calc_job);
1926 if (wd->zoom_animator)
1928 ecore_animator_del(wd->zoom_animator);
1929 wd->zoom_animator = NULL;
1932 wd->paused = EINA_TRUE;
1933 if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1934 else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1935 elm_map_zoom_set(data, wd->zoom + zoom);
1936 wd->pinch.level = 1.0;
1937 wd->pinch.doing = EINA_FALSE;
1940 wd->rotate.doing = EINA_FALSE;
1942 ev = get_event_object(data, up->device);
1945 DBG("Cannot get multi device");
1949 ev0 = get_event_object(data, 0);
1951 ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1956 ecore_timer_del(ev->hold_timer);
1957 ev->hold_timer = NULL;
1960 destroy_event_object(data, ev);
1964 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1966 ELM_CHECK_WIDTYPE(data, widtype);
1967 Widget_Data *wd = elm_widget_data_get(data);
1968 Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1969 Evas_Coord x, y, w, h;
1970 float half_w, half_h;
1973 evas_object_geometry_get(data, &x, &y, &w, &h);
1974 half_w = (float)w * 0.5;
1975 half_h = (float)h * 0.5;
1979 wd->zoom_method = ZOOM_METHOD_OUT;
1980 wd->wheel_zoom -= 0.1;
1981 if (wd->wheel_zoom <= -2.0) wd->wheel_zoom = -2.0;
1985 wd->zoom_method = ZOOM_METHOD_IN;
1986 wd->wheel_zoom += 0.1;
1987 if (wd->wheel_zoom >= 2.0) wd->wheel_zoom = 2.0;
1992 wd->pinch.level = pow(2.0, wd->wheel_zoom);
1993 wd->pinch.cx = x + half_w;
1994 wd->pinch.cy = y + half_h;
1995 if (wd->calc_job) ecore_job_del(wd->calc_job);
1996 wd->calc_job = ecore_job_add(_calc_job, wd);
1999 if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
2000 wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
2004 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
2007 _hold_timer_cb(void *data)
2011 ev0->hold_timer = NULL;
2012 return ECORE_CALLBACK_CANCEL;
2016 _wheel_timer_cb(void *data)
2018 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2019 Widget_Data *wd = elm_widget_data_get(data);
2024 wd->wheel_timer = NULL;
2025 return ECORE_CALLBACK_CANCEL;
2027 if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom);
2028 else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor(wd->wheel_zoom);
2031 wd->wheel_timer = NULL;
2032 return ECORE_CALLBACK_CANCEL;
2035 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2036 wd->pinch.level = 1.0;
2037 elm_map_zoom_set(data, wd->zoom + zoom);
2038 wd->wheel_zoom = 0.0;
2039 wd->wheel_timer = NULL;
2040 wd->zoom_method = ZOOM_METHOD_NONE;
2041 return ECORE_CALLBACK_CANCEL;
2045 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2047 ELM_CHECK_WIDTYPE(data, widtype);
2048 Widget_Data *wd = elm_widget_data_get(data);
2051 evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2052 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2053 evas_object_resize(wd->rect, w, h);
2054 evas_object_move(wd->rect, x, y);
2058 _del_hook(Evas_Object *obj)
2060 ELM_CHECK_WIDTYPE(obj, widtype);
2061 Widget_Data *wd = elm_widget_data_get(obj);
2062 Elm_Map_Group_Class *group_clas;
2063 Elm_Map_Marker_Class *marker_clas;
2069 Ecore_Event_Handler *h;
2075 EINA_LIST_FREE(wd->groups_clas, group_clas)
2077 if (group_clas->style)
2078 eina_stringshare_del(group_clas->style);
2082 EINA_LIST_FREE(wd->markers_clas, marker_clas)
2084 if (marker_clas->style)
2085 eina_stringshare_del(marker_clas->style);
2089 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2091 destroy_event_object(obj, ev);
2094 EINA_LIST_FOREACH(wd->route, l, r)
2096 EINA_LIST_FREE(r->path, p)
2101 EINA_LIST_FREE(r->waypoint, w)
2103 if (w->point) eina_stringshare_del(w->point);
2107 EINA_LIST_FREE(r->nodes, n)
2109 if (n->pos.address) eina_stringshare_del(n->pos.address);
2113 EINA_LIST_FREE(r->handlers, h)
2115 ecore_event_handler_del(h);
2118 if (r->con_url) ecore_con_url_free(r->con_url);
2119 if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2120 if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2123 EINA_LIST_FREE(wd->names, na)
2125 if (na->address) free(na->address);
2126 if (na->handler) ecore_event_handler_del(na->handler);
2129 ecore_file_remove(na->ud.fname);
2131 na->ud.fname = NULL;
2135 EINA_LIST_FREE(wd->track, route)
2137 evas_object_del(route);
2140 if (wd->map) evas_map_free(wd->map);
2141 if (wd->source_names) free(wd->source_names);
2142 if (wd->calc_job) ecore_job_del(wd->calc_job);
2143 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2144 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2145 if (wd->long_timer) ecore_timer_del(wd->long_timer);
2146 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2147 if (wd->ua) eina_hash_free(wd->ua);
2148 if (wd->markers) free(wd->markers);
2154 _del_pre_hook(Evas_Object *obj)
2156 ELM_CHECK_WIDTYPE(obj, widtype);
2157 Widget_Data *wd = elm_widget_data_get(obj);
2158 Marker_Group *group;
2159 Elm_Map_Marker *marker;
2161 Eina_Bool free_marker = EINA_TRUE;
2166 for (i = 0; i <= wd->zoom_max; i++)
2168 if (!wd->markers[i]) continue;
2169 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2170 Eina_Matrixsparse_Cell *cell;
2172 EINA_ITERATOR_FOREACH(it, cell)
2174 l = eina_matrixsparse_cell_data_get(cell);
2175 EINA_LIST_FREE(l, group)
2177 EINA_LIST_FREE(group->markers, marker)
2179 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2180 _bubble_sc_hits_changed_cb, group);
2181 if (free_marker) free(marker);
2185 free_marker = EINA_FALSE;
2187 eina_iterator_free(it);
2188 eina_matrixsparse_free(wd->markers[i]);
2191 evas_object_del(wd->sep_maps_markers);
2192 evas_object_del(wd->pan_smart);
2193 wd->pan_smart = NULL;
2197 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2199 ELM_CHECK_WIDTYPE(obj, widtype);
2200 Widget_Data *wd = elm_widget_data_get(obj);
2203 if (elm_widget_focus_get(obj))
2205 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2206 evas_object_focus_set(wd->obj, EINA_TRUE);
2210 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2211 evas_object_focus_set(wd->obj, EINA_FALSE);
2216 _theme_hook(Evas_Object *obj)
2218 ELM_CHECK_WIDTYPE(obj, widtype);
2219 Widget_Data *wd = elm_widget_data_get(obj);
2222 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2223 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2228 _sizing_eval(Evas_Object *obj)
2230 ELM_CHECK_WIDTYPE(obj, widtype);
2231 Widget_Data *wd = elm_widget_data_get(obj);
2232 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2235 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2236 evas_object_size_hint_min_set(obj, minw, minh);
2237 evas_object_size_hint_max_set(obj, maxw, maxh);
2241 _calc_job(void *data)
2243 Widget_Data *wd = data;
2244 Evas_Coord minw, minh;
2251 wd->resized = EINA_FALSE;
2252 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2254 double tz = wd->zoom;
2256 elm_map_zoom_set(wd->obj, tz);
2259 if ((minw != wd->minw) || (minh != wd->minh))
2263 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2264 _sizing_eval(wd->obj);
2266 wd->calc_job = NULL;
2267 evas_object_smart_changed(wd->pan_smart);
2271 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2273 Pan *sd = evas_object_smart_data_get(obj);
2275 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2278 evas_object_smart_changed(obj);
2282 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2284 Pan *sd = evas_object_smart_data_get(obj);
2286 if (x) *x = sd->wd->pan_x;
2287 if (y) *y = sd->wd->pan_y;
2291 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2293 Pan *sd = evas_object_smart_data_get(obj);
2296 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2297 ow = sd->wd->minw - ow;
2299 oh = sd->wd->minh - oh;
2306 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2313 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2315 Pan *sd = evas_object_smart_data_get(obj);
2317 if (w) *w = sd->wd->minw;
2318 if (h) *h = sd->wd->minh;
2322 _pan_add(Evas_Object *obj)
2325 Evas_Object_Smart_Clipped_Data *cd;
2327 cd = evas_object_smart_data_get(obj);
2329 sd = calloc(1, sizeof(Pan));
2331 sd->__clipped_data = *cd;
2333 evas_object_smart_data_set(obj, sd);
2337 _pan_del(Evas_Object *obj)
2339 Pan *sd = evas_object_smart_data_get(obj);
2345 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2347 Pan *sd = evas_object_smart_data_get(obj);
2350 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2351 if ((ow == w) && (oh == h)) return;
2352 sd->wd->resized = EINA_TRUE;
2353 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2354 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2358 _pan_calculate(Evas_Object *obj)
2360 Pan *sd = evas_object_smart_data_get(obj);
2361 Evas_Coord ox, oy, ow, oh;
2365 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2366 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2367 EINA_LIST_FOREACH(sd->wd->grids, l, g)
2369 if (sd->wd->zoom == g->zoom) grid_load(sd->wd->obj, g);
2370 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2371 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2372 if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2373 if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2378 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2380 Pan *sd = evas_object_smart_data_get(obj);
2382 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2383 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2387 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2389 ELM_CHECK_WIDTYPE(obj, widtype);
2390 Widget_Data *wd = elm_widget_data_get(obj);
2393 elm_smart_scroller_hold_set(wd->scr, 1);
2397 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2399 ELM_CHECK_WIDTYPE(obj, widtype);
2400 Widget_Data *wd = elm_widget_data_get(obj);
2403 elm_smart_scroller_hold_set(wd->scr, 0);
2407 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2409 ELM_CHECK_WIDTYPE(obj, widtype);
2410 Widget_Data *wd = elm_widget_data_get(obj);
2413 elm_smart_scroller_freeze_set(wd->scr, 1);
2417 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2419 ELM_CHECK_WIDTYPE(obj, widtype);
2420 Widget_Data *wd = elm_widget_data_get(obj);
2423 elm_smart_scroller_freeze_set(wd->scr, 0);
2427 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2429 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2433 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2435 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2439 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2441 Widget_Data *wd = elm_widget_data_get(data);
2442 wd->center_on.enabled = EINA_FALSE;
2443 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2447 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2449 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2453 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2455 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2460 _group_object_create(Marker_Group *group)
2462 const char *style = "radio";
2463 Evas_Object *icon = NULL;
2465 if (group->obj) return;
2466 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2468 //set icon and style
2469 if (eina_list_count(group->markers) == 1)
2471 Elm_Map_Marker *m = eina_list_data_get(group->markers);
2473 style = m->clas->style;
2475 if (m->clas->func.icon_get)
2476 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2478 group->delete_object = EINA_TRUE;
2482 if (group->clas->style)
2483 style = group->clas->style;
2485 if (group->clas->func.icon_get)
2486 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2488 group->delete_object = EINA_FALSE;
2491 group->obj = elm_layout_add(group->wd->obj);
2492 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2494 if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
2496 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2497 elm_widget_sub_object_add(group->wd->obj, group->obj);
2498 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2500 if (!group->delete_object)
2501 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2505 group->delete_object = EINA_FALSE;
2507 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2508 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2509 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2510 evas_object_show(group->obj);
2513 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2514 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2516 group->update_nbelems = EINA_TRUE;
2517 group->update_resize = EINA_TRUE;
2518 group->update_raise = EINA_TRUE;
2520 if (group->open) _group_bubble_create(group);
2524 _group_object_free(Marker_Group *group)
2526 if (!group->obj) return;
2527 if (!group->delete_object)
2529 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2530 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2531 evas_object_hide(group->obj);
2533 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2534 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2537 evas_object_del(group->obj);
2540 _group_bubble_free(group);
2544 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2546 Marker_Group *group = data;
2548 if (!evas_object_above_get(group->rect)) return;
2549 evas_object_raise(group->bubble);
2550 evas_object_raise(group->sc);
2551 evas_object_raise(group->rect);
2555 _group_bubble_create(Marker_Group *group)
2557 if (group->bubble) return;
2559 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2560 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2561 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2562 elm_widget_style_get(group->wd->obj));
2563 evas_object_smart_member_add(group->bubble,
2565 elm_widget_sub_object_add(group->wd->obj, group->bubble);
2567 _group_bubble_content_free(group);
2568 if (!_group_bubble_content_update(group))
2570 //no content, we can delete the bubble
2571 _group_bubble_free(group);
2575 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2576 evas_object_color_set(group->rect, 0, 0, 0, 0);
2577 evas_object_repeat_events_set(group->rect, EINA_TRUE);
2578 evas_object_smart_member_add(group->rect, group->wd->obj);
2579 elm_widget_sub_object_add(group->wd->obj, group->rect);
2581 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2583 _group_bubble_place(group);
2586 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2588 _group_bubble_place(data);
2592 _group_bubble_content_update(Marker_Group *group)
2595 Elm_Map_Marker *marker;
2598 if (!group->bubble) return 1;
2602 group->sc = elm_scroller_add(group->bubble);
2603 elm_widget_style_set(group->sc, "map_bubble");
2604 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2605 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2606 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2607 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2608 evas_object_show(group->sc);
2609 evas_object_smart_member_add(group->sc,
2611 elm_widget_sub_object_add(group->wd->obj, group->sc);
2613 group->bx = elm_box_add(group->bubble);
2614 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2615 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2616 elm_box_horizontal_set(group->bx, EINA_TRUE);
2617 evas_object_show(group->bx);
2619 elm_scroller_content_set(group->sc, group->bx);
2621 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
2622 _bubble_sc_hits_changed_cb, group);
2625 EINA_LIST_FOREACH(group->markers, l, marker)
2627 if (i >= group->wd->markers_max_num) break;
2628 if ((!marker->content) && (marker->clas->func.get))
2629 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2630 else if (marker->content)
2631 elm_box_unpack(group->bx, marker->content);
2632 if (marker->content)
2634 elm_box_pack_end(group->bx, marker->content);
2642 _group_bubble_content_free(Marker_Group *group)
2645 Elm_Map_Marker *marker;
2647 if (!group->sc) return;
2648 EINA_LIST_FOREACH(group->markers, l, marker)
2650 if ((marker->content) && (marker->clas->func.del))
2651 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2652 else if (marker->content)
2653 evas_object_del(marker->content);
2654 marker->content = NULL;
2656 evas_object_del(group->sc);
2661 _group_bubble_free(Marker_Group *group)
2663 if (!group->bubble) return;
2664 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2665 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2666 _bubble_sc_hits_changed_cb, group);
2667 evas_object_del(group->bubble);
2668 evas_object_del(group->rect);
2669 group->bubble = NULL;
2670 _group_bubble_content_free(group);
2674 _group_bubble_place(Marker_Group *group)
2677 Evas_Coord xx, yy, ww, hh;
2680 if ((!group->bubble) || (!group->obj)) return;
2682 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2683 edje_object_size_min_calc(group->bubble, NULL, &hh);
2685 s = edje_object_data_get(group->bubble, "size_w");
2686 if (s) ww = atoi(s);
2688 xx = x + w / 2 - ww / 2;
2691 evas_object_move(group->bubble, xx, yy);
2692 evas_object_resize(group->bubble, ww, hh);
2693 obj_rotate_zoom(group->wd, group->bubble);
2694 evas_object_show(group->bubble);
2696 evas_object_move(group->rect, xx, yy);
2697 evas_object_resize(group->rect, ww, hh);
2698 obj_rotate_zoom(group->wd, group->rect);
2699 evas_object_show(group->rect);
2703 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2705 Marker_Group *group = data;
2706 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2707 if (!marker) return;
2708 group->bringin = EINA_TRUE;
2709 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2713 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2715 Marker_Group *group = data;
2719 group->bringin = EINA_FALSE;
2725 group->open = EINA_FALSE;
2726 _group_bubble_free(group);
2729 group->open = EINA_TRUE;
2730 _group_bubble_create(group);
2734 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2736 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2737 Widget_Data *wd = elm_widget_data_get(obj);
2741 Evas_Coord step_x = 0;
2742 Evas_Coord step_y = 0;
2745 Evas_Coord page_x = 0;
2746 Evas_Coord page_y = 0;
2748 if (!wd) return EINA_FALSE;
2749 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2750 Evas_Event_Key_Down *ev = event_info;
2751 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2753 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2754 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2755 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2756 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2758 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2762 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2766 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2770 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2774 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2777 y -= -(page_y * v_h) / 100;
2781 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2784 y += -(page_y * v_h) / 100;
2788 else if (!strcmp(ev->keyname, "KP_Add"))
2790 zoom = elm_map_zoom_get(obj) + 1;
2791 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2792 elm_map_zoom_set(obj, zoom);
2795 else if (!strcmp(ev->keyname, "KP_Subtract"))
2797 zoom = elm_map_zoom_get(obj) - 1;
2798 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2799 elm_map_zoom_set(obj, zoom);
2802 else return EINA_FALSE;
2804 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2805 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2811 cb_dump_name_attrs(void *data, const char *key, const char *value)
2813 Name_Dump *dump = (Name_Dump*)data;
2814 if (!dump) return EINA_FALSE;
2816 if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2817 else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2824 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2826 Route_Dump *dump = data;
2827 if (!dump) return EINA_FALSE;
2831 case EINA_SIMPLE_XML_OPEN:
2832 case EINA_SIMPLE_XML_OPEN_EMPTY:
2836 attrs = eina_simple_xml_tag_attributes_find(value, length);
2839 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2840 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2841 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2842 else dump->id = ROUTE_XML_NONE;
2846 case EINA_SIMPLE_XML_DATA:
2848 char *buf = malloc(length);
2849 if (!buf) return EINA_FALSE;
2850 snprintf(buf, length, "%s", value);
2851 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2852 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2853 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2865 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2867 Name_Dump *dump = data;
2868 if (!dump) return EINA_FALSE;
2872 case EINA_SIMPLE_XML_OPEN:
2873 case EINA_SIMPLE_XML_OPEN_EMPTY:
2876 attrs = eina_simple_xml_tag_attributes_find(value, length);
2879 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2880 else dump->id = NAME_XML_NONE;
2882 eina_simple_xml_attributes_parse
2883 (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2887 case EINA_SIMPLE_XML_DATA:
2889 char *buf = malloc(length + 1);
2890 if (!buf) return EINA_FALSE;
2891 snprintf(buf, length + 1, "%s", value);
2892 if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2904 _parse_kml(void *data)
2906 Elm_Map_Route *r = (Elm_Map_Route*)data;
2907 if (!r && !r->ud.fname) return;
2911 unsigned int ele, idx;
2915 Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2917 f = fopen(r->ud.fname, "rb");
2922 fseek(f, 0, SEEK_END);
2928 fseek(f, 0, SEEK_SET);
2932 if (fread(buf, 1, sz, f))
2934 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
2941 if (dump.distance) r->info.distance = dump.distance;
2942 if (dump.description)
2944 eina_stringshare_replace(&r->info.waypoints, dump.description);
2945 str = eina_str_split_full(dump.description, "\n", 0, &ele);
2946 r->info.waypoint_count = ele;
2947 for (idx = 0 ; idx < ele ; idx++)
2949 Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
2953 wp->point = eina_stringshare_add(str[idx]);
2954 DBG("%s", str[idx]);
2955 r->waypoint = eina_list_append(r->waypoint, wp);
2964 else WRN("description is not found !");
2966 if (dump.coordinates)
2968 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2969 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2970 r->info.node_count = ele;
2971 for (idx = 0 ; idx < ele ; idx++)
2973 sscanf(str[idx], "%lf,%lf", &lon, &lat);
2974 Path_Node *n = ELM_NEW(Path_Node);
2981 DBG("%lf:%lf", lon, lat);
2982 n->pos.address = NULL;
2983 r->nodes = eina_list_append(r->nodes, n);
2985 path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
2986 evas_object_smart_member_add(path, r->wd->pan_smart);
2987 r->path = eina_list_append(r->path, path);
3000 _parse_name(void *data)
3002 Elm_Map_Name *n = (Elm_Map_Name*)data;
3003 if (!n && !n->ud.fname) return;
3007 Name_Dump dump = {0, NULL, 0.0, 0.0};
3009 f = fopen(n->ud.fname, "rb");
3014 fseek(f, 0, SEEK_END);
3020 fseek(f, 0, SEEK_SET);
3024 if (fread(buf, 1, sz, f))
3026 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3035 INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3036 n->address = strdup(dump.address);
3044 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3046 Ecore_Con_Event_Url_Complete *ev = event;
3047 Elm_Map_Route *r = (Elm_Map_Route*)data;
3048 Widget_Data *wd = r->wd;
3050 if ((!r) || (!ev)) return EINA_TRUE;
3051 Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3052 ecore_con_url_data_set(r->con_url, NULL);
3053 if (r!=rr) return EINA_TRUE;
3055 if (r->ud.fd) fclose(r->ud.fd);
3060 Evas_Coord ox, oy, ow, oh;
3061 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3062 route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3064 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3065 "elm,state,busy,stop", "elm");
3066 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3071 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3073 Ecore_Con_Event_Url_Complete *ev = event;
3074 Elm_Map_Name *n = (Elm_Map_Name*)data;
3075 Widget_Data *wd = n->wd;
3077 if ((!n) || (!ev)) return EINA_TRUE;
3078 Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3079 ecore_con_url_data_set(n->con_url, NULL);
3080 if (n!=nn) return EINA_TRUE;
3082 if (n->ud.fd) fclose(n->ud.fd);
3085 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3086 "elm,state,busy,stop", "elm");
3087 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3091 static Elm_Map_Name *
3092 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3094 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3095 Widget_Data *wd = elm_widget_data_get(obj);
3100 if ((!wd) || (!wd->src)) return NULL;
3101 Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3102 if (!name) return NULL;
3104 snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3112 name->con_url = ecore_con_url_new(NULL);
3113 name->ud.fname = strdup(buf);
3114 INF("xml file : %s", name->ud.fname);
3116 name->ud.fd = fdopen(fd, "w+");
3117 if ((!name->con_url) || (!name->ud.fd))
3119 ecore_con_url_free(name->con_url);
3125 name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3126 name->method = method;
3127 if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3128 else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3132 source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3133 INF("name url = %s", source);
3135 wd->names = eina_list_append(wd->names, name);
3136 ecore_con_url_url_set(name->con_url, source);
3137 ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3138 ecore_con_url_data_set(name->con_url, name);
3140 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3141 "elm,state,busy,start", "elm");
3142 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3143 ecore_con_url_get(name->con_url);
3144 if (source) free(source);
3150 static int idnum = 1;
3153 * Add a new Map object
3155 * @param parent The parent object
3156 * @return The new object or NULL if it cannot be created
3161 elm_map_add(Evas_Object *parent)
3165 Evas_Coord minw, minh;
3167 static Evas_Smart *smart = NULL;
3168 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3170 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3172 ELM_SET_WIDTYPE(widtype, "map");
3173 elm_widget_type_set(obj, "map");
3174 elm_widget_sub_object_add(parent, obj);
3175 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3176 elm_widget_data_set(obj, wd);
3177 elm_widget_del_hook_set(obj, _del_hook);
3178 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3179 elm_widget_theme_hook_set(obj, _theme_hook);
3180 elm_widget_can_focus_set(obj, EINA_TRUE);
3181 elm_widget_event_hook_set(obj, _event_hook);
3183 wd->scr = elm_smart_scroller_add(e);
3184 elm_smart_scroller_widget_set(wd->scr, obj);
3185 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3186 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3187 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3188 elm_widget_resize_object_set(obj, wd->scr);
3189 elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3191 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3192 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3193 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3194 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3195 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3197 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3201 wd->map = evas_map_new(4);
3202 if (!wd->map) return NULL;
3204 wd->zoom_min = 0xFF;
3205 wd->zoom_max = 0X00;
3206 wd->markers_max_num = 30;
3207 wd->pinch.level = 1.0;
3210 wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3212 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3213 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3214 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3215 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3219 static Evas_Smart_Class sc;
3221 evas_object_smart_clipped_smart_set(&_pan_sc);
3223 sc.name = "elm_map_pan";
3224 sc.version = EVAS_SMART_CLASS_VERSION;
3227 sc.resize = _pan_resize;
3228 sc.move = _pan_move;
3229 sc.calculate = _pan_calculate;
3230 smart = evas_smart_class_new(&sc);
3234 wd->pan_smart = evas_object_smart_add(e, smart);
3235 wd->pan = evas_object_smart_data_get(wd->pan_smart);
3239 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3240 _pan_set, _pan_get, _pan_max_get,
3241 _pan_min_get, _pan_child_size_get);
3243 wd->rect = evas_object_rectangle_add(e);
3244 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3245 _rect_resize_cb, obj);
3246 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3248 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3250 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3252 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3253 _mouse_multi_down, obj);
3254 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3255 _mouse_multi_move, obj);
3256 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3257 _mouse_multi_up, obj);
3258 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3259 _mouse_wheel_cb, obj);
3261 evas_object_smart_member_add(wd->rect, wd->pan_smart);
3262 elm_widget_sub_object_add(obj, wd->rect);
3263 evas_object_show(wd->rect);
3264 evas_object_color_set(wd->rect, 0, 0, 0, 0);
3266 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3267 wd->id = ((int)getpid() << 16) | idnum;
3271 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3273 evas_object_size_hint_min_set(obj, minw, minh);
3275 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3276 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3278 wd->paused = EINA_TRUE;
3279 elm_map_zoom_set(obj, 0);
3280 wd->paused = EINA_FALSE;
3283 // TODO: convert Elementary to subclassing of Evas_Smart_Class
3284 // TODO: and save some bytes, making descriptions per-class and not instance!
3285 evas_object_smart_callbacks_descriptions_set(obj, _signals);
3287 if (!ecore_file_download_protocol_available("http://"))
3289 ERR("Ecore must be built with curl support for the map widget!");
3296 * Set the zoom level of the map
3298 * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
3300 * @param obj The map object
3301 * @param zoom The zoom level to set
3306 elm_map_zoom_set(Evas_Object *obj, int zoom)
3308 ELM_CHECK_WIDTYPE(obj, widtype);
3309 Widget_Data *wd = elm_widget_data_get(obj);
3311 Grid *g, *g_zoom = NULL;
3312 Evas_Coord rx, ry, rw, rh;
3316 int z = 0, zoom_changed = 0, started = 0;
3318 if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3319 if (zoom < 0 ) zoom = 0;
3320 if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3321 if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3323 if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3324 else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3325 else wd->zoom_method = ZOOM_METHOD_NONE;
3326 if (wd->zoom != zoom ) zoom_changed = 1;
3328 wd->size.ow = wd->size.w;
3329 wd->size.oh = wd->size.h;
3330 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3331 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3333 EINA_LIST_FOREACH(wd->route, l, r)
3337 EINA_LIST_FOREACH(r->path, l, p)
3339 evas_object_polygon_points_clear(p);
3344 EINA_LIST_FOREACH(wd->track, l, route)
3346 evas_object_hide(route);
3349 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3356 while (cumulw <= rw)
3365 while (cumulh <= rh)
3372 if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3374 if (p2w < p2h) z = p2w;
3377 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3379 if (p2w > p2h) z = p2w;
3384 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3385 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3387 g = grid_create(obj);
3390 if (eina_list_count(wd->grids) > 1)
3392 g_zoom = eina_list_last(wd->grids)->data;
3393 wd->grids = eina_list_remove(wd->grids, g_zoom);
3394 grid_clear(obj, g_zoom);
3397 wd->grids = eina_list_prepend(wd->grids, g);
3401 EINA_LIST_FREE(wd->grids, g)
3409 if ((wd->size.w > 0) && (wd->size.h > 0))
3411 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3412 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3416 wd->size.spos.x = 0.5;
3417 wd->size.spos.y = 0.5;
3420 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3421 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3422 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3423 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3428 if (wd->calc_job) ecore_job_del(wd->calc_job);
3429 wd->calc_job = ecore_job_add(_calc_job, wd);
3433 if (!wd->zoom_animator)
3435 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3437 if (wd->nosmooth == 1) _smooth_update(obj);
3444 if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3445 if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3448 if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3452 * Get the zoom level of the map
3454 * This returns the current zoom level of the map object. Note that if
3455 * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
3456 * (which is the default), the zoom level may be changed at any time by the
3457 * map object itself to account for map size and map viewpoer size
3459 * @param obj The map object
3460 * @return The current zoom level
3465 elm_map_zoom_get(const Evas_Object *obj)
3467 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3468 Widget_Data *wd = elm_widget_data_get(obj);
3477 * This sets the zoom mode to manual or one of several automatic levels.
3478 * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
3479 * elm_map_zoom_set() and will stay at that level until changed by code
3480 * or until zoom mode is changed. This is the default mode.
3481 * The Automatic modes will allow the map object to automatically
3482 * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT will
3483 * adjust zoom so the map fits inside the scroll frame with no pixels
3484 * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
3485 * 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.
3487 * @param obj The map object
3488 * @param mode The desired mode
3493 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3495 ELM_CHECK_WIDTYPE(obj, widtype);
3496 Widget_Data *wd = elm_widget_data_get(obj);
3499 if (wd->mode == mode) return;
3502 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3506 elm_map_zoom_set(wd->obj, tz);
3513 * This gets the current zoom mode of the map object
3515 * @param obj The map object
3516 * @return The current zoom mode
3520 EAPI Elm_Map_Zoom_Mode
3521 elm_map_zoom_mode_get(const Evas_Object *obj)
3523 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3524 Widget_Data *wd = elm_widget_data_get(obj);
3526 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3531 * Centers the map at @p lon @p lat using an animation to scroll.
3533 * @param obj The map object
3534 * @param lon Longitude to center at
3535 * @param lon Latitude to center at
3540 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3542 ELM_CHECK_WIDTYPE(obj, widtype);
3543 Widget_Data *wd = elm_widget_data_get(obj);
3547 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3548 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3553 if (wd->zoom_animator)
3556 if (!wd->nosmooth) _smooth_update(obj);
3557 ecore_animator_del(wd->zoom_animator);
3558 wd->zoom_animator = NULL;
3560 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3562 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3564 wd->center_on.enabled = EINA_TRUE;
3565 wd->center_on.lon = lon;
3566 wd->center_on.lat = lat;
3570 * Move the map to the current coordinates.
3572 * This move the map to the current coordinates. The map will be centered on these coordinates.
3574 * @param obj The map object
3575 * @param lat The latitude.
3576 * @param lon The longitude.
3581 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3583 ELM_CHECK_WIDTYPE(obj, widtype);
3584 Widget_Data *wd = elm_widget_data_get(obj);
3588 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3589 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3594 if (wd->zoom_animator)
3597 ecore_animator_del(wd->zoom_animator);
3598 wd->zoom_animator = NULL;
3600 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3602 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3604 wd->center_on.enabled = EINA_TRUE;
3605 wd->center_on.lon = lon;
3606 wd->center_on.lat = lat;
3610 * Get the current coordinates of the map.
3612 * This gets the current coordinates of the map object.
3614 * @param obj The map object
3615 * @param lat The latitude.
3616 * @param lon The longitude.
3621 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3623 ELM_CHECK_WIDTYPE(obj, widtype);
3624 Widget_Data *wd = elm_widget_data_get(obj);
3625 Evas_Coord sx, sy, sw, sh;
3628 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3629 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3633 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3637 * Set the paused state for map
3639 * This sets the paused state to on (1) or off (0) for map. The default
3640 * is off. This will stop zooming using animation change zoom levels and
3641 * change instantly. This will stop any existing animations that are running.
3643 * @param obj The map object
3644 * @param paused The pause state to set
3649 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3651 ELM_CHECK_WIDTYPE(obj, widtype);
3652 Widget_Data *wd = elm_widget_data_get(obj);
3655 if (wd->paused == !!paused) return;
3656 wd->paused = paused;
3659 if (wd->zoom_animator)
3661 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3662 wd->zoom_animator = NULL;
3664 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3670 * Set the paused state for the markers
3672 * This sets the paused state to on (1) or off (0) for the markers. The default
3673 * is off. This will stop displaying the markers during change zoom levels. Set
3674 * to on if you have a large number of markers.
3676 * @param obj The map object
3677 * @param paused The pause state to set
3682 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3684 ELM_CHECK_WIDTYPE(obj, widtype);
3685 Widget_Data *wd = elm_widget_data_get(obj);
3688 if (wd->paused_markers == !!paused) return;
3689 wd->paused_markers = paused;
3693 * Get the paused state for map
3695 * This gets the current paused state for the map object.
3697 * @param obj The map object
3698 * @return The current paused state
3703 elm_map_paused_get(const Evas_Object *obj)
3705 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3706 Widget_Data *wd = elm_widget_data_get(obj);
3708 if (!wd) return EINA_FALSE;
3713 * Get the paused state for the markers
3715 * This gets the current paused state for the markers object.
3717 * @param obj The map object
3718 * @return The current paused state
3723 elm_map_paused_markers_get(const Evas_Object *obj)
3725 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3726 Widget_Data *wd = elm_widget_data_get(obj);
3728 if (!wd) return EINA_FALSE;
3729 return wd->paused_markers;
3733 * Get the information of downloading status
3735 * This gets the current downloading status for the map object.
3737 * @param obj The map object
3738 * @param try_num the number of download trying map
3739 * @param finish_num the number of downloaded map
3745 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3747 ELM_CHECK_WIDTYPE(obj, widtype);
3748 Widget_Data *wd = elm_widget_data_get(obj);
3753 *try_num = wd->try_num;
3758 *finish_num = wd->finish_num;
3762 * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
3764 * @param obj The map object
3765 * @param x the coordinate
3766 * @param y the coordinate
3767 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3768 * @param lon the longitude correspond to x
3769 * @param lat the latitude correspond to y
3774 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3776 ELM_CHECK_WIDTYPE(obj, widtype);
3777 Widget_Data *wd = elm_widget_data_get(obj);
3780 int zoom = floor(log(size / 256) / log(2));
3781 if ((wd->src) && (wd->src->coord_into_geo))
3783 if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3788 *lon = x / (double)size * 360.0 - 180;
3792 double n = ELM_PI - 2.0 * ELM_PI * y / size;
3793 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3798 * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
3800 * @param obj The map object
3801 * @param lon the longitude
3802 * @param lat the latitude
3803 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3804 * @param x the coordinate correspond to the longitude
3805 * @param y the coordinate correspond to the latitude
3810 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3812 ELM_CHECK_WIDTYPE(obj, widtype);
3813 Widget_Data *wd = elm_widget_data_get(obj);
3816 int zoom = floor(log(size / 256) / log(2));
3817 if ((wd->src) && (wd->src->geo_into_coord))
3819 if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3823 *x = floor((lon + 180.0) / 360.0 * size);
3825 *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3829 * Convert a geographic coordinate (longitude, latitude) into a name (address).
3831 * @param obj The map object
3832 * @param lon the longitude
3833 * @param lat the latitude
3835 * @return name the address
3840 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3842 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3843 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3847 * Convert a name (address) into a geographic coordinate (longitude, latitude).
3849 * @param obj The map object
3850 * @param name the address
3851 * @param lat the latitude correspond to y
3853 * @return name the address
3858 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3860 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3861 if (!address) return NULL;
3862 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3866 * Convert a pixel coordinate into a roated pixcel coordinate.
3868 * @param obj The map object
3869 * @param x x to rotate.
3870 * @param y y to rotate.
3871 * @param cx rotation's center horizontal position.
3872 * @param cy rotation's center vertical position.
3873 * @param degree amount of degrees from 0.0 to 360.0 to rotate arount Z axis.
3874 * @param xx rotated x.
3875 * @param yy rotated y.
3880 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)
3882 if ((!xx) || (!yy)) return;
3884 double r = (degree * M_PI) / 180.0;
3885 double tx, ty, ttx, tty;
3892 tx = ttx + (ty * cos(r + M_PI_2));
3893 ty = tty + (ty * sin(r + M_PI_2));
3900 * Add a marker on the map
3902 * @param obj The map object
3903 * @param lon the longitude
3904 * @param lat the latitude
3905 * @param clas the class to use
3906 * @param clas_group the class group
3907 * @param data the data passed to the callbacks
3909 * @return The marker object
3913 EAPI Elm_Map_Marker *
3914 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3916 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3917 Widget_Data *wd = elm_widget_data_get(obj);
3920 Marker_Group *group;
3928 if (!wd) return NULL;
3929 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3930 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3932 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3935 marker->clas = clas;
3936 marker->clas_group = clas_group;
3937 marker->longitude = lon;
3938 marker->latitude = lat;
3939 marker->data = data;
3940 marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3941 marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3942 marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
3944 tabi[1] = tabi[4] = tabi[6] = -1;
3945 tabi[2] = tabi[0] = tabi[7] = 0;
3946 tabi[3] = tabi[5] = tabi[8] = 1;
3948 tabj[1] = tabj[2] = tabj[3] = -1;
3949 tabj[4] = tabj[0] = tabj[5] = 0;
3950 tabj[6] = tabj[7] = tabj[8] = 1;
3952 if (!clas_group->priv.set)
3955 if (marker->clas_group && marker->clas_group->style)
3956 style = marker->clas_group->style;
3958 o = edje_object_add(evas_object_evas_get(obj));
3959 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3960 s = edje_object_data_get(o, "size_w");
3961 if (s) clas_group->priv.edje_w = atoi(s);
3962 else clas_group->priv.edje_w = 0;
3963 s = edje_object_data_get(o, "size_h");
3964 if (s) clas_group->priv.edje_h = atoi(s);
3965 else clas_group->priv.edje_h = 0;
3966 s = edje_object_data_get(o, "size_max_w");
3967 if (s) clas_group->priv.edje_max_w = atoi(s);
3968 else clas_group->priv.edje_max_w = 0;
3969 s = edje_object_data_get(o, "size_max_h");
3970 if (s) clas_group->priv.edje_max_h = atoi(s);
3971 else clas_group->priv.edje_max_h = 0;
3974 clas_group->priv.set = EINA_TRUE;
3977 if (!clas->priv.set)
3980 if (marker->clas && marker->clas->style)
3981 style = marker->clas->style;
3983 o = edje_object_add(evas_object_evas_get(obj));
3984 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3985 s = edje_object_data_get(o, "size_w");
3986 if (s) clas->priv.edje_w = atoi(s);
3987 else clas->priv.edje_w = 0;
3988 s = edje_object_data_get(o, "size_h");
3989 if (s) clas->priv.edje_h = atoi(s);
3990 else clas->priv.edje_h = 0;
3993 clas->priv.set = EINA_TRUE;
3996 for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3998 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3999 &(marker->x[i]), &(marker->y[i]));
4001 //search in the matrixsparse the region where the marker will be
4002 mpi = marker->x[i] / wd->tsize;
4003 mpj = marker->y[i] / wd->tsize;
4005 if (!wd->markers[i])
4007 int size = pow(2.0, i);
4008 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
4012 if (i <= clas_group->zoom_grouped)
4014 for (j = 0, group = NULL; j < 9 && !group; j++)
4016 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
4019 if (group->clas == marker->clas_group
4020 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
4021 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
4022 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
4024 group->markers = eina_list_append(group->markers, marker);
4025 group->update_nbelems = EINA_TRUE;
4026 group->update_resize = EINA_TRUE;
4028 group->sum_x += marker->x[i];
4029 group->sum_y += marker->y[i];
4030 group->x = group->sum_x / eina_list_count(group->markers);
4031 group->y = group->sum_y / eina_list_count(group->markers);
4033 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
4034 * eina_list_count(group->markers);
4035 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
4036 * eina_list_count(group->markers);
4037 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
4038 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
4040 if (group->obj && eina_list_count(group->markers) == 2)
4042 _group_object_free(group);
4043 _group_object_create(group);
4046 _group_bubble_content_update(group);
4055 group = calloc(1, sizeof(Marker_Group));
4057 group->sum_x = marker->x[i];
4058 group->sum_y = marker->y[i];
4059 group->x = marker->x[i];
4060 group->y = marker->y[i];
4061 group->w = clas_group->priv.edje_w;
4062 group->h = clas_group->priv.edje_h;
4063 group->clas = clas_group;
4065 group->markers = eina_list_append(group->markers, marker);
4066 group->update_nbelems = EINA_TRUE;
4067 group->update_resize = EINA_TRUE;
4069 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4073 l = eina_list_append(NULL, group);
4074 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
4075 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4079 l = eina_matrixsparse_cell_data_get(group->cell);
4080 l = eina_list_append(l, group);
4081 eina_matrixsparse_cell_data_set(group->cell, l);
4084 marker->groups[i] = group;
4089 Evas_Coord ox, oy, ow, oh;
4090 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4091 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4098 * Remove a marker from the map
4100 * @param marker The marker to remove
4105 elm_map_marker_remove(Elm_Map_Marker *marker)
4111 EINA_SAFETY_ON_NULL_RETURN(marker);
4114 for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4116 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
4117 if (!eina_list_count(marker->groups[i]->markers))
4119 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
4120 groups = eina_list_remove(groups, marker->groups[i]);
4121 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
4123 _group_object_free(marker->groups[i]);
4124 _group_bubble_free(marker->groups[i]);
4125 free(marker->groups[i]);
4129 marker->groups[i]->sum_x -= marker->x[i];
4130 marker->groups[i]->sum_y -= marker->y[i];
4132 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
4133 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
4135 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
4136 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
4137 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
4138 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
4139 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
4140 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
4141 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
4142 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
4144 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
4146 _group_object_free(marker->groups[i]);
4147 _group_object_create(marker->groups[i]);
4152 if ((marker->content) && (marker->clas->func.del))
4153 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4154 else if (marker->content)
4155 evas_object_del(marker->content);
4157 if (marker->x) free(marker->x);
4158 if (marker->y) free(marker->y);
4159 if (marker->groups) free(marker->groups);
4165 Evas_Coord ox, oy, ow, oh;
4166 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4167 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4172 * Get the current coordinates of the marker.
4174 * @param marker marker.
4175 * @param lat The latitude.
4176 * @param lon The longitude.
4181 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
4183 EINA_SAFETY_ON_NULL_RETURN(marker);
4184 if (lon) *lon = marker->longitude;
4185 if (lat) *lat = marker->latitude;
4189 * Move the map to the coordinate of the marker.
4191 * @param marker The marker where the map will be center.
4196 elm_map_marker_bring_in(Elm_Map_Marker *marker)
4198 EINA_SAFETY_ON_NULL_RETURN(marker);
4199 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
4203 * Move the map to the coordinate of the marker.
4205 * @param marker The marker where the map will be center.
4210 elm_map_marker_show(Elm_Map_Marker *marker)
4212 EINA_SAFETY_ON_NULL_RETURN(marker);
4213 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
4217 * Move and zoom the map to display a list of markers.
4219 * The map will be centered on the center point of the markers in the list. Then
4220 * the map will be zoomed in order to fit the markers using the maximum zoom which
4221 * allows display of all the markers.
4223 * @param markers The list of markers (list of Elm_Map_Marker *)
4228 elm_map_markers_list_show(Eina_List *markers)
4233 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
4234 Evas_Coord rw, rh, xc, yc;
4237 EINA_SAFETY_ON_NULL_RETURN(markers);
4238 EINA_LIST_FOREACH(markers, l, marker)
4242 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
4245 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
4248 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
4251 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
4255 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
4256 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
4258 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
4259 for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
4261 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4262 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4264 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4265 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4266 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4267 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4271 elm_map_geo_region_show(wd->obj, lon, lat);
4272 elm_map_zoom_set(wd->obj, zoom);
4276 * Set the maximum numbers of markers display in a group.
4278 * A group can have a long list of markers, consequently the creation of the content
4279 * of the bubble can be very slow. In order to avoid this, a maximum number of items
4280 * is displayed in a bubble. By default this number is 30.
4282 * @param obj The map object.
4283 * @param max The maximum numbers of items displayed in a bubble.
4288 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4290 ELM_CHECK_WIDTYPE(obj, widtype);
4291 Widget_Data *wd = elm_widget_data_get(obj);
4294 wd->markers_max_num = max;
4298 * Return the evas object getting from the ElmMapMarkerGetFunc callback
4300 * @param marker The marker.
4301 * @return Return the evas object if it exists, else NULL.
4306 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4308 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4309 return marker->content;
4315 * @param marker The marker.
4320 elm_map_marker_update(Elm_Map_Marker *marker)
4322 EINA_SAFETY_ON_NULL_RETURN(marker);
4323 if (marker->content)
4325 if (marker->clas->func.del)
4326 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4328 evas_object_del(marker->content);
4329 marker->content = NULL;
4330 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4335 * Close all opened bubbles
4337 * @param obj The map object
4342 elm_map_bubbles_close(Evas_Object *obj)
4344 ELM_CHECK_WIDTYPE(obj, widtype);
4345 Widget_Data *wd = elm_widget_data_get(obj);
4346 Marker_Group *group;
4347 Eina_List *l, *l_next;
4350 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4351 _group_bubble_free(group);
4355 * Create a group class.
4357 * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
4358 * The group class defines the style of the marker when a marker is grouped to others markers.
4360 * @param obj The map object
4361 * @return Returns the new group class
4365 EAPI Elm_Map_Group_Class *
4366 elm_map_group_class_new(Evas_Object *obj)
4368 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4369 Widget_Data *wd = elm_widget_data_get(obj);
4371 if (!wd) return NULL;
4372 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4373 clas->zoom_grouped = wd->zoom_max;
4374 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4379 * Set the style of a group class (radio, radio2 or empty)
4381 * @param clas the group class
4382 * @param style the new style
4387 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4389 EINA_SAFETY_ON_NULL_RETURN(clas);
4390 eina_stringshare_replace(&clas->style, style);
4394 * Set the icon callback of a group class.
4396 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4398 * @param clas the group class
4399 * @param icon_get the callback to create the icon
4404 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4406 EINA_SAFETY_ON_NULL_RETURN(clas);
4407 clas->func.icon_get = icon_get;
4411 * Set the data associated to the group class (radio, radio2 or empty)
4413 * @param clas the group class
4414 * @param data the new user data
4419 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4421 EINA_SAFETY_ON_NULL_RETURN(clas);
4426 * Set the zoom from where the markers are displayed.
4428 * Markers will not be displayed for a zoom less than @ref zoom
4430 * @param clas the group class
4431 * @param zoom the zoom
4436 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4438 EINA_SAFETY_ON_NULL_RETURN(clas);
4439 clas->zoom_displayed = zoom;
4443 * Set the zoom from where the markers are no more grouped.
4445 * @param clas the group class
4446 * @param zoom the zoom
4451 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4453 EINA_SAFETY_ON_NULL_RETURN(clas);
4454 clas->zoom_grouped = zoom;
4458 * Set if the markers associated to the group class @clas are hidden or not.
4459 * If @ref hide is true the markers will be hidden.
4461 * @param clas the group class
4462 * @param hide if true the markers will be hidden, else they will be displayed.
4467 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4469 ELM_CHECK_WIDTYPE(obj, widtype);
4470 Widget_Data *wd = elm_widget_data_get(obj);
4473 EINA_SAFETY_ON_NULL_RETURN(clas);
4474 if (clas->hide == hide) return;
4478 Evas_Coord ox, oy, ow, oh;
4479 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4480 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4486 * Create a marker class.
4488 * Each marker must be associated to a class.
4489 * The class defines the style of the marker when a marker is displayed alone (not grouped).
4491 * @param obj The map object
4492 * @return Returns the new class
4496 EAPI Elm_Map_Marker_Class *
4497 elm_map_marker_class_new(Evas_Object *obj)
4499 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4500 Widget_Data *wd = elm_widget_data_get(obj);
4502 if (!wd) return NULL;
4503 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4504 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4509 * Set the style of a class (radio, radio2 or empty)
4511 * @param clas the group class
4512 * @param style the new style
4517 elm_map_marker_class_style_set(Elm_Map_Marker_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 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_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4536 EINA_SAFETY_ON_NULL_RETURN(clas);
4537 clas->func.icon_get = icon_get;
4542 * Set the callback of the content of the bubble.
4544 * When the user click on a marker, a bubble is displayed with a content.
4545 * The callback @ref get musst return this content. It can be NULL.
4547 * @param clas the group class
4548 * @param get the callback to create the content
4553 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4555 EINA_SAFETY_ON_NULL_RETURN(clas);
4556 clas->func.get = get;
4560 * Set the callback of the content of delete the object created by the callback "get".
4562 * If this callback is defined the user will have to delete (or not) the object inside.
4563 * If the callback is not defined the object will be destroyed with evas_object_del()
4565 * @param clas the group class
4566 * @param del the callback to delete the content
4571 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4573 EINA_SAFETY_ON_NULL_RETURN(clas);
4574 clas->func.del = del;
4578 * Get the list of the sources.
4580 * @param obj The map object
4581 * @return sources the source list
4587 elm_map_source_names_get(const Evas_Object *obj)
4589 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4590 Widget_Data *wd = elm_widget_data_get(obj);
4592 if (!wd) return NULL;
4593 return wd->source_names;
4597 * Set the source of the map.
4599 * Elm_Map retrieves the image which composed the map from a web service. This web service can
4600 * be set with this method. A different service can return a different maps with different
4601 * information and it can use different zoom value.
4603 * @param obj the map object
4604 * @param source the new source
4609 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4611 ELM_CHECK_WIDTYPE(obj, widtype);
4612 Widget_Data *wd = elm_widget_data_get(obj);
4619 if ((wd->src) && (!strcmp(wd->src->name, source_name))) return;
4620 if ((wd->src) && (!wd->src->url_cb)) return;
4622 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4623 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4625 if (!strcmp(s->name, source_name))
4634 if (wd->src->zoom_max < zoom)
4635 zoom = wd->src->zoom_max;
4636 if (wd->src->zoom_min > zoom)
4637 zoom = wd->src->zoom_min;
4639 elm_map_zoom_set(obj, zoom);
4643 * Get the name of a source.
4645 * @param source the source
4646 * @return Returns the name of the source
4651 elm_map_source_name_get(const Evas_Object *obj)
4653 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4654 Widget_Data *wd = elm_widget_data_get(obj);
4656 if ((!wd) || (!wd->src)) return NULL;
4657 return wd->src->name;
4661 * Set the source of the route.
4663 * @param clas the group class
4664 * @param source the new source
4669 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4671 ELM_CHECK_WIDTYPE(obj, widtype);
4672 Widget_Data *wd = elm_widget_data_get(obj);
4675 wd->route_source = source;
4679 * Get the current route source
4681 * @param obj the map object
4682 * @return Returns the source of the route
4686 EAPI Elm_Map_Route_Sources
4687 elm_map_route_source_get(const Evas_Object *obj)
4689 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4690 Widget_Data *wd = elm_widget_data_get(obj);
4692 if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4693 return wd->route_source;
4697 * Set the maximum zoom of the source.
4699 * @param source the source
4704 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4706 ELM_CHECK_WIDTYPE(obj, widtype);
4707 Widget_Data *wd = elm_widget_data_get(obj);
4709 if ((!wd) || (!wd->src)) return;
4710 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4711 wd->src->zoom_max = zoom;
4715 * Get the maximum zoom of the source.
4717 * @param source the source
4718 * @return Returns the maximum zoom of the source
4723 elm_map_source_zoom_max_get(const Evas_Object *obj)
4725 ELM_CHECK_WIDTYPE(obj, widtype) 18;
4726 Widget_Data *wd = elm_widget_data_get(obj);
4728 if ((!wd) || (!wd->src)) return 18;
4729 return wd->src->zoom_max;
4733 * Set the minimum zoom of the source.
4735 * @param source the source
4740 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4742 ELM_CHECK_WIDTYPE(obj, widtype);
4743 Widget_Data *wd = elm_widget_data_get(obj);
4745 if ((!wd) || (!wd->src)) return;
4746 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4747 wd->src->zoom_min = zoom;
4752 * Get the minimum zoom of the source.
4754 * @param source the source
4755 * @return Returns the minimum zoom of the source
4760 elm_map_source_zoom_min_get(const Evas_Object *obj)
4762 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4763 Widget_Data *wd = elm_widget_data_get(obj);
4765 if ((!wd) || (!wd->src)) return 0;
4766 return wd->src->zoom_min;
4770 * Set the user agent of the widget map.
4772 * @param obj The map object
4773 * @param user_agent the user agent of the widget map
4778 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4780 ELM_CHECK_WIDTYPE(obj, widtype);
4781 Widget_Data *wd = elm_widget_data_get(obj);
4784 if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4785 else eina_stringshare_replace(&wd->user_agent, user_agent);
4787 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4788 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4792 * Get the user agent of the widget map.
4794 * @param obj The map object
4795 * @return The user agent of the widget map
4800 elm_map_user_agent_get(const Evas_Object *obj)
4802 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4803 Widget_Data *wd = elm_widget_data_get(obj);
4805 if (!wd) return NULL;
4806 return wd->user_agent;
4810 * Add a route on the map
4812 * @param obj The map object
4813 * @param type the type if transport
4814 * @param method the routing method
4815 * @param flon the start longitude
4816 * @param flat the start latitude
4817 * @param tlon the destination longitude
4818 * @param tlat the destination latitude
4820 * @return The Route object
4824 EAPI Elm_Map_Route *
4825 elm_map_route_add(Evas_Object *obj,
4826 Elm_Map_Route_Type type,
4827 Elm_Map_Route_Method method,
4833 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4834 Widget_Data *wd = elm_widget_data_get(obj);
4837 char *type_name = NULL;
4840 if ((!wd) || (!wd->src)) return NULL;
4842 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4843 if (!route) return NULL;
4845 snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4853 route->con_url = ecore_con_url_new(NULL);
4854 route->ud.fname = strdup(buf);
4855 INF("xml file : %s", route->ud.fname);
4857 route->ud.fd = fdopen(fd, "w+");
4858 if ((!route->con_url) || (!route->ud.fd))
4860 ecore_con_url_free(route->con_url);
4866 route->color.r = 255;
4869 route->color.a = 255;
4870 route->handlers = eina_list_append
4871 (route->handlers, (void *)ecore_event_handler_add
4872 (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
4874 route->inbound = EINA_FALSE;
4876 route->method = method;
4884 case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4885 type_name = strdup(ROUTE_TYPE_MOTORCAR);
4887 case ELM_MAP_ROUTE_TYPE_BICYCLE:
4888 type_name = strdup(ROUTE_TYPE_BICYCLE);
4890 case ELM_MAP_ROUTE_TYPE_FOOT:
4891 type_name = strdup(ROUTE_TYPE_FOOT);
4897 source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4898 INF("route url = %s", source);
4900 wd->route = eina_list_append(wd->route, route);
4902 ecore_con_url_url_set(route->con_url, source);
4903 ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4904 ecore_con_url_data_set(route->con_url, route);
4905 ecore_con_url_get(route->con_url);
4906 if (type_name) free(type_name);
4907 if (source) free(source);
4909 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4910 "elm,state,busy,start", "elm");
4911 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4917 * Remove a route from the map
4919 * @param route The route to remove
4925 elm_map_route_remove(Elm_Map_Route *route)
4927 EINA_SAFETY_ON_NULL_RETURN(route);
4932 Ecore_Event_Handler *h;
4934 EINA_LIST_FREE(route->path, p)
4939 EINA_LIST_FREE(route->waypoint, w)
4941 if (w->point) eina_stringshare_del(w->point);
4945 EINA_LIST_FREE(route->nodes, n)
4947 if (n->pos.address) eina_stringshare_del(n->pos.address);
4951 EINA_LIST_FREE(route->handlers, h)
4953 ecore_event_handler_del(h);
4956 if (route->ud.fname)
4958 ecore_file_remove(route->ud.fname);
4959 free(route->ud.fname);
4960 route->ud.fname = NULL;
4965 * Set the option used for the background color
4967 * @param route The route object
4973 * This sets the color used for the route
4978 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4980 EINA_SAFETY_ON_NULL_RETURN(route);
4988 * Get the option used for the background color
4990 * @param route The route object
4999 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
5001 EINA_SAFETY_ON_NULL_RETURN(route);
5002 if (r) *r = route->color.r;
5003 if (g) *g = route->color.g;
5004 if (b) *b = route->color.b;
5005 if (a) *a = route->color.a;
5009 * Get the information of route distance
5011 * @param route the route object
5012 * @return Returns the distance of route (unit : km)
5017 elm_map_route_distance_get(const Elm_Map_Route *route)
5019 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
5020 return route->info.distance;
5024 * Get the information of route nodes
5026 * @param route the route object
5027 * @return Returns the nodes of route
5033 elm_map_route_node_get(const Elm_Map_Route *route)
5035 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5036 return route->info.nodes;
5040 * Get the information of route waypoint
5042 * @param route the route object
5043 * @return Returns the waypoint of route
5049 elm_map_route_waypoint_get(const Elm_Map_Route *route)
5051 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5052 return route->info.waypoints;
5056 * Get the information of address
5058 * @param name the name object
5059 * @return Returns the address of name
5064 elm_map_name_address_get(const Elm_Map_Name *name)
5066 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
5067 return name->address;
5071 * Get the current coordinates of the name.
5073 * This gets the current coordinates of the name object.
5075 * @param obj The name object
5076 * @param lat The latitude
5077 * @param lon The longitude
5082 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
5084 EINA_SAFETY_ON_NULL_RETURN(name);
5085 if (lon) *lon = name->lon;
5086 if (lat) *lat = name->lat;
5090 * Remove a name from the map
5092 * @param name The name to remove
5097 elm_map_name_remove(Elm_Map_Name *name)
5099 EINA_SAFETY_ON_NULL_RETURN(name);
5102 free(name->address);
5103 name->address = NULL;
5107 ecore_event_handler_del(name->handler);
5108 name->handler = NULL;
5112 ecore_file_remove(name->ud.fname);
5113 free(name->ud.fname);
5114 name->ud.fname = NULL;
5119 * Set the rotate degree of the map
5121 * @param obj The map object
5122 * @param angle amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5123 * @param cx rotation's center horizontal position
5124 * @param cy rotation's center vertical position
5129 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
5131 ELM_CHECK_WIDTYPE(obj, widtype);
5132 Widget_Data *wd = elm_widget_data_get(obj);
5135 wd->rotate.d = degree;
5138 wd->calc_job = ecore_job_add(_calc_job, wd);
5142 * Get the rotate degree of the map
5144 * @param obj The map object
5145 * @return amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5146 * @param cx rotation's center horizontal position
5147 * @param cy rotation's center vertical position
5152 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
5154 ELM_CHECK_WIDTYPE(obj, widtype);
5155 Widget_Data *wd = elm_widget_data_get(obj);
5158 if (degree) *degree = wd->rotate.d;
5159 if (cx) *cx = wd->rotate.cx;
5160 if (cy) *cy = wd->rotate.cy;
5164 * Set the wheel control state of the map
5166 * @param obj The map object
5167 * @param disabled status of wheel control
5172 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
5174 ELM_CHECK_WIDTYPE(obj, widtype);
5175 Widget_Data *wd = elm_widget_data_get(obj);
5178 if ((!wd->wheel_disabled) && (disabled))
5179 evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5180 else if ((wd->wheel_disabled) && (!disabled))
5181 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5182 wd->wheel_disabled = !!disabled;
5186 * Get the wheel control state of the map
5188 * @param obj The map object
5189 * @return Returns the status of wheel control
5194 elm_map_wheel_disabled_get(const Evas_Object *obj)
5196 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5197 Widget_Data *wd = elm_widget_data_get(obj);
5199 if (!wd) return EINA_FALSE;
5200 return wd->wheel_disabled;
5205 * Add a track on the map
5207 * @param obj The map object
5208 * @param emap the emap object
5210 * @return The Route object. This is a elm object of type Elm_Route
5215 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
5217 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5218 Widget_Data *wd = elm_widget_data_get(obj);
5220 if (!wd) return EINA_FALSE;
5222 Evas_Object *route = elm_route_add(obj);
5223 elm_route_emap_set(route, emap);
5224 wd->track = eina_list_append(wd->track, route);
5232 * Remove a track from the map
5234 * @param track The track to remove
5240 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
5242 ELM_CHECK_WIDTYPE(obj, widtype) ;
5243 Widget_Data *wd = elm_widget_data_get(obj);
5247 wd->track = eina_list_remove(wd->track, route);
5248 evas_object_del(route);
5252 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5255 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
5261 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5264 snprintf(buf, sizeof(buf),
5265 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
5271 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5274 snprintf(buf, sizeof(buf),
5275 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
5281 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5284 snprintf(buf, sizeof(buf),
5285 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
5290 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5293 snprintf(buf, sizeof(buf),
5294 "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
5295 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
5300 // TODO: fix monav api
5302 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5305 snprintf(buf, sizeof(buf),
5306 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5307 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
5313 // TODO: fix ors api
5315 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5318 snprintf(buf, sizeof(buf),
5319 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5320 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
5327 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
5329 ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
5330 Widget_Data *wd = elm_widget_data_get(obj);
5332 unsigned int ele, idx;
5333 char search_url[PATH_MAX];
5336 if (!wd) return strdup("");
5337 if (method == ELM_MAP_NAME_METHOD_SEARCH)
5339 search_url[0] = '\0';
5340 str = eina_str_split_full(name, " ", 0, &ele);
5341 for (idx = 0 ; idx < ele ; idx++)
5343 eina_strlcat(search_url, str[idx], sizeof(search_url));
5344 if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
5346 snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
5348 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);
5349 else strcpy(buf, "");