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