Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_map.c
1
2
3 #ifdef HAVE_CONFIG_H
4 # include "elementary_config.h"
5 #endif
6
7 #ifdef HAVE_ECORE_CON
8 # include <Ecore_Con.h>
9 #endif
10
11 #include "Elementary.h"
12 #include "elm_priv.h"
13
14 /**
15  * @defgroup Map Map
16  * @ingroup Elementary
17  *
18  * This is a widget specifically for displaying the map. It uses basically
19  * OpenStreetMap provider. but it can be added custom providers.
20  *
21  * Signals that you can add callbacks for are:
22  *
23  * "clicked" - This is called when a user has clicked the map without dragging
24  *             around.
25  *
26  * "press" - This is called when a user has pressed down on the map.
27  *
28  * "longpressed" - This is called when a user has pressed down on the map for
29  *                 a long time without dragging around.
30  *
31  * "clicked,double" - This is called when a user has double-clicked the map.
32  *
33  * "load,detail" - Map detailed data load begins.
34  *
35  * "loaded,detail" - This is called when all parts of the map are loaded.
36  *
37  * "zoom,start" - Zoom animation started.
38  *
39  * "zoom,stop" - Zoom animation stopped.
40  *
41  * "zoom,change" - Zoom changed when using an auto zoom mode.
42  *
43  * "scroll" - the content has been scrolled (moved)
44  *
45  * "scroll,anim,start" - scrolling animation has started
46  *
47  * "scroll,anim,stop" - scrolling animation has stopped
48  *
49  * "scroll,drag,start" - dragging the contents around has started
50  *
51  * "scroll,drag,stop" - dragging the contents around has stopped
52  *
53  * "downloaded" - This is called when map images are downloaded
54  *
55  * "route,load" - This is called when route request begins
56  *
57  * "route,loaded" - This is called when route request ends
58  *
59  * "name,load" - This is called when name request begins
60  *
61  * "name,loaded- This is called when name request ends
62  *
63  * TODO : doxygen
64  */
65
66
67 typedef struct _Widget_Data Widget_Data;
68 typedef struct _Pan Pan;
69 typedef struct _Grid Grid;
70 typedef struct _Grid_Item Grid_Item;
71 typedef struct _Marker_Group Marker_Group;
72 typedef struct _Event Event;
73 typedef struct _Path_Node Path_Node;
74 typedef struct _Path_Waypoint Path_Waypoint;
75 typedef struct _Url_Data Url_Data;
76 typedef struct _Route_Dump Route_Dump;
77 typedef struct _Name_Dump Name_Dump;
78 typedef struct _Track_Dump Track_Dump;
79
80 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
81 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
82 #define DEST_FILE_PATH "%s%d.png"
83 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
84 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
85
86 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
87 #define ROUTE_TYPE_MOTORCAR "motocar"
88 #define ROUTE_TYPE_BICYCLE "bicycle"
89 #define ROUTE_TYPE_FOOT "foot"
90 #define YOURS_DISTANCE "distance"
91 #define YOURS_DESCRIPTION "description"
92 #define YOURS_COORDINATES "coordinates"
93
94 // TODO: fix monav & ors url
95 #define ROUTE_MONAV_URL "http://"
96 #define ROUTE_ORS_URL "http:///"
97
98 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
99 #define NOMINATIM_RESULT "result"
100 #define NOMINATIM_PLACE "place"
101 #define NOMINATIM_ATTR_LON "lon"
102 #define NOMINATIM_ATTR_LAT "lat"
103
104 #define PINCH_ZOOM_MIN 0.1
105 #define PINCH_ZOOM_MAX 5.0
106
107 #define GPX_NAME "name>"
108 #define GPX_COORDINATES "trkpt "
109 #define GPX_LON "lon"
110 #define GPX_LAT "lat"
111 #define GPX_ELE "ele>"
112 #define GPX_TIME "time>"
113
114 // Map sources
115 // Currently the size of a tile must be 256*256
116 // and the size of the map must be pow(2.0, z)*tile_size
117 typedef struct _Map_Sources_Tab
118 {
119    const char *name;
120    int zoom_min;
121    int zoom_max;
122    ElmMapModuleUrlFunc url_cb;
123    Elm_Map_Route_Sources route_source;
124    ElmMapModuleRouteUrlFunc route_url_cb;
125    ElmMapModuleNameUrlFunc name_url_cb;
126    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
127    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
128 } Map_Sources_Tab;
129
130 //Zemm min is supposed to be 0
131 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
132 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
133 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
134 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
135
136 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
137 /*
138 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
139 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
140  */
141 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
142
143 static Map_Sources_Tab default_map_sources_tab[] =
144 {
145      {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
146      {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
147      {"CycleMap", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
148      {"Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
149 };
150
151 struct _Url_Data
152 {
153    Ecore_Con_Url *con_url;
154
155    FILE *fd;
156    char *fname;
157 };
158
159 struct _Elm_Map_Marker_Class
160 {
161    const char *style;
162    int zoom_displayed;
163
164    struct _Elm_Map_Marker_Class_Func {
165         ElmMapMarkerGetFunc get;
166         ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
167         ElmMapMarkerIconGetFunc icon_get;
168    } func;
169
170    struct { //this part is private, do not modify these values
171         Eina_Bool set : 1;
172         Evas_Coord edje_w, edje_h;
173    } priv;
174 };
175
176 struct _Elm_Map_Marker
177 {
178    Widget_Data *wd;
179    Elm_Map_Marker_Class *clas;
180    Elm_Map_Group_Class *clas_group;
181    double longitude, latitude;
182
183    Evas_Coord map_size;
184    Evas_Coord *x, *y;
185    void *data;
186    Marker_Group **groups;
187    Evas_Object *content;
188 };
189
190 struct _Elm_Map_Group_Class
191 {
192    const char *style;
193    void *data;
194    int zoom_displayed; // display the group if the zoom is >= to zoom_display
195    int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
196    Eina_Bool hide : 1;
197
198    struct {
199         ElmMapGroupIconGetFunc icon_get;
200    } func;
201
202    struct { //this part is private, do not modify these values
203         Eina_Bool set : 1;
204         Evas_Coord edje_w, edje_h;
205         Evas_Coord edje_max_w, edje_max_h;
206
207         Eina_List *objs_used;
208         Eina_List *objs_notused;
209    } priv;
210 };
211
212 struct _Marker_Group
213 {
214    Widget_Data *wd;
215    Eina_Matrixsparse_Cell *cell;
216    Elm_Map_Group_Class *clas;
217
218    Eina_List *markers;
219    long long sum_x, sum_y;
220    Evas_Coord x, y;
221    Evas_Coord w, h;
222
223    Evas_Object *obj, *bubble, *sc, *bx, *rect;
224    Eina_Bool open : 1;
225    Eina_Bool bringin : 1;
226    Eina_Bool update_nbelems : 1;
227    Eina_Bool update_resize : 1;
228    Eina_Bool update_raise : 1;
229    Eina_Bool delete_object : 1;
230 };
231
232 struct _Elm_Map_Route
233 {
234    Widget_Data *wd;
235
236    Path_Node *n;
237    Path_Waypoint *w;
238    Ecore_Con_Url *con_url;
239
240    int type;
241    int method;
242    int x, y;
243    double flon, flat, tlon, tlat;
244
245    Eina_List *nodes, *path;
246    Eina_List *waypoint;
247
248    struct {
249       int node_count;
250       int waypoint_count;
251       const char *nodes;
252       const char *waypoints;
253       double distance; /* unit : km */
254    } info;
255
256    Eina_List *handlers;
257    Url_Data ud;
258
259    struct {
260       int r;
261       int g;
262       int b;
263       int a;
264    } color;
265
266    Eina_Bool inbound : 1;
267 };
268
269 struct _Path_Node
270 {
271    Widget_Data *wd;
272
273    int idx;
274    struct {
275       double lon, lat;
276       char *address;
277    } pos;
278 };
279
280 struct _Path_Waypoint
281 {
282    Widget_Data *wd;
283
284    const char *point;
285 };
286
287 struct _Elm_Map_Name
288 {
289    Widget_Data *wd;
290
291    Ecore_Con_Url *con_url;
292    int method;
293    char *address;
294    double lon, lat;
295    Url_Data ud;
296    Ecore_Event_Handler *handler;
297 };
298
299 struct _Grid_Item
300 {
301    Widget_Data *wd;
302    Evas_Object *img;
303    //Evas_Object *txt;
304    const char *file;
305    struct {
306         int x, y, w, h;
307    } src, out;
308    Eina_Bool want : 1;
309    Eina_Bool download : 1;
310    Eina_Bool have : 1;
311    Ecore_File_Download_Job *job;
312    int try_num;
313 };
314
315 struct _Grid
316 {
317    Widget_Data *wd;
318    int tsize; // size of tile (tsize x tsize pixels)
319    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
320    int iw, ih; // size of image in pixels
321    int w, h; // size of grid image in pixels (represented by grid)
322    int gw, gh; // size of grid in tiles
323    Eina_Matrixsparse *grid;
324 };
325
326 struct _Widget_Data
327 {
328    Evas_Object *obj;
329    Evas_Object *scr;
330    Evas_Object *pan_smart;
331    Evas_Object *rect;
332    Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
333    Pan *pan;
334    Evas_Coord pan_x, pan_y, minw, minh;
335
336    int id;
337    int zoom;
338    int zoom_method;
339    Elm_Map_Zoom_Mode mode;
340
341    Ecore_Job *calc_job;
342    Ecore_Timer *scr_timer;
343    Ecore_Timer *long_timer;
344    Ecore_Animator *zoom_animator;
345    double t;
346    struct {
347         int w, h;
348         int ow, oh, nw, nh;
349         struct {
350              double x, y;
351         } spos;
352    } size;
353    struct {
354         Eina_Bool show : 1;
355         Evas_Coord x, y ,w ,h;
356    } show;
357    int tsize;
358    int nosmooth;
359    int preload_num;
360    Eina_List *grids;
361    Eina_Bool resized : 1;
362    Eina_Bool on_hold : 1;
363    Eina_Bool paused : 1;
364    Eina_Bool paused_markers : 1;
365
366    struct {
367         Eina_Bool enabled;
368         double lon, lat;
369    } center_on;
370
371    Ecore_Job *markers_place_job;
372    Eina_Matrixsparse **markers;
373    Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
374    Evas_Coord markers_max_num;
375    int marker_max_w, marker_max_h;
376    int marker_zoom;
377    Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
378
379    Eina_List *groups_clas; // list of Elm_Map_Group_Class*
380    Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
381
382    Elm_Map_Route_Sources route_source;
383    Eina_List *s_event_list;
384    int try_num;
385    int finish_num;
386
387    Eina_Hash *ua;
388    const char *user_agent;
389    Eina_List *route;
390    Eina_List *track;
391    Evas_Event_Mouse_Down ev;
392    Eina_List *names;
393    int multi_count;
394
395    struct {
396         Evas_Coord cx, cy;
397         double level, diff;
398         Eina_Bool doing : 1;
399    } pinch;
400
401    struct {
402         Evas_Coord cx, cy;
403         double a, d;
404         Eina_Bool doing : 1;
405    } rotate;
406
407    struct {
408         Evas_Coord cx, cy;
409         double level;
410    } pinch_zoom;
411    double wheel_zoom;
412    Ecore_Timer *wheel_timer;
413    Eina_Bool wheel_disabled : 1;
414
415    Eina_Array *modules;
416    Eina_List *map_sources_tab;
417    const char **source_names;
418    Evas_Map *map;
419    Ecore_Timer *zoom_timer;
420    Map_Sources_Tab *src;
421    const char *gpx_file;
422    int zoom_min, zoom_max;
423 };
424
425 struct _Pan
426 {
427    Evas_Object_Smart_Clipped_Data __clipped_data;
428    Widget_Data *wd;
429 };
430
431 struct _Event
432 {
433    int device;
434
435    struct {
436         Evas_Coord x, y;
437    } start;
438
439    struct {
440         Evas_Coord x, y;
441    } prev;
442
443    Evas_Coord x, y, w, h;
444
445    Evas_Object *object;
446    Ecore_Timer *hold_timer;
447
448    int pinch_start_dis;
449    int pinch_dis;
450 };
451
452 struct _Route_Dump
453 {
454    int id;
455    char *fname;
456    double distance;
457    char *description;
458    char *coordinates;
459 };
460
461 enum _Route_Xml_Attribute
462 {
463    ROUTE_XML_NONE,
464    ROUTE_XML_DISTANCE,
465    ROUTE_XML_DESCRIPTION,
466    ROUTE_XML_COORDINATES,
467    ROUTE_XML_LAST
468 } Route_Xml_Attibute;
469
470 struct _Name_Dump
471 {
472    int id;
473    char *address;
474    double lon;
475    double lat;
476 };
477
478 enum _Name_Xml_Attribute
479 {
480    NAME_XML_NONE,
481    NAME_XML_NAME,
482    NAME_XML_LON,
483    NAME_XML_LAT,
484    NAME_XML_LAST
485 } Name_Xml_Attibute;
486
487 enum _Zoom_Method
488 {
489    ZOOM_METHOD_NONE,
490    ZOOM_METHOD_IN,
491    ZOOM_METHOD_OUT,
492    ZOOM_METHOD_LAST
493 } Zoom_Mode;
494
495 enum _Track_Xml_Attribute
496 {
497    TRACK_XML_NONE,
498    TRACK_XML_COORDINATES,
499    TRACK_XML_LAST
500 } Track_Xml_Attibute;
501
502
503 static const char *widtype = NULL;
504
505 static const char SIG_CHANGED[] = "changed";
506 static const char SIG_CLICKED[] = "clicked";
507 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
508 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
509 static const char SIG_LOAD_DETAIL[] = "load,detail";
510 static const char SIG_LONGPRESSED[] = "longpressed";
511 static const char SIG_PRESS[] = "press";
512 static const char SIG_SCROLL[] = "scroll";
513 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
514 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
515 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
516 static const char SIG_ZOOM_START[] = "zoom,start";
517 static const char SIG_ZOOM_STOP[] = "zoom,stop";
518 static const char SIG_DOWNLOADED[] = "downloaded";
519 static const char SIG_ROUTE_LOAD[] = "route,load";
520 static const char SIG_ROUTE_LOADED[] = "route,loaded";
521 static const char SIG_NAME_LOAD[] = "name,load";
522 static const char SIG_NAME_LOADED[] = "name,loaded";
523 static const Evas_Smart_Cb_Description _signals[] = {
524        {SIG_CHANGED, ""},
525        {SIG_CLICKED, ""},
526        {SIG_CLICKED_DOUBLE, ""},
527        {SIG_LOADED_DETAIL, ""},
528        {SIG_LOAD_DETAIL, ""},
529        {SIG_LONGPRESSED, ""},
530        {SIG_PRESS, ""},
531        {SIG_SCROLL, ""},
532        {SIG_SCROLL_DRAG_START, ""},
533        {SIG_SCROLL_DRAG_STOP, ""},
534        {SIG_ZOOM_CHANGE, ""},
535        {SIG_ZOOM_START, ""},
536        {SIG_ZOOM_STOP, ""},
537        {SIG_DOWNLOADED, ""},
538        {SIG_ROUTE_LOAD, ""},
539        {SIG_ROUTE_LOADED, ""},
540        {SIG_NAME_LOAD, ""},
541        {SIG_NAME_LOADED, ""},
542        {NULL, NULL}
543 };
544
545 static void _pan_calculate(Evas_Object *obj);
546
547 static Eina_Bool _hold_timer_cb(void *data);
548 static Eina_Bool _wheel_timer_cb(void *data);
549 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
550 static void _del_hook(Evas_Object *obj);
551 static void _theme_hook(Evas_Object *obj);
552 static void _on_focus_hook(void *data, Evas_Object *obj);
553 static void _sizing_eval(Evas_Object *obj);
554 static void _calc_job(void *data);
555 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
556                              Evas_Callback_Type type, void *event_info);
557 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
558 static void grid_clear(Evas_Object *obj, Grid *g);
559 static Grid *grid_create(Evas_Object *obj);
560 static void grid_load(Evas_Object *obj, Grid *g);
561
562
563 static void _group_object_create(Marker_Group *group);
564 static void _group_object_free(Marker_Group *group);
565 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
566 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
567 static void _group_bubble_create(Marker_Group *group);
568 static void _group_bubble_free(Marker_Group *group);
569 static void _group_bubble_place(Marker_Group *group);
570
571 static int _group_bubble_content_update(Marker_Group *group);
572 static void _group_bubble_content_free(Marker_Group *group);
573 static void marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
574 static void _bubble_sc_hits_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
575
576 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
577 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
578 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
579
580 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
581 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
582 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
583
584 static void route_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
585 static void track_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
586
587 static int
588 get_multi_device(Evas_Object *obj)
589 {
590    Widget_Data *wd = elm_widget_data_get(obj);
591    Eina_List *l;
592    Event *ev;
593
594    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
595      {
596         if (ev->device) return ev->device;
597      }
598    return 0;
599 }
600
601 static Event *
602 create_event_object(void *data, Evas_Object *obj, int device)
603 {
604    Widget_Data *wd = elm_widget_data_get(data);
605    Event *ev = calloc(1, sizeof(Event));
606
607    EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
608
609    ev->object = obj;
610    ev->device = device;
611    evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
612    wd->s_event_list = eina_list_append(wd->s_event_list, ev);
613    return ev;
614 }
615
616 static Event*
617 get_event_object(void *data, int device)
618 {
619    Widget_Data *wd = elm_widget_data_get(data);
620    Eina_List *l;
621    Event *ev;
622
623    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
624      {
625         if (ev->device == device) break;
626         ev = NULL;
627      }
628    return ev;
629 }
630
631 static void
632 destroy_event_object(void *data, Event *ev)
633 {
634    Widget_Data *wd = elm_widget_data_get(data);
635    EINA_SAFETY_ON_NULL_RETURN(ev);
636    ev->pinch_dis = 0;
637    wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
638    if (ev->hold_timer)
639      {
640         ecore_timer_del(ev->hold_timer);
641         ev->hold_timer = NULL;
642      }
643    free(ev);
644 }
645
646 static Eina_Bool
647 module_list_cb(Eina_Module *m, void *data)
648 {
649    ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
650    Widget_Data *wd = elm_widget_data_get(data);
651    Map_Sources_Tab *s;
652    ElmMapModuleSourceFunc source;
653    ElmMapModuleZoomMinFunc zoom_min;
654    ElmMapModuleZoomMaxFunc zoom_max;
655    ElmMapModuleUrlFunc url;
656    ElmMapModuleRouteSourceFunc route_source;
657    ElmMapModuleRouteUrlFunc route_url;
658    ElmMapModuleNameUrlFunc name_url;
659    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
660    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
661    const char *file;
662
663    if (!wd) return EINA_FALSE;
664
665    file = eina_module_file_get(m);
666    if (!eina_module_load(m))
667      {
668         ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
669         return EINA_FALSE;
670      }
671
672    source = eina_module_symbol_get(m, "map_module_source_get");
673    zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
674    zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
675    url = eina_module_symbol_get(m, "map_module_url_get");
676    route_source = eina_module_symbol_get(m, "map_module_route_source_get");
677    route_url = eina_module_symbol_get(m, "map_module_route_url_get");
678    name_url = eina_module_symbol_get(m, "map_module_name_url_get");
679    geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
680    coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
681    if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
682      {
683         ERR("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
684         eina_module_unload(m);
685         return EINA_FALSE;
686      }
687    s = calloc(1, sizeof(Map_Sources_Tab));
688    EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
689    s->name = source();
690    s->zoom_min = zoom_min();
691    s->zoom_max = zoom_max();
692    s->url_cb = url;
693    s->route_source = route_source();
694    s->route_url_cb = route_url;
695    s->name_url_cb = name_url;
696    s->geo_into_coord = geo_into_coord;
697    s->coord_into_geo = coord_into_geo;
698    wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
699
700    return EINA_TRUE;
701 }
702
703 static void
704 module_init(void *data)
705 {
706    ELM_CHECK_WIDTYPE(data, widtype);
707    Widget_Data *wd = elm_widget_data_get(data);
708
709    if (!wd) return;
710    wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
711 }
712
713 static void
714 source_init(void *data)
715 {
716    ELM_CHECK_WIDTYPE(data, widtype);
717    Widget_Data *wd = elm_widget_data_get(data);
718    Map_Sources_Tab *s;
719    Eina_List *l;
720    int idx;
721
722    if (!wd) return;
723    for (idx = 0; idx < 4; idx++)
724      {
725         s = calloc(1, sizeof(Map_Sources_Tab));
726         EINA_SAFETY_ON_NULL_RETURN(s);
727         s->name = default_map_sources_tab[idx].name;
728         s->zoom_min = default_map_sources_tab[idx].zoom_min;
729         s->zoom_max = default_map_sources_tab[idx].zoom_max;
730         s->url_cb = default_map_sources_tab[idx].url_cb;
731         s->route_source = default_map_sources_tab[idx].route_source;
732         s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
733         s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
734         s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
735         s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
736         wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
737         if (!idx) wd->src = s;
738      }
739    module_init(data);
740
741    int n = eina_list_count(wd->map_sources_tab);
742    wd->source_names = malloc(sizeof(char *) * (n + 1));
743    if (!wd->source_names)
744      {
745         ERR("init source names failed.");
746         return;
747      }
748    idx = 0;
749    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
750      {
751         wd->source_names[idx] = strdup(s->name);
752         INF("source : %s", wd->source_names[idx]);
753         idx++;
754      }
755    wd->source_names[idx] = NULL;
756 }
757
758 static void
759 zoom_min_get(void *data)
760 {
761    ELM_CHECK_WIDTYPE(data, widtype);
762    Widget_Data *wd = elm_widget_data_get(data);
763    Map_Sources_Tab *s;
764    Eina_List *l;
765    int tz;
766
767    if (!wd) return;
768    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
769      {
770         tz = s->zoom_min;
771         if (tz < wd->zoom_min) wd->zoom_min = tz;
772      }
773 }
774
775 static void
776 zoom_max_get(void *data)
777 {
778    ELM_CHECK_WIDTYPE(data, widtype);
779    Widget_Data *wd = elm_widget_data_get(data);
780    Map_Sources_Tab *s;
781    Eina_List *l;
782    int tz;
783
784    if (!wd) return;
785    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
786      {
787         tz = s->zoom_max;
788         if (tz > wd->zoom_max) wd->zoom_max = tz;
789      }
790 }
791
792 static void
793 obj_rotate_zoom(void *data, Evas_Object *obj)
794 {
795    ELM_CHECK_WIDTYPE(data, widtype);
796    Widget_Data *wd = elm_widget_data_get(data);
797    if ((!wd->pinch.cx) && (!wd->pinch.cy))
798      {
799         wd->pinch.cx = wd->rotate.cx;
800         wd->pinch.cy = wd->rotate.cy;
801      }
802
803    evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
804    evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
805    evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
806    evas_object_map_enable_set(obj, EINA_TRUE);
807    evas_object_map_set(obj, wd->map);
808 }
809
810 static void
811 #ifdef ELM_EMAP
812 track_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
813 #else
814 track_place(Evas_Object *obj __UNUSED__, Grid *g __UNUSED__, Evas_Coord px __UNUSED__, Evas_Coord py __UNUSED__, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow __UNUSED__, Evas_Coord oh __UNUSED__)
815 #endif
816 {
817 #ifdef ELM_EMAP
818    ELM_CHECK_WIDTYPE(obj, widtype);
819    Widget_Data *wd = elm_widget_data_get(obj);
820    Eina_List *l;
821    Evas_Object *route;
822    int xmin, xmax, ymin, ymax;
823
824    if (!wd) return;
825    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
826
827    EINA_LIST_FOREACH(wd->track, l, route)
828      {
829         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
830         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
831
832         if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
833         {
834            if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
835            {
836               //display the route
837               evas_object_move(route, xmin - px + ox, ymin - py + oy);
838               evas_object_resize(route, xmax - xmin, ymax - ymin);
839
840               evas_object_raise(route);
841               obj_rotate_zoom(obj, route);
842               evas_object_show(route);
843
844               continue;
845            }
846         }
847         //the route is not display
848         evas_object_hide(route);
849      }
850 #endif
851 }
852 static void
853 route_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
854 {
855    ELM_CHECK_WIDTYPE(obj, widtype);
856    Widget_Data *wd = elm_widget_data_get(obj);
857    Eina_List *lr, *lp, *ln;
858    Path_Node *n;
859    Evas_Object *p;
860    Elm_Map_Route *r;
861    int nodes;
862    int x, y, rx, ry;
863    double a;
864
865    if (!wd) return;
866    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
867
868    EINA_LIST_FOREACH(wd->route, lr, r)
869      {
870         EINA_LIST_FOREACH(r->path, lp, p)
871           {
872              evas_object_polygon_points_clear(p);
873           }
874
875         evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
876         nodes = eina_list_count(r->nodes);
877
878         EINA_LIST_FOREACH(r->nodes, ln, n)
879           {
880              if ((!wd->zoom) || ((n->idx) &&
881                  ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
882              if (r->inbound)
883                {
884                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
885                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
886                       (y >= py - oh) && (y <= (py + oh*2)))
887                     {
888                        x = x - px + rx;
889                        y = y - py + ry;
890
891                        p = eina_list_nth(r->path, n->idx);
892                        a = (double)(y - r->y) / (double)(x - r->x);
893                        if ((abs(a) >= 1) || (r->x == x))
894                          {
895                             evas_object_polygon_point_add(p, r->x - 3, r->y);
896                             evas_object_polygon_point_add(p, r->x + 3, r->y);
897                             evas_object_polygon_point_add(p, x + 3, y);
898                             evas_object_polygon_point_add(p, x - 3, y);
899                          }
900                        else
901                          {
902                             evas_object_polygon_point_add(p, r->x, r->y - 3);
903                             evas_object_polygon_point_add(p, r->x, r->y + 3);
904                             evas_object_polygon_point_add(p, x, y + 3);
905                             evas_object_polygon_point_add(p, x, y - 3);
906                          }
907
908                        evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
909                        evas_object_raise(p);
910                        obj_rotate_zoom(obj, p);
911                        evas_object_show(p);
912                        r->x = x;
913                        r->y = y;
914                     }
915                   else r->inbound = EINA_FALSE;
916                }
917              else
918                {
919                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
920                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
921                       (y >= py - oh) && (y <= (py + oh*2)))
922                     {
923                        r->x = x - px + rx;
924                        r->y = y - py + ry;
925                        r->inbound = EINA_TRUE;
926                     }
927                   else r->inbound = EINA_FALSE;
928                }
929           }
930           r->inbound = EINA_FALSE;
931      }
932 }
933
934 static void
935 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
936 {
937    ELM_CHECK_WIDTYPE(obj, widtype);
938    Widget_Data *wd = elm_widget_data_get(obj);
939    Evas_Coord ax, ay, gw, gh, hh, ww;
940
941    if (!wd) return;
942    evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
943
944    ax = 0;
945    ay = 0;
946    gw = wd->size.w;
947    gh = wd->size.h;
948
949    if ((ww == gw) && (hh == gh)) return;
950
951    if (ow > gw) ax = (ow - gw) / 2;
952    if (oh > gh) ay = (oh - gh) / 2;
953    evas_object_move(wd->rect,
954                     ox + 0 - px + ax,
955                     oy + 0 - py + ay);
956    evas_object_resize(wd->rect, gw, gh);
957
958    if (wd->show.show)
959      {
960         wd->show.show = EINA_FALSE;
961         elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
962      }
963 }
964
965 static void
966 marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
967 {
968    ELM_CHECK_WIDTYPE(obj, widtype);
969    Widget_Data *wd = elm_widget_data_get(obj);
970    Evas_Coord ax, ay, gw, gh, tx, ty;
971    Eina_List *l, *markers;
972    Eina_Matrixsparse_Cell *cell;
973    Marker_Group *group;
974    int xx, yy, ww, hh;
975    char buf[PATH_MAX];
976    int y, x;
977    int g_xx, g_yy, g_hh, g_ww;
978
979    if (!wd) return;
980    if (g != eina_list_data_get(wd->grids)) return;
981
982    ax = 0;
983    ay = 0;
984    gw = wd->size.w;
985    gh = wd->size.h;
986    if (ow > gw) ax = (ow - gw) / 2;
987    if (oh > gh) ay = (oh - gh) / 2;
988
989    if (wd->zoom != wd->marker_zoom)
990      {
991         EINA_LIST_FREE(wd->cells_displayed, cell)
992           {
993              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
994                {
995                   if (group->obj) _group_object_free(group);
996                }
997           }
998      }
999    wd->marker_zoom = wd->zoom;
1000
1001    if ((wd->paused_markers)
1002        && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
1003      return;
1004
1005    g_xx = wd->pan_x / wd->tsize;
1006    if (g_xx < 0) g_xx = 0;
1007    g_yy = wd->pan_y / wd->tsize;
1008    if (g_yy < 0) g_yy = 0;
1009    g_ww = (ow / wd->tsize) + 1;
1010    if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
1011    g_hh = (oh / wd->tsize) + 1;
1012    if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
1013
1014    //hide groups no more displayed
1015    EINA_LIST_FREE(wd->cells_displayed, cell)
1016      {
1017         eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
1018         if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
1019           {
1020              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1021                {
1022                   if (group->obj) _group_object_free(group);
1023                }
1024           }
1025      }
1026
1027    if (!wd->marker_zoom)
1028      {
1029         g_ww = 0;
1030         g_hh = 0;
1031      }
1032
1033    for (y = g_yy; y <= g_yy + g_hh; y++)
1034      {
1035         for (x = g_xx; x <= g_xx + g_ww; x++)
1036           {
1037              if (!wd->markers[wd->zoom]) continue;
1038              eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1039              if (!cell) continue;
1040              wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1041              markers = eina_matrixsparse_cell_data_get(cell);
1042              EINA_LIST_FOREACH(markers, l, group)
1043                {
1044                   if (!group->markers) continue;
1045                   if (group->clas->zoom_displayed > wd->zoom) continue;
1046
1047                   xx = group->x;
1048                   yy = group->y;
1049                   ww = group->w;
1050                   hh = group->h;
1051
1052                   if (eina_list_count(group->markers) == 1)
1053                     {
1054                        Elm_Map_Marker *m = eina_list_data_get(group->markers);
1055                        ww = m->clas->priv.edje_w;
1056                        hh = m->clas->priv.edje_h;
1057                     }
1058
1059                   if (ww <= 0) ww = 1;
1060                   if (hh <= 0) hh = 1;
1061
1062                   if ((gw != g->w) && (g->w > 0))
1063                     {
1064                        tx = xx;
1065                        xx = ((long long )gw * xx) / g->w;
1066                        ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1067                     }
1068                   if ((gh != g->h) && (g->h > 0))
1069                     {
1070                        ty = yy;
1071                        yy = ((long long)gh * yy) / g->h;
1072                        hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1073                     }
1074
1075                   if ((!group->clas->hide)
1076                       && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1077                       && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1078                     {
1079                        if (!group->obj) _group_object_create(group);
1080
1081                        if (group->update_nbelems)
1082                          {
1083                             group->update_nbelems = EINA_FALSE;
1084                             if (eina_list_count(group->markers) > 1)
1085                               {
1086                                  snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1087                                  edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1088                               }
1089                             else
1090                               edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1091                          }
1092                        evas_object_move(group->obj,
1093                                         xx - px + ax + ox - ww/2,
1094                                         yy - py + ay + oy - hh/2);
1095                        if ((!wd->paused_markers) || (group->update_resize))
1096                          {
1097                             group->update_resize = EINA_FALSE;
1098                             evas_object_resize(group->obj, ww, hh);
1099                             obj_rotate_zoom(obj, group->obj);
1100                          }
1101                        if (group->update_raise)
1102                          {
1103                             group->update_raise = EINA_FALSE;
1104                             evas_object_raise(group->obj);
1105                             obj_rotate_zoom(obj, group->obj);
1106                             evas_object_show(group->obj);
1107                          }
1108                        if (group->bubble) _group_bubble_place(group);
1109                     }
1110                   else if (group->obj)
1111                     {
1112                        _group_object_free(group);
1113                     }
1114                }
1115           }
1116      }
1117 }
1118
1119 static void
1120 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1121 {
1122    ELM_CHECK_WIDTYPE(obj, widtype);
1123    Widget_Data *wd = elm_widget_data_get(obj);
1124    Evas_Coord ax, ay, gw, gh, tx, ty;
1125    int xx, yy, ww, hh;
1126
1127    if (!wd) return;
1128    ax = 0;
1129    ay = 0;
1130    gw = wd->size.w;
1131    gh = wd->size.h;
1132    if (ow > gw) ax = (ow - gw) / 2;
1133    if (oh > gh) ay = (oh - gh) / 2;
1134
1135    Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1136    Eina_Matrixsparse_Cell *cell;
1137
1138    EINA_ITERATOR_FOREACH(it, cell)
1139      {
1140         Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1141
1142         xx = gi->out.x;
1143         yy = gi->out.y;
1144         ww = gi->out.w;
1145         hh = gi->out.h;
1146         if ((gw != g->w) && (g->w > 0))
1147           {
1148              tx = xx;
1149              xx = ((long long )gw * xx) / g->w;
1150              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1151           }
1152         if ((gh != g->h) && (g->h > 0))
1153           {
1154              ty = yy;
1155              yy = ((long long)gh * yy) / g->h;
1156              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1157           }
1158         evas_object_move(gi->img,
1159                          xx - px + ax + ox,
1160                          yy - py + ay + oy);
1161
1162         evas_object_resize(gi->img, ww, hh);
1163
1164         obj_rotate_zoom(obj, gi->img);
1165         /*evas_object_move(gi->txt,
1166                            xx - px + ax + ox,
1167                            yy - py + ay + oy);
1168
1169           evas_object_resize(gi->txt, ww, hh);
1170          */
1171      }
1172    eina_iterator_free(it);
1173 }
1174
1175 static void
1176 grid_clear(Evas_Object *obj, Grid *g)
1177 {
1178    ELM_CHECK_WIDTYPE(obj, widtype);
1179    Widget_Data *wd = elm_widget_data_get(obj);
1180    char buf[PATH_MAX];
1181
1182    if (!wd) return;
1183    if (!g->grid) return;
1184
1185    Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1186    Eina_Matrixsparse_Cell *cell;
1187
1188    snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1189    ecore_file_recursive_rm(buf);
1190
1191    EINA_ITERATOR_FOREACH(it, cell)
1192      {
1193         Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1194         evas_object_del(gi->img);
1195         //evas_object_del(gi->txt);
1196
1197         if (gi->want)
1198           {
1199              gi->want = EINA_FALSE;
1200              wd->preload_num--;
1201              if (!wd->preload_num)
1202                {
1203                   edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1204                                           "elm,state,busy,stop", "elm");
1205                   evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
1206                }
1207           }
1208
1209         if (gi->job)
1210           {
1211              DBG("DOWNLOAD abort %s", gi->file);
1212              ecore_file_download_abort(gi->job);
1213              ecore_file_remove(gi->file);
1214              gi->job = NULL;
1215              wd->try_num--;
1216           }
1217         if (gi->file)
1218           eina_stringshare_del(gi->file);
1219
1220         free(gi);
1221      }
1222    eina_matrixsparse_free(g->grid);
1223    eina_iterator_free(it);
1224    g->grid = NULL;
1225    g->gw = 0;
1226    g->gh = 0;
1227 }
1228
1229 static void
1230 _tile_update(Grid_Item *gi)
1231 {
1232    gi->want = EINA_FALSE;
1233    gi->download = EINA_FALSE;
1234    evas_object_image_file_set(gi->img, gi->file, NULL);
1235    if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1236      ecore_file_remove(gi->file);
1237
1238    obj_rotate_zoom(gi->wd->obj, gi->img);
1239    evas_object_show(gi->img);
1240
1241    //evas_object_text_text_set(gi->txt, gi->file);
1242    //evas_object_show(gi->txt);
1243
1244    gi->have = EINA_TRUE;
1245    gi->wd->preload_num--;
1246    if (!gi->wd->preload_num)
1247      {
1248         edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1249                                 "elm,state,busy,stop", "elm");
1250         evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1251      }
1252 }
1253
1254
1255 static void
1256 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1257 {
1258    Grid_Item *gi = data;
1259
1260    gi->download = EINA_FALSE;
1261    gi->job = NULL;
1262
1263    DBG("DOWNLOAD done %s", gi->file);
1264    if ((gi->want) && (!status)) _tile_update(gi);
1265
1266    if (status)
1267      {
1268         DBG("Download failed %s (%d) ", gi->file, status);
1269         ecore_file_remove(gi->file);
1270      }
1271    else
1272      gi->wd->finish_num++;
1273
1274    evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1275 }
1276
1277 static Grid *
1278 grid_create(Evas_Object *obj)
1279 {
1280    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1281    Widget_Data *wd = elm_widget_data_get(obj);
1282    Grid *g;
1283
1284    if ((!wd) || (!wd->src)) return NULL;
1285    g = calloc(1, sizeof(Grid));
1286
1287    g->zoom = wd->zoom;
1288    g->tsize = wd->tsize;
1289    g->wd = wd;
1290
1291    if (g->zoom > wd->src->zoom_max) return NULL;
1292    if (g->zoom < wd->src->zoom_min) return NULL;
1293
1294    int size =  pow(2.0, wd->zoom);
1295    g->gw = size;
1296    g->gh = size;
1297
1298    g->w = g->tsize * g->gw;
1299    g->h = g->tsize * g->gh;
1300
1301    g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1302
1303    return g;
1304 }
1305
1306 static void
1307 grid_load(Evas_Object *obj, Grid *g)
1308 {
1309    ELM_CHECK_WIDTYPE(obj, widtype);
1310    Widget_Data *wd = elm_widget_data_get(obj);
1311    int x, y;
1312    int size;
1313    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1314    Eina_Iterator *it;
1315    Eina_Matrixsparse_Cell *cell;
1316    Grid_Item *gi;
1317
1318    if ((!wd) || (!wd->src)) return;
1319    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1320    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1321
1322    gw = wd->size.w;
1323    gh = wd->size.h;
1324
1325    if ((gw <= 0) || (gh <= 0)) return;
1326
1327    size = g->tsize;
1328    if ((gw != g->w) && (g->w > 0))
1329      size = ((long long)gw * size) / g->w;
1330    if (size < (g->tsize / 2)) return; // else we will load to much tiles
1331
1332    it = eina_matrixsparse_iterator_new(g->grid);
1333
1334    EINA_ITERATOR_FOREACH(it, cell)
1335      {
1336         gi = eina_matrixsparse_cell_data_get(cell);
1337
1338         xx = gi->out.x;
1339         yy = gi->out.y;
1340         ww = gi->out.w;
1341         hh = gi->out.h;
1342
1343         if ((gw != g->w) && (g->w > 0))
1344           {
1345              tx = xx;
1346              xx = ((long long )gw * xx) / g->w;
1347              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1348           }
1349         if ((gh != g->h) && (g->h > 0))
1350           {
1351              ty = yy;
1352              yy = ((long long)gh * yy) / g->h;
1353              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1354           }
1355
1356         if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1357                                  yy  - wd->pan_y + oy,
1358                                  ww, hh,
1359                                  cvx, cvy, cvw, cvh))
1360           {
1361              if (gi->want)
1362                {
1363                   evas_object_hide(gi->img);
1364                   //evas_object_hide(gi->txt);
1365                   evas_object_image_file_set(gi->img, NULL, NULL);
1366                   gi->want = EINA_FALSE;
1367                   gi->have = EINA_FALSE;
1368
1369                   if (gi->job)
1370                     {
1371                        DBG("DOWNLOAD abort %s", gi->file);
1372                        ecore_file_download_abort(gi->job);
1373                        ecore_file_remove(gi->file);
1374                        gi->job = NULL;
1375                        wd->try_num--;
1376                     }
1377                   gi->download = EINA_FALSE;
1378                   wd->preload_num--;
1379                   if (!wd->preload_num)
1380                     {
1381                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1382                                                "elm,state,busy,stop", "elm");
1383                        evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL,
1384                                                        NULL);
1385                     }
1386
1387                }
1388              else if (gi->have)
1389                {
1390                   evas_object_hide(gi->img);
1391                   //evas_object_hide(gi->txt);
1392                   evas_object_image_preload(gi->img, 1);
1393                   evas_object_image_file_set(gi->img, NULL, NULL);
1394                   gi->have = EINA_FALSE;
1395                   gi->want = EINA_FALSE;
1396                }
1397           }
1398      }
1399    eina_iterator_free(it);
1400
1401    xx = wd->pan_x / size - 1;
1402    if (xx < 0) xx = 0;
1403
1404    yy = wd->pan_y / size - 1;
1405    if (yy < 0) yy = 0;
1406
1407    ww = ow / size + 2;
1408    if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1409
1410    hh = oh / size + 2;
1411    if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1412
1413    for (y = yy; y <= yy + hh; y++)
1414      {
1415         for (x = xx; x <= xx + ww; x++)
1416           {
1417              gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1418
1419              if ((!gi) && (g != eina_list_data_get(wd->grids)))
1420                continue;
1421
1422              if (!gi)
1423                {
1424                   gi = calloc(1, sizeof(Grid_Item));
1425                   gi->src.x = x * g->tsize;
1426                   gi->src.y = y * g->tsize;
1427                   gi->src.w = g->tsize;
1428                   gi->src.h = g->tsize;
1429
1430                   gi->out.x = gi->src.x;
1431                   gi->out.y = gi->src.y;
1432                   gi->out.w = gi->src.w;
1433                   gi->out.h = gi->src.h;
1434
1435                   gi->wd = wd;
1436
1437                   gi->img = evas_object_image_add(evas_object_evas_get(obj));
1438                   evas_object_image_scale_hint_set
1439                      (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1440                   evas_object_image_filled_set(gi->img, 1);
1441
1442                   evas_object_smart_member_add(gi->img, wd->pan_smart);
1443                   elm_widget_sub_object_add(obj, gi->img);
1444                   evas_object_pass_events_set(gi->img, EINA_TRUE);
1445                   evas_object_stack_below(gi->img, wd->sep_maps_markers);
1446
1447 /*                gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1448                   evas_object_text_font_set(gi->txt, "Vera", 12);
1449                   evas_object_color_set(gi->txt, 100, 100, 100, 255);
1450                   evas_object_smart_member_add(gi->txt,
1451                                                wd->pan_smart);
1452                   elm_widget_sub_object_add(obj, gi->txt);
1453                   evas_object_pass_events_set(gi->txt, EINA_TRUE);
1454 */
1455                   eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1456                }
1457
1458              if ((!gi->have) && (!gi->download))
1459                {
1460                   char buf[PATH_MAX], buf2[PATH_MAX];
1461                   char *source;
1462
1463                   gi->want = EINA_TRUE;
1464
1465                   snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1466                   if (!ecore_file_exists(buf))
1467                     ecore_file_mkpath(buf);
1468
1469                   snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1470
1471                   source = wd->src->url_cb(obj, x, y, g->zoom);
1472                   if ((!source) || (strlen(source)==0)) continue;
1473
1474                   eina_stringshare_replace(&gi->file, buf2);
1475
1476                   if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1477                     {
1478                        gi->download = EINA_TRUE;
1479                        wd->preload_num++;
1480                        if (wd->preload_num == 1)
1481                          {
1482                             edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1483                                                     "elm,state,busy,start", "elm");
1484                             evas_object_smart_callback_call(obj,
1485                                                             SIG_LOAD_DETAIL,
1486                                                             NULL);
1487                          }
1488
1489                        if (ecore_file_exists(buf2))
1490                          _tile_update(gi);
1491                        else
1492                          {
1493                             DBG("DOWNLOAD %s \t in %s", source, buf2);
1494                             ecore_file_download_full(source, buf2, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1495                             if (!gi->job)
1496                               DBG("Can't start to download %s", buf);
1497                             else
1498                               wd->try_num++;
1499                          }
1500                     }
1501                   if (source) free(source);
1502                }
1503              else if (gi->have)
1504                {
1505                   obj_rotate_zoom(obj, gi->img);
1506                   evas_object_show(gi->img);
1507                }
1508           }
1509      }
1510 }
1511
1512 static void
1513 grid_clearall(Evas_Object *obj)
1514 {
1515    ELM_CHECK_WIDTYPE(obj, widtype);
1516    Widget_Data *wd = elm_widget_data_get(obj);
1517    Grid *g;
1518
1519    if (!wd) return;
1520    EINA_LIST_FREE(wd->grids, g)
1521      {
1522         grid_clear(obj, g);
1523         free(g);
1524      }
1525 }
1526
1527 static void
1528 _smooth_update(Evas_Object *obj)
1529 {
1530    ELM_CHECK_WIDTYPE(obj, widtype);
1531    Widget_Data *wd = elm_widget_data_get(obj);
1532    Eina_List *l;
1533    Grid *g;
1534
1535    if (!wd) return;
1536    EINA_LIST_FOREACH(wd->grids, l, g)
1537      {
1538         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1539         Eina_Matrixsparse_Cell *cell;
1540
1541         EINA_ITERATOR_FOREACH(it, cell)
1542           {
1543              Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1544              evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1545           }
1546         eina_iterator_free(it);
1547      }
1548 }
1549
1550 static Eina_Bool
1551 _scr_timeout(void *data)
1552 {
1553    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1554    Widget_Data *wd = elm_widget_data_get(data);
1555
1556    if (!wd) return ECORE_CALLBACK_CANCEL;
1557    wd->nosmooth--;
1558    if (!wd->nosmooth) _smooth_update(data);
1559    wd->scr_timer = NULL;
1560    return ECORE_CALLBACK_CANCEL;
1561 }
1562
1563 static void
1564 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1565 {
1566    ELM_CHECK_WIDTYPE(data, widtype);
1567    Widget_Data *wd = elm_widget_data_get(data);
1568
1569    if (!wd) return;
1570    if (!wd->scr_timer)
1571      {
1572         wd->nosmooth++;
1573         if (wd->nosmooth == 1) _smooth_update(data);
1574      }
1575    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1576    wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1577 }
1578
1579 static void
1580 zoom_do(Evas_Object *obj)
1581 {
1582    ELM_CHECK_WIDTYPE(obj, widtype);
1583    Widget_Data *wd = elm_widget_data_get(obj);
1584    Evas_Coord xx, yy, ow, oh;
1585
1586    if (!wd) return;
1587    wd->size.w = wd->size.nw;
1588    wd->size.h = wd->size.nh;
1589
1590    elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1591
1592    if (wd->center_on.enabled)
1593      {
1594         elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1595         xx -= ow / 2;
1596         yy -= oh / 2;
1597      }
1598    else
1599      {
1600         xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1601         yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1602      }
1603
1604
1605    if (xx < 0) xx = 0;
1606    else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1607    if (yy < 0) yy = 0;
1608    else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1609
1610    wd->show.show = EINA_TRUE;
1611    wd->show.x = xx;
1612    wd->show.y = yy;
1613    wd->show.w = ow;
1614    wd->show.h = oh;
1615
1616    if (wd->calc_job) ecore_job_del(wd->calc_job);
1617    wd->calc_job = ecore_job_add(_calc_job, wd);
1618 }
1619
1620 static Eina_Bool
1621 _zoom_timeout(void *data)
1622 {
1623    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1624    Widget_Data *wd = elm_widget_data_get(data);
1625
1626    if (!wd) return ECORE_CALLBACK_CANCEL;
1627    wd->zoom_timer = NULL;
1628    wd->pinch.level = 1.0;
1629    zoom_do(data);
1630    evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1631    return ECORE_CALLBACK_CANCEL;
1632 }
1633
1634 static Eina_Bool
1635 _zoom_anim(void *data)
1636 {
1637    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1638    Evas_Object *obj = data;
1639    Widget_Data *wd = elm_widget_data_get(obj);
1640
1641    if (!wd) return ECORE_CALLBACK_CANCEL;
1642    if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1643    else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1644    else
1645      {
1646         wd->zoom_animator = NULL;
1647         zoom_do(obj);
1648         evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1649         return ECORE_CALLBACK_CANCEL;
1650      }
1651
1652    if (wd->t >= 2.0)
1653      {
1654         wd->zoom_animator = NULL;
1655         wd->pinch.level = 2.0;
1656         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1657         wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1658         return ECORE_CALLBACK_CANCEL;
1659      }
1660    else if (wd->t <= 0.5)
1661      {
1662         wd->zoom_animator = NULL;
1663         wd->pinch.level = 0.5;
1664         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1665         wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1666         return ECORE_CALLBACK_CANCEL;
1667      }
1668    else if (wd->t != 1.0)
1669      {
1670         Evas_Coord x, y, w, h;
1671         float half_w, half_h;
1672         evas_object_geometry_get(data, &x, &y, &w, &h);
1673         half_w = (float)w * 0.5;
1674         half_h = (float)h * 0.5;
1675         wd->pinch.cx = x + half_w;
1676         wd->pinch.cy = y + half_h;
1677         wd->pinch.level = wd->t;
1678         if (wd->calc_job) ecore_job_del(wd->calc_job);
1679         wd->calc_job = ecore_job_add(_calc_job, wd);
1680      }
1681    return ECORE_CALLBACK_RENEW;
1682 }
1683
1684 static Eina_Bool
1685 _long_press(void *data)
1686 {
1687    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1688    Widget_Data *wd = elm_widget_data_get(data);
1689
1690    if (!wd) return ECORE_CALLBACK_CANCEL;
1691    wd->long_timer = NULL;
1692    evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1693    return ECORE_CALLBACK_CANCEL;
1694 }
1695
1696 static void
1697 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1698 {
1699    ELM_CHECK_WIDTYPE(data, widtype);
1700    Widget_Data *wd = elm_widget_data_get(data);
1701    Evas_Event_Mouse_Down *ev = event_info;
1702    Event *ev0;
1703
1704    if (!wd) return;
1705    ev0 = get_event_object(data, 0);
1706    if (ev0) return;
1707    ev0 = create_event_object(data, obj, 0);
1708    if (!ev0) return;
1709
1710    ev0->hold_timer = NULL;
1711    ev0->prev.x = ev->canvas.x;
1712    ev0->prev.y = ev->canvas.y;
1713
1714    if (ev->button != 1) return;
1715    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1716    else wd->on_hold = EINA_FALSE;
1717    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1718      evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1719    else
1720      evas_object_smart_callback_call(data, SIG_PRESS, ev);
1721    if (wd->long_timer) ecore_timer_del(wd->long_timer);
1722    wd->ev.canvas.x = ev->output.x;
1723    wd->ev.canvas.y = ev->output.y;
1724    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1725 }
1726
1727 static void
1728 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1729 {
1730    Evas_Event_Mouse_Move *move = event_info;
1731    Event *ev0;
1732
1733    ev0 = get_event_object(data, 0);
1734    if (!ev0) return;
1735    ev0->prev.x = move->cur.canvas.x;
1736    ev0->prev.y = move->cur.canvas.y;
1737 }
1738
1739 static void
1740 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1741 {
1742    ELM_CHECK_WIDTYPE(data, widtype);
1743    Widget_Data *wd = elm_widget_data_get(data);
1744
1745    if (!wd) return;
1746    Evas_Event_Mouse_Up *ev = event_info;
1747    int mdevice;
1748    Event *ev0;
1749    Event *ev1;
1750
1751    ev0 = get_event_object(data, 0);
1752    if (ev0)
1753      {
1754         mdevice = get_multi_device(data);
1755         if (mdevice == 0)
1756           {
1757              if (ev0->hold_timer)
1758                {
1759                   ecore_timer_del(ev0->hold_timer);
1760                   ev0->hold_timer = NULL;
1761                }
1762              elm_smart_scroller_hold_set(wd->scr, 0);
1763              elm_smart_scroller_freeze_set(wd->scr, 0);
1764           }
1765         else
1766           {
1767              ev1 = get_event_object(data, mdevice);
1768              if (ev1)
1769                ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1770           }
1771         destroy_event_object(data, ev0);
1772      }
1773
1774    if (ev->button != 1) return;
1775    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1776    else wd->on_hold = EINA_FALSE;
1777    if (wd->long_timer)
1778      {
1779         ecore_timer_del(wd->long_timer);
1780         wd->long_timer = NULL;
1781      }
1782    if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1783    wd->on_hold = EINA_FALSE;
1784 }
1785
1786 static void
1787 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1788 {
1789    ELM_CHECK_WIDTYPE(data, widtype);
1790    Widget_Data *wd = elm_widget_data_get(data);
1791    Event *ev;
1792    Evas_Event_Multi_Down *down = event_info;
1793
1794    elm_smart_scroller_hold_set(wd->scr, 1);
1795    elm_smart_scroller_freeze_set(wd->scr, 1);
1796
1797    ev = create_event_object(data, obj, down->device);
1798    if (!ev)
1799      {
1800         DBG("Failed : create_event_object");
1801         goto done;
1802      }
1803    wd->multi_count++;
1804
1805    ev->hold_timer = NULL;
1806    ev->start.x = ev->prev.x = down->canvas.x;
1807    ev->start.y = ev->prev.y = down->canvas.y;
1808    ev->pinch_start_dis = 0;
1809    wd->pinch.level = 1.0;
1810    wd->pinch.diff = 1.0;
1811
1812 done:
1813    if (wd->long_timer)
1814      {
1815         ecore_timer_del(wd->long_timer);
1816         wd->long_timer = NULL;
1817      }
1818    return;
1819 }
1820
1821 static void
1822 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1823 {
1824    ELM_CHECK_WIDTYPE(data, widtype);
1825    Widget_Data *wd = elm_widget_data_get(data);
1826    Evas_Event_Multi_Move *move = event_info;
1827    int dis_new, dx, dy;
1828    double t, tt, a, a_diff;
1829    Event *ev0;
1830    Event *ev;
1831
1832    if ((!wd) || (!wd->src)) return;
1833    ev = get_event_object(data, move->device);
1834    if (!ev) return;
1835
1836    ev0 = get_event_object(data, 0);
1837    if (!ev0) return;
1838
1839    if (wd->multi_count >= 1)
1840      {
1841         Evas_Coord x, y, w, h;
1842         float half_w, half_h;
1843
1844         evas_object_geometry_get(data, &x, &y, &w, &h);
1845         half_w = (float)w * 0.5;
1846         half_h = (float)h * 0.5;
1847         dx = ev0->prev.x - ev->prev.x;
1848         dy = ev0->prev.y - ev->prev.y;
1849         dis_new = sqrt((dx * dx) + (dy * dy));
1850
1851         if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1852         else
1853           {
1854              ev->pinch_dis = dis_new;
1855              tt = wd->pinch.diff;
1856              wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1857              t = (wd->pinch.diff * 0.01) + 1.0;
1858              if ((t > 1.1) || (wd->rotate.doing))
1859                {
1860                   if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1861                       ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1862                       (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1863                     {
1864                        wd->pinch.diff = tt;
1865                        goto do_nothing;
1866                     }
1867                   else
1868                     {
1869                        wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1870                        wd->pinch.cx = x + half_w;
1871                        wd->pinch.cy = y + half_h;
1872                        wd->pinch.doing = EINA_TRUE;
1873                        if (!wd->rotate.doing) goto do_zoom_only;
1874                     }
1875                }
1876              else
1877                {
1878                   if (wd->pinch.doing) goto do_nothing;
1879                }
1880
1881              a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1882              if (!wd->rotate.a) wd->rotate.a = a;
1883              else
1884                {
1885                   a_diff = wd->rotate.a - a;
1886                   if (a_diff > 0) wd->rotate.d -= 1.0;
1887                   else if (a_diff < 0) wd->rotate.d += 1.0;
1888                   wd->rotate.a = a;
1889                   wd->rotate.cx = x + half_w;
1890                   wd->rotate.cy = y + half_h;
1891                   wd->rotate.doing = EINA_TRUE;
1892                }
1893 do_zoom_only:
1894              if (wd->calc_job) ecore_job_del(wd->calc_job);
1895              wd->calc_job = ecore_job_add(_calc_job, wd);
1896           }
1897      }
1898 do_nothing:
1899    ev->prev.x = move->cur.canvas.x;
1900    ev->prev.y = move->cur.canvas.y;
1901 }
1902
1903 static void
1904 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1905 {
1906    ELM_CHECK_WIDTYPE(data, widtype);
1907    Widget_Data *wd = elm_widget_data_get(data);
1908    Evas_Event_Multi_Up *up = event_info;
1909    Event *ev0;
1910    Event *ev;
1911    Eina_Bool tp;
1912    int zoom = 0;
1913
1914    wd->multi_count--;
1915    if (wd->calc_job) ecore_job_del(wd->calc_job);
1916    if (wd->zoom_animator)
1917      {
1918         ecore_animator_del(wd->zoom_animator);
1919         wd->zoom_animator = NULL;
1920      }
1921    tp = wd->paused;
1922    wd->paused = EINA_TRUE;
1923    if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1924    else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1925    elm_map_zoom_set(data, wd->zoom + zoom);
1926    wd->pinch.level = 1.0;
1927    wd->pinch.doing = EINA_FALSE;
1928    wd->paused = tp;
1929    wd->rotate.a = 0.0;
1930    wd->rotate.doing = EINA_FALSE;
1931
1932    ev = get_event_object(data, up->device);
1933    if (!ev)
1934      {
1935         DBG("Cannot get multi device");
1936         return;
1937      }
1938
1939    ev0 = get_event_object(data, 0);
1940    if (ev0)
1941      ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1942    else
1943      {
1944         if (ev->hold_timer)
1945           {
1946              ecore_timer_del(ev->hold_timer);
1947              ev->hold_timer = NULL;
1948           }
1949      }
1950    destroy_event_object(data, ev);
1951 }
1952
1953 static void
1954 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1955 {
1956    ELM_CHECK_WIDTYPE(data, widtype);
1957    Widget_Data *wd = elm_widget_data_get(data);
1958    Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1959    Evas_Coord x, y, w, h;
1960    float half_w, half_h;
1961
1962    if (!wd) return;
1963    evas_object_geometry_get(data, &x, &y, &w, &h);
1964    half_w = (float)w * 0.5;
1965    half_h = (float)h * 0.5;
1966
1967    if (!wd->wheel_zoom) wd->wheel_zoom = 1.0;
1968    if (ev->z > 0)
1969      {
1970         wd->zoom_method = ZOOM_METHOD_OUT;
1971         wd->wheel_zoom -= 0.05;
1972         if (wd->wheel_zoom <= PINCH_ZOOM_MIN) wd->wheel_zoom = PINCH_ZOOM_MIN;
1973      }
1974    else
1975      {
1976         wd->zoom_method = ZOOM_METHOD_IN;
1977         wd->wheel_zoom += 0.2;
1978         if (wd->wheel_zoom >= PINCH_ZOOM_MAX) wd->wheel_zoom = PINCH_ZOOM_MAX;
1979      }
1980
1981    if (!wd->paused)
1982      {
1983    wd->pinch.level = wd->wheel_zoom;
1984    wd->pinch.cx = x + half_w;
1985    wd->pinch.cy = y + half_h;
1986    if (wd->calc_job) ecore_job_del(wd->calc_job);
1987    wd->calc_job = ecore_job_add(_calc_job, wd);
1988      }
1989
1990    if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
1991    wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
1992 }
1993
1994
1995 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
1996
1997 static Eina_Bool
1998 _hold_timer_cb(void *data)
1999 {
2000    Event *ev0 = data;
2001
2002    ev0->hold_timer = NULL;
2003    return ECORE_CALLBACK_CANCEL;
2004 }
2005
2006 static Eina_Bool
2007 _wheel_timer_cb(void *data)
2008 {
2009    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2010    Widget_Data *wd = elm_widget_data_get(data);
2011    int zoom;
2012
2013    if (!wd)
2014      {
2015         wd->wheel_timer = NULL;
2016         return ECORE_CALLBACK_CANCEL;
2017      }
2018    if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom - 1.0);
2019    else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor((-1.0 / wd->wheel_zoom) + 1.0);
2020    else
2021      {
2022         wd->wheel_timer = NULL;
2023         return ECORE_CALLBACK_CANCEL;
2024      }
2025    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2026    elm_map_zoom_set(data, wd->zoom + zoom);
2027    wd->wheel_zoom = 0.0;
2028    wd->wheel_timer = NULL;
2029    return ECORE_CALLBACK_CANCEL;
2030 }
2031
2032 static void
2033 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2034 {
2035    ELM_CHECK_WIDTYPE(data, widtype);
2036    Widget_Data *wd = elm_widget_data_get(data);
2037    int x, y, w, h;
2038
2039    evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2040    evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2041    evas_object_resize(wd->rect, w, h);
2042    evas_object_move(wd->rect, x, y);
2043 }
2044
2045 static void
2046 _del_hook(Evas_Object *obj)
2047 {
2048    ELM_CHECK_WIDTYPE(obj, widtype);
2049    Widget_Data *wd = elm_widget_data_get(obj);
2050    Elm_Map_Group_Class *group_clas;
2051    Elm_Map_Marker_Class *marker_clas;
2052    Eina_List *l;
2053    Event *ev;
2054    Evas_Object *p;
2055    Path_Node *n;
2056    Path_Waypoint *w;
2057    Ecore_Event_Handler *h;
2058    Elm_Map_Route *r;
2059    Elm_Map_Name *na;
2060    Evas_Object *route;
2061
2062    if (!wd) return;
2063    EINA_LIST_FREE(wd->groups_clas, group_clas)
2064      {
2065         if (group_clas->style)
2066           eina_stringshare_del(group_clas->style);
2067         free(group_clas);
2068      }
2069
2070    EINA_LIST_FREE(wd->markers_clas, marker_clas)
2071      {
2072         if (marker_clas->style)
2073           eina_stringshare_del(marker_clas->style);
2074         free(marker_clas);
2075      }
2076
2077    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2078      {
2079         destroy_event_object(obj, ev);
2080      }
2081
2082    EINA_LIST_FOREACH(wd->route, l, r)
2083      {
2084         EINA_LIST_FREE(r->path, p)
2085           {
2086              evas_object_del(p);
2087           }
2088
2089         EINA_LIST_FREE(r->waypoint, w)
2090           {
2091              if (w->point) eina_stringshare_del(w->point);
2092              free(w);
2093           }
2094
2095         EINA_LIST_FREE(r->nodes, n)
2096           {
2097              if (n->pos.address) eina_stringshare_del(n->pos.address);
2098              free(n);
2099           }
2100
2101         EINA_LIST_FREE(r->handlers, h)
2102           {
2103              ecore_event_handler_del(h);
2104           }
2105
2106         if (r->con_url) ecore_con_url_free(r->con_url);
2107         if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2108         if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2109      }
2110
2111    EINA_LIST_FREE(wd->names, na)
2112      {
2113         if (na->address) free(na->address);
2114         if (na->handler) ecore_event_handler_del(na->handler);
2115         if (na->ud.fname)
2116           {
2117              ecore_file_remove(na->ud.fname);
2118              free(na->ud.fname);
2119              na->ud.fname = NULL;
2120           }
2121      }
2122
2123    EINA_LIST_FREE(wd->track, route)
2124      {
2125         evas_object_del(route);
2126      }
2127
2128    if (wd->map) evas_map_free(wd->map);
2129    if (wd->source_names) free(wd->source_names);
2130    if (wd->calc_job) ecore_job_del(wd->calc_job);
2131    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2132    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2133    if (wd->long_timer) ecore_timer_del(wd->long_timer);
2134    if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2135    if (wd->ua) eina_hash_free(wd->ua);
2136    if (wd->markers) free(wd->markers);
2137
2138    free(wd);
2139 }
2140
2141 static void
2142 _del_pre_hook(Evas_Object *obj)
2143 {
2144    ELM_CHECK_WIDTYPE(obj, widtype);
2145    Widget_Data *wd = elm_widget_data_get(obj);
2146    Marker_Group *group;
2147    Elm_Map_Marker *marker;
2148    int i;
2149    Eina_Bool free_marker = EINA_TRUE;
2150    Eina_List *l;
2151
2152    if (!wd) return;
2153    grid_clearall(obj);
2154    for (i = 0; i <= wd->zoom_max; i++)
2155      {
2156         if (!wd->markers[i]) continue;
2157         Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2158         Eina_Matrixsparse_Cell *cell;
2159
2160         EINA_ITERATOR_FOREACH(it, cell)
2161           {
2162              l =  eina_matrixsparse_cell_data_get(cell);
2163              EINA_LIST_FREE(l, group)
2164                {
2165                   EINA_LIST_FREE(group->markers, marker)
2166                     {
2167                        evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2168                                                            _bubble_sc_hits_changed_cb, group);
2169                        if (free_marker) free(marker);
2170                     }
2171                   free(group);
2172                }
2173              free_marker = EINA_FALSE;
2174           }
2175         eina_iterator_free(it);
2176         eina_matrixsparse_free(wd->markers[i]);
2177      }
2178
2179    evas_object_del(wd->sep_maps_markers);
2180    evas_object_del(wd->pan_smart);
2181    wd->pan_smart = NULL;
2182 }
2183
2184 static void
2185 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2186 {
2187    ELM_CHECK_WIDTYPE(obj, widtype);
2188    Widget_Data *wd = elm_widget_data_get(obj);
2189
2190    if (!wd) return;
2191    if (elm_widget_focus_get(obj))
2192      {
2193         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2194         evas_object_focus_set(wd->obj, EINA_TRUE);
2195      }
2196    else
2197      {
2198         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2199         evas_object_focus_set(wd->obj, EINA_FALSE);
2200      }
2201 }
2202
2203 static void
2204 _theme_hook(Evas_Object *obj)
2205 {
2206    ELM_CHECK_WIDTYPE(obj, widtype);
2207    Widget_Data *wd = elm_widget_data_get(obj);
2208
2209    if (!wd) return;
2210    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2211    //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2212    _sizing_eval(obj);
2213 }
2214
2215 static void
2216 _sizing_eval(Evas_Object *obj)
2217 {
2218    ELM_CHECK_WIDTYPE(obj, widtype);
2219    Widget_Data *wd = elm_widget_data_get(obj);
2220    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2221
2222    if (!wd) return;
2223    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2224    evas_object_size_hint_min_set(obj, minw, minh);
2225    evas_object_size_hint_max_set(obj, maxw, maxh);
2226 }
2227
2228 static void
2229 _calc_job(void *data)
2230 {
2231    Widget_Data *wd = data;
2232    Evas_Coord minw, minh;
2233
2234    if (!wd) return;
2235    minw = wd->size.w;
2236    minh = wd->size.h;
2237    if (wd->resized)
2238      {
2239         wd->resized = EINA_FALSE;
2240         if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2241           {
2242              double tz = wd->zoom;
2243              wd->zoom = 0.0;
2244              elm_map_zoom_set(wd->obj, tz);
2245           }
2246      }
2247    if ((minw != wd->minw) || (minh != wd->minh))
2248      {
2249         wd->minw = minw;
2250         wd->minh = minh;
2251         evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2252         _sizing_eval(wd->obj);
2253      }
2254    wd->calc_job = NULL;
2255    evas_object_smart_changed(wd->pan_smart);
2256 }
2257
2258 static void
2259 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2260 {
2261    Pan *sd = evas_object_smart_data_get(obj);
2262    if (!sd) return;
2263    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2264    sd->wd->pan_x = x;
2265    sd->wd->pan_y = y;
2266    evas_object_smart_changed(obj);
2267 }
2268
2269 static void
2270 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2271 {
2272    Pan *sd = evas_object_smart_data_get(obj);
2273    if (!sd) return;
2274    if (x) *x = sd->wd->pan_x;
2275    if (y) *y = sd->wd->pan_y;
2276 }
2277
2278 static void
2279 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2280 {
2281    Pan *sd = evas_object_smart_data_get(obj);
2282    Evas_Coord ow, oh;
2283    if (!sd) return;
2284    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2285    ow = sd->wd->minw - ow;
2286    if (ow < 0) ow = 0;
2287    oh = sd->wd->minh - oh;
2288    if (oh < 0) oh = 0;
2289    if (x) *x = ow;
2290    if (y) *y = oh;
2291 }
2292
2293 static void
2294 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2295 {
2296    if (x) *x = 0;
2297    if (y) *y = 0;
2298 }
2299
2300 static void
2301 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2302 {
2303    Pan *sd = evas_object_smart_data_get(obj);
2304    if (!sd) return;
2305    if (w) *w = sd->wd->minw;
2306    if (h) *h = sd->wd->minh;
2307 }
2308
2309 static void
2310 _pan_add(Evas_Object *obj)
2311 {
2312    Pan *sd;
2313    Evas_Object_Smart_Clipped_Data *cd;
2314    _pan_sc.add(obj);
2315    cd = evas_object_smart_data_get(obj);
2316    if (!cd) return;
2317    sd = calloc(1, sizeof(Pan));
2318    if (!sd) return;
2319    sd->__clipped_data = *cd;
2320    free(cd);
2321    evas_object_smart_data_set(obj, sd);
2322 }
2323
2324 static void
2325 _pan_del(Evas_Object *obj)
2326 {
2327    Pan *sd = evas_object_smart_data_get(obj);
2328    if (!sd) return;
2329    _pan_sc.del(obj);
2330 }
2331
2332 static void
2333 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2334 {
2335    Pan *sd = evas_object_smart_data_get(obj);
2336    Evas_Coord ow, oh;
2337    if (!sd) return;
2338    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2339    if ((ow == w) && (oh == h)) return;
2340    sd->wd->resized = EINA_TRUE;
2341    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2342    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2343 }
2344
2345 static void
2346 _pan_calculate(Evas_Object *obj)
2347 {
2348    Pan *sd = evas_object_smart_data_get(obj);
2349    Evas_Coord ox, oy, ow, oh;
2350    Eina_List *l;
2351    Grid *g;
2352    if (!sd) return;
2353    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2354    rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2355    EINA_LIST_FOREACH(sd->wd->grids, l, g)
2356      {
2357         if ((sd->wd->pinch.level == 1.0) || (sd->wd->pinch.level == 0.5)) grid_load(sd->wd->obj, g);
2358         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2359         marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2360         if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2361         if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2362      }
2363 }
2364
2365 static void
2366 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2367 {
2368    Pan *sd = evas_object_smart_data_get(obj);
2369    if (!sd) return;
2370    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2371    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2372 }
2373
2374 static void
2375 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2376 {
2377    ELM_CHECK_WIDTYPE(obj, widtype);
2378    Widget_Data *wd = elm_widget_data_get(obj);
2379
2380    if (!wd) return;
2381    elm_smart_scroller_hold_set(wd->scr, 1);
2382 }
2383
2384 static void
2385 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2386 {
2387    ELM_CHECK_WIDTYPE(obj, widtype);
2388    Widget_Data *wd = elm_widget_data_get(obj);
2389
2390    if (!wd) return;
2391    elm_smart_scroller_hold_set(wd->scr, 0);
2392 }
2393
2394 static void
2395 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2396 {
2397    ELM_CHECK_WIDTYPE(obj, widtype);
2398    Widget_Data *wd = elm_widget_data_get(obj);
2399
2400    if (!wd) return;
2401    elm_smart_scroller_freeze_set(wd->scr, 1);
2402 }
2403
2404 static void
2405 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2406 {
2407    ELM_CHECK_WIDTYPE(obj, widtype);
2408    Widget_Data *wd = elm_widget_data_get(obj);
2409
2410    if (!wd) return;
2411    elm_smart_scroller_freeze_set(wd->scr, 0);
2412 }
2413
2414 static void
2415 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2416 {
2417    evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2418 }
2419
2420 static void
2421 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2422 {
2423    evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2424 }
2425
2426 static void
2427 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2428 {
2429    Widget_Data *wd = elm_widget_data_get(data);
2430    wd->center_on.enabled = EINA_FALSE;
2431    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2432 }
2433
2434 static void
2435 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2436 {
2437    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2438 }
2439
2440 static void
2441 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2442 {
2443    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2444 }
2445
2446
2447 static void
2448 _group_object_create(Marker_Group *group)
2449 {
2450    const char *style = "radio";
2451    Evas_Object *icon = NULL;
2452
2453    if (group->obj) return;
2454    if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2455      {
2456         //set icon and style
2457         if (eina_list_count(group->markers) == 1)
2458           {
2459              Elm_Map_Marker *m = eina_list_data_get(group->markers);
2460              if (m->clas->style)
2461                style = m->clas->style;
2462
2463              if (m->clas->func.icon_get)
2464                icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2465
2466              group->delete_object = EINA_TRUE;
2467           }
2468         else
2469           {
2470              if (group->clas->style)
2471                style = group->clas->style;
2472
2473              if (group->clas->func.icon_get)
2474                icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2475
2476              group->delete_object = EINA_FALSE;
2477           }
2478
2479         group->obj = elm_layout_add(group->wd->obj);
2480         elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2481
2482         if (icon) elm_layout_content_set(group->obj, "elm.icon", icon);
2483
2484         evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2485         elm_widget_sub_object_add(group->wd->obj, group->obj);
2486         evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2487
2488         if (!group->delete_object)
2489           group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2490      }
2491    else
2492      {
2493         group->delete_object = EINA_FALSE;
2494
2495         group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2496         group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2497         group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2498         evas_object_show(group->obj);
2499      }
2500
2501    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2502    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2503
2504    group->update_nbelems = EINA_TRUE;
2505    group->update_resize = EINA_TRUE;
2506    group->update_raise = EINA_TRUE;
2507
2508    if (group->open) _group_bubble_create(group);
2509 }
2510
2511 static void
2512 _group_object_free(Marker_Group *group)
2513 {
2514    if (!group->obj) return;
2515    if (!group->delete_object)
2516      {
2517         group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2518         group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2519         evas_object_hide(group->obj);
2520
2521         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2522         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2523      }
2524    else
2525      evas_object_del(group->obj);
2526
2527    group->obj = NULL;
2528    _group_bubble_free(group);
2529 }
2530
2531 static void
2532 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2533 {
2534    Marker_Group *group = data;
2535
2536    if (!evas_object_above_get(group->rect)) return;
2537    evas_object_raise(group->bubble);
2538    evas_object_raise(group->sc);
2539    evas_object_raise(group->rect);
2540 }
2541
2542 static void
2543 _group_bubble_create(Marker_Group *group)
2544 {
2545    if (group->bubble) return;
2546
2547    group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2548    group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2549    _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2550                          elm_widget_style_get(group->wd->obj));
2551    evas_object_smart_member_add(group->bubble,
2552                                 group->wd->obj);
2553    elm_widget_sub_object_add(group->wd->obj, group->bubble);
2554
2555    _group_bubble_content_free(group);
2556    if (!_group_bubble_content_update(group))
2557      {
2558         //no content, we can delete the bubble
2559         _group_bubble_free(group);
2560         return;
2561      }
2562
2563    group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2564    evas_object_color_set(group->rect, 0, 0, 0, 0);
2565    evas_object_repeat_events_set(group->rect, EINA_TRUE);
2566    evas_object_smart_member_add(group->rect, group->wd->obj);
2567    elm_widget_sub_object_add(group->wd->obj, group->rect);
2568
2569    evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2570
2571    _group_bubble_place(group);
2572 }
2573
2574 static void _bubble_sc_hits_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2575 {
2576    _group_bubble_place(data);
2577 }
2578
2579 static int
2580 _group_bubble_content_update(Marker_Group *group)
2581 {
2582    Eina_List *l;
2583    Elm_Map_Marker *marker;
2584    int i = 0;
2585
2586    if (!group->bubble) return 1;
2587
2588    if (!group->sc)
2589      {
2590         group->sc = elm_scroller_add(group->bubble);
2591         elm_widget_style_set(group->sc, "map_bubble");
2592         elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2593         elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2594         elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2595         edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2596         evas_object_show(group->sc);
2597         evas_object_smart_member_add(group->sc,
2598                                      group->wd->obj);
2599         elm_widget_sub_object_add(group->wd->obj, group->sc);
2600
2601         group->bx = elm_box_add(group->bubble);
2602         evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2603         evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2604         elm_box_horizontal_set(group->bx, EINA_TRUE);
2605         evas_object_show(group->bx);
2606
2607         elm_scroller_content_set(group->sc, group->bx);
2608
2609         evas_object_event_callback_add(group->sc, EVAS_CALLBACK_RESIZE,
2610                                        _bubble_sc_hits_changed_cb, group);
2611      }
2612
2613    EINA_LIST_FOREACH(group->markers, l, marker)
2614      {
2615         if (i >= group->wd->markers_max_num) break;
2616         if ((!marker->content) && (marker->clas->func.get))
2617           marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2618         else if (marker->content)
2619           elm_box_unpack(group->bx, marker->content);
2620         if (marker->content)
2621           {
2622              elm_box_pack_end(group->bx, marker->content);
2623              i++;
2624           }
2625      }
2626    return i;
2627 }
2628
2629 static void
2630 _group_bubble_content_free(Marker_Group *group)
2631 {
2632    Eina_List *l;
2633    Elm_Map_Marker *marker;
2634
2635    if (!group->sc) return;
2636    EINA_LIST_FOREACH(group->markers, l, marker)
2637      {
2638         if ((marker->content) && (marker->clas->func.del))
2639           marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2640         else if (marker->content)
2641           evas_object_del(marker->content);
2642         marker->content = NULL;
2643      }
2644    evas_object_del(group->sc);
2645    group->sc = NULL;
2646 }
2647
2648 static void
2649 _group_bubble_free(Marker_Group *group)
2650 {
2651    if (!group->bubble) return;
2652    group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2653    evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2654                                        _bubble_sc_hits_changed_cb, group);
2655    evas_object_del(group->bubble);
2656    evas_object_del(group->rect);
2657    group->bubble = NULL;
2658    _group_bubble_content_free(group);
2659 }
2660
2661 static void
2662 _group_bubble_place(Marker_Group *group)
2663 {
2664    Evas_Coord x, y, w;
2665    Evas_Coord xx, yy, ww, hh;
2666    const char *s;
2667
2668    if ((!group->bubble) || (!group->obj)) return;
2669
2670    evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2671    edje_object_size_min_calc(group->bubble, NULL, &hh);
2672
2673    s = edje_object_data_get(group->bubble, "size_w");
2674    if (s) ww = atoi(s);
2675    else ww = 0;
2676    xx = x + w / 2 - ww / 2;
2677    yy = y-hh;
2678
2679    evas_object_move(group->bubble, xx, yy);
2680    evas_object_resize(group->bubble, ww, hh);
2681    obj_rotate_zoom(group->wd, group->bubble);
2682    evas_object_show(group->bubble);
2683
2684    evas_object_move(group->rect, xx, yy);
2685    evas_object_resize(group->rect, ww, hh);
2686    obj_rotate_zoom(group->wd, group->rect);
2687    evas_object_show(group->rect);
2688 }
2689
2690 static void
2691 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2692 {
2693    Marker_Group *group = data;
2694    Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2695    if (!marker) return;
2696    group->bringin = EINA_TRUE;
2697    elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2698 }
2699
2700 static void
2701 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2702 {
2703    Marker_Group *group = data;
2704
2705    if (group->bringin)
2706      {
2707         group->bringin = EINA_FALSE;
2708         return;
2709      }
2710
2711    if (group->bubble)
2712      {
2713         group->open = EINA_FALSE;
2714         _group_bubble_free(group);
2715         return;
2716      }
2717    group->open = EINA_TRUE;
2718    _group_bubble_create(group);
2719 }
2720
2721 static Eina_Bool
2722 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2723 {
2724    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2725    Widget_Data *wd = elm_widget_data_get(obj);
2726    int zoom;
2727    Evas_Coord x = 0;
2728    Evas_Coord y = 0;
2729    Evas_Coord step_x = 0;
2730    Evas_Coord step_y = 0;
2731    Evas_Coord v_w = 0;
2732    Evas_Coord v_h = 0;
2733    Evas_Coord page_x = 0;
2734    Evas_Coord page_y = 0;
2735
2736    if (!wd) return EINA_FALSE;
2737    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2738    Evas_Event_Key_Down *ev = event_info;
2739    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2740
2741    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2742    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2743    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2744    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2745
2746    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2747      {
2748         x -= step_x;
2749      }
2750    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2751      {
2752         x += step_x;
2753      }
2754    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
2755      {
2756         y -= step_y;
2757      }
2758    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2759      {
2760         y += step_y;
2761      }
2762    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2763      {
2764         if (page_y < 0)
2765           y -= -(page_y * v_h) / 100;
2766         else
2767           y -= page_y;
2768      }
2769    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2770      {
2771         if (page_y < 0)
2772           y += -(page_y * v_h) / 100;
2773         else
2774           y += page_y;
2775      }
2776    else if (!strcmp(ev->keyname, "KP_Add"))
2777      {
2778         zoom = elm_map_zoom_get(obj) + 1;
2779         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2780         elm_map_zoom_set(obj, zoom);
2781         return EINA_TRUE;
2782      }
2783    else if (!strcmp(ev->keyname, "KP_Subtract"))
2784      {
2785         zoom = elm_map_zoom_get(obj) - 1;
2786         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2787         elm_map_zoom_set(obj, zoom);
2788         return EINA_TRUE;
2789      }
2790    else return EINA_FALSE;
2791
2792    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2793    elm_smart_scroller_child_pos_set(wd->scr, x, y);
2794
2795    return EINA_TRUE;
2796 }
2797
2798 static Eina_Bool
2799 cb_dump_name_attrs(void *data, const char *key, const char *value)
2800 {
2801    Name_Dump *dump = (Name_Dump*)data;
2802    if (!dump) return EINA_FALSE;
2803
2804    if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2805    else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2806
2807    return EINA_TRUE;
2808 }
2809
2810
2811 static Eina_Bool
2812 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2813 {
2814    Route_Dump *dump = data;
2815    if (!dump) return EINA_FALSE;
2816
2817    switch (type)
2818      {
2819       case EINA_SIMPLE_XML_OPEN:
2820       case EINA_SIMPLE_XML_OPEN_EMPTY:
2821         {
2822            const char *attrs;
2823
2824            attrs = eina_simple_xml_tag_attributes_find(value, length);
2825            if (!attrs)
2826              {
2827                 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2828                 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2829                 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2830                 else dump->id = ROUTE_XML_NONE;
2831              }
2832          }
2833         break;
2834       case EINA_SIMPLE_XML_DATA:
2835         {
2836            char *buf = malloc(length);
2837            if (!buf) return EINA_FALSE;
2838            snprintf(buf, length, "%s", value);
2839            if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2840            else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2841            else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2842            free(buf);
2843         }
2844         break;
2845       default:
2846         break;
2847      }
2848
2849    return EINA_TRUE;
2850 }
2851
2852 static Eina_Bool
2853 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2854 {
2855    Name_Dump *dump = data;
2856    if (!dump) return EINA_FALSE;
2857
2858    switch (type)
2859      {
2860       case EINA_SIMPLE_XML_OPEN:
2861       case EINA_SIMPLE_XML_OPEN_EMPTY:
2862         {
2863            const char *attrs;
2864            attrs = eina_simple_xml_tag_attributes_find(value, length);
2865            if (attrs)
2866              {
2867                 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2868                 else dump->id = NAME_XML_NONE;
2869
2870                 eina_simple_xml_attributes_parse
2871                   (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2872              }
2873         }
2874         break;
2875       case EINA_SIMPLE_XML_DATA:
2876         {
2877            char *buf = malloc(length + 1);
2878            if (!buf) return EINA_FALSE;
2879            snprintf(buf, length + 1, "%s", value);
2880            if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2881            free(buf);
2882         }
2883         break;
2884       default:
2885         break;
2886      }
2887
2888    return EINA_TRUE;
2889 }
2890
2891 static void
2892 _parse_kml(void *data)
2893 {
2894    Elm_Map_Route *r = (Elm_Map_Route*)data;
2895    if (!r && !r->ud.fname) return;
2896
2897    FILE *f;
2898    char **str;
2899    unsigned int ele, idx;
2900    double lon, lat;
2901    Evas_Object *path;
2902
2903    Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2904
2905    f = fopen(r->ud.fname, "rb");
2906    if (f)
2907      {
2908         long sz;
2909
2910         fseek(f, 0, SEEK_END);
2911         sz = ftell(f);
2912         if (sz > 0)
2913           {
2914              char *buf;
2915
2916              fseek(f, 0, SEEK_SET);
2917              buf = malloc(sz);
2918              if (buf)
2919                {
2920                   if (fread(buf, 1, sz, f))
2921                     {
2922                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
2923                        free(buf);
2924                     }
2925                }
2926           }
2927         fclose(f);
2928
2929         if (dump.distance) r->info.distance = dump.distance;
2930         if (dump.description)
2931           {
2932              eina_stringshare_replace(&r->info.waypoints, dump.description);
2933              str = eina_str_split_full(dump.description, "\n", 0, &ele);
2934              r->info.waypoint_count = ele;
2935              for (idx = 0 ; idx < ele ; idx++)
2936                {
2937                   Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
2938                   if (wp)
2939                     {
2940                        wp->wd = r->wd;
2941                        wp->point = eina_stringshare_add(str[idx]);
2942                        DBG("%s", str[idx]);
2943                        r->waypoint = eina_list_append(r->waypoint, wp);
2944                     }
2945                }
2946              if (str && str[0])
2947                {
2948                   free(str[0]);
2949                   free(str);
2950                }
2951           }
2952         else WRN("description is not found !");
2953
2954         if (dump.coordinates)
2955           {
2956              eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2957              str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2958              r->info.node_count = ele;
2959              for (idx = 0 ; idx < ele ; idx++)
2960                {
2961                   sscanf(str[idx], "%lf,%lf", &lon, &lat);
2962                   Path_Node *n = ELM_NEW(Path_Node);
2963                   if (n)
2964                     {
2965                        n->wd = r->wd;
2966                        n->pos.lon = lon;
2967                        n->pos.lat = lat;
2968                        n->idx = idx;
2969                        DBG("%lf:%lf", lon, lat);
2970                        n->pos.address = NULL;
2971                        r->nodes = eina_list_append(r->nodes, n);
2972
2973                        path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
2974                        evas_object_smart_member_add(path, r->wd->pan_smart);
2975                        r->path = eina_list_append(r->path, path);
2976                     }
2977                }
2978              if (str && str[0])
2979                {
2980                   free(str[0]);
2981                   free(str);
2982                }
2983           }
2984      }
2985 }
2986
2987 static void
2988 _parse_name(void *data)
2989 {
2990    Elm_Map_Name *n = (Elm_Map_Name*)data;
2991    if (!n && !n->ud.fname) return;
2992
2993    FILE *f;
2994
2995    Name_Dump dump = {0, NULL, 0.0, 0.0};
2996
2997    f = fopen(n->ud.fname, "rb");
2998    if (f)
2999      {
3000         long sz;
3001
3002         fseek(f, 0, SEEK_END);
3003         sz = ftell(f);
3004         if (sz > 0)
3005           {
3006              char *buf;
3007
3008              fseek(f, 0, SEEK_SET);
3009              buf = malloc(sz);
3010              if (buf)
3011                {
3012                   if (fread(buf, 1, sz, f))
3013                     {
3014                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3015                        free(buf);
3016                     }
3017                }
3018           }
3019         fclose(f);
3020
3021         if (dump.address)
3022           {
3023              INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3024              n->address = strdup(dump.address);
3025           }
3026         n->lon = dump.lon;
3027         n->lat = dump.lat;
3028      }
3029 }
3030
3031 static Eina_Bool
3032 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3033 {
3034    Ecore_Con_Event_Url_Complete *ev = event;
3035    Elm_Map_Route *r = (Elm_Map_Route*)data;
3036    Widget_Data *wd = r->wd;
3037
3038    if ((!r) || (!ev)) return EINA_TRUE;
3039    Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3040    ecore_con_url_data_set(r->con_url, NULL);
3041    if (r!=rr) return EINA_TRUE;
3042
3043    if (r->ud.fd) fclose(r->ud.fd);
3044    _parse_kml(r);
3045
3046    if (wd->grids)
3047      {
3048         Evas_Coord ox, oy, ow, oh;
3049         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3050         route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3051      }
3052    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3053                            "elm,state,busy,stop", "elm");
3054    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3055    return EINA_TRUE;
3056 }
3057
3058 static Eina_Bool
3059 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3060 {
3061    Ecore_Con_Event_Url_Complete *ev = event;
3062    Elm_Map_Name *n = (Elm_Map_Name*)data;
3063    Widget_Data *wd = n->wd;
3064
3065    if ((!n) || (!ev)) return EINA_TRUE;
3066    Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3067    ecore_con_url_data_set(n->con_url, NULL);
3068    if (n!=nn) return EINA_TRUE;
3069
3070    if (n->ud.fd) fclose(n->ud.fd);
3071    _parse_name(n);
3072
3073    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3074                            "elm,state,busy,stop", "elm");
3075    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3076    return EINA_TRUE;
3077 }
3078
3079 static Elm_Map_Name *
3080 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3081 {
3082    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3083    Widget_Data *wd = elm_widget_data_get(obj);
3084    char buf[PATH_MAX];
3085    char *source;
3086    int fd;
3087
3088    if ((!wd) || (!wd->src)) return NULL;
3089    Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3090    if (!name) return NULL;
3091
3092    snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3093    fd = mkstemp(buf);
3094    if (fd < 0)
3095      {
3096         free(name);
3097         return NULL;
3098      }
3099
3100    name->con_url = ecore_con_url_new(NULL);
3101    name->ud.fname = strdup(buf);
3102    INF("xml file : %s", name->ud.fname);
3103
3104    name->ud.fd = fdopen(fd, "w+");
3105    if ((!name->con_url) || (!name->ud.fd))
3106      {
3107         ecore_con_url_free(name->con_url);
3108         free(name);
3109         return NULL;
3110      }
3111
3112    name->wd = wd;
3113    name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3114    name->method = method;
3115    if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3116    else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3117    name->lon = lon;
3118    name->lat = lat;
3119
3120    source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3121    INF("name url = %s", source);
3122
3123    wd->names = eina_list_append(wd->names, name);
3124    ecore_con_url_url_set(name->con_url, source);
3125    ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3126    ecore_con_url_data_set(name->con_url, name);
3127
3128    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3129                            "elm,state,busy,start", "elm");
3130    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3131    ecore_con_url_get(name->con_url);
3132    if (source) free(source);
3133
3134    return name;
3135
3136 }
3137
3138 static int idnum = 1;
3139
3140 /**
3141  * Add a new Map object
3142  *
3143  * @param parent The parent object
3144  * @return The new object or NULL if it cannot be created
3145  *
3146  * @ingroup Map
3147  */
3148 EAPI Evas_Object *
3149 elm_map_add(Evas_Object *parent)
3150 {
3151    Evas *e;
3152    Widget_Data *wd;
3153    Evas_Coord minw, minh;
3154    Evas_Object *obj;
3155    static Evas_Smart *smart = NULL;
3156    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3157
3158    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3159
3160    ELM_SET_WIDTYPE(widtype, "map");
3161    elm_widget_type_set(obj, "map");
3162    elm_widget_sub_object_add(parent, obj);
3163    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3164    elm_widget_data_set(obj, wd);
3165    elm_widget_del_hook_set(obj, _del_hook);
3166    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3167    elm_widget_theme_hook_set(obj, _theme_hook);
3168    elm_widget_can_focus_set(obj, EINA_TRUE);
3169    elm_widget_event_hook_set(obj, _event_hook);
3170
3171    wd->scr = elm_smart_scroller_add(e);
3172    elm_smart_scroller_widget_set(wd->scr, obj);
3173    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3174    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3175    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3176    elm_widget_resize_object_set(obj, wd->scr);
3177    elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3178
3179    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3180    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3181    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3182    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3183    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3184
3185    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3186    source_init(obj);
3187
3188    wd->obj = obj;
3189    wd->map = evas_map_new(4);
3190    if (!wd->map) return NULL;
3191
3192    wd->zoom_min = 0xFF;
3193    wd->zoom_max = 0X00;
3194    wd->markers_max_num = 30;
3195    wd->pinch.level = 1.0;
3196    zoom_min_get(obj);
3197    zoom_max_get(obj);
3198    wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3199
3200    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3201    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3202    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3203    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3204
3205    if (!smart)
3206      {
3207         static Evas_Smart_Class sc;
3208
3209         evas_object_smart_clipped_smart_set(&_pan_sc);
3210         sc = _pan_sc;
3211         sc.name = "elm_map_pan";
3212         sc.version = EVAS_SMART_CLASS_VERSION;
3213         sc.add = _pan_add;
3214         sc.del = _pan_del;
3215         sc.resize = _pan_resize;
3216         sc.move = _pan_move;
3217         sc.calculate = _pan_calculate;
3218         smart = evas_smart_class_new(&sc);
3219      }
3220    if (smart)
3221      {
3222         wd->pan_smart = evas_object_smart_add(e, smart);
3223         wd->pan = evas_object_smart_data_get(wd->pan_smart);
3224         wd->pan->wd = wd;
3225      }
3226
3227    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3228                                      _pan_set, _pan_get, _pan_max_get,
3229                                      _pan_min_get, _pan_child_size_get);
3230
3231    wd->rect = evas_object_rectangle_add(e);
3232    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3233                                   _rect_resize_cb, obj);
3234    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3235                                   _mouse_down, obj);
3236    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3237                                   _mouse_move, obj);
3238    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3239                                   _mouse_up, obj);
3240    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3241                                   _mouse_multi_down, obj);
3242    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3243                                   _mouse_multi_move, obj);
3244    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3245                                   _mouse_multi_up, obj);
3246    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3247                                   _mouse_wheel_cb, obj);
3248
3249    evas_object_smart_member_add(wd->rect, wd->pan_smart);
3250    elm_widget_sub_object_add(obj, wd->rect);
3251    evas_object_show(wd->rect);
3252    evas_object_color_set(wd->rect, 0, 0, 0, 0);
3253
3254    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3255    wd->id = ((int)getpid() << 16) | idnum;
3256    idnum++;
3257
3258    wd->tsize = 256;
3259    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3260                              &minw, &minh);
3261    evas_object_size_hint_min_set(obj, minw, minh);
3262
3263    wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3264    evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3265
3266    wd->paused = EINA_TRUE;
3267    elm_map_zoom_set(obj, 0);
3268    wd->paused = EINA_FALSE;
3269    _sizing_eval(obj);
3270
3271    // TODO: convert Elementary to subclassing of Evas_Smart_Class
3272    // TODO: and save some bytes, making descriptions per-class and not instance!
3273    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3274
3275    if (!ecore_file_download_protocol_available("http://"))
3276      {
3277         ERR("Ecore must be built with curl support for the map widget!");
3278      }
3279
3280    return obj;
3281 }
3282
3283 /**
3284  * Set the zoom level of the map
3285  *
3286  * This sets the zoom level. 0 is the world map and 18 is the maximum zoom.
3287  *
3288  * @param obj The map object
3289  * @param zoom The zoom level to set
3290  *
3291  * @ingroup Map
3292  */
3293 EAPI void
3294 elm_map_zoom_set(Evas_Object *obj, int zoom)
3295 {
3296    ELM_CHECK_WIDTYPE(obj, widtype);
3297    Widget_Data *wd = elm_widget_data_get(obj);
3298    Eina_List *l;
3299    Grid *g, *g_zoom = NULL;
3300    Evas_Coord rx, ry, rw, rh;
3301    Evas_Object *p;
3302    Elm_Map_Route *r;
3303    Evas_Object *route;
3304    int z = 0, zoom_changed = 0, started = 0;
3305
3306    if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3307    if (zoom < 0 ) zoom = 0;
3308    if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3309    if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3310
3311    if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3312    else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3313    else wd->zoom_method = ZOOM_METHOD_NONE;
3314    if (wd->zoom != zoom ) zoom_changed = 1;
3315    wd->zoom = zoom;
3316    wd->size.ow = wd->size.w;
3317    wd->size.oh = wd->size.h;
3318    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3319    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3320
3321    EINA_LIST_FOREACH(wd->route, l, r)
3322      {
3323         if (r)
3324           {
3325              EINA_LIST_FOREACH(r->path, l, p)
3326                {
3327                   evas_object_polygon_points_clear(p);
3328                }
3329           }
3330      }
3331
3332    EINA_LIST_FOREACH(wd->track, l, route)
3333      {
3334        evas_object_hide(route);
3335      }
3336
3337    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3338      {
3339         int p2w, p2h;
3340         int cumulw, cumulh;
3341
3342         cumulw = wd->tsize;
3343         p2w = 0;
3344         while (cumulw <= rw)
3345           {
3346              p2w++;
3347              cumulw *= 2;
3348           }
3349         p2w--;
3350
3351         cumulh = wd->tsize;
3352         p2h = 0;
3353         while (cumulh <= rh)
3354           {
3355              p2h++;
3356              cumulh *= 2;
3357           }
3358         p2h--;
3359
3360         if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3361           {
3362              if (p2w < p2h) z = p2w;
3363              else z = p2h;
3364           }
3365         else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3366           {
3367              if (p2w > p2h) z = p2w;
3368              else z = p2h;
3369           }
3370         wd->zoom = z;
3371      }
3372    wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3373    wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3374
3375    g = grid_create(obj);
3376    if (g)
3377      {
3378         if (eina_list_count(wd->grids) > 1)
3379           {
3380              g_zoom = eina_list_last(wd->grids)->data;
3381              wd->grids = eina_list_remove(wd->grids, g_zoom);
3382              grid_clear(obj, g_zoom);
3383              free(g_zoom);
3384           }
3385         wd->grids = eina_list_prepend(wd->grids, g);
3386      }
3387    else
3388      {
3389         EINA_LIST_FREE(wd->grids, g)
3390           {
3391              grid_clear(obj, g);
3392              free(g);
3393           }
3394      }
3395
3396    wd->t = 1.0;
3397    if ((wd->size.w > 0) && (wd->size.h > 0))
3398      {
3399         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3400         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3401      }
3402    else
3403      {
3404         wd->size.spos.x = 0.5;
3405         wd->size.spos.y = 0.5;
3406      }
3407
3408    if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3409    if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3410    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3411    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3412
3413    if (wd->paused)
3414      {
3415         zoom_do(obj);
3416         if (wd->calc_job) ecore_job_del(wd->calc_job);
3417         wd->calc_job = ecore_job_add(_calc_job, wd);
3418      }
3419    else
3420      {
3421         if (!wd->zoom_animator)
3422           {
3423              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3424              wd->nosmooth++;
3425              if (wd->nosmooth == 1) _smooth_update(obj);
3426              started = 1;
3427           }
3428      }
3429
3430    if (!wd->paused)
3431      {
3432         if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3433         if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3434      }
3435
3436    if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3437 }
3438
3439 /**
3440  * Get the zoom level of the map
3441  *
3442  * This returns the current zoom level of the map object. Note that if
3443  * you set the fill mode to other than ELM_MAP_ZOOM_MODE_MANUAL
3444  * (which is the default), the zoom level may be changed at any time by the
3445  * map object itself to account for map size and map viewpoer size
3446  *
3447  * @param obj The map object
3448  * @return The current zoom level
3449  *
3450  * @ingroup Map
3451  */
3452 EAPI int
3453 elm_map_zoom_get(const Evas_Object *obj)
3454 {
3455    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3456    Widget_Data *wd = elm_widget_data_get(obj);
3457
3458    if (!wd) return 0;
3459    return wd->zoom;
3460 }
3461
3462 /**
3463  * Set the zoom mode
3464  *
3465  * This sets the zoom mode to manual or one of several automatic levels.
3466  * Manual (ELM_MAP_ZOOM_MODE_MANUAL) means that zoom is set manually by
3467  * elm_map_zoom_set() and will stay at that level until changed by code
3468  * or until zoom mode is changed. This is the default mode.
3469  * The Automatic modes will allow the map object to automatically
3470  * adjust zoom mode based on properties. ELM_MAP_ZOOM_MODE_AUTO_FIT will
3471  * adjust zoom so the map fits inside the scroll frame with no pixels
3472  * outside this area. ELM_MAP_ZOOM_MODE_AUTO_FILL will be similar but
3473  * ensure no pixels within the frame are left unfilled. Do not forget that the valid sizes are 2^zoom, consequently the map may be smaller than the scroller view.
3474  *
3475  * @param obj The map object
3476  * @param mode The desired mode
3477  *
3478  * @ingroup Map
3479  */
3480 EAPI void
3481 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3482 {
3483    ELM_CHECK_WIDTYPE(obj, widtype);
3484    Widget_Data *wd = elm_widget_data_get(obj);
3485
3486    if (!wd) return;
3487    if (wd->mode == mode) return;
3488    wd->mode = mode;
3489
3490    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3491      {
3492         int tz = wd->zoom;
3493         wd->zoom = 0;
3494         elm_map_zoom_set(wd->obj, tz);
3495      }
3496 }
3497
3498 /**
3499  * Get the zoom mode
3500  *
3501  * This gets the current zoom mode of the map object
3502  *
3503  * @param obj The map object
3504  * @return The current zoom mode
3505  *
3506  * @ingroup Map
3507  */
3508 EAPI Elm_Map_Zoom_Mode
3509 elm_map_zoom_mode_get(const Evas_Object *obj)
3510 {
3511    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3512    Widget_Data *wd = elm_widget_data_get(obj);
3513
3514    if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3515    return wd->mode;
3516 }
3517
3518 /**
3519  * Centers the map at @p lon @p lat using an animation to scroll.
3520  *
3521  * @param obj The map object
3522  * @param lon Longitude to center at
3523  * @param lon Latitude to center at
3524  *
3525  * @ingroup Map
3526  */
3527 EAPI void
3528 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3529 {
3530    ELM_CHECK_WIDTYPE(obj, widtype);
3531    Widget_Data *wd = elm_widget_data_get(obj);
3532    int rx, ry, rw, rh;
3533
3534    if (!wd) return;
3535    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3536    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3537
3538    rx = rx - rw / 2;
3539    ry = ry - rh / 2;
3540
3541    if (wd->zoom_animator)
3542      {
3543         wd->nosmooth--;
3544         if (!wd->nosmooth) _smooth_update(obj);
3545         ecore_animator_del(wd->zoom_animator);
3546         wd->zoom_animator = NULL;
3547         zoom_do(obj);
3548         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3549      }
3550    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3551
3552    wd->center_on.enabled = EINA_TRUE;
3553    wd->center_on.lon = lon;
3554    wd->center_on.lat = lat;
3555 }
3556
3557 /**
3558  * Move the map to the current coordinates.
3559  *
3560  * This move the map to the current coordinates. The map will be centered on these coordinates.
3561  *
3562  * @param obj The map object
3563  * @param lat The latitude.
3564  * @param lon The longitude.
3565  *
3566  * @ingroup Map
3567  */
3568 EAPI void
3569 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3570 {
3571    ELM_CHECK_WIDTYPE(obj, widtype);
3572    Widget_Data *wd = elm_widget_data_get(obj);
3573    int rx, ry, rw, rh;
3574
3575    if (!wd) return;
3576    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3577    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3578
3579    rx = rx - rw / 2;
3580    ry = ry - rh / 2;
3581
3582    if (wd->zoom_animator)
3583      {
3584         wd->nosmooth--;
3585         ecore_animator_del(wd->zoom_animator);
3586         wd->zoom_animator = NULL;
3587         zoom_do(obj);
3588         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3589      }
3590    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3591
3592    wd->center_on.enabled = EINA_TRUE;
3593    wd->center_on.lon = lon;
3594    wd->center_on.lat = lat;
3595 }
3596
3597 /**
3598  * Get the current coordinates of the map.
3599  *
3600  * This gets the current coordinates of the map object.
3601  *
3602  * @param obj The map object
3603  * @param lat The latitude.
3604  * @param lon The longitude.
3605  *
3606  * @ingroup Map
3607  */
3608 EAPI void
3609 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3610 {
3611    ELM_CHECK_WIDTYPE(obj, widtype);
3612    Widget_Data *wd = elm_widget_data_get(obj);
3613    Evas_Coord sx, sy, sw, sh;
3614
3615    if (!wd) return;
3616    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3617    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3618    sx += sw / 2;
3619    sy += sh / 2;
3620
3621    elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3622 }
3623
3624 /**
3625  * Set the paused state for map
3626  *
3627  * This sets the paused state to on (1) or off (0) for map. The default
3628  * is off. This will stop zooming using animation change zoom levels and
3629  * change instantly. This will stop any existing animations that are running.
3630  *
3631  * @param obj The map object
3632  * @param paused The pause state to set
3633  *
3634  * @ingroup Map
3635  */
3636 EAPI void
3637 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3638 {
3639    ELM_CHECK_WIDTYPE(obj, widtype);
3640    Widget_Data *wd = elm_widget_data_get(obj);
3641
3642    if (!wd) return;
3643    if (wd->paused == !!paused) return;
3644    wd->paused = paused;
3645    if (wd->paused)
3646      {
3647         if (wd->zoom_animator)
3648           {
3649              if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3650              wd->zoom_animator = NULL;
3651              zoom_do(obj);
3652              evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3653           }
3654      }
3655 }
3656
3657 /**
3658  * Set the paused state for the markers
3659  *
3660  * This sets the paused state to on (1) or off (0) for the markers. The default
3661  * is off. This will stop displaying the markers during change zoom levels. Set
3662  * to on if you have a large number of markers.
3663  *
3664  * @param obj The map object
3665  * @param paused The pause state to set
3666  *
3667  * @ingroup Map
3668  */
3669 EAPI void
3670 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3671 {
3672    ELM_CHECK_WIDTYPE(obj, widtype);
3673    Widget_Data *wd = elm_widget_data_get(obj);
3674
3675    if (!wd) return;
3676    if (wd->paused_markers == !!paused) return;
3677    wd->paused_markers = paused;
3678 }
3679
3680 /**
3681  * Get the paused state for map
3682  *
3683  * This gets the current paused state for the map object.
3684  *
3685  * @param obj The map object
3686  * @return The current paused state
3687  *
3688  * @ingroup Map
3689  */
3690 EAPI Eina_Bool
3691 elm_map_paused_get(const Evas_Object *obj)
3692 {
3693    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3694    Widget_Data *wd = elm_widget_data_get(obj);
3695
3696    if (!wd) return EINA_FALSE;
3697    return wd->paused;
3698 }
3699
3700 /**
3701  * Get the paused state for the markers
3702  *
3703  * This gets the current paused state for the markers object.
3704  *
3705  * @param obj The map object
3706  * @return The current paused state
3707  *
3708  * @ingroup Map
3709  */
3710 EAPI Eina_Bool
3711 elm_map_paused_markers_get(const Evas_Object *obj)
3712 {
3713    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3714    Widget_Data *wd = elm_widget_data_get(obj);
3715
3716    if (!wd) return EINA_FALSE;
3717    return wd->paused_markers;
3718 }
3719
3720 /**
3721  * Get the information of downloading status
3722  *
3723  * This gets the current downloading status for the map object.
3724  *
3725  * @param obj The map object
3726  * @param try_num the number of download trying map
3727  * @param finish_num the number of downloaded map
3728  *
3729  * @ingroup Map
3730  */
3731
3732 EAPI void
3733 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3734 {
3735    ELM_CHECK_WIDTYPE(obj, widtype);
3736    Widget_Data *wd = elm_widget_data_get(obj);
3737
3738    if (!wd) return;
3739    if (try_num)
3740      {
3741         *try_num = wd->try_num;
3742      }
3743
3744    if (finish_num)
3745      {
3746         *finish_num = wd->finish_num;
3747      }
3748 }
3749 /**
3750  * Convert a pixel coordinate (x,y) into a geographic coordinate (longitude, latitude).
3751  *
3752  * @param obj The map object
3753  * @param x the coordinate
3754  * @param y the coordinate
3755  * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3756  * @param lon the longitude correspond to x
3757  * @param lat the latitude correspond to y
3758  *
3759  * @ingroup Map
3760  */
3761 EAPI void
3762 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3763 {
3764    ELM_CHECK_WIDTYPE(obj, widtype);
3765    Widget_Data *wd = elm_widget_data_get(obj);
3766
3767    if (!wd) return;
3768    int zoom = floor(log(size / 256) / log(2));
3769    if ((wd->src) && (wd->src->coord_into_geo))
3770      {
3771         if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3772      }
3773
3774    if (lon)
3775      {
3776         *lon = x / (double)size * 360.0 - 180;
3777      }
3778    if (lat)
3779      {
3780         double n = ELM_PI - 2.0 * ELM_PI * y / size;
3781         *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3782      }
3783 }
3784
3785 /**
3786  * Convert a geographic coordinate (longitude, latitude) into a pixel coordinate (x, y).
3787  *
3788  * @param obj The map object
3789  * @param lon the longitude
3790  * @param lat the latitude
3791  * @param size the size in pixels of the map. The map is a square and generally his size is : pow(2.0, zoom)*256.
3792  * @param x the coordinate correspond to the longitude
3793  * @param y the coordinate correspond to the latitude
3794  *
3795  * @ingroup Map
3796  */
3797 EAPI void
3798 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3799 {
3800    ELM_CHECK_WIDTYPE(obj, widtype);
3801    Widget_Data *wd = elm_widget_data_get(obj);
3802
3803    if (!wd) return;
3804    int zoom = floor(log(size / 256) / log(2));
3805    if ((wd->src) && (wd->src->geo_into_coord))
3806      {
3807         if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3808      }
3809
3810    if (x)
3811      *x = floor((lon + 180.0) / 360.0 * size);
3812    if (y)
3813      *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3814 }
3815
3816 /**
3817  * Convert a geographic coordinate (longitude, latitude) into a name (address).
3818  *
3819  * @param obj The map object
3820  * @param lon the longitude
3821  * @param lat the latitude
3822  *
3823  * @return name the address
3824  *
3825  * @ingroup Map
3826  */
3827 EAPI Elm_Map_Name *
3828 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3829 {
3830    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3831    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3832 }
3833
3834 /**
3835  * Convert a name (address) into a geographic coordinate (longitude, latitude).
3836  *
3837  * @param obj The map object
3838  * @param name the address
3839  * @param lat the latitude correspond to y
3840  *
3841  * @return name the address
3842  *
3843  * @ingroup Map
3844  */
3845 EAPI Elm_Map_Name *
3846 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3847 {
3848    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3849    if (!address) return NULL;
3850    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3851 }
3852
3853 /**
3854  * Convert a pixel coordinate into a roated pixcel coordinate.
3855  *
3856  * @param obj The map object
3857  * @param x x to rotate.
3858  * @param y y to rotate.
3859  * @param cx rotation's center horizontal position.
3860  * @param cy rotation's center vertical position.
3861  * @param degree amount of degrees from 0.0 to 360.0 to rotate arount Z axis.
3862  * @param xx rotated x.
3863  * @param yy rotated y.
3864  *
3865  * @ingroup Map
3866  */
3867 EAPI void
3868 elm_map_utils_rotate_coord(const Evas_Object *obj __UNUSED__, const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
3869 {
3870    if ((!xx) || (!yy)) return;
3871
3872    double r = (degree * M_PI) / 180.0;
3873    double tx, ty, ttx, tty;
3874
3875    tx = x - cx;
3876    ty = y - cy;
3877
3878    ttx = tx * cos(r);
3879    tty = tx * sin(r);
3880    tx = ttx + (ty * cos(r + M_PI_2));
3881    ty = tty + (ty * sin(r + M_PI_2));
3882
3883    *xx = tx + cx;
3884    *yy = ty + cy;
3885 }
3886
3887 /**
3888  * Add a marker on the map
3889  *
3890  * @param obj The map object
3891  * @param lon the longitude
3892  * @param lat the latitude
3893  * @param clas the class to use
3894  * @param clas_group the class group
3895  * @param data the data passed to the callbacks
3896  *
3897  * @return The marker object
3898  *
3899  * @ingroup Map
3900  */
3901 EAPI Elm_Map_Marker *
3902 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3903 {
3904    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3905    Widget_Data *wd = elm_widget_data_get(obj);
3906    int i, j;
3907    Eina_List *l;
3908    Marker_Group *group;
3909    int mpi, mpj;
3910    int tabi[9];
3911    int tabj[9];
3912    const char *s;
3913    const char *style;
3914    Evas_Object *o;
3915
3916    if (!wd) return NULL;
3917    EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3918    EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3919
3920    Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3921
3922    marker->wd = wd;
3923    marker->clas = clas;
3924    marker->clas_group = clas_group;
3925    marker->longitude = lon;
3926    marker->latitude = lat;
3927    marker->data = data;
3928    marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3929    marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3930    marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
3931
3932    tabi[1] = tabi[4] = tabi[6] = -1;
3933    tabi[2] = tabi[0] = tabi[7] = 0;
3934    tabi[3] = tabi[5] = tabi[8] = 1;
3935
3936    tabj[1] = tabj[2] = tabj[3] = -1;
3937    tabj[4] = tabj[0] = tabj[5] = 0;
3938    tabj[6] = tabj[7] = tabj[8] = 1;
3939
3940    if (!clas_group->priv.set)
3941      {
3942         style = "radio";
3943         if (marker->clas_group && marker->clas_group->style)
3944           style = marker->clas_group->style;
3945
3946         o = edje_object_add(evas_object_evas_get(obj));
3947         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3948         s = edje_object_data_get(o, "size_w");
3949         if (s) clas_group->priv.edje_w = atoi(s);
3950         else clas_group->priv.edje_w = 0;
3951         s = edje_object_data_get(o, "size_h");
3952         if (s) clas_group->priv.edje_h = atoi(s);
3953         else clas_group->priv.edje_h = 0;
3954         s = edje_object_data_get(o, "size_max_w");
3955         if (s) clas_group->priv.edje_max_w = atoi(s);
3956         else clas_group->priv.edje_max_w = 0;
3957         s = edje_object_data_get(o, "size_max_h");
3958         if (s) clas_group->priv.edje_max_h = atoi(s);
3959         else clas_group->priv.edje_max_h = 0;
3960         evas_object_del(o);
3961
3962         clas_group->priv.set = EINA_TRUE;
3963      }
3964
3965    if (!clas->priv.set)
3966      {
3967         style = "radio";
3968         if (marker->clas && marker->clas->style)
3969           style = marker->clas->style;
3970
3971         o = edje_object_add(evas_object_evas_get(obj));
3972         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3973         s = edje_object_data_get(o, "size_w");
3974         if (s) clas->priv.edje_w = atoi(s);
3975         else clas->priv.edje_w = 0;
3976         s = edje_object_data_get(o, "size_h");
3977         if (s) clas->priv.edje_h = atoi(s);
3978         else clas->priv.edje_h = 0;
3979         evas_object_del(o);
3980
3981         clas->priv.set = EINA_TRUE;
3982      }
3983
3984    for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3985      {
3986         elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3987                                              &(marker->x[i]), &(marker->y[i]));
3988
3989         //search in the matrixsparse the region where the marker will be
3990         mpi = marker->x[i] / wd->tsize;
3991         mpj = marker->y[i] / wd->tsize;
3992
3993         if (!wd->markers[i])
3994           {
3995              int size =  pow(2.0, i);
3996              wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
3997           }
3998
3999         group = NULL;
4000         if (i <= clas_group->zoom_grouped)
4001           {
4002              for (j = 0, group = NULL; j < 9 && !group; j++)
4003                {
4004                   EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
4005                                     l, group)
4006                     {
4007                        if (group->clas == marker->clas_group
4008                            && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
4009                                                   marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
4010                                                   group->x-group->w/4, group->y-group->h/4, group->w, group->h))
4011                          {
4012                             group->markers = eina_list_append(group->markers, marker);
4013                             group->update_nbelems = EINA_TRUE;
4014                             group->update_resize = EINA_TRUE;
4015
4016                             group->sum_x += marker->x[i];
4017                             group->sum_y += marker->y[i];
4018                             group->x = group->sum_x / eina_list_count(group->markers);
4019                             group->y = group->sum_y / eina_list_count(group->markers);
4020
4021                             group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
4022                                * eina_list_count(group->markers);
4023                             group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
4024                                * eina_list_count(group->markers);
4025                             if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
4026                             if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
4027
4028                             if (group->obj && eina_list_count(group->markers) == 2)
4029                               {
4030                                  _group_object_free(group);
4031                                  _group_object_create(group);
4032                               }
4033                             if (group->bubble)
4034                               _group_bubble_content_update(group);
4035
4036                             break;
4037                          }
4038                     }
4039                }
4040           }
4041         if (!group)
4042           {
4043              group = calloc(1, sizeof(Marker_Group));
4044              group->wd = wd;
4045              group->sum_x = marker->x[i];
4046              group->sum_y = marker->y[i];
4047              group->x = marker->x[i];
4048              group->y = marker->y[i];
4049              group->w = clas_group->priv.edje_w;
4050              group->h = clas_group->priv.edje_h;
4051              group->clas = clas_group;
4052
4053              group->markers = eina_list_append(group->markers, marker);
4054              group->update_nbelems = EINA_TRUE;
4055              group->update_resize = EINA_TRUE;
4056
4057              eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4058
4059              if (!group->cell)
4060                {
4061                   l = eina_list_append(NULL, group);
4062                   eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
4063                   eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
4064                }
4065              else
4066                {
4067                   l = eina_matrixsparse_cell_data_get(group->cell);
4068                   l = eina_list_append(l, group);
4069                   eina_matrixsparse_cell_data_set(group->cell, l);
4070                }
4071           }
4072         marker->groups[i] = group;
4073      }
4074
4075    if (wd->grids)
4076      {
4077         Evas_Coord ox, oy, ow, oh;
4078         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4079         marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4080      }
4081
4082    return marker;
4083 }
4084
4085 /**
4086  * Remove a marker from the map
4087  *
4088  * @param marker The marker to remove
4089  *
4090  * @ingroup Map
4091  */
4092 EAPI void
4093 elm_map_marker_remove(Elm_Map_Marker *marker)
4094 {
4095    int i;
4096    Eina_List *groups;
4097    Widget_Data *wd;
4098
4099    EINA_SAFETY_ON_NULL_RETURN(marker);
4100    wd = marker->wd;
4101    if (!wd) return;
4102    for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4103      {
4104         marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
4105         if (!eina_list_count(marker->groups[i]->markers))
4106           {
4107              groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
4108              groups = eina_list_remove(groups, marker->groups[i]);
4109              eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
4110
4111              _group_object_free(marker->groups[i]);
4112              _group_bubble_free(marker->groups[i]);
4113              free(marker->groups[i]);
4114           }
4115         else
4116           {
4117              marker->groups[i]->sum_x -= marker->x[i];
4118              marker->groups[i]->sum_y -= marker->y[i];
4119
4120              marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
4121              marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
4122
4123              marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
4124                 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
4125              marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
4126                 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
4127              if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
4128                marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
4129              if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
4130                marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
4131
4132              if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
4133                {
4134                   _group_object_free(marker->groups[i]);
4135                   _group_object_create(marker->groups[i]);
4136                }
4137           }
4138      }
4139
4140    if ((marker->content) && (marker->clas->func.del))
4141      marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4142    else if (marker->content)
4143      evas_object_del(marker->content);
4144
4145    if (marker->x) free(marker->x);
4146    if (marker->y) free(marker->y);
4147    if (marker->groups) free(marker->groups);
4148
4149    free(marker);
4150
4151    if (wd->grids)
4152      {
4153         Evas_Coord ox, oy, ow, oh;
4154         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4155         marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4156      }
4157 }
4158
4159 /**
4160  * Get the current coordinates of the marker.
4161  *
4162  * @param marker marker.
4163  * @param lat The latitude.
4164  * @param lon The longitude.
4165  *
4166  * @ingroup Map
4167  */
4168 EAPI void
4169 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
4170 {
4171    EINA_SAFETY_ON_NULL_RETURN(marker);
4172    if (lon) *lon = marker->longitude;
4173    if (lat) *lat = marker->latitude;
4174 }
4175
4176 /**
4177  * Move the map to the coordinate of the marker.
4178  *
4179  * @param marker The marker where the map will be center.
4180  *
4181  * @ingroup Map
4182  */
4183 EAPI void
4184 elm_map_marker_bring_in(Elm_Map_Marker *marker)
4185 {
4186    EINA_SAFETY_ON_NULL_RETURN(marker);
4187    elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
4188 }
4189
4190 /**
4191  * Move the map to the coordinate of the marker.
4192  *
4193  * @param marker The marker where the map will be center.
4194  *
4195  * @ingroup Map
4196  */
4197 EAPI void
4198 elm_map_marker_show(Elm_Map_Marker *marker)
4199 {
4200    EINA_SAFETY_ON_NULL_RETURN(marker);
4201    elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
4202 }
4203
4204 /**
4205  * Move and zoom the map to display a list of markers.
4206  *
4207  * The map will be centered on the center point of the markers in the list. Then
4208  * the map will be zoomed in order to fit the markers using the maximum zoom which
4209  * allows display of all the markers.
4210  *
4211  * @param markers The list of markers (list of Elm_Map_Marker *)
4212  *
4213  * @ingroup Map
4214  */
4215 EAPI void
4216 elm_map_markers_list_show(Eina_List *markers)
4217 {
4218    int zoom;
4219    double lon, lat;
4220    Eina_List *l;
4221    Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
4222    Evas_Coord rw, rh, xc, yc;
4223    Widget_Data *wd;
4224
4225    EINA_SAFETY_ON_NULL_RETURN(markers);
4226    EINA_LIST_FOREACH(markers, l, marker)
4227      {
4228         wd = marker->wd;
4229
4230         if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
4231           m_min_lon = marker;
4232
4233         if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
4234           m_max_lon = marker;
4235
4236         if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
4237           m_min_lat = marker;
4238
4239         if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
4240           m_max_lat = marker;
4241      }
4242
4243    lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
4244    lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
4245
4246    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
4247    for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
4248      {
4249         Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4250         elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4251
4252         if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4253             && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4254             && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4255             && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4256           break;
4257      }
4258
4259    elm_map_geo_region_show(wd->obj, lon, lat);
4260    elm_map_zoom_set(wd->obj, zoom);
4261 }
4262
4263 /**
4264  * Set the maximum numbers of markers display in a group.
4265  *
4266  * A group can have a long list of markers, consequently the creation of the content
4267  * of the bubble can be very slow. In order to avoid this, a maximum number of items
4268  * is displayed in a bubble. By default this number is 30.
4269  *
4270  * @param obj The map object.
4271  * @param max The maximum numbers of items displayed in a bubble.
4272  *
4273  * @ingroup Map
4274  */
4275 EAPI void
4276 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4277 {
4278    ELM_CHECK_WIDTYPE(obj, widtype);
4279    Widget_Data *wd = elm_widget_data_get(obj);
4280
4281    if (!wd) return;
4282    wd->markers_max_num = max;
4283 }
4284
4285 /**
4286  * Return the evas object getting from the ElmMapMarkerGetFunc callback
4287  *
4288  * @param marker The marker.
4289  * @return Return the evas object if it exists, else NULL.
4290  *
4291  * @ingroup Map
4292  */
4293 EAPI Evas_Object *
4294 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4295 {
4296    EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4297    return marker->content;
4298 }
4299
4300 /**
4301  * Update the marker
4302  *
4303  * @param marker The marker.
4304  *
4305  * @ingroup Map
4306  */
4307 EAPI void
4308 elm_map_marker_update(Elm_Map_Marker *marker)
4309 {
4310    EINA_SAFETY_ON_NULL_RETURN(marker);
4311    if (marker->content)
4312      {
4313         if (marker->clas->func.del)
4314           marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4315         else
4316           evas_object_del(marker->content);
4317         marker->content = NULL;
4318         _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4319      }
4320 }
4321
4322 /**
4323  * Close all opened bubbles
4324  *
4325  * @param obj The map object
4326  *
4327  * @ingroup Map
4328  */
4329 EAPI void
4330 elm_map_bubbles_close(Evas_Object *obj)
4331 {
4332    ELM_CHECK_WIDTYPE(obj, widtype);
4333    Widget_Data *wd = elm_widget_data_get(obj);
4334    Marker_Group *group;
4335    Eina_List *l, *l_next;
4336
4337    if (!wd) return;
4338    EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4339       _group_bubble_free(group);
4340 }
4341
4342 /**
4343  * Create a group class.
4344  *
4345  * Each marker must be associated to a group class. Marker with the same group are grouped if they are close.
4346  * The group class defines the style of the marker when a marker is grouped to others markers.
4347  *
4348  * @param obj The map object
4349  * @return Returns the new group class
4350  *
4351  * @ingroup Map
4352  */
4353 EAPI Elm_Map_Group_Class *
4354 elm_map_group_class_new(Evas_Object *obj)
4355 {
4356    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4357    Widget_Data *wd = elm_widget_data_get(obj);
4358
4359    if (!wd) return NULL;
4360    Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4361    clas->zoom_grouped = wd->zoom_max;
4362    wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4363    return clas;
4364 }
4365
4366 /**
4367  * Set the style of a group class (radio, radio2 or empty)
4368  *
4369  * @param clas the group class
4370  * @param style the new style
4371  *
4372  * @ingroup Map
4373  */
4374 EAPI void
4375 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4376 {
4377    EINA_SAFETY_ON_NULL_RETURN(clas);
4378    eina_stringshare_replace(&clas->style, style);
4379 }
4380
4381 /**
4382  * Set the icon callback of a group class.
4383  *
4384  * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4385  *
4386  * @param clas the group class
4387  * @param icon_get the callback to create the icon
4388  *
4389  * @ingroup Map
4390  */
4391 EAPI void
4392 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4393 {
4394    EINA_SAFETY_ON_NULL_RETURN(clas);
4395    clas->func.icon_get = icon_get;
4396 }
4397
4398 /**
4399  * Set the data associated to the group class (radio, radio2 or empty)
4400  *
4401  * @param clas the group class
4402  * @param data the new user data
4403  *
4404  * @ingroup Map
4405  */
4406 EAPI void
4407 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4408 {
4409    EINA_SAFETY_ON_NULL_RETURN(clas);
4410    clas->data = data;
4411 }
4412
4413 /**
4414  * Set the zoom from where the markers are displayed.
4415  *
4416  * Markers will not be displayed for a zoom less than @ref zoom
4417  *
4418  * @param clas the group class
4419  * @param zoom the zoom
4420  *
4421  * @ingroup Map
4422  */
4423 EAPI void
4424 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4425 {
4426    EINA_SAFETY_ON_NULL_RETURN(clas);
4427    clas->zoom_displayed = zoom;
4428 }
4429
4430 /**
4431  * Set the zoom from where the markers are no more grouped.
4432  *
4433  * @param clas the group class
4434  * @param zoom the zoom
4435  *
4436  * @ingroup Map
4437  */
4438 EAPI void
4439 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4440 {
4441    EINA_SAFETY_ON_NULL_RETURN(clas);
4442    clas->zoom_grouped = zoom;
4443 }
4444
4445 /**
4446  * Set if the markers associated to the group class @clas are hidden or not.
4447  * If @ref hide is true the markers will be hidden.
4448  *
4449  * @param clas the group class
4450  * @param hide if true the markers will be hidden, else they will be displayed.
4451  *
4452  * @ingroup Map
4453  */
4454 EAPI void
4455 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4456 {
4457    ELM_CHECK_WIDTYPE(obj, widtype);
4458    Widget_Data *wd = elm_widget_data_get(obj);
4459
4460    if (!wd) return;
4461    EINA_SAFETY_ON_NULL_RETURN(clas);
4462    if (clas->hide == hide) return;
4463    clas->hide = hide;
4464    if (wd->grids)
4465      {
4466         Evas_Coord ox, oy, ow, oh;
4467         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4468         marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4469      }
4470 }
4471
4472
4473 /**
4474  * Create a marker class.
4475  *
4476  * Each marker must be associated to a class.
4477  * The class defines the style of the marker when a marker is displayed alone (not grouped).
4478  *
4479  * @param obj The map object
4480  * @return Returns the new class
4481  *
4482  * @ingroup Map
4483  */
4484 EAPI Elm_Map_Marker_Class *
4485 elm_map_marker_class_new(Evas_Object *obj)
4486 {
4487    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4488    Widget_Data *wd = elm_widget_data_get(obj);
4489
4490    if (!wd) return NULL;
4491    Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4492    wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4493    return clas;
4494 }
4495
4496 /**
4497  * Set the style of a class (radio, radio2 or empty)
4498  *
4499  * @param clas the group class
4500  * @param style the new style
4501  *
4502  * @ingroup Map
4503  */
4504 EAPI void
4505 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
4506 {
4507    EINA_SAFETY_ON_NULL_RETURN(clas);
4508    eina_stringshare_replace(&clas->style, style);
4509 }
4510
4511 /**
4512  * Set the icon callback of a class.
4513  *
4514  * A custom icon can be displayed in a marker. The function @ref icon_get must return this icon.
4515  *
4516  * @param clas the group class
4517  * @param icon_get the callback to create the icon
4518  *
4519  * @ingroup Map
4520  */
4521 EAPI void
4522 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4523 {
4524    EINA_SAFETY_ON_NULL_RETURN(clas);
4525    clas->func.icon_get = icon_get;
4526 }
4527
4528 /**
4529  *
4530  * Set the callback of the content of the bubble.
4531  *
4532  * When the user click on a marker, a bubble is displayed with a content.
4533  * The callback @ref get musst return this content. It can be NULL.
4534  *
4535  * @param clas the group class
4536  * @param get the callback to create the content
4537  *
4538  * @ingroup Map
4539  */
4540 EAPI void
4541 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4542 {
4543    EINA_SAFETY_ON_NULL_RETURN(clas);
4544    clas->func.get = get;
4545 }
4546
4547 /**
4548  * Set the callback of the content of delete the object created by the callback "get".
4549  *
4550  * If this callback is defined the user will have to delete (or not) the object inside.
4551  * If the callback is not defined the object will be destroyed with evas_object_del()
4552  *
4553  * @param clas the group class
4554  * @param del the callback to delete the content
4555  *
4556  * @ingroup Map
4557  */
4558 EAPI void
4559 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4560 {
4561    EINA_SAFETY_ON_NULL_RETURN(clas);
4562    clas->func.del = del;
4563 }
4564
4565 /**
4566  * Get the list of the sources.
4567  *
4568  * @param obj The map object
4569  * @return sources the source list
4570  *
4571  * @ingroup Map
4572  */
4573
4574 EAPI const char **
4575 elm_map_source_names_get(const Evas_Object *obj)
4576 {
4577    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4578    Widget_Data *wd = elm_widget_data_get(obj);
4579
4580    if (!wd) return NULL;
4581    return wd->source_names;
4582 }
4583
4584 /**
4585  * Set the source of the map.
4586  *
4587  * Elm_Map retrieves the image which composed the map from a web service. This web service can
4588  * be set with this method. A different service can return a different maps with different
4589  * information and it can use different zoom value.
4590  *
4591  * @param obj the map object
4592  * @param source the new source
4593  *
4594  * @ingroup Map
4595  */
4596 EAPI void
4597 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4598 {
4599    ELM_CHECK_WIDTYPE(obj, widtype);
4600    Widget_Data *wd = elm_widget_data_get(obj);
4601    Map_Sources_Tab *s;
4602    Eina_List *l;
4603    Grid *grid;
4604    int zoom;
4605
4606    if (!wd) return;
4607    if ((wd->src) && (!strcmp(wd->src->name, source_name))) return;
4608    if ((wd->src) && (!wd->src->url_cb)) return;
4609
4610    EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4611    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4612      {
4613         if (!strcmp(s->name, source_name))
4614           {
4615              wd->src = s;
4616              break;
4617           }
4618      }
4619    zoom = wd->zoom;
4620    wd->zoom = -1;
4621
4622    if (wd->src->zoom_max < zoom)
4623      zoom = wd->src->zoom_max;
4624    if (wd->src->zoom_min > zoom)
4625      zoom = wd->src->zoom_min;
4626
4627    elm_map_zoom_set(obj, zoom);
4628 }
4629
4630 /**
4631  * Get the name of a source.
4632  *
4633  * @param source the source
4634  * @return Returns the name of the source
4635  *
4636  * @ingroup Map
4637  */
4638 EAPI const char *
4639 elm_map_source_name_get(const Evas_Object *obj)
4640 {
4641    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4642    Widget_Data *wd = elm_widget_data_get(obj);
4643
4644    if ((!wd) || (!wd->src)) return NULL;
4645    return wd->src->name;
4646 }
4647
4648 /**
4649  * Set the source of the route.
4650  *
4651  * @param clas the group class
4652  * @param source the new source
4653  *
4654  * @ingroup Map
4655  */
4656 EAPI void
4657 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4658 {
4659    ELM_CHECK_WIDTYPE(obj, widtype);
4660    Widget_Data *wd = elm_widget_data_get(obj);
4661
4662    if (!wd) return;
4663    wd->route_source = source;
4664 }
4665
4666 /**
4667  * Get the current route source
4668  *
4669  * @param obj the map object
4670  * @return Returns the source of the route
4671  *
4672  * @ingroup Map
4673  */
4674 EAPI Elm_Map_Route_Sources
4675 elm_map_route_source_get(const Evas_Object *obj)
4676 {
4677    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4678    Widget_Data *wd = elm_widget_data_get(obj);
4679
4680    if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4681    return wd->route_source;
4682 }
4683
4684 /**
4685  * Set the maximum zoom of the source.
4686  *
4687  * @param source the source
4688  *
4689  * @ingroup Map
4690  */
4691 EAPI void
4692 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4693 {
4694    ELM_CHECK_WIDTYPE(obj, widtype);
4695    Widget_Data *wd = elm_widget_data_get(obj);
4696
4697    if ((!wd) || (!wd->src)) return;
4698    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4699    wd->src->zoom_max = zoom;
4700 }
4701
4702 /**
4703  * Get the maximum zoom of the source.
4704  *
4705  * @param source the source
4706  * @return Returns the maximum zoom of the source
4707  *
4708  * @ingroup Map
4709  */
4710 EAPI int
4711 elm_map_source_zoom_max_get(const Evas_Object *obj)
4712 {
4713    ELM_CHECK_WIDTYPE(obj, widtype) 18;
4714    Widget_Data *wd = elm_widget_data_get(obj);
4715
4716    if ((!wd) || (!wd->src)) return 18;
4717    return wd->src->zoom_max;
4718 }
4719
4720 /**
4721  * Set the minimum zoom of the source.
4722  *
4723  * @param source the source
4724  *
4725  * @ingroup Map
4726  */
4727 EAPI void
4728 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4729 {
4730    ELM_CHECK_WIDTYPE(obj, widtype);
4731    Widget_Data *wd = elm_widget_data_get(obj);
4732
4733    if ((!wd) || (!wd->src)) return;
4734    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4735    wd->src->zoom_min = zoom;
4736 }
4737
4738
4739 /**
4740  * Get the minimum zoom of the source.
4741  *
4742  * @param source the source
4743  * @return Returns the minimum zoom of the source
4744  *
4745  * @ingroup Map
4746  */
4747 EAPI int
4748 elm_map_source_zoom_min_get(const Evas_Object *obj)
4749 {
4750    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4751    Widget_Data *wd = elm_widget_data_get(obj);
4752
4753    if ((!wd) || (!wd->src)) return 0;
4754    return wd->src->zoom_min;
4755 }
4756
4757 /**
4758  * Set the user agent of the widget map.
4759  *
4760  * @param obj The map object
4761  * @param user_agent the user agent of the widget map
4762  *
4763  * @ingroup Map
4764  */
4765 EAPI void
4766 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4767 {
4768    ELM_CHECK_WIDTYPE(obj, widtype);
4769    Widget_Data *wd = elm_widget_data_get(obj);
4770
4771    if (!wd) return;
4772    if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4773    else eina_stringshare_replace(&wd->user_agent, user_agent);
4774
4775    if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4776    eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4777 }
4778
4779 /**
4780  * Get the user agent of the widget map.
4781  *
4782  * @param obj The map object
4783  * @return The user agent of the widget map
4784  *
4785  * @ingroup Map
4786  */
4787 EAPI const char *
4788 elm_map_user_agent_get(const Evas_Object *obj)
4789 {
4790    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4791    Widget_Data *wd = elm_widget_data_get(obj);
4792
4793    if (!wd) return NULL;
4794    return wd->user_agent;
4795 }
4796
4797 /**
4798  * Add a route on the map
4799  *
4800  * @param obj The map object
4801  * @param type the type if transport
4802  * @param method the routing method
4803  * @param flon the start longitude
4804  * @param flat the start latitude
4805  * @param tlon the destination longitude
4806  * @param tlat the destination latitude
4807  *
4808  * @return The Route object
4809  *
4810  * @ingroup Map
4811  */
4812 EAPI Elm_Map_Route *
4813 elm_map_route_add(Evas_Object *obj,
4814                   Elm_Map_Route_Type type,
4815                   Elm_Map_Route_Method method,
4816                   double flon,
4817                   double flat,
4818                   double tlon,
4819                   double tlat)
4820 {
4821    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4822    Widget_Data *wd = elm_widget_data_get(obj);
4823    char buf[PATH_MAX];
4824    char *source;
4825    char *type_name = NULL;
4826    int fd;
4827
4828    if ((!wd) || (!wd->src)) return NULL;
4829
4830    Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4831    if (!route) return NULL;
4832
4833    snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4834    fd = mkstemp(buf);
4835    if (fd < 0)
4836      {
4837         free(route);
4838         return NULL;
4839      }
4840
4841    route->con_url = ecore_con_url_new(NULL);
4842    route->ud.fname = strdup(buf);
4843    INF("xml file : %s", route->ud.fname);
4844
4845    route->ud.fd = fdopen(fd, "w+");
4846    if ((!route->con_url) || (!route->ud.fd))
4847      {
4848         ecore_con_url_free(route->con_url);
4849         free(route);
4850         return NULL;
4851      }
4852
4853    route->wd = wd;
4854    route->color.r = 255;
4855    route->color.g = 0;
4856    route->color.b = 0;
4857    route->color.a = 255;
4858    route->handlers = eina_list_append
4859      (route->handlers, (void *)ecore_event_handler_add
4860          (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
4861
4862    route->inbound = EINA_FALSE;
4863    route->type = type;
4864    route->method = method;
4865    route->flon = flon;
4866    route->flat = flat;
4867    route->tlon = tlon;
4868    route->tlat = tlat;
4869
4870    switch (type)
4871      {
4872       case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4873         type_name = strdup(ROUTE_TYPE_MOTORCAR);
4874         break;
4875       case ELM_MAP_ROUTE_TYPE_BICYCLE:
4876         type_name = strdup(ROUTE_TYPE_BICYCLE);
4877         break;
4878       case ELM_MAP_ROUTE_TYPE_FOOT:
4879         type_name = strdup(ROUTE_TYPE_FOOT);
4880         break;
4881       default:
4882         break;
4883      }
4884
4885    source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4886    INF("route url = %s", source);
4887
4888    wd->route = eina_list_append(wd->route, route);
4889
4890    ecore_con_url_url_set(route->con_url, source);
4891    ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4892    ecore_con_url_data_set(route->con_url, route);
4893    ecore_con_url_get(route->con_url);
4894    if (type_name) free(type_name);
4895    if (source) free(source);
4896
4897    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4898                            "elm,state,busy,start", "elm");
4899    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4900    return route;
4901 }
4902
4903
4904 /**
4905  * Remove a route from the map
4906  *
4907  * @param route The route to remove
4908  *
4909  * @ingroup Map
4910  */
4911
4912 EAPI void
4913 elm_map_route_remove(Elm_Map_Route *route)
4914 {
4915    EINA_SAFETY_ON_NULL_RETURN(route);
4916
4917    Path_Waypoint *w;
4918    Path_Node *n;
4919    Evas_Object *p;
4920    Ecore_Event_Handler *h;
4921
4922    EINA_LIST_FREE(route->path, p)
4923      {
4924         evas_object_del(p);
4925      }
4926
4927    EINA_LIST_FREE(route->waypoint, w)
4928      {
4929         if (w->point) eina_stringshare_del(w->point);
4930         free(w);
4931      }
4932
4933    EINA_LIST_FREE(route->nodes, n)
4934      {
4935         if (n->pos.address) eina_stringshare_del(n->pos.address);
4936         free(n);
4937      }
4938
4939    EINA_LIST_FREE(route->handlers, h)
4940      {
4941         ecore_event_handler_del(h);
4942      }
4943
4944    if (route->ud.fname)
4945      {
4946         ecore_file_remove(route->ud.fname);
4947         free(route->ud.fname);
4948         route->ud.fname = NULL;
4949      }
4950 }
4951
4952 /**
4953  * Set the option used for the background color
4954  *
4955  * @param route The route object
4956  * @param r
4957  * @param g
4958  * @param b
4959  * @param a
4960  *
4961  * This sets the color used for the route
4962  *
4963  * @ingroup Map
4964  */
4965 EAPI void
4966 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4967 {
4968    EINA_SAFETY_ON_NULL_RETURN(route);
4969    route->color.r = r;
4970    route->color.g = g;
4971    route->color.b = b;
4972    route->color.a = a;
4973 }
4974
4975 /**
4976  * Get the option used for the background color
4977  *
4978  * @param route The route object
4979  * @param r
4980  * @param g
4981  * @param b
4982  * @param a
4983  *
4984  * @ingroup Map
4985  */
4986 EAPI void
4987 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
4988 {
4989    EINA_SAFETY_ON_NULL_RETURN(route);
4990    if (r) *r = route->color.r;
4991    if (g) *g = route->color.g;
4992    if (b) *b = route->color.b;
4993    if (a) *a = route->color.a;
4994 }
4995
4996 /**
4997  * Get the information of route distance
4998  *
4999  * @param route the route object
5000  * @return Returns the distance of route (unit : km)
5001  *
5002  * @ingroup Map
5003  */
5004 EAPI double
5005 elm_map_route_distance_get(const Elm_Map_Route *route)
5006 {
5007    EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
5008    return route->info.distance;
5009 }
5010
5011 /**
5012  * Get the information of route nodes
5013  *
5014  * @param route the route object
5015  * @return Returns the nodes of route
5016  *
5017  * @ingroup Map
5018  */
5019
5020 EAPI const char*
5021 elm_map_route_node_get(const Elm_Map_Route *route)
5022 {
5023    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5024    return route->info.nodes;
5025 }
5026
5027 /**
5028  * Get the information of route waypoint
5029  *
5030  * @param route the route object
5031  * @return Returns the waypoint of route
5032  *
5033  * @ingroup Map
5034  */
5035
5036 EAPI const char*
5037 elm_map_route_waypoint_get(const Elm_Map_Route *route)
5038 {
5039    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5040    return route->info.waypoints;
5041 }
5042
5043 /**
5044  * Get the information of address
5045  *
5046  * @param name the name object
5047  * @return Returns the address of name
5048  *
5049  * @ingroup Map
5050  */
5051 EAPI const char *
5052 elm_map_name_address_get(const Elm_Map_Name *name)
5053 {
5054    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
5055    return name->address;
5056 }
5057
5058 /**
5059  * Get the current coordinates of the name.
5060  *
5061  * This gets the current coordinates of the name object.
5062  *
5063  * @param obj The name object
5064  * @param lat The latitude
5065  * @param lon The longitude
5066  *
5067  * @ingroup Map
5068  */
5069 EAPI void
5070 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
5071 {
5072    EINA_SAFETY_ON_NULL_RETURN(name);
5073    if (lon) *lon = name->lon;
5074    if (lat) *lat = name->lat;
5075 }
5076
5077 /**
5078  * Remove a name from the map
5079  *
5080  * @param name The name to remove
5081  *
5082  * @ingroup Map
5083  */
5084 EAPI void
5085 elm_map_name_remove(Elm_Map_Name *name)
5086 {
5087    EINA_SAFETY_ON_NULL_RETURN(name);
5088    if (name->address)
5089      {
5090         free(name->address);
5091         name->address = NULL;
5092      }
5093    if (name->handler)
5094      {
5095         ecore_event_handler_del(name->handler);
5096         name->handler = NULL;
5097      }
5098    if (name->ud.fname)
5099      {
5100         ecore_file_remove(name->ud.fname);
5101         free(name->ud.fname);
5102         name->ud.fname = NULL;
5103      }
5104 }
5105
5106 /**
5107  * Set the rotate degree of the map
5108  *
5109  * @param obj The map object
5110  * @param angle amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5111  * @param cx rotation's center horizontal position
5112  * @param cy rotation's center vertical position
5113  *
5114  * @ingroup Map
5115  */
5116 EAPI void
5117 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
5118 {
5119    ELM_CHECK_WIDTYPE(obj, widtype);
5120    Widget_Data *wd = elm_widget_data_get(obj);
5121
5122    if (!wd) return;
5123    wd->rotate.d = degree;
5124    wd->rotate.cx = cx;
5125    wd->rotate.cy = cy;
5126    wd->calc_job = ecore_job_add(_calc_job, wd);
5127 }
5128
5129 /**
5130  * Get the rotate degree of the map
5131  *
5132  * @param obj The map object
5133  * @return amount of degrees from 0.0 to 360.0 to rotate arount Z axis
5134  * @param cx rotation's center horizontal position
5135  * @param cy rotation's center vertical position
5136  *
5137  * @ingroup Map
5138  */
5139 EAPI void
5140 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
5141 {
5142    ELM_CHECK_WIDTYPE(obj, widtype);
5143    Widget_Data *wd = elm_widget_data_get(obj);
5144
5145    if (!wd) return;
5146    if (degree) *degree = wd->rotate.d;
5147    if (cx) *cx = wd->rotate.cx;
5148    if (cy) *cy = wd->rotate.cy;
5149 }
5150
5151 /**
5152  * Set the wheel control state of the map
5153  *
5154  * @param obj The map object
5155  * @param disabled status of wheel control
5156  *
5157  * @ingroup Map
5158  */
5159 EAPI void
5160 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
5161 {
5162    ELM_CHECK_WIDTYPE(obj, widtype);
5163    Widget_Data *wd = elm_widget_data_get(obj);
5164
5165    if (!wd) return;
5166    if ((!wd->wheel_disabled) && (disabled))
5167      evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5168    else if ((wd->wheel_disabled) && (!disabled))
5169      evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
5170    wd->wheel_disabled = !!disabled;
5171 }
5172
5173 /**
5174  * Get the wheel control state of the map
5175  *
5176  * @param obj The map object
5177  * @return Returns the status of wheel control
5178  *
5179  * @ingroup Map
5180  */
5181 EAPI Eina_Bool
5182 elm_map_wheel_disabled_get(const Evas_Object *obj)
5183 {
5184    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5185    Widget_Data *wd = elm_widget_data_get(obj);
5186
5187    if (!wd) return EINA_FALSE;
5188    return wd->wheel_disabled;
5189 }
5190
5191 #ifdef ELM_EMAP
5192 /**
5193  * Add a track on the map
5194  *
5195  * @param obj The map object
5196  * @param emap the emap object
5197  *
5198  * @return The Route object. This is a elm object of type Elm_Route
5199  *
5200  * @ingroup Map
5201  */
5202 EAPI Evas_Object *
5203 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
5204 {
5205    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5206    Widget_Data *wd = elm_widget_data_get(obj);
5207
5208    if (!wd) return EINA_FALSE;
5209
5210    Evas_Object *route = elm_route_add(obj);
5211    elm_route_emap_set(route, emap);
5212    wd->track = eina_list_append(wd->track, route);
5213
5214    return route;
5215 }
5216
5217 #endif
5218
5219 /**
5220  * Remove a track from the map
5221  *
5222  * @param track The track to remove
5223  *
5224  * @ingroup Map
5225  */
5226
5227 EAPI void
5228 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
5229 {
5230    ELM_CHECK_WIDTYPE(obj, widtype) ;
5231    Widget_Data *wd = elm_widget_data_get(obj);
5232
5233    if (!wd) return ;
5234
5235    wd->track = eina_list_remove(wd->track, route);
5236    evas_object_del(route);
5237 }
5238
5239 static char *
5240 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5241 {
5242    char buf[PATH_MAX];
5243    snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
5244           zoom, x, y);
5245    return strdup(buf);
5246 }
5247
5248 static char *
5249 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5250 {
5251    char buf[PATH_MAX];
5252    snprintf(buf, sizeof(buf),
5253             "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
5254             zoom, x, y);
5255    return strdup(buf);
5256 }
5257
5258 static char *
5259 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5260 {
5261    char buf[PATH_MAX];
5262    snprintf(buf, sizeof(buf),
5263             "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
5264             zoom, x, y);
5265    return strdup(buf);
5266 }
5267
5268 static char *
5269 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5270 {
5271    char buf[PATH_MAX];
5272    snprintf(buf, sizeof(buf),
5273             "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
5274             zoom, x, y);
5275    return strdup(buf);
5276 }
5277
5278 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5279 {
5280    char buf[PATH_MAX];
5281    snprintf(buf, sizeof(buf),
5282             "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
5283             ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
5284
5285    return strdup(buf);
5286 }
5287
5288 // TODO: fix monav api
5289 /*
5290 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5291 {
5292    char buf[PATH_MAX];
5293    snprintf(buf, sizeof(buf),
5294             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5295             ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
5296
5297    return strdup(buf);
5298 }
5299 */
5300
5301 // TODO: fix ors api
5302 /*
5303 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5304 {
5305    char buf[PATH_MAX];
5306    snprintf(buf, sizeof(buf),
5307             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5308             ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
5309
5310    return strdup(buf);
5311 }
5312 */
5313
5314 static char *
5315 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
5316 {
5317    ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
5318    Widget_Data *wd = elm_widget_data_get(obj);
5319    char **str;
5320    unsigned int ele, idx;
5321    char search_url[PATH_MAX];
5322    char buf[PATH_MAX];
5323
5324    if (!wd) return strdup("");
5325    if (method == ELM_MAP_NAME_METHOD_SEARCH)
5326      {
5327         search_url[0] = '\0';
5328         str = eina_str_split_full(name, " ", 0, &ele);
5329         for (idx = 0 ; idx < ele ; idx++)
5330           {
5331              eina_strlcat(search_url, str[idx], sizeof(search_url));
5332              if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
5333           }
5334         snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
5335      }
5336    else if (method == ELM_MAP_NAME_METHOD_REVERSE) snprintf(buf, sizeof(buf), "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0", NAME_NOMINATIM_URL, lat, lon, wd->zoom);
5337    else strcpy(buf, "");
5338
5339    return strdup(buf);
5340 }
5341