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