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