2 # include "elementary_config.h"
5 #include "Elementary.h"
7 #include "els_scroller.h"
9 #ifdef HAVE_ELEMENTARY_ECORE_CON
11 typedef struct _Widget_Data Widget_Data;
12 typedef struct _Pan Pan;
13 typedef struct _Grid Grid;
14 typedef struct _Grid_Item Grid_Item;
15 typedef struct _Overlay_Default Overlay_Default;
16 typedef struct _Overlay_Group Overlay_Group;
17 typedef struct _Overlay_Class Overlay_Class;
18 typedef struct _Overlay_Bubble Overlay_Bubble;
19 typedef struct _Overlay_Route Overlay_Route;
20 typedef struct _Marker_Group Marker_Group;
21 typedef struct _Marker_Bubble Marker_Bubble;
22 typedef struct _Path_Node Path_Node;
23 typedef struct _Path_Waypoint Path_Waypoint;
24 typedef struct _Url_Data Url_Data;
25 typedef struct _Route_Dump Route_Dump;
26 typedef struct _Name_Dump Name_Dump;
27 typedef struct _Delayed_Data Delayed_Data;
28 typedef struct _Source_Tile Source_Tile;
29 typedef struct _Source_Route Source_Route;
30 typedef struct _Source_Name Source_Name;
32 #define ROUND(z) (((z) < 0) ? (int)ceil((z) - 0.005) : (int)floor((z) + 0.005))
33 #define EVAS_MAP_POINT 4
34 #define DEFAULT_TILE_SIZE 256
35 #define MAX_CONCURRENT_DOWNLOAD 10
36 #define MARER_MAX_NUMBER 30
37 #define OVERLAY_CLASS_ZOOM_MAX 255
38 #define OVERLAY_GROUPING_SCALE 2
40 #define CACHE_ROOT "/tmp/elm_map"
41 #define CACHE_TILE_ROOT CACHE_ROOT"/%d/%d/%d"
42 #define CACHE_TILE_PATH "%s/%d.png"
43 #define CACHE_ROUTE_ROOT CACHE_ROOT"/route"
44 #define CACHE_NAME_ROOT CACHE_ROOT"/name"
46 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
47 #define ROUTE_TYPE_MOTORCAR "motocar"
48 #define ROUTE_TYPE_BICYCLE "bicycle"
49 #define ROUTE_TYPE_FOOT "foot"
50 #define YOURS_DISTANCE "distance"
51 #define YOURS_DESCRIPTION "description"
52 #define YOURS_COORDINATES "coordinates"
54 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
55 #define NOMINATIM_RESULT "result"
56 #define NOMINATIM_PLACE "place"
57 #define NOMINATIM_ATTR_LON "lon"
58 #define NOMINATIM_ATTR_LAT "lat"
60 enum _Route_Xml_Attribute
64 ROUTE_XML_DESCRIPTION,
65 ROUTE_XML_COORDINATES,
69 enum _Name_Xml_Attribute
78 enum _Track_Xml_Attribute
81 TRACK_XML_COORDINATES,
87 void (*func)(void *data);
89 Elm_Map_Zoom_Mode mode;
97 // FIXME: Currently tile size must be 256*256
98 // and the map size is pow(2.0, z) * (tile size)
104 Elm_Map_Module_Tile_Url_Func url_cb;
105 Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
106 Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
113 Elm_Map_Module_Route_Url_Func url_cb;
120 Elm_Map_Module_Name_Url_Func url_cb;
125 Ecore_Con_Url *con_url;
131 struct _Overlay_Default
135 // Display priority is obj > icon > clas_obj > clas_icon > layout
139 // if obj or icon exists, do not inherit from class
140 Evas_Object *clas_obj; // Duplicated from class icon
141 Evas_Object *clas_obj_ref; // Checking fro class icon is changed
142 Evas_Object *clas_icon; // Duplicated from class icon
143 Evas_Object *clas_icon_ref; // Checking for class icon is changed
151 struct _Overlay_Group
153 Overlay_Default *ovl;
154 Evas_Object *clas_icon;
155 Elm_Map_Overlay *clas;
159 struct _Overlay_Class
161 Elm_Map_Overlay *clas;
169 struct _Overlay_Bubble
173 Evas_Object *obj, *sc, *bx;
175 Evas_Coord x, y, w, h;
178 struct _Overlay_Route
182 Eina_Bool inbound : 1;
196 struct _Elm_Map_Overlay
200 Eina_Bool paused : 1;
204 void *data; // user set data
206 Elm_Map_Overlay_Type type;
207 void *ovl; // Overlay Data for each type
209 // These are not used if overlay type is class
210 Eina_Bool grp_in : 1;
211 Eina_Bool grp_boss : 1;
214 Elm_Map_Overlay_Get_Cb cb;
218 struct _Elm_Map_Marker_Class
221 struct _Elm_Map_Marker_Class_Func
223 Elm_Map_Marker_Get_Func get;
224 Elm_Map_Marker_Del_Func del; //if NULL the object will be destroyed with evas_object_del()
225 Elm_Map_Marker_Icon_Get_Func icon_get;
229 struct _Elm_Map_Group_Class
234 int zoom_displayed; // display the group if the zoom is >= to zoom_display
235 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
240 Elm_Map_Group_Icon_Get_Func icon_get;
246 struct _Marker_Bubble
250 Evas_Object *obj, *sc, *bx;
253 struct _Elm_Map_Marker
256 Elm_Map_Marker_Class *clas;
257 Elm_Map_Group_Class *group_clas;
258 double longitude, latitude;
263 Eina_Bool grouped : 1;
264 Eina_Bool leader : 1; // if marker is group leader
267 Marker_Bubble *bubble;
268 Evas_Object *content;
275 Elm_Map_Group_Class *clas;
282 Marker_Bubble *bubble;
285 struct _Elm_Map_Route
290 Elm_Map_Route_Type type;
291 Elm_Map_Route_Method method;
292 double flon, flat, tlon, tlat;
295 Ecore_File_Download_Job *job;
305 const char *waypoints;
306 double distance; /* unit : km */
326 struct _Path_Waypoint
342 Ecore_File_Download_Job *job;
372 int x, y; // Tile coordinate
373 Eina_Bool file_have : 1;
375 Ecore_File_Download_Job *job;
381 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
382 int tw, th; // size of grid in tiles
383 Eina_Matrixsparse *grid;
388 Evas_Object_Smart_Clipped_Data __clipped_data;
397 Evas_Object *pan_smart;
398 Evas_Object *sep_maps_markers; // Tiles are below this and overlays are on top
401 Source_Tile *src_tile;
402 Eina_List *src_tiles;
403 const char **src_tile_names;
405 Source_Route *src_route;
406 Eina_List *src_routes;
407 const char **src_route_names;
409 Source_Name *src_name;
410 Eina_List *src_names;
411 const char **src_name_names;
413 int zoom_min, zoom_max;
421 double prev_lon, prev_lat;
425 int w, h; // Current pixel width, heigth of a grid
426 int tile; // Current pixel size of a grid item
428 Elm_Map_Zoom_Mode mode;
435 Ecore_Timer *zoom_timer;
436 Ecore_Animator *zoom_animator;
441 Eina_List *download_list;
442 Ecore_Idler *download_idler;
444 const char *user_agent;
446 Evas_Coord pan_x, pan_y;
447 Eina_List *delayed_jobs;
449 Ecore_Timer *scr_timer;
450 Ecore_Timer *long_timer;
451 Evas_Event_Mouse_Down ev;
452 Eina_Bool on_hold : 1;
453 Eina_Bool paused : 1;
462 Eina_Bool wheel_disabled : 1;
464 unsigned int markers_max_num;
465 Eina_Bool paused_markers : 1;
466 Eina_List *group_classes;
467 Eina_List *marker_classes;
477 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
478 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
479 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
480 static char *_mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
481 static char *_mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
482 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat);
483 static char *_nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat);
485 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
486 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
489 const Source_Tile src_tiles[] =
491 {"Mapnik", 0, 18, _mapnik_url_cb, NULL, NULL},
492 {"Osmarender", 0, 17, _osmarender_url_cb, NULL, NULL},
493 {"CycleMap", 0, 16, _cyclemap_url_cb, NULL, NULL},
494 {"MapQuest", 0, 18, _mapquest_url_cb, NULL, NULL},
495 {"MapQuest Open Aerial", 0, 11, _mapquest_aerial_url_cb, NULL, NULL},
498 // FIXME: Fix more open sources
499 const Source_Route src_routes[] =
501 {"Yours", _yours_url_cb} // http://www.yournavigation.org/
502 //{"Monav", _monav_url_cb},
503 //{"ORS", _ors_url_cb}, // http://www.openrouteservice.org
506 // FIXME: Add more open sources
507 const Source_Name src_names[] =
509 {"Nominatim", _nominatim_url_cb}
512 static const char *widtype = NULL;
513 static Evas_Smart_Class parent_sc = EVAS_SMART_CLASS_INIT_NULL;
514 static Evas_Smart_Class sc;
515 static Evas_Smart *smart;
516 static int idnum = 1;
518 static const char SIG_CLICKED[] = "clicked";
519 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
520 static const char SIG_PRESS[] = "press";
521 static const char SIG_LONGPRESSED[] = "longpressed";
522 static const char SIG_SCROLL[] = "scroll";
523 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
524 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
525 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
526 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
527 static const char SIG_ZOOM_START[] = "zoom,start";
528 static const char SIG_ZOOM_STOP[] = "zoom,stop";
529 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
530 static const char SIG_TILE_LOAD[] = "tile,load";
531 static const char SIG_TILE_LOADED[] = "tile,loaded";
532 static const char SIG_TILE_LOADED_FAIL[] = "tile,loaded,fail";
533 static const char SIG_ROUTE_LOAD[] = "route,load";
534 static const char SIG_ROUTE_LOADED[] = "route,loaded";
535 static const char SIG_ROUTE_LOADED_FAIL[] = "route,loaded,fail";
536 static const char SIG_NAME_LOAD[] = "name,load";
537 static const char SIG_NAME_LOADED[] = "name,loaded";
538 static const char SIG_NAME_LOADED_FAIL[] = "name,loaded,fail";
539 static const char SIG_OVERLAY_CLICKED[] = "overlay,clicked";
540 static const Evas_Smart_Cb_Description _signals[] = {
542 {SIG_CLICKED_DOUBLE, ""},
544 {SIG_LONGPRESSED, ""},
546 {SIG_SCROLL_DRAG_START, ""},
547 {SIG_SCROLL_DRAG_STOP, ""},
548 {SIG_SCROLL_ANIM_START, ""},
549 {SIG_SCROLL_ANIM_STOP, ""},
550 {SIG_ZOOM_START, ""},
552 {SIG_ZOOM_CHANGE, ""},
554 {SIG_TILE_LOADED, ""},
555 {SIG_TILE_LOADED_FAIL, ""},
556 {SIG_ROUTE_LOAD, ""},
557 {SIG_ROUTE_LOADED, ""},
558 {SIG_ROUTE_LOADED_FAIL, ""},
560 {SIG_NAME_LOADED, ""},
561 {SIG_NAME_LOADED_FAIL, ""},
562 {SIG_OVERLAY_CLICKED, ""},
567 _edj_marker_size_get(Widget_Data *wd, Evas_Coord *w, Evas_Coord *h)
569 EINA_SAFETY_ON_NULL_RETURN(wd);
570 EINA_SAFETY_ON_NULL_RETURN(w);
571 EINA_SAFETY_ON_NULL_RETURN(h);
576 edj = edje_object_add(evas_object_evas_get(wd->obj));
577 _elm_theme_object_set(wd->obj, edj, "map/marker", "radio",
578 elm_widget_style_get(wd->obj));
579 s = edje_object_data_get(edj, "size_w");
582 s = edje_object_data_get(edj, "size_h");
585 evas_object_del(edj);
589 _coord_rotate(Evas_Coord x, Evas_Coord y, Evas_Coord cx, Evas_Coord cy, double degree, Evas_Coord *xx, Evas_Coord *yy)
591 EINA_SAFETY_ON_NULL_RETURN(xx);
592 EINA_SAFETY_ON_NULL_RETURN(yy);
594 double r = (degree * M_PI) / 180.0;
596 if (xx) *xx = ((x - cx) * cos(r)) + ((y - cy) * cos(r + M_PI_2)) + cx;
597 if (yy) *yy = ((x - cx) * sin(r)) + ((y - cy) * sin(r + M_PI_2)) + cy;
601 _obj_rotate(Widget_Data *wd, Evas_Object *obj)
603 Evas_Coord w, h, ow, oh;
604 evas_map_util_points_populate_from_object(wd->map, obj);
606 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
607 evas_object_image_size_get(obj, &w, &h);
608 if ((w > ow) || (h > oh))
610 evas_map_point_image_uv_set(wd->map, 0, 0, 0);
611 evas_map_point_image_uv_set(wd->map, 1, w, 0);
612 evas_map_point_image_uv_set(wd->map, 2, w, h);
613 evas_map_point_image_uv_set(wd->map, 3, 0, h);
615 evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
617 evas_object_map_set(obj, wd->map);
618 evas_object_map_enable_set(obj, EINA_TRUE);
622 _obj_place(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
624 EINA_SAFETY_ON_NULL_RETURN(obj);
626 evas_object_move(obj, x, y);
627 evas_object_resize(obj, w, h);
628 evas_object_show(obj);
632 _coord_to_region_convert(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord size, double *lon, double *lat)
634 EINA_SAFETY_ON_NULL_RETURN(wd);
636 int zoom = floor(log(size / wd->size.tile) / log(2));
637 if ((wd->src_tile) && (wd->src_tile->coord_to_geo))
639 if (wd->src_tile->coord_to_geo(wd->obj, zoom, x, y, size, lon, lat))
643 if (lon) *lon = (x / (double)size * 360.0) - 180;
646 double n = ELM_PI - (2.0 * ELM_PI * y / size);
647 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
652 _geo_to_coord_convert(Widget_Data *wd, double lon, double lat, Evas_Coord size, Evas_Coord *x, Evas_Coord *y)
654 EINA_SAFETY_ON_NULL_RETURN(wd);
656 int zoom = floor(log(size / 256) / log(2));
657 if ((wd->src_tile) && (wd->src_tile->geo_to_coord))
659 if (wd->src_tile->geo_to_coord(wd->obj, zoom, lon, lat, size, x, y)) return;
662 if (x) *x = floor((lon + 180.0) / 360.0 * size);
664 *y = floor((1.0 - log(tan(lat * ELM_PI / 180.0) + (1.0 / cos(lat * ELM_PI / 180.0)))
665 / ELM_PI) / 2.0 * size);
670 _viewport_size_get(Widget_Data *wd, Evas_Coord *vw, Evas_Coord *vh)
672 EINA_SAFETY_ON_NULL_RETURN(wd);
674 Evas_Coord x, y, w, h;
675 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
676 if (vw) *vw = (x * 2) + w;
677 if (vh) *vh = (y * 2) + h;
681 _pan_geometry_get(Widget_Data *wd, Evas_Coord *px, Evas_Coord *py)
683 EINA_SAFETY_ON_NULL_RETURN(wd);
685 Evas_Coord x, y, vx, vy, vw, vh;
686 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
687 evas_object_geometry_get(wd->pan_smart, &vx, &vy, &vw, &vh);
690 if (vw > wd->size.w) x += (((vw - wd->size.w) / 2) + vx);
692 if (vh > wd->size.h) y += (((vh - wd->size.h) / 2) + vy);
699 _region_show(void *data)
701 EINA_SAFETY_ON_NULL_RETURN(data);
702 Delayed_Data *dd = data;
705 _geo_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
706 _viewport_size_get(dd->wd, &w, &h);
709 elm_smart_scroller_child_region_show(dd->wd->scr, x, y, w, h);
710 evas_object_smart_changed(dd->wd->pan_smart);
714 _bubble_update(Marker_Bubble *bubble, Eina_List *contents)
716 EINA_SAFETY_ON_NULL_RETURN(bubble);
717 EINA_SAFETY_ON_NULL_RETURN(contents);
722 elm_box_clear(bubble->bx);
723 EINA_LIST_FOREACH(contents, l, c) elm_box_pack_end(bubble->bx, c);
727 _bubble_place(Marker_Bubble *bubble)
729 EINA_SAFETY_ON_NULL_RETURN(bubble);
731 Evas_Coord x, y, w, h;
732 Evas_Coord xx, yy, ww, hh;
735 if ((!bubble->obj) || (!bubble->pobj)) return;
736 evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
738 s = edje_object_data_get(bubble->obj, "size_w");
742 edje_object_size_min_calc(bubble->obj, NULL, &hh);
743 s = edje_object_data_get(bubble->obj, "size_h");
748 xx = x + (w / 2) - (ww / 2);
751 _obj_place(bubble->obj, xx, yy, ww, hh);
752 evas_object_raise(bubble->obj);
756 _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
758 Marker_Bubble *bubble = data;
759 EINA_SAFETY_ON_NULL_RETURN(bubble);
764 _bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
766 Marker_Bubble *bubble = data;
767 EINA_SAFETY_ON_NULL_RETURN(bubble);
768 _bubble_place(bubble);
772 _bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
774 Marker_Bubble *bubble = data;
775 EINA_SAFETY_ON_NULL_RETURN(bubble);
776 evas_object_hide(bubble->obj);
780 _bubble_show_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
782 Marker_Bubble *bubble = data;
783 EINA_SAFETY_ON_NULL_RETURN(bubble);
784 _bubble_place(bubble);
788 _bubble_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
790 Marker_Bubble *bubble = data;
791 EINA_SAFETY_ON_NULL_RETURN(bubble);
792 _bubble_place(bubble);
796 _bubble_free(Marker_Bubble* bubble)
798 EINA_SAFETY_ON_NULL_RETURN(bubble);
800 evas_object_del(bubble->bx);
801 evas_object_del(bubble->sc);
802 evas_object_del(bubble->obj);
806 static Marker_Bubble*
807 _bubble_create(Evas_Object *pobj, Widget_Data *wd)
809 EINA_SAFETY_ON_NULL_RETURN_VAL(pobj, NULL);
810 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
812 Marker_Bubble *bubble = ELM_NEW(Marker_Bubble);
813 EINA_SAFETY_ON_NULL_RETURN_VAL(bubble, NULL);
817 evas_object_event_callback_add(pobj, EVAS_CALLBACK_HIDE, _bubble_hide_cb,
819 evas_object_event_callback_add(pobj, EVAS_CALLBACK_SHOW, _bubble_show_cb,
821 evas_object_event_callback_add(pobj, EVAS_CALLBACK_MOVE, _bubble_move_cb,
824 bubble->obj = edje_object_add(evas_object_evas_get(pobj));
825 _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
826 elm_widget_style_get(wd->obj));
827 evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
828 _bubble_mouse_up_cb, bubble);
830 bubble->sc = elm_scroller_add(bubble->obj);
831 elm_widget_style_set(bubble->sc, "map_bubble");
832 elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
833 elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
834 ELM_SCROLLER_POLICY_OFF);
835 elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
837 edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
838 evas_object_event_callback_add(bubble->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
839 _bubble_sc_hints_changed_cb, bubble);
841 bubble->bx = elm_box_add(bubble->sc);
842 evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
843 evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
845 elm_box_horizontal_set(bubble->bx, EINA_TRUE);
846 elm_object_content_set(bubble->sc, bubble->bx);
852 _marker_group_update(Marker_Group* group, Elm_Map_Group_Class *clas, Eina_List *markers)
854 EINA_SAFETY_ON_NULL_RETURN(group);
855 EINA_SAFETY_ON_NULL_RETURN(clas);
856 EINA_SAFETY_ON_NULL_RETURN(markers);
857 Widget_Data *wd = clas->wd;
858 EINA_SAFETY_ON_NULL_RETURN(wd);
862 Elm_Map_Marker *marker;
864 int sum_x = 0, sum_y = 0;
866 EINA_LIST_FOREACH(markers, l, marker)
873 group->x = sum_x / cnt;
874 group->y = sum_y / cnt;
875 _edj_marker_size_get(wd, &group->w, &group->h);
879 group->markers = markers;
881 if (clas->style) elm_layout_theme_set(group->obj, "map/marker", clas->style,
882 elm_widget_style_get(wd->obj));
883 else elm_layout_theme_set(group->obj, "map/marker", "radio",
884 elm_widget_style_get(wd->obj));
887 if (clas->func.icon_get)
889 Evas_Object *icon = NULL;
891 icon = elm_object_part_content_get(group->obj, "elm.icon");
892 if (icon) evas_object_del(icon);
894 icon = clas->func.icon_get(wd->obj, clas->data);
895 elm_object_part_content_set(group->obj, "elm.icon", icon);
897 snprintf(buf, sizeof(buf), "%d", cnt);
898 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
902 Eina_List *contents = NULL;
904 EINA_LIST_FOREACH(group->markers, l, marker)
906 Evas_Object *c = marker->clas->func.get(marker->wd->obj,
907 marker, marker->data);
908 if (c) contents = eina_list_append(contents, c);
910 _bubble_update(group->bubble, contents);
915 _marker_group_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
917 EINA_SAFETY_ON_NULL_RETURN(data);
918 Marker_Group *group = data;
920 Elm_Map_Marker *marker;
921 Eina_List *contents = NULL;
923 if (!group->bubble) group->bubble = _bubble_create(group->obj, group->wd);
925 EINA_LIST_FOREACH(group->markers, l, marker)
927 if (group->wd->markers_max_num <= eina_list_count(contents)) break;
928 Evas_Object *c = marker->clas->func.get(marker->wd->obj,
929 marker, marker->data);
930 if (c) contents = eina_list_append(contents, c);
932 _bubble_update(group->bubble, contents);
933 _bubble_place(group->bubble);
937 _marker_group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
939 EINA_SAFETY_ON_NULL_RETURN(data);
942 Marker_Group *group = data;
943 _coord_to_region_convert(group->wd, group->x, group->y, group->wd->size.w,
945 elm_map_region_bring_in(group->wd->obj, lon, lat);
949 _marker_group_free(Marker_Group* group)
951 EINA_SAFETY_ON_NULL_RETURN(group);
953 if (group->bubble) _bubble_free(group->bubble);
955 eina_list_free(group->markers);
956 evas_object_del(group->obj);
962 _marker_group_create(Widget_Data *wd)
964 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
966 Marker_Group *group = ELM_NEW(Marker_Group);
969 group->obj = elm_layout_add(wd->obj);
970 evas_object_smart_member_add(group->obj, wd->pan_smart);
971 evas_object_stack_above(group->obj, wd->sep_maps_markers);
972 elm_layout_theme_set(group->obj, "map/marker", "radio",
973 elm_widget_style_get(wd->obj));
974 edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
975 "open", "elm", _marker_group_bubble_open_cb,
977 edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
978 "bringin", "elm", _marker_group_bringin_cb,
984 _marker_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
986 Elm_Map_Marker *marker = data;
987 EINA_SAFETY_ON_NULL_RETURN(marker);
988 elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
992 _marker_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
994 EINA_SAFETY_ON_NULL_RETURN(data);
995 Elm_Map_Marker *marker = data;
997 if (!marker->bubble) marker->bubble = _bubble_create(marker->obj, marker->wd);
998 evas_object_smart_changed(marker->wd->pan_smart);
1002 _marker_update(Elm_Map_Marker *marker)
1004 EINA_SAFETY_ON_NULL_RETURN(marker);
1005 Elm_Map_Marker_Class *clas = marker->clas;
1006 EINA_SAFETY_ON_NULL_RETURN(clas);
1008 if (clas->style) elm_layout_theme_set(marker->obj, "map/marker", clas->style,
1009 elm_widget_style_get(marker->wd->obj));
1010 else elm_layout_theme_set(marker->obj, "map/marker", "radio",
1011 elm_widget_style_get(marker->wd->obj));
1013 if (clas->func.icon_get)
1015 Evas_Object *icon = NULL;
1017 icon = elm_object_part_content_get(marker->obj, "elm.icon");
1018 if (icon) evas_object_del(icon);
1020 icon = clas->func.icon_get(marker->wd->obj, marker, marker->data);
1021 elm_object_part_content_set(marker->obj, "elm.icon", icon);
1023 _geo_to_coord_convert(marker->wd, marker->longitude, marker->latitude,
1024 marker->wd->size.w, &(marker->x), &(marker->y));
1028 if (marker->content) evas_object_del(marker->content);
1029 if (marker->clas->func.get)
1030 marker->content = marker->clas->func.get(marker->wd->obj, marker,
1032 if (marker->content)
1034 Eina_List *contents = NULL;
1035 contents = eina_list_append(contents, marker->content);
1036 _bubble_update(marker->bubble, contents);
1044 _marker_place(Widget_Data *wd)
1046 EINA_SAFETY_ON_NULL_RETURN(wd);
1050 Elm_Map_Marker *marker;
1051 Elm_Map_Group_Class *group_clas;
1056 if (wd->paused_markers || (!eina_list_count(wd->markers))) return;
1058 _pan_geometry_get(wd, &px, &py);
1060 _edj_marker_size_get(wd, &gw, &gh);
1064 EINA_LIST_FOREACH(wd->markers, l, marker)
1066 _marker_update(marker);
1067 marker->grouped = EINA_FALSE;
1068 marker->leader = EINA_FALSE;
1071 EINA_LIST_FOREACH(wd->group_classes, l, group_clas)
1074 EINA_LIST_FOREACH(group_clas->markers, ll, marker)
1078 Eina_List *markers = NULL;
1080 if (marker->grouped) continue;
1081 if (group_clas->zoom_grouped < wd->zoom)
1083 marker->grouped = EINA_FALSE;
1087 EINA_LIST_FOREACH(group_clas->markers, lll, mm)
1089 if (marker == mm || mm->grouped) continue;
1090 if (ELM_RECTS_INTERSECT(mm->x, mm->y, mm->w, mm->h,
1091 marker->x, marker->y, gw, gh))
1093 // mm is group follower.
1094 mm->leader = EINA_FALSE;
1095 mm->grouped = EINA_TRUE;
1096 markers = eina_list_append(markers, mm);
1099 if (eina_list_count(markers) >= 1)
1101 // marker is group leader.
1102 marker->leader = EINA_TRUE;
1103 marker->grouped = EINA_TRUE;
1104 markers = eina_list_append(markers, marker);
1106 if (!marker->group) marker->group = _marker_group_create(wd);
1107 _marker_group_update(marker->group, group_clas, markers);
1112 EINA_LIST_FOREACH(wd->markers, l, marker)
1115 if (marker->grouped ||
1116 (marker->group_clas &&
1117 (marker->group_clas->hide ||
1118 marker->group_clas->zoom_displayed > wd->zoom)))
1119 evas_object_hide(marker->obj);
1123 _coord_rotate(marker->x + px, marker->y + py, wd->rotate.cx,
1124 wd->rotate.cy, wd->rotate.d, &x, &y);
1125 _obj_place(marker->obj, x - (marker->w / 2), y - (marker->h / 2),
1126 marker->w, marker->h);
1130 EINA_LIST_FOREACH(wd->markers, l, marker)
1132 Marker_Group *group = marker->group;
1133 if (!group) continue;
1135 if (!marker->leader || (group->clas->hide) ||
1136 (group->clas->zoom_displayed > wd->zoom))
1137 evas_object_hide(group->obj);
1141 _coord_rotate(group->x + px, group->y + py, wd->rotate.cx,
1142 wd->rotate.cy, wd->rotate.d, &x, &y);
1143 _obj_place(group->obj, x - (group->w / 2), y - (group->h / 2),
1144 group->w, group->h);
1150 _grid_item_coord_get(Grid_Item *gi, int *x, int *y, int *w, int *h)
1152 EINA_SAFETY_ON_NULL_RETURN(gi);
1154 if (x) *x = gi->x * gi->wd->size.tile;
1155 if (y) *y = gi->y * gi->wd->size.tile;
1156 if (w) *w = gi->wd->size.tile;
1157 if (h) *h = gi->wd->size.tile;
1161 _grid_item_intersect(Grid_Item *gi)
1163 EINA_SAFETY_ON_NULL_RETURN_VAL(gi, EINA_FALSE);
1167 Evas_Coord x, y, w, h;
1169 _pan_geometry_get(gi->wd, &px, &py);
1170 _viewport_size_get(gi->wd, &vw, &vh);
1171 _grid_item_coord_get(gi, &x, &y, &w, &h);
1172 return ELM_RECTS_INTERSECT(x + px, y + py, w, h, 0, 0, vw, vh);
1176 _grid_item_update(Grid_Item *gi)
1178 evas_object_image_file_set(gi->img, gi->file, NULL);
1179 if (!gi->wd->zoom_timer && !gi->wd->scr_timer)
1180 evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
1181 else evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
1183 Evas_Load_Error err = evas_object_image_load_error_get(gi->img);
1184 if (err != EVAS_LOAD_ERROR_NONE)
1186 ERR("Image loading error (%s): %s", gi->file, evas_load_error_str(err));
1187 ecore_file_remove(gi->file);
1188 gi->file_have = EINA_FALSE;
1193 Evas_Coord x, y, w, h;
1195 _pan_geometry_get(gi->wd, &px, &py);
1196 _grid_item_coord_get(gi, &x, &y, &w, &h);
1198 _obj_place(gi->img, x + px, y + py, w, h);
1199 _obj_rotate(gi->wd, gi->img);
1200 gi->file_have = EINA_TRUE;
1205 _grid_item_load(Grid_Item *gi)
1207 EINA_SAFETY_ON_NULL_RETURN(gi);
1208 if (gi->file_have) _grid_item_update(gi);
1211 gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
1212 gi->wd->download_list = eina_list_append(gi->wd->download_list, gi);
1217 _grid_item_unload(Grid_Item *gi)
1219 EINA_SAFETY_ON_NULL_RETURN(gi);
1222 evas_object_hide(gi->img);
1223 evas_object_image_file_set(gi->img, NULL, NULL);
1227 ecore_file_download_abort(gi->job);
1228 ecore_file_remove(gi->file);
1232 else gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
1237 _grid_item_create(Grid *g, Evas_Coord x, Evas_Coord y)
1239 EINA_SAFETY_ON_NULL_RETURN_VAL(g, NULL);
1241 char buf2[PATH_MAX];
1245 gi = ELM_NEW(Grid_Item);
1251 gi->file_have = EINA_FALSE;
1254 gi->img = evas_object_image_add(evas_object_evas_get(g->wd->obj));
1255 evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
1256 evas_object_image_scale_hint_set(gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1257 evas_object_image_filled_set(gi->img, 1);
1258 evas_object_smart_member_add(gi->img, g->wd->pan_smart);
1259 evas_object_pass_events_set(gi->img, EINA_TRUE);
1260 evas_object_stack_below(gi->img, g->wd->sep_maps_markers);
1262 snprintf(buf, sizeof(buf), CACHE_TILE_ROOT, g->wd->id, g->zoom, x);
1263 snprintf(buf2, sizeof(buf2), CACHE_TILE_PATH, buf, y);
1264 if (!ecore_file_exists(buf)) ecore_file_mkpath(buf);
1266 eina_stringshare_replace(&gi->file, buf2);
1267 url = g->wd->src_tile->url_cb(g->wd->obj, x, y, g->zoom);
1268 if ((!url) || (!strlen(url)))
1270 eina_stringshare_replace(&gi->url, NULL);
1271 ERR("Getting source url failed: %s", gi->file);
1273 else eina_stringshare_replace(&gi->url, url);
1275 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1280 _grid_item_free(Grid_Item *gi)
1282 EINA_SAFETY_ON_NULL_RETURN(gi);
1283 _grid_item_unload(gi);
1284 if (gi->g && gi->g->grid) eina_matrixsparse_data_idx_set(gi->g->grid,
1285 gi->y, gi->x, NULL);
1286 if (gi->url) eina_stringshare_del(gi->url);
1287 if (gi->file) eina_stringshare_del(gi->file);
1288 if (gi->img) evas_object_del(gi->img);
1289 if (gi->file_have) ecore_file_remove(gi->file);
1294 _downloaded_cb(void *data, const char *file __UNUSED__, int status)
1296 Grid_Item *gi = data;
1300 DBG("Download success from %s to %s", gi->url, gi->file);
1301 _grid_item_update(gi);
1302 gi->wd->finish_num++;
1303 evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED, NULL);
1307 WRN("Download failed from %s to %s (%d) ", gi->url, gi->file, status);
1308 ecore_file_remove(gi->file);
1309 gi->file_have = EINA_FALSE;
1310 evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED_FAIL, NULL);
1314 gi->wd->download_num--;
1315 if (!gi->wd->download_num)
1316 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1317 "elm,state,busy,stop", "elm");
1321 _download_job(void *data)
1323 EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1324 Widget_Data *wd = data;
1329 if (!eina_list_count(wd->download_list))
1331 wd->download_idler = NULL;
1332 return ECORE_CALLBACK_CANCEL;
1335 EINA_LIST_REVERSE_FOREACH_SAFE(wd->download_list, l, ll, gi)
1337 if (gi->g->zoom != wd->zoom || !_grid_item_intersect(gi))
1339 wd->download_list = eina_list_remove(wd->download_list, gi);
1342 if (wd->download_num >= MAX_CONCURRENT_DOWNLOAD)
1343 return ECORE_CALLBACK_RENEW;
1345 Eina_Bool ret = ecore_file_download_full(gi->url, gi->file,
1346 _downloaded_cb, NULL,
1347 gi, &(gi->job), wd->ua);
1348 if ((!ret) || (!gi->job))
1349 ERR("Can't start to download from %s to %s", gi->url, gi->file);
1352 wd->download_list = eina_list_remove(wd->download_list, gi);
1355 evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOAD,
1357 if (wd->download_num == 1)
1358 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1359 "elm,state,busy,start", "elm");
1363 return ECORE_CALLBACK_RENEW;
1367 _grid_viewport_get(Grid *g, int *x, int *y, int *w, int *h)
1369 EINA_SAFETY_ON_NULL_RETURN(g);
1371 Evas_Coord px, py, vw, vh;
1373 _pan_geometry_get(g->wd, &px, &py);
1374 _viewport_size_get(g->wd, &vw, &vh);
1378 xx = (-px / g->wd->size.tile) - 1;
1381 yy = (-py / g->wd->size.tile) - 1;
1384 ww = (vw / g->wd->size.tile) + 3;
1385 if (xx + ww >= g->tw) ww = g->tw - xx;
1387 hh = (vh / g->wd->size.tile) + 3;
1388 if (yy + hh >= g->th) hh = g->th - yy;
1397 _grid_unload(Grid *g)
1399 EINA_SAFETY_ON_NULL_RETURN(g);
1401 Eina_Matrixsparse_Cell *cell;
1404 it = eina_matrixsparse_iterator_new(g->grid);
1405 EINA_ITERATOR_FOREACH(it, cell)
1407 gi = eina_matrixsparse_cell_data_get(cell);
1408 _grid_item_unload(gi);
1410 eina_iterator_free(it);
1416 EINA_SAFETY_ON_NULL_RETURN(g);
1417 int x, y, xx, yy, ww, hh;
1419 Eina_Matrixsparse_Cell *cell;
1422 it = eina_matrixsparse_iterator_new(g->grid);
1423 EINA_ITERATOR_FOREACH(it, cell)
1425 gi = eina_matrixsparse_cell_data_get(cell);
1426 if (!_grid_item_intersect(gi)) _grid_item_unload(gi);
1428 eina_iterator_free(it);
1430 _grid_viewport_get(g, &xx, &yy, &ww, &hh);
1431 for (y = yy; y < yy + hh; y++)
1433 for (x = xx; x < xx + ww; x++)
1435 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1436 if (!gi) gi = _grid_item_create(g, x, y);
1437 _grid_item_load(gi);
1443 _grid_place(Widget_Data *wd)
1445 EINA_SAFETY_ON_NULL_RETURN(wd);
1449 EINA_LIST_FOREACH(wd->grids, l, g)
1451 if (wd->zoom == g->zoom) _grid_load(g);
1452 else _grid_unload(g);
1454 if (!wd->download_idler) wd->download_idler = ecore_idler_add(_download_job, wd);
1458 _grid_all_create(Widget_Data *wd)
1460 EINA_SAFETY_ON_NULL_RETURN(wd);
1461 EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
1464 for (zoom = wd->src_tile->zoom_min; zoom <= wd->src_tile->zoom_max; zoom++)
1471 tnum = pow(2.0, g->zoom);
1474 g->grid = eina_matrixsparse_new(g->th, g->tw, NULL, NULL);
1475 wd->grids = eina_list_append(wd->grids, g);
1480 _grid_all_clear(Widget_Data *wd)
1482 EINA_SAFETY_ON_NULL_RETURN(wd);
1485 EINA_LIST_FREE(wd->grids, g)
1487 Eina_Matrixsparse_Cell *cell;
1488 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1489 EINA_ITERATOR_FOREACH(it, cell)
1492 gi = eina_matrixsparse_cell_data_get(cell);
1493 if (gi) _grid_item_free(gi);
1495 eina_iterator_free(it);
1497 eina_matrixsparse_free(g->grid);
1503 _track_place(Widget_Data *wd)
1506 EINA_SAFETY_ON_NULL_RETURN(wd);
1510 int xmin, xmax, ymin, ymax;
1511 Evas_Coord px, py, ow, oh;
1514 _viewport_size_get(wd, &ow, &oh);
1516 Evas_Coord size = wd->size.w;
1518 EINA_LIST_FOREACH(wd->track, l, route)
1520 double lon_min, lon_max;
1521 double lat_min, lat_max;
1522 elm_route_longitude_min_max_get(route, &lon_min, &lon_max);
1523 elm_route_latitude_min_max_get(route, &lat_min, &lat_max);
1524 _geo_to_coord_convert(wd, lon_min, lat_max, size, &xmin, &ymin);
1525 _geo_to_coord_convert(wd, lon_max, lat_min, size, &xmax, &ymax);
1527 if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
1529 if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
1532 evas_object_move(route, xmin - px, ymin - py);
1533 evas_object_resize(route, xmax - xmin, ymax - ymin);
1535 evas_object_raise(route);
1536 _obj_rotate(wd, route);
1537 evas_object_show(route);
1542 //the route is not display
1543 evas_object_hide(route);
1551 _delayed_do(Widget_Data *wd)
1554 dd = eina_list_nth(wd->delayed_jobs, 0);
1555 if (dd && !dd->wd->zoom_animator)
1558 wd->delayed_jobs = eina_list_remove(wd->delayed_jobs, dd);
1564 _smooth_update(Widget_Data *wd)
1566 EINA_SAFETY_ON_NULL_RETURN(wd);
1570 EINA_LIST_FOREACH(wd->grids, l, g)
1572 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1573 Eina_Matrixsparse_Cell *cell;
1575 EINA_ITERATOR_FOREACH(it, cell)
1577 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1578 if (_grid_item_intersect(gi))
1579 evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
1581 eina_iterator_free(it);
1586 _zoom_timeout(void *data)
1588 EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1589 Widget_Data *wd = data;
1591 wd->zoom_timer = NULL;
1592 evas_object_smart_callback_call(wd->obj, SIG_ZOOM_STOP, NULL);
1593 return ECORE_CALLBACK_CANCEL;
1597 zoom_do(Widget_Data *wd, double zoom)
1599 EINA_SAFETY_ON_NULL_RETURN(wd);
1600 if (zoom > wd->zoom_max) zoom = wd->zoom_max;
1601 else if (zoom < wd->zoom_min) zoom = wd->zoom_min;
1603 Evas_Coord px, py, vw, vh;
1606 wd->zoom = ROUND(zoom);
1607 wd->zoom_detail = zoom;
1610 wd->size.tile = pow(2.0, (zoom - wd->zoom)) * wd->tsize;
1611 wd->size.w = pow(2.0, wd->zoom) * wd->size.tile;
1612 wd->size.h = wd->size.w;;
1614 // Fix to zooming with (viewport center px, py) as the center to prevent
1615 // from zooming with (0,0) as the cetner. (scroller default behavior)
1616 _pan_geometry_get(wd, &px, &py);
1617 _viewport_size_get(wd, &vw, &vh);
1618 if ((vw > 0) && (vh > 0) && (ow > 0) && (oh > 0))
1622 if (vw > ow) sx = 0.5;
1623 else sx = (double)(-px + (vw / 2)) / ow;
1624 if (vh > oh) sy = 0.5;
1625 else sy = (double)(-py + (vh / 2)) / oh;
1627 if (sx > 1.0) sx = 1.0;
1628 if (sy > 1.0) sy = 1.0;
1630 xx = (sx * wd->size.w) - (vw / 2);
1631 yy = (sy * wd->size.h) - (vh / 2);
1633 else if (xx > (wd->size.w - vw)) xx = wd->size.w - vw;
1635 else if (yy > (wd->size.h - vh)) yy = wd->size.h - vh;
1636 elm_smart_scroller_child_region_show(wd->scr, xx, yy, vw, vh);
1638 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1639 else evas_object_smart_callback_call(wd->obj, SIG_ZOOM_START, NULL);
1640 wd->zoom_timer = ecore_timer_add(0.25, _zoom_timeout, wd);
1641 evas_object_smart_callback_call(wd->obj, SIG_ZOOM_CHANGE, NULL);
1643 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1644 evas_object_smart_changed(wd->pan_smart);
1648 _zoom_anim(void *data)
1650 Widget_Data *wd = data;
1651 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ECORE_CALLBACK_CANCEL);
1653 if (wd->ani.cnt <= 0)
1655 wd->zoom_animator = NULL;
1656 evas_object_smart_changed(wd->pan_smart);
1657 return ECORE_CALLBACK_CANCEL;
1661 wd->ani.zoom += wd->ani.diff;
1663 zoom_do(wd, wd->ani.zoom);
1664 return ECORE_CALLBACK_RENEW;
1669 zoom_with_animation(Widget_Data *wd, double zoom, int cnt)
1671 EINA_SAFETY_ON_NULL_RETURN(wd);
1672 if (cnt == 0) return;
1675 wd->ani.zoom = wd->zoom;
1676 wd->ani.diff = (double)(zoom - wd->zoom) / cnt;
1677 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
1678 wd->zoom_animator = ecore_animator_add(_zoom_anim, wd);
1682 _sizing_eval(Widget_Data *wd)
1684 EINA_SAFETY_ON_NULL_RETURN(wd);
1686 Evas_Coord maxw = -1, maxh = -1;
1688 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
1689 evas_object_size_hint_max_set(wd->obj, maxw, maxh);
1693 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1699 _scr_timeout(void *data)
1701 EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1702 Widget_Data *wd = data;
1704 wd->scr_timer = NULL;
1705 evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_STOP, NULL);
1706 return ECORE_CALLBACK_CANCEL;
1710 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1712 EINA_SAFETY_ON_NULL_RETURN(data);
1713 Widget_Data *wd = data;
1715 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1716 else evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_START, NULL);
1717 wd->scr_timer = ecore_timer_add(0.25, _scr_timeout, wd);
1718 evas_object_smart_callback_call(wd->obj, SIG_SCROLL, NULL);
1722 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1724 EINA_SAFETY_ON_NULL_RETURN(data);
1725 Widget_Data *wd = data;
1726 evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_START, NULL);
1730 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1732 EINA_SAFETY_ON_NULL_RETURN(data);
1733 Widget_Data *wd = data;
1734 evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_STOP, NULL);
1738 _long_press(void *data)
1740 EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1741 Widget_Data *wd = data;
1743 wd->long_timer = NULL;
1744 evas_object_smart_callback_call(wd->obj, SIG_LONGPRESSED, &wd->ev);
1745 return ECORE_CALLBACK_CANCEL;
1749 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1751 EINA_SAFETY_ON_NULL_RETURN(data);
1752 Widget_Data *wd = data;
1753 Evas_Event_Mouse_Down *ev = event_info;
1755 if (ev->button != 1) return;
1757 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1758 else wd->on_hold = EINA_FALSE;
1760 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1761 evas_object_smart_callback_call(wd->obj, SIG_CLICKED_DOUBLE, ev);
1762 else evas_object_smart_callback_call(wd->obj, SIG_PRESS, ev);
1764 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1766 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, wd);
1770 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1772 EINA_SAFETY_ON_NULL_RETURN(data);
1773 Widget_Data *wd = data;
1775 Evas_Event_Mouse_Up *ev = event_info;
1776 EINA_SAFETY_ON_NULL_RETURN(ev);
1778 if (ev->button != 1) return;
1779 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1780 else wd->on_hold = EINA_FALSE;
1783 ecore_timer_del(wd->long_timer);
1784 wd->long_timer = NULL;
1786 if (!wd->on_hold) evas_object_smart_callback_call(wd->obj, SIG_CLICKED, ev);
1787 wd->on_hold = EINA_FALSE;
1791 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1793 EINA_SAFETY_ON_NULL_RETURN(data);
1794 Widget_Data *wd = data;
1798 Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1799 zoom_do(wd, wd->zoom_detail - ((double)ev->z / 10));
1804 _region_max_min_get(Eina_List *overlays, double *max_longitude, double *min_longitude, double *max_latitude, double *min_latitude)
1806 double max_lon = -180, min_lon = 180;
1807 double max_lat = -90, min_lat = 90;
1808 Elm_Map_Overlay *overlay;
1809 EINA_LIST_FREE(overlays, overlay)
1812 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
1814 Overlay_Default *ovl = overlay->ovl;
1818 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
1820 // FIXME: class center coord is alright??
1821 Overlay_Class *ovl = overlay->ovl;
1822 double max_lo, min_lo, max_la, min_la;
1823 _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la,
1825 lon = (max_lo + min_lo) / 2;
1826 lat = (max_la + min_la) / 2;
1828 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
1830 Overlay_Bubble *ovl = overlay->ovl;
1836 WRN("Not supported overlay type: %d", overlay->type);
1839 if (lon> max_lon) max_lon = lon;
1840 if (lon< min_lon) min_lon = lon;
1841 if (lat > max_lat) max_lat = lat;
1842 if (lat < min_lat) min_lat = lat;
1844 if (max_longitude) *max_longitude = max_lon;
1845 if (min_longitude) *min_longitude = min_lon;
1846 if (max_latitude) *max_latitude = max_lat;
1847 if (min_latitude) *min_latitude = min_lat;
1850 static Evas_Object *
1851 _icon_dup(Evas_Object *icon, Evas_Object *parent)
1853 if (!icon || !parent) return NULL;
1854 // Evas_Object do not support object duplication??
1855 const char *file = NULL, *group = NULL;
1856 Eina_Bool size_up, size_down;
1859 dupp = elm_icon_add(parent);
1860 elm_icon_file_get(icon, &file, &group);
1861 elm_icon_file_set(dupp, file, group);
1862 elm_icon_animated_set(dupp, elm_icon_animated_get(icon));
1863 elm_icon_animated_play_set(dupp, elm_icon_animated_play_get(icon));
1864 elm_icon_standard_set(dupp, elm_icon_standard_get(icon));
1865 elm_icon_order_lookup_set(dupp, elm_icon_order_lookup_get(icon));
1866 elm_icon_no_scale_set(dupp, elm_icon_no_scale_get(icon));
1867 elm_icon_resizable_get(icon, &size_up, &size_down);
1868 elm_icon_resizable_set(dupp, size_up, size_down);
1869 elm_icon_fill_outside_set(dupp, elm_icon_fill_outside_get(icon));
1870 elm_icon_prescale_set(dupp, elm_icon_prescale_get(icon));
1871 elm_icon_aspect_fixed_set(dupp, elm_icon_aspect_fixed_get(icon));
1875 static Evas_Object *
1876 _overlay_layout_new(Widget_Data *wd, const char *group)
1878 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
1879 EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
1880 Evas_Object *obj = elm_layout_add(wd->obj);
1881 evas_object_smart_member_add(obj, wd->pan_smart);
1882 evas_object_stack_above(obj, wd->sep_maps_markers);
1883 elm_layout_theme_set(obj, "map/marker", group, elm_widget_style_get(wd->obj));
1888 _overlay_layout_update(Widget_Data *wd, Evas_Object *layout, Evas_Object *icon, const char *text, const char *group)
1890 EINA_SAFETY_ON_NULL_RETURN(wd);
1891 EINA_SAFETY_ON_NULL_RETURN(layout);
1893 Evas_Object *prev_icon = elm_object_part_content_get(layout, "elm.icon");
1894 if (icon && (prev_icon != icon))
1896 elm_layout_theme_set(layout, "map/marker", "empty",
1897 elm_widget_style_get(wd->obj));
1898 elm_object_part_content_set(layout, "elm.icon", icon);
1902 if (group) elm_layout_theme_set(layout, "map/marker", group,
1903 elm_widget_style_get(wd->obj));
1904 edje_object_part_text_set(elm_layout_edje_get(layout), "elm.text", text);
1909 _overlay_clicked_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
1911 EINA_SAFETY_ON_NULL_RETURN(data);
1912 Elm_Map_Overlay *overlay = data;
1914 evas_object_smart_callback_call(overlay->wd->obj, SIG_OVERLAY_CLICKED,
1916 if (overlay->cb) overlay->cb(overlay->cb_data, overlay->wd->obj,
1921 _overlay_default_cb_add(Overlay_Default *ovl, Evas_Object_Event_Cb cb, void *data)
1923 EINA_SAFETY_ON_NULL_RETURN(ovl);
1924 EINA_SAFETY_ON_NULL_RETURN(data);
1926 // FIXME: Add icon or object event callback
1927 evas_object_event_callback_add(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb,
1932 _overlay_default_cb_del(Overlay_Default *ovl, Evas_Object_Event_Cb cb)
1934 EINA_SAFETY_ON_NULL_RETURN(ovl);
1935 // FIXME: Add icon or object event callback
1936 evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb);
1940 _overlay_default_hide(Overlay_Default *ovl)
1942 EINA_SAFETY_ON_NULL_RETURN(ovl);
1943 if (ovl->obj) evas_object_hide(ovl->obj);
1944 if (ovl->layout) evas_object_hide(ovl->layout);
1948 _overlay_default_show(Widget_Data *wd, Overlay_Default *ovl)
1952 Evas_Coord x, y, w, h;
1957 evas_object_geometry_get(disp, NULL, NULL, &w, &h);
1958 if (w <= 0 || h <= 0) evas_object_size_hint_min_get(disp, &w, &h);
1967 _pan_geometry_get(wd, &px, &py);
1968 _coord_rotate(ovl->x + px, ovl->y + py, wd->rotate.cx, wd->rotate.cy,
1969 wd->rotate.d, &x, &y);
1970 _obj_place(disp, x - (w / 2), y - (h / 2), w, h);
1974 _overlay_default_update(Widget_Data *wd, Overlay_Default *ovl, Evas_Object *obj, Evas_Object *icon, Overlay_Class *ovl_clas, const char *text, const char *group)
1976 EINA_SAFETY_ON_NULL_RETURN(wd);
1977 EINA_SAFETY_ON_NULL_RETURN(ovl);
1979 _geo_to_coord_convert(wd, ovl->lon, ovl->lat, wd->size.w, &ovl->x, &ovl->y);
1983 if (ovl->obj == obj) return;
1984 if (ovl->obj) evas_object_del(ovl->obj);
1987 else if (!(ovl->obj) && icon)
1989 if (ovl->icon == icon) return;
1990 if (ovl->icon) evas_object_del(ovl->icon);
1992 _overlay_layout_update(wd, ovl->layout, ovl->icon, NULL, NULL);
1995 else if (!(ovl->obj) && !(ovl->icon) && (ovl_clas) &&
1996 ((ovl_clas->obj) || (ovl_clas->icon)))
1998 // Inherit icon from group overlay's ojbect or icon
2000 // FIXME: It is hard to duplicate evas object :-)
2002 if (ovl_clas->obj && (ovl_clas->obj != ovl->clas_obj_ref))
2004 if (ovl->clas_obj) evas_object_del(ovl->clas_obj);
2005 ovl->clas_obj_ref = ovl_clas->obj;
2006 ovl->clas_obj = _obj_dup(ovl->clas_obj_ref, ovl->layout);
2007 _overlay_layout_update(wd, ovl->layout, ovl->clas_obj, NULL, NULL);
2010 if (ovl_clas->icon && (ovl_clas->icon != ovl->clas_icon_ref))
2012 if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
2013 ovl->clas_icon_ref = ovl_clas->icon;
2014 ovl->clas_icon = _icon_dup(ovl->clas_icon_ref, ovl->layout);
2015 _overlay_layout_update(wd, ovl->layout, ovl->clas_icon, NULL, NULL);
2018 else if (!(ovl->obj) && !(ovl->icon) && !(ovl->clas_icon) && text)
2020 _overlay_layout_update(wd, ovl->layout, NULL, text, group);
2025 _overlay_default_free(Overlay_Default *ovl)
2027 EINA_SAFETY_ON_NULL_RETURN(ovl);
2028 if (ovl->obj) evas_object_del(ovl->obj);
2029 if (ovl->icon) evas_object_del(ovl->icon);
2030 if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
2031 evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN,
2032 _overlay_clicked_cb);
2033 if (ovl->layout) evas_object_del(ovl->layout);
2037 static Overlay_Default *
2038 _overlay_default_new(Widget_Data *wd, double lon, double lat, const char *group)
2040 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2041 EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
2043 Overlay_Default *ovl = ELM_NEW(Overlay_Default);
2044 _edj_marker_size_get(wd, &(ovl->w), &(ovl->h));
2045 ovl->layout = _overlay_layout_new(wd, group);
2052 _overlay_group_clicked_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
2054 EINA_SAFETY_ON_NULL_RETURN(data);
2055 Overlay_Group *ovl = data;
2057 evas_object_smart_callback_call(ovl->clas->wd->obj, SIG_OVERLAY_CLICKED,
2059 if (ovl->clas->cb) ovl->clas->cb(ovl->clas->cb_data, ovl->clas->wd->obj,
2064 _overlay_group_cb_add(Overlay_Group *ovl)
2066 EINA_SAFETY_ON_NULL_RETURN(ovl);
2067 _overlay_default_cb_add(ovl->ovl, _overlay_group_clicked_cb, ovl);
2071 _overlay_group_cb_del(Overlay_Group *ovl)
2073 EINA_SAFETY_ON_NULL_RETURN(ovl);
2074 _overlay_default_cb_del(ovl->ovl, _overlay_group_clicked_cb);
2078 _overlay_group_update(Widget_Data *wd, Overlay_Group *grp, Eina_List *members)
2080 EINA_SAFETY_ON_NULL_RETURN(wd);
2081 EINA_SAFETY_ON_NULL_RETURN(grp);
2084 Elm_Map_Overlay *overlay;
2085 Evas_Coord sum_x = 0, sum_y = 0, cnt = 0;
2087 if (grp->members) eina_list_free(grp->members);
2088 grp->members = members;
2090 if (!grp->members || eina_list_count(grp->members) <= 0)
2092 _overlay_default_hide(grp->ovl);
2095 EINA_LIST_FOREACH(grp->members, l, overlay)
2097 Overlay_Default *df = overlay->ovl;
2103 Overlay_Class *ovl_clas = grp->clas->ovl;
2106 snprintf(text, sizeof(text), "%d", cnt);
2107 _overlay_default_update(wd, grp->ovl, NULL, NULL, ovl_clas, text, "radio2");
2109 grp->ovl->x = sum_x / cnt;
2110 grp->ovl->y = sum_y / cnt;
2114 _overlay_group_free(Overlay_Group *grp, Elm_Map_Overlay *club_owner)
2116 EINA_SAFETY_ON_NULL_RETURN(grp);
2118 _overlay_default_cb_del(grp->ovl, _overlay_group_clicked_cb);
2119 _overlay_default_free(grp->ovl);
2120 if (grp->clas) elm_map_overlay_class_remove(grp->clas, club_owner);
2121 if (grp->members) eina_list_free(grp->members);
2125 static Overlay_Group *
2126 _overlay_group_new(Widget_Data *wd)
2128 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2130 Overlay_Group *grp = ELM_NEW(Overlay_Group);
2131 grp->ovl = ELM_NEW(Overlay_Default);
2132 grp->ovl = _overlay_default_new(wd, -1, -1, "radio2");
2139 _overlay_class_update(Widget_Data *wd, Overlay_Class *clas, Evas_Object *obj, Evas_Object *icon)
2141 EINA_SAFETY_ON_NULL_RETURN(wd);
2142 EINA_SAFETY_ON_NULL_RETURN(clas);
2144 if (obj && (clas->obj != obj))
2146 if (clas->obj) evas_object_del(clas->obj);
2149 else if (icon && (clas->icon != icon))
2151 if (clas->icon) evas_object_del(clas->icon);
2157 _overlay_class_free(Overlay_Class *clas)
2159 EINA_SAFETY_ON_NULL_RETURN(clas);
2160 if (clas->icon) evas_object_del(clas->icon);
2161 if (clas->members) eina_list_free(clas->members);
2165 static Overlay_Class *
2166 _overlay_class_new(Widget_Data *wd, Elm_Map_Overlay *clas)
2168 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2169 Overlay_Class *ovl = ELM_NEW(Overlay_Class);
2172 ovl->zoom_max = OVERLAY_CLASS_ZOOM_MAX;
2177 _overlay_bubble_cb_add(Overlay_Bubble *ovl, Elm_Map_Overlay *overlay)
2179 EINA_SAFETY_ON_NULL_RETURN(ovl);
2180 EINA_SAFETY_ON_NULL_RETURN(overlay);
2181 evas_object_event_callback_add(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
2182 _overlay_clicked_cb, overlay);
2186 _overlay_bubble_cb_del(Overlay_Bubble *ovl)
2188 EINA_SAFETY_ON_NULL_RETURN(ovl);
2189 evas_object_event_callback_del(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
2190 _overlay_clicked_cb);
2194 _overlay_bubble_hide(Overlay_Bubble *bubble)
2196 EINA_SAFETY_ON_NULL_RETURN(bubble);
2197 if (bubble->obj) evas_object_hide(bubble->obj);
2201 _overlay_bubble_update(Overlay_Bubble *bubble)
2203 EINA_SAFETY_ON_NULL_RETURN(bubble);
2204 if ((!bubble->pobj) && (bubble->lon >= 0) && (bubble->lat >= 0))
2206 _geo_to_coord_convert(bubble->wd, bubble->lon, bubble->lat,
2207 bubble->wd->size.w, &bubble->x, &bubble->y);
2212 _overlay_bubble_show(Overlay_Bubble *bubble)
2214 EINA_SAFETY_ON_NULL_RETURN(bubble);
2217 if ((bubble->x < 0) || (bubble->y < 0)) return;
2219 _pan_geometry_get(bubble->wd, &px, &py);
2220 _coord_rotate(bubble->x + px, bubble->y + py, bubble->wd->rotate.cx,
2221 bubble->wd->rotate.cy, bubble->wd->rotate.d, &x, &y);
2222 x = x - (bubble->w / 2);
2223 y = y - (bubble->h / 2);
2224 _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
2225 //evas_object_raise(bubble->obj);
2229 _overlay_bubble_chase(Overlay_Bubble *bubble)
2231 EINA_SAFETY_ON_NULL_RETURN(bubble);
2232 EINA_SAFETY_ON_NULL_RETURN(bubble->pobj);
2235 evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
2236 x = x + (w / 2) - (bubble->w / 2);
2238 _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
2239 evas_object_raise(bubble->obj);
2243 _overlay_bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2245 EINA_SAFETY_ON_NULL_RETURN(data);
2246 _overlay_bubble_hide(data);
2250 _overlay_bubble_chase_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2252 EINA_SAFETY_ON_NULL_RETURN(data);
2253 _overlay_bubble_chase(data);
2257 _overlay_bubble_free(Overlay_Bubble* bubble)
2259 EINA_SAFETY_ON_NULL_RETURN(bubble);
2261 evas_object_del(bubble->bx);
2262 evas_object_del(bubble->sc);
2263 evas_object_del(bubble->obj);
2266 evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_HIDE,
2267 _overlay_bubble_hide_cb, bubble);
2268 evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_SHOW,
2269 _overlay_bubble_chase_cb, bubble);
2270 evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_MOVE,
2271 _overlay_bubble_chase_cb, bubble);
2276 static Overlay_Bubble*
2277 _overlay_bubble_new(Widget_Data *wd)
2279 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2283 Overlay_Bubble *bubble = ELM_NEW(Overlay_Bubble);
2286 bubble->obj = edje_object_add(evas_object_evas_get(wd->obj));
2287 _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
2288 elm_widget_style_get(wd->obj));
2289 evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
2290 _overlay_bubble_chase_cb, bubble);
2292 bubble->sc = elm_scroller_add(bubble->obj);
2293 elm_widget_style_set(bubble->sc, "map_bubble");
2294 elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
2295 elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
2296 ELM_SCROLLER_POLICY_OFF);
2297 elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
2299 edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
2301 bubble->bx = elm_box_add(bubble->sc);
2302 evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2303 evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
2305 elm_box_horizontal_set(bubble->bx, EINA_TRUE);
2306 elm_object_content_set(bubble->sc, bubble->bx);
2308 s = edje_object_data_get(bubble->obj, "size_w");
2309 if (s) bubble->w = atoi(s);
2312 edje_object_size_min_calc(bubble->obj, NULL, &(bubble->h));
2313 s = edje_object_data_get(bubble->obj, "size_h");
2316 if (bubble->h < h) bubble->h = h;
2326 _overlay_route_hide(Overlay_Route *r)
2328 EINA_SAFETY_ON_NULL_RETURN(r);
2331 EINA_LIST_FOREACH(r->paths, l, p) evas_object_hide(p);
2335 _overlay_route_show(Overlay_Route *r)
2337 EINA_SAFETY_ON_NULL_RETURN(r);
2338 EINA_SAFETY_ON_NULL_RETURN(r->wd);
2347 Evas_Coord ow, oh, px, py, size;
2350 _viewport_size_get(wd, &ow, &oh);
2355 EINA_LIST_FOREACH(r->paths, l, p) evas_object_polygon_points_clear(p);
2357 cnt = eina_list_count(r->nodes);
2358 EINA_LIST_FOREACH(r->nodes, l, n)
2360 if ((!wd->zoom) || ((n->idx) &&
2361 ((n->idx % (int)ceil((double)cnt/(double)size*100.0))))) continue;
2364 _geo_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
2366 if ((x >= px - ow) && (x <= (px + ow*2)) &&
2367 (y >= py - oh) && (y <= (py + oh*2)))
2372 p = eina_list_nth(r->paths, n->idx);
2373 a = (double)(y - r->y) / (double)(x - r->x);
2374 if ((abs(a) >= 1) || (r->x == x))
2376 evas_object_polygon_point_add(p, r->x - 3, r->y);
2377 evas_object_polygon_point_add(p, r->x + 3, r->y);
2378 evas_object_polygon_point_add(p, x + 3, y);
2379 evas_object_polygon_point_add(p, x - 3, y);
2383 evas_object_polygon_point_add(p, r->x, r->y - 3);
2384 evas_object_polygon_point_add(p, r->x, r->y + 3);
2385 evas_object_polygon_point_add(p, x, y + 3);
2386 evas_object_polygon_point_add(p, x, y - 3);
2389 evas_object_color_set(p, r->color.r, r->color.g, r->color.b,
2391 evas_object_raise(p);
2393 evas_object_show(p);
2398 else r->inbound = EINA_FALSE;
2402 _geo_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
2404 if ((x >= px - ow) && (x <= (px + ow*2)) &&
2405 (y >= py - oh) && (y <= (py + oh*2)))
2409 r->inbound = EINA_TRUE;
2411 else r->inbound = EINA_FALSE;
2414 r->inbound = EINA_FALSE;
2418 _overlay_route_free(Overlay_Route* route)
2420 EINA_SAFETY_ON_NULL_RETURN(route);
2424 EINA_LIST_FREE(route->paths, p) evas_object_del(p);
2425 EINA_LIST_FREE(route->nodes, n)
2427 if (n->pos.address) eina_stringshare_del(n->pos.address);
2433 static Overlay_Route *
2434 _overlay_route_new(Widget_Data *wd, const Elm_Map_Route *route)
2436 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2437 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
2442 Overlay_Route *ovl = ELM_NEW(Overlay_Route);
2444 ovl->inbound = EINA_FALSE;
2450 EINA_LIST_FOREACH(route->nodes, l, n)
2455 node = ELM_NEW(Path_Node);
2457 node->pos.lon = n->pos.lon;
2458 node->pos.lat = n->pos.lat;
2459 if (n->pos.address) node->pos.address = strdup(n->pos.address);
2460 ovl->nodes = eina_list_append(ovl->nodes, node);
2462 path = evas_object_polygon_add(evas_object_evas_get(wd->obj));
2463 evas_object_smart_member_add(path, wd->pan_smart);
2464 ovl->paths = eina_list_append(ovl->paths, path);
2470 _overlay_grouping(Eina_List *members, Elm_Map_Overlay *overlay)
2472 EINA_SAFETY_ON_NULL_RETURN(members);
2473 EINA_SAFETY_ON_NULL_RETURN(overlay);
2474 // Currently support only basic overlay type
2475 EINA_SAFETY_ON_FALSE_RETURN(overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT);
2478 Elm_Map_Overlay *overlay_memb;
2479 Eina_List *club_members = NULL;
2481 // Grouping only supports overlay default
2482 Overlay_Default *ovl = (Overlay_Default *)overlay->ovl;
2483 EINA_LIST_FOREACH(members, l, overlay_memb)
2485 Overlay_Default *ovl_memb = overlay_memb->ovl;
2486 if ((overlay_memb->hide) ||
2487 (overlay_memb->zoom_min > overlay_memb->wd->zoom)) continue;
2488 if (overlay == overlay_memb || overlay_memb->grp_in) continue;
2489 if (ELM_RECTS_INTERSECT(ovl_memb->x, ovl_memb->y, ovl_memb->w,
2490 ovl_memb->h, ovl->x, ovl->y,
2491 ovl->w * OVERLAY_GROUPING_SCALE,
2492 ovl->h * OVERLAY_GROUPING_SCALE))
2495 overlay_memb->grp_boss = EINA_FALSE;
2496 overlay_memb->grp_in = EINA_TRUE;
2497 club_members = eina_list_append(club_members, overlay_memb);
2498 _overlay_group_update(overlay_memb->wd, overlay_memb->grp, NULL);
2499 _overlay_group_cb_del(overlay_memb->grp);
2503 if (eina_list_count(club_members) >= 1)
2506 overlay->grp_boss = EINA_TRUE;
2507 overlay->grp_in = EINA_TRUE;
2508 club_members = eina_list_append(club_members, overlay);
2509 _overlay_group_update(overlay->wd, overlay->grp, club_members);
2510 _overlay_group_cb_del(overlay->grp);
2511 _overlay_group_cb_add(overlay->grp);
2516 _overlay_display(Widget_Data *wd, Elm_Map_Overlay *overlay)
2518 Eina_Bool hide = EINA_FALSE;
2520 if ((overlay->grp_in) || (overlay->hide) || (overlay->zoom_min > wd->zoom))
2522 if ((overlay->grp->clas) && ((overlay->grp->clas->hide) ||
2523 (overlay->grp->clas->zoom_min > wd->zoom)))
2526 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2528 if (hide) _overlay_default_hide(overlay->ovl);
2529 else _overlay_default_show(wd, overlay->ovl);
2531 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
2533 if (hide) _overlay_bubble_hide(overlay->ovl);
2534 else _overlay_bubble_show(overlay->ovl);
2536 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
2538 if (hide) _overlay_route_hide(overlay->ovl);
2539 else _overlay_route_show(overlay->ovl);
2544 _overlay_place(Widget_Data *wd)
2546 EINA_SAFETY_ON_NULL_RETURN(wd);
2549 Elm_Map_Overlay *overlay, *grp;
2551 if (eina_list_count(wd->overlays) == 0) return;
2553 // Reset overlays coord & grp except class type
2554 EINA_LIST_FOREACH(wd->overlays, l, overlay)
2557 if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS) continue;
2558 if (overlay->paused) continue;
2559 if ((overlay->grp) && (overlay->grp->clas) &&
2560 (overlay->grp->clas->paused)) continue;
2561 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2563 Overlay_Class *ovl_grp = NULL;
2564 if (overlay->grp->clas) ovl_grp = overlay->grp->clas->ovl;
2565 _overlay_default_update(wd, overlay->ovl, NULL, NULL, ovl_grp,
2568 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
2569 _overlay_bubble_update(overlay->ovl);
2571 overlay->grp_in = EINA_FALSE;
2572 overlay->grp_boss = EINA_FALSE;
2573 _overlay_group_update(wd, overlay->grp, NULL);
2576 // Classify into group idol or follwer
2577 EINA_LIST_FOREACH(wd->overlays, l, grp)
2579 Elm_Map_Overlay *idol;
2582 if (grp->type != ELM_MAP_OVERLAY_TYPE_CLASS) continue;
2583 if ((grp->hide) || (grp->zoom_min > wd->zoom)) continue;
2586 if (ovl->zoom_max < wd->zoom) continue;
2587 EINA_LIST_FOREACH(ovl->members, ll, idol)
2589 if (!idol->grp_in) _overlay_grouping(ovl->members, idol);
2594 EINA_LIST_FOREACH(wd->overlays, l, overlay)
2595 if (overlay->type != ELM_MAP_OVERLAY_TYPE_CLASS)
2596 _overlay_display(wd, overlay);
2598 // Place group overlays
2599 EINA_LIST_FOREACH(wd->overlays, l, overlay)
2601 if (overlay->grp_boss) _overlay_default_show(wd, overlay->grp->ovl);
2605 static Evas_Object *
2606 _overlay_obj_get(Elm_Map_Overlay *overlay)
2608 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
2609 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2611 Overlay_Default *ovl = overlay->ovl;
2616 ERR("Not supported overlay type: %d", overlay->type);
2622 _overlays_show(void *data)
2624 EINA_SAFETY_ON_NULL_RETURN(data);
2625 Delayed_Data *dd = data;
2628 double max_lon, min_lon, max_lat, min_lat;
2631 _region_max_min_get(dd->overlays, &max_lon, &min_lon, &max_lat, &min_lat);
2632 dd->lon = (max_lon + min_lon) / 2;
2633 dd->lat = (max_lat + min_lat) / 2;
2635 zoom = dd->wd->src_tile->zoom_min;
2636 _viewport_size_get(dd->wd, &vw, &vh);
2637 while (zoom <= dd->wd->src_tile->zoom_max)
2639 Evas_Coord size, max_x, max_y, min_x, min_y;
2640 size = pow(2.0, zoom) * dd->wd->tsize;
2641 _geo_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
2642 _geo_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
2643 if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
2648 zoom_do(dd->wd, zoom);
2650 evas_object_smart_changed(dd->wd->pan_smart);
2654 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2656 Pan *sd = evas_object_smart_data_get(obj);
2657 EINA_SAFETY_ON_NULL_RETURN(sd);
2658 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2662 evas_object_smart_changed(obj);
2666 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2668 Pan *sd = evas_object_smart_data_get(obj);
2669 EINA_SAFETY_ON_NULL_RETURN(sd);
2670 if (x) *x = sd->wd->pan_x;
2671 if (y) *y = sd->wd->pan_y;
2675 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2677 Pan *sd = evas_object_smart_data_get(obj);
2678 EINA_SAFETY_ON_NULL_RETURN(sd);
2680 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2681 ow = sd->wd->size.w - ow;
2682 oh = sd->wd->size.h - oh;
2690 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2697 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2699 Pan *sd = evas_object_smart_data_get(obj);
2700 EINA_SAFETY_ON_NULL_RETURN(sd);
2701 if (w) *w = sd->wd->size.w;
2702 if (h) *h = sd->wd->size.h;
2706 _pan_add(Evas_Object *obj)
2709 Evas_Object_Smart_Clipped_Data *cd;
2711 cd = evas_object_smart_data_get(obj);
2712 EINA_SAFETY_ON_NULL_RETURN(cd);
2714 sd->__clipped_data = *cd;
2716 evas_object_smart_data_set(obj, sd);
2720 _pan_resize(Evas_Object *obj, Evas_Coord w __UNUSED__, Evas_Coord h __UNUSED__)
2722 Pan *sd = evas_object_smart_data_get(obj);
2723 EINA_SAFETY_ON_NULL_RETURN(sd);
2725 _sizing_eval(sd->wd);
2726 elm_map_zoom_mode_set(sd->wd->obj, sd->wd->mode);
2727 evas_object_smart_changed(obj);
2731 _pan_calculate(Evas_Object *obj)
2733 Pan *sd = evas_object_smart_data_get(obj);
2734 EINA_SAFETY_ON_NULL_RETURN(sd);
2737 evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &w, &h);
2738 if (w <= 0 || h <= 0) return;
2740 _grid_place(sd->wd);
2741 _marker_place(sd->wd);
2742 _overlay_place(sd->wd);
2743 _track_place(sd->wd);
2744 _delayed_do(sd->wd);
2748 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2750 EINA_SAFETY_ON_NULL_RETURN(obj);
2751 evas_object_smart_changed(obj);
2755 _hold_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2757 EINA_SAFETY_ON_NULL_RETURN(data);
2758 Widget_Data *wd = data;
2759 elm_smart_scroller_hold_set(wd->scr, 1);
2763 _hold_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2765 EINA_SAFETY_ON_NULL_RETURN(data);
2766 Widget_Data *wd = data;
2767 elm_smart_scroller_hold_set(wd->scr, 0);
2771 _freeze_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2773 EINA_SAFETY_ON_NULL_RETURN(data);
2774 Widget_Data *wd = data;
2775 elm_smart_scroller_freeze_set(wd->scr, 1);
2779 _freeze_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2781 EINA_SAFETY_ON_NULL_RETURN(data);
2782 Widget_Data *wd = data;
2783 elm_smart_scroller_freeze_set(wd->scr, 0);
2787 _elm_map_marker_remove(Elm_Map_Marker *marker)
2789 #ifdef HAVE_ELEMENTARY_ECORE_CON
2790 EINA_SAFETY_ON_NULL_RETURN(marker);
2791 Widget_Data *wd = marker->wd;
2792 EINA_SAFETY_ON_NULL_RETURN(wd);
2794 if ((marker->content) && (marker->clas->func.del))
2795 marker->clas->func.del(wd->obj, marker, marker->data, marker->content);
2797 if (marker->bubble) _bubble_free(marker->bubble);
2798 if (marker->group) _marker_group_free(marker->group);
2800 if (marker->group_clas)
2801 marker->group_clas->markers = eina_list_remove(marker->group_clas->markers, marker);
2802 wd->markers = eina_list_remove(wd->markers, marker);
2804 evas_object_del(marker->obj);
2807 evas_object_smart_changed(wd->pan_smart);
2814 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2816 ELM_CHECK_WIDTYPE(obj, widtype);
2817 Widget_Data *wd = elm_widget_data_get(obj);
2818 EINA_SAFETY_ON_NULL_RETURN(wd);
2820 if (elm_widget_focus_get(obj))
2822 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2823 evas_object_focus_set(wd->obj, EINA_TRUE);
2827 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2828 evas_object_focus_set(wd->obj, EINA_FALSE);
2833 _del_hook(Evas_Object *obj)
2835 ELM_CHECK_WIDTYPE(obj, widtype);
2836 Widget_Data *wd = elm_widget_data_get(obj);
2837 EINA_SAFETY_ON_NULL_RETURN(wd);
2839 if (wd->map) evas_map_free(wd->map);
2844 _del_pre_hook(Evas_Object *obj)
2846 ELM_CHECK_WIDTYPE(obj, widtype);
2847 Widget_Data *wd = elm_widget_data_get(obj);
2848 EINA_SAFETY_ON_NULL_RETURN(wd);
2854 Elm_Map_Marker *marker;
2855 Elm_Map_Group_Class *group_clas;
2856 Elm_Map_Marker_Class *clas;
2857 Elm_Map_Overlay *overlay;
2864 EINA_LIST_FOREACH_SAFE(wd->routes, l, ll, r) elm_map_route_del(r);
2865 eina_list_free(wd->routes);
2867 EINA_LIST_FOREACH_SAFE(wd->names, l, ll, na) elm_map_name_del(na);
2868 eina_list_free(wd->names);
2870 EINA_LIST_FOREACH_SAFE(wd->overlays, l, ll, overlay)
2871 elm_map_overlay_del(overlay);
2872 eina_list_free(wd->overlays);
2874 EINA_LIST_FREE(wd->track, track) evas_object_del(track);
2876 EINA_LIST_FOREACH_SAFE(wd->markers, l, ll, marker)
2877 _elm_map_marker_remove(marker);
2878 eina_list_free(wd->markers);
2880 EINA_LIST_FREE(wd->group_classes, group_clas)
2882 eina_list_free(group_clas->markers);
2883 if (group_clas->style) eina_stringshare_del(group_clas->style);
2886 EINA_LIST_FREE(wd->marker_classes, clas)
2888 if (clas->style) eina_stringshare_del(clas->style);
2892 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2893 if (wd->long_timer) ecore_timer_del(wd->long_timer);
2895 if (wd->delayed_jobs) EINA_LIST_FREE(wd->delayed_jobs, dd) free(dd);
2897 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2898 if (wd->ua) eina_hash_free(wd->ua);
2900 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
2901 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2903 _grid_all_clear(wd);
2904 // Removal of download list should be after grid clear.
2905 if (wd->download_idler) ecore_idler_del(wd->download_idler);
2906 eina_list_free(wd->download_list);
2908 for (idx = 0; wd->src_tile_names[idx]; idx++)
2909 eina_stringshare_del(wd->src_tile_names[idx]);
2910 EINA_LIST_FREE(wd->src_tiles, ts) free(ts);
2912 for (idx = 0; wd->src_route_names[idx]; idx++)
2913 eina_stringshare_del(wd->src_route_names[idx]);
2914 EINA_LIST_FREE(wd->src_routes, rs) free(rs);
2916 for (idx = 0; wd->src_name_names[idx]; idx++)
2917 eina_stringshare_del(wd->src_name_names[idx]);
2918 EINA_LIST_FREE(wd->src_names, ns) free(ns);
2920 if (!ecore_file_recursive_rm(CACHE_ROOT))
2921 ERR("Deletion of %s failed", CACHE_ROOT);
2925 _theme_hook(Evas_Object *obj)
2927 ELM_CHECK_WIDTYPE(obj, widtype);
2928 Widget_Data *wd = elm_widget_data_get(obj);
2929 EINA_SAFETY_ON_NULL_RETURN(wd);
2931 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2936 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2938 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2939 Widget_Data *wd = elm_widget_data_get(obj);
2940 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
2944 Evas_Coord step_x, step_y, page_x, page_y;
2946 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2947 Evas_Event_Key_Down *ev = event_info;
2948 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2950 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2951 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2952 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2953 _viewport_size_get(wd, NULL, &vh);
2955 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2959 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2963 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2967 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2971 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2974 y -= -(page_y * vh) / 100;
2978 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2981 y += -(page_y * vh) / 100;
2985 else if (!strcmp(ev->keyname, "KP_Add"))
2987 zoom_with_animation(wd, wd->zoom + 1, 10);
2990 else if (!strcmp(ev->keyname, "KP_Subtract"))
2992 zoom_with_animation(wd, wd->zoom - 1, 10);
2995 else return EINA_FALSE;
2997 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2998 elm_smart_scroller_child_pos_set(wd->scr, x, y);
3004 cb_dump_name_attrs(void *data, const char *key, const char *value)
3006 Name_Dump *dump = (Name_Dump*)data;
3007 if (!dump) return EINA_FALSE;
3009 if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
3010 else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
3016 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
3018 Route_Dump *dump = data;
3019 if (!dump) return EINA_FALSE;
3023 case EINA_SIMPLE_XML_OPEN:
3024 case EINA_SIMPLE_XML_OPEN_EMPTY:
3028 attrs = eina_simple_xml_tag_attributes_find(value, length);
3031 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
3032 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
3033 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
3034 else dump->id = ROUTE_XML_NONE;
3038 case EINA_SIMPLE_XML_DATA:
3040 char *buf = malloc(length);
3041 if (!buf) return EINA_FALSE;
3042 snprintf(buf, length, "%s", value);
3043 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
3044 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
3045 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
3057 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
3059 Name_Dump *dump = data;
3060 if (!dump) return EINA_FALSE;
3064 case EINA_SIMPLE_XML_OPEN:
3065 case EINA_SIMPLE_XML_OPEN_EMPTY:
3068 attrs = eina_simple_xml_tag_attributes_find(value, length);
3071 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
3072 else dump->id = NAME_XML_NONE;
3074 eina_simple_xml_attributes_parse
3075 (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
3079 case EINA_SIMPLE_XML_DATA:
3081 char *buf = malloc(length + 1);
3082 if (!buf) return EINA_FALSE;
3083 snprintf(buf, length + 1, "%s", value);
3084 if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
3096 _kml_parse(Elm_Map_Route *r)
3098 EINA_SAFETY_ON_NULL_RETURN(r);
3099 EINA_SAFETY_ON_NULL_RETURN(r->fname);
3103 unsigned int ele, idx;
3106 Route_Dump dump = {0, r->fname, 0.0, NULL, NULL};
3108 f = fopen(r->fname, "rb");
3113 fseek(f, 0, SEEK_END);
3119 fseek(f, 0, SEEK_SET);
3123 if (fread(buf, 1, sz, f))
3125 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump,
3133 if (dump.distance) r->info.distance = dump.distance;
3134 if (dump.description)
3136 eina_stringshare_replace(&r->info.waypoints, dump.description);
3137 str = eina_str_split_full(dump.description, "\n", 0, &ele);
3138 r->info.waypoint_count = ele;
3139 for (idx = 0; idx < ele; idx++)
3141 Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
3145 wp->point = eina_stringshare_add(str[idx]);
3146 DBG("%s", str[idx]);
3147 r->waypoint = eina_list_append(r->waypoint, wp);
3156 else WRN("description is not found !");
3158 if (dump.coordinates)
3160 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
3161 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
3162 r->info.node_count = ele;
3163 for (idx = 0; idx < ele; idx++)
3165 sscanf(str[idx], "%lf,%lf", &lon, &lat);
3166 Path_Node *n = ELM_NEW(Path_Node);
3173 DBG("%lf:%lf", lon, lat);
3174 n->pos.address = NULL;
3175 r->nodes = eina_list_append(r->nodes, n);
3188 _name_parse(Elm_Map_Name *n)
3190 EINA_SAFETY_ON_NULL_RETURN(n);
3191 EINA_SAFETY_ON_NULL_RETURN(n->fname);
3195 Name_Dump dump = {0, NULL, 0.0, 0.0};
3197 f = fopen(n->fname, "rb");
3202 fseek(f, 0, SEEK_END);
3208 fseek(f, 0, SEEK_SET);
3212 if (fread(buf, 1, sz, f))
3214 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3223 INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3224 n->address = strdup(dump.address);
3231 Grid *_get_current_grid(Widget_Data *wd)
3233 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
3235 Grid *g = NULL, *ret = NULL;
3236 EINA_LIST_FOREACH(wd->grids, l, g)
3238 if (wd->zoom == g->zoom)
3248 _route_cb(void *data, const char *file, int status)
3250 EINA_SAFETY_ON_NULL_RETURN(data);
3251 EINA_SAFETY_ON_NULL_RETURN(file);
3253 Elm_Map_Route *route = data;
3254 Widget_Data *wd = route->wd;
3255 EINA_SAFETY_ON_NULL_RETURN(wd);
3261 INF("Route request success from (%lf, %lf) to (%lf, %lf)",
3262 route->flon, route->flat, route->tlon, route->tlat);
3263 if (route->cb) route->cb(route->data, wd->obj, route);
3264 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3268 ERR("Route request failed: %d", status);
3269 if (route->cb) route->cb(route->data, wd->obj, NULL);
3270 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED_FAIL, NULL);
3273 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3274 "elm,state,busy,stop", "elm");
3278 _name_cb(void *data, const char *file, int status)
3280 EINA_SAFETY_ON_NULL_RETURN(data);
3281 EINA_SAFETY_ON_NULL_RETURN(file);
3283 Elm_Map_Name *name = data;
3284 Widget_Data *wd = name->wd;
3285 EINA_SAFETY_ON_NULL_RETURN(wd);
3291 INF("Name request success address:%s, lon:%lf, lat:%lf",
3292 name->address, name->lon, name->lat);
3293 if (name->cb) name->cb(name->data, wd->obj, name);
3294 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3298 ERR("Name request failed: %d", status);
3299 if (name->cb) name->cb(name->data, wd->obj, NULL);
3300 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED_FAIL, NULL);
3302 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3303 "elm,state,busy,stop", "elm");
3308 static Elm_Map_Name *
3309 _name_request(const Evas_Object *obj, int method, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
3311 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3312 Widget_Data *wd = elm_widget_data_get(obj);
3313 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
3314 EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_name, NULL);
3318 char fname[PATH_MAX];
3320 if (!ecore_file_exists(CACHE_NAME_ROOT)) ecore_file_mkpath(CACHE_NAME_ROOT);
3322 url = wd->src_name->url_cb(wd->obj, method, address, lon, lat);
3325 ERR("Name URL is NULL");
3329 Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3331 snprintf(fname, sizeof(fname), CACHE_NAME_ROOT"/%d", rand());
3332 name->fname = strdup(fname);
3333 name->method = method;
3334 if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3335 else if (method == ELM_MAP_NAME_METHOD_REVERSE)
3343 if (!ecore_file_download_full(url, name->fname, _name_cb, NULL, name,
3344 &(name->job), wd->ua) || !(name->job))
3346 ERR("Can't request Name from %s to %s", url, name->fname);
3347 if (name->address) free(name->address);
3352 INF("Name requested from %s to %s", url, name->fname);
3355 wd->names = eina_list_append(wd->names, name);
3356 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, name);
3357 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3358 "elm,state,busy,start", "elm");
3362 static Evas_Event_Flags
3363 _pinch_zoom_start_cb(void *data, void *event_info __UNUSED__)
3365 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EVAS_EVENT_FLAG_NONE);
3366 Widget_Data *wd = data;
3368 wd->pinch_zoom = wd->zoom_detail;
3369 return EVAS_EVENT_FLAG_NONE;
3372 static Evas_Event_Flags
3373 _pinch_zoom_cb(void *data, void *event_info)
3375 Widget_Data *wd = data;
3376 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3380 Elm_Gesture_Zoom_Info *ei = event_info;
3381 zoom_do(wd, wd->pinch_zoom + ei->zoom - 1);
3383 return EVAS_EVENT_FLAG_NONE;
3386 static Evas_Event_Flags
3387 _pinch_rotate_cb(void *data, void *event_info)
3389 Widget_Data *wd = data;
3390 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3395 Elm_Gesture_Rotate_Info *ei = event_info;
3396 evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
3398 wd->rotate.d = wd->rotate.a + ei->angle - ei->base_angle;
3399 wd->rotate.cx = x + ((double)w * 0.5);
3400 wd->rotate.cy = y + ((double)h * 0.5);
3402 evas_object_smart_changed(wd->pan_smart);
3404 return EVAS_EVENT_FLAG_NONE;
3407 static Evas_Event_Flags
3408 _pinch_rotate_end_cb(void *data, void *event_info __UNUSED__)
3410 Widget_Data *wd = data;
3411 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3413 wd->rotate.a = wd->rotate.d;
3415 return EVAS_EVENT_FLAG_NONE;
3419 _source_tile_mod_cb(Eina_Module *m, void *data)
3421 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3423 Widget_Data *wd = data;
3425 Elm_Map_Module_Source_Name_Func name_cb;
3426 Elm_Map_Module_Tile_Zoom_Min_Func zoom_min;
3427 Elm_Map_Module_Tile_Zoom_Max_Func zoom_max;
3428 Elm_Map_Module_Tile_Url_Func url_cb;
3429 Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
3430 Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
3433 file = eina_module_file_get(m);
3434 if (!eina_module_load(m))
3436 ERR("Could not load module \"%s\": %s", file,
3437 eina_error_msg_get(eina_error_get()));
3441 name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3442 zoom_min = eina_module_symbol_get(m, "map_module_tile_zoom_min_get");
3443 zoom_max = eina_module_symbol_get(m, "map_module_tile_zoom_max_get");
3444 url_cb = eina_module_symbol_get(m, "map_module_tile_url_get");
3445 geo_to_coord = eina_module_symbol_get(m, "map_module_tile_geo_to_coord");
3446 coord_to_geo = eina_module_symbol_get(m, "map_module_tile_coord_to_geo");
3448 if ((!name_cb) || (!zoom_min) || (!zoom_max) || (!url_cb) ||
3449 (!geo_to_coord) || (!coord_to_geo))
3451 WRN("Could not find map module functions from module \"%s\": %s",
3452 file, eina_error_msg_get(eina_error_get()));
3453 eina_module_unload(m);
3456 s = ELM_NEW(Source_Tile);
3457 s->name = name_cb();
3458 s->zoom_min = zoom_min();
3459 s->zoom_max = zoom_max();
3461 s->geo_to_coord = geo_to_coord;
3462 s->coord_to_geo = coord_to_geo;
3463 wd->src_tiles = eina_list_append(wd->src_tiles, s);
3465 eina_module_unload(m);
3470 _source_tile_load(Widget_Data *wd)
3475 Eina_Array *modules = NULL;
3477 // Load from hard coded data
3478 for (idx = 0; idx < (sizeof(src_tiles) / sizeof(Source_Tile)); idx++)
3480 s= ELM_NEW(Source_Tile);
3481 s->name = src_tiles[idx].name;
3482 s->zoom_min = src_tiles[idx].zoom_min;
3483 s->zoom_max = src_tiles[idx].zoom_max;
3484 s->url_cb = src_tiles[idx].url_cb;
3485 s->geo_to_coord = src_tiles[idx].geo_to_coord;
3486 s->coord_to_geo = src_tiles[idx].coord_to_geo;
3487 wd->src_tiles = eina_list_append(wd->src_tiles, s);
3490 // Load from modules
3491 modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_tile_mod_cb, wd);
3492 eina_array_free(modules);
3494 // Set default source
3495 wd->src_tile = eina_list_nth(wd->src_tiles, 0);
3497 // Make name strings
3499 wd->src_tile_names = calloc((eina_list_count(wd->src_tiles) + 1),
3501 EINA_LIST_FOREACH(wd->src_tiles, l, s)
3503 eina_stringshare_replace(&wd->src_tile_names[idx], s->name);
3504 INF("source : %s", wd->src_tile_names[idx]);
3510 _source_tile_set(Widget_Data *wd, const char *source_name)
3512 EINA_SAFETY_ON_NULL_RETURN(wd);
3513 EINA_SAFETY_ON_NULL_RETURN(source_name);
3517 if (wd->src_tile && !strcmp(wd->src_tile->name, source_name)) return;
3519 EINA_LIST_FOREACH(wd->src_tiles, l, s)
3521 if (!strcmp(s->name, source_name))
3529 ERR("source name (%s) is not found", source_name);
3533 if (wd->src_tile->zoom_max < wd->zoom)
3534 wd->zoom = wd->src_tile->zoom_max;
3535 else if (wd->src_tile->zoom_min > wd->zoom)
3536 wd->zoom = wd->src_tile->zoom_min;
3538 if (wd->src_tile->zoom_max < wd->zoom_max)
3539 wd->zoom_max = wd->src_tile->zoom_max;
3540 if (wd->src_tile->zoom_min > wd->zoom_min)
3541 wd->zoom_min = wd->src_tile->zoom_min;
3543 _grid_all_clear(wd);
3544 _grid_all_create(wd);
3545 zoom_do(wd, wd->zoom);
3549 _source_route_mod_cb(Eina_Module *m, void *data)
3551 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3553 Widget_Data *wd = data;
3555 Elm_Map_Module_Source_Name_Func name_cb;
3556 Elm_Map_Module_Route_Url_Func url_cb;
3559 file = eina_module_file_get(m);
3560 if (!eina_module_load(m))
3562 ERR("Could not load module \"%s\": %s", file,
3563 eina_error_msg_get(eina_error_get()));
3567 name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3568 url_cb = eina_module_symbol_get(m, "map_module_route_url_get");
3570 if ((!name_cb) || (!url_cb))
3572 WRN("Could not find map module functions from module \"%s\": %s",
3573 file, eina_error_msg_get(eina_error_get()));
3574 eina_module_unload(m);
3577 s = ELM_NEW(Source_Tile);
3578 s->name = name_cb();
3580 wd->src_routes = eina_list_append(wd->src_routes, s);
3582 eina_module_unload(m);
3587 _source_route_load(Widget_Data *wd)
3592 Eina_Array *modules = NULL;
3594 // Load from hard coded data
3595 for (idx = 0; idx < (sizeof(src_routes) / sizeof(Source_Route)); idx++)
3597 s= ELM_NEW(Source_Route);
3598 s->name = src_routes[idx].name;
3599 s->url_cb = src_routes[idx].url_cb;
3600 wd->src_routes = eina_list_append(wd->src_routes, s);
3603 // Load from modules
3604 modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_route_mod_cb, wd);
3605 eina_array_free(modules);
3607 // Set default source
3608 wd->src_route = eina_list_nth(wd->src_routes, 0);
3610 // Make name strings
3612 wd->src_route_names = calloc((eina_list_count(wd->src_routes) + 1),
3614 EINA_LIST_FOREACH(wd->src_routes, l, s)
3616 eina_stringshare_replace(&wd->src_route_names[idx], s->name);
3617 INF("source : %s", wd->src_route_names[idx]);
3623 _source_route_set(Widget_Data *wd, const char *source_name)
3625 EINA_SAFETY_ON_NULL_RETURN(wd);
3626 EINA_SAFETY_ON_NULL_RETURN(source_name);
3630 if (wd->src_route && !strcmp(wd->src_route->name, source_name)) return;
3632 EINA_LIST_FOREACH(wd->src_routes, l, s)
3634 if (!strcmp(s->name, source_name))
3642 ERR("source name (%s) is not found", source_name);
3648 _source_name_mod_cb(Eina_Module *m, void *data)
3650 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3652 Widget_Data *wd = data;
3654 Elm_Map_Module_Source_Name_Func name_cb;
3655 Elm_Map_Module_Name_Url_Func url_cb;
3658 file = eina_module_file_get(m);
3659 if (!eina_module_load(m))
3661 ERR("Could not load module \"%s\": %s", file,
3662 eina_error_msg_get(eina_error_get()));
3666 name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3667 url_cb = eina_module_symbol_get(m, "map_module_name_url_get");
3669 if ((!name_cb) || (!url_cb))
3671 WRN("Could not find map module functions from module \"%s\": %s",
3672 file, eina_error_msg_get(eina_error_get()));
3673 eina_module_unload(m);
3676 s = ELM_NEW(Source_Tile);
3677 s->name = name_cb();
3679 wd->src_names = eina_list_append(wd->src_names, s);
3681 eina_module_unload(m);
3686 _source_name_load(Widget_Data *wd)
3691 Eina_Array *modules = NULL;
3693 // Load from hard coded data
3694 for (idx = 0; idx < (sizeof(src_names) / sizeof(Source_Name)); idx++)
3696 s= ELM_NEW(Source_Name);
3697 s->name = src_names[idx].name;
3698 s->url_cb = src_names[idx].url_cb;
3699 wd->src_names = eina_list_append(wd->src_names, s);
3702 // Load from modules
3703 modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_name_mod_cb, wd);
3704 eina_array_free(modules);
3706 // Set default source
3707 wd->src_name = eina_list_nth(wd->src_names, 0);
3709 // Make name strings
3711 wd->src_name_names = calloc((eina_list_count(wd->src_names) + 1),
3713 EINA_LIST_FOREACH(wd->src_names, l, s)
3715 eina_stringshare_replace(&wd->src_name_names[idx], s->name);
3716 INF("source : %s", wd->src_name_names[idx]);
3722 _source_name_set(Widget_Data *wd, const char *source_name)
3724 EINA_SAFETY_ON_NULL_RETURN(wd);
3725 EINA_SAFETY_ON_NULL_RETURN(source_name);
3730 if (wd->src_name && !strcmp(wd->src_name->name, source_name)) return;
3732 EINA_LIST_FOREACH(wd->src_names, l, s)
3734 if (!strcmp(s->name, source_name))
3742 ERR("source name (%s) is not found", source_name);
3748 _source_all_load(Widget_Data *wd)
3750 EINA_SAFETY_ON_NULL_RETURN(wd);
3751 _source_tile_load(wd);
3752 _source_route_load(wd);
3753 _source_name_load(wd);
3757 _zoom_mode_set(void *data)
3759 EINA_SAFETY_ON_NULL_RETURN(data);
3760 Delayed_Data *dd = data;
3762 dd->wd->mode = dd->mode;
3763 if (dd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3773 zoom = dd->wd->zoom_detail;
3774 _viewport_size_get(dd->wd, &vw, &vh);
3776 if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3778 if ((w < vw) && (h < vh))
3781 while ((w < vw) && (h < vh))
3784 w = pow(2.0, zoom) * dd->wd->tsize;
3785 h = pow(2.0, zoom) * dd->wd->tsize;
3791 while ((w > vw) || (h > vh))
3794 w = pow(2.0, zoom) * dd->wd->tsize;
3795 h = pow(2.0, zoom) * dd->wd->tsize;
3800 else if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3802 if ((w < vw) || (h < vh))
3805 while ((w < vw) || (h < vh))
3808 w = pow(2.0, zoom) * dd->wd->tsize;
3809 h = pow(2.0, zoom) * dd->wd->tsize;
3815 while ((w > vw) && (h > vh))
3818 w = pow(2.0, zoom) * dd->wd->tsize;
3819 h = pow(2.0, zoom) * dd->wd->tsize;
3823 zoom_with_animation(dd->wd, zoom, 10);
3828 _zoom_set(void *data)
3830 EINA_SAFETY_ON_NULL_RETURN(data);
3831 Delayed_Data *dd = data;
3833 if (dd->wd->paused) zoom_do(dd->wd, dd->zoom);
3834 else zoom_with_animation(dd->wd, dd->zoom, 10);
3835 evas_object_smart_changed(dd->wd->pan_smart);
3839 _region_bring_in(void *data)
3841 EINA_SAFETY_ON_NULL_RETURN(data);
3842 Delayed_Data *dd = data;
3845 _geo_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
3846 _viewport_size_get(dd->wd, &w, &h);
3849 elm_smart_scroller_region_bring_in(dd->wd->scr, x, y, w, h);
3850 evas_object_smart_changed(dd->wd->pan_smart);
3854 _marker_list_show(void *data)
3856 EINA_SAFETY_ON_NULL_RETURN(data);
3857 Delayed_Data *dd = data;
3859 double max_lon = -180, min_lon = 180;
3860 double max_lat = -90, min_lat = 90;
3862 Elm_Map_Marker *marker;
3864 EINA_LIST_FREE(dd->markers, marker)
3866 if (marker->longitude > max_lon) max_lon = marker->longitude;
3867 if (marker->longitude < min_lon) min_lon = marker->longitude;
3868 if (marker->latitude > max_lat) max_lat = marker->latitude;
3869 if (marker->latitude < min_lat) min_lat = marker->latitude;
3871 dd->lon = (max_lon + min_lon) / 2;
3872 dd->lat = (max_lat + min_lat) / 2;
3874 zoom = dd->wd->src_tile->zoom_min;
3875 _viewport_size_get(dd->wd, &vw, &vh);
3876 while (zoom <= dd->wd->src_tile->zoom_max)
3878 Evas_Coord size, max_x, max_y, min_x, min_y;
3879 size = pow(2.0, zoom) * dd->wd->tsize;
3880 _geo_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
3881 _geo_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
3882 if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
3887 zoom_do(dd->wd, zoom);
3889 evas_object_smart_changed(dd->wd->pan_smart);
3893 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3896 // ((x+y+zoom)%3)+'a' is requesting map images from distributed tile servers (eg., a, b, c)
3897 snprintf(buf, sizeof(buf), "http://%c.tile.openstreetmap.org/%d/%d/%d.png",
3898 ((x + y + zoom) % 3) + 'a', zoom, x, y);
3903 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3906 snprintf(buf, sizeof(buf),
3907 "http://%c.tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
3908 ((x + y + zoom) % 3) + 'a', zoom, x, y);
3913 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3916 snprintf(buf, sizeof(buf),
3917 "http://%c.tile.opencyclemap.org/cycle/%d/%d/%d.png",
3918 (( x + y + zoom) % 3) + 'a', zoom, x, y);
3923 _mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3926 snprintf(buf, sizeof(buf),
3927 "http://otile%d.mqcdn.com/tiles/1.0.0/osm/%d/%d/%d.png",
3928 ((x + y + zoom) % 4) + 1, zoom, x, y);
3933 _mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3936 snprintf(buf, sizeof(buf), "http://oatile%d.mqcdn.com/naip/%d/%d/%d.png",
3937 ((x + y + zoom) % 4) + 1, zoom, x, y);
3941 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat)
3944 snprintf(buf, sizeof(buf),
3945 "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
3946 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
3951 // TODO: fix monav api
3953 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
3956 snprintf(buf, sizeof(buf),
3957 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
3958 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
3964 // TODO: fix ors api
3966 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
3969 snprintf(buf, sizeof(buf),
3970 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
3971 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
3978 _nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat)
3980 ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
3981 Widget_Data *wd = elm_widget_data_get(obj);
3982 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, strdup(""));
3985 unsigned int ele, idx;
3986 char search_url[PATH_MAX];
3989 if (method == ELM_MAP_NAME_METHOD_SEARCH)
3991 search_url[0] = '\0';
3992 str = eina_str_split_full(name, " ", 0, &ele);
3993 for (idx = 0; idx < ele; idx++)
3995 eina_strlcat(search_url, str[idx], sizeof(search_url));
3996 if (!(idx == (ele-1)))
3997 eina_strlcat(search_url, "+", sizeof(search_url));
3999 snprintf(buf, sizeof(buf),
4000 "%s/search?q=%s&format=xml&polygon=0&addressdetails=0",
4001 NAME_NOMINATIM_URL, search_url);
4009 else if (method == ELM_MAP_NAME_METHOD_REVERSE)
4010 snprintf(buf, sizeof(buf),
4011 "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0",
4012 NAME_NOMINATIM_URL, lat, lon, (int)wd->zoom);
4013 else strcpy(buf, "");
4023 elm_map_add(Evas_Object *parent)
4025 #ifdef HAVE_ELEMENTARY_ECORE_CON
4029 Evas_Coord minw, minh;
4031 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
4032 ELM_SET_WIDTYPE(widtype, "map");
4033 elm_widget_type_set(obj, "map");
4034 elm_widget_sub_object_add(parent, obj);
4035 elm_widget_data_set(obj, wd);
4036 elm_widget_can_focus_set(obj, EINA_TRUE);
4037 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
4038 elm_widget_del_hook_set(obj, _del_hook);
4039 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
4040 elm_widget_theme_hook_set(obj, _theme_hook);
4041 elm_widget_event_hook_set(obj, _event_hook);
4042 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, wd);
4043 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, wd);
4044 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, wd);
4045 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, wd);
4046 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
4048 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
4050 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
4051 _mouse_wheel_cb,wd);
4054 wd->scr = elm_smart_scroller_add(e);
4055 elm_widget_sub_object_add(obj, wd->scr);
4056 elm_smart_scroller_widget_set(wd->scr, obj);
4057 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
4058 elm_widget_resize_object_set(obj, wd->scr);
4059 elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
4060 elm_smart_scroller_bounce_allow_set(wd->scr,
4061 _elm_config->thumbscroll_bounce_enable,
4062 _elm_config->thumbscroll_bounce_enable);
4063 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
4064 _changed_size_hints, wd);
4065 evas_object_smart_callback_add(wd->scr, "scroll", _scr, wd);
4066 evas_object_smart_callback_add(wd->scr, "drag", _scr, wd);
4067 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, wd);
4068 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, wd);
4072 evas_object_smart_clipped_smart_set(&parent_sc);
4074 sc.name = "elm_map_pan";
4075 sc.version = EVAS_SMART_CLASS_VERSION;
4077 sc.resize = _pan_resize;
4078 sc.move = _pan_move;
4079 sc.calculate = _pan_calculate;
4080 smart = evas_smart_class_new(&sc);
4085 wd->pan_smart = evas_object_smart_add(e, smart);
4086 pan = evas_object_smart_data_get(wd->pan_smart);
4089 elm_widget_sub_object_add(obj, wd->pan_smart);
4091 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
4092 _pan_set, _pan_get, _pan_max_get,
4093 _pan_min_get, _pan_child_size_get);
4094 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
4096 evas_object_size_hint_min_set(obj, minw, minh);
4098 wd->ges = elm_gesture_layer_add(obj);
4099 if (!wd->ges) ERR("elm_gesture_layer_add() failed");
4100 elm_gesture_layer_attach(wd->ges, obj);
4101 elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
4102 _pinch_zoom_start_cb, wd);
4103 elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
4104 _pinch_zoom_cb, wd);
4105 elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE,
4106 _pinch_rotate_cb, wd);
4107 elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END,
4108 _pinch_rotate_end_cb, wd);
4109 elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT,
4110 _pinch_rotate_end_cb, wd);
4112 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
4113 elm_widget_sub_object_add(obj, wd->sep_maps_markers);
4114 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
4116 wd->map = evas_map_new(EVAS_MAP_POINT);
4118 _source_all_load(wd);
4119 wd->zoom_min = wd->src_tile->zoom_min;
4120 wd->zoom_max = wd->src_tile->zoom_max;
4121 // FIXME: Tile Provider is better to provide tile size!
4122 wd->tsize = DEFAULT_TILE_SIZE;
4126 wd->id = ((int)getpid() << 16) | idnum;
4128 _grid_all_create(wd);
4132 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
4133 wd->markers_max_num = MARER_MAX_NUMBER;
4135 // TODO: convert Elementary to subclassing of Evas_Smart_Class
4136 // TODO: and save some bytes, making descriptions per-class and not instance!
4137 evas_object_smart_callbacks_descriptions_set(obj, _signals);
4139 if (!ecore_file_download_protocol_available("http://"))
4140 ERR("Ecore must be built with curl support for the map widget!");
4150 elm_map_zoom_set(Evas_Object *obj, int zoom)
4152 #ifdef HAVE_ELEMENTARY_ECORE_CON
4153 ELM_CHECK_WIDTYPE(obj, widtype);
4154 Widget_Data *wd = elm_widget_data_get(obj);
4155 EINA_SAFETY_ON_NULL_RETURN(wd);
4156 EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4158 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL) return;
4159 if (zoom < 0) zoom = 0;
4160 if (wd->zoom == zoom) return;
4161 if (zoom > wd->src_tile->zoom_max) zoom = wd->src_tile->zoom_max;
4162 if (zoom < wd->src_tile->zoom_min) zoom = wd->src_tile->zoom_min;
4164 Delayed_Data *data = ELM_NEW(Delayed_Data);
4165 data->func = _zoom_set;
4168 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4169 evas_object_smart_changed(data->wd->pan_smart);
4177 elm_map_zoom_get(const Evas_Object *obj)
4179 #ifdef HAVE_ELEMENTARY_ECORE_CON
4180 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4181 Widget_Data *wd = elm_widget_data_get(obj);
4183 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, 0);
4192 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
4194 #ifdef HAVE_ELEMENTARY_ECORE_CON
4195 ELM_CHECK_WIDTYPE(obj, widtype);
4196 Widget_Data *wd = elm_widget_data_get(obj);
4197 EINA_SAFETY_ON_NULL_RETURN(wd);
4199 if ((mode == ELM_MAP_ZOOM_MODE_MANUAL) && (wd->mode == !!mode)) return;
4201 Delayed_Data *data = ELM_NEW(Delayed_Data);
4203 data->func = _zoom_mode_set;
4205 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4206 evas_object_smart_changed(data->wd->pan_smart);
4213 EAPI Elm_Map_Zoom_Mode
4214 elm_map_zoom_mode_get(const Evas_Object *obj)
4216 #ifdef HAVE_ELEMENTARY_ECORE_CON
4217 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
4218 Widget_Data *wd = elm_widget_data_get(obj);
4219 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ELM_MAP_ZOOM_MODE_MANUAL);
4224 return ELM_MAP_ZOOM_MODE_MANUAL;
4229 elm_map_zoom_max_set(Evas_Object *obj, int zoom)
4231 #ifdef HAVE_ELEMENTARY_ECORE_CON
4232 ELM_CHECK_WIDTYPE(obj, widtype);
4233 Widget_Data *wd = elm_widget_data_get(obj);
4234 EINA_SAFETY_ON_NULL_RETURN(wd);
4235 EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4237 if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
4239 wd->zoom_max = zoom;
4247 elm_map_zoom_max_get(const Evas_Object *obj)
4249 #ifdef HAVE_ELEMENTARY_ECORE_CON
4250 ELM_CHECK_WIDTYPE(obj, widtype) 18;
4251 Widget_Data *wd = elm_widget_data_get(obj);
4252 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
4253 EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
4255 return wd->zoom_max;
4263 elm_map_zoom_min_set(Evas_Object *obj, int zoom)
4265 #ifdef HAVE_ELEMENTARY_ECORE_CON
4266 ELM_CHECK_WIDTYPE(obj, widtype);
4267 Widget_Data *wd = elm_widget_data_get(obj);
4268 EINA_SAFETY_ON_NULL_RETURN(wd);
4269 EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4271 if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
4273 wd->zoom_min = zoom;
4281 elm_map_zoom_min_get(const Evas_Object *obj)
4283 #ifdef HAVE_ELEMENTARY_ECORE_CON
4284 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4285 Widget_Data *wd = elm_widget_data_get(obj);
4286 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
4287 EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
4289 return wd->zoom_min;
4298 elm_map_region_bring_in(Evas_Object *obj, double lon, double lat)
4300 #ifdef HAVE_ELEMENTARY_ECORE_CON
4301 ELM_CHECK_WIDTYPE(obj, widtype);
4302 Widget_Data *wd = elm_widget_data_get(obj);
4304 Delayed_Data *data = ELM_NEW(Delayed_Data);
4305 data->func = _region_bring_in;
4309 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4310 evas_object_smart_changed(data->wd->pan_smart);
4319 elm_map_region_show(Evas_Object *obj, double lon, double lat)
4321 #ifdef HAVE_ELEMENTARY_ECORE_CON
4322 ELM_CHECK_WIDTYPE(obj, widtype);
4323 Widget_Data *wd = elm_widget_data_get(obj);
4325 Delayed_Data *data = ELM_NEW(Delayed_Data);
4326 data->func = _region_show;
4330 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4331 evas_object_smart_changed(data->wd->pan_smart);
4340 elm_map_region_get(const Evas_Object *obj, double *lon, double *lat)
4342 #ifdef HAVE_ELEMENTARY_ECORE_CON
4343 ELM_CHECK_WIDTYPE(obj, widtype);
4344 Widget_Data *wd = elm_widget_data_get(obj);
4345 EINA_SAFETY_ON_NULL_RETURN(wd);
4348 Evas_Coord px, py, vw, vh;
4350 _pan_geometry_get(wd, &px, &py);
4351 _viewport_size_get(wd, &vw, &vh);
4352 _coord_to_region_convert(wd, vw/2 - px, vh/2 -py, wd->size.w, &tlon, &tlat);
4353 if (lon) *lon = tlon;
4354 if (lat) *lat = tlat;
4363 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
4365 #ifdef HAVE_ELEMENTARY_ECORE_CON
4366 ELM_CHECK_WIDTYPE(obj, widtype);
4367 Widget_Data *wd = elm_widget_data_get(obj);
4368 EINA_SAFETY_ON_NULL_RETURN(wd);
4370 if (wd->paused == !!paused) return;
4371 wd->paused = !!paused;
4374 if (wd->zoom_animator)
4376 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
4377 wd->zoom_animator = NULL;
4378 zoom_do(wd, wd->zoom);
4380 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4381 "elm,state,busy,stop", "elm");
4385 if (wd->download_num >= 1)
4386 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4387 "elm,state,busy,start", "elm");
4396 elm_map_paused_get(const Evas_Object *obj)
4398 #ifdef HAVE_ELEMENTARY_ECORE_CON
4399 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4400 Widget_Data *wd = elm_widget_data_get(obj);
4401 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
4411 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
4413 #ifdef HAVE_ELEMENTARY_ECORE_CON
4414 ELM_CHECK_WIDTYPE(obj, widtype);
4415 Widget_Data *wd = elm_widget_data_get(obj);
4416 EINA_SAFETY_ON_NULL_RETURN(wd);
4418 wd->rotate.d = degree;
4422 evas_object_smart_changed(wd->pan_smart);
4432 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
4434 #ifdef HAVE_ELEMENTARY_ECORE_CON
4435 ELM_CHECK_WIDTYPE(obj, widtype);
4436 Widget_Data *wd = elm_widget_data_get(obj);
4437 EINA_SAFETY_ON_NULL_RETURN(wd);
4439 if (degree) *degree = wd->rotate.d;
4440 if (cx) *cx = wd->rotate.cx;
4441 if (cy) *cy = wd->rotate.cy;
4451 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4453 #ifdef HAVE_ELEMENTARY_ECORE_CON
4454 ELM_CHECK_WIDTYPE(obj, widtype);
4455 Widget_Data *wd = elm_widget_data_get(obj);
4456 EINA_SAFETY_ON_NULL_RETURN(wd);
4458 if ((!wd->wheel_disabled) && (disabled))
4459 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4460 else if ((wd->wheel_disabled) && (!disabled))
4461 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4462 wd->wheel_disabled = !!disabled;
4470 elm_map_wheel_disabled_get(const Evas_Object *obj)
4472 #ifdef HAVE_ELEMENTARY_ECORE_CON
4473 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4474 Widget_Data *wd = elm_widget_data_get(obj);
4475 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
4477 return wd->wheel_disabled;
4485 elm_map_tile_load_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
4487 #ifdef HAVE_ELEMENTARY_ECORE_CON
4488 ELM_CHECK_WIDTYPE(obj, widtype);
4489 Widget_Data *wd = elm_widget_data_get(obj);
4490 EINA_SAFETY_ON_NULL_RETURN(wd);
4492 if (try_num) *try_num = wd->try_num;
4493 if (finish_num) *finish_num = wd->finish_num;
4502 elm_map_canvas_to_region_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
4504 #ifdef HAVE_ELEMENTARY_ECORE_CON
4505 ELM_CHECK_WIDTYPE(obj, widtype);
4506 Widget_Data *wd = elm_widget_data_get(obj);
4507 EINA_SAFETY_ON_NULL_RETURN(wd);
4508 EINA_SAFETY_ON_NULL_RETURN(lon);
4509 EINA_SAFETY_ON_NULL_RETURN(lat);
4511 Evas_Coord px, py, vw, vh;
4512 _pan_geometry_get(wd, &px, &py);
4513 _viewport_size_get(wd, &vw, &vh);
4514 _coord_rotate(x - px, y - py, (vw / 2) - px, (vh / 2) - py, -wd->rotate.d,
4516 _coord_to_region_convert(wd, x, y, wd->size.w, lon, lat);
4529 elm_map_region_to_canvas_convert(const Evas_Object *obj, double lon, double lat, Evas_Coord *x, Evas_Coord *y)
4531 #ifdef HAVE_ELEMENTARY_ECORE_CON
4532 ELM_CHECK_WIDTYPE(obj, widtype);
4533 Widget_Data *wd = elm_widget_data_get(obj);
4534 EINA_SAFETY_ON_NULL_RETURN(wd);
4535 EINA_SAFETY_ON_NULL_RETURN(x);
4536 EINA_SAFETY_ON_NULL_RETURN(y);
4548 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4550 #ifdef HAVE_ELEMENTARY_ECORE_CON
4551 ELM_CHECK_WIDTYPE(obj, widtype);
4552 Widget_Data *wd = elm_widget_data_get(obj);
4553 EINA_SAFETY_ON_NULL_RETURN(wd);
4554 EINA_SAFETY_ON_NULL_RETURN(user_agent);
4556 eina_stringshare_replace(&wd->user_agent, user_agent);
4558 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4559 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4567 elm_map_user_agent_get(const Evas_Object *obj)
4569 #ifdef HAVE_ELEMENTARY_ECORE_CON
4570 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4571 Widget_Data *wd = elm_widget_data_get(obj);
4572 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4574 return wd->user_agent;
4582 elm_map_source_set(Evas_Object *obj, Elm_Map_Source_Type type, const char *source_name)
4584 #ifdef HAVE_ELEMENTARY_ECORE_CON
4585 ELM_CHECK_WIDTYPE(obj, widtype);
4586 Widget_Data *wd = elm_widget_data_get(obj);
4587 EINA_SAFETY_ON_NULL_RETURN(wd);
4588 EINA_SAFETY_ON_NULL_RETURN(source_name);
4590 if (type == ELM_MAP_SOURCE_TYPE_TILE) _source_tile_set(wd, source_name);
4591 else if (type == ELM_MAP_SOURCE_TYPE_ROUTE)
4592 _source_route_set(wd, source_name);
4593 else if (type == ELM_MAP_SOURCE_TYPE_NAME) _source_name_set(wd, source_name);
4594 else ERR("Not supported map source type: %d", type);
4603 elm_map_source_get(const Evas_Object *obj, Elm_Map_Source_Type type)
4605 #ifdef HAVE_ELEMENTARY_ECORE_CON
4606 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4607 Widget_Data *wd = elm_widget_data_get(obj);
4608 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4609 EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, NULL);
4611 if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile->name;
4612 else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route->name;
4613 else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_name->name;
4614 else ERR("Not supported map source type: %d", type);
4623 elm_map_sources_get(const Evas_Object *obj, Elm_Map_Source_Type type)
4625 #ifdef HAVE_ELEMENTARY_ECORE_CON
4626 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4627 Widget_Data *wd = elm_widget_data_get(obj);
4628 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4630 if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile_names;
4631 else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route_names;
4632 else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_tile_names;
4633 else ERR("Not supported map source type: %d", type);
4641 EAPI Elm_Map_Route *
4642 elm_map_route_add(Evas_Object *obj, Elm_Map_Route_Type type, Elm_Map_Route_Method method, double flon, double flat, double tlon, double tlat, Elm_Map_Route_Cb route_cb, void *data)
4644 #ifdef HAVE_ELEMENTARY_ECORE_CON
4645 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4646 Widget_Data *wd = elm_widget_data_get(obj);
4647 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4648 EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_route, NULL);
4652 char fname[PATH_MAX];
4654 if (!ecore_file_exists(CACHE_ROUTE_ROOT))
4655 ecore_file_mkpath(CACHE_ROUTE_ROOT);
4657 if (type == ELM_MAP_ROUTE_TYPE_MOTOCAR)
4658 type_name = strdup(ROUTE_TYPE_MOTORCAR);
4659 else if (type == ELM_MAP_ROUTE_TYPE_BICYCLE)
4660 type_name = strdup(ROUTE_TYPE_BICYCLE);
4661 else if (type == ELM_MAP_ROUTE_TYPE_FOOT)
4662 type_name = strdup(ROUTE_TYPE_FOOT);
4663 else type_name = NULL;
4665 url = wd->src_route->url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4668 ERR("Route URL is NULL");
4669 if (type_name) free(type_name);
4672 if (type_name) free(type_name);
4674 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4676 snprintf(fname, sizeof(fname), CACHE_ROUTE_ROOT"/%d", rand());
4677 route->fname = strdup(fname);
4679 route->method = method;
4684 route->cb = route_cb;
4687 if (!ecore_file_download_full(url, route->fname, _route_cb, NULL, route,
4688 &(route->job), wd->ua) || !(route->job))
4690 ERR("Can't request Route from %s to %s", url, route->fname);
4695 INF("Route requested from %s to %s", url, route->fname);
4698 wd->routes = eina_list_append(wd->routes, route);
4699 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, route);
4700 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4701 "elm,state,busy,start", "elm");
4719 elm_map_route_del(Elm_Map_Route *route)
4721 #ifdef HAVE_ELEMENTARY_ECORE_CON
4722 EINA_SAFETY_ON_NULL_RETURN(route);
4723 EINA_SAFETY_ON_NULL_RETURN(route->wd);
4724 ELM_CHECK_WIDTYPE(route->wd->obj, widtype);
4729 if (route->job) ecore_file_download_abort(route->job);
4731 EINA_LIST_FREE(route->waypoint, w)
4733 if (w->point) eina_stringshare_del(w->point);
4737 EINA_LIST_FREE(route->nodes, n)
4739 if (n->pos.address) eina_stringshare_del(n->pos.address);
4745 ecore_file_remove(route->fname);
4749 route->wd->routes = eina_list_remove(route->wd->routes, route);
4757 elm_map_route_distance_get(const Elm_Map_Route *route)
4759 #ifdef HAVE_ELEMENTARY_ECORE_CON
4760 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
4761 return route->info.distance;
4769 elm_map_route_node_get(const Elm_Map_Route *route)
4771 #ifdef HAVE_ELEMENTARY_ECORE_CON
4772 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4773 return route->info.nodes;
4781 elm_map_route_waypoint_get(const Elm_Map_Route *route)
4783 #ifdef HAVE_ELEMENTARY_ECORE_CON
4784 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4785 return route->info.waypoints;
4793 elm_map_name_add(const Evas_Object *obj, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
4795 #ifdef HAVE_ELEMENTARY_ECORE_CON
4796 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4799 return _name_request(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0, 0,
4802 return _name_request(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat,
4816 elm_map_name_del(Elm_Map_Name *name)
4818 #ifdef HAVE_ELEMENTARY_ECORE_CON
4819 EINA_SAFETY_ON_NULL_RETURN(name);
4820 EINA_SAFETY_ON_NULL_RETURN(name->wd);
4821 ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
4823 if (name->job) ecore_file_download_abort(name->job);
4824 if (name->address) free(name->address);
4827 ecore_file_remove(name->fname);
4831 name->wd->names = eina_list_remove(name->wd->names, name);
4839 elm_map_name_address_get(const Elm_Map_Name *name)
4841 #ifdef HAVE_ELEMENTARY_ECORE_CON
4842 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
4843 EINA_SAFETY_ON_NULL_RETURN_VAL(name->wd, NULL);
4844 ELM_CHECK_WIDTYPE(name->wd->obj, widtype) NULL;
4846 return name->address;
4854 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
4856 #ifdef HAVE_ELEMENTARY_ECORE_CON
4857 EINA_SAFETY_ON_NULL_RETURN(name);
4858 EINA_SAFETY_ON_NULL_RETURN(name->wd);
4859 ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
4861 if (lon) *lon = name->lon;
4862 if (lat) *lat = name->lat;
4870 EAPI Elm_Map_Overlay *
4871 elm_map_overlay_add(Evas_Object *obj, double lon, double lat)
4873 #ifdef HAVE_ELEMENTARY_ECORE_CON
4874 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4875 Widget_Data *wd = elm_widget_data_get(obj);
4876 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4878 Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
4880 overlay->type = ELM_MAP_OVERLAY_TYPE_DEFAULT;
4881 overlay->ovl = _overlay_default_new(wd, lon, lat, "radio");
4882 _overlay_default_cb_add(overlay->ovl, _overlay_clicked_cb, overlay);
4883 overlay->grp = _overlay_group_new(wd);
4884 wd->overlays = eina_list_append(wd->overlays, overlay);
4886 evas_object_smart_changed(wd->pan_smart);
4897 elm_map_overlay_del(Elm_Map_Overlay *overlay)
4899 #ifdef HAVE_ELEMENTARY_ECORE_CON
4900 EINA_SAFETY_ON_NULL_RETURN(overlay);
4901 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4902 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4904 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
4906 _overlay_default_cb_del(overlay->ovl, _overlay_clicked_cb);
4907 _overlay_default_free(overlay->ovl);
4909 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
4911 _overlay_bubble_cb_del(overlay->ovl);
4912 _overlay_bubble_free(overlay->ovl);
4914 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
4915 _overlay_class_free(overlay->ovl);
4917 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
4918 _overlay_route_free(overlay->ovl);
4922 _overlay_group_cb_del(overlay->grp);
4923 _overlay_group_free(overlay->grp, overlay);
4926 overlay->wd->overlays = eina_list_remove(overlay->wd->overlays, overlay);
4927 evas_object_smart_changed(overlay->wd->pan_smart);
4935 EAPI Elm_Map_Overlay_Type
4936 elm_map_overlay_type_get(const Elm_Map_Overlay *overlay)
4938 #ifdef HAVE_ELEMENTARY_ECORE_CON
4939 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, ELM_MAP_OVERLAY_TYPE_NONE);
4940 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, ELM_MAP_OVERLAY_TYPE_NONE);
4941 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) ELM_MAP_OVERLAY_TYPE_NONE;
4943 return overlay->type;
4946 return OVERLAY_TYPE_NONE;
4951 elm_map_overlay_data_set(Elm_Map_Overlay *overlay, void *data)
4953 #ifdef HAVE_ELEMENTARY_ECORE_CON
4954 EINA_SAFETY_ON_NULL_RETURN(overlay);
4955 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4956 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4958 overlay->data = data;
4966 elm_map_overlay_data_get(const Elm_Map_Overlay *overlay)
4968 #ifdef HAVE_ELEMENTARY_ECORE_CON
4969 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
4970 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
4971 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
4973 return overlay->data;
4981 elm_map_overlay_hide_set(Elm_Map_Overlay *overlay, Eina_Bool hide)
4983 #ifdef HAVE_ELEMENTARY_ECORE_CON
4984 EINA_SAFETY_ON_NULL_RETURN(overlay);
4985 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4986 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4988 if (overlay->hide == !!hide) return;
4989 overlay->hide = hide;
4991 evas_object_smart_changed(overlay->wd->pan_smart);
4999 elm_map_overlay_hide_get(const Elm_Map_Overlay *overlay)
5001 #ifdef HAVE_ELEMENTARY_ECORE_CON
5002 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
5003 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
5004 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
5006 return overlay->hide;
5014 elm_map_overlay_displayed_zoom_min_set(Elm_Map_Overlay *overlay, int zoom)
5016 #ifdef HAVE_ELEMENTARY_ECORE_CON
5017 EINA_SAFETY_ON_NULL_RETURN(overlay);
5018 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5019 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5021 overlay->zoom_min = zoom;
5022 evas_object_smart_changed(overlay->wd->pan_smart);
5030 elm_map_overlay_displayed_zoom_min_get(const Elm_Map_Overlay *overlay)
5032 #ifdef HAVE_ELEMENTARY_ECORE_CON
5033 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, 0);
5034 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, 0);
5035 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) 0;
5037 return overlay->zoom_min;
5045 elm_map_overlay_paused_set(Elm_Map_Overlay *overlay, Eina_Bool paused)
5047 #ifdef HAVE_ELEMENTARY_ECORE_CON
5048 EINA_SAFETY_ON_NULL_RETURN(overlay);
5049 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5050 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5052 if (overlay->paused == !!paused) return;
5053 overlay->paused = paused;
5055 evas_object_smart_changed(overlay->wd->pan_smart);
5063 elm_map_overlay_paused_get(const Elm_Map_Overlay *overlay)
5065 #ifdef HAVE_ELEMENTARY_ECORE_CON
5066 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
5067 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
5068 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
5070 return overlay->paused;
5078 elm_map_overlay_show(Elm_Map_Overlay *overlay)
5080 #ifdef HAVE_ELEMENTARY_ECORE_CON
5081 EINA_SAFETY_ON_NULL_RETURN(overlay);
5082 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5083 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5085 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5087 Overlay_Default *ovl = overlay->ovl;
5088 elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
5090 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5092 Overlay_Bubble *ovl = overlay->ovl;
5093 elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
5095 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5097 Overlay_Class *ovl = overlay->ovl;
5098 double lon, lat, max_lo, min_lo, max_la, min_la;
5099 _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la, &min_la);
5100 lon = (max_lo + min_lo) / 2;
5101 lat = (max_la + min_la) / 2;
5102 elm_map_region_show(overlay->wd->obj, lon, lat);
5104 else ERR("Not supported overlay type: %d", overlay->type);
5106 evas_object_smart_changed(overlay->wd->pan_smart);
5113 elm_map_overlays_show(Eina_List *overlays)
5115 #ifdef HAVE_ELEMENTARY_ECORE_CON
5116 EINA_SAFETY_ON_NULL_RETURN(overlays);
5117 EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(overlays));
5119 Elm_Map_Overlay *overlay;
5120 overlay = eina_list_data_get(overlays);
5122 Delayed_Data *data = ELM_NEW(Delayed_Data);
5123 data->func = _overlays_show;
5124 data->wd = overlay->wd;
5125 data->overlays = eina_list_clone(overlays);
5126 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
5127 evas_object_smart_changed(data->wd->pan_smart);
5134 elm_map_overlay_region_set(Elm_Map_Overlay *overlay, double lon, double lat)
5136 #ifdef HAVE_ELEMENTARY_ECORE_CON
5137 EINA_SAFETY_ON_NULL_RETURN(overlay);
5138 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5139 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5141 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5143 Overlay_Default *ovl = overlay->ovl;
5147 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5149 Overlay_Bubble *ovl = overlay->ovl;
5153 else ERR("Not supported overlay type: %d", overlay->type);
5155 evas_object_smart_changed(overlay->wd->pan_smart);
5164 elm_map_overlay_region_get(const Elm_Map_Overlay *overlay, double *lon, double *lat)
5166 #ifdef HAVE_ELEMENTARY_ECORE_CON
5167 EINA_SAFETY_ON_NULL_RETURN(overlay);
5168 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5169 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5171 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5173 const Overlay_Default *ovl = overlay->ovl;
5174 if (lon) *lon = ovl->lon;
5175 if (lat) *lat = ovl->lat;
5177 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5179 const Overlay_Bubble *ovl = overlay->ovl;
5180 if (lon) *lon = ovl->lon;
5181 if (lat) *lat = ovl->lat;
5183 else ERR("Not supported overlay type: %d", overlay->type);
5192 elm_map_overlay_icon_set(Elm_Map_Overlay *overlay, Evas_Object *icon)
5194 #ifdef HAVE_ELEMENTARY_ECORE_CON
5195 EINA_SAFETY_ON_NULL_RETURN(overlay);
5196 EINA_SAFETY_ON_NULL_RETURN(icon);
5197 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5198 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5200 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5201 _overlay_default_update(overlay->wd, overlay->ovl, NULL, icon,
5203 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5204 _overlay_class_update(overlay->wd, overlay->ovl, NULL, icon);
5205 else ERR("Not supported overlay type: %d", overlay->type);
5207 evas_object_smart_changed(overlay->wd->pan_smart);
5214 EAPI const Evas_Object *
5215 elm_map_overlay_icon_get(const Elm_Map_Overlay *overlay)
5217 #ifdef HAVE_ELEMENTARY_ECORE_CON
5218 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
5219 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
5220 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
5222 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5224 const Overlay_Default *ovl = overlay->ovl;
5225 return elm_object_part_content_get(ovl->layout, "elm.icon");
5227 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5229 const Overlay_Class *ovl = overlay->ovl;
5234 ERR("Not supported overlay type: %d", overlay->type);
5244 elm_map_overlay_content_set(Elm_Map_Overlay *overlay, Evas_Object *obj)
5246 #ifdef HAVE_ELEMENTARY_ECORE_CON
5247 EINA_SAFETY_ON_NULL_RETURN(overlay);
5248 EINA_SAFETY_ON_NULL_RETURN(obj);
5249 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5250 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5252 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5253 _overlay_default_update(overlay->wd, overlay->ovl, obj, NULL, NULL,
5255 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5256 _overlay_class_update(overlay->wd, overlay->ovl, obj, NULL);
5257 else ERR("Not supported overlay type: %d", overlay->type);
5259 evas_object_smart_changed(overlay->wd->pan_smart);
5266 EAPI const Evas_Object *
5267 elm_map_overlay_content_get(const Elm_Map_Overlay *overlay)
5269 #ifdef HAVE_ELEMENTARY_ECORE_CON
5270 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
5271 EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
5272 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
5274 if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5276 const Overlay_Default *ovl = overlay->ovl;
5277 return elm_object_part_content_get(ovl->layout, "elm.icon");
5279 else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5281 const Overlay_Class *ovl = overlay->ovl;
5286 ERR("Not supported overlay type: %d", overlay->type);
5296 elm_map_overlay_color_set(Elm_Map_Overlay *overlay, int r, int g , int b, int a)
5298 #ifdef HAVE_ELEMENTARY_ECORE_CON
5299 EINA_SAFETY_ON_NULL_RETURN(overlay);
5300 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5301 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5303 if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
5305 Overlay_Route *route = overlay->ovl;
5311 else ERR("Not supported overlay type: %d", overlay->type);
5322 elm_map_overlay_color_get(const Elm_Map_Overlay *overlay, int *r, int *g , int *b, int *a)
5324 #ifdef HAVE_ELEMENTARY_ECORE_CON
5325 EINA_SAFETY_ON_NULL_RETURN(overlay);
5326 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5327 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5331 if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
5333 Overlay_Route *route = overlay->ovl;
5334 rr = route->color.r;
5335 gg = route->color.g;
5336 bb = route->color.b;
5337 aa = route->color.a;
5341 ERR("Not supported overlay type: %d", overlay->type);
5358 elm_map_overlay_get_cb_set(Elm_Map_Overlay *overlay, Elm_Map_Overlay_Get_Cb get_cb, void *data)
5360 #ifdef HAVE_ELEMENTARY_ECORE_CON
5361 EINA_SAFETY_ON_NULL_RETURN(overlay);
5362 EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5363 ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5365 overlay->cb = get_cb;
5366 overlay->cb_data = data;
5374 EAPI Elm_Map_Overlay *
5375 elm_map_overlay_class_add(Evas_Object *obj)
5377 #ifdef HAVE_ELEMENTARY_ECORE_CON
5378 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5379 Widget_Data *wd = elm_widget_data_get(obj);
5380 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5382 Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5384 overlay->type = ELM_MAP_OVERLAY_TYPE_CLASS;
5385 overlay->ovl = _overlay_class_new(wd, overlay);
5386 overlay->grp = NULL;
5387 wd->overlays = eina_list_append(wd->overlays, overlay);
5389 evas_object_smart_changed(wd->pan_smart);
5398 elm_map_overlay_class_append(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
5400 #ifdef HAVE_ELEMENTARY_ECORE_CON
5401 EINA_SAFETY_ON_NULL_RETURN(group);
5402 EINA_SAFETY_ON_NULL_RETURN(overlay);
5403 EINA_SAFETY_ON_NULL_RETURN(group->wd);
5404 ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5405 EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5407 if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
5409 ERR("Currently group supports only default overlays");
5413 Overlay_Class *ovl = group->ovl;
5414 if (eina_list_data_find(ovl->members, overlay))
5416 ERR("Already added overlay into group");
5419 ovl->members = eina_list_append(ovl->members, overlay);
5420 overlay->grp->clas = group;
5422 evas_object_smart_changed(group->wd->pan_smart);
5430 elm_map_overlay_class_remove(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
5432 #ifdef HAVE_ELEMENTARY_ECORE_CON
5433 EINA_SAFETY_ON_NULL_RETURN(group);
5434 EINA_SAFETY_ON_NULL_RETURN(overlay);
5435 EINA_SAFETY_ON_NULL_RETURN(group->wd);
5436 ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5437 EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5439 if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
5441 ERR("Currently group supports only default overlays");
5444 Overlay_Class *ovl = group->ovl;
5445 ovl->members = eina_list_remove(ovl->members, overlay);
5446 overlay->grp->clas = NULL;
5447 _overlay_group_update(group->wd, overlay->grp, NULL);
5449 evas_object_smart_changed(group->wd->pan_smart);
5457 elm_map_overlay_class_zoom_max_set(Elm_Map_Overlay *group, int zoom)
5459 #ifdef HAVE_ELEMENTARY_ECORE_CON
5460 EINA_SAFETY_ON_NULL_RETURN(group);
5461 EINA_SAFETY_ON_NULL_RETURN(group->wd);
5462 ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5463 EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5465 Overlay_Class *ovl = group->ovl;
5466 if (ovl->zoom_max == !!zoom) return;
5467 ovl->zoom_max = zoom;
5469 evas_object_smart_changed(group->wd->pan_smart);
5477 elm_map_overlay_class_zoom_max_get(const Elm_Map_Overlay *group)
5479 #ifdef HAVE_ELEMENTARY_ECORE_CON
5480 EINA_SAFETY_ON_NULL_RETURN_VAL(group, OVERLAY_CLASS_ZOOM_MAX);
5481 EINA_SAFETY_ON_NULL_RETURN_VAL(group->wd, OVERLAY_CLASS_ZOOM_MAX);
5482 ELM_CHECK_WIDTYPE(group->wd->obj, widtype) OVERLAY_CLASS_ZOOM_MAX;
5483 EINA_SAFETY_ON_FALSE_RETURN_VAL(group->type == ELM_MAP_OVERLAY_TYPE_CLASS, OVERLAY_CLASS_ZOOM_MAX);
5485 const Overlay_Class *ovl = group->ovl;
5486 return ovl->zoom_max;
5489 return OVERLAY_CLASS_ZOOM_MAX;
5493 EAPI Elm_Map_Overlay *
5494 elm_map_overlay_bubble_add(Evas_Object *obj)
5496 #ifdef HAVE_ELEMENTARY_ECORE_CON
5497 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5498 Widget_Data *wd = elm_widget_data_get(obj);
5499 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5501 Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5503 overlay->type = ELM_MAP_OVERLAY_TYPE_BUBBLE;
5504 overlay->ovl = _overlay_bubble_new(wd);
5505 _overlay_bubble_cb_add(overlay->ovl, overlay);
5506 overlay->grp = _overlay_group_new(wd);
5507 wd->overlays = eina_list_append(wd->overlays, overlay);
5509 evas_object_smart_changed(wd->pan_smart);
5518 elm_map_overlay_bubble_follow(Elm_Map_Overlay *bubble, Elm_Map_Overlay *parent)
5520 #ifdef HAVE_ELEMENTARY_ECORE_CON
5521 EINA_SAFETY_ON_NULL_RETURN(bubble);
5522 EINA_SAFETY_ON_NULL_RETURN(parent);
5523 ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5524 EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5526 Overlay_Bubble *ovl = bubble->ovl;
5527 Evas_Object *pobj = _overlay_obj_get(parent);
5532 evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_HIDE,
5533 _overlay_bubble_hide_cb, ovl);
5534 evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_SHOW,
5535 _overlay_bubble_chase_cb, ovl);
5536 evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_MOVE,
5537 _overlay_bubble_chase_cb, ovl);
5541 evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_HIDE,
5542 _overlay_bubble_hide_cb, ovl);
5543 evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_SHOW,
5544 _overlay_bubble_chase_cb, ovl);
5545 evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_MOVE,
5546 _overlay_bubble_chase_cb, ovl);
5548 _overlay_bubble_chase(ovl);
5549 evas_object_smart_changed(bubble->wd->pan_smart);
5557 elm_map_overlay_bubble_content_append(Elm_Map_Overlay *bubble, Evas_Object *content)
5559 #ifdef HAVE_ELEMENTARY_ECORE_CON
5560 EINA_SAFETY_ON_NULL_RETURN(bubble);
5561 EINA_SAFETY_ON_NULL_RETURN(content);
5562 ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5563 EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5565 Overlay_Bubble *bb = bubble->ovl;
5566 elm_box_pack_end(bb->bx, content);
5568 evas_object_smart_changed(bubble->wd->pan_smart);
5576 elm_map_overlay_bubble_content_clear(Elm_Map_Overlay *bubble)
5578 #ifdef HAVE_ELEMENTARY_ECORE_CON
5579 EINA_SAFETY_ON_NULL_RETURN(bubble);
5580 ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5581 EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5583 Overlay_Bubble *bb = bubble->ovl;
5584 elm_box_clear(bb->bx);
5586 evas_object_smart_changed(bubble->wd->pan_smart);
5592 EAPI Elm_Map_Overlay *
5593 elm_map_overlay_route_add(Evas_Object *obj, const Elm_Map_Route *route)
5595 #ifdef HAVE_ELEMENTARY_ECORE_CON
5596 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5597 Widget_Data *wd = elm_widget_data_get(obj);
5598 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5599 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5600 EINA_SAFETY_ON_NULL_RETURN_VAL(route->wd, NULL);
5601 EINA_SAFETY_ON_FALSE_RETURN_VAL(obj == route->wd->obj, NULL);
5603 Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5605 overlay->type = ELM_MAP_OVERLAY_TYPE_ROUTE;
5606 overlay->ovl = _overlay_route_new(wd, route);
5607 overlay->grp = _overlay_group_new(wd);
5608 wd->overlays = eina_list_append(wd->overlays, overlay);
5610 evas_object_smart_changed(wd->pan_smart);
5621 elm_map_track_add(Evas_Object *obj, void *emap)
5623 #ifdef HAVE_ELEMENTARY_ECORE_CON
5624 EMap_Route *emapr = emap;
5625 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5626 Widget_Data *wd = elm_widget_data_get(obj);
5627 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
5629 Evas_Object *route = elm_route_add(obj);
5630 elm_route_emap_set(route, emapr);
5631 wd->track = eina_list_append(wd->track, route);
5642 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
5644 #ifdef HAVE_ELEMENTARY_ECORE_CON
5645 ELM_CHECK_WIDTYPE(obj, widtype) ;
5646 Widget_Data *wd = elm_widget_data_get(obj);
5647 EINA_SAFETY_ON_NULL_RETURN(wd);
5649 wd->track = eina_list_remove(wd->track, route);
5650 evas_object_del(route);
5658 elm_map_track_add(Evas_Object *obj __UNUSED__, void *emap __UNUSED__)
5664 elm_map_track_remove(Evas_Object *obj __UNUSED__, Evas_Object *route __UNUSED__)
5669 /************************* Belows are deprecated APIs *************************/
5671 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
5673 elm_map_zoom_max_set(obj, zoom);
5677 elm_map_source_zoom_max_get(const Evas_Object *obj)
5679 return elm_map_zoom_max_get(obj);
5683 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
5685 elm_map_zoom_min_set(obj, zoom);
5689 elm_map_source_zoom_min_get(const Evas_Object *obj)
5691 return elm_map_zoom_min_get(obj);
5695 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
5697 #ifdef HAVE_ELEMENTARY_ECORE_CON
5698 ELM_CHECK_WIDTYPE(obj, widtype);
5699 Widget_Data *wd = elm_widget_data_get(obj);
5700 EINA_SAFETY_ON_NULL_RETURN(wd);
5702 _coord_to_region_convert(wd, x, y, size, lon, lat);
5714 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
5716 #ifdef HAVE_ELEMENTARY_ECORE_CON
5717 ELM_CHECK_WIDTYPE(obj, widtype);
5718 Widget_Data *wd = elm_widget_data_get(obj);
5719 EINA_SAFETY_ON_NULL_RETURN(wd);
5721 _geo_to_coord_convert(wd, lon, lat, size, x, y);
5733 elm_map_utils_rotate_coord(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord cx, const Evas_Coord cy, double degree, Evas_Coord *xx, Evas_Coord *yy)
5735 #ifdef HAVE_ELEMENTARY_ECORE_CON
5736 ELM_CHECK_WIDTYPE(obj, widtype);
5737 _coord_rotate(x, y, cx, cy, degree, xx, yy);
5750 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
5752 elm_map_tile_load_status_get(obj, try_num, finish_num);
5756 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
5758 elm_map_region_bring_in(obj, lon, lat);
5762 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
5764 elm_map_region_show(obj, lon, lat);
5768 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
5770 elm_map_region_get(obj, lon, lat);
5774 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
5776 return elm_map_name_add(obj, NULL, lon, lat, NULL, NULL);
5780 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
5782 return elm_map_name_add(obj, address, 0, 0, NULL, NULL);
5786 elm_map_canvas_to_geo_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
5788 elm_map_canvas_to_region_convert(obj, x, y, lon, lat);
5791 EAPI Elm_Map_Marker *
5792 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *group_clas, void *data)
5794 #ifdef HAVE_ELEMENTARY_ECORE_CON
5795 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5796 Widget_Data *wd = elm_widget_data_get(obj);
5798 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5799 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
5801 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
5803 marker->clas = clas;
5804 marker->group_clas = group_clas;
5805 marker->longitude = lon;
5806 marker->latitude = lat;
5807 marker->data = data;
5810 _edj_marker_size_get(wd, &marker->w, &marker->h);
5812 marker->obj = elm_layout_add(wd->obj);
5813 evas_object_smart_member_add(marker->obj, wd->pan_smart);
5814 evas_object_stack_above(marker->obj, wd->sep_maps_markers);
5816 edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
5817 "open", "elm", _marker_bubble_open_cb,
5819 edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
5820 "bringin", "elm", _marker_bringin_cb,
5823 wd->markers = eina_list_append(wd->markers, marker);
5824 if (marker->group_clas) group_clas->markers = eina_list_append(group_clas->markers,
5826 evas_object_smart_changed(wd->pan_smart);
5840 elm_map_marker_remove(Elm_Map_Marker *marker)
5842 _elm_map_marker_remove(marker);
5846 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
5848 #ifdef HAVE_ELEMENTARY_ECORE_CON
5849 EINA_SAFETY_ON_NULL_RETURN(marker);
5850 if (lon) *lon = marker->longitude;
5851 if (lat) *lat = marker->latitude;
5860 elm_map_marker_bring_in(Elm_Map_Marker *marker)
5862 #ifdef HAVE_ELEMENTARY_ECORE_CON
5863 EINA_SAFETY_ON_NULL_RETURN(marker);
5864 elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
5871 elm_map_marker_show(Elm_Map_Marker *marker)
5873 #ifdef HAVE_ELEMENTARY_ECORE_CON
5874 EINA_SAFETY_ON_NULL_RETURN(marker);
5875 elm_map_region_show(marker->wd->obj, marker->longitude, marker->latitude);
5882 elm_map_markers_list_show(Eina_List *markers)
5884 #ifdef HAVE_ELEMENTARY_ECORE_CON
5885 EINA_SAFETY_ON_NULL_RETURN(markers);
5886 EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(markers));
5888 Elm_Map_Marker *marker;
5889 marker = eina_list_data_get(markers);
5891 Delayed_Data *data = ELM_NEW(Delayed_Data);
5892 data->func = _marker_list_show;
5893 data->wd = marker->wd;
5894 data->markers = eina_list_clone(markers);
5895 data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
5896 evas_object_smart_changed(data->wd->pan_smart);
5903 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
5905 #ifdef HAVE_ELEMENTARY_ECORE_CON
5906 ELM_CHECK_WIDTYPE(obj, widtype);
5907 Widget_Data *wd = elm_widget_data_get(obj);
5908 EINA_SAFETY_ON_NULL_RETURN(wd);
5910 if (wd->paused_markers == !!paused) return;
5911 wd->paused_markers = paused;
5919 elm_map_paused_markers_get(const Evas_Object *obj)
5921 #ifdef HAVE_ELEMENTARY_ECORE_CON
5922 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5923 Widget_Data *wd = elm_widget_data_get(obj);
5924 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
5926 return wd->paused_markers;
5934 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
5936 #ifdef HAVE_ELEMENTARY_ECORE_CON
5937 ELM_CHECK_WIDTYPE(obj, widtype);
5938 Widget_Data *wd = elm_widget_data_get(obj);
5939 EINA_SAFETY_ON_NULL_RETURN(wd);
5941 wd->markers_max_num = max;
5949 elm_map_marker_object_get(const Elm_Map_Marker *marker)
5951 #ifdef HAVE_ELEMENTARY_ECORE_CON
5952 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
5953 return marker->content;
5961 elm_map_marker_update(Elm_Map_Marker *marker)
5963 #ifdef HAVE_ELEMENTARY_ECORE_CON
5964 EINA_SAFETY_ON_NULL_RETURN(marker);
5965 Widget_Data *wd = marker->wd;
5966 EINA_SAFETY_ON_NULL_RETURN(wd);
5968 _marker_update(marker);
5975 elm_map_bubbles_close(Evas_Object *obj)
5977 #ifdef HAVE_ELEMENTARY_ECORE_CON
5978 ELM_CHECK_WIDTYPE(obj, widtype);
5979 Widget_Data *wd = elm_widget_data_get(obj);
5980 EINA_SAFETY_ON_NULL_RETURN(wd);
5983 Elm_Map_Marker *marker;
5984 EINA_LIST_FOREACH(wd->markers, l, marker)
5986 if (marker->bubble) _bubble_free(marker->bubble);
5987 marker->bubble = NULL;
5991 if (marker->group->bubble) _bubble_free(marker->group->bubble);
5992 marker->group->bubble = NULL;
6000 EAPI Elm_Map_Group_Class *
6001 elm_map_group_class_new(Evas_Object *obj)
6003 #ifdef HAVE_ELEMENTARY_ECORE_CON
6004 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
6005 Widget_Data *wd = elm_widget_data_get(obj);
6006 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6008 Elm_Map_Group_Class *clas = ELM_NEW(Elm_Map_Group_Class);
6010 clas->zoom_displayed = 0;
6011 clas->zoom_grouped = 255;
6012 eina_stringshare_replace(&clas->style, "radio");
6014 wd->group_classes = eina_list_append(wd->group_classes, clas);
6024 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
6026 #ifdef HAVE_ELEMENTARY_ECORE_CON
6027 EINA_SAFETY_ON_NULL_RETURN(clas);
6028 eina_stringshare_replace(&clas->style, style);
6036 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, Elm_Map_Group_Icon_Get_Func icon_get)
6038 #ifdef HAVE_ELEMENTARY_ECORE_CON
6039 EINA_SAFETY_ON_NULL_RETURN(clas);
6040 clas->func.icon_get = icon_get;
6048 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
6050 #ifdef HAVE_ELEMENTARY_ECORE_CON
6051 EINA_SAFETY_ON_NULL_RETURN(clas);
6060 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
6062 #ifdef HAVE_ELEMENTARY_ECORE_CON
6063 EINA_SAFETY_ON_NULL_RETURN(clas);
6064 clas->zoom_displayed = zoom;
6072 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
6074 #ifdef HAVE_ELEMENTARY_ECORE_CON
6075 EINA_SAFETY_ON_NULL_RETURN(clas);
6076 clas->zoom_grouped = zoom;
6084 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
6086 #ifdef HAVE_ELEMENTARY_ECORE_CON
6087 ELM_CHECK_WIDTYPE(obj, widtype);
6088 Widget_Data *wd = elm_widget_data_get(obj);
6089 EINA_SAFETY_ON_NULL_RETURN(wd);
6090 EINA_SAFETY_ON_NULL_RETURN(clas);
6093 evas_object_smart_changed(wd->pan_smart);
6101 EAPI Elm_Map_Marker_Class *
6102 elm_map_marker_class_new(Evas_Object *obj)
6104 #ifdef HAVE_ELEMENTARY_ECORE_CON
6105 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
6106 Widget_Data *wd = elm_widget_data_get(obj);
6107 EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6109 Elm_Map_Marker_Class *clas = ELM_NEW(Elm_Map_Marker_Class);
6110 eina_stringshare_replace(&clas->style, "radio");
6112 wd->marker_classes = eina_list_append(wd->marker_classes, clas);
6121 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
6123 #ifdef HAVE_ELEMENTARY_ECORE_CON
6124 EINA_SAFETY_ON_NULL_RETURN(clas);
6125 eina_stringshare_replace(&clas->style, style);
6133 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Icon_Get_Func icon_get)
6135 #ifdef HAVE_ELEMENTARY_ECORE_CON
6136 EINA_SAFETY_ON_NULL_RETURN(clas);
6137 clas->func.icon_get = icon_get;
6145 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Get_Func get)
6147 #ifdef HAVE_ELEMENTARY_ECORE_CON
6148 EINA_SAFETY_ON_NULL_RETURN(clas);
6149 clas->func.get = get;
6157 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Del_Func del)
6159 #ifdef HAVE_ELEMENTARY_ECORE_CON
6160 EINA_SAFETY_ON_NULL_RETURN(clas);
6161 clas->func.del = del;
6169 elm_map_route_color_set(Elm_Map_Route *route __UNUSED__, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
6175 elm_map_route_color_get(const Elm_Map_Route *route __UNUSED__, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int *a __UNUSED__)
6181 elm_map_route_remove(Elm_Map_Route *route)
6183 elm_map_route_del(route);
6187 elm_map_name_remove(Elm_Map_Name *name)
6189 elm_map_name_del(name);