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