2 # include "elementary_config.h"
5 #include "Elementary.h"
7 //#include "els_scroller.h"
9 typedef struct _Widget_Data Widget_Data;
10 typedef struct _Pan Pan;
11 typedef struct _Grid Grid;
12 typedef struct _Grid_Item Grid_Item;
13 typedef struct _Marker_Group Marker_Group;
14 typedef struct _Event Event;
15 typedef struct _Path_Node Path_Node;
16 typedef struct _Path_Waypoint Path_Waypoint;
17 typedef struct _Url_Data Url_Data;
18 typedef struct _Route_Dump Route_Dump;
19 typedef struct _Name_Dump Name_Dump;
20 typedef struct _Track_Dump Track_Dump;
22 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
23 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
24 #define DEST_FILE_PATH "%s%d.png"
25 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
26 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
28 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
29 #define ROUTE_TYPE_MOTORCAR "motocar"
30 #define ROUTE_TYPE_BICYCLE "bicycle"
31 #define ROUTE_TYPE_FOOT "foot"
32 #define YOURS_DISTANCE "distance"
33 #define YOURS_DESCRIPTION "description"
34 #define YOURS_COORDINATES "coordinates"
36 // TODO: fix monav & ors url
37 #define ROUTE_MONAV_URL "http://"
38 #define ROUTE_ORS_URL "http:///"
40 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
41 #define NOMINATIM_RESULT "result"
42 #define NOMINATIM_PLACE "place"
43 #define NOMINATIM_ATTR_LON "lon"
44 #define NOMINATIM_ATTR_LAT "lat"
46 #define PINCH_ZOOM_MIN 0.25
47 #define PINCH_ZOOM_MAX 4.0
48 #define MAX_CONCURRENT_DOWNLOAD 10
50 #define GPX_NAME "name>"
51 #define GPX_COORDINATES "trkpt "
54 #define GPX_ELE "ele>"
55 #define GPX_TIME "time>"
58 // Currently the size of a tile must be 256*256
59 // and the size of the map must be pow(2.0, z)*tile_size
60 typedef struct _Map_Sources_Tab
65 ElmMapModuleUrlFunc url_cb;
66 Elm_Map_Route_Sources route_source;
67 ElmMapModuleRouteUrlFunc route_url_cb;
68 ElmMapModuleNameUrlFunc name_url_cb;
69 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
70 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
73 //Zemm min is supposed to be 0
74 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
75 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
76 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
77 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
79 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
81 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
82 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
84 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
86 static Map_Sources_Tab default_map_sources_tab[] =
88 {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
89 {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
90 {"CycleMap", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
91 {"Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
96 Ecore_Con_Url *con_url;
102 struct _Elm_Map_Marker_Class
107 struct _Elm_Map_Marker_Class_Func {
108 ElmMapMarkerGetFunc get;
109 ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
110 ElmMapMarkerIconGetFunc icon_get;
113 struct { //this part is private, do not modify these values
115 Evas_Coord edje_w, edje_h;
119 struct _Elm_Map_Marker
122 Elm_Map_Marker_Class *clas;
123 Elm_Map_Group_Class *clas_group;
124 double longitude, latitude;
129 Marker_Group **groups;
130 Evas_Object *content;
133 struct _Elm_Map_Group_Class
137 int zoom_displayed; // display the group if the zoom is >= to zoom_display
138 int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
142 ElmMapGroupIconGetFunc icon_get;
145 struct { //this part is private, do not modify these values
147 Evas_Coord edje_w, edje_h;
148 Evas_Coord edje_max_w, edje_max_h;
150 Eina_List *objs_used;
151 Eina_List *objs_notused;
158 Eina_Matrixsparse_Cell *cell;
159 Elm_Map_Group_Class *clas;
162 long long sum_x, sum_y;
166 Evas_Object *obj, *bubble, *sc, *bx, *rect;
168 Eina_Bool bringin : 1;
169 Eina_Bool update_nbelems : 1;
170 Eina_Bool update_resize : 1;
171 Eina_Bool update_raise : 1;
172 Eina_Bool delete_object : 1;
175 struct _Elm_Map_Route
181 Ecore_Con_Url *con_url;
186 double flon, flat, tlon, tlat;
188 Eina_List *nodes, *path;
195 const char *waypoints;
196 double distance; /* unit : km */
209 Eina_Bool inbound : 1;
223 struct _Path_Waypoint
234 Ecore_Con_Url *con_url;
239 Ecore_Event_Handler *handler;
254 Eina_Bool download : 1;
256 Ecore_File_Download_Job *job;
263 int tsize; // size of tile (tsize x tsize pixels)
264 int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
265 int iw, ih; // size of image in pixels
266 int w, h; // size of grid image in pixels (represented by grid)
267 int gw, gh; // size of grid in tiles
268 Eina_Matrixsparse *grid;
275 Evas_Object *pan_smart;
277 Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
279 Evas_Coord pan_x, pan_y, minw, minh;
284 Elm_Map_Zoom_Mode mode;
287 Ecore_Timer *scr_timer;
288 Ecore_Timer *long_timer;
289 Ecore_Animator *zoom_animator;
300 Evas_Coord x, y ,w ,h;
305 Eina_Bool resized : 1;
306 Eina_Bool on_hold : 1;
307 Eina_Bool paused : 1;
308 Eina_Bool paused_markers : 1;
315 Ecore_Job *markers_place_job;
316 Eina_Matrixsparse **markers;
317 Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
318 Evas_Coord markers_max_num;
319 int marker_max_w, marker_max_h;
321 Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
323 Eina_List *groups_clas; // list of Elm_Map_Group_Class*
324 Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
326 Elm_Map_Route_Sources route_source;
327 Eina_List *s_event_list;
332 const char *user_agent;
335 Evas_Event_Mouse_Down ev;
356 Ecore_Timer *wheel_timer;
357 Eina_Bool wheel_disabled : 1;
360 Eina_List *map_sources_tab;
361 const char **source_names;
363 Ecore_Timer *zoom_timer;
364 Map_Sources_Tab *src;
365 const char *gpx_file;
366 int zoom_min, zoom_max;
367 Eina_List *download_list;
373 Evas_Object_Smart_Clipped_Data __clipped_data;
389 Evas_Coord x, y, w, h;
392 Ecore_Timer *hold_timer;
407 enum _Route_Xml_Attribute
411 ROUTE_XML_DESCRIPTION,
412 ROUTE_XML_COORDINATES,
414 } Route_Xml_Attibute;
424 enum _Name_Xml_Attribute
441 enum _Track_Xml_Attribute
444 TRACK_XML_COORDINATES,
446 } Track_Xml_Attibute;
449 static const char *widtype = NULL;
451 static const char SIG_CHANGED[] = "changed";
452 static const char SIG_CLICKED[] = "clicked";
453 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
454 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
455 static const char SIG_LOAD_DETAIL[] = "load,detail";
456 static const char SIG_LONGPRESSED[] = "longpressed";
457 static const char SIG_PRESS[] = "press";
458 static const char SIG_SCROLL[] = "scroll";
459 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
460 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
461 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
462 static const char SIG_ZOOM_START[] = "zoom,start";
463 static const char SIG_ZOOM_STOP[] = "zoom,stop";
464 static const char SIG_DOWNLOADED[] = "downloaded";
465 static const char SIG_ROUTE_LOAD[] = "route,load";
466 static const char SIG_ROUTE_LOADED[] = "route,loaded";
467 static const char SIG_NAME_LOAD[] = "name,load";
468 static const char SIG_NAME_LOADED[] = "name,loaded";
469 static const Evas_Smart_Cb_Description _signals[] = {
472 {SIG_CLICKED_DOUBLE, ""},
473 {SIG_LOADED_DETAIL, ""},
474 {SIG_LOAD_DETAIL, ""},
475 {SIG_LONGPRESSED, ""},
478 {SIG_SCROLL_DRAG_START, ""},
479 {SIG_SCROLL_DRAG_STOP, ""},
480 {SIG_ZOOM_CHANGE, ""},
481 {SIG_ZOOM_START, ""},
483 {SIG_DOWNLOADED, ""},
484 {SIG_ROUTE_LOAD, ""},
485 {SIG_ROUTE_LOADED, ""},
487 {SIG_NAME_LOADED, ""},
491 static void _pan_calculate(Evas_Object *obj);
493 static Eina_Bool _hold_timer_cb(void *data);
494 static Eina_Bool _wheel_timer_cb(void *data);
495 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
496 static void _del_hook(Evas_Object *obj);
497 static void _theme_hook(Evas_Object *obj);
498 static void _on_focus_hook(void *data, Evas_Object *obj);
499 static void _sizing_eval(Evas_Object *obj);
500 static void _calc_job(void *data);
501 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
502 Evas_Callback_Type type, void *event_info);
503 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
504 static void grid_clear(Evas_Object *obj, Grid *g);
505 static Grid *grid_create(Evas_Object *obj);
506 static void grid_load(Evas_Object *obj, Grid *g);
508 static void _process_download_list(Evas_Object *obj);
509 static void _add_download_list(Evas_Object *obj, Grid_Item *gi);
511 static void _group_object_create(Marker_Group *group);
512 static void _group_object_free(Marker_Group *group);
513 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
514 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
515 static void _group_bubble_create(Marker_Group *group);
516 static void _group_bubble_free(Marker_Group *group);
517 static void _group_bubble_place(Marker_Group *group);
519 static int _group_bubble_content_update(Marker_Group *group);
520 static void _group_bubble_content_free(Marker_Group *group);
521 static void marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
522 static void _bubble_sc_hints_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
524 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
525 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
526 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
528 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
529 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
530 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
532 static void route_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
533 static void track_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
536 get_multi_device(Evas_Object *obj)
538 Widget_Data *wd = elm_widget_data_get(obj);
542 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
544 if (ev->device) return ev->device;
550 create_event_object(void *data, Evas_Object *obj, int device)
552 Widget_Data *wd = elm_widget_data_get(data);
553 Event *ev = calloc(1, sizeof(Event));
555 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
559 evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
560 wd->s_event_list = eina_list_append(wd->s_event_list, ev);
565 get_event_object(void *data, int device)
567 Widget_Data *wd = elm_widget_data_get(data);
571 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
573 if (ev->device == device) break;
580 destroy_event_object(void *data, Event *ev)
582 Widget_Data *wd = elm_widget_data_get(data);
583 EINA_SAFETY_ON_NULL_RETURN(ev);
585 wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
588 ecore_timer_del(ev->hold_timer);
589 ev->hold_timer = NULL;
595 module_list_cb(Eina_Module *m, void *data)
597 ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
598 Widget_Data *wd = elm_widget_data_get(data);
600 ElmMapModuleSourceFunc source;
601 ElmMapModuleZoomMinFunc zoom_min;
602 ElmMapModuleZoomMaxFunc zoom_max;
603 ElmMapModuleUrlFunc url;
604 ElmMapModuleRouteSourceFunc route_source;
605 ElmMapModuleRouteUrlFunc route_url;
606 ElmMapModuleNameUrlFunc name_url;
607 ElmMapModuleGeoIntoCoordFunc geo_into_coord;
608 ElmMapModuleCoordIntoGeoFunc coord_into_geo;
611 if (!wd) return EINA_FALSE;
613 file = eina_module_file_get(m);
614 if (!eina_module_load(m))
616 ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
620 source = eina_module_symbol_get(m, "map_module_source_get");
621 zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
622 zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
623 url = eina_module_symbol_get(m, "map_module_url_get");
624 route_source = eina_module_symbol_get(m, "map_module_route_source_get");
625 route_url = eina_module_symbol_get(m, "map_module_route_url_get");
626 name_url = eina_module_symbol_get(m, "map_module_name_url_get");
627 geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
628 coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
629 if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
631 ERR("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
632 eina_module_unload(m);
635 s = calloc(1, sizeof(Map_Sources_Tab));
636 EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
638 s->zoom_min = zoom_min();
639 s->zoom_max = zoom_max();
641 s->route_source = route_source();
642 s->route_url_cb = route_url;
643 s->name_url_cb = name_url;
644 s->geo_into_coord = geo_into_coord;
645 s->coord_into_geo = coord_into_geo;
646 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
652 module_init(void *data)
654 ELM_CHECK_WIDTYPE(data, widtype);
655 Widget_Data *wd = elm_widget_data_get(data);
658 wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
662 source_init(void *data)
664 ELM_CHECK_WIDTYPE(data, widtype);
665 Widget_Data *wd = elm_widget_data_get(data);
671 for (idx = 0; idx < 4; idx++)
673 s = calloc(1, sizeof(Map_Sources_Tab));
674 EINA_SAFETY_ON_NULL_RETURN(s);
675 s->name = default_map_sources_tab[idx].name;
676 s->zoom_min = default_map_sources_tab[idx].zoom_min;
677 s->zoom_max = default_map_sources_tab[idx].zoom_max;
678 s->url_cb = default_map_sources_tab[idx].url_cb;
679 s->route_source = default_map_sources_tab[idx].route_source;
680 s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
681 s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
682 s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
683 s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
684 wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
685 if (!idx) wd->src = s;
689 int n = eina_list_count(wd->map_sources_tab);
690 wd->source_names = malloc(sizeof(char *) * (n + 1));
691 if (!wd->source_names)
693 ERR("init source names failed.");
697 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
699 wd->source_names[idx] = strdup(s->name);
700 INF("source : %s", wd->source_names[idx]);
703 wd->source_names[idx] = NULL;
707 zoom_min_get(void *data)
709 ELM_CHECK_WIDTYPE(data, widtype);
710 Widget_Data *wd = elm_widget_data_get(data);
716 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
719 if (tz < wd->zoom_min) wd->zoom_min = tz;
724 zoom_max_get(void *data)
726 ELM_CHECK_WIDTYPE(data, widtype);
727 Widget_Data *wd = elm_widget_data_get(data);
733 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
736 if (tz > wd->zoom_max) wd->zoom_max = tz;
741 obj_rotate_zoom(void *data, Evas_Object *obj)
743 ELM_CHECK_WIDTYPE(data, widtype);
744 Widget_Data *wd = elm_widget_data_get(data);
746 if ((!wd->pinch.cx) && (!wd->pinch.cy))
748 wd->pinch.cx = wd->rotate.cx;
749 wd->pinch.cy = wd->rotate.cy;
752 evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
753 evas_object_image_size_get(obj, &iw, &ih);
754 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
755 if ((ow < iw) || (oh < ih))
757 ow *= (double)iw / ow;
758 oh *= (double)ih / oh;
759 evas_map_point_image_uv_set(wd->map, 1, ow, 0);
760 evas_map_point_image_uv_set(wd->map, 2, ow, oh);
761 evas_map_point_image_uv_set(wd->map, 3, 0, oh);
763 evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
764 evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
765 evas_object_map_enable_set(obj, EINA_TRUE);
766 evas_object_map_set(obj, wd->map);
771 track_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
773 track_place(Evas_Object *obj __UNUSED__, Grid *g __UNUSED__, Evas_Coord px __UNUSED__, Evas_Coord py __UNUSED__, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow __UNUSED__, Evas_Coord oh __UNUSED__)
777 ELM_CHECK_WIDTYPE(obj, widtype);
778 Widget_Data *wd = elm_widget_data_get(obj);
781 int xmin, xmax, ymin, ymax;
784 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
786 EINA_LIST_FOREACH(wd->track, l, route)
788 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
789 elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
791 if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
793 if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
796 evas_object_move(route, xmin - px + ox, ymin - py + oy);
797 evas_object_resize(route, xmax - xmin, ymax - ymin);
799 evas_object_raise(route);
800 obj_rotate_zoom(obj, route);
801 evas_object_show(route);
806 //the route is not display
807 evas_object_hide(route);
812 route_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
814 ELM_CHECK_WIDTYPE(obj, widtype);
815 Widget_Data *wd = elm_widget_data_get(obj);
816 Eina_List *lr, *lp, *ln;
825 Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
827 EINA_LIST_FOREACH(wd->route, lr, r)
829 EINA_LIST_FOREACH(r->path, lp, p)
831 evas_object_polygon_points_clear(p);
834 evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
835 nodes = eina_list_count(r->nodes);
837 EINA_LIST_FOREACH(r->nodes, ln, n)
839 if ((!wd->zoom) || ((n->idx) &&
840 ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
843 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
844 if ((x >= px - ow) && (x <= (px + ow*2)) &&
845 (y >= py - oh) && (y <= (py + oh*2)))
850 p = eina_list_nth(r->path, n->idx);
851 a = (double)(y - r->y) / (double)(x - r->x);
852 if ((abs(a) >= 1) || (r->x == x))
854 evas_object_polygon_point_add(p, r->x - 3, r->y);
855 evas_object_polygon_point_add(p, r->x + 3, r->y);
856 evas_object_polygon_point_add(p, x + 3, y);
857 evas_object_polygon_point_add(p, x - 3, y);
861 evas_object_polygon_point_add(p, r->x, r->y - 3);
862 evas_object_polygon_point_add(p, r->x, r->y + 3);
863 evas_object_polygon_point_add(p, x, y + 3);
864 evas_object_polygon_point_add(p, x, y - 3);
867 evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
868 evas_object_raise(p);
869 obj_rotate_zoom(obj, p);
874 else r->inbound = EINA_FALSE;
878 elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
879 if ((x >= px - ow) && (x <= (px + ow*2)) &&
880 (y >= py - oh) && (y <= (py + oh*2)))
884 r->inbound = EINA_TRUE;
886 else r->inbound = EINA_FALSE;
889 r->inbound = EINA_FALSE;
894 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
896 ELM_CHECK_WIDTYPE(obj, widtype);
897 Widget_Data *wd = elm_widget_data_get(obj);
898 Evas_Coord ax, ay, gw, gh, hh, ww;
901 evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
908 if ((ww == gw) && (hh == gh)) return;
910 if (ow > gw) ax = (ow - gw) / 2;
911 if (oh > gh) ay = (oh - gh) / 2;
912 evas_object_move(wd->rect,
915 evas_object_resize(wd->rect, gw, gh);
919 wd->show.show = EINA_FALSE;
920 elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
925 marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
927 ELM_CHECK_WIDTYPE(obj, widtype);
928 Widget_Data *wd = elm_widget_data_get(obj);
929 Evas_Coord ax, ay, gw, gh, tx, ty;
930 Eina_List *l, *markers;
931 Eina_Matrixsparse_Cell *cell;
936 int g_xx, g_yy, g_hh, g_ww;
939 if (g != eina_list_data_get(wd->grids)) return;
945 if (ow > gw) ax = (ow - gw) / 2;
946 if (oh > gh) ay = (oh - gh) / 2;
948 if (wd->zoom != wd->marker_zoom)
950 EINA_LIST_FREE(wd->cells_displayed, cell)
952 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
954 if (group->obj) _group_object_free(group);
958 wd->marker_zoom = wd->zoom;
960 if ((wd->paused_markers)
961 && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
964 g_xx = wd->pan_x / wd->tsize;
965 if (g_xx < 0) g_xx = 0;
966 g_yy = wd->pan_y / wd->tsize;
967 if (g_yy < 0) g_yy = 0;
968 g_ww = (ow / wd->tsize) + 1;
969 if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
970 g_hh = (oh / wd->tsize) + 1;
971 if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
973 //hide groups no more displayed
974 EINA_LIST_FREE(wd->cells_displayed, cell)
976 eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
977 if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
979 EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
981 if (group->obj) _group_object_free(group);
986 if (!wd->marker_zoom)
992 for (y = g_yy; y <= g_yy + g_hh; y++)
994 for (x = g_xx; x <= g_xx + g_ww; x++)
996 if (!wd->markers[wd->zoom]) continue;
997 eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
999 wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1000 markers = eina_matrixsparse_cell_data_get(cell);
1001 EINA_LIST_FOREACH(markers, l, group)
1003 if (!group->markers) continue;
1004 if (group->clas->zoom_displayed > wd->zoom) continue;
1011 if (eina_list_count(group->markers) == 1)
1013 Elm_Map_Marker *m = eina_list_data_get(group->markers);
1014 ww = m->clas->priv.edje_w;
1015 hh = m->clas->priv.edje_h;
1018 if (ww <= 0) ww = 1;
1019 if (hh <= 0) hh = 1;
1021 if ((gw != g->w) && (g->w > 0))
1024 xx = ((long long )gw * xx) / g->w;
1025 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1027 if ((gh != g->h) && (g->h > 0))
1030 yy = ((long long)gh * yy) / g->h;
1031 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1034 if ((!group->clas->hide)
1035 && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1036 && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1038 if (!group->obj) _group_object_create(group);
1040 if (group->update_nbelems)
1042 group->update_nbelems = EINA_FALSE;
1043 if (eina_list_count(group->markers) > 1)
1045 snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1046 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1049 edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1051 evas_object_move(group->obj,
1052 xx - px + ax + ox - ww/2,
1053 yy - py + ay + oy - hh/2);
1054 if ((!wd->paused_markers) || (group->update_resize))
1056 group->update_resize = EINA_FALSE;
1057 evas_object_resize(group->obj, ww, hh);
1058 obj_rotate_zoom(obj, group->obj);
1060 if (group->update_raise)
1062 group->update_raise = EINA_FALSE;
1063 evas_object_raise(group->obj);
1064 obj_rotate_zoom(obj, group->obj);
1065 evas_object_show(group->obj);
1067 if (group->bubble) _group_bubble_place(group);
1069 else if (group->obj)
1071 _group_object_free(group);
1079 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1081 ELM_CHECK_WIDTYPE(obj, widtype);
1082 Widget_Data *wd = elm_widget_data_get(obj);
1083 Evas_Coord ax, ay, gw, gh, tx, ty;
1091 if (ow > gw) ax = (ow - gw) / 2;
1092 if (oh > gh) ay = (oh - gh) / 2;
1094 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1095 Eina_Matrixsparse_Cell *cell;
1097 EINA_ITERATOR_FOREACH(it, cell)
1099 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1105 if ((gw != g->w) && (g->w > 0))
1108 xx = ((long long )gw * xx) / g->w;
1109 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1111 if ((gh != g->h) && (g->h > 0))
1114 yy = ((long long)gh * yy) / g->h;
1115 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1117 evas_object_move(gi->img,
1121 evas_object_resize(gi->img, ww, hh);
1123 obj_rotate_zoom(obj, gi->img);
1124 /*evas_object_move(gi->txt,
1128 evas_object_resize(gi->txt, ww, hh);
1131 eina_iterator_free(it);
1135 grid_clear(Evas_Object *obj, Grid *g)
1137 ELM_CHECK_WIDTYPE(obj, widtype);
1138 Widget_Data *wd = elm_widget_data_get(obj);
1142 if (!g->grid) return;
1144 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1145 Eina_Matrixsparse_Cell *cell;
1147 snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1148 ecore_file_recursive_rm(buf);
1150 EINA_ITERATOR_FOREACH(it, cell)
1152 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1153 evas_object_del(gi->img);
1154 //evas_object_del(gi->txt);
1156 wd->download_list = eina_list_remove(wd->download_list, gi);
1157 gi->want = EINA_FALSE;
1161 DBG("DOWNLOAD abort %s", gi->file);
1162 ecore_file_download_abort(gi->job);
1163 ecore_file_remove(gi->file);
1164 gi->have = EINA_FALSE;
1169 eina_stringshare_del(gi->file);
1171 eina_stringshare_del(gi->source);
1175 eina_matrixsparse_free(g->grid);
1176 eina_iterator_free(it);
1183 _tile_update(Grid_Item *gi)
1185 gi->want = EINA_FALSE;
1186 gi->download = EINA_FALSE;
1187 evas_object_image_file_set(gi->img, gi->file, NULL);
1188 if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1190 ERR("Image loading error (%s)", gi->file);
1191 ecore_file_remove(gi->file);
1192 gi->have = EINA_FALSE;
1196 obj_rotate_zoom(gi->wd->obj, gi->img);
1197 evas_object_show(gi->img);
1199 //evas_object_text_text_set(gi->txt, gi->file);
1200 //evas_object_show(gi->txt);
1202 gi->have = EINA_TRUE;
1206 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1208 Grid_Item *gi = data;
1210 gi->wd->download_num--;
1211 gi->download = EINA_FALSE;
1214 if ((gi->want) && (status == 200))
1217 DBG("DOWNLOAD done %s", gi->file);
1222 DBG("Download failed %s (%d) ", gi->file, status);
1223 ecore_file_remove(gi->file);
1224 gi->have = EINA_FALSE;
1227 gi->wd->finish_num++;
1229 evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1230 if (!gi->wd->download_num)
1232 edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr), "elm,state,busy,stop", "elm");
1233 evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1235 _process_download_list(gi->wd->obj);
1239 _process_download_list(Evas_Object *obj)
1241 ELM_CHECK_WIDTYPE(obj, widtype);
1242 Widget_Data *wd = elm_widget_data_get(obj);
1244 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1247 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1248 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1253 EINA_LIST_FOREACH(wd->download_list, l, gi)
1260 if ((gw != gi->g->w) && (gi->g->w > 0))
1263 xx = ((long long )gw * xx) / gi->g->w;
1264 ww = (((long long)gw * (tx + ww)) / gi->g->w) - xx;
1266 if ((gh != gi->g->h) && (gi->g->h > 0))
1269 yy = ((long long)gh * yy) / gi->g->h;
1270 hh = (((long long)gh * (ty + hh)) / gi->g->h) - yy;
1272 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1273 yy - wd->pan_y + oy,
1275 cvx, cvy, cvw, cvh))
1277 gi->download = EINA_FALSE;
1278 wd->download_list = eina_list_remove(wd->download_list, gi);
1282 EINA_LIST_REVERSE_FOREACH(wd->download_list, l, gi)
1284 if (gi->wd->download_num >= MAX_CONCURRENT_DOWNLOAD)
1287 Eina_Bool ret = ecore_file_download_full(gi->source, gi->file, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1288 if (!ret || !gi->job)
1289 WRN("Can't start to download %s to %s", gi->source, gi->file);
1292 gi->wd->download_num++;
1294 wd->download_list = eina_list_remove(wd->download_list, gi);
1295 if (wd->download_num == 1)
1296 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,state,busy,start", "elm");
1302 _add_download_list(Evas_Object *obj, Grid_Item *gi)
1304 ELM_CHECK_WIDTYPE(obj, widtype);
1305 Widget_Data *wd = elm_widget_data_get(obj);
1307 wd->download_list = eina_list_remove(wd->download_list, gi);
1308 wd->download_list = eina_list_append(wd->download_list, gi);
1309 _process_download_list(obj);
1313 grid_create(Evas_Object *obj)
1315 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1316 Widget_Data *wd = elm_widget_data_get(obj);
1319 if ((!wd) || (!wd->src)) return NULL;
1320 g = calloc(1, sizeof(Grid));
1323 g->tsize = wd->tsize;
1326 if (g->zoom > wd->src->zoom_max) return NULL;
1327 if (g->zoom < wd->src->zoom_min) return NULL;
1329 int size = pow(2.0, wd->zoom);
1333 g->w = g->tsize * g->gw;
1334 g->h = g->tsize * g->gh;
1336 g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1342 grid_load(Evas_Object *obj, Grid *g)
1344 ELM_CHECK_WIDTYPE(obj, widtype);
1345 Widget_Data *wd = elm_widget_data_get(obj);
1348 Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1350 Eina_Matrixsparse_Cell *cell;
1353 if ((!wd) || (!wd->src)) return;
1354 evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1355 evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1360 if ((gw <= 0) || (gh <= 0)) return;
1363 if ((gw != g->w) && (g->w > 0))
1364 size = ((long long)gw * size) / g->w;
1365 if (size < (g->tsize / 2)) return; // else we will load to much tiles
1367 it = eina_matrixsparse_iterator_new(g->grid);
1369 EINA_ITERATOR_FOREACH(it, cell)
1371 gi = eina_matrixsparse_cell_data_get(cell);
1378 if ((gw != g->w) && (g->w > 0))
1381 xx = ((long long )gw * xx) / g->w;
1382 ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1384 if ((gh != g->h) && (g->h > 0))
1387 yy = ((long long)gh * yy) / g->h;
1388 hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1391 if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1392 yy - wd->pan_y + oy,
1394 cvx, cvy, cvw, cvh))
1398 evas_object_hide(gi->img);
1399 //evas_object_hide(gi->txt);
1400 evas_object_image_file_set(gi->img, NULL, NULL);
1401 gi->want = EINA_FALSE;
1402 gi->have = EINA_FALSE;
1406 DBG("DOWNLOAD abort %s", gi->file);
1407 ecore_file_download_abort(gi->job);
1408 ecore_file_remove(gi->file);
1412 gi->download = EINA_FALSE;
1416 evas_object_hide(gi->img);
1417 //evas_object_hide(gi->txt);
1418 evas_object_image_preload(gi->img, 1);
1419 evas_object_image_file_set(gi->img, NULL, NULL);
1420 gi->have = EINA_FALSE;
1421 gi->want = EINA_FALSE;
1425 eina_iterator_free(it);
1427 xx = wd->pan_x / size - 1;
1430 yy = wd->pan_y / size - 1;
1434 if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1437 if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1439 for (y = yy; y <= yy + hh; y++)
1441 for (x = xx; x <= xx + ww; x++)
1443 gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1445 if ((!gi) && (g != eina_list_data_get(wd->grids)))
1450 gi = calloc(1, sizeof(Grid_Item));
1451 gi->src.x = x * g->tsize;
1452 gi->src.y = y * g->tsize;
1453 gi->src.w = g->tsize;
1454 gi->src.h = g->tsize;
1456 gi->out.x = gi->src.x;
1457 gi->out.y = gi->src.y;
1458 gi->out.w = gi->src.w;
1459 gi->out.h = gi->src.h;
1464 gi->img = evas_object_image_add(evas_object_evas_get(obj));
1465 evas_object_image_scale_hint_set
1466 (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1467 evas_object_image_filled_set(gi->img, 1);
1469 evas_object_smart_member_add(gi->img, wd->pan_smart);
1470 elm_widget_sub_object_add(obj, gi->img);
1471 evas_object_pass_events_set(gi->img, EINA_TRUE);
1472 evas_object_stack_below(gi->img, wd->sep_maps_markers);
1474 /* gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1475 evas_object_text_font_set(gi->txt, "Vera", 12);
1476 evas_object_color_set(gi->txt, 100, 100, 100, 255);
1477 evas_object_smart_member_add(gi->txt,
1479 elm_widget_sub_object_add(obj, gi->txt);
1480 evas_object_pass_events_set(gi->txt, EINA_TRUE);
1482 eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1485 if ((!gi->have) && (!gi->download))
1487 char buf[PATH_MAX], buf2[PATH_MAX];
1490 gi->want = EINA_TRUE;
1492 snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1493 if (!ecore_file_exists(buf))
1494 ecore_file_mkpath(buf);
1496 snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1498 source = wd->src->url_cb(obj, x, y, g->zoom);
1499 if ((!source) || (strlen(source)==0)) continue;
1501 eina_stringshare_replace(&gi->file, buf2);
1502 eina_stringshare_replace(&gi->source, source);
1504 if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1506 gi->download = EINA_TRUE;
1507 if (ecore_file_exists(buf2))
1510 _add_download_list(obj, gi);
1512 if (source) free(source);
1516 obj_rotate_zoom(obj, gi->img);
1517 evas_object_show(gi->img);
1524 grid_clearall(Evas_Object *obj)
1526 ELM_CHECK_WIDTYPE(obj, widtype);
1527 Widget_Data *wd = elm_widget_data_get(obj);
1531 EINA_LIST_FREE(wd->grids, g)
1536 wd->download_list = eina_list_free(wd->download_list);
1540 _smooth_update(Evas_Object *obj)
1542 ELM_CHECK_WIDTYPE(obj, widtype);
1543 Widget_Data *wd = elm_widget_data_get(obj);
1548 EINA_LIST_FOREACH(wd->grids, l, g)
1550 Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1551 Eina_Matrixsparse_Cell *cell;
1553 EINA_ITERATOR_FOREACH(it, cell)
1555 Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1556 evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1558 eina_iterator_free(it);
1563 _scr_timeout(void *data)
1565 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1566 Widget_Data *wd = elm_widget_data_get(data);
1568 if (!wd) return ECORE_CALLBACK_CANCEL;
1570 if (!wd->nosmooth) _smooth_update(data);
1571 wd->scr_timer = NULL;
1572 return ECORE_CALLBACK_CANCEL;
1576 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1578 ELM_CHECK_WIDTYPE(data, widtype);
1579 Widget_Data *wd = elm_widget_data_get(data);
1585 if (wd->nosmooth == 1) _smooth_update(data);
1587 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1588 wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1592 zoom_do(Evas_Object *obj)
1594 ELM_CHECK_WIDTYPE(obj, widtype);
1595 Widget_Data *wd = elm_widget_data_get(obj);
1596 Evas_Coord xx, yy, ow, oh;
1599 wd->size.w = wd->size.nw;
1600 wd->size.h = wd->size.nh;
1602 elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1604 if (wd->center_on.enabled)
1606 elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1612 xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1613 yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1618 else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1620 else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1622 wd->show.show = EINA_TRUE;
1628 if (wd->calc_job) ecore_job_del(wd->calc_job);
1629 wd->calc_job = ecore_job_add(_calc_job, wd);
1633 _zoom_timeout(void *data)
1635 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1636 Widget_Data *wd = elm_widget_data_get(data);
1638 if (!wd) return ECORE_CALLBACK_CANCEL;
1639 wd->zoom_timer = NULL;
1640 wd->pinch.level = 1.0;
1642 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1643 return ECORE_CALLBACK_CANCEL;
1647 _zoom_anim(void *data)
1649 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1650 Evas_Object *obj = data;
1651 Widget_Data *wd = elm_widget_data_get(obj);
1653 if (!wd) return ECORE_CALLBACK_CANCEL;
1654 if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1655 else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1658 wd->zoom_animator = NULL;
1660 evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1661 return ECORE_CALLBACK_CANCEL;
1666 wd->zoom_animator = NULL;
1667 wd->pinch.level = 2.0;
1668 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1669 wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1670 return ECORE_CALLBACK_CANCEL;
1672 else if (wd->t <= 0.5)
1674 wd->zoom_animator = NULL;
1675 wd->pinch.level = 0.5;
1676 if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1677 wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1678 return ECORE_CALLBACK_CANCEL;
1680 else if (wd->t != 1.0)
1682 Evas_Coord x, y, w, h;
1683 float half_w, half_h;
1684 evas_object_geometry_get(data, &x, &y, &w, &h);
1685 half_w = (float)w * 0.5;
1686 half_h = (float)h * 0.5;
1687 wd->pinch.cx = x + half_w;
1688 wd->pinch.cy = y + half_h;
1689 wd->pinch.level = wd->t;
1690 if (wd->calc_job) ecore_job_del(wd->calc_job);
1691 wd->calc_job = ecore_job_add(_calc_job, wd);
1693 return ECORE_CALLBACK_RENEW;
1697 _long_press(void *data)
1699 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1700 Widget_Data *wd = elm_widget_data_get(data);
1702 if (!wd) return ECORE_CALLBACK_CANCEL;
1703 wd->long_timer = NULL;
1704 evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1705 return ECORE_CALLBACK_CANCEL;
1709 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1711 ELM_CHECK_WIDTYPE(data, widtype);
1712 Widget_Data *wd = elm_widget_data_get(data);
1713 Evas_Event_Mouse_Down *ev = event_info;
1717 ev0 = get_event_object(data, 0);
1719 ev0 = create_event_object(data, obj, 0);
1722 ev0->hold_timer = NULL;
1723 ev0->prev.x = ev->canvas.x;
1724 ev0->prev.y = ev->canvas.y;
1726 if (ev->button != 1) return;
1727 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1728 else wd->on_hold = EINA_FALSE;
1729 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1730 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1732 evas_object_smart_callback_call(data, SIG_PRESS, ev);
1733 if (wd->long_timer) ecore_timer_del(wd->long_timer);
1734 wd->ev.canvas.x = ev->output.x;
1735 wd->ev.canvas.y = ev->output.y;
1736 wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1740 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1742 Evas_Event_Mouse_Move *move = event_info;
1745 ev0 = get_event_object(data, 0);
1747 ev0->prev.x = move->cur.canvas.x;
1748 ev0->prev.y = move->cur.canvas.y;
1752 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1754 ELM_CHECK_WIDTYPE(data, widtype);
1755 Widget_Data *wd = elm_widget_data_get(data);
1758 Evas_Event_Mouse_Up *ev = event_info;
1763 ev0 = get_event_object(data, 0);
1766 mdevice = get_multi_device(data);
1769 if (ev0->hold_timer)
1771 ecore_timer_del(ev0->hold_timer);
1772 ev0->hold_timer = NULL;
1774 elm_smart_scroller_hold_set(wd->scr, 0);
1775 elm_smart_scroller_freeze_set(wd->scr, 0);
1779 ev1 = get_event_object(data, mdevice);
1781 ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1783 destroy_event_object(data, ev0);
1786 if (ev->button != 1) return;
1787 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1788 else wd->on_hold = EINA_FALSE;
1791 ecore_timer_del(wd->long_timer);
1792 wd->long_timer = NULL;
1794 if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1795 wd->on_hold = EINA_FALSE;
1799 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1801 ELM_CHECK_WIDTYPE(data, widtype);
1802 Widget_Data *wd = elm_widget_data_get(data);
1804 Evas_Event_Multi_Down *down = event_info;
1806 elm_smart_scroller_hold_set(wd->scr, 1);
1807 elm_smart_scroller_freeze_set(wd->scr, 1);
1809 ev = create_event_object(data, obj, down->device);
1812 DBG("Failed : create_event_object");
1817 ev->hold_timer = NULL;
1818 ev->start.x = ev->prev.x = down->canvas.x;
1819 ev->start.y = ev->prev.y = down->canvas.y;
1820 ev->pinch_start_dis = 0;
1821 wd->pinch.level = 1.0;
1822 wd->pinch.diff = 1.0;
1827 ecore_timer_del(wd->long_timer);
1828 wd->long_timer = NULL;
1834 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1836 ELM_CHECK_WIDTYPE(data, widtype);
1837 Widget_Data *wd = elm_widget_data_get(data);
1838 Evas_Event_Multi_Move *move = event_info;
1839 int dis_new, dx, dy;
1840 double t, tt, a, a_diff;
1844 if ((!wd) || (!wd->src)) return;
1845 ev = get_event_object(data, move->device);
1848 ev0 = get_event_object(data, 0);
1851 if (wd->multi_count >= 1)
1853 Evas_Coord x, y, w, h;
1854 float half_w, half_h;
1856 evas_object_geometry_get(data, &x, &y, &w, &h);
1857 half_w = (float)w * 0.5;
1858 half_h = (float)h * 0.5;
1859 dx = ev0->prev.x - ev->prev.x;
1860 dy = ev0->prev.y - ev->prev.y;
1861 dis_new = sqrt((dx * dx) + (dy * dy));
1863 if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1866 ev->pinch_dis = dis_new;
1867 tt = wd->pinch.diff;
1868 wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1869 t = (wd->pinch.diff * 0.01) + 1.0;
1870 if ((t > 1.1) || (wd->rotate.doing))
1872 if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1873 ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1874 (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1876 wd->pinch.diff = tt;
1881 wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1882 wd->pinch.cx = x + half_w;
1883 wd->pinch.cy = y + half_h;
1884 wd->pinch.doing = EINA_TRUE;
1885 if (!wd->rotate.doing) goto do_zoom_only;
1890 if (wd->pinch.doing) goto do_nothing;
1893 a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1894 if (!wd->rotate.a) wd->rotate.a = a;
1897 a_diff = wd->rotate.a - a;
1898 if (a_diff > 0) wd->rotate.d -= 1.0;
1899 else if (a_diff < 0) wd->rotate.d += 1.0;
1901 wd->rotate.cx = x + half_w;
1902 wd->rotate.cy = y + half_h;
1903 wd->rotate.doing = EINA_TRUE;
1906 if (wd->calc_job) ecore_job_del(wd->calc_job);
1907 wd->calc_job = ecore_job_add(_calc_job, wd);
1911 ev->prev.x = move->cur.canvas.x;
1912 ev->prev.y = move->cur.canvas.y;
1916 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1918 ELM_CHECK_WIDTYPE(data, widtype);
1919 Widget_Data *wd = elm_widget_data_get(data);
1920 Evas_Event_Multi_Up *up = event_info;
1927 if (wd->calc_job) ecore_job_del(wd->calc_job);
1928 if (wd->zoom_animator)
1930 ecore_animator_del(wd->zoom_animator);
1931 wd->zoom_animator = NULL;
1934 wd->paused = EINA_TRUE;
1935 if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1936 else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1937 elm_map_zoom_set(data, wd->zoom + zoom);
1938 wd->pinch.level = 1.0;
1939 wd->pinch.doing = EINA_FALSE;
1942 wd->rotate.doing = EINA_FALSE;
1944 ev = get_event_object(data, up->device);
1947 DBG("Cannot get multi device");
1951 ev0 = get_event_object(data, 0);
1953 ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1958 ecore_timer_del(ev->hold_timer);
1959 ev->hold_timer = NULL;
1962 destroy_event_object(data, ev);
1966 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1968 ELM_CHECK_WIDTYPE(data, widtype);
1969 Widget_Data *wd = elm_widget_data_get(data);
1970 Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1971 Evas_Coord x, y, w, h;
1972 float half_w, half_h;
1975 evas_object_geometry_get(data, &x, &y, &w, &h);
1976 half_w = (float)w * 0.5;
1977 half_h = (float)h * 0.5;
1981 wd->zoom_method = ZOOM_METHOD_OUT;
1982 wd->wheel_zoom -= 0.1;
1983 if (wd->wheel_zoom <= -2.0) wd->wheel_zoom = -2.0;
1987 wd->zoom_method = ZOOM_METHOD_IN;
1988 wd->wheel_zoom += 0.1;
1989 if (wd->wheel_zoom >= 2.0) wd->wheel_zoom = 2.0;
1994 wd->pinch.level = pow(2.0, wd->wheel_zoom);
1995 wd->pinch.cx = x + half_w;
1996 wd->pinch.cy = y + half_h;
1997 if (wd->calc_job) ecore_job_del(wd->calc_job);
1998 wd->calc_job = ecore_job_add(_calc_job, wd);
2001 if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
2002 wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
2006 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
2009 _hold_timer_cb(void *data)
2013 ev0->hold_timer = NULL;
2014 return ECORE_CALLBACK_CANCEL;
2018 _wheel_timer_cb(void *data)
2020 ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2021 Widget_Data *wd = elm_widget_data_get(data);
2024 if (!wd) return ECORE_CALLBACK_CANCEL;
2025 if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom);
2026 else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor(wd->wheel_zoom);
2029 wd->wheel_timer = NULL;
2030 return ECORE_CALLBACK_CANCEL;
2033 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2034 wd->pinch.level = 1.0;
2035 elm_map_zoom_set(data, wd->zoom + zoom);
2036 wd->wheel_zoom = 0.0;
2037 wd->wheel_timer = NULL;
2038 wd->zoom_method = ZOOM_METHOD_NONE;
2039 return ECORE_CALLBACK_CANCEL;
2043 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2045 ELM_CHECK_WIDTYPE(data, widtype);
2046 Widget_Data *wd = elm_widget_data_get(data);
2049 evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2050 evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2051 evas_object_resize(wd->rect, w, h);
2052 evas_object_move(wd->rect, x, y);
2056 _del_hook(Evas_Object *obj)
2058 ELM_CHECK_WIDTYPE(obj, widtype);
2059 Widget_Data *wd = elm_widget_data_get(obj);
2060 Elm_Map_Group_Class *group_clas;
2061 Elm_Map_Marker_Class *marker_clas;
2067 Ecore_Event_Handler *h;
2073 EINA_LIST_FREE(wd->groups_clas, group_clas)
2075 if (group_clas->style)
2076 eina_stringshare_del(group_clas->style);
2080 EINA_LIST_FREE(wd->markers_clas, marker_clas)
2082 if (marker_clas->style)
2083 eina_stringshare_del(marker_clas->style);
2087 EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2089 destroy_event_object(obj, ev);
2092 EINA_LIST_FOREACH(wd->route, l, r)
2094 EINA_LIST_FREE(r->path, p)
2099 EINA_LIST_FREE(r->waypoint, w)
2101 if (w->point) eina_stringshare_del(w->point);
2105 EINA_LIST_FREE(r->nodes, n)
2107 if (n->pos.address) eina_stringshare_del(n->pos.address);
2111 EINA_LIST_FREE(r->handlers, h)
2113 ecore_event_handler_del(h);
2116 if (r->con_url) ecore_con_url_free(r->con_url);
2117 if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2118 if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2121 EINA_LIST_FREE(wd->names, na)
2123 if (na->address) free(na->address);
2124 if (na->handler) ecore_event_handler_del(na->handler);
2127 ecore_file_remove(na->ud.fname);
2129 na->ud.fname = NULL;
2133 EINA_LIST_FREE(wd->track, route)
2135 evas_object_del(route);
2138 if (wd->map) evas_map_free(wd->map);
2139 if (wd->source_names) free(wd->source_names);
2140 if (wd->calc_job) ecore_job_del(wd->calc_job);
2141 if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2142 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2143 if (wd->long_timer) ecore_timer_del(wd->long_timer);
2144 if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2145 if (wd->ua) eina_hash_free(wd->ua);
2146 if (wd->markers) free(wd->markers);
2152 _del_pre_hook(Evas_Object *obj)
2154 ELM_CHECK_WIDTYPE(obj, widtype);
2155 Widget_Data *wd = elm_widget_data_get(obj);
2156 Marker_Group *group;
2157 Elm_Map_Marker *marker;
2159 Eina_Bool free_marker = EINA_TRUE;
2164 for (i = 0; i <= wd->zoom_max; i++)
2166 if (!wd->markers[i]) continue;
2167 Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2168 Eina_Matrixsparse_Cell *cell;
2170 EINA_ITERATOR_FOREACH(it, cell)
2172 l = eina_matrixsparse_cell_data_get(cell);
2173 EINA_LIST_FREE(l, group)
2175 EINA_LIST_FREE(group->markers, marker)
2177 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2178 _bubble_sc_hints_changed_cb, group);
2179 if (free_marker) free(marker);
2183 free_marker = EINA_FALSE;
2185 eina_iterator_free(it);
2186 eina_matrixsparse_free(wd->markers[i]);
2189 evas_object_del(wd->sep_maps_markers);
2190 evas_object_del(wd->pan_smart);
2191 wd->pan_smart = NULL;
2195 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2197 ELM_CHECK_WIDTYPE(obj, widtype);
2198 Widget_Data *wd = elm_widget_data_get(obj);
2201 if (elm_widget_focus_get(obj))
2203 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2204 evas_object_focus_set(wd->obj, EINA_TRUE);
2208 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2209 evas_object_focus_set(wd->obj, EINA_FALSE);
2214 _theme_hook(Evas_Object *obj)
2216 ELM_CHECK_WIDTYPE(obj, widtype);
2217 Widget_Data *wd = elm_widget_data_get(obj);
2220 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2221 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2226 _sizing_eval(Evas_Object *obj)
2228 ELM_CHECK_WIDTYPE(obj, widtype);
2229 Widget_Data *wd = elm_widget_data_get(obj);
2230 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2233 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2234 evas_object_size_hint_min_set(obj, minw, minh);
2235 evas_object_size_hint_max_set(obj, maxw, maxh);
2239 _calc_job(void *data)
2241 Widget_Data *wd = data;
2242 Evas_Coord minw, minh;
2249 wd->resized = EINA_FALSE;
2250 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2252 double tz = wd->zoom;
2254 elm_map_zoom_set(wd->obj, tz);
2257 if ((minw != wd->minw) || (minh != wd->minh))
2261 evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2262 _sizing_eval(wd->obj);
2264 wd->calc_job = NULL;
2265 evas_object_smart_changed(wd->pan_smart);
2269 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2271 Pan *sd = evas_object_smart_data_get(obj);
2273 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2276 evas_object_smart_changed(obj);
2280 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2282 Pan *sd = evas_object_smart_data_get(obj);
2284 if (x) *x = sd->wd->pan_x;
2285 if (y) *y = sd->wd->pan_y;
2289 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2291 Pan *sd = evas_object_smart_data_get(obj);
2294 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2295 ow = sd->wd->minw - ow;
2297 oh = sd->wd->minh - oh;
2304 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2311 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2313 Pan *sd = evas_object_smart_data_get(obj);
2315 if (w) *w = sd->wd->minw;
2316 if (h) *h = sd->wd->minh;
2320 _pan_add(Evas_Object *obj)
2323 Evas_Object_Smart_Clipped_Data *cd;
2325 cd = evas_object_smart_data_get(obj);
2327 sd = calloc(1, sizeof(Pan));
2329 sd->__clipped_data = *cd;
2331 evas_object_smart_data_set(obj, sd);
2335 _pan_del(Evas_Object *obj)
2337 Pan *sd = evas_object_smart_data_get(obj);
2343 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2345 Pan *sd = evas_object_smart_data_get(obj);
2348 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2349 if ((ow == w) && (oh == h)) return;
2350 sd->wd->resized = EINA_TRUE;
2351 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2352 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2356 _pan_calculate(Evas_Object *obj)
2358 Pan *sd = evas_object_smart_data_get(obj);
2359 Evas_Coord ox, oy, ow, oh;
2363 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2364 rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2365 EINA_LIST_FOREACH(sd->wd->grids, l, g)
2367 if (sd->wd->zoom == g->zoom) grid_load(sd->wd->obj, g);
2368 grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2369 marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2370 if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2371 if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2376 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2378 Pan *sd = evas_object_smart_data_get(obj);
2380 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2381 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2385 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2387 ELM_CHECK_WIDTYPE(obj, widtype);
2388 Widget_Data *wd = elm_widget_data_get(obj);
2391 elm_smart_scroller_hold_set(wd->scr, 1);
2395 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2397 ELM_CHECK_WIDTYPE(obj, widtype);
2398 Widget_Data *wd = elm_widget_data_get(obj);
2401 elm_smart_scroller_hold_set(wd->scr, 0);
2405 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2407 ELM_CHECK_WIDTYPE(obj, widtype);
2408 Widget_Data *wd = elm_widget_data_get(obj);
2411 elm_smart_scroller_freeze_set(wd->scr, 1);
2415 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2417 ELM_CHECK_WIDTYPE(obj, widtype);
2418 Widget_Data *wd = elm_widget_data_get(obj);
2421 elm_smart_scroller_freeze_set(wd->scr, 0);
2425 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2427 evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2431 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2433 evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2437 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2439 Widget_Data *wd = elm_widget_data_get(data);
2440 wd->center_on.enabled = EINA_FALSE;
2441 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2445 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2447 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2451 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2453 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2458 _group_object_create(Marker_Group *group)
2460 const char *style = "radio";
2461 Evas_Object *icon = NULL;
2463 if (group->obj) return;
2464 if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2466 //set icon and style
2467 if (eina_list_count(group->markers) == 1)
2469 Elm_Map_Marker *m = eina_list_data_get(group->markers);
2471 style = m->clas->style;
2473 if (m->clas->func.icon_get)
2474 icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2476 group->delete_object = EINA_TRUE;
2480 if (group->clas->style)
2481 style = group->clas->style;
2483 if (group->clas->func.icon_get)
2484 icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2486 group->delete_object = EINA_FALSE;
2489 group->obj = elm_layout_add(group->wd->obj);
2490 elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2492 if (icon) elm_object_content_part_set(group->obj, "elm.icon", icon);
2494 evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2495 elm_widget_sub_object_add(group->wd->obj, group->obj);
2496 evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2498 if (!group->delete_object)
2499 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2503 group->delete_object = EINA_FALSE;
2505 group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2506 group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2507 group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2508 evas_object_show(group->obj);
2511 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2512 edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2514 group->update_nbelems = EINA_TRUE;
2515 group->update_resize = EINA_TRUE;
2516 group->update_raise = EINA_TRUE;
2518 if (group->open) _group_bubble_create(group);
2522 _group_object_free(Marker_Group *group)
2524 if (!group->obj) return;
2525 if (!group->delete_object)
2527 group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2528 group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2529 evas_object_hide(group->obj);
2531 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2532 edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2535 evas_object_del(group->obj);
2538 _group_bubble_free(group);
2542 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2544 Marker_Group *group = data;
2546 if (!evas_object_above_get(group->rect)) return;
2547 evas_object_raise(group->bubble);
2548 evas_object_raise(group->sc);
2549 evas_object_raise(group->rect);
2553 _group_bubble_create(Marker_Group *group)
2555 if (group->bubble) return;
2557 group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2558 group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2559 _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2560 elm_widget_style_get(group->wd->obj));
2561 evas_object_smart_member_add(group->bubble,
2563 elm_widget_sub_object_add(group->wd->obj, group->bubble);
2565 _group_bubble_content_free(group);
2566 if (!_group_bubble_content_update(group))
2568 //no content, we can delete the bubble
2569 _group_bubble_free(group);
2573 group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2574 evas_object_color_set(group->rect, 0, 0, 0, 0);
2575 evas_object_repeat_events_set(group->rect, EINA_TRUE);
2576 evas_object_smart_member_add(group->rect, group->wd->obj);
2577 elm_widget_sub_object_add(group->wd->obj, group->rect);
2579 evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2581 _group_bubble_place(group);
2584 static void _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2586 _group_bubble_place(data);
2590 _group_bubble_content_update(Marker_Group *group)
2593 Elm_Map_Marker *marker;
2596 if (!group->bubble) return 1;
2600 group->sc = elm_scroller_add(group->bubble);
2601 elm_widget_style_set(group->sc, "map_bubble");
2602 elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2603 elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2604 elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2605 edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2606 evas_object_show(group->sc);
2607 evas_object_smart_member_add(group->sc,
2609 elm_widget_sub_object_add(group->wd->obj, group->sc);
2611 group->bx = elm_box_add(group->bubble);
2612 evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2613 evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2614 elm_box_horizontal_set(group->bx, EINA_TRUE);
2615 evas_object_show(group->bx);
2617 elm_object_content_set(group->sc, group->bx);
2619 evas_object_event_callback_add(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2620 _bubble_sc_hints_changed_cb, group);
2623 EINA_LIST_FOREACH(group->markers, l, marker)
2625 if (i >= group->wd->markers_max_num) break;
2626 if ((!marker->content) && (marker->clas->func.get))
2627 marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2628 else if (marker->content)
2629 elm_box_unpack(group->bx, marker->content);
2630 if (marker->content)
2632 elm_box_pack_end(group->bx, marker->content);
2640 _group_bubble_content_free(Marker_Group *group)
2643 Elm_Map_Marker *marker;
2645 if (!group->sc) return;
2646 EINA_LIST_FOREACH(group->markers, l, marker)
2648 if ((marker->content) && (marker->clas->func.del))
2649 marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2650 else if (marker->content)
2651 evas_object_del(marker->content);
2652 marker->content = NULL;
2654 evas_object_del(group->sc);
2659 _group_bubble_free(Marker_Group *group)
2661 if (!group->bubble) return;
2662 group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2663 evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2664 _bubble_sc_hints_changed_cb, group);
2665 evas_object_del(group->bubble);
2666 evas_object_del(group->rect);
2667 group->bubble = NULL;
2668 _group_bubble_content_free(group);
2672 _group_bubble_place(Marker_Group *group)
2675 Evas_Coord xx, yy, ww, hh;
2678 if ((!group->bubble) || (!group->obj)) return;
2680 evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2681 edje_object_size_min_calc(group->bubble, NULL, &hh);
2683 s = edje_object_data_get(group->bubble, "size_w");
2684 if (s) ww = atoi(s);
2686 xx = x + w / 2 - ww / 2;
2689 evas_object_move(group->bubble, xx, yy);
2690 evas_object_resize(group->bubble, ww, hh);
2691 obj_rotate_zoom(group->wd, group->bubble);
2692 evas_object_show(group->bubble);
2694 evas_object_move(group->rect, xx, yy);
2695 evas_object_resize(group->rect, ww, hh);
2696 obj_rotate_zoom(group->wd, group->rect);
2697 evas_object_show(group->rect);
2701 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2703 Marker_Group *group = data;
2704 Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2705 if (!marker) return;
2706 group->bringin = EINA_TRUE;
2707 elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2711 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2713 Marker_Group *group = data;
2717 group->bringin = EINA_FALSE;
2723 group->open = EINA_FALSE;
2724 _group_bubble_free(group);
2727 group->open = EINA_TRUE;
2728 _group_bubble_create(group);
2732 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2734 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2735 Widget_Data *wd = elm_widget_data_get(obj);
2739 Evas_Coord step_x = 0;
2740 Evas_Coord step_y = 0;
2743 Evas_Coord page_x = 0;
2744 Evas_Coord page_y = 0;
2746 if (!wd) return EINA_FALSE;
2747 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2748 Evas_Event_Key_Down *ev = event_info;
2749 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2751 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2752 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2753 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2754 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2756 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2760 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2764 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
2768 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2772 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2775 y -= -(page_y * v_h) / 100;
2779 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2782 y += -(page_y * v_h) / 100;
2786 else if (!strcmp(ev->keyname, "KP_Add"))
2788 zoom = elm_map_zoom_get(obj) + 1;
2789 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2790 elm_map_zoom_set(obj, zoom);
2793 else if (!strcmp(ev->keyname, "KP_Subtract"))
2795 zoom = elm_map_zoom_get(obj) - 1;
2796 elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2797 elm_map_zoom_set(obj, zoom);
2800 else return EINA_FALSE;
2802 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2803 elm_smart_scroller_child_pos_set(wd->scr, x, y);
2809 cb_dump_name_attrs(void *data, const char *key, const char *value)
2811 Name_Dump *dump = (Name_Dump*)data;
2812 if (!dump) return EINA_FALSE;
2814 if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2815 else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2822 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2824 Route_Dump *dump = data;
2825 if (!dump) return EINA_FALSE;
2829 case EINA_SIMPLE_XML_OPEN:
2830 case EINA_SIMPLE_XML_OPEN_EMPTY:
2834 attrs = eina_simple_xml_tag_attributes_find(value, length);
2837 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2838 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2839 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2840 else dump->id = ROUTE_XML_NONE;
2844 case EINA_SIMPLE_XML_DATA:
2846 char *buf = malloc(length);
2847 if (!buf) return EINA_FALSE;
2848 snprintf(buf, length, "%s", value);
2849 if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2850 else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2851 else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2863 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2865 Name_Dump *dump = data;
2866 if (!dump) return EINA_FALSE;
2870 case EINA_SIMPLE_XML_OPEN:
2871 case EINA_SIMPLE_XML_OPEN_EMPTY:
2874 attrs = eina_simple_xml_tag_attributes_find(value, length);
2877 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2878 else dump->id = NAME_XML_NONE;
2880 eina_simple_xml_attributes_parse
2881 (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2885 case EINA_SIMPLE_XML_DATA:
2887 char *buf = malloc(length + 1);
2888 if (!buf) return EINA_FALSE;
2889 snprintf(buf, length + 1, "%s", value);
2890 if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2902 _parse_kml(void *data)
2904 Elm_Map_Route *r = (Elm_Map_Route*)data;
2905 if (!r || !r->ud.fname) return;
2909 unsigned int ele, idx;
2913 Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2915 f = fopen(r->ud.fname, "rb");
2920 fseek(f, 0, SEEK_END);
2926 fseek(f, 0, SEEK_SET);
2930 if (fread(buf, 1, sz, f))
2932 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
2939 if (dump.distance) r->info.distance = dump.distance;
2940 if (dump.description)
2942 eina_stringshare_replace(&r->info.waypoints, dump.description);
2943 str = eina_str_split_full(dump.description, "\n", 0, &ele);
2944 r->info.waypoint_count = ele;
2945 for (idx = 0 ; idx < ele ; idx++)
2947 Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
2951 wp->point = eina_stringshare_add(str[idx]);
2952 DBG("%s", str[idx]);
2953 r->waypoint = eina_list_append(r->waypoint, wp);
2962 else WRN("description is not found !");
2964 if (dump.coordinates)
2966 eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2967 str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2968 r->info.node_count = ele;
2969 for (idx = 0 ; idx < ele ; idx++)
2971 sscanf(str[idx], "%lf,%lf", &lon, &lat);
2972 Path_Node *n = ELM_NEW(Path_Node);
2979 DBG("%lf:%lf", lon, lat);
2980 n->pos.address = NULL;
2981 r->nodes = eina_list_append(r->nodes, n);
2983 path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
2984 evas_object_smart_member_add(path, r->wd->pan_smart);
2985 r->path = eina_list_append(r->path, path);
2998 _parse_name(void *data)
3000 Elm_Map_Name *n = (Elm_Map_Name*)data;
3001 if (!n || !n->ud.fname) return;
3005 Name_Dump dump = {0, NULL, 0.0, 0.0};
3007 f = fopen(n->ud.fname, "rb");
3012 fseek(f, 0, SEEK_END);
3018 fseek(f, 0, SEEK_SET);
3022 if (fread(buf, 1, sz, f))
3024 eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3033 INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3034 n->address = strdup(dump.address);
3042 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3044 Ecore_Con_Event_Url_Complete *ev = event;
3045 Elm_Map_Route *r = (Elm_Map_Route*)data;
3046 Widget_Data *wd = r->wd;
3048 if ((!r) || (!ev)) return EINA_TRUE;
3049 Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3050 ecore_con_url_data_set(r->con_url, NULL);
3051 if (r!=rr) return EINA_TRUE;
3053 if (r->ud.fd) fclose(r->ud.fd);
3058 Evas_Coord ox, oy, ow, oh;
3059 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3060 route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3062 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3063 "elm,state,busy,stop", "elm");
3064 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3069 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3071 Ecore_Con_Event_Url_Complete *ev = event;
3072 Elm_Map_Name *n = (Elm_Map_Name*)data;
3073 Widget_Data *wd = n->wd;
3075 if ((!n) || (!ev)) return EINA_TRUE;
3076 Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3077 ecore_con_url_data_set(n->con_url, NULL);
3078 if (n!=nn) return EINA_TRUE;
3080 if (n->ud.fd) fclose(n->ud.fd);
3083 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3084 "elm,state,busy,stop", "elm");
3085 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3089 static Elm_Map_Name *
3090 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3092 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3093 Widget_Data *wd = elm_widget_data_get(obj);
3098 if ((!wd) || (!wd->src)) return NULL;
3099 Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3100 if (!name) return NULL;
3102 snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3110 name->con_url = ecore_con_url_new(NULL);
3111 name->ud.fname = strdup(buf);
3112 INF("xml file : %s", name->ud.fname);
3114 name->ud.fd = fdopen(fd, "w+");
3115 if ((!name->con_url) || (!name->ud.fd))
3117 ecore_con_url_free(name->con_url);
3123 name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3124 name->method = method;
3125 if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3126 else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3130 source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3131 INF("name url = %s", source);
3133 wd->names = eina_list_append(wd->names, name);
3134 ecore_con_url_url_set(name->con_url, source);
3135 ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3136 ecore_con_url_data_set(name->con_url, name);
3138 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3139 "elm,state,busy,start", "elm");
3140 evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3141 ecore_con_url_get(name->con_url);
3142 if (source) free(source);
3148 static int idnum = 1;
3151 elm_map_add(Evas_Object *parent)
3155 Evas_Coord minw, minh;
3157 static Evas_Smart *smart = NULL;
3158 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3160 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3162 ELM_SET_WIDTYPE(widtype, "map");
3163 elm_widget_type_set(obj, "map");
3164 elm_widget_sub_object_add(parent, obj);
3165 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3166 elm_widget_data_set(obj, wd);
3167 elm_widget_del_hook_set(obj, _del_hook);
3168 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3169 elm_widget_theme_hook_set(obj, _theme_hook);
3170 elm_widget_can_focus_set(obj, EINA_TRUE);
3171 elm_widget_event_hook_set(obj, _event_hook);
3173 wd->scr = elm_smart_scroller_add(e);
3174 elm_smart_scroller_widget_set(wd->scr, obj);
3175 elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3176 evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3177 evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3178 elm_widget_resize_object_set(obj, wd->scr);
3179 elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3181 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3182 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3183 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3184 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3185 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3187 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3191 wd->map = evas_map_new(4);
3192 if (!wd->map) return NULL;
3194 wd->zoom_min = 0xFF;
3195 wd->zoom_max = 0X00;
3196 wd->markers_max_num = 30;
3197 wd->pinch.level = 1.0;
3200 wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3202 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3203 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3204 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3205 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3209 static Evas_Smart_Class sc;
3211 evas_object_smart_clipped_smart_set(&_pan_sc);
3213 sc.name = "elm_map_pan";
3214 sc.version = EVAS_SMART_CLASS_VERSION;
3217 sc.resize = _pan_resize;
3218 sc.move = _pan_move;
3219 sc.calculate = _pan_calculate;
3220 smart = evas_smart_class_new(&sc);
3224 wd->pan_smart = evas_object_smart_add(e, smart);
3225 wd->pan = evas_object_smart_data_get(wd->pan_smart);
3229 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3230 _pan_set, _pan_get, _pan_max_get,
3231 _pan_min_get, _pan_child_size_get);
3233 wd->rect = evas_object_rectangle_add(e);
3234 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3235 _rect_resize_cb, obj);
3236 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3238 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3240 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3242 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3243 _mouse_multi_down, obj);
3244 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3245 _mouse_multi_move, obj);
3246 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3247 _mouse_multi_up, obj);
3248 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3249 _mouse_wheel_cb, obj);
3251 evas_object_smart_member_add(wd->rect, wd->pan_smart);
3252 elm_widget_sub_object_add(obj, wd->rect);
3253 evas_object_show(wd->rect);
3254 evas_object_color_set(wd->rect, 0, 0, 0, 0);
3256 wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3257 wd->id = ((int)getpid() << 16) | idnum;
3261 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3263 evas_object_size_hint_min_set(obj, minw, minh);
3265 wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3266 evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3268 wd->paused = EINA_TRUE;
3269 elm_map_zoom_set(obj, 0);
3270 wd->paused = EINA_FALSE;
3273 // TODO: convert Elementary to subclassing of Evas_Smart_Class
3274 // TODO: and save some bytes, making descriptions per-class and not instance!
3275 evas_object_smart_callbacks_descriptions_set(obj, _signals);
3277 if (!ecore_file_download_protocol_available("http://"))
3279 ERR("Ecore must be built with curl support for the map widget!");
3286 elm_map_zoom_set(Evas_Object *obj, int zoom)
3288 ELM_CHECK_WIDTYPE(obj, widtype);
3289 Widget_Data *wd = elm_widget_data_get(obj);
3291 Grid *g, *g_zoom = NULL;
3292 Evas_Coord rx, ry, rw, rh;
3296 int z = 0, zoom_changed = 0, started = 0;
3298 if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3299 if (zoom < 0 ) zoom = 0;
3300 if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3301 if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3303 if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3304 else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3305 else wd->zoom_method = ZOOM_METHOD_NONE;
3306 if (wd->zoom != zoom ) zoom_changed = 1;
3308 wd->size.ow = wd->size.w;
3309 wd->size.oh = wd->size.h;
3310 elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3311 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3313 EINA_LIST_FOREACH(wd->route, l, r)
3317 EINA_LIST_FOREACH(r->path, l, p)
3319 evas_object_polygon_points_clear(p);
3324 EINA_LIST_FOREACH(wd->track, l, route)
3326 evas_object_hide(route);
3329 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3336 while (cumulw <= rw)
3345 while (cumulh <= rh)
3352 if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3354 if (p2w < p2h) z = p2w;
3357 else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3359 if (p2w > p2h) z = p2w;
3364 wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3365 wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3367 g = grid_create(obj);
3370 if (eina_list_count(wd->grids) > 1)
3372 g_zoom = eina_list_last(wd->grids)->data;
3373 wd->grids = eina_list_remove(wd->grids, g_zoom);
3374 grid_clear(obj, g_zoom);
3377 wd->grids = eina_list_prepend(wd->grids, g);
3381 EINA_LIST_FREE(wd->grids, g)
3389 if ((wd->size.w > 0) && (wd->size.h > 0))
3391 wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3392 wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3396 wd->size.spos.x = 0.5;
3397 wd->size.spos.y = 0.5;
3400 if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3401 if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3402 if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3403 if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3408 if (wd->calc_job) ecore_job_del(wd->calc_job);
3409 wd->calc_job = ecore_job_add(_calc_job, wd);
3413 if (!wd->zoom_animator)
3415 wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3417 if (wd->nosmooth == 1) _smooth_update(obj);
3424 if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3425 if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3428 if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3432 elm_map_zoom_get(const Evas_Object *obj)
3434 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3435 Widget_Data *wd = elm_widget_data_get(obj);
3442 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3444 ELM_CHECK_WIDTYPE(obj, widtype);
3445 Widget_Data *wd = elm_widget_data_get(obj);
3448 if (wd->mode == mode) return;
3451 if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3455 elm_map_zoom_set(wd->obj, tz);
3459 EAPI Elm_Map_Zoom_Mode
3460 elm_map_zoom_mode_get(const Evas_Object *obj)
3462 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3463 Widget_Data *wd = elm_widget_data_get(obj);
3465 if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3470 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3472 ELM_CHECK_WIDTYPE(obj, widtype);
3473 Widget_Data *wd = elm_widget_data_get(obj);
3477 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3478 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3483 if (wd->zoom_animator)
3486 if (!wd->nosmooth) _smooth_update(obj);
3487 ecore_animator_del(wd->zoom_animator);
3488 wd->zoom_animator = NULL;
3490 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3492 elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3494 wd->center_on.enabled = EINA_TRUE;
3495 wd->center_on.lon = lon;
3496 wd->center_on.lat = lat;
3500 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3502 ELM_CHECK_WIDTYPE(obj, widtype);
3503 Widget_Data *wd = elm_widget_data_get(obj);
3507 elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3508 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3513 if (wd->zoom_animator)
3516 ecore_animator_del(wd->zoom_animator);
3517 wd->zoom_animator = NULL;
3519 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3521 elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3523 wd->center_on.enabled = EINA_TRUE;
3524 wd->center_on.lon = lon;
3525 wd->center_on.lat = lat;
3529 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3531 ELM_CHECK_WIDTYPE(obj, widtype);
3532 Widget_Data *wd = elm_widget_data_get(obj);
3533 Evas_Coord sx, sy, sw, sh;
3536 elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3537 elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3541 elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3545 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3547 ELM_CHECK_WIDTYPE(obj, widtype);
3548 Widget_Data *wd = elm_widget_data_get(obj);
3551 if (wd->paused == !!paused) return;
3552 wd->paused = paused;
3555 if (wd->zoom_animator)
3557 if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3558 wd->zoom_animator = NULL;
3560 evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3566 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3568 ELM_CHECK_WIDTYPE(obj, widtype);
3569 Widget_Data *wd = elm_widget_data_get(obj);
3572 if (wd->paused_markers == !!paused) return;
3573 wd->paused_markers = paused;
3577 elm_map_paused_get(const Evas_Object *obj)
3579 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3580 Widget_Data *wd = elm_widget_data_get(obj);
3582 if (!wd) return EINA_FALSE;
3587 elm_map_paused_markers_get(const Evas_Object *obj)
3589 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3590 Widget_Data *wd = elm_widget_data_get(obj);
3592 if (!wd) return EINA_FALSE;
3593 return wd->paused_markers;
3597 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3599 ELM_CHECK_WIDTYPE(obj, widtype);
3600 Widget_Data *wd = elm_widget_data_get(obj);
3605 *try_num = wd->try_num;
3610 *finish_num = wd->finish_num;
3615 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3617 ELM_CHECK_WIDTYPE(obj, widtype);
3618 Widget_Data *wd = elm_widget_data_get(obj);
3621 int zoom = floor(log(size / 256) / log(2));
3622 if ((wd->src) && (wd->src->coord_into_geo))
3624 if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3629 *lon = x / (double)size * 360.0 - 180;
3633 double n = ELM_PI - 2.0 * ELM_PI * y / size;
3634 *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3639 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3641 ELM_CHECK_WIDTYPE(obj, widtype);
3642 Widget_Data *wd = elm_widget_data_get(obj);
3645 int zoom = floor(log(size / 256) / log(2));
3646 if ((wd->src) && (wd->src->geo_into_coord))
3648 if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3652 *x = floor((lon + 180.0) / 360.0 * size);
3654 *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3658 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3660 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3661 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3665 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3667 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3668 if (!address) return NULL;
3669 return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3673 elm_map_utils_rotate_coord(const Evas_Object *obj __UNUSED__, const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
3675 if ((!xx) || (!yy)) return;
3677 double r = (degree * M_PI) / 180.0;
3678 double tx, ty, ttx, tty;
3685 tx = ttx + (ty * cos(r + M_PI_2));
3686 ty = tty + (ty * sin(r + M_PI_2));
3692 EAPI Elm_Map_Marker *
3693 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3695 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3696 Widget_Data *wd = elm_widget_data_get(obj);
3699 Marker_Group *group;
3707 if (!wd) return NULL;
3708 EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3709 EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3711 Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3714 marker->clas = clas;
3715 marker->clas_group = clas_group;
3716 marker->longitude = lon;
3717 marker->latitude = lat;
3718 marker->data = data;
3719 marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3720 marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3721 marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
3723 tabi[1] = tabi[4] = tabi[6] = -1;
3724 tabi[2] = tabi[0] = tabi[7] = 0;
3725 tabi[3] = tabi[5] = tabi[8] = 1;
3727 tabj[1] = tabj[2] = tabj[3] = -1;
3728 tabj[4] = tabj[0] = tabj[5] = 0;
3729 tabj[6] = tabj[7] = tabj[8] = 1;
3731 if (!clas_group->priv.set)
3734 if (marker->clas_group && marker->clas_group->style)
3735 style = marker->clas_group->style;
3737 o = edje_object_add(evas_object_evas_get(obj));
3738 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3739 s = edje_object_data_get(o, "size_w");
3740 if (s) clas_group->priv.edje_w = atoi(s);
3741 else clas_group->priv.edje_w = 0;
3742 s = edje_object_data_get(o, "size_h");
3743 if (s) clas_group->priv.edje_h = atoi(s);
3744 else clas_group->priv.edje_h = 0;
3745 s = edje_object_data_get(o, "size_max_w");
3746 if (s) clas_group->priv.edje_max_w = atoi(s);
3747 else clas_group->priv.edje_max_w = 0;
3748 s = edje_object_data_get(o, "size_max_h");
3749 if (s) clas_group->priv.edje_max_h = atoi(s);
3750 else clas_group->priv.edje_max_h = 0;
3753 clas_group->priv.set = EINA_TRUE;
3756 if (!clas->priv.set)
3759 if (marker->clas && marker->clas->style)
3760 style = marker->clas->style;
3762 o = edje_object_add(evas_object_evas_get(obj));
3763 _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3764 s = edje_object_data_get(o, "size_w");
3765 if (s) clas->priv.edje_w = atoi(s);
3766 else clas->priv.edje_w = 0;
3767 s = edje_object_data_get(o, "size_h");
3768 if (s) clas->priv.edje_h = atoi(s);
3769 else clas->priv.edje_h = 0;
3772 clas->priv.set = EINA_TRUE;
3775 for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3777 elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3778 &(marker->x[i]), &(marker->y[i]));
3780 //search in the matrixsparse the region where the marker will be
3781 mpi = marker->x[i] / wd->tsize;
3782 mpj = marker->y[i] / wd->tsize;
3784 if (!wd->markers[i])
3786 int size = pow(2.0, i);
3787 wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
3791 if (i <= clas_group->zoom_grouped)
3793 for (j = 0, group = NULL; j < 9 && !group; j++)
3795 EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
3798 if (group->clas == marker->clas_group
3799 && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
3800 marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
3801 group->x-group->w/4, group->y-group->h/4, group->w, group->h))
3803 group->markers = eina_list_append(group->markers, marker);
3804 group->update_nbelems = EINA_TRUE;
3805 group->update_resize = EINA_TRUE;
3807 group->sum_x += marker->x[i];
3808 group->sum_y += marker->y[i];
3809 group->x = group->sum_x / eina_list_count(group->markers);
3810 group->y = group->sum_y / eina_list_count(group->markers);
3812 group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
3813 * eina_list_count(group->markers);
3814 group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
3815 * eina_list_count(group->markers);
3816 if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
3817 if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
3819 if (group->obj && eina_list_count(group->markers) == 2)
3821 _group_object_free(group);
3822 _group_object_create(group);
3825 _group_bubble_content_update(group);
3834 group = calloc(1, sizeof(Marker_Group));
3836 group->sum_x = marker->x[i];
3837 group->sum_y = marker->y[i];
3838 group->x = marker->x[i];
3839 group->y = marker->y[i];
3840 group->w = clas_group->priv.edje_w;
3841 group->h = clas_group->priv.edje_h;
3842 group->clas = clas_group;
3844 group->markers = eina_list_append(group->markers, marker);
3845 group->update_nbelems = EINA_TRUE;
3846 group->update_resize = EINA_TRUE;
3848 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3852 l = eina_list_append(NULL, group);
3853 eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
3854 eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3858 l = eina_matrixsparse_cell_data_get(group->cell);
3859 l = eina_list_append(l, group);
3860 eina_matrixsparse_cell_data_set(group->cell, l);
3863 marker->groups[i] = group;
3868 Evas_Coord ox, oy, ow, oh;
3869 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3870 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3877 elm_map_marker_remove(Elm_Map_Marker *marker)
3883 EINA_SAFETY_ON_NULL_RETURN(marker);
3886 for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3888 marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
3889 if (!eina_list_count(marker->groups[i]->markers))
3891 groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
3892 groups = eina_list_remove(groups, marker->groups[i]);
3893 eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
3895 _group_object_free(marker->groups[i]);
3896 _group_bubble_free(marker->groups[i]);
3897 free(marker->groups[i]);
3901 marker->groups[i]->sum_x -= marker->x[i];
3902 marker->groups[i]->sum_y -= marker->y[i];
3904 marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
3905 marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
3907 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
3908 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
3909 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
3910 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
3911 if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
3912 marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
3913 if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
3914 marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
3916 if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
3918 _group_object_free(marker->groups[i]);
3919 _group_object_create(marker->groups[i]);
3924 if ((marker->content) && (marker->clas->func.del))
3925 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
3926 else if (marker->content)
3927 evas_object_del(marker->content);
3929 if (marker->x) free(marker->x);
3930 if (marker->y) free(marker->y);
3931 if (marker->groups) free(marker->groups);
3937 Evas_Coord ox, oy, ow, oh;
3938 evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3939 marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3944 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
3946 EINA_SAFETY_ON_NULL_RETURN(marker);
3947 if (lon) *lon = marker->longitude;
3948 if (lat) *lat = marker->latitude;
3952 elm_map_marker_bring_in(Elm_Map_Marker *marker)
3954 EINA_SAFETY_ON_NULL_RETURN(marker);
3955 elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
3959 elm_map_marker_show(Elm_Map_Marker *marker)
3961 EINA_SAFETY_ON_NULL_RETURN(marker);
3962 elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
3966 elm_map_markers_list_show(Eina_List *markers)
3971 Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
3972 Evas_Coord rw, rh, xc, yc;
3975 EINA_SAFETY_ON_NULL_RETURN(markers);
3976 EINA_LIST_FOREACH(markers, l, marker)
3980 if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
3983 if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
3986 if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
3989 if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
3993 lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
3994 lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
3996 elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3997 for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
3999 Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4000 elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4002 if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4003 && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4004 && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4005 && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4009 elm_map_geo_region_show(wd->obj, lon, lat);
4010 elm_map_zoom_set(wd->obj, zoom);
4014 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4016 ELM_CHECK_WIDTYPE(obj, widtype);
4017 Widget_Data *wd = elm_widget_data_get(obj);
4020 wd->markers_max_num = max;
4024 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4026 EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4027 return marker->content;
4031 elm_map_marker_update(Elm_Map_Marker *marker)
4033 EINA_SAFETY_ON_NULL_RETURN(marker);
4034 if (marker->content)
4036 if (marker->clas->func.del)
4037 marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4039 evas_object_del(marker->content);
4040 marker->content = NULL;
4041 _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4046 elm_map_bubbles_close(Evas_Object *obj)
4048 ELM_CHECK_WIDTYPE(obj, widtype);
4049 Widget_Data *wd = elm_widget_data_get(obj);
4050 Marker_Group *group;
4051 Eina_List *l, *l_next;
4054 EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4055 _group_bubble_free(group);
4058 EAPI Elm_Map_Group_Class *
4059 elm_map_group_class_new(Evas_Object *obj)
4061 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4062 Widget_Data *wd = elm_widget_data_get(obj);
4064 if (!wd) return NULL;
4065 Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4066 clas->zoom_grouped = wd->zoom_max;
4067 wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4072 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4074 EINA_SAFETY_ON_NULL_RETURN(clas);
4075 eina_stringshare_replace(&clas->style, style);
4079 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4081 EINA_SAFETY_ON_NULL_RETURN(clas);
4082 clas->func.icon_get = icon_get;
4086 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4088 EINA_SAFETY_ON_NULL_RETURN(clas);
4093 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4095 EINA_SAFETY_ON_NULL_RETURN(clas);
4096 clas->zoom_displayed = zoom;
4100 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4102 EINA_SAFETY_ON_NULL_RETURN(clas);
4103 clas->zoom_grouped = zoom;
4107 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4109 ELM_CHECK_WIDTYPE(obj, widtype);
4110 Widget_Data *wd = elm_widget_data_get(obj);
4113 EINA_SAFETY_ON_NULL_RETURN(clas);
4114 if (clas->hide == hide) return;
4118 Evas_Coord ox, oy, ow, oh;
4119 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4120 marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4124 EAPI Elm_Map_Marker_Class *
4125 elm_map_marker_class_new(Evas_Object *obj)
4127 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4128 Widget_Data *wd = elm_widget_data_get(obj);
4130 if (!wd) return NULL;
4131 Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4132 wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4137 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
4139 EINA_SAFETY_ON_NULL_RETURN(clas);
4140 eina_stringshare_replace(&clas->style, style);
4144 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4146 EINA_SAFETY_ON_NULL_RETURN(clas);
4147 clas->func.icon_get = icon_get;
4151 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4153 EINA_SAFETY_ON_NULL_RETURN(clas);
4154 clas->func.get = get;
4158 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4160 EINA_SAFETY_ON_NULL_RETURN(clas);
4161 clas->func.del = del;
4165 elm_map_source_names_get(const Evas_Object *obj)
4167 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4168 Widget_Data *wd = elm_widget_data_get(obj);
4170 if (!wd) return NULL;
4171 return wd->source_names;
4175 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4177 ELM_CHECK_WIDTYPE(obj, widtype);
4178 Widget_Data *wd = elm_widget_data_get(obj);
4187 if (!strcmp(wd->src->name, source_name)) return;
4188 if (!wd->src->url_cb) return;
4191 EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4192 EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4194 if (!strcmp(s->name, source_name))
4205 if (wd->src->zoom_max < zoom)
4206 zoom = wd->src->zoom_max;
4207 if (wd->src->zoom_min > zoom)
4208 zoom = wd->src->zoom_min;
4210 elm_map_zoom_set(obj, zoom);
4214 elm_map_source_name_get(const Evas_Object *obj)
4216 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4217 Widget_Data *wd = elm_widget_data_get(obj);
4219 if ((!wd) || (!wd->src)) return NULL;
4220 return wd->src->name;
4224 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4226 ELM_CHECK_WIDTYPE(obj, widtype);
4227 Widget_Data *wd = elm_widget_data_get(obj);
4230 wd->route_source = source;
4233 EAPI Elm_Map_Route_Sources
4234 elm_map_route_source_get(const Evas_Object *obj)
4236 ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4237 Widget_Data *wd = elm_widget_data_get(obj);
4239 if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4240 return wd->route_source;
4244 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4246 ELM_CHECK_WIDTYPE(obj, widtype);
4247 Widget_Data *wd = elm_widget_data_get(obj);
4249 if ((!wd) || (!wd->src)) return;
4250 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4251 wd->src->zoom_max = zoom;
4255 elm_map_source_zoom_max_get(const Evas_Object *obj)
4257 ELM_CHECK_WIDTYPE(obj, widtype) 18;
4258 Widget_Data *wd = elm_widget_data_get(obj);
4260 if ((!wd) || (!wd->src)) return 18;
4261 return wd->src->zoom_max;
4265 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4267 ELM_CHECK_WIDTYPE(obj, widtype);
4268 Widget_Data *wd = elm_widget_data_get(obj);
4270 if ((!wd) || (!wd->src)) return;
4271 if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4272 wd->src->zoom_min = zoom;
4276 elm_map_source_zoom_min_get(const Evas_Object *obj)
4278 ELM_CHECK_WIDTYPE(obj, widtype) 0;
4279 Widget_Data *wd = elm_widget_data_get(obj);
4281 if ((!wd) || (!wd->src)) return 0;
4282 return wd->src->zoom_min;
4286 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4288 ELM_CHECK_WIDTYPE(obj, widtype);
4289 Widget_Data *wd = elm_widget_data_get(obj);
4292 if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4293 else eina_stringshare_replace(&wd->user_agent, user_agent);
4295 if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4296 eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4300 elm_map_user_agent_get(const Evas_Object *obj)
4302 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4303 Widget_Data *wd = elm_widget_data_get(obj);
4305 if (!wd) return NULL;
4306 return wd->user_agent;
4309 EAPI Elm_Map_Route *
4310 elm_map_route_add(Evas_Object *obj,
4311 Elm_Map_Route_Type type,
4312 Elm_Map_Route_Method method,
4318 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4319 Widget_Data *wd = elm_widget_data_get(obj);
4322 char *type_name = NULL;
4325 if ((!wd) || (!wd->src)) return NULL;
4327 Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4328 if (!route) return NULL;
4330 snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4338 route->con_url = ecore_con_url_new(NULL);
4339 route->ud.fname = strdup(buf);
4340 INF("xml file : %s", route->ud.fname);
4342 route->ud.fd = fdopen(fd, "w+");
4343 if ((!route->con_url) || (!route->ud.fd))
4345 ecore_con_url_free(route->con_url);
4351 route->color.r = 255;
4354 route->color.a = 255;
4355 route->handlers = eina_list_append
4356 (route->handlers, (void *)ecore_event_handler_add
4357 (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
4359 route->inbound = EINA_FALSE;
4361 route->method = method;
4369 case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4370 type_name = strdup(ROUTE_TYPE_MOTORCAR);
4372 case ELM_MAP_ROUTE_TYPE_BICYCLE:
4373 type_name = strdup(ROUTE_TYPE_BICYCLE);
4375 case ELM_MAP_ROUTE_TYPE_FOOT:
4376 type_name = strdup(ROUTE_TYPE_FOOT);
4382 source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4383 INF("route url = %s", source);
4385 wd->route = eina_list_append(wd->route, route);
4387 ecore_con_url_url_set(route->con_url, source);
4388 ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4389 ecore_con_url_data_set(route->con_url, route);
4390 ecore_con_url_get(route->con_url);
4391 if (type_name) free(type_name);
4392 if (source) free(source);
4394 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4395 "elm,state,busy,start", "elm");
4396 evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4401 elm_map_route_remove(Elm_Map_Route *route)
4403 EINA_SAFETY_ON_NULL_RETURN(route);
4408 Ecore_Event_Handler *h;
4410 EINA_LIST_FREE(route->path, p)
4415 EINA_LIST_FREE(route->waypoint, w)
4417 if (w->point) eina_stringshare_del(w->point);
4421 EINA_LIST_FREE(route->nodes, n)
4423 if (n->pos.address) eina_stringshare_del(n->pos.address);
4427 EINA_LIST_FREE(route->handlers, h)
4429 ecore_event_handler_del(h);
4432 if (route->ud.fname)
4434 ecore_file_remove(route->ud.fname);
4435 free(route->ud.fname);
4436 route->ud.fname = NULL;
4441 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4443 EINA_SAFETY_ON_NULL_RETURN(route);
4451 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
4453 EINA_SAFETY_ON_NULL_RETURN(route);
4454 if (r) *r = route->color.r;
4455 if (g) *g = route->color.g;
4456 if (b) *b = route->color.b;
4457 if (a) *a = route->color.a;
4461 elm_map_route_distance_get(const Elm_Map_Route *route)
4463 EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
4464 return route->info.distance;
4468 elm_map_route_node_get(const Elm_Map_Route *route)
4470 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4471 return route->info.nodes;
4475 elm_map_route_waypoint_get(const Elm_Map_Route *route)
4477 EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4478 return route->info.waypoints;
4482 elm_map_name_address_get(const Elm_Map_Name *name)
4484 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
4485 return name->address;
4489 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
4491 EINA_SAFETY_ON_NULL_RETURN(name);
4492 if (lon) *lon = name->lon;
4493 if (lat) *lat = name->lat;
4497 elm_map_name_remove(Elm_Map_Name *name)
4499 EINA_SAFETY_ON_NULL_RETURN(name);
4502 free(name->address);
4503 name->address = NULL;
4507 ecore_event_handler_del(name->handler);
4508 name->handler = NULL;
4512 ecore_file_remove(name->ud.fname);
4513 free(name->ud.fname);
4514 name->ud.fname = NULL;
4519 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
4521 ELM_CHECK_WIDTYPE(obj, widtype);
4522 Widget_Data *wd = elm_widget_data_get(obj);
4525 wd->rotate.d = degree;
4528 wd->calc_job = ecore_job_add(_calc_job, wd);
4532 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
4534 ELM_CHECK_WIDTYPE(obj, widtype);
4535 Widget_Data *wd = elm_widget_data_get(obj);
4538 if (degree) *degree = wd->rotate.d;
4539 if (cx) *cx = wd->rotate.cx;
4540 if (cy) *cy = wd->rotate.cy;
4544 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4546 ELM_CHECK_WIDTYPE(obj, widtype);
4547 Widget_Data *wd = elm_widget_data_get(obj);
4550 if ((!wd->wheel_disabled) && (disabled))
4551 evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4552 else if ((wd->wheel_disabled) && (!disabled))
4553 evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4554 wd->wheel_disabled = !!disabled;
4558 elm_map_wheel_disabled_get(const Evas_Object *obj)
4560 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4561 Widget_Data *wd = elm_widget_data_get(obj);
4563 if (!wd) return EINA_FALSE;
4564 return wd->wheel_disabled;
4569 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
4571 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4572 Widget_Data *wd = elm_widget_data_get(obj);
4574 if (!wd) return EINA_FALSE;
4576 Evas_Object *route = elm_route_add(obj);
4577 elm_route_emap_set(route, emap);
4578 wd->track = eina_list_append(wd->track, route);
4585 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
4587 ELM_CHECK_WIDTYPE(obj, widtype) ;
4588 Widget_Data *wd = elm_widget_data_get(obj);
4592 wd->track = eina_list_remove(wd->track, route);
4593 evas_object_del(route);
4597 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4600 snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
4606 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4609 snprintf(buf, sizeof(buf),
4610 "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
4616 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4619 snprintf(buf, sizeof(buf),
4620 "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
4626 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4629 snprintf(buf, sizeof(buf),
4630 "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
4635 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4638 snprintf(buf, sizeof(buf),
4639 "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
4640 ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
4645 // TODO: fix monav api
4647 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4650 snprintf(buf, sizeof(buf),
4651 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
4652 ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
4658 // TODO: fix ors api
4660 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
4663 snprintf(buf, sizeof(buf),
4664 "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
4665 ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
4672 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
4674 ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
4675 Widget_Data *wd = elm_widget_data_get(obj);
4677 unsigned int ele, idx;
4678 char search_url[PATH_MAX];
4681 if (!wd) return strdup("");
4682 if (method == ELM_MAP_NAME_METHOD_SEARCH)
4684 search_url[0] = '\0';
4685 str = eina_str_split_full(name, " ", 0, &ele);
4686 for (idx = 0 ; idx < ele ; idx++)
4688 eina_strlcat(search_url, str[idx], sizeof(search_url));
4689 if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
4691 snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
4693 else if (method == ELM_MAP_NAME_METHOD_REVERSE) snprintf(buf, sizeof(buf), "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0", NAME_NOMINATIM_URL, lat, lon, wd->zoom);
4694 else strcpy(buf, "");