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