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.1
105 #define PINCH_ZOOM_MAX 5.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);
804 evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
805 evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
806 evas_object_map_enable_set(obj, EINA_TRUE);
807 evas_object_map_set(obj, wd->map);
812 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)
814 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__)
818 ELM_CHECK_WIDTYPE(obj, widtype);
819 Widget_Data *wd = elm_widget_data_get(obj);
822 int xmin, xmax, ymin, ymax;
825 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
827 EINA_LIST_FOREACH(wd->track, l, route)
829 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
830 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
832 if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
834 if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
837 evas_object_move(route, xmin - px + ox, ymin - py + oy);
838 evas_object_resize(route, xmax - xmin, ymax - ymin);
840 evas_object_raise(route);
841 obj_rotate_zoom(obj, route);
842 evas_object_show(route);
847 //the route is not display
848 evas_object_hide(route);
853 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)
855 ELM_CHECK_WIDTYPE(obj, widtype);
856 Widget_Data *wd = elm_widget_data_get(obj);
857 Eina_List *lr, *lp, *ln;
866 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
868 EINA_LIST_FOREACH(wd->route, lr, r)
870 EINA_LIST_FOREACH(r->path, lp, p)
872 evas_object_polygon_points_clear(p);
875 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
876 nodes = eina_list_count(r->nodes);
878 EINA_LIST_FOREACH(r->nodes, ln, n)
880 if ((!wd->zoom) || ((n->idx) &&
881 ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
884 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
885 if ((x >= px - ow) && (x <= (px + ow*2)) &&
886 (y >= py - oh) && (y <= (py + oh*2)))
891 p = eina_list_nth(r->path, n->idx);
892 a = (double)(y - r->y) / (double)(x - r->x);
893 if ((abs(a) >= 1) || (r->x == x))
895 evas_object_polygon_point_add(p, r->x - 3, r->y);
896 evas_object_polygon_point_add(p, r->x + 3, r->y);
897 evas_object_polygon_point_add(p, x + 3, y);
898 evas_object_polygon_point_add(p, x - 3, y);
902 evas_object_polygon_point_add(p, r->x, r->y - 3);
903 evas_object_polygon_point_add(p, r->x, r->y + 3);
904 evas_object_polygon_point_add(p, x, y + 3);
905 evas_object_polygon_point_add(p, x, y - 3);
908 evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
909 evas_object_raise(p);
910 obj_rotate_zoom(obj, p);
915 else r->inbound = EINA_FALSE;
919 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
920 if ((x >= px - ow) && (x <= (px + ow*2)) &&
921 (y >= py - oh) && (y <= (py + oh*2)))
925 r->inbound = EINA_TRUE;
927 else r->inbound = EINA_FALSE;
930 r->inbound = EINA_FALSE;
935 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
937 ELM_CHECK_WIDTYPE(obj, widtype);
938 Widget_Data *wd = elm_widget_data_get(obj);
939 Evas_Coord ax, ay, gw, gh, hh, ww;
942 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
949 if ((ww == gw) && (hh == gh)) return;
951 if (ow > gw) ax = (ow - gw) / 2;
952 if (oh > gh) ay = (oh - gh) / 2;
953 evas_object_move(wd->rect,
956 evas_object_resize(wd->rect, gw, gh);
960 wd->show.show = EINA_FALSE;
961 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
966 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)
968 ELM_CHECK_WIDTYPE(obj, widtype);
969 Widget_Data *wd = elm_widget_data_get(obj);
970 Evas_Coord ax, ay, gw, gh, tx, ty;
971 Eina_List *l, *markers;
972 Eina_Matrixsparse_Cell *cell;
977 int g_xx, g_yy, g_hh, g_ww;
980 if (g != eina_list_data_get(wd->grids)) return;
986 if (ow > gw) ax = (ow - gw) / 2;
987 if (oh > gh) ay = (oh - gh) / 2;
989 if (wd->zoom != wd->marker_zoom)
991 EINA_LIST_FREE(wd->cells_displayed, cell)
993 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
995 if (group->obj) _group_object_free(group);
999 wd->marker_zoom = wd->zoom;
1001 if ((wd->paused_markers)
1002 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
1005 g_xx = wd->pan_x / wd->tsize;
1006 if (g_xx < 0) g_xx = 0;
1007 g_yy = wd->pan_y / wd->tsize;
1008 if (g_yy < 0) g_yy = 0;
1009 g_ww = (ow / wd->tsize) + 1;
1010 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
1011 g_hh = (oh / wd->tsize) + 1;
1012 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
1014 //hide groups no more displayed
1015 EINA_LIST_FREE(wd->cells_displayed, cell)
1017 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
1018 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
1020 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1022 if (group->obj) _group_object_free(group);
1027 if (!wd->marker_zoom)
1033 for (y = g_yy; y <= g_yy + g_hh; y++)
1035 for (x = g_xx; x <= g_xx + g_ww; x++)
1037 if (!wd->markers[wd->zoom]) continue;
1038 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1039 if (!cell) continue;
1040 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1041 markers = eina_matrixsparse_cell_data_get(cell);
1042 EINA_LIST_FOREACH(markers, l, group)
1044 if (!group->markers) continue;
1045 if (group->clas->zoom_displayed > wd->zoom) continue;
1052 if (eina_list_count(group->markers) == 1)
1054 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1055 ww = m->clas->priv.edje_w;
1056 hh = m->clas->priv.edje_h;
1059 if (ww <= 0) ww = 1;
1060 if (hh <= 0) hh = 1;
1062 if ((gw != g->w) && (g->w > 0))
1065 xx = ((long long )gw * xx) / g->w;
1066 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1068 if ((gh != g->h) && (g->h > 0))
1071 yy = ((long long)gh * yy) / g->h;
1072 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1075 if ((!group->clas->hide)
1076 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1077 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1079 if (!group->obj) _group_object_create(group);
1081 if (group->update_nbelems)
1083 group->update_nbelems = EINA_FALSE;
1084 if (eina_list_count(group->markers) > 1)
1086 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1087 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1090 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1092 evas_object_move(group->obj,
1093 xx - px + ax + ox - ww/2,
1094 yy - py + ay + oy - hh/2);
1095 if ((!wd->paused_markers) || (group->update_resize))
1097 group->update_resize = EINA_FALSE;
1098 evas_object_resize(group->obj, ww, hh);
1099 obj_rotate_zoom(obj, group->obj);
1101 if (group->update_raise)
1103 group->update_raise = EINA_FALSE;
1104 evas_object_raise(group->obj);
1105 obj_rotate_zoom(obj, group->obj);
1106 evas_object_show(group->obj);
1108 if (group->bubble) _group_bubble_place(group);
1110 else if (group->obj)
1112 _group_object_free(group);
1120 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)
1122 ELM_CHECK_WIDTYPE(obj, widtype);
1123 Widget_Data *wd = elm_widget_data_get(obj);
1124 Evas_Coord ax, ay, gw, gh, tx, ty;
1132 if (ow > gw) ax = (ow - gw) / 2;
1133 if (oh > gh) ay = (oh - gh) / 2;
1135 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1136 Eina_Matrixsparse_Cell *cell;
1138 EINA_ITERATOR_FOREACH(it, cell)
1140 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1146 if ((gw != g->w) && (g->w > 0))
1149 xx = ((long long )gw * xx) / g->w;
1150 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1152 if ((gh != g->h) && (g->h > 0))
1155 yy = ((long long)gh * yy) / g->h;
1156 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1158 evas_object_move(gi->img,
1162 evas_object_resize(gi->img, ww, hh);
1164 obj_rotate_zoom(obj, gi->img);
1165 /*evas_object_move(gi->txt,
1169 evas_object_resize(gi->txt, ww, hh);
1172 eina_iterator_free(it);
1176 grid_clear(Evas_Object *obj, Grid *g)
1178 ELM_CHECK_WIDTYPE(obj, widtype);
1179 Widget_Data *wd = elm_widget_data_get(obj);
1183 if (!g->grid) return;
1185 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1186 Eina_Matrixsparse_Cell *cell;
1188 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1189 ecore_file_recursive_rm(buf);
1191 EINA_ITERATOR_FOREACH(it, cell)
1193 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1194 evas_object_del(gi->img);
1195 //evas_object_del(gi->txt);
1199 gi->want = EINA_FALSE;
1201 if (!wd->preload_num)
1203 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1204 "elm,state,busy,stop", "elm");
1205 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
1211 DBG("DOWNLOAD abort %s", gi->file);
1212 ecore_file_download_abort(gi->job);
1213 ecore_file_remove(gi->file);
1218 eina_stringshare_del(gi->file);
1222 eina_matrixsparse_free(g->grid);
1223 eina_iterator_free(it);
1230 _tile_update(Grid_Item *gi)
1232 gi->want = EINA_FALSE;
1233 gi->download = EINA_FALSE;
1234 evas_object_image_file_set(gi->img, gi->file, NULL);
1235 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1236 ecore_file_remove(gi->file);
1238 obj_rotate_zoom(gi->wd->obj, gi->img);
1239 evas_object_show(gi->img);
1241 //evas_object_text_text_set(gi->txt, gi->file);
1242 //evas_object_show(gi->txt);
1244 gi->have = EINA_TRUE;
1245 gi->wd->preload_num--;
1246 if (!gi->wd->preload_num)
1248 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1249 "elm,state,busy,stop", "elm");
1250 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1256 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1258 Grid_Item *gi = data;
1260 gi->download = EINA_FALSE;
1263 DBG("DOWNLOAD done %s", gi->file);
1264 if ((gi->want) && (!status)) _tile_update(gi);
1268 DBG("Download failed %s (%d) ", gi->file, status);
1269 ecore_file_remove(gi->file);
1272 gi->wd->finish_num++;
1274 evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1278 grid_create(Evas_Object *obj)
1280 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1281 Widget_Data *wd = elm_widget_data_get(obj);
1284 if ((!wd) || (!wd->src)) return NULL;
1285 g = calloc(1, sizeof(Grid));
1288 g->tsize = wd->tsize;
1291 if (g->zoom > wd->src->zoom_max) return NULL;
1292 if (g->zoom < wd->src->zoom_min) return NULL;
1294 int size = pow(2.0, wd->zoom);
1298 g->w = g->tsize * g->gw;
1299 g->h = g->tsize * g->gh;
1301 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1307 grid_load(Evas_Object *obj, Grid *g)
1309 ELM_CHECK_WIDTYPE(obj, widtype);
1310 Widget_Data *wd = elm_widget_data_get(obj);
1313 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1315 Eina_Matrixsparse_Cell *cell;
1318 if ((!wd) || (!wd->src)) return;
1319 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1320 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1325 if ((gw <= 0) || (gh <= 0)) return;
1328 if ((gw != g->w) && (g->w > 0))
1329 size = ((long long)gw * size) / g->w;
1330 if (size < (g->tsize / 2)) return; // else we will load to much tiles
1332 it = eina_matrixsparse_iterator_new(g->grid);
1334 EINA_ITERATOR_FOREACH(it, cell)
1336 gi = eina_matrixsparse_cell_data_get(cell);
1343 if ((gw != g->w) && (g->w > 0))
1346 xx = ((long long )gw * xx) / g->w;
1347 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1349 if ((gh != g->h) && (g->h > 0))
1352 yy = ((long long)gh * yy) / g->h;
1353 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1356 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1357 yy - wd->pan_y + oy,
1359 cvx, cvy, cvw, cvh))
1363 evas_object_hide(gi->img);
1364 //evas_object_hide(gi->txt);
1365 evas_object_image_file_set(gi->img, NULL, NULL);
1366 gi->want = EINA_FALSE;
1367 gi->have = EINA_FALSE;
1371 DBG("DOWNLOAD abort %s", gi->file);
1372 ecore_file_download_abort(gi->job);
1373 ecore_file_remove(gi->file);
1377 gi->download = EINA_FALSE;
1379 if (!wd->preload_num)
1381 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1382 "elm,state,busy,stop", "elm");
1383 evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
1390 evas_object_hide(gi->img);
1391 //evas_object_hide(gi->txt);
1392 evas_object_image_preload(gi->img, 1);
1393 evas_object_image_file_set(gi->img, NULL, NULL);
1394 gi->have = EINA_FALSE;
1395 gi->want = EINA_FALSE;
1399 eina_iterator_free(it);
1401 xx = wd->pan_x / size - 1;
1404 yy = wd->pan_y / size - 1;
1408 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1411 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1413 for (y = yy; y <= yy + hh; y++)
1415 for (x = xx; x <= xx + ww; x++)
1417 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1419 if ((!gi) && (g != eina_list_data_get(wd->grids)))
1424 gi = calloc(1, sizeof(Grid_Item));
1425 gi->src.x = x * g->tsize;
1426 gi->src.y = y * g->tsize;
1427 gi->src.w = g->tsize;
1428 gi->src.h = g->tsize;
1430 gi->out.x = gi->src.x;
1431 gi->out.y = gi->src.y;
1432 gi->out.w = gi->src.w;
1433 gi->out.h = gi->src.h;
1437 gi->img = evas_object_image_add(evas_object_evas_get(obj));
1438 evas_object_image_scale_hint_set
1439 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1440 evas_object_image_filled_set(gi->img, 1);
1442 evas_object_smart_member_add(gi->img, wd->pan_smart);
1443 elm_widget_sub_object_add(obj, gi->img);
1444 evas_object_pass_events_set(gi->img, EINA_TRUE);
1445 evas_object_stack_below(gi->img, wd->sep_maps_markers);
1447 /* gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1448 evas_object_text_font_set(gi->txt, "Vera", 12);
1449 evas_object_color_set(gi->txt, 100, 100, 100, 255);
1450 evas_object_smart_member_add(gi->txt,
1452 elm_widget_sub_object_add(obj, gi->txt);
1453 evas_object_pass_events_set(gi->txt, EINA_TRUE);
1455 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1458 if ((!gi->have) && (!gi->download))
1460 char buf[PATH_MAX], buf2[PATH_MAX];
1463 gi->want = EINA_TRUE;
1465 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1466 if (!ecore_file_exists(buf))
1467 ecore_file_mkpath(buf);
1469 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1471 source = wd->src->url_cb(obj, x, y, g->zoom);
1472 if ((!source) || (strlen(source)==0)) continue;
1474 eina_stringshare_replace(&gi->file, buf2);
1476 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1478 gi->download = EINA_TRUE;
1480 if (wd->preload_num == 1)
1482 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1483 "elm,state,busy,start", "elm");
1484 evas_object_smart_callback_call(obj,
1489 if (ecore_file_exists(buf2))
1493 DBG("DOWNLOAD %s \t in %s", source, buf2);
1494 ecore_file_download_full(source, buf2, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1496 DBG("Can't start to download %s", buf);
1501 if (source) free(source);
1505 obj_rotate_zoom(obj, gi->img);
1506 evas_object_show(gi->img);
1513 grid_clearall(Evas_Object *obj)
1515 ELM_CHECK_WIDTYPE(obj, widtype);
1516 Widget_Data *wd = elm_widget_data_get(obj);
1520 EINA_LIST_FREE(wd->grids, g)
1528 _smooth_update(Evas_Object *obj)
1530 ELM_CHECK_WIDTYPE(obj, widtype);
1531 Widget_Data *wd = elm_widget_data_get(obj);
1536 EINA_LIST_FOREACH(wd->grids, l, g)
1538 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1539 Eina_Matrixsparse_Cell *cell;
1541 EINA_ITERATOR_FOREACH(it, cell)
1543 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1544 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1546 eina_iterator_free(it);
1551 _scr_timeout(void *data)
1553 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1554 Widget_Data *wd = elm_widget_data_get(data);
1556 if (!wd) return ECORE_CALLBACK_CANCEL;
1558 if (!wd->nosmooth) _smooth_update(data);
1559 wd->scr_timer = NULL;
1560 return ECORE_CALLBACK_CANCEL;
1564 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1566 ELM_CHECK_WIDTYPE(data, widtype);
1567 Widget_Data *wd = elm_widget_data_get(data);
1573 if (wd->nosmooth == 1) _smooth_update(data);
1575 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1576 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1580 zoom_do(Evas_Object *obj)
1582 ELM_CHECK_WIDTYPE(obj, widtype);
1583 Widget_Data *wd = elm_widget_data_get(obj);
1584 Evas_Coord xx, yy, ow, oh;
1587 wd->size.w = wd->size.nw;
1588 wd->size.h = wd->size.nh;
1590 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1592 if (wd->center_on.enabled)
1594 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1600 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1601 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1606 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1608 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1610 wd->show.show = EINA_TRUE;
1616 if (wd->calc_job) ecore_job_del(wd->calc_job);
1617 wd->calc_job = ecore_job_add(_calc_job, wd);
1621 _zoom_timeout(void *data)
1623 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1624 Widget_Data *wd = elm_widget_data_get(data);
1626 if (!wd) return ECORE_CALLBACK_CANCEL;
1627 wd->zoom_timer = NULL;
1628 wd->pinch.level = 1.0;
1630 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1631 return ECORE_CALLBACK_CANCEL;
1635 _zoom_anim(void *data)
1637 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1638 Evas_Object *obj = data;
1639 Widget_Data *wd = elm_widget_data_get(obj);
1641 if (!wd) return ECORE_CALLBACK_CANCEL;
1642 if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1643 else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1646 wd->zoom_animator = NULL;
1648 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1649 return ECORE_CALLBACK_CANCEL;
1654 wd->zoom_animator = NULL;
1655 wd->pinch.level = 2.0;
1656 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1657 wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1658 return ECORE_CALLBACK_CANCEL;
1660 else if (wd->t <= 0.5)
1662 wd->zoom_animator = NULL;
1663 wd->pinch.level = 0.5;
1664 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1665 wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1666 return ECORE_CALLBACK_CANCEL;
1668 else if (wd->t != 1.0)
1670 Evas_Coord x, y, w, h;
1671 float half_w, half_h;
1672 evas_object_geometry_get(data, &x, &y, &w, &h);
1673 half_w = (float)w * 0.5;
1674 half_h = (float)h * 0.5;
1675 wd->pinch.cx = x + half_w;
1676 wd->pinch.cy = y + half_h;
1677 wd->pinch.level = wd->t;
1678 if (wd->calc_job) ecore_job_del(wd->calc_job);
1679 wd->calc_job = ecore_job_add(_calc_job, wd);
1681 return ECORE_CALLBACK_RENEW;
1685 _long_press(void *data)
1687 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1688 Widget_Data *wd = elm_widget_data_get(data);
1690 if (!wd) return ECORE_CALLBACK_CANCEL;
1691 wd->long_timer = NULL;
1692 evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1693 return ECORE_CALLBACK_CANCEL;
1697 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1699 ELM_CHECK_WIDTYPE(data, widtype);
1700 Widget_Data *wd = elm_widget_data_get(data);
1701 Evas_Event_Mouse_Down *ev = event_info;
1705 ev0 = get_event_object(data, 0);
1707 ev0 = create_event_object(data, obj, 0);
1710 ev0->hold_timer = NULL;
1711 ev0->prev.x = ev->canvas.x;
1712 ev0->prev.y = ev->canvas.y;
1714 if (ev->button != 1) return;
1715 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1716 else wd->on_hold = EINA_FALSE;
1717 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1718 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1720 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1721 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1722 wd->ev.canvas.x = ev->output.x;
1723 wd->ev.canvas.y = ev->output.y;
1724 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1728 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1730 Evas_Event_Mouse_Move *move = event_info;
1733 ev0 = get_event_object(data, 0);
1735 ev0->prev.x = move->cur.canvas.x;
1736 ev0->prev.y = move->cur.canvas.y;
1740 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1742 ELM_CHECK_WIDTYPE(data, widtype);
1743 Widget_Data *wd = elm_widget_data_get(data);
1746 Evas_Event_Mouse_Up *ev = event_info;
1751 ev0 = get_event_object(data, 0);
1754 mdevice = get_multi_device(data);
1757 if (ev0->hold_timer)
1759 ecore_timer_del(ev0->hold_timer);
1760 ev0->hold_timer = NULL;
1762 elm_smart_scroller_hold_set(wd->scr, 0);
1763 elm_smart_scroller_freeze_set(wd->scr, 0);
1767 ev1 = get_event_object(data, mdevice);
1769 ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1771 destroy_event_object(data, ev0);
1774 if (ev->button != 1) return;
1775 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1776 else wd->on_hold = EINA_FALSE;
1779 ecore_timer_del(wd->long_timer);
1780 wd->long_timer = NULL;
1782 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1783 wd->on_hold = EINA_FALSE;
1787 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1789 ELM_CHECK_WIDTYPE(data, widtype);
1790 Widget_Data *wd = elm_widget_data_get(data);
1792 Evas_Event_Multi_Down *down = event_info;
1794 elm_smart_scroller_hold_set(wd->scr, 1);
1795 elm_smart_scroller_freeze_set(wd->scr, 1);
1797 ev = create_event_object(data, obj, down->device);
1800 DBG("Failed : create_event_object");
1805 ev->hold_timer = NULL;
1806 ev->start.x = ev->prev.x = down->canvas.x;
1807 ev->start.y = ev->prev.y = down->canvas.y;
1808 ev->pinch_start_dis = 0;
1809 wd->pinch.level = 1.0;
1810 wd->pinch.diff = 1.0;
1815 ecore_timer_del(wd->long_timer);
1816 wd->long_timer = NULL;
1822 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1824 ELM_CHECK_WIDTYPE(data, widtype);
1825 Widget_Data *wd = elm_widget_data_get(data);
1826 Evas_Event_Multi_Move *move = event_info;
1827 int dis_new, dx, dy;
1828 double t, tt, a, a_diff;
1832 if ((!wd) || (!wd->src)) return;
1833 ev = get_event_object(data, move->device);
1836 ev0 = get_event_object(data, 0);
1839 if (wd->multi_count >= 1)
1841 Evas_Coord x, y, w, h;
1842 float half_w, half_h;
1844 evas_object_geometry_get(data, &x, &y, &w, &h);
1845 half_w = (float)w * 0.5;
1846 half_h = (float)h * 0.5;
1847 dx = ev0->prev.x - ev->prev.x;
1848 dy = ev0->prev.y - ev->prev.y;
1849 dis_new = sqrt((dx * dx) + (dy * dy));
1851 if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1854 ev->pinch_dis = dis_new;
1855 tt = wd->pinch.diff;
1856 wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1857 t = (wd->pinch.diff * 0.01) + 1.0;
1858 if ((t > 1.1) || (wd->rotate.doing))
1860 if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1861 ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1862 (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1864 wd->pinch.diff = tt;
1869 wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1870 wd->pinch.cx = x + half_w;
1871 wd->pinch.cy = y + half_h;
1872 wd->pinch.doing = EINA_TRUE;
1873 if (!wd->rotate.doing) goto do_zoom_only;
1878 if (wd->pinch.doing) goto do_nothing;
1881 a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1882 if (!wd->rotate.a) wd->rotate.a = a;
1885 a_diff = wd->rotate.a - a;
1886 if (a_diff > 0) wd->rotate.d -= 1.0;
1887 else if (a_diff < 0) wd->rotate.d += 1.0;
1889 wd->rotate.cx = x + half_w;
1890 wd->rotate.cy = y + half_h;
1891 wd->rotate.doing = EINA_TRUE;
1894 if (wd->calc_job) ecore_job_del(wd->calc_job);
1895 wd->calc_job = ecore_job_add(_calc_job, wd);
1899 ev->prev.x = move->cur.canvas.x;
1900 ev->prev.y = move->cur.canvas.y;
1904 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1906 ELM_CHECK_WIDTYPE(data, widtype);
1907 Widget_Data *wd = elm_widget_data_get(data);
1908 Evas_Event_Multi_Up *up = event_info;
1915 if (wd->calc_job) ecore_job_del(wd->calc_job);
1916 if (wd->zoom_animator)
1918 ecore_animator_del(wd->zoom_animator);
1919 wd->zoom_animator = NULL;
1922 wd->paused = EINA_TRUE;
1923 if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1924 else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1925 elm_map_zoom_set(data, wd->zoom + zoom);
1926 wd->pinch.level = 1.0;
1927 wd->pinch.doing = EINA_FALSE;
1930 wd->rotate.doing = EINA_FALSE;
1932 ev = get_event_object(data, up->device);
1935 DBG("Cannot get multi device");
1939 ev0 = get_event_object(data, 0);
1941 ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1946 ecore_timer_del(ev->hold_timer);
1947 ev->hold_timer = NULL;
1950 destroy_event_object(data, ev);
1954 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1956 ELM_CHECK_WIDTYPE(data, widtype);
1957 Widget_Data *wd = elm_widget_data_get(data);
1958 Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1959 Evas_Coord x, y, w, h;
1960 float half_w, half_h;
1963 evas_object_geometry_get(data, &x, &y, &w, &h);
1964 half_w = (float)w * 0.5;
1965 half_h = (float)h * 0.5;
1967 if (!wd->wheel_zoom) wd->wheel_zoom = 1.0;
1970 wd->zoom_method = ZOOM_METHOD_OUT;
1971 wd->wheel_zoom -= 0.05;
1972 if (wd->wheel_zoom <= PINCH_ZOOM_MIN) wd->wheel_zoom = PINCH_ZOOM_MIN;
1976 wd->zoom_method = ZOOM_METHOD_IN;
1977 wd->wheel_zoom += 0.2;
1978 if (wd->wheel_zoom >= PINCH_ZOOM_MAX) wd->wheel_zoom = PINCH_ZOOM_MAX;
1983 wd->pinch.level = wd->wheel_zoom;
1984 wd->pinch.cx = x + half_w;
1985 wd->pinch.cy = y + half_h;
1986 if (wd->calc_job) ecore_job_del(wd->calc_job);
1987 wd->calc_job = ecore_job_add(_calc_job, wd);
1990 if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
1991 wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
1995 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
1998 _hold_timer_cb(void *data)
2002 ev0->hold_timer = NULL;
2003 return ECORE_CALLBACK_CANCEL;
2007 _wheel_timer_cb(void *data)
2009 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2010 Widget_Data *wd = elm_widget_data_get(data);
2015 wd->wheel_timer = NULL;
2016 return ECORE_CALLBACK_CANCEL;
2018 if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom - 1.0);
2019 else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor((-1.0 / wd->wheel_zoom) + 1.0);
2022 wd->wheel_timer = NULL;
2023 return ECORE_CALLBACK_CANCEL;
2025 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2026 elm_map_zoom_set(data, wd->zoom + zoom);
2027 wd->wheel_zoom = 0.0;
2028 wd->wheel_timer = NULL;
2029 return ECORE_CALLBACK_CANCEL;
2033 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2035 ELM_CHECK_WIDTYPE(data, widtype);
2036 Widget_Data *wd = elm_widget_data_get(data);
2039 evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2040 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2041 evas_object_resize(wd->rect, w, h);
2042 evas_object_move(wd->rect, x, y);
2046 _del_hook(Evas_Object *obj)
2048 ELM_CHECK_WIDTYPE(obj, widtype);
2049 Widget_Data *wd = elm_widget_data_get(obj);
2050 Elm_Map_Group_Class *group_clas;
2051 Elm_Map_Marker_Class *marker_clas;
2057 Ecore_Event_Handler *h;
2063 EINA_LIST_FREE(wd->groups_clas, group_clas)
2065 if (group_clas->style)
2066 eina_stringshare_del(group_clas->style);
2070 EINA_LIST_FREE(wd->markers_clas, marker_clas)
2072 if (marker_clas->style)
2073 eina_stringshare_del(marker_clas->style);
2077 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2079 destroy_event_object(obj, ev);
2082 EINA_LIST_FOREACH(wd->route, l, r)
2084 EINA_LIST_FREE(r->path, p)
2089 EINA_LIST_FREE(r->waypoint, w)
2091 if (w->point) eina_stringshare_del(w->point);
2095 EINA_LIST_FREE(r->nodes, n)
2097 if (n->pos.address) eina_stringshare_del(n->pos.address);
2101 EINA_LIST_FREE(r->handlers, h)
2103 ecore_event_handler_del(h);
2106 if (r->con_url) ecore_con_url_free(r->con_url);
2107 if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2108 if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2111 EINA_LIST_FREE(wd->names, na)
2113 if (na->address) free(na->address);
2114 if (na->handler) ecore_event_handler_del(na->handler);
2117 ecore_file_remove(na->ud.fname);
2119 na->ud.fname = NULL;
2123 EINA_LIST_FREE(wd->track, route)
2125 evas_object_del(route);
2128 if (wd->map) evas_map_free(wd->map);
2129 if (wd->source_names) free(wd->source_names);
2130 if (wd->calc_job) ecore_job_del(wd->calc_job);
2131 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2132 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2133 if (wd->long_timer) ecore_timer_del(wd->long_timer);
2134 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2135 if (wd->ua) eina_hash_free(wd->ua);
2136 if (wd->markers) free(wd->markers);
2142 _del_pre_hook(Evas_Object *obj)
2144 ELM_CHECK_WIDTYPE(obj, widtype);
2145 Widget_Data *wd = elm_widget_data_get(obj);
2146 Marker_Group *group;
2147 Elm_Map_Marker *marker;
2149 Eina_Bool free_marker = EINA_TRUE;
2154 for (i = 0; i <= wd->zoom_max; i++)
2156 if (!wd->markers[i]) continue;
2157 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2158 Eina_Matrixsparse_Cell *cell;
2160 EINA_ITERATOR_FOREACH(it, cell)
2162 l = eina_matrixsparse_cell_data_get(cell);
2163 EINA_LIST_FREE(l, group)
2165 EINA_LIST_FREE(group->markers, marker)
2167 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2168 _bubble_sc_hits_changed_cb, group);
2169 if (free_marker) free(marker);
2173 free_marker = EINA_FALSE;
2175 eina_iterator_free(it);
2176 eina_matrixsparse_free(wd->markers[i]);
2179 evas_object_del(wd->sep_maps_markers);
2180 evas_object_del(wd->pan_smart);
2181 wd->pan_smart = NULL;
2185 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2187 ELM_CHECK_WIDTYPE(obj, widtype);
2188 Widget_Data *wd = elm_widget_data_get(obj);
2191 if (elm_widget_focus_get(obj))
2193 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2194 evas_object_focus_set(wd->obj, EINA_TRUE);
2198 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2199 evas_object_focus_set(wd->obj, EINA_FALSE);
2204 _theme_hook(Evas_Object *obj)
2206 ELM_CHECK_WIDTYPE(obj, widtype);
2207 Widget_Data *wd = elm_widget_data_get(obj);
2210 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2211 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2216 _sizing_eval(Evas_Object *obj)
2218 ELM_CHECK_WIDTYPE(obj, widtype);
2219 Widget_Data *wd = elm_widget_data_get(obj);
2220 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2223 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2224 evas_object_size_hint_min_set(obj, minw, minh);
2225 evas_object_size_hint_max_set(obj, maxw, maxh);
2229 _calc_job(void *data)
2231 Widget_Data *wd = data;
2232 Evas_Coord minw, minh;
2239 wd->resized = EINA_FALSE;
2240 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2242 double tz = wd->zoom;
2244 elm_map_zoom_set(wd->obj, tz);
2247 if ((minw != wd->minw) || (minh != wd->minh))
2251 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2252 _sizing_eval(wd->obj);
2254 wd->calc_job = NULL;
2255 evas_object_smart_changed(wd->pan_smart);
2259 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2261 Pan *sd = evas_object_smart_data_get(obj);
2263 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2266 evas_object_smart_changed(obj);
2270 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2272 Pan *sd = evas_object_smart_data_get(obj);
2274 if (x) *x = sd->wd->pan_x;
2275 if (y) *y = sd->wd->pan_y;
2279 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2281 Pan *sd = evas_object_smart_data_get(obj);
2284 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2285 ow = sd->wd->minw - ow;
2287 oh = sd->wd->minh - oh;
2294 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2301 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2303 Pan *sd = evas_object_smart_data_get(obj);
2305 if (w) *w = sd->wd->minw;
2306 if (h) *h = sd->wd->minh;
2310 _pan_add(Evas_Object *obj)
2313 Evas_Object_Smart_Clipped_Data *cd;
2315 cd = evas_object_smart_data_get(obj);
2317 sd = calloc(1, sizeof(Pan));
2319 sd->__clipped_data = *cd;
2321 evas_object_smart_data_set(obj, sd);
2325 _pan_del(Evas_Object *obj)
2327 Pan *sd = evas_object_smart_data_get(obj);
2333 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2335 Pan *sd = evas_object_smart_data_get(obj);
2338 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2339 if ((ow == w) && (oh == h)) return;
2340 sd->wd->resized = EINA_TRUE;
2341 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2342 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2346 _pan_calculate(Evas_Object *obj)
2348 Pan *sd = evas_object_smart_data_get(obj);
2349 Evas_Coord ox, oy, ow, oh;
2353 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2354 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2355 EINA_LIST_FOREACH(sd->wd->grids, l, g)
2357 if ((sd->wd->pinch.level == 1.0) || (sd->wd->pinch.level == 0.5)) grid_load(sd->wd->obj, g);
2358 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2359 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2360 if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2361 if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2366 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2368 Pan *sd = evas_object_smart_data_get(obj);
2370 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2371 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2375 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2377 ELM_CHECK_WIDTYPE(obj, widtype);
2378 Widget_Data *wd = elm_widget_data_get(obj);
2381 elm_smart_scroller_hold_set(wd->scr, 1);
2385 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2387 ELM_CHECK_WIDTYPE(obj, widtype);
2388 Widget_Data *wd = elm_widget_data_get(obj);
2391 elm_smart_scroller_hold_set(wd->scr, 0);
2395 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2397 ELM_CHECK_WIDTYPE(obj, widtype);
2398 Widget_Data *wd = elm_widget_data_get(obj);
2401 elm_smart_scroller_freeze_set(wd->scr, 1);
2405 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2407 ELM_CHECK_WIDTYPE(obj, widtype);
2408 Widget_Data *wd = elm_widget_data_get(obj);
2411 elm_smart_scroller_freeze_set(wd->scr, 0);
2415 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2417 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2421 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2423 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2427 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2429 Widget_Data *wd = elm_widget_data_get(data);
2430 wd->center_on.enabled = EINA_FALSE;
2431 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2435 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2437 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2441 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2443 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2448 _group_object_create(Marker_Group *group)
2450 const char *style = "radio";
2451 Evas_Object *icon = NULL;
2453 if (group->obj) return;
2454 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2456 //set icon and style
2457 if (eina_list_count(group->markers) == 1)
2459 Elm_Map_Marker *m = eina_list_data_get(group->markers);
2461 style = m->clas->style;
2463 if (m->clas->func.icon_get)
2464 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2466 group->delete_object = EINA_TRUE;
2470 if (group->clas->style)
2471 style = group->clas->style;
2473 if (group->clas->func.icon_get)
2474 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2476 group->delete_object = EINA_FALSE;
2479 group->obj = elm_layout_add(group->wd->obj);
2480 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2482 if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
2484 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2485 elm_widget_sub_object_add(group->wd->obj, group->obj);
2486 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2488 if (!group->delete_object)
2489 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2493 group->delete_object = EINA_FALSE;
2495 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2496 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2497 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2498 evas_object_show(group->obj);
2501 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2502 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2504 group->update_nbelems = EINA_TRUE;
2505 group->update_resize = EINA_TRUE;
2506 group->update_raise = EINA_TRUE;
2508 if (group->open) _group_bubble_create(group);
2512 _group_object_free(Marker_Group *group)
2514 if (!group->obj) return;
2515 if (!group->delete_object)
2517 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2518 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2519 evas_object_hide(group->obj);
2521 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2522 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2525 evas_object_del(group->obj);
2528 _group_bubble_free(group);
2532 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2534 Marker_Group *group = data;
2536 if (!evas_object_above_get(group->rect)) return;
2537 evas_object_raise(group->bubble);
2538 evas_object_raise(group->sc);
2539 evas_object_raise(group->rect);
2543 _group_bubble_create(Marker_Group *group)
2545 if (group->bubble) return;
2547 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2548 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2549 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2550 elm_widget_style_get(group->wd->obj));
2551 evas_object_smart_member_add(group->bubble,
2553 elm_widget_sub_object_add(group->wd->obj, group->bubble);
2555 _group_bubble_content_free(group);
2556 if (!_group_bubble_content_update(group))
2558 //no content, we can delete the bubble
2559 _group_bubble_free(group);
2563 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2564 evas_object_color_set(group->rect, 0, 0, 0, 0);
2565 evas_object_repeat_events_set(group->rect, EINA_TRUE);
2566 evas_object_smart_member_add(group->rect, group->wd->obj);
2567 elm_widget_sub_object_add(group->wd->obj, group->rect);
2569 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2571 _group_bubble_place(group);
2574 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2576 _group_bubble_place(data);
2580 _group_bubble_content_update(Marker_Group *group)
2583 Elm_Map_Marker *marker;
2586 if (!group->bubble) return 1;
2590 group->sc = elm_scroller_add(group->bubble);
2591 elm_widget_style_set(group->sc, "map_bubble");
2592 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2593 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2594 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2595 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2596 evas_object_show(group->sc);
2597 evas_object_smart_member_add(group->sc,
2599 elm_widget_sub_object_add(group->wd->obj, group->sc);
2601 group->bx = elm_box_add(group->bubble);
2602 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2603 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2604 elm_box_horizontal_set(group->bx, EINA_TRUE);
2605 evas_object_show(group->bx);
2607 elm_scroller_content_set(group->sc, group->bx);
2609 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
2610 _bubble_sc_hits_changed_cb, group);
2613 EINA_LIST_FOREACH(group->markers, l, marker)
2615 if (i >= group->wd->markers_max_num) break;
2616 if ((!marker->content) && (marker->clas->func.get))
2617 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2618 else if (marker->content)
2619 elm_box_unpack(group->bx, marker->content);
2620 if (marker->content)
2622 elm_box_pack_end(group->bx, marker->content);
2630 _group_bubble_content_free(Marker_Group *group)
2633 Elm_Map_Marker *marker;
2635 if (!group->sc) return;
2636 EINA_LIST_FOREACH(group->markers, l, marker)
2638 if ((marker->content) && (marker->clas->func.del))
2639 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2640 else if (marker->content)
2641 evas_object_del(marker->content);
2642 marker->content = NULL;
2644 evas_object_del(group->sc);
2649 _group_bubble_free(Marker_Group *group)
2651 if (!group->bubble) return;
2652 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2653 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2654 _bubble_sc_hits_changed_cb, group);
2655 evas_object_del(group->bubble);
2656 evas_object_del(group->rect);
2657 group->bubble = NULL;
2658 _group_bubble_content_free(group);
2662 _group_bubble_place(Marker_Group *group)
2665 Evas_Coord xx, yy, ww, hh;
2668 if ((!group->bubble) || (!group->obj)) return;
2670 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2671 edje_object_size_min_calc(group->bubble, NULL, &hh);
2673 s = edje_object_data_get(group->bubble, "size_w");
2674 if (s) ww = atoi(s);
2676 xx = x + w / 2 - ww / 2;
2679 evas_object_move(group->bubble, xx, yy);
2680 evas_object_resize(group->bubble, ww, hh);
2681 obj_rotate_zoom(group->wd, group->bubble);
2682 evas_object_show(group->bubble);
2684 evas_object_move(group->rect, xx, yy);
2685 evas_object_resize(group->rect, ww, hh);
2686 obj_rotate_zoom(group->wd, group->rect);
2687 evas_object_show(group->rect);
2691 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2693 Marker_Group *group = data;
2694 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2695 if (!marker) return;
2696 group->bringin = EINA_TRUE;
2697 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2701 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2703 Marker_Group *group = data;
2707 group->bringin = EINA_FALSE;
2713 group->open = EINA_FALSE;
2714 _group_bubble_free(group);
2717 group->open = EINA_TRUE;
2718 _group_bubble_create(group);
2722 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2724 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2725 Widget_Data *wd = elm_widget_data_get(obj);
2729 Evas_Coord step_x = 0;
2730 Evas_Coord step_y = 0;
2733 Evas_Coord page_x = 0;
2734 Evas_Coord page_y = 0;
2736 if (!wd) return EINA_FALSE;
2737 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2738 Evas_Event_Key_Down *ev = event_info;
2739 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2741 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2742 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2743 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2744 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2746 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2750 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2754 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2758 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2762 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2765 y -= -(page_y * v_h) / 100;
2769 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2772 y += -(page_y * v_h) / 100;
2776 else if (!strcmp(ev->keyname, "KP_Add"))
2778 zoom = elm_map_zoom_get(obj) + 1;
2779 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2780 elm_map_zoom_set(obj, zoom);
2783 else if (!strcmp(ev->keyname, "KP_Subtract"))
2785 zoom = elm_map_zoom_get(obj) - 1;
2786 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2787 elm_map_zoom_set(obj, zoom);
2790 else return EINA_FALSE;
2792 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2793 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2799 cb_dump_name_attrs(void *data, const char *key, const char *value)
2801 Name_Dump *dump = (Name_Dump*)data;
2802 if (!dump) return EINA_FALSE;
2804 if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2805 else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2812 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2814 Route_Dump *dump = data;
2815 if (!dump) return EINA_FALSE;
2819 case EINA_SIMPLE_XML_OPEN:
2820 case EINA_SIMPLE_XML_OPEN_EMPTY:
2824 attrs = eina_simple_xml_tag_attributes_find(value, length);
2827 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2828 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2829 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2830 else dump->id = ROUTE_XML_NONE;
2834 case EINA_SIMPLE_XML_DATA:
2836 char *buf = malloc(length);
2837 if (!buf) return EINA_FALSE;
2838 snprintf(buf, length, "%s", value);
2839 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2840 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2841 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2853 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2855 Name_Dump *dump = data;
2856 if (!dump) return EINA_FALSE;
2860 case EINA_SIMPLE_XML_OPEN:
2861 case EINA_SIMPLE_XML_OPEN_EMPTY:
2864 attrs = eina_simple_xml_tag_attributes_find(value, length);
2867 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2868 else dump->id = NAME_XML_NONE;
2870 eina_simple_xml_attributes_parse
2871 (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2875 case EINA_SIMPLE_XML_DATA:
2877 char *buf = malloc(length + 1);
2878 if (!buf) return EINA_FALSE;
2879 snprintf(buf, length + 1, "%s", value);
2880 if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2892 _parse_kml(void *data)
2894 Elm_Map_Route *r = (Elm_Map_Route*)data;
2895 if (!r && !r->ud.fname) return;
2899 unsigned int ele, idx;
2903 Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2905 f = fopen(r->ud.fname, "rb");
2910 fseek(f, 0, SEEK_END);
2916 fseek(f, 0, SEEK_SET);
2920 if (fread(buf, 1, sz, f))
2922 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
2929 if (dump.distance) r->info.distance = dump.distance;
2930 if (dump.description)
2932 eina_stringshare_replace(&r->info.waypoints, dump.description);
2933 str = eina_str_split_full(dump.description, "\n", 0, &ele);
2934 r->info.waypoint_count = ele;
2935 for (idx = 0 ; idx < ele ; idx++)
2937 Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
2941 wp->point = eina_stringshare_add(str[idx]);
2942 DBG("%s", str[idx]);
2943 r->waypoint = eina_list_append(r->waypoint, wp);
2952 else WRN("description is not found !");
2954 if (dump.coordinates)
2956 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2957 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2958 r->info.node_count = ele;
2959 for (idx = 0 ; idx < ele ; idx++)
2961 sscanf(str[idx], "%lf,%lf", &lon, &lat);
2962 Path_Node *n = ELM_NEW(Path_Node);
2969 DBG("%lf:%lf", lon, lat);
2970 n->pos.address = NULL;
2971 r->nodes = eina_list_append(r->nodes, n);
2973 path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
2974 evas_object_smart_member_add(path, r->wd->pan_smart);
2975 r->path = eina_list_append(r->path, path);
2988 _parse_name(void *data)
2990 Elm_Map_Name *n = (Elm_Map_Name*)data;
2991 if (!n && !n->ud.fname) return;
2995 Name_Dump dump = {0, NULL, 0.0, 0.0};
2997 f = fopen(n->ud.fname, "rb");
3002 fseek(f, 0, SEEK_END);
3008 fseek(f, 0, SEEK_SET);
3012 if (fread(buf, 1, sz, f))
3014 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3023 INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3024 n->address = strdup(dump.address);
3032 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3034 Ecore_Con_Event_Url_Complete *ev = event;
3035 Elm_Map_Route *r = (Elm_Map_Route*)data;
3036 Widget_Data *wd = r->wd;
3038 if ((!r) || (!ev)) return EINA_TRUE;
3039 Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3040 ecore_con_url_data_set(r->con_url, NULL);
3041 if (r!=rr) return EINA_TRUE;
3043 if (r->ud.fd) fclose(r->ud.fd);
3048 Evas_Coord ox, oy, ow, oh;
3049 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3050 route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3052 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3053 "elm,state,busy,stop", "elm");
3054 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3059 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3061 Ecore_Con_Event_Url_Complete *ev = event;
3062 Elm_Map_Name *n = (Elm_Map_Name*)data;
3063 Widget_Data *wd = n->wd;
3065 if ((!n) || (!ev)) return EINA_TRUE;
3066 Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3067 ecore_con_url_data_set(n->con_url, NULL);
3068 if (n!=nn) return EINA_TRUE;
3070 if (n->ud.fd) fclose(n->ud.fd);
3073 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3074 "elm,state,busy,stop", "elm");
3075 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3079 static Elm_Map_Name *
3080 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3082 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3083 Widget_Data *wd = elm_widget_data_get(obj);
3088 if ((!wd) || (!wd->src)) return NULL;
3089 Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3090 if (!name) return NULL;
3092 snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3100 name->con_url = ecore_con_url_new(NULL);
3101 name->ud.fname = strdup(buf);
3102 INF("xml file : %s", name->ud.fname);
3104 name->ud.fd = fdopen(fd, "w+");
3105 if ((!name->con_url) || (!name->ud.fd))
3107 ecore_con_url_free(name->con_url);
3113 name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3114 name->method = method;
3115 if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3116 else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3120 source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3121 INF("name url = %s", source);
3123 wd->names = eina_list_append(wd->names, name);
3124 ecore_con_url_url_set(name->con_url, source);
3125 ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3126 ecore_con_url_data_set(name->con_url, name);
3128 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3129 "elm,state,busy,start", "elm");
3130 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3131 ecore_con_url_get(name->con_url);
3132 if (source) free(source);
3138 static int idnum = 1;
3141 * Add a new Map object
3143 * @param parent The parent object
3144 * @return The new object or NULL if it cannot be created
3149 elm_map_add(Evas_Object *parent)
3153 Evas_Coord minw, minh;
3155 static Evas_Smart *smart = NULL;
3156 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3158 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3160 ELM_SET_WIDTYPE(widtype, "map");
3161 elm_widget_type_set(obj, "map");
3162 elm_widget_sub_object_add(parent, obj);
3163 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3164 elm_widget_data_set(obj, wd);
3165 elm_widget_del_hook_set(obj, _del_hook);
3166 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3167 elm_widget_theme_hook_set(obj, _theme_hook);
3168 elm_widget_can_focus_set(obj, EINA_TRUE);
3169 elm_widget_event_hook_set(obj, _event_hook);
3171 wd->scr = elm_smart_scroller_add(e);
3172 elm_smart_scroller_widget_set(wd->scr, obj);
3173 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3174 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3175 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3176 elm_widget_resize_object_set(obj, wd->scr);
3177 elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3179 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3180 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3181 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3182 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3183 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3185 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3189 wd->map = evas_map_new(4);
3190 if (!wd->map) return NULL;
3192 wd->zoom_min = 0xFF;
3193 wd->zoom_max = 0X00;
3194 wd->markers_max_num = 30;
3195 wd->pinch.level = 1.0;
3198 wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3200 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3201 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3202 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3203 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3207 static Evas_Smart_Class sc;
3209 evas_object_smart_clipped_smart_set(&_pan_sc);
3211 sc.name = "elm_map_pan";
3212 sc.version = EVAS_SMART_CLASS_VERSION;
3215 sc.resize = _pan_resize;
3216 sc.move = _pan_move;
3217 sc.calculate = _pan_calculate;
3218 smart = evas_smart_class_new(&sc);
3222 wd->pan_smart = evas_object_smart_add(e, smart);
3223 wd->pan = evas_object_smart_data_get(wd->pan_smart);
3227 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3228 _pan_set, _pan_get, _pan_max_get,
3229 _pan_min_get, _pan_child_size_get);
3231 wd->rect = evas_object_rectangle_add(e);
3232 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3233 _rect_resize_cb, obj);
3234 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3236 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3238 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3240 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3241 _mouse_multi_down, obj);
3242 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3243 _mouse_multi_move, obj);
3244 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3245 _mouse_multi_up, obj);
3246 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3247 _mouse_wheel_cb, obj);
3249 evas_object_smart_member_add(wd->rect, wd->pan_smart);
3250 elm_widget_sub_object_add(obj, wd->rect);
3251 evas_object_show(wd->rect);
3252 evas_object_color_set(wd->rect, 0, 0, 0, 0);
3254 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3255 wd->id = ((int)getpid() << 16) | idnum;
3259 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3261 evas_object_size_hint_min_set(obj, minw, minh);
3263 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3264 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3266 wd->paused = EINA_TRUE;
3267 elm_map_zoom_set(obj, 0);
3268 wd->paused = EINA_FALSE;
3271 // TODO: convert Elementary to subclassing of Evas_Smart_Class
3272 // TODO: and save some bytes, making descriptions per-class and not instance!
3273 evas_object_smart_callbacks_descriptions_set(obj, _signals);
3275 if (!ecore_file_download_protocol_available("http://"))
3277 ERR("Ecore must be built with curl support for the map widget!");
3284 * Set the zoom level of the map
3286 * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
3288 * @param obj The map object
3289 * @param zoom The zoom level to set
3294 elm_map_zoom_set(Evas_Object *obj, int zoom)
3296 ELM_CHECK_WIDTYPE(obj, widtype);
3297 Widget_Data *wd = elm_widget_data_get(obj);
3299 Grid *g, *g_zoom = NULL;
3300 Evas_Coord rx, ry, rw, rh;
3304 int z = 0, zoom_changed = 0, started = 0;
3306 if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3307 if (zoom < 0 ) zoom = 0;
3308 if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3309 if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3311 if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3312 else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3313 else wd->zoom_method = ZOOM_METHOD_NONE;
3314 if (wd->zoom != zoom ) zoom_changed = 1;
3316 wd->size.ow = wd->size.w;
3317 wd->size.oh = wd->size.h;
3318 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3319 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3321 EINA_LIST_FOREACH(wd->route, l, r)
3325 EINA_LIST_FOREACH(r->path, l, p)
3327 evas_object_polygon_points_clear(p);
3332 EINA_LIST_FOREACH(wd->track, l, route)
3334 evas_object_hide(route);
3337 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3344 while (cumulw <= rw)
3353 while (cumulh <= rh)
3360 if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3362 if (p2w < p2h) z = p2w;
3365 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3367 if (p2w > p2h) z = p2w;
3372 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3373 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3375 g = grid_create(obj);
3378 if (eina_list_count(wd->grids) > 1)
3380 g_zoom = eina_list_last(wd->grids)->data;
3381 wd->grids = eina_list_remove(wd->grids, g_zoom);
3382 grid_clear(obj, g_zoom);
3385 wd->grids = eina_list_prepend(wd->grids, g);
3389 EINA_LIST_FREE(wd->grids, g)
3397 if ((wd->size.w > 0) && (wd->size.h > 0))
3399 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3400 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3404 wd->size.spos.x = 0.5;
3405 wd->size.spos.y = 0.5;
3408 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3409 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3410 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3411 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3416 if (wd->calc_job) ecore_job_del(wd->calc_job);
3417 wd->calc_job = ecore_job_add(_calc_job, wd);
3421 if (!wd->zoom_animator)
3423 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3425 if (wd->nosmooth == 1) _smooth_update(obj);
3432 if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3433 if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3436 if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3440 * Get the zoom level of the map
3442 * This returns the current zoom level of the map object. Note that if
3443 * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
3444 * (which is the default), the zoom level may be changed at any time by the
3445 * map object itself to account for map size and map viewpoer size
3447 * @param obj The map object
3448 * @return The current zoom level
3453 elm_map_zoom_get(const Evas_Object *obj)
3455 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3456 Widget_Data *wd = elm_widget_data_get(obj);
3465 * This sets the zoom mode to manual or one of several automatic levels.
3466 * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
3467 * elm_map_zoom_set() and will stay at that level until changed by code
3468 * or until zoom mode is changed. This is the default mode.
3469 * The Automatic modes will allow the map object to automatically
3470 * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT will
3471 * adjust zoom so the map fits inside the scroll frame with no pixels
3472 * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
3473 * 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.
3475 * @param obj The map object
3476 * @param mode The desired mode
3481 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3483 ELM_CHECK_WIDTYPE(obj, widtype);
3484 Widget_Data *wd = elm_widget_data_get(obj);
3487 if (wd->mode == mode) return;
3490 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3494 elm_map_zoom_set(wd->obj, tz);
3501 * This gets the current zoom mode of the map object
3503 * @param obj The map object
3504 * @return The current zoom mode
3508 EAPI Elm_Map_Zoom_Mode
3509 elm_map_zoom_mode_get(const Evas_Object *obj)
3511 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3512 Widget_Data *wd = elm_widget_data_get(obj);
3514 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3519 * Centers the map at @p lon @p lat using an animation to scroll.
3521 * @param obj The map object
3522 * @param lon Longitude to center at
3523 * @param lon Latitude to center at
3528 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3530 ELM_CHECK_WIDTYPE(obj, widtype);
3531 Widget_Data *wd = elm_widget_data_get(obj);
3535 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3536 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3541 if (wd->zoom_animator)
3544 if (!wd->nosmooth) _smooth_update(obj);
3545 ecore_animator_del(wd->zoom_animator);
3546 wd->zoom_animator = NULL;
3548 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3550 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3552 wd->center_on.enabled = EINA_TRUE;
3553 wd->center_on.lon = lon;
3554 wd->center_on.lat = lat;
3558 * Move the map to the current coordinates.
3560 * This move the map to the current coordinates. The map will be centered on these coordinates.
3562 * @param obj The map object
3563 * @param lat The latitude.
3564 * @param lon The longitude.
3569 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3571 ELM_CHECK_WIDTYPE(obj, widtype);
3572 Widget_Data *wd = elm_widget_data_get(obj);
3576 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3577 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3582 if (wd->zoom_animator)
3585 ecore_animator_del(wd->zoom_animator);
3586 wd->zoom_animator = NULL;
3588 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3590 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3592 wd->center_on.enabled = EINA_TRUE;
3593 wd->center_on.lon = lon;
3594 wd->center_on.lat = lat;
3598 * Get the current coordinates of the map.
3600 * This gets the current coordinates of the map object.
3602 * @param obj The map object
3603 * @param lat The latitude.
3604 * @param lon The longitude.
3609 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3611 ELM_CHECK_WIDTYPE(obj, widtype);
3612 Widget_Data *wd = elm_widget_data_get(obj);
3613 Evas_Coord sx, sy, sw, sh;
3616 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3617 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3621 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3625 * Set the paused state for map
3627 * This sets the paused state to on (1) or off (0) for map. The default
3628 * is off. This will stop zooming using animation change zoom levels and
3629 * change instantly. This will stop any existing animations that are running.
3631 * @param obj The map object
3632 * @param paused The pause state to set
3637 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3639 ELM_CHECK_WIDTYPE(obj, widtype);
3640 Widget_Data *wd = elm_widget_data_get(obj);
3643 if (wd->paused == !!paused) return;
3644 wd->paused = paused;
3647 if (wd->zoom_animator)
3649 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3650 wd->zoom_animator = NULL;
3652 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3658 * Set the paused state for the markers
3660 * This sets the paused state to on (1) or off (0) for the markers. The default
3661 * is off. This will stop displaying the markers during change zoom levels. Set
3662 * to on if you have a large number of markers.
3664 * @param obj The map object
3665 * @param paused The pause state to set
3670 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3672 ELM_CHECK_WIDTYPE(obj, widtype);
3673 Widget_Data *wd = elm_widget_data_get(obj);
3676 if (wd->paused_markers == !!paused) return;
3677 wd->paused_markers = paused;
3681 * Get the paused state for map
3683 * This gets the current paused state for the map object.
3685 * @param obj The map object
3686 * @return The current paused state
3691 elm_map_paused_get(const Evas_Object *obj)
3693 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3694 Widget_Data *wd = elm_widget_data_get(obj);
3696 if (!wd) return EINA_FALSE;
3701 * Get the paused state for the markers
3703 * This gets the current paused state for the markers object.
3705 * @param obj The map object
3706 * @return The current paused state
3711 elm_map_paused_markers_get(const Evas_Object *obj)
3713 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3714 Widget_Data *wd = elm_widget_data_get(obj);
3716 if (!wd) return EINA_FALSE;
3717 return wd->paused_markers;
3721 * Get the information of downloading status
3723 * This gets the current downloading status for the map object.
3725 * @param obj The map object
3726 * @param try_num the number of download trying map
3727 * @param finish_num the number of downloaded map
3733 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3735 ELM_CHECK_WIDTYPE(obj, widtype);
3736 Widget_Data *wd = elm_widget_data_get(obj);
3741 *try_num = wd->try_num;
3746 *finish_num = wd->finish_num;
3750 * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
3752 * @param obj The map object
3753 * @param x the coordinate
3754 * @param y the coordinate
3755 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3756 * @param lon the longitude correspond to x
3757 * @param lat the latitude correspond to y
3762 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3764 ELM_CHECK_WIDTYPE(obj, widtype);
3765 Widget_Data *wd = elm_widget_data_get(obj);
3768 int zoom = floor(log(size / 256) / log(2));
3769 if ((wd->src) && (wd->src->coord_into_geo))
3771 if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3776 *lon = x / (double)size * 360.0 - 180;
3780 double n = ELM_PI - 2.0 * ELM_PI * y / size;
3781 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3786 * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
3788 * @param obj The map object
3789 * @param lon the longitude
3790 * @param lat the latitude
3791 * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3792 * @param x the coordinate correspond to the longitude
3793 * @param y the coordinate correspond to the latitude
3798 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3800 ELM_CHECK_WIDTYPE(obj, widtype);
3801 Widget_Data *wd = elm_widget_data_get(obj);
3804 int zoom = floor(log(size / 256) / log(2));
3805 if ((wd->src) && (wd->src->geo_into_coord))
3807 if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3811 *x = floor((lon + 180.0) / 360.0 * size);
3813 *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3817 * Convert a geographic coordinate (longitude, latitude) into a name (address).
3819 * @param obj The map object
3820 * @param lon the longitude
3821 * @param lat the latitude
3823 * @return name the address
3828 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3830 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3831 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3835 * Convert a name (address) into a geographic coordinate (longitude, latitude).
3837 * @param obj The map object
3838 * @param name the address
3839 * @param lat the latitude correspond to y
3841 * @return name the address
3846 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3848 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3849 if (!address) return NULL;
3850 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3854 * Convert a pixel coordinate into a roated pixcel coordinate.
3856 * @param obj The map object
3857 * @param x x to rotate.
3858 * @param y y to rotate.
3859 * @param cx rotation's center horizontal position.
3860 * @param cy rotation's center vertical position.
3861 * @param degree amount of degrees from 0.0 to 360.0 to rotate arount Z axis.
3862 * @param xx rotated x.
3863 * @param yy rotated y.
3868 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)
3870 if ((!xx) || (!yy)) return;
3872 double r = (degree * M_PI) / 180.0;
3873 double tx, ty, ttx, tty;
3880 tx = ttx + (ty * cos(r + M_PI_2));
3881 ty = tty + (ty * sin(r + M_PI_2));
3888 * Add a marker on the map
3890 * @param obj The map object
3891 * @param lon the longitude
3892 * @param lat the latitude
3893 * @param clas the class to use
3894 * @param clas_group the class group
3895 * @param data the data passed to the callbacks
3897 * @return The marker object
3901 EAPI Elm_Map_Marker *
3902 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3904 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3905 Widget_Data *wd = elm_widget_data_get(obj);
3908 Marker_Group *group;
3916 if (!wd) return NULL;
3917 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3918 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3920 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3923 marker->clas = clas;
3924 marker->clas_group = clas_group;
3925 marker->longitude = lon;
3926 marker->latitude = lat;
3927 marker->data = data;
3928 marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3929 marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3930 marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
3932 tabi[1] = tabi[4] = tabi[6] = -1;
3933 tabi[2] = tabi[0] = tabi[7] = 0;
3934 tabi[3] = tabi[5] = tabi[8] = 1;
3936 tabj[1] = tabj[2] = tabj[3] = -1;
3937 tabj[4] = tabj[0] = tabj[5] = 0;
3938 tabj[6] = tabj[7] = tabj[8] = 1;
3940 if (!clas_group->priv.set)
3943 if (marker->clas_group && marker->clas_group->style)
3944 style = marker->clas_group->style;
3946 o = edje_object_add(evas_object_evas_get(obj));
3947 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3948 s = edje_object_data_get(o, "size_w");
3949 if (s) clas_group->priv.edje_w = atoi(s);
3950 else clas_group->priv.edje_w = 0;
3951 s = edje_object_data_get(o, "size_h");
3952 if (s) clas_group->priv.edje_h = atoi(s);
3953 else clas_group->priv.edje_h = 0;
3954 s = edje_object_data_get(o, "size_max_w");
3955 if (s) clas_group->priv.edje_max_w = atoi(s);
3956 else clas_group->priv.edje_max_w = 0;
3957 s = edje_object_data_get(o, "size_max_h");
3958 if (s) clas_group->priv.edje_max_h = atoi(s);
3959 else clas_group->priv.edje_max_h = 0;
3962 clas_group->priv.set = EINA_TRUE;
3965 if (!clas->priv.set)
3968 if (marker->clas && marker->clas->style)
3969 style = marker->clas->style;
3971 o = edje_object_add(evas_object_evas_get(obj));
3972 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3973 s = edje_object_data_get(o, "size_w");
3974 if (s) clas->priv.edje_w = atoi(s);
3975 else clas->priv.edje_w = 0;
3976 s = edje_object_data_get(o, "size_h");
3977 if (s) clas->priv.edje_h = atoi(s);
3978 else clas->priv.edje_h = 0;
3981 clas->priv.set = EINA_TRUE;
3984 for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3986 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3987 &(marker->x[i]), &(marker->y[i]));
3989 //search in the matrixsparse the region where the marker will be
3990 mpi = marker->x[i] / wd->tsize;
3991 mpj = marker->y[i] / wd->tsize;
3993 if (!wd->markers[i])
3995 int size = pow(2.0, i);
3996 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
4000 if (i <= clas_group->zoom_grouped)
4002 for (j = 0, group = NULL; j < 9 && !group; j++)
4004 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
4007 if (group->clas == marker->clas_group
4008 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
4009 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
4010 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
4012 group->markers = eina_list_append(group->markers, marker);
4013 group->update_nbelems = EINA_TRUE;
4014 group->update_resize = EINA_TRUE;
4016 group->sum_x += marker->x[i];
4017 group->sum_y += marker->y[i];
4018 group->x = group->sum_x / eina_list_count(group->markers);
4019 group->y = group->sum_y / eina_list_count(group->markers);
4021 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
4022 * eina_list_count(group->markers);
4023 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
4024 * eina_list_count(group->markers);
4025 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
4026 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
4028 if (group->obj && eina_list_count(group->markers) == 2)
4030 _group_object_free(group);
4031 _group_object_create(group);
4034 _group_bubble_content_update(group);
4043 group = calloc(1, sizeof(Marker_Group));
4045 group->sum_x = marker->x[i];
4046 group->sum_y = marker->y[i];
4047 group->x = marker->x[i];
4048 group->y = marker->y[i];
4049 group->w = clas_group->priv.edje_w;
4050 group->h = clas_group->priv.edje_h;
4051 group->clas = clas_group;
4053 group->markers = eina_list_append(group->markers, marker);
4054 group->update_nbelems = EINA_TRUE;
4055 group->update_resize = EINA_TRUE;
4057 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4061 l = eina_list_append(NULL, group);
4062 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
4063 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4067 l = eina_matrixsparse_cell_data_get(group->cell);
4068 l = eina_list_append(l, group);
4069 eina_matrixsparse_cell_data_set(group->cell, l);
4072 marker->groups[i] = group;
4077 Evas_Coord ox, oy, ow, oh;
4078 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4079 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4086 * Remove a marker from the map
4088 * @param marker The marker to remove
4093 elm_map_marker_remove(Elm_Map_Marker *marker)
4099 EINA_SAFETY_ON_NULL_RETURN(marker);
4102 for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4104 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
4105 if (!eina_list_count(marker->groups[i]->markers))
4107 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
4108 groups = eina_list_remove(groups, marker->groups[i]);
4109 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
4111 _group_object_free(marker->groups[i]);
4112 _group_bubble_free(marker->groups[i]);
4113 free(marker->groups[i]);
4117 marker->groups[i]->sum_x -= marker->x[i];
4118 marker->groups[i]->sum_y -= marker->y[i];
4120 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
4121 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
4123 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
4124 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
4125 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
4126 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
4127 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
4128 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
4129 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
4130 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
4132 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
4134 _group_object_free(marker->groups[i]);
4135 _group_object_create(marker->groups[i]);
4140 if ((marker->content) && (marker->clas->func.del))
4141 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4142 else if (marker->content)
4143 evas_object_del(marker->content);
4145 if (marker->x) free(marker->x);
4146 if (marker->y) free(marker->y);
4147 if (marker->groups) free(marker->groups);
4153 Evas_Coord ox, oy, ow, oh;
4154 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4155 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4160 * Get the current coordinates of the marker.
4162 * @param marker marker.
4163 * @param lat The latitude.
4164 * @param lon The longitude.
4169 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
4171 EINA_SAFETY_ON_NULL_RETURN(marker);
4172 if (lon) *lon = marker->longitude;
4173 if (lat) *lat = marker->latitude;
4177 * Move the map to the coordinate of the marker.
4179 * @param marker The marker where the map will be center.
4184 elm_map_marker_bring_in(Elm_Map_Marker *marker)
4186 EINA_SAFETY_ON_NULL_RETURN(marker);
4187 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
4191 * Move the map to the coordinate of the marker.
4193 * @param marker The marker where the map will be center.
4198 elm_map_marker_show(Elm_Map_Marker *marker)
4200 EINA_SAFETY_ON_NULL_RETURN(marker);
4201 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
4205 * Move and zoom the map to display a list of markers.
4207 * The map will be centered on the center point of the markers in the list. Then
4208 * the map will be zoomed in order to fit the markers using the maximum zoom which
4209 * allows display of all the markers.
4211 * @param markers The list of markers (list of Elm_Map_Marker *)
4216 elm_map_markers_list_show(Eina_List *markers)
4221 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
4222 Evas_Coord rw, rh, xc, yc;
4225 EINA_SAFETY_ON_NULL_RETURN(markers);
4226 EINA_LIST_FOREACH(markers, l, marker)
4230 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
4233 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
4236 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
4239 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
4243 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
4244 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
4246 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
4247 for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
4249 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4250 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4252 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4253 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4254 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4255 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4259 elm_map_geo_region_show(wd->obj, lon, lat);
4260 elm_map_zoom_set(wd->obj, zoom);
4264 * Set the maximum numbers of markers display in a group.
4266 * A group can have a long list of markers, consequently the creation of the content
4267 * of the bubble can be very slow. In order to avoid this, a maximum number of items
4268 * is displayed in a bubble. By default this number is 30.
4270 * @param obj The map object.
4271 * @param max The maximum numbers of items displayed in a bubble.
4276 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4278 ELM_CHECK_WIDTYPE(obj, widtype);
4279 Widget_Data *wd = elm_widget_data_get(obj);
4282 wd->markers_max_num = max;
4286 * Return the evas object getting from the ElmMapMarkerGetFunc callback
4288 * @param marker The marker.
4289 * @return Return the evas object if it exists, else NULL.
4294 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4296 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4297 return marker->content;
4303 * @param marker The marker.
4308 elm_map_marker_update(Elm_Map_Marker *marker)
4310 EINA_SAFETY_ON_NULL_RETURN(marker);
4311 if (marker->content)
4313 if (marker->clas->func.del)
4314 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4316 evas_object_del(marker->content);
4317 marker->content = NULL;
4318 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4323 * Close all opened bubbles
4325 * @param obj The map object
4330 elm_map_bubbles_close(Evas_Object *obj)
4332 ELM_CHECK_WIDTYPE(obj, widtype);
4333 Widget_Data *wd = elm_widget_data_get(obj);
4334 Marker_Group *group;
4335 Eina_List *l, *l_next;
4338 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4339 _group_bubble_free(group);
4343 * Create a group class.
4345 * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
4346 * The group class defines the style of the marker when a marker is grouped to others markers.
4348 * @param obj The map object
4349 * @return Returns the new group class
4353 EAPI Elm_Map_Group_Class *
4354 elm_map_group_class_new(Evas_Object *obj)
4356 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4357 Widget_Data *wd = elm_widget_data_get(obj);
4359 if (!wd) return NULL;
4360 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4361 clas->zoom_grouped = wd->zoom_max;
4362 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4367 * Set the style of a group class (radio, radio2 or empty)
4369 * @param clas the group class
4370 * @param style the new style
4375 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4377 EINA_SAFETY_ON_NULL_RETURN(clas);
4378 eina_stringshare_replace(&clas->style, style);
4382 * Set the icon callback of a group class.
4384 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4386 * @param clas the group class
4387 * @param icon_get the callback to create the icon
4392 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4394 EINA_SAFETY_ON_NULL_RETURN(clas);
4395 clas->func.icon_get = icon_get;
4399 * Set the data associated to the group class (radio, radio2 or empty)
4401 * @param clas the group class
4402 * @param data the new user data
4407 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4409 EINA_SAFETY_ON_NULL_RETURN(clas);
4414 * Set the zoom from where the markers are displayed.
4416 * Markers will not be displayed for a zoom less than @ref zoom
4418 * @param clas the group class
4419 * @param zoom the zoom
4424 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4426 EINA_SAFETY_ON_NULL_RETURN(clas);
4427 clas->zoom_displayed = zoom;
4431 * Set the zoom from where the markers are no more grouped.
4433 * @param clas the group class
4434 * @param zoom the zoom
4439 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4441 EINA_SAFETY_ON_NULL_RETURN(clas);
4442 clas->zoom_grouped = zoom;
4446 * Set if the markers associated to the group class @clas are hidden or not.
4447 * If @ref hide is true the markers will be hidden.
4449 * @param clas the group class
4450 * @param hide if true the markers will be hidden, else they will be displayed.
4455 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4457 ELM_CHECK_WIDTYPE(obj, widtype);
4458 Widget_Data *wd = elm_widget_data_get(obj);
4461 EINA_SAFETY_ON_NULL_RETURN(clas);
4462 if (clas->hide == hide) return;
4466 Evas_Coord ox, oy, ow, oh;
4467 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4468 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4474 * Create a marker class.
4476 * Each marker must be associated to a class.
4477 * The class defines the style of the marker when a marker is displayed alone (not grouped).
4479 * @param obj The map object
4480 * @return Returns the new class
4484 EAPI Elm_Map_Marker_Class *
4485 elm_map_marker_class_new(Evas_Object *obj)
4487 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4488 Widget_Data *wd = elm_widget_data_get(obj);
4490 if (!wd) return NULL;
4491 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4492 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4497 * Set the style of a class (radio, radio2 or empty)
4499 * @param clas the group class
4500 * @param style the new style
4505 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
4507 EINA_SAFETY_ON_NULL_RETURN(clas);
4508 eina_stringshare_replace(&clas->style, style);
4512 * Set the icon callback of a class.
4514 * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4516 * @param clas the group class
4517 * @param icon_get the callback to create the icon
4522 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4524 EINA_SAFETY_ON_NULL_RETURN(clas);
4525 clas->func.icon_get = icon_get;
4530 * Set the callback of the content of the bubble.
4532 * When the user click on a marker, a bubble is displayed with a content.
4533 * The callback @ref get musst return this content. It can be NULL.
4535 * @param clas the group class
4536 * @param get the callback to create the content
4541 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4543 EINA_SAFETY_ON_NULL_RETURN(clas);
4544 clas->func.get = get;
4548 * Set the callback of the content of delete the object created by the callback "get".
4550 * If this callback is defined the user will have to delete (or not) the object inside.
4551 * If the callback is not defined the object will be destroyed with evas_object_del()
4553 * @param clas the group class
4554 * @param del the callback to delete the content
4559 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4561 EINA_SAFETY_ON_NULL_RETURN(clas);
4562 clas->func.del = del;
4566 * Get the list of the sources.
4568 * @param obj The map object
4569 * @return sources the source list
4575 elm_map_source_names_get(const Evas_Object *obj)
4577 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4578 Widget_Data *wd = elm_widget_data_get(obj);
4580 if (!wd) return NULL;
4581 return wd->source_names;
4585 * Set the source of the map.
4587 * Elm_Map retrieves the image which composed the map from a web service. This web service can
4588 * be set with this method. A different service can return a different maps with different
4589 * information and it can use different zoom value.
4591 * @param obj the map object
4592 * @param source the new source
4597 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4599 ELM_CHECK_WIDTYPE(obj, widtype);
4600 Widget_Data *wd = elm_widget_data_get(obj);
4607 if ((wd->src) && (!strcmp(wd->src->name, source_name))) return;
4608 if ((wd->src) && (!wd->src->url_cb)) return;
4610 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4611 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4613 if (!strcmp(s->name, source_name))
4622 if (wd->src->zoom_max < zoom)
4623 zoom = wd->src->zoom_max;
4624 if (wd->src->zoom_min > zoom)
4625 zoom = wd->src->zoom_min;
4627 elm_map_zoom_set(obj, zoom);
4631 * Get the name of a source.
4633 * @param source the source
4634 * @return Returns the name of the source
4639 elm_map_source_name_get(const Evas_Object *obj)
4641 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4642 Widget_Data *wd = elm_widget_data_get(obj);
4644 if ((!wd) || (!wd->src)) return NULL;
4645 return wd->src->name;
4649 * Set the source of the route.
4651 * @param clas the group class
4652 * @param source the new source
4657 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4659 ELM_CHECK_WIDTYPE(obj, widtype);
4660 Widget_Data *wd = elm_widget_data_get(obj);
4663 wd->route_source = source;
4667 * Get the current route source
4669 * @param obj the map object
4670 * @return Returns the source of the route
4674 EAPI Elm_Map_Route_Sources
4675 elm_map_route_source_get(const Evas_Object *obj)
4677 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4678 Widget_Data *wd = elm_widget_data_get(obj);
4680 if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4681 return wd->route_source;
4685 * Set the maximum zoom of the source.
4687 * @param source the source
4692 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4694 ELM_CHECK_WIDTYPE(obj, widtype);
4695 Widget_Data *wd = elm_widget_data_get(obj);
4697 if ((!wd) || (!wd->src)) return;
4698 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4699 wd->src->zoom_max = zoom;
4703 * Get the maximum zoom of the source.
4705 * @param source the source
4706 * @return Returns the maximum zoom of the source
4711 elm_map_source_zoom_max_get(const Evas_Object *obj)
4713 ELM_CHECK_WIDTYPE(obj, widtype) 18;
4714 Widget_Data *wd = elm_widget_data_get(obj);
4716 if ((!wd) || (!wd->src)) return 18;
4717 return wd->src->zoom_max;
4721 * Set the minimum zoom of the source.
4723 * @param source the source
4728 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4730 ELM_CHECK_WIDTYPE(obj, widtype);
4731 Widget_Data *wd = elm_widget_data_get(obj);
4733 if ((!wd) || (!wd->src)) return;
4734 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4735 wd->src->zoom_min = zoom;
4740 * Get the minimum zoom of the source.
4742 * @param source the source
4743 * @return Returns the minimum zoom of the source
4748 elm_map_source_zoom_min_get(const Evas_Object *obj)
4750 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4751 Widget_Data *wd = elm_widget_data_get(obj);
4753 if ((!wd) || (!wd->src)) return 0;
4754 return wd->src->zoom_min;
4758 * Set the user agent of the widget map.
4760 * @param obj The map object
4761 * @param user_agent the user agent of the widget map
4766 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4768 ELM_CHECK_WIDTYPE(obj, widtype);
4769 Widget_Data *wd = elm_widget_data_get(obj);
4772 if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4773 else eina_stringshare_replace(&wd->user_agent, user_agent);
4775 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4776 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4780 * Get the user agent of the widget map.
4782 * @param obj The map object
4783 * @return The user agent of the widget map
4788 elm_map_user_agent_get(const Evas_Object *obj)
4790 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4791 Widget_Data *wd = elm_widget_data_get(obj);
4793 if (!wd) return NULL;
4794 return wd->user_agent;
4798 * Add a route on the map
4800 * @param obj The map object
4801 * @param type the type if transport
4802 * @param method the routing method
4803 * @param flon the start longitude
4804 * @param flat the start latitude
4805 * @param tlon the destination longitude
4806 * @param tlat the destination latitude
4808 * @return The Route object
4812 EAPI Elm_Map_Route *
4813 elm_map_route_add(Evas_Object *obj,
4814 Elm_Map_Route_Type type,
4815 Elm_Map_Route_Method method,
4821 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4822 Widget_Data *wd = elm_widget_data_get(obj);
4825 char *type_name = NULL;
4828 if ((!wd) || (!wd->src)) return NULL;
4830 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4831 if (!route) return NULL;
4833 snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4841 route->con_url = ecore_con_url_new(NULL);
4842 route->ud.fname = strdup(buf);
4843 INF("xml file : %s", route->ud.fname);
4845 route->ud.fd = fdopen(fd, "w+");
4846 if ((!route->con_url) || (!route->ud.fd))
4848 ecore_con_url_free(route->con_url);
4854 route->color.r = 255;
4857 route->color.a = 255;
4858 route->handlers = eina_list_append
4859 (route->handlers, (void *)ecore_event_handler_add
4860 (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
4862 route->inbound = EINA_FALSE;
4864 route->method = method;
4872 case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4873 type_name = strdup(ROUTE_TYPE_MOTORCAR);
4875 case ELM_MAP_ROUTE_TYPE_BICYCLE:
4876 type_name = strdup(ROUTE_TYPE_BICYCLE);
4878 case ELM_MAP_ROUTE_TYPE_FOOT:
4879 type_name = strdup(ROUTE_TYPE_FOOT);
4885 source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4886 INF("route url = %s", source);
4888 wd->route = eina_list_append(wd->route, route);
4890 ecore_con_url_url_set(route->con_url, source);
4891 ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4892 ecore_con_url_data_set(route->con_url, route);
4893 ecore_con_url_get(route->con_url);
4894 if (type_name) free(type_name);
4895 if (source) free(source);
4897 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4898 "elm,state,busy,start", "elm");
4899 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4905 * Remove a route from the map
4907 * @param route The route to remove
4913 elm_map_route_remove(Elm_Map_Route *route)
4915 EINA_SAFETY_ON_NULL_RETURN(route);
4920 Ecore_Event_Handler *h;
4922 EINA_LIST_FREE(route->path, p)
4927 EINA_LIST_FREE(route->waypoint, w)
4929 if (w->point) eina_stringshare_del(w->point);
4933 EINA_LIST_FREE(route->nodes, n)
4935 if (n->pos.address) eina_stringshare_del(n->pos.address);
4939 EINA_LIST_FREE(route->handlers, h)
4941 ecore_event_handler_del(h);
4944 if (route->ud.fname)
4946 ecore_file_remove(route->ud.fname);
4947 free(route->ud.fname);
4948 route->ud.fname = NULL;
4953 * Set the option used for the background color
4955 * @param route The route object
4961 * This sets the color used for the route
4966 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4968 EINA_SAFETY_ON_NULL_RETURN(route);
4976 * Get the option used for the background color
4978 * @param route The route object
4987 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
4989 EINA_SAFETY_ON_NULL_RETURN(route);
4990 if (r) *r = route->color.r;
4991 if (g) *g = route->color.g;
4992 if (b) *b = route->color.b;
4993 if (a) *a = route->color.a;
4997 * Get the information of route distance
4999 * @param route the route object
5000 * @return Returns the distance of route (unit : km)
5005 elm_map_route_distance_get(const Elm_Map_Route *route)
5007 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
5008 return route->info.distance;
5012 * Get the information of route nodes
5014 * @param route the route object
5015 * @return Returns the nodes of route
5021 elm_map_route_node_get(const Elm_Map_Route *route)
5023 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5024 return route->info.nodes;
5028 * Get the information of route waypoint
5030 * @param route the route object
5031 * @return Returns the waypoint of route
5037 elm_map_route_waypoint_get(const Elm_Map_Route *route)
5039 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5040 return route->info.waypoints;
5044 * Get the information of address
5046 * @param name the name object
5047 * @return Returns the address of name
5052 elm_map_name_address_get(const Elm_Map_Name *name)
5054 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
5055 return name->address;
5059 * Get the current coordinates of the name.
5061 * This gets the current coordinates of the name object.
5063 * @param obj The name object
5064 * @param lat The latitude
5065 * @param lon The longitude
5070 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
5072 EINA_SAFETY_ON_NULL_RETURN(name);
5073 if (lon) *lon = name->lon;
5074 if (lat) *lat = name->lat;
5078 * Remove a name from the map
5080 * @param name The name to remove
5085 elm_map_name_remove(Elm_Map_Name *name)
5087 EINA_SAFETY_ON_NULL_RETURN(name);
5090 free(name->address);
5091 name->address = NULL;
5095 ecore_event_handler_del(name->handler);
5096 name->handler = NULL;
5100 ecore_file_remove(name->ud.fname);
5101 free(name->ud.fname);
5102 name->ud.fname = NULL;
5107 * Set the rotate degree of the map
5109 * @param obj The map object
5110 * @param angle amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5111 * @param cx rotation's center horizontal position
5112 * @param cy rotation's center vertical position
5117 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
5119 ELM_CHECK_WIDTYPE(obj, widtype);
5120 Widget_Data *wd = elm_widget_data_get(obj);
5123 wd->rotate.d = degree;
5126 wd->calc_job = ecore_job_add(_calc_job, wd);
5130 * Get the rotate degree of the map
5132 * @param obj The map object
5133 * @return amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5134 * @param cx rotation's center horizontal position
5135 * @param cy rotation's center vertical position
5140 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
5142 ELM_CHECK_WIDTYPE(obj, widtype);
5143 Widget_Data *wd = elm_widget_data_get(obj);
5146 if (degree) *degree = wd->rotate.d;
5147 if (cx) *cx = wd->rotate.cx;
5148 if (cy) *cy = wd->rotate.cy;
5152 * Set the wheel control state of the map
5154 * @param obj The map object
5155 * @param disabled status of wheel control
5160 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
5162 ELM_CHECK_WIDTYPE(obj, widtype);
5163 Widget_Data *wd = elm_widget_data_get(obj);
5166 if ((!wd->wheel_disabled) && (disabled))
5167 evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5168 else if ((wd->wheel_disabled) && (!disabled))
5169 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5170 wd->wheel_disabled = !!disabled;
5174 * Get the wheel control state of the map
5176 * @param obj The map object
5177 * @return Returns the status of wheel control
5182 elm_map_wheel_disabled_get(const Evas_Object *obj)
5184 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5185 Widget_Data *wd = elm_widget_data_get(obj);
5187 if (!wd) return EINA_FALSE;
5188 return wd->wheel_disabled;
5193 * Add a track on the map
5195 * @param obj The map object
5196 * @param emap the emap object
5198 * @return The Route object. This is a elm object of type Elm_Route
5203 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
5205 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5206 Widget_Data *wd = elm_widget_data_get(obj);
5208 if (!wd) return EINA_FALSE;
5210 Evas_Object *route = elm_route_add(obj);
5211 elm_route_emap_set(route, emap);
5212 wd->track = eina_list_append(wd->track, route);
5220 * Remove a track from the map
5222 * @param track The track to remove
5228 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
5230 ELM_CHECK_WIDTYPE(obj, widtype) ;
5231 Widget_Data *wd = elm_widget_data_get(obj);
5235 wd->track = eina_list_remove(wd->track, route);
5236 evas_object_del(route);
5240 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5243 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
5249 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5252 snprintf(buf, sizeof(buf),
5253 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
5259 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5262 snprintf(buf, sizeof(buf),
5263 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
5269 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5272 snprintf(buf, sizeof(buf),
5273 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
5278 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5281 snprintf(buf, sizeof(buf),
5282 "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
5283 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
5288 // TODO: fix monav api
5290 static char *_monav_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=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5295 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
5301 // TODO: fix ors api
5303 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5306 snprintf(buf, sizeof(buf),
5307 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5308 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
5315 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
5317 ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
5318 Widget_Data *wd = elm_widget_data_get(obj);
5320 unsigned int ele, idx;
5321 char search_url[PATH_MAX];
5324 if (!wd) return strdup("");
5325 if (method == ELM_MAP_NAME_METHOD_SEARCH)
5327 search_url[0] = '\0';
5328 str = eina_str_split_full(name, " ", 0, &ele);
5329 for (idx = 0 ; idx < ele ; idx++)
5331 eina_strlcat(search_url, str[idx], sizeof(search_url));
5332 if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
5334 snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
5336 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);
5337 else strcpy(buf, "");