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