From: Hyoyoung Chang <hyoyoung@gmail.com>
[framework/uifw/elementary.git] / src / lib / elm_map.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #include "Elementary.h"
6 #include "elm_priv.h"
7 #include "els_scroller.h"
8
9 #ifdef HAVE_ELEMENTARY_ECORE_CON
10
11 typedef struct _Widget_Data Widget_Data;
12 typedef struct _Pan Pan;
13 typedef struct _Grid Grid;
14 typedef struct _Grid_Item Grid_Item;
15 typedef struct _Overlay_Default Overlay_Default;
16 typedef struct _Overlay_Group Overlay_Group;
17 typedef struct _Overlay_Class Overlay_Class;
18 typedef struct _Overlay_Bubble Overlay_Bubble;
19 typedef struct _Overlay_Route Overlay_Route;
20 typedef struct _Marker_Group Marker_Group;
21 typedef struct _Marker_Bubble Marker_Bubble;
22 typedef struct _Path_Node Path_Node;
23 typedef struct _Path_Waypoint Path_Waypoint;
24 typedef struct _Url_Data Url_Data;
25 typedef struct _Route_Dump Route_Dump;
26 typedef struct _Name_Dump Name_Dump;
27 typedef struct _Delayed_Data Delayed_Data;
28 typedef struct _Source_Tile Source_Tile;
29 typedef struct _Source_Route Source_Route;
30 typedef struct _Source_Name Source_Name;
31
32 #define ROUND(z)                (((z) < 0) ? (int)ceil((z) - 0.005) : (int)floor((z) + 0.005))
33 #define EVAS_MAP_POINT          4
34 #define DEFAULT_TILE_SIZE       256
35 #define MAX_CONCURRENT_DOWNLOAD 10
36 #define MARER_MAX_NUMBER        30
37 #define OVERLAY_CLASS_ZOOM_MAX 255
38 #define OVERLAY_GROUPING_SCALE 2
39
40 #define CACHE_ROOT          "/tmp/elm_map"
41 #define CACHE_TILE_ROOT     CACHE_ROOT"/%d/%d/%d"
42 #define CACHE_TILE_PATH     "%s/%d.png"
43 #define CACHE_ROUTE_ROOT    CACHE_ROOT"/route"
44 #define CACHE_NAME_ROOT     CACHE_ROOT"/name"
45
46 #define ROUTE_YOURS_URL     "http://www.yournavigation.org/api/dev/route.php"
47 #define ROUTE_TYPE_MOTORCAR "motocar"
48 #define ROUTE_TYPE_BICYCLE  "bicycle"
49 #define ROUTE_TYPE_FOOT     "foot"
50 #define YOURS_DISTANCE      "distance"
51 #define YOURS_DESCRIPTION   "description"
52 #define YOURS_COORDINATES   "coordinates"
53
54 #define NAME_NOMINATIM_URL  "http://nominatim.openstreetmap.org"
55 #define NOMINATIM_RESULT    "result"
56 #define NOMINATIM_PLACE     "place"
57 #define NOMINATIM_ATTR_LON  "lon"
58 #define NOMINATIM_ATTR_LAT  "lat"
59
60 enum _Route_Xml_Attribute
61 {
62    ROUTE_XML_NONE,
63    ROUTE_XML_DISTANCE,
64    ROUTE_XML_DESCRIPTION,
65    ROUTE_XML_COORDINATES,
66    ROUTE_XML_LAST
67 } Route_Xml_Attibute;
68
69 enum _Name_Xml_Attribute
70 {
71    NAME_XML_NONE,
72    NAME_XML_NAME,
73    NAME_XML_LON,
74    NAME_XML_LAT,
75    NAME_XML_LAST
76 } Name_Xml_Attibute;
77
78 enum _Track_Xml_Attribute
79 {
80    TRACK_XML_NONE,
81    TRACK_XML_COORDINATES,
82    TRACK_XML_LAST
83 } Track_Xml_Attibute;
84
85 struct _Delayed_Data
86 {
87    void (*func)(void *data);
88    Widget_Data *wd;
89    Elm_Map_Zoom_Mode mode;
90    int zoom;
91    double lon, lat;
92    Eina_List *markers;
93    Eina_List *overlays;
94 };
95
96 // Map Tile source
97 // FIXME: Currently tile size must be 256*256
98 // and the map size is pow(2.0, z) * (tile size)
99 struct _Source_Tile
100 {
101    const char *name;
102    int zoom_min;
103    int zoom_max;
104    Elm_Map_Module_Tile_Url_Func url_cb;
105    Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
106    Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
107 };
108
109 // Map Route Source
110 struct _Source_Route
111 {
112    const char *name;
113    Elm_Map_Module_Route_Url_Func url_cb;
114 };
115
116 // Map Name Source
117 struct _Source_Name
118 {
119    const char *name;
120    Elm_Map_Module_Name_Url_Func url_cb;
121 };
122
123 struct _Url_Data
124 {
125    Ecore_Con_Url *con_url;
126
127    FILE *fd;
128    char *fname;
129 };
130
131 struct _Overlay_Default
132 {
133    Evas_Coord w, h;
134
135    // Display priority is obj > icon > clas_obj > clas_icon > layout
136    Evas_Object *obj;
137    Evas_Object *icon;
138
139    // if obj or icon exists, do not inherit from class
140    Evas_Object *clas_obj;      // Duplicated from class icon
141    Evas_Object *clas_obj_ref;  // Checking fro class icon is changed
142    Evas_Object *clas_icon;     // Duplicated from class icon
143    Evas_Object *clas_icon_ref; // Checking for class icon is changed
144
145    char *style;
146    Evas_Object *layout;
147    double lon, lat;
148    Evas_Coord x, y;
149 };
150
151 struct _Overlay_Group
152 {
153    Overlay_Default *ovl;
154    Evas_Object *clas_icon;
155    Elm_Map_Overlay *clas;
156    Eina_List *members;
157 };
158
159 struct _Overlay_Class
160 {
161    Elm_Map_Overlay *clas;
162    Evas_Object *obj;
163    char *style;
164    Evas_Object *icon;
165    Eina_List *members;
166    int zoom_max;
167 };
168
169 struct _Overlay_Bubble
170 {
171    Widget_Data *wd;
172    Evas_Object *pobj;
173    Evas_Object *obj, *sc, *bx;
174    double lon, lat;
175    Evas_Coord x, y, w, h;
176 };
177
178 struct _Overlay_Route
179 {
180    Widget_Data *wd;
181
182    Eina_Bool inbound : 1;
183    struct
184      {
185         int r;
186         int g;
187         int b;
188         int a;
189      } color;
190
191    Eina_List *paths;
192    Eina_List *nodes;
193    int x, y;
194 };
195
196 struct _Elm_Map_Overlay
197 {
198    Widget_Data *wd;
199
200    Eina_Bool paused : 1;
201    Eina_Bool hide : 1;
202    Evas_Coord zoom_min;
203
204     void *data;               // user set data
205
206    Elm_Map_Overlay_Type type;
207    void *ovl;                 // Overlay Data for each type
208
209    // These are not used if overlay type is class
210    Eina_Bool grp_in : 1;
211    Eina_Bool grp_boss : 1;
212    Overlay_Group *grp;
213
214    Elm_Map_Overlay_Get_Cb cb;
215    void *cb_data;
216 };
217
218 struct _Elm_Map_Marker_Class
219 {
220    const char *style;
221    struct _Elm_Map_Marker_Class_Func
222      {
223         Elm_Map_Marker_Get_Func get;
224         Elm_Map_Marker_Del_Func del; //if NULL the object will be destroyed with evas_object_del()
225         Elm_Map_Marker_Icon_Get_Func icon_get;
226      } func;
227 };
228
229 struct _Elm_Map_Group_Class
230 {
231    Widget_Data *wd;
232
233    Eina_List *markers;
234    int zoom_displayed; // display the group if the zoom is >= to zoom_display
235    int zoom_grouped;   // group the markers only if the zoom is <= to zoom_groups
236    const char *style;
237    void *data;
238    struct
239      {
240         Elm_Map_Group_Icon_Get_Func icon_get;
241      } func;
242
243    Eina_Bool hide : 1;
244 };
245
246 struct _Marker_Bubble
247 {
248    Widget_Data *wd;
249    Evas_Object *pobj;
250    Evas_Object *obj, *sc, *bx;
251 };
252
253 struct _Elm_Map_Marker
254 {
255    Widget_Data *wd;
256    Elm_Map_Marker_Class *clas;
257    Elm_Map_Group_Class *group_clas;
258    double longitude, latitude;
259    Evas_Coord w, h;
260    Evas_Object *obj;
261
262    Evas_Coord x, y;
263    Eina_Bool grouped : 1;
264    Eina_Bool leader : 1; // if marker is group leader
265    Marker_Group *group;
266
267    Marker_Bubble *bubble;
268    Evas_Object *content;
269    void *data;
270 };
271
272 struct _Marker_Group
273 {
274    Widget_Data *wd;
275    Elm_Map_Group_Class *clas;
276    Evas_Coord w, h;
277    Evas_Object *obj;
278
279    Evas_Coord x, y;
280    Eina_List *markers;
281
282    Marker_Bubble *bubble;
283 };
284
285 struct _Elm_Map_Route
286 {
287    Widget_Data *wd;
288
289    char *fname;
290    Elm_Map_Route_Type type;
291    Elm_Map_Route_Method method;
292    double flon, flat, tlon, tlat;
293    Elm_Map_Route_Cb cb;
294    void *data;
295    Ecore_File_Download_Job *job;
296
297
298    Eina_List *nodes;
299    Eina_List *waypoint;
300    struct
301      {
302         int node_count;
303         int waypoint_count;
304         const char *nodes;
305         const char *waypoints;
306         double distance; /* unit : km */
307      } info;
308
309    Path_Node *n;
310    Path_Waypoint *w;
311
312 };
313
314 struct _Path_Node
315 {
316    Widget_Data *wd;
317
318    int idx;
319    struct
320      {
321         double lon, lat;
322         char *address;
323      } pos;
324 };
325
326 struct _Path_Waypoint
327 {
328    Widget_Data *wd;
329
330    const char *point;
331 };
332
333 struct _Elm_Map_Name
334 {
335    Widget_Data *wd;
336
337    int method;
338    char *address;
339    double lon, lat;
340
341    char *fname;
342    Ecore_File_Download_Job *job;
343    Elm_Map_Name_Cb cb;
344    void *data;
345 };
346
347 struct _Route_Dump
348 {
349    int id;
350    char *fname;
351    double distance;
352    char *description;
353    char *coordinates;
354 };
355
356 struct _Name_Dump
357 {
358    int id;
359    char *address;
360    double lon;
361    double lat;
362 };
363
364 struct _Grid_Item
365 {
366    Grid *g;
367
368    Widget_Data *wd;
369    Evas_Object *img;
370    const char *file;
371    const char *url;
372    int x, y;  // Tile coordinate
373    Eina_Bool file_have : 1;
374
375    Ecore_File_Download_Job *job;
376 };
377
378 struct _Grid
379 {
380    Widget_Data *wd;
381    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
382    int tw, th; // size of grid in tiles
383    Eina_Matrixsparse *grid;
384 };
385
386 struct _Pan
387 {
388    Evas_Object_Smart_Clipped_Data __clipped_data;
389    Widget_Data *wd;
390 };
391
392 struct _Widget_Data
393 {
394    Evas_Object *obj;
395    Evas_Object *scr;
396    Evas_Object *ges;
397    Evas_Object *pan_smart;
398    Evas_Object *sep_maps_markers; // Tiles are below this and overlays are on top
399    Evas_Map *map;
400
401    Source_Tile *src_tile;
402    Eina_List *src_tiles;
403    const char **src_tile_names;
404
405    Source_Route *src_route;
406    Eina_List *src_routes;
407    const char **src_route_names;
408
409    Source_Name *src_name;
410    Eina_List *src_names;
411    const char **src_name_names;
412
413    int zoom_min, zoom_max;
414    int tsize;
415
416    int id;
417    Eina_List *grids;
418
419    int zoom;
420    double zoom_detail;
421    double prev_lon, prev_lat;
422    Evas_Coord ox, oy;
423    struct
424      {
425         int w, h;  // Current pixel width, heigth of a grid
426         int tile;  // Current pixel size of a grid item
427      } size;
428    Elm_Map_Zoom_Mode mode;
429    struct
430      {
431         double zoom;
432         double diff;
433         int cnt;
434      } ani;
435    Ecore_Timer *zoom_timer;
436    Ecore_Animator *zoom_animator;
437
438    int try_num;
439    int finish_num;
440    int download_num;
441    Eina_List *download_list;
442    Ecore_Idler *download_idler;
443    Eina_Hash *ua;
444    const char *user_agent;
445
446    Evas_Coord pan_x, pan_y;
447    Eina_List *delayed_jobs;
448
449    Ecore_Timer *scr_timer;
450    Ecore_Timer *long_timer;
451    Evas_Event_Mouse_Down ev;
452    Eina_Bool on_hold : 1;
453    Eina_Bool paused : 1;
454
455    double pinch_zoom;
456    struct
457      {
458         Evas_Coord cx, cy;
459         double a, d;
460      } rotate;
461
462    Eina_Bool wheel_disabled : 1;
463
464    unsigned int markers_max_num;
465    Eina_Bool paused_markers : 1;
466    Eina_List *group_classes;
467    Eina_List *marker_classes;
468    Eina_List *markers;
469
470    Eina_List *routes;
471    Eina_List *track;
472    Eina_List *names;
473
474    Eina_List *overlays;
475 };
476
477 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
478 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
479 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
480 static char *_mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
481 static char *_mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
482 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat);
483 static char *_nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat);
484 /*
485 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
486 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
487 */
488
489 const Source_Tile src_tiles[] =
490 {
491    {"Mapnik", 0, 18, _mapnik_url_cb, NULL, NULL},
492    {"Osmarender", 0, 17, _osmarender_url_cb, NULL, NULL},
493    {"CycleMap", 0, 16, _cyclemap_url_cb, NULL, NULL},
494    {"MapQuest", 0, 18, _mapquest_url_cb, NULL, NULL},
495    {"MapQuest Open Aerial", 0, 11, _mapquest_aerial_url_cb, NULL, NULL},
496 };
497
498 // FIXME: Fix more open sources
499 const Source_Route src_routes[] =
500 {
501    {"Yours", _yours_url_cb}    // http://www.yournavigation.org/
502    //{"Monav", _monav_url_cb},
503    //{"ORS", _ors_url_cb},     // http://www.openrouteservice.org
504 };
505
506 // FIXME: Add more open sources
507 const Source_Name src_names[] =
508 {
509    {"Nominatim", _nominatim_url_cb}
510 };
511
512 static const char *widtype = NULL;
513 static Evas_Smart_Class parent_sc = EVAS_SMART_CLASS_INIT_NULL;
514 static Evas_Smart_Class sc;
515 static Evas_Smart *smart;
516 static int idnum = 1;
517
518 static const char SIG_CLICKED[] =            "clicked";
519 static const char SIG_CLICKED_DOUBLE[] =     "clicked,double";
520 static const char SIG_PRESS[] =              "press";
521 static const char SIG_LONGPRESSED[] =        "longpressed";
522 static const char SIG_SCROLL[] =             "scroll";
523 static const char SIG_SCROLL_DRAG_START[] =  "scroll,drag,start";
524 static const char SIG_SCROLL_DRAG_STOP[] =   "scroll,drag,stop";
525 static const char SIG_SCROLL_ANIM_START[] =  "scroll,anim,start";
526 static const char SIG_SCROLL_ANIM_STOP[] =   "scroll,anim,stop";
527 static const char SIG_ZOOM_START[] =         "zoom,start";
528 static const char SIG_ZOOM_STOP[] =          "zoom,stop";
529 static const char SIG_ZOOM_CHANGE[] =        "zoom,change";
530 static const char SIG_TILE_LOAD[] =          "tile,load";
531 static const char SIG_TILE_LOADED[] =        "tile,loaded";
532 static const char SIG_TILE_LOADED_FAIL[] =   "tile,loaded,fail";
533 static const char SIG_ROUTE_LOAD[] =         "route,load";
534 static const char SIG_ROUTE_LOADED[] =       "route,loaded";
535 static const char SIG_ROUTE_LOADED_FAIL[] =  "route,loaded,fail";
536 static const char SIG_NAME_LOAD[] =          "name,load";
537 static const char SIG_NAME_LOADED[] =        "name,loaded";
538 static const char SIG_NAME_LOADED_FAIL[] =   "name,loaded,fail";
539 static const char SIG_OVERLAY_CLICKED[] =    "overlay,clicked";
540 static const Evas_Smart_Cb_Description _signals[] = {
541        {SIG_CLICKED, ""},
542        {SIG_CLICKED_DOUBLE, ""},
543        {SIG_PRESS, ""},
544        {SIG_LONGPRESSED, ""},
545        {SIG_SCROLL, ""},
546        {SIG_SCROLL_DRAG_START, ""},
547        {SIG_SCROLL_DRAG_STOP, ""},
548        {SIG_SCROLL_ANIM_START, ""},
549        {SIG_SCROLL_ANIM_STOP, ""},
550        {SIG_ZOOM_START, ""},
551        {SIG_ZOOM_STOP, ""},
552        {SIG_ZOOM_CHANGE, ""},
553        {SIG_TILE_LOAD, ""},
554        {SIG_TILE_LOADED, ""},
555        {SIG_TILE_LOADED_FAIL, ""},
556        {SIG_ROUTE_LOAD, ""},
557        {SIG_ROUTE_LOADED, ""},
558        {SIG_ROUTE_LOADED_FAIL, ""},
559        {SIG_NAME_LOAD, ""},
560        {SIG_NAME_LOADED, ""},
561        {SIG_NAME_LOADED_FAIL, ""},
562        {SIG_OVERLAY_CLICKED, ""},
563        {NULL, NULL}
564 };
565
566 static void
567 _edj_marker_size_get(Widget_Data *wd, Evas_Coord *w, Evas_Coord *h)
568 {
569    EINA_SAFETY_ON_NULL_RETURN(wd);
570    EINA_SAFETY_ON_NULL_RETURN(w);
571    EINA_SAFETY_ON_NULL_RETURN(h);
572
573    Evas_Object *edj;
574    const char *s;
575
576    edj = edje_object_add(evas_object_evas_get(wd->obj));
577    _elm_theme_object_set(wd->obj, edj, "map/marker", "radio",
578                          elm_widget_style_get(wd->obj));
579    s = edje_object_data_get(edj, "size_w");
580    if (s) *w = atoi(s);
581    else   *w = 0;
582    s = edje_object_data_get(edj, "size_h");
583    if (s) *h = atoi(s);
584    else   *h = 0;
585    evas_object_del(edj);
586 }
587
588 static void
589 _coord_rotate(Evas_Coord x, Evas_Coord y, Evas_Coord cx, Evas_Coord cy, double degree, Evas_Coord *xx, Evas_Coord *yy)
590 {
591    EINA_SAFETY_ON_NULL_RETURN(xx);
592    EINA_SAFETY_ON_NULL_RETURN(yy);
593
594    double r = (degree * M_PI) / 180.0;
595
596    if (xx) *xx = ((x - cx) * cos(r)) + ((y - cy) * cos(r + M_PI_2)) + cx;
597    if (yy) *yy = ((x - cx) * sin(r)) + ((y - cy) * sin(r + M_PI_2)) + cy;
598 }
599
600 static void
601 _obj_rotate(Widget_Data *wd, Evas_Object *obj)
602 {
603    Evas_Coord w, h, ow, oh;
604    evas_map_util_points_populate_from_object(wd->map, obj);
605
606    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
607    evas_object_image_size_get(obj, &w, &h);
608    if ((w > ow) || (h > oh))
609      {
610         evas_map_point_image_uv_set(wd->map, 0, 0, 0);
611         evas_map_point_image_uv_set(wd->map, 1, w, 0);
612         evas_map_point_image_uv_set(wd->map, 2, w, h);
613         evas_map_point_image_uv_set(wd->map, 3, 0, h);
614      }
615    evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
616
617    evas_object_map_set(obj, wd->map);
618    evas_object_map_enable_set(obj, EINA_TRUE);
619 }
620
621 static void
622 _obj_place(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
623 {
624    EINA_SAFETY_ON_NULL_RETURN(obj);
625
626    evas_object_move(obj, x, y);
627    evas_object_resize(obj, w, h);
628    evas_object_show(obj);
629 }
630
631 static void
632 _coord_to_region_convert(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord size, double *lon, double *lat)
633 {
634    EINA_SAFETY_ON_NULL_RETURN(wd);
635
636    int zoom = floor(log(size / wd->size.tile) / log(2));
637    if ((wd->src_tile) && (wd->src_tile->coord_to_geo))
638      {
639         if (wd->src_tile->coord_to_geo(wd->obj, zoom, x, y, size, lon, lat))
640            return;
641      }
642
643    if (lon) *lon = (x / (double)size * 360.0) - 180;
644    if (lat)
645      {
646         double n = ELM_PI - (2.0 * ELM_PI * y / size);
647         *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
648      }
649 }
650
651 static void
652 _geo_to_coord_convert(Widget_Data *wd, double lon, double lat, Evas_Coord size, Evas_Coord *x, Evas_Coord *y)
653 {
654    EINA_SAFETY_ON_NULL_RETURN(wd);
655
656    int zoom = floor(log(size / 256) / log(2));
657    if ((wd->src_tile) && (wd->src_tile->geo_to_coord))
658      {
659         if (wd->src_tile->geo_to_coord(wd->obj, zoom, lon, lat, size, x, y)) return;
660      }
661
662    if (x) *x = floor((lon + 180.0) / 360.0 * size);
663    if (y)
664       *y = floor((1.0 - log(tan(lat * ELM_PI / 180.0) + (1.0 / cos(lat * ELM_PI / 180.0)))
665                  / ELM_PI) / 2.0 * size);
666 }
667
668
669 static void
670 _viewport_size_get(Widget_Data *wd, Evas_Coord *vw, Evas_Coord *vh)
671 {
672    EINA_SAFETY_ON_NULL_RETURN(wd);
673
674    Evas_Coord x, y, w, h;
675    evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
676    if (vw) *vw = (x * 2) + w;
677    if (vh) *vh = (y * 2) + h;
678 }
679
680 static void
681 _pan_geometry_get(Widget_Data *wd, Evas_Coord *px, Evas_Coord *py)
682 {
683    EINA_SAFETY_ON_NULL_RETURN(wd);
684
685    Evas_Coord x, y, vx, vy, vw, vh;
686    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
687    evas_object_geometry_get(wd->pan_smart, &vx, &vy, &vw, &vh);
688    x = -x;
689    y = -y;
690    if (vw > wd->size.w) x += (((vw - wd->size.w) / 2) + vx);
691    else x -= vx;
692    if (vh > wd->size.h) y += (((vh - wd->size.h) / 2) + vy);
693    else y -= vy;
694    if (px) *px = x;
695    if (py) *py = y;
696  }
697
698 static void
699 _region_show(void *data)
700 {
701    EINA_SAFETY_ON_NULL_RETURN(data);
702    Delayed_Data *dd = data;
703    int x, y, w, h;
704
705    _geo_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
706    _viewport_size_get(dd->wd, &w, &h);
707    x = x - (w / 2);
708    y = y - (h / 2);
709    elm_smart_scroller_child_region_show(dd->wd->scr, x, y, w, h);
710    evas_object_smart_changed(dd->wd->pan_smart);
711 }
712
713 static void
714 _bubble_update(Marker_Bubble *bubble, Eina_List *contents)
715 {
716    EINA_SAFETY_ON_NULL_RETURN(bubble);
717    EINA_SAFETY_ON_NULL_RETURN(contents);
718
719    Eina_List *l;
720    Evas_Object *c;
721
722    elm_box_clear(bubble->bx);
723    EINA_LIST_FOREACH(contents, l, c) elm_box_pack_end(bubble->bx, c);
724 }
725
726 static void
727 _bubble_place(Marker_Bubble *bubble)
728 {
729    EINA_SAFETY_ON_NULL_RETURN(bubble);
730
731    Evas_Coord x, y, w, h;
732    Evas_Coord xx, yy, ww, hh;
733    const char *s;
734
735    if ((!bubble->obj) || (!bubble->pobj)) return;
736    evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
737
738    s = edje_object_data_get(bubble->obj, "size_w");
739    if (s) ww = atoi(s);
740    else ww = 0;
741
742    edje_object_size_min_calc(bubble->obj, NULL, &hh);
743    s = edje_object_data_get(bubble->obj, "size_h");
744    if (s) h = atoi(s);
745    else h = 0;
746    if (hh < h) hh = h;
747
748    xx = x + (w / 2) - (ww / 2);
749    yy = y - hh;
750
751    _obj_place(bubble->obj, xx, yy, ww, hh);
752    evas_object_raise(bubble->obj);
753 }
754
755 static void
756 _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
757 {
758    Marker_Bubble *bubble = data;
759    EINA_SAFETY_ON_NULL_RETURN(bubble);
760    _bubble_place(data);
761 }
762
763 static void
764 _bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
765 {
766    Marker_Bubble *bubble = data;
767    EINA_SAFETY_ON_NULL_RETURN(bubble);
768    _bubble_place(bubble);
769 }
770
771 static void
772 _bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
773 {
774    Marker_Bubble *bubble = data;
775    EINA_SAFETY_ON_NULL_RETURN(bubble);
776    evas_object_hide(bubble->obj);
777 }
778
779 static void
780 _bubble_show_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
781 {
782    Marker_Bubble *bubble = data;
783    EINA_SAFETY_ON_NULL_RETURN(bubble);
784    _bubble_place(bubble);
785 }
786
787 static void
788 _bubble_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
789 {
790    Marker_Bubble *bubble = data;
791    EINA_SAFETY_ON_NULL_RETURN(bubble);
792    _bubble_place(bubble);
793 }
794
795 static void
796 _bubble_free(Marker_Bubble* bubble)
797 {
798    EINA_SAFETY_ON_NULL_RETURN(bubble);
799
800    evas_object_del(bubble->bx);
801    evas_object_del(bubble->sc);
802    evas_object_del(bubble->obj);
803    free(bubble);
804 }
805
806 static Marker_Bubble*
807 _bubble_create(Evas_Object *pobj, Widget_Data *wd)
808 {
809    EINA_SAFETY_ON_NULL_RETURN_VAL(pobj, NULL);
810    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
811
812    Marker_Bubble *bubble = ELM_NEW(Marker_Bubble);
813    EINA_SAFETY_ON_NULL_RETURN_VAL(bubble, NULL);
814
815    bubble->wd = wd;
816    bubble->pobj = pobj;
817    evas_object_event_callback_add(pobj, EVAS_CALLBACK_HIDE, _bubble_hide_cb,
818                                   bubble);
819    evas_object_event_callback_add(pobj, EVAS_CALLBACK_SHOW, _bubble_show_cb,
820                                   bubble);
821    evas_object_event_callback_add(pobj, EVAS_CALLBACK_MOVE, _bubble_move_cb,
822                                   bubble);
823
824    bubble->obj = edje_object_add(evas_object_evas_get(pobj));
825    _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
826                          elm_widget_style_get(wd->obj));
827    evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
828                                   _bubble_mouse_up_cb, bubble);
829
830    bubble->sc = elm_scroller_add(bubble->obj);
831    elm_widget_style_set(bubble->sc, "map_bubble");
832    elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
833    elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
834                            ELM_SCROLLER_POLICY_OFF);
835    elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
836                            EINA_FALSE);
837    edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
838    evas_object_event_callback_add(bubble->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
839                                   _bubble_sc_hints_changed_cb, bubble);
840
841    bubble->bx = elm_box_add(bubble->sc);
842    evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
843    evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
844                                     EVAS_HINT_EXPAND);
845    elm_box_horizontal_set(bubble->bx, EINA_TRUE);
846    elm_object_content_set(bubble->sc, bubble->bx);
847
848    return bubble;
849 }
850
851 static void
852 _marker_group_update(Marker_Group* group, Elm_Map_Group_Class *clas, Eina_List *markers)
853 {
854    EINA_SAFETY_ON_NULL_RETURN(group);
855    EINA_SAFETY_ON_NULL_RETURN(clas);
856    EINA_SAFETY_ON_NULL_RETURN(markers);
857    Widget_Data *wd = clas->wd;
858    EINA_SAFETY_ON_NULL_RETURN(wd);
859
860    char buf[PATH_MAX];
861    Eina_List *l;
862    Elm_Map_Marker *marker;
863    int cnt = 0;
864    int sum_x = 0, sum_y = 0;
865
866    EINA_LIST_FOREACH(markers, l, marker)
867      {
868         sum_x += marker->x;
869         sum_y += marker->y;
870         cnt++;
871      }
872
873    group->x = sum_x / cnt;
874    group->y = sum_y / cnt;
875    _edj_marker_size_get(wd, &group->w, &group->h);
876    group->w *=2;
877    group->h *=2;
878    group->clas = clas;
879    group->markers = markers;
880
881    if (clas->style) elm_layout_theme_set(group->obj, "map/marker", clas->style,
882                                          elm_widget_style_get(wd->obj));
883    else elm_layout_theme_set(group->obj, "map/marker", "radio",
884                              elm_widget_style_get(wd->obj));
885
886
887    if (clas->func.icon_get)
888      {
889         Evas_Object *icon = NULL;
890
891         icon = elm_object_part_content_get(group->obj, "elm.icon");
892         if (icon) evas_object_del(icon);
893
894         icon = clas->func.icon_get(wd->obj, clas->data);
895         elm_object_part_content_set(group->obj, "elm.icon", icon);
896      }
897    snprintf(buf, sizeof(buf), "%d", cnt);
898    edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
899
900    if (group->bubble)
901       {
902          Eina_List *contents = NULL;
903
904          EINA_LIST_FOREACH(group->markers, l, marker)
905            {
906               Evas_Object *c = marker->clas->func.get(marker->wd->obj,
907                                                       marker, marker->data);
908               if (c) contents = eina_list_append(contents, c);
909            }
910          _bubble_update(group->bubble, contents);
911       }
912 }
913
914 static void
915 _marker_group_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
916 {
917    EINA_SAFETY_ON_NULL_RETURN(data);
918    Marker_Group *group = data;
919    Eina_List *l;
920    Elm_Map_Marker *marker;
921    Eina_List *contents = NULL;
922
923    if (!group->bubble) group->bubble = _bubble_create(group->obj, group->wd);
924
925    EINA_LIST_FOREACH(group->markers, l, marker)
926      {
927         if (group->wd->markers_max_num <= eina_list_count(contents)) break;
928         Evas_Object *c = marker->clas->func.get(marker->wd->obj,
929                                                 marker, marker->data);
930         if (c) contents = eina_list_append(contents, c);
931      }
932    _bubble_update(group->bubble, contents);
933    _bubble_place(group->bubble);
934 }
935
936 static void
937 _marker_group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
938 {
939    EINA_SAFETY_ON_NULL_RETURN(data);
940
941    double lon, lat;
942    Marker_Group *group = data;
943    _coord_to_region_convert(group->wd, group->x, group->y, group->wd->size.w,
944                          &lon, &lat);
945    elm_map_region_bring_in(group->wd->obj, lon, lat);
946 }
947
948 static void
949 _marker_group_free(Marker_Group* group)
950 {
951    EINA_SAFETY_ON_NULL_RETURN(group);
952
953    if (group->bubble) _bubble_free(group->bubble);
954
955    eina_list_free(group->markers);
956    evas_object_del(group->obj);
957
958    free(group);
959 }
960
961 static Marker_Group*
962 _marker_group_create(Widget_Data *wd)
963 {
964    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
965
966    Marker_Group *group = ELM_NEW(Marker_Group);
967
968    group->wd = wd;
969    group->obj = elm_layout_add(wd->obj);
970    evas_object_smart_member_add(group->obj, wd->pan_smart);
971    evas_object_stack_above(group->obj, wd->sep_maps_markers);
972    elm_layout_theme_set(group->obj, "map/marker", "radio",
973                         elm_widget_style_get(wd->obj));
974    edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
975                                    "open", "elm", _marker_group_bubble_open_cb,
976                                    group);
977    edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
978                                    "bringin", "elm", _marker_group_bringin_cb,
979                                    group);
980    return group;
981 }
982
983 static void
984 _marker_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
985 {
986    Elm_Map_Marker *marker = data;
987    EINA_SAFETY_ON_NULL_RETURN(marker);
988    elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
989 }
990
991 static void
992 _marker_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
993 {
994    EINA_SAFETY_ON_NULL_RETURN(data);
995    Elm_Map_Marker *marker = data;
996
997    if (!marker->bubble) marker->bubble = _bubble_create(marker->obj, marker->wd);
998    evas_object_smart_changed(marker->wd->pan_smart);
999 }
1000
1001 static void
1002 _marker_update(Elm_Map_Marker *marker)
1003 {
1004    EINA_SAFETY_ON_NULL_RETURN(marker);
1005    Elm_Map_Marker_Class *clas = marker->clas;
1006    EINA_SAFETY_ON_NULL_RETURN(clas);
1007
1008    if (clas->style) elm_layout_theme_set(marker->obj, "map/marker", clas->style,
1009                                          elm_widget_style_get(marker->wd->obj));
1010    else elm_layout_theme_set(marker->obj, "map/marker", "radio",
1011                              elm_widget_style_get(marker->wd->obj));
1012
1013    if (clas->func.icon_get)
1014      {
1015         Evas_Object *icon = NULL;
1016
1017         icon = elm_object_part_content_get(marker->obj, "elm.icon");
1018         if (icon) evas_object_del(icon);
1019
1020         icon = clas->func.icon_get(marker->wd->obj, marker, marker->data);
1021         elm_object_part_content_set(marker->obj, "elm.icon", icon);
1022      }
1023    _geo_to_coord_convert(marker->wd, marker->longitude, marker->latitude,
1024                          marker->wd->size.w, &(marker->x), &(marker->y));
1025
1026     if (marker->bubble)
1027       {
1028          if (marker->content) evas_object_del(marker->content);
1029          if (marker->clas->func.get)
1030             marker->content = marker->clas->func.get(marker->wd->obj, marker,
1031                                                      marker->data);
1032         if (marker->content)
1033           {
1034              Eina_List *contents = NULL;
1035              contents = eina_list_append(contents, marker->content);
1036              _bubble_update(marker->bubble, contents);
1037           }
1038       }
1039 }
1040
1041
1042
1043 static void
1044 _marker_place(Widget_Data *wd)
1045 {
1046    EINA_SAFETY_ON_NULL_RETURN(wd);
1047
1048    Eina_List *l;
1049
1050    Elm_Map_Marker *marker;
1051    Elm_Map_Group_Class *group_clas;
1052
1053    Evas_Coord gw, gh;
1054    Evas_Coord px, py;
1055
1056    if (wd->paused_markers || (!eina_list_count(wd->markers))) return;
1057
1058    _pan_geometry_get(wd, &px, &py);
1059
1060    _edj_marker_size_get(wd, &gw, &gh);
1061    gw *= 2;
1062    gh *= 2;
1063
1064    EINA_LIST_FOREACH(wd->markers, l, marker)
1065      {
1066         _marker_update(marker);
1067         marker->grouped = EINA_FALSE;
1068         marker->leader = EINA_FALSE;
1069      }
1070
1071    EINA_LIST_FOREACH(wd->group_classes, l, group_clas)
1072      {
1073         Eina_List *ll;
1074         EINA_LIST_FOREACH(group_clas->markers, ll, marker)
1075           {
1076              Eina_List *lll;
1077              Elm_Map_Marker *mm;
1078              Eina_List *markers = NULL;
1079
1080              if (marker->grouped) continue;
1081              if (group_clas->zoom_grouped < wd->zoom)
1082                {
1083                   marker->grouped = EINA_FALSE;
1084                   continue;
1085                }
1086
1087              EINA_LIST_FOREACH(group_clas->markers, lll, mm)
1088                {
1089                   if (marker == mm || mm->grouped) continue;
1090                   if (ELM_RECTS_INTERSECT(mm->x, mm->y, mm->w, mm->h,
1091                                           marker->x, marker->y, gw, gh))
1092                     {
1093                        // mm is group follower.
1094                        mm->leader = EINA_FALSE;
1095                        mm->grouped = EINA_TRUE;
1096                        markers = eina_list_append(markers, mm);
1097                     }
1098                }
1099               if (eina_list_count(markers) >= 1)
1100                 {
1101                    // marker is group leader.
1102                    marker->leader = EINA_TRUE;
1103                    marker->grouped = EINA_TRUE;
1104                    markers = eina_list_append(markers, marker);
1105
1106                    if (!marker->group) marker->group = _marker_group_create(wd);
1107                    _marker_group_update(marker->group, group_clas, markers);
1108                 }
1109           }
1110      }
1111
1112    EINA_LIST_FOREACH(wd->markers, l, marker)
1113      {
1114
1115         if (marker->grouped ||
1116            (marker->group_clas &&
1117             (marker->group_clas->hide ||
1118              marker->group_clas->zoom_displayed > wd->zoom)))
1119            evas_object_hide(marker->obj);
1120         else
1121           {
1122              Evas_Coord x, y;
1123              _coord_rotate(marker->x + px, marker->y + py, wd->rotate.cx,
1124                            wd->rotate.cy, wd->rotate.d, &x, &y);
1125              _obj_place(marker->obj, x - (marker->w / 2), y - (marker->h / 2),
1126                          marker->w, marker->h);
1127           }
1128      }
1129
1130    EINA_LIST_FOREACH(wd->markers, l, marker)
1131      {
1132         Marker_Group *group = marker->group;
1133         if (!group) continue;
1134
1135         if (!marker->leader || (group->clas->hide) ||
1136             (group->clas->zoom_displayed > wd->zoom))
1137            evas_object_hide(group->obj);
1138         else
1139           {
1140              Evas_Coord x, y;
1141              _coord_rotate(group->x + px, group->y + py, wd->rotate.cx,
1142                            wd->rotate.cy, wd->rotate.d, &x, &y);
1143              _obj_place(group->obj, x - (group->w / 2), y - (group->h / 2),
1144                          group->w, group->h);
1145           }
1146      }
1147 }
1148
1149 static void
1150 _grid_item_coord_get(Grid_Item *gi, int *x, int *y, int *w, int *h)
1151 {
1152    EINA_SAFETY_ON_NULL_RETURN(gi);
1153
1154    if (x) *x = gi->x * gi->wd->size.tile;
1155    if (y) *y = gi->y * gi->wd->size.tile;
1156    if (w) *w = gi->wd->size.tile;
1157    if (h) *h = gi->wd->size.tile;
1158 }
1159
1160 static Eina_Bool
1161 _grid_item_intersect(Grid_Item *gi)
1162 {
1163    EINA_SAFETY_ON_NULL_RETURN_VAL(gi, EINA_FALSE);
1164
1165    Evas_Coord px, py;
1166    Evas_Coord vw, vh;
1167    Evas_Coord x, y, w, h;
1168
1169    _pan_geometry_get(gi->wd, &px, &py);
1170    _viewport_size_get(gi->wd, &vw, &vh);
1171    _grid_item_coord_get(gi, &x, &y, &w, &h);
1172    return ELM_RECTS_INTERSECT(x + px, y + py, w, h, 0, 0, vw, vh);
1173 }
1174
1175 static void
1176 _grid_item_update(Grid_Item *gi)
1177 {
1178    evas_object_image_file_set(gi->img, gi->file, NULL);
1179    if (!gi->wd->zoom_timer && !gi->wd->scr_timer)
1180       evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
1181    else evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
1182
1183    Evas_Load_Error err = evas_object_image_load_error_get(gi->img);
1184    if (err != EVAS_LOAD_ERROR_NONE)
1185      {
1186         ERR("Image loading error (%s): %s", gi->file, evas_load_error_str(err));
1187         ecore_file_remove(gi->file);
1188         gi->file_have = EINA_FALSE;
1189      }
1190    else
1191      {
1192         Evas_Coord px, py;
1193         Evas_Coord x, y, w, h;
1194
1195         _pan_geometry_get(gi->wd, &px, &py);
1196         _grid_item_coord_get(gi, &x, &y, &w, &h);
1197
1198         _obj_place(gi->img, x + px, y + py, w, h);
1199         _obj_rotate(gi->wd, gi->img);
1200         gi->file_have = EINA_TRUE;
1201      }
1202 }
1203
1204 static void
1205 _grid_item_load(Grid_Item *gi)
1206 {
1207    EINA_SAFETY_ON_NULL_RETURN(gi);
1208    if (gi->file_have) _grid_item_update(gi);
1209    else if (!gi->job)
1210      {
1211         gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
1212         gi->wd->download_list = eina_list_append(gi->wd->download_list, gi);
1213      }
1214 }
1215
1216 static void
1217 _grid_item_unload(Grid_Item *gi)
1218 {
1219    EINA_SAFETY_ON_NULL_RETURN(gi);
1220    if (gi->file_have)
1221      {
1222         evas_object_hide(gi->img);
1223         evas_object_image_file_set(gi->img, NULL, NULL);
1224      }
1225    else if (gi->job)
1226      {
1227         ecore_file_download_abort(gi->job);
1228         ecore_file_remove(gi->file);
1229         gi->job = NULL;
1230         gi->wd->try_num--;
1231      }
1232    else gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
1233
1234 }
1235
1236 static Grid_Item *
1237 _grid_item_create(Grid *g, Evas_Coord x, Evas_Coord y)
1238 {
1239    EINA_SAFETY_ON_NULL_RETURN_VAL(g, NULL);
1240    char buf[PATH_MAX];
1241    char buf2[PATH_MAX];
1242    char *url;
1243    Grid_Item *gi;
1244
1245    gi = ELM_NEW(Grid_Item);
1246    gi->wd = g->wd;
1247    gi->g = g;
1248    gi->x = x;
1249    gi->y = y;
1250
1251    gi->file_have = EINA_FALSE;
1252    gi->job = NULL;
1253
1254    gi->img = evas_object_image_add(evas_object_evas_get(g->wd->obj));
1255    evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
1256    evas_object_image_scale_hint_set(gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1257    evas_object_image_filled_set(gi->img, 1);
1258    evas_object_smart_member_add(gi->img, g->wd->pan_smart);
1259    evas_object_pass_events_set(gi->img, EINA_TRUE);
1260    evas_object_stack_below(gi->img, g->wd->sep_maps_markers);
1261
1262    snprintf(buf, sizeof(buf), CACHE_TILE_ROOT, g->wd->id, g->zoom, x);
1263    snprintf(buf2, sizeof(buf2), CACHE_TILE_PATH, buf, y);
1264    if (!ecore_file_exists(buf)) ecore_file_mkpath(buf);
1265
1266    eina_stringshare_replace(&gi->file, buf2);
1267    url = g->wd->src_tile->url_cb(g->wd->obj, x, y, g->zoom);
1268    if ((!url) || (!strlen(url)))
1269      {
1270         eina_stringshare_replace(&gi->url, NULL);
1271         ERR("Getting source url failed: %s", gi->file);
1272      }
1273    else eina_stringshare_replace(&gi->url, url);
1274    if (url) free(url);
1275    eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1276    return gi;
1277 }
1278
1279 static void
1280 _grid_item_free(Grid_Item *gi)
1281 {
1282    EINA_SAFETY_ON_NULL_RETURN(gi);
1283    _grid_item_unload(gi);
1284    if (gi->g && gi->g->grid) eina_matrixsparse_data_idx_set(gi->g->grid,
1285                                                             gi->y, gi->x, NULL);
1286    if (gi->url) eina_stringshare_del(gi->url);
1287    if (gi->file) eina_stringshare_del(gi->file);
1288    if (gi->img) evas_object_del(gi->img);
1289    if (gi->file_have) ecore_file_remove(gi->file);
1290    free(gi);
1291 }
1292
1293 static void
1294 _downloaded_cb(void *data, const char *file __UNUSED__, int status)
1295 {
1296    Grid_Item *gi = data;
1297
1298    if (status == 200)
1299      {
1300         DBG("Download success from %s to %s", gi->url, gi->file);
1301         _grid_item_update(gi);
1302         gi->wd->finish_num++;
1303         evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED, NULL);
1304      }
1305    else
1306      {
1307         WRN("Download failed from %s to %s (%d) ", gi->url, gi->file, status);
1308         ecore_file_remove(gi->file);
1309         gi->file_have = EINA_FALSE;
1310         evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED_FAIL, NULL);
1311      }
1312
1313    gi->job = NULL;
1314    gi->wd->download_num--;
1315    if (!gi->wd->download_num)
1316       edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
1317                               "elm,state,busy,stop", "elm");
1318 }
1319
1320 static Eina_Bool
1321 _download_job(void *data)
1322 {
1323    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1324    Widget_Data *wd = data;
1325
1326    Eina_List *l, *ll;
1327    Grid_Item *gi;
1328
1329    if (!eina_list_count(wd->download_list))
1330      {
1331         wd->download_idler = NULL;
1332         return ECORE_CALLBACK_CANCEL;
1333      }
1334
1335    EINA_LIST_REVERSE_FOREACH_SAFE(wd->download_list, l, ll, gi)
1336      {
1337         if (gi->g->zoom != wd->zoom || !_grid_item_intersect(gi))
1338           {
1339              wd->download_list = eina_list_remove(wd->download_list, gi);
1340              continue;
1341           }
1342         if (wd->download_num >= MAX_CONCURRENT_DOWNLOAD)
1343            return ECORE_CALLBACK_RENEW;
1344
1345         Eina_Bool ret = ecore_file_download_full(gi->url, gi->file,
1346                                                  _downloaded_cb, NULL,
1347                                                  gi, &(gi->job), wd->ua);
1348         if ((!ret) || (!gi->job))
1349            ERR("Can't start to download from %s to %s", gi->url, gi->file);
1350         else
1351           {
1352              wd->download_list = eina_list_remove(wd->download_list, gi);
1353              wd->try_num++;
1354              wd->download_num++;
1355              evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOAD,
1356                                              NULL);
1357              if (wd->download_num == 1)
1358                 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1359                                         "elm,state,busy,start", "elm");
1360
1361           }
1362      }
1363    return ECORE_CALLBACK_RENEW;
1364 }
1365
1366 static void
1367 _grid_viewport_get(Grid *g, int *x, int *y, int *w, int *h)
1368 {
1369    EINA_SAFETY_ON_NULL_RETURN(g);
1370    int xx, yy, ww, hh;
1371    Evas_Coord px, py, vw, vh;
1372
1373    _pan_geometry_get(g->wd, &px, &py);
1374    _viewport_size_get(g->wd, &vw, &vh);
1375    if (px > 0) px = 0;
1376    if (py > 0) py = 0;
1377
1378    xx = (-px / g->wd->size.tile) - 1;
1379    if (xx < 0) xx = 0;
1380
1381    yy = (-py / g->wd->size.tile) - 1;
1382    if (yy < 0) yy = 0;
1383
1384    ww = (vw / g->wd->size.tile) + 3;
1385    if (xx + ww >= g->tw) ww = g->tw - xx;
1386
1387    hh = (vh / g->wd->size.tile) + 3;
1388    if (yy + hh >= g->th) hh = g->th - yy;
1389
1390    if (x) *x = xx;
1391    if (y) *y = yy;
1392    if (w) *w = ww;
1393    if (h) *h = hh;
1394 }
1395
1396 static void
1397 _grid_unload(Grid *g)
1398 {
1399    EINA_SAFETY_ON_NULL_RETURN(g);
1400    Eina_Iterator *it;
1401    Eina_Matrixsparse_Cell *cell;
1402    Grid_Item *gi;
1403
1404    it = eina_matrixsparse_iterator_new(g->grid);
1405    EINA_ITERATOR_FOREACH(it, cell)
1406      {
1407         gi = eina_matrixsparse_cell_data_get(cell);
1408         _grid_item_unload(gi);
1409      }
1410    eina_iterator_free(it);
1411 }
1412
1413 static void
1414 _grid_load(Grid *g)
1415 {
1416    EINA_SAFETY_ON_NULL_RETURN(g);
1417    int x, y, xx, yy, ww, hh;
1418    Eina_Iterator *it;
1419    Eina_Matrixsparse_Cell *cell;
1420    Grid_Item *gi;
1421
1422    it = eina_matrixsparse_iterator_new(g->grid);
1423    EINA_ITERATOR_FOREACH(it, cell)
1424      {
1425         gi = eina_matrixsparse_cell_data_get(cell);
1426         if (!_grid_item_intersect(gi)) _grid_item_unload(gi);
1427      }
1428    eina_iterator_free(it);
1429
1430    _grid_viewport_get(g, &xx, &yy, &ww, &hh);
1431    for (y = yy; y < yy + hh; y++)
1432      {
1433         for (x = xx; x < xx + ww; x++)
1434           {
1435              gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1436              if (!gi) gi = _grid_item_create(g, x, y);
1437              _grid_item_load(gi);
1438           }
1439      }
1440 }
1441
1442 static void
1443 _grid_place(Widget_Data *wd)
1444 {
1445    EINA_SAFETY_ON_NULL_RETURN(wd);
1446    Eina_List *l;
1447    Grid *g;
1448
1449    EINA_LIST_FOREACH(wd->grids, l, g)
1450      {
1451         if (wd->zoom == g->zoom) _grid_load(g);
1452         else _grid_unload(g);
1453      }
1454   if (!wd->download_idler) wd->download_idler = ecore_idler_add(_download_job, wd);
1455 }
1456
1457 static void
1458 _grid_all_create(Widget_Data *wd)
1459 {
1460    EINA_SAFETY_ON_NULL_RETURN(wd);
1461    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
1462
1463    int zoom;
1464    for (zoom = wd->src_tile->zoom_min; zoom <= wd->src_tile->zoom_max; zoom++)
1465      {
1466         Grid *g;
1467         int tnum;
1468         g = ELM_NEW(Grid);
1469         g->wd = wd;
1470         g->zoom = zoom;
1471         tnum =  pow(2.0, g->zoom);
1472         g->tw = tnum;
1473         g->th = tnum;
1474         g->grid = eina_matrixsparse_new(g->th, g->tw, NULL, NULL);
1475         wd->grids = eina_list_append(wd->grids, g);
1476      }
1477 }
1478
1479 static void
1480 _grid_all_clear(Widget_Data *wd)
1481 {
1482    EINA_SAFETY_ON_NULL_RETURN(wd);
1483
1484    Grid *g;
1485    EINA_LIST_FREE(wd->grids, g)
1486      {
1487         Eina_Matrixsparse_Cell *cell;
1488         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1489         EINA_ITERATOR_FOREACH(it, cell)
1490           {
1491              Grid_Item *gi;
1492              gi = eina_matrixsparse_cell_data_get(cell);
1493              if (gi) _grid_item_free(gi);
1494           }
1495         eina_iterator_free(it);
1496
1497         eina_matrixsparse_free(g->grid);
1498         free(g);
1499      }
1500 }
1501
1502 static void
1503 _track_place(Widget_Data *wd)
1504 {
1505 #ifdef ELM_EMAP
1506    EINA_SAFETY_ON_NULL_RETURN(wd);
1507
1508    Eina_List *l;
1509    Evas_Object *route;
1510    int xmin, xmax, ymin, ymax;
1511    Evas_Coord px, py, ow, oh;
1512    px = wd->pan_x;
1513    py = wd->pan_y;
1514    _viewport_size_get(wd, &ow, &oh);
1515
1516    Evas_Coord size = wd->size.w;
1517
1518    EINA_LIST_FOREACH(wd->track, l, route)
1519      {
1520         double lon_min, lon_max;
1521         double lat_min, lat_max;
1522         elm_route_longitude_min_max_get(route, &lon_min, &lon_max);
1523         elm_route_latitude_min_max_get(route, &lat_min, &lat_max);
1524         _geo_to_coord_convert(wd, lon_min, lat_max, size, &xmin, &ymin);
1525         _geo_to_coord_convert(wd, lon_max, lat_min, size, &xmax, &ymax);
1526
1527         if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
1528         {
1529            if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
1530            {
1531               //display the route
1532               evas_object_move(route, xmin - px, ymin - py);
1533               evas_object_resize(route, xmax - xmin, ymax - ymin);
1534
1535               evas_object_raise(route);
1536               _obj_rotate(wd, route);
1537               evas_object_show(route);
1538
1539               continue;
1540            }
1541         }
1542         //the route is not display
1543         evas_object_hide(route);
1544      }
1545 #else
1546    (void) wd;
1547 #endif
1548 }
1549
1550 static void
1551 _delayed_do(Widget_Data *wd)
1552 {
1553    Delayed_Data *dd;
1554    dd = eina_list_nth(wd->delayed_jobs, 0);
1555    if (dd && !dd->wd->zoom_animator)
1556      {
1557         dd->func(dd);
1558         wd->delayed_jobs = eina_list_remove(wd->delayed_jobs, dd);
1559         free(dd);
1560      }
1561 }
1562
1563 static void
1564 _smooth_update(Widget_Data *wd)
1565 {
1566    EINA_SAFETY_ON_NULL_RETURN(wd);
1567    Eina_List *l;
1568    Grid *g;
1569
1570    EINA_LIST_FOREACH(wd->grids, l, g)
1571      {
1572         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1573         Eina_Matrixsparse_Cell *cell;
1574
1575         EINA_ITERATOR_FOREACH(it, cell)
1576           {
1577              Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1578              if (_grid_item_intersect(gi))
1579                 evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
1580           }
1581         eina_iterator_free(it);
1582      }
1583 }
1584
1585 static Eina_Bool
1586 _zoom_timeout(void *data)
1587 {
1588    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1589    Widget_Data *wd = data;
1590    _smooth_update(wd);
1591    wd->zoom_timer = NULL;
1592    evas_object_smart_callback_call(wd->obj, SIG_ZOOM_STOP, NULL);
1593   return ECORE_CALLBACK_CANCEL;
1594 }
1595
1596 static void
1597 zoom_do(Widget_Data *wd, double zoom)
1598 {
1599    EINA_SAFETY_ON_NULL_RETURN(wd);
1600    if (zoom > wd->zoom_max) zoom = wd->zoom_max;
1601    else if (zoom < wd->zoom_min) zoom = wd->zoom_min;
1602
1603    Evas_Coord px, py, vw, vh;
1604    Evas_Coord ow, oh;
1605
1606    wd->zoom = ROUND(zoom);
1607    wd->zoom_detail = zoom;
1608    ow = wd->size.w;
1609    oh = wd->size.h;
1610    wd->size.tile = pow(2.0, (zoom - wd->zoom)) * wd->tsize;
1611    wd->size.w = pow(2.0, wd->zoom) * wd->size.tile;
1612    wd->size.h = wd->size.w;;
1613
1614    // Fix to zooming with (viewport center px, py) as the center to prevent
1615    // from zooming with (0,0) as the cetner. (scroller default behavior)
1616    _pan_geometry_get(wd, &px, &py);
1617    _viewport_size_get(wd, &vw, &vh);
1618    if ((vw > 0) && (vh > 0) && (ow > 0) && (oh > 0))
1619      {
1620         Evas_Coord xx, yy;
1621         double sx, sy;
1622         if (vw > ow) sx = 0.5;
1623         else         sx = (double)(-px + (vw / 2)) / ow;
1624         if (vh > oh) sy = 0.5;
1625         else         sy = (double)(-py + (vh / 2)) / oh;
1626
1627         if (sx > 1.0) sx = 1.0;
1628         if (sy > 1.0) sy = 1.0;
1629
1630         xx = (sx * wd->size.w) - (vw / 2);
1631         yy = (sy * wd->size.h) - (vh / 2);
1632         if (xx < 0) xx = 0;
1633         else if (xx > (wd->size.w - vw)) xx = wd->size.w - vw;
1634         if (yy < 0) yy = 0;
1635         else if (yy > (wd->size.h - vh)) yy = wd->size.h - vh;
1636         elm_smart_scroller_child_region_show(wd->scr, xx, yy, vw, vh);
1637      }
1638    if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1639    else evas_object_smart_callback_call(wd->obj, SIG_ZOOM_START, NULL);
1640    wd->zoom_timer = ecore_timer_add(0.25, _zoom_timeout, wd);
1641    evas_object_smart_callback_call(wd->obj, SIG_ZOOM_CHANGE, NULL);
1642
1643    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1644    evas_object_smart_changed(wd->pan_smart);
1645 }
1646
1647 static Eina_Bool
1648 _zoom_anim(void *data)
1649 {
1650    Widget_Data *wd = data;
1651    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ECORE_CALLBACK_CANCEL);
1652
1653    if (wd->ani.cnt <= 0)
1654      {
1655         wd->zoom_animator = NULL;
1656         evas_object_smart_changed(wd->pan_smart);
1657         return ECORE_CALLBACK_CANCEL;
1658      }
1659    else
1660      {
1661         wd->ani.zoom += wd->ani.diff;
1662         wd->ani.cnt--;
1663         zoom_do(wd, wd->ani.zoom);
1664         return ECORE_CALLBACK_RENEW;
1665      }
1666 }
1667
1668 static void
1669 zoom_with_animation(Widget_Data *wd, double zoom, int cnt)
1670 {
1671    EINA_SAFETY_ON_NULL_RETURN(wd);
1672    if (cnt == 0) return;
1673
1674    wd->ani.cnt = cnt;
1675    wd->ani.zoom = wd->zoom;
1676    wd->ani.diff = (double)(zoom - wd->zoom) / cnt;
1677    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
1678    wd->zoom_animator = ecore_animator_add(_zoom_anim, wd);
1679 }
1680
1681 static void
1682 _sizing_eval(Widget_Data *wd)
1683 {
1684    EINA_SAFETY_ON_NULL_RETURN(wd);
1685
1686    Evas_Coord maxw = -1, maxh = -1;
1687
1688    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
1689    evas_object_size_hint_max_set(wd->obj, maxw, maxh);
1690 }
1691
1692 static void
1693 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1694 {
1695    _sizing_eval(data);
1696 }
1697
1698 static Eina_Bool
1699 _scr_timeout(void *data)
1700 {
1701    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1702    Widget_Data *wd = data;
1703    _smooth_update(wd);
1704    wd->scr_timer = NULL;
1705    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_STOP, NULL);
1706    return ECORE_CALLBACK_CANCEL;
1707 }
1708
1709 static void
1710 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1711 {
1712    EINA_SAFETY_ON_NULL_RETURN(data);
1713    Widget_Data *wd = data;
1714
1715    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1716    else evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_START, NULL);
1717    wd->scr_timer = ecore_timer_add(0.25, _scr_timeout, wd);
1718    evas_object_smart_callback_call(wd->obj, SIG_SCROLL, NULL);
1719 }
1720
1721 static void
1722 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1723 {
1724    EINA_SAFETY_ON_NULL_RETURN(data);
1725    Widget_Data *wd = data;
1726    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_START, NULL);
1727 }
1728
1729 static void
1730 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1731 {
1732    EINA_SAFETY_ON_NULL_RETURN(data);
1733    Widget_Data *wd = data;
1734    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_STOP, NULL);
1735 }
1736
1737 static Eina_Bool
1738 _long_press(void *data)
1739 {
1740    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
1741    Widget_Data *wd = data;
1742
1743    wd->long_timer = NULL;
1744    evas_object_smart_callback_call(wd->obj, SIG_LONGPRESSED, &wd->ev);
1745    return ECORE_CALLBACK_CANCEL;
1746 }
1747
1748 static void
1749 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1750 {
1751    EINA_SAFETY_ON_NULL_RETURN(data);
1752    Widget_Data *wd = data;
1753    Evas_Event_Mouse_Down *ev = event_info;
1754
1755    if (ev->button != 1) return;
1756
1757    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1758    else wd->on_hold = EINA_FALSE;
1759
1760    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1761      evas_object_smart_callback_call(wd->obj, SIG_CLICKED_DOUBLE, ev);
1762    else evas_object_smart_callback_call(wd->obj, SIG_PRESS, ev);
1763
1764    if (wd->long_timer) ecore_timer_del(wd->long_timer);
1765    wd->ev = *ev;
1766    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, wd);
1767 }
1768
1769 static void
1770 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1771 {
1772    EINA_SAFETY_ON_NULL_RETURN(data);
1773    Widget_Data *wd = data;
1774
1775    Evas_Event_Mouse_Up *ev = event_info;
1776    EINA_SAFETY_ON_NULL_RETURN(ev);
1777
1778    if (ev->button != 1) return;
1779    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1780    else wd->on_hold = EINA_FALSE;
1781    if (wd->long_timer)
1782      {
1783         ecore_timer_del(wd->long_timer);
1784         wd->long_timer = NULL;
1785      }
1786    if (!wd->on_hold) evas_object_smart_callback_call(wd->obj, SIG_CLICKED, ev);
1787    wd->on_hold = EINA_FALSE;
1788 }
1789
1790 static void
1791 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1792 {
1793    EINA_SAFETY_ON_NULL_RETURN(data);
1794    Widget_Data *wd = data;
1795
1796    if (!wd->paused)
1797      {
1798         Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1799         zoom_do(wd, wd->zoom_detail - ((double)ev->z / 10));
1800     }
1801 }
1802
1803 static void
1804 _region_max_min_get(Eina_List *overlays, double *max_longitude, double *min_longitude, double *max_latitude, double *min_latitude)
1805 {
1806    double max_lon = -180, min_lon = 180;
1807    double max_lat = -90, min_lat = 90;
1808    Elm_Map_Overlay *overlay;
1809    EINA_LIST_FREE(overlays, overlay)
1810      {
1811         double lon, lat;
1812         if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
1813           {
1814              Overlay_Default *ovl = overlay->ovl;
1815              lon = ovl->lon;
1816              lat = ovl->lat;
1817           }
1818         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
1819           {
1820              // FIXME: class center coord is alright??
1821              Overlay_Class *ovl = overlay->ovl;
1822              double max_lo, min_lo, max_la, min_la;
1823              _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la,
1824                                  &min_la);
1825              lon = (max_lo + min_lo) / 2;
1826              lat = (max_la + min_la) / 2;
1827           }
1828         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
1829           {
1830              Overlay_Bubble *ovl = overlay->ovl;
1831              lon = ovl->lon;
1832              lat = ovl->lat;
1833           }
1834         else
1835           {
1836              WRN("Not supported overlay type: %d", overlay->type);
1837              continue;
1838           }
1839         if (lon> max_lon) max_lon = lon;
1840         if (lon< min_lon) min_lon = lon;
1841         if (lat > max_lat) max_lat = lat;
1842         if (lat < min_lat) min_lat = lat;
1843      }
1844    if (max_longitude) *max_longitude = max_lon;
1845    if (min_longitude) *min_longitude = min_lon;
1846    if (max_latitude) *max_latitude = max_lat;
1847    if (min_latitude) *min_latitude = min_lat;
1848 }
1849
1850 static Evas_Object *
1851 _icon_dup(Evas_Object *icon, Evas_Object *parent)
1852 {
1853    if (!icon || !parent) return NULL;
1854    // Evas_Object do not support object duplication??
1855    const char *file = NULL, *group = NULL;
1856    Eina_Bool size_up, size_down;
1857    Evas_Object *dupp;
1858    
1859    dupp = elm_icon_add(parent);
1860    elm_icon_file_get(icon, &file, &group);
1861    elm_icon_file_set(dupp, file, group);
1862    elm_icon_animated_set(dupp, elm_icon_animated_get(icon));
1863    elm_icon_animated_play_set(dupp, elm_icon_animated_play_get(icon));
1864    elm_icon_standard_set(dupp, elm_icon_standard_get(icon));
1865    elm_icon_order_lookup_set(dupp, elm_icon_order_lookup_get(icon));
1866    elm_icon_no_scale_set(dupp, elm_icon_no_scale_get(icon));
1867    elm_icon_resizable_get(icon, &size_up, &size_down);
1868    elm_icon_resizable_set(dupp, size_up, size_down);
1869    elm_icon_fill_outside_set(dupp, elm_icon_fill_outside_get(icon));
1870    elm_icon_prescale_set(dupp, elm_icon_prescale_get(icon));
1871    elm_icon_aspect_fixed_set(dupp, elm_icon_aspect_fixed_get(icon));
1872    return dupp;
1873 }
1874
1875 static Evas_Object *
1876 _overlay_layout_new(Widget_Data *wd, const char *group)
1877 {
1878    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
1879    EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
1880    Evas_Object *obj = elm_layout_add(wd->obj);
1881    evas_object_smart_member_add(obj, wd->pan_smart);
1882    evas_object_stack_above(obj, wd->sep_maps_markers);
1883    elm_layout_theme_set(obj, "map/marker", group,  elm_widget_style_get(wd->obj));
1884    return obj;
1885 }
1886
1887 static void
1888 _overlay_layout_update(Widget_Data *wd, Evas_Object *layout, Evas_Object *icon, const char *text, const char *group)
1889 {
1890    EINA_SAFETY_ON_NULL_RETURN(wd);
1891    EINA_SAFETY_ON_NULL_RETURN(layout);
1892
1893    Evas_Object *prev_icon = elm_object_part_content_get(layout, "elm.icon");
1894    if (icon && (prev_icon != icon))
1895      {
1896         elm_layout_theme_set(layout, "map/marker", "empty",
1897                              elm_widget_style_get(wd->obj));
1898         elm_object_part_content_set(layout, "elm.icon", icon);
1899      }
1900    else if (text)
1901      {
1902         if (group) elm_layout_theme_set(layout, "map/marker", group,
1903                                         elm_widget_style_get(wd->obj));
1904         edje_object_part_text_set(elm_layout_edje_get(layout), "elm.text", text);
1905      }
1906 }
1907
1908 static void
1909 _overlay_clicked_cb(void *data, Evas *e __UNUSED__,  Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
1910 {
1911    EINA_SAFETY_ON_NULL_RETURN(data);
1912    Elm_Map_Overlay *overlay = data;
1913
1914    evas_object_smart_callback_call(overlay->wd->obj, SIG_OVERLAY_CLICKED,
1915                                    overlay);
1916    if (overlay->cb) overlay->cb(overlay->cb_data, overlay->wd->obj,
1917                                 overlay);
1918 }
1919
1920 static void
1921 _overlay_default_cb_add(Overlay_Default *ovl, Evas_Object_Event_Cb cb, void *data)
1922 {
1923    EINA_SAFETY_ON_NULL_RETURN(ovl);
1924    EINA_SAFETY_ON_NULL_RETURN(data);
1925
1926    // FIXME: Add icon or object event callback
1927    evas_object_event_callback_add(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb,
1928                                   data);
1929 }
1930
1931 static void
1932 _overlay_default_cb_del(Overlay_Default *ovl, Evas_Object_Event_Cb cb)
1933 {
1934    EINA_SAFETY_ON_NULL_RETURN(ovl);
1935    // FIXME: Add icon or object event callback
1936    evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb);
1937 }
1938
1939 static void
1940 _overlay_default_hide(Overlay_Default *ovl)
1941 {
1942    EINA_SAFETY_ON_NULL_RETURN(ovl);
1943    if (ovl->obj) evas_object_hide(ovl->obj);
1944    if (ovl->layout) evas_object_hide(ovl->layout);
1945 }
1946
1947 static void
1948 _overlay_default_show(Widget_Data *wd, Overlay_Default *ovl)
1949 {
1950    Evas_Object *disp;
1951    Evas_Coord px, py;
1952    Evas_Coord x, y, w, h;
1953
1954    if (ovl->obj)
1955      {
1956         disp = ovl->obj;
1957         evas_object_geometry_get(disp, NULL, NULL, &w, &h);
1958         if (w <= 0 || h <= 0) evas_object_size_hint_min_get(disp, &w, &h);
1959      }
1960    else
1961      {
1962         disp = ovl->layout;
1963         w = ovl->w;
1964         h = ovl->h;
1965      }
1966
1967    _pan_geometry_get(wd, &px, &py);
1968    _coord_rotate(ovl->x + px, ovl->y + py, wd->rotate.cx,  wd->rotate.cy,
1969                  wd->rotate.d, &x, &y);
1970    _obj_place(disp, x - (w / 2), y - (h / 2), w, h);
1971 }
1972
1973 static void
1974 _overlay_default_update(Widget_Data *wd, Overlay_Default *ovl, Evas_Object *obj, Evas_Object *icon, Overlay_Class *ovl_clas, const char *text, const char *group)
1975 {
1976    EINA_SAFETY_ON_NULL_RETURN(wd);
1977    EINA_SAFETY_ON_NULL_RETURN(ovl);
1978
1979    _geo_to_coord_convert(wd, ovl->lon, ovl->lat, wd->size.w, &ovl->x, &ovl->y);
1980
1981    if (obj)
1982      {
1983         if (ovl->obj == obj) return;
1984         if (ovl->obj) evas_object_del(ovl->obj);
1985         ovl->obj = obj;
1986      }
1987    else if (!(ovl->obj) && icon)
1988      {
1989         if (ovl->icon == icon) return;
1990         if (ovl->icon) evas_object_del(ovl->icon);
1991         ovl->icon = icon;
1992        _overlay_layout_update(wd, ovl->layout, ovl->icon, NULL, NULL);
1993
1994      }
1995    else if (!(ovl->obj) && !(ovl->icon) && (ovl_clas) &&
1996             ((ovl_clas->obj) || (ovl_clas->icon)))
1997      {
1998         // Inherit icon from group overlay's ojbect or icon
1999
2000         // FIXME: It is hard to duplicate evas object :-)
2001         /*
2002         if (ovl_clas->obj && (ovl_clas->obj != ovl->clas_obj_ref))
2003           {
2004              if (ovl->clas_obj) evas_object_del(ovl->clas_obj);
2005              ovl->clas_obj_ref = ovl_clas->obj;
2006              ovl->clas_obj = _obj_dup(ovl->clas_obj_ref, ovl->layout);
2007              _overlay_layout_update(wd, ovl->layout, ovl->clas_obj, NULL, NULL);
2008           }
2009         */
2010         if (ovl_clas->icon && (ovl_clas->icon != ovl->clas_icon_ref))
2011           {
2012              if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
2013              ovl->clas_icon_ref = ovl_clas->icon;
2014              ovl->clas_icon = _icon_dup(ovl->clas_icon_ref, ovl->layout);
2015              _overlay_layout_update(wd, ovl->layout, ovl->clas_icon, NULL, NULL);
2016         }
2017      }
2018    else if (!(ovl->obj) && !(ovl->icon) && !(ovl->clas_icon) && text)
2019      {
2020         _overlay_layout_update(wd, ovl->layout, NULL, text, group);
2021      }
2022 }
2023
2024 static void
2025 _overlay_default_free(Overlay_Default *ovl)
2026 {
2027    EINA_SAFETY_ON_NULL_RETURN(ovl);
2028    if (ovl->obj) evas_object_del(ovl->obj);
2029    if (ovl->icon) evas_object_del(ovl->icon);
2030    if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
2031    evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN,
2032                                   _overlay_clicked_cb);
2033    if (ovl->layout) evas_object_del(ovl->layout);
2034    free(ovl);
2035 }
2036
2037 static Overlay_Default *
2038 _overlay_default_new(Widget_Data *wd, double lon, double lat, const char *group)
2039 {
2040    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2041    EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
2042
2043    Overlay_Default *ovl = ELM_NEW(Overlay_Default);
2044    _edj_marker_size_get(wd, &(ovl->w), &(ovl->h));
2045    ovl->layout = _overlay_layout_new(wd, group);
2046    ovl->lon = lon;
2047    ovl->lat = lat;
2048    return ovl;
2049 }
2050
2051 static void
2052 _overlay_group_clicked_cb(void *data, Evas *e __UNUSED__,  Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
2053 {
2054    EINA_SAFETY_ON_NULL_RETURN(data);
2055    Overlay_Group *ovl = data;
2056
2057    evas_object_smart_callback_call(ovl->clas->wd->obj, SIG_OVERLAY_CLICKED,
2058                                    ovl->clas);
2059    if (ovl->clas->cb) ovl->clas->cb(ovl->clas->cb_data, ovl->clas->wd->obj,
2060                                     ovl->clas);
2061 }
2062
2063 static void
2064 _overlay_group_cb_add(Overlay_Group *ovl)
2065 {
2066    EINA_SAFETY_ON_NULL_RETURN(ovl);
2067    _overlay_default_cb_add(ovl->ovl, _overlay_group_clicked_cb, ovl);
2068 }
2069
2070 static void
2071 _overlay_group_cb_del(Overlay_Group *ovl)
2072 {
2073    EINA_SAFETY_ON_NULL_RETURN(ovl);
2074    _overlay_default_cb_del(ovl->ovl, _overlay_group_clicked_cb);
2075 }
2076
2077 static void
2078 _overlay_group_update(Widget_Data *wd, Overlay_Group *grp, Eina_List *members)
2079 {
2080    EINA_SAFETY_ON_NULL_RETURN(wd);
2081    EINA_SAFETY_ON_NULL_RETURN(grp);
2082
2083    Eina_List *l;
2084    Elm_Map_Overlay *overlay;
2085    Evas_Coord sum_x = 0, sum_y = 0, cnt = 0;
2086
2087    if (grp->members) eina_list_free(grp->members);
2088    grp->members = members;
2089
2090    if (!grp->members || eina_list_count(grp->members) <= 0)
2091      {
2092         _overlay_default_hide(grp->ovl);
2093         return;
2094      }
2095    EINA_LIST_FOREACH(grp->members, l, overlay)
2096      {
2097         Overlay_Default *df = overlay->ovl;
2098         sum_x += df->x;
2099         sum_y += df->y;
2100         cnt++;
2101      }
2102
2103    Overlay_Class *ovl_clas = grp->clas->ovl;
2104
2105    char text[128];
2106    snprintf(text, sizeof(text), "%d", cnt);
2107    _overlay_default_update(wd, grp->ovl, NULL, NULL, ovl_clas, text, "radio2");
2108
2109    grp->ovl->x = sum_x / cnt;
2110    grp->ovl->y = sum_y / cnt;
2111 }
2112
2113 static void
2114 _overlay_group_free(Overlay_Group *grp, Elm_Map_Overlay *club_owner)
2115 {
2116    EINA_SAFETY_ON_NULL_RETURN(grp);
2117
2118    _overlay_default_cb_del(grp->ovl, _overlay_group_clicked_cb);
2119    _overlay_default_free(grp->ovl);
2120    if (grp->clas) elm_map_overlay_class_remove(grp->clas, club_owner);
2121    if (grp->members) eina_list_free(grp->members);
2122    free(grp);
2123 }
2124
2125 static Overlay_Group *
2126 _overlay_group_new(Widget_Data *wd)
2127 {
2128    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2129
2130    Overlay_Group *grp = ELM_NEW(Overlay_Group);
2131    grp->ovl = ELM_NEW(Overlay_Default);
2132    grp->ovl = _overlay_default_new(wd, -1, -1, "radio2");
2133    grp->ovl->w *= 2;
2134    grp->ovl->h *= 2;
2135    return grp;
2136 }
2137
2138 static void
2139 _overlay_class_update(Widget_Data *wd, Overlay_Class *clas, Evas_Object *obj, Evas_Object *icon)
2140 {
2141    EINA_SAFETY_ON_NULL_RETURN(wd);
2142    EINA_SAFETY_ON_NULL_RETURN(clas);
2143
2144    if (obj && (clas->obj != obj))
2145      {
2146         if (clas->obj) evas_object_del(clas->obj);
2147         clas->obj = icon;
2148      }
2149    else if (icon && (clas->icon != icon))
2150      {
2151         if (clas->icon) evas_object_del(clas->icon);
2152         clas->icon = icon;
2153      }
2154 }
2155
2156 static void
2157 _overlay_class_free(Overlay_Class *clas)
2158 {
2159    EINA_SAFETY_ON_NULL_RETURN(clas);
2160    if (clas->icon) evas_object_del(clas->icon);
2161    if (clas->members) eina_list_free(clas->members);
2162    free(clas);
2163 }
2164
2165 static Overlay_Class *
2166 _overlay_class_new(Widget_Data *wd, Elm_Map_Overlay *clas)
2167 {
2168    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2169    Overlay_Class *ovl = ELM_NEW(Overlay_Class);
2170    ovl->clas = clas;
2171    ovl->icon = NULL;
2172    ovl->zoom_max = OVERLAY_CLASS_ZOOM_MAX;
2173    return ovl;
2174 }
2175
2176 static void
2177 _overlay_bubble_cb_add(Overlay_Bubble *ovl, Elm_Map_Overlay *overlay)
2178 {
2179    EINA_SAFETY_ON_NULL_RETURN(ovl);
2180    EINA_SAFETY_ON_NULL_RETURN(overlay);
2181    evas_object_event_callback_add(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
2182                                   _overlay_clicked_cb, overlay);
2183 }
2184
2185 static void
2186 _overlay_bubble_cb_del(Overlay_Bubble *ovl)
2187 {
2188    EINA_SAFETY_ON_NULL_RETURN(ovl);
2189    evas_object_event_callback_del(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
2190                                   _overlay_clicked_cb);
2191 }
2192
2193 static void
2194 _overlay_bubble_hide(Overlay_Bubble *bubble)
2195 {
2196    EINA_SAFETY_ON_NULL_RETURN(bubble);
2197    if (bubble->obj) evas_object_hide(bubble->obj);
2198 }
2199
2200 static void
2201 _overlay_bubble_update(Overlay_Bubble *bubble)
2202 {
2203    EINA_SAFETY_ON_NULL_RETURN(bubble);
2204    if ((!bubble->pobj) && (bubble->lon >= 0) && (bubble->lat >= 0))
2205      {
2206         _geo_to_coord_convert(bubble->wd, bubble->lon, bubble->lat,
2207                               bubble->wd->size.w, &bubble->x, &bubble->y);
2208      }
2209 }
2210
2211 static void
2212 _overlay_bubble_show(Overlay_Bubble *bubble)
2213 {
2214    EINA_SAFETY_ON_NULL_RETURN(bubble);
2215    Evas_Coord x, y;
2216
2217    if ((bubble->x < 0) || (bubble->y < 0)) return;
2218    Evas_Coord px, py;
2219    _pan_geometry_get(bubble->wd, &px, &py);
2220    _coord_rotate(bubble->x + px, bubble->y + py, bubble->wd->rotate.cx,
2221                  bubble->wd->rotate.cy, bubble->wd->rotate.d, &x, &y);
2222    x = x - (bubble->w / 2);
2223    y = y - (bubble->h / 2);
2224    _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
2225    //evas_object_raise(bubble->obj);
2226 }
2227
2228 static void
2229 _overlay_bubble_chase(Overlay_Bubble *bubble)
2230 {
2231    EINA_SAFETY_ON_NULL_RETURN(bubble);
2232    EINA_SAFETY_ON_NULL_RETURN(bubble->pobj);
2233
2234    Evas_Coord x, y, w;
2235    evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
2236    x = x + (w / 2) - (bubble->w / 2);
2237    y = y - bubble->h;
2238    _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
2239    evas_object_raise(bubble->obj);
2240 }
2241
2242 static void
2243 _overlay_bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2244 {
2245    EINA_SAFETY_ON_NULL_RETURN(data);
2246    _overlay_bubble_hide(data);
2247 }
2248
2249 static void
2250 _overlay_bubble_chase_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2251 {
2252    EINA_SAFETY_ON_NULL_RETURN(data);
2253    _overlay_bubble_chase(data);
2254 }
2255
2256 static void
2257 _overlay_bubble_free(Overlay_Bubble* bubble)
2258 {
2259    EINA_SAFETY_ON_NULL_RETURN(bubble);
2260
2261    evas_object_del(bubble->bx);
2262    evas_object_del(bubble->sc);
2263    evas_object_del(bubble->obj);
2264    if (bubble->pobj)
2265      {
2266         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_HIDE,
2267                                             _overlay_bubble_hide_cb, bubble);
2268         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_SHOW,
2269                                             _overlay_bubble_chase_cb, bubble);
2270         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_MOVE,
2271                                             _overlay_bubble_chase_cb, bubble);
2272      }
2273    free(bubble);
2274 }
2275
2276 static Overlay_Bubble*
2277 _overlay_bubble_new(Widget_Data *wd)
2278 {
2279    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2280
2281    Evas_Coord h;
2282    const char *s;
2283    Overlay_Bubble *bubble = ELM_NEW(Overlay_Bubble);
2284    bubble->wd = wd;
2285
2286    bubble->obj = edje_object_add(evas_object_evas_get(wd->obj));
2287    _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
2288                          elm_widget_style_get(wd->obj));
2289    evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
2290                                   _overlay_bubble_chase_cb, bubble);
2291
2292    bubble->sc = elm_scroller_add(bubble->obj);
2293    elm_widget_style_set(bubble->sc, "map_bubble");
2294    elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
2295    elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
2296                            ELM_SCROLLER_POLICY_OFF);
2297    elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
2298                            EINA_FALSE);
2299    edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
2300
2301    bubble->bx = elm_box_add(bubble->sc);
2302    evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2303    evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
2304                                     EVAS_HINT_EXPAND);
2305    elm_box_horizontal_set(bubble->bx, EINA_TRUE);
2306    elm_object_content_set(bubble->sc, bubble->bx);
2307
2308    s = edje_object_data_get(bubble->obj, "size_w");
2309    if (s) bubble->w = atoi(s);
2310    else bubble->w = 0;
2311
2312    edje_object_size_min_calc(bubble->obj, NULL, &(bubble->h));
2313    s = edje_object_data_get(bubble->obj, "size_h");
2314    if (s) h = atoi(s);
2315    else h = 0;
2316    if (bubble->h < h) bubble->h = h;
2317
2318    bubble->lon = -1;
2319    bubble->lat = -1;
2320    bubble->x = -1;
2321    bubble->y = -1;
2322    return bubble;
2323 }
2324
2325 static void
2326 _overlay_route_hide(Overlay_Route *r)
2327 {
2328    EINA_SAFETY_ON_NULL_RETURN(r);
2329    Eina_List *l;
2330    Evas_Object *p;
2331    EINA_LIST_FOREACH(r->paths, l, p) evas_object_hide(p);
2332 }
2333
2334 static void
2335 _overlay_route_show(Overlay_Route *r)
2336 {
2337    EINA_SAFETY_ON_NULL_RETURN(r);
2338    EINA_SAFETY_ON_NULL_RETURN(r->wd);
2339
2340    Widget_Data *wd;
2341    Eina_List *l;
2342    Evas_Object *p;
2343    Path_Node *n;
2344    int cnt;
2345    int x, y;
2346    double a;
2347    Evas_Coord ow, oh, px, py, size;
2348
2349    wd = r->wd;
2350    _viewport_size_get(wd, &ow, &oh);
2351    px = wd->pan_x;
2352    py = wd->pan_y;
2353    size = wd->size.w;
2354
2355    EINA_LIST_FOREACH(r->paths, l, p) evas_object_polygon_points_clear(p);
2356
2357    cnt = eina_list_count(r->nodes);
2358    EINA_LIST_FOREACH(r->nodes, l, n)
2359      {
2360         if ((!wd->zoom) || ((n->idx) &&
2361             ((n->idx % (int)ceil((double)cnt/(double)size*100.0))))) continue;
2362         if (r->inbound)
2363           {
2364              _geo_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
2365                                    &x, &y);
2366              if ((x >= px - ow) && (x <= (px + ow*2)) &&
2367                  (y >= py - oh) && (y <= (py + oh*2)))
2368                {
2369                   x = x - px;
2370                   y = y - py;
2371
2372                   p = eina_list_nth(r->paths, n->idx);
2373                   a = (double)(y - r->y) / (double)(x - r->x);
2374                   if ((abs(a) >= 1) || (r->x == x))
2375                     {
2376                        evas_object_polygon_point_add(p, r->x - 3, r->y);
2377                        evas_object_polygon_point_add(p, r->x + 3, r->y);
2378                        evas_object_polygon_point_add(p, x + 3, y);
2379                        evas_object_polygon_point_add(p, x - 3, y);
2380                     }
2381                   else
2382                     {
2383                        evas_object_polygon_point_add(p, r->x, r->y - 3);
2384                        evas_object_polygon_point_add(p, r->x, r->y + 3);
2385                        evas_object_polygon_point_add(p, x, y + 3);
2386                        evas_object_polygon_point_add(p, x, y - 3);
2387                     }
2388
2389                   evas_object_color_set(p, r->color.r, r->color.g, r->color.b,
2390                                         r->color.a);
2391                   evas_object_raise(p);
2392                   _obj_rotate(wd, p);
2393                   evas_object_show(p);
2394                   r->x = x;
2395                   r->y = y;
2396                }
2397
2398              else r->inbound = EINA_FALSE;
2399           }
2400         else
2401           {
2402              _geo_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
2403                                    &x, &y);
2404              if ((x >= px - ow) && (x <= (px + ow*2)) &&
2405                  (y >= py - oh) && (y <= (py + oh*2)))
2406                {
2407                   r->x = x - px;
2408                   r->y = y - py;
2409                   r->inbound = EINA_TRUE;
2410                }
2411              else r->inbound = EINA_FALSE;
2412           }
2413      }
2414    r->inbound = EINA_FALSE;
2415 }
2416
2417 static void
2418 _overlay_route_free(Overlay_Route* route)
2419 {
2420    EINA_SAFETY_ON_NULL_RETURN(route);
2421    Evas_Object *p;
2422    Path_Node *n;
2423
2424    EINA_LIST_FREE(route->paths, p) evas_object_del(p);
2425    EINA_LIST_FREE(route->nodes, n)
2426      {
2427         if (n->pos.address) eina_stringshare_del(n->pos.address);
2428         free(n);
2429      }
2430    free(route);
2431 }
2432
2433 static Overlay_Route *
2434 _overlay_route_new(Widget_Data *wd, const Elm_Map_Route *route)
2435 {
2436    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2437    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
2438
2439    Eina_List *l;
2440    Path_Node *n;
2441
2442    Overlay_Route *ovl = ELM_NEW(Overlay_Route);
2443    ovl->wd = wd;
2444    ovl->inbound = EINA_FALSE;
2445    ovl->color.r = 255;
2446    ovl->color.g = 0;
2447    ovl->color.b = 0;
2448    ovl->color.a = 255;
2449
2450     EINA_LIST_FOREACH(route->nodes, l, n)
2451      {
2452         Evas_Object *path;
2453         Path_Node *node;
2454
2455         node = ELM_NEW(Path_Node);
2456         node->idx = n->idx;
2457         node->pos.lon = n->pos.lon;
2458         node->pos.lat = n->pos.lat;
2459         if (n->pos.address) node->pos.address = strdup(n->pos.address);
2460         ovl->nodes = eina_list_append(ovl->nodes, node);
2461
2462         path = evas_object_polygon_add(evas_object_evas_get(wd->obj));
2463         evas_object_smart_member_add(path, wd->pan_smart);
2464         ovl->paths = eina_list_append(ovl->paths, path);
2465      }
2466    return ovl;
2467 }
2468
2469 static void
2470 _overlay_grouping(Eina_List *members, Elm_Map_Overlay *overlay)
2471 {
2472    EINA_SAFETY_ON_NULL_RETURN(members);
2473    EINA_SAFETY_ON_NULL_RETURN(overlay);
2474    // Currently support only basic overlay type
2475    EINA_SAFETY_ON_FALSE_RETURN(overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT);
2476
2477    Eina_List *l;
2478    Elm_Map_Overlay *overlay_memb;
2479    Eina_List *club_members = NULL;
2480
2481    // Grouping only supports overlay default
2482    Overlay_Default *ovl = (Overlay_Default *)overlay->ovl;
2483    EINA_LIST_FOREACH(members, l, overlay_memb)
2484      {
2485         Overlay_Default *ovl_memb = overlay_memb->ovl;
2486         if ((overlay_memb->hide) ||
2487             (overlay_memb->zoom_min > overlay_memb->wd->zoom)) continue;
2488         if (overlay == overlay_memb || overlay_memb->grp_in) continue;
2489         if (ELM_RECTS_INTERSECT(ovl_memb->x, ovl_memb->y, ovl_memb->w,
2490                                 ovl_memb->h, ovl->x, ovl->y,
2491                                 ovl->w * OVERLAY_GROUPING_SCALE,
2492                                 ovl->h * OVERLAY_GROUPING_SCALE))
2493           {
2494              // Join group.
2495              overlay_memb->grp_boss = EINA_FALSE;
2496              overlay_memb->grp_in = EINA_TRUE;
2497              club_members = eina_list_append(club_members, overlay_memb);
2498              _overlay_group_update(overlay_memb->wd, overlay_memb->grp, NULL);
2499              _overlay_group_cb_del(overlay_memb->grp);
2500           }
2501      }
2502
2503    if (eina_list_count(club_members) >= 1)
2504      {
2505         // Mark as boss
2506         overlay->grp_boss = EINA_TRUE;
2507         overlay->grp_in = EINA_TRUE;
2508         club_members = eina_list_append(club_members, overlay);
2509         _overlay_group_update(overlay->wd, overlay->grp, club_members);
2510         _overlay_group_cb_del(overlay->grp);
2511         _overlay_group_cb_add(overlay->grp);
2512      }
2513 }
2514
2515 static void
2516 _overlay_display(Widget_Data *wd, Elm_Map_Overlay *overlay)
2517 {
2518    Eina_Bool hide = EINA_FALSE;
2519
2520    if ((overlay->grp_in) || (overlay->hide) || (overlay->zoom_min > wd->zoom))
2521       hide = EINA_TRUE;
2522    if ((overlay->grp->clas) && ((overlay->grp->clas->hide) ||
2523                                 (overlay->grp->clas->zoom_min > wd->zoom)))
2524       hide = EINA_TRUE;
2525
2526    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2527      {
2528         if (hide) _overlay_default_hide(overlay->ovl);
2529         else _overlay_default_show(wd, overlay->ovl);
2530      }
2531    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
2532      {
2533         if (hide) _overlay_bubble_hide(overlay->ovl);
2534         else _overlay_bubble_show(overlay->ovl);
2535      }
2536    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
2537      {
2538        if (hide) _overlay_route_hide(overlay->ovl);
2539        else _overlay_route_show(overlay->ovl);
2540      }
2541 }
2542
2543 static void
2544 _overlay_place(Widget_Data *wd)
2545 {
2546    EINA_SAFETY_ON_NULL_RETURN(wd);
2547
2548    Eina_List *l, *ll;
2549    Elm_Map_Overlay *overlay, *grp;
2550
2551    if (eina_list_count(wd->overlays) == 0) return;
2552
2553    // Reset overlays coord & grp except class type
2554    EINA_LIST_FOREACH(wd->overlays, l, overlay)
2555      {
2556
2557         if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS) continue;
2558         if (overlay->paused) continue;
2559         if ((overlay->grp) && (overlay->grp->clas) &&
2560             (overlay->grp->clas->paused)) continue;
2561         if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2562           {
2563              Overlay_Class *ovl_grp = NULL;
2564              if (overlay->grp->clas) ovl_grp = overlay->grp->clas->ovl;
2565              _overlay_default_update(wd, overlay->ovl, NULL, NULL, ovl_grp,
2566                                      NULL, NULL);
2567            }
2568         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
2569            _overlay_bubble_update(overlay->ovl);
2570         // Reset grp flags
2571         overlay->grp_in = EINA_FALSE;
2572         overlay->grp_boss = EINA_FALSE;
2573         _overlay_group_update(wd, overlay->grp, NULL);
2574      }
2575
2576    // Classify into group idol or follwer
2577    EINA_LIST_FOREACH(wd->overlays, l, grp)
2578      {
2579         Elm_Map_Overlay *idol;
2580         Overlay_Class *ovl;
2581
2582         if (grp->type != ELM_MAP_OVERLAY_TYPE_CLASS) continue;
2583         if ((grp->hide) || (grp->zoom_min > wd->zoom)) continue;
2584
2585         ovl = grp->ovl;
2586         if (ovl->zoom_max < wd->zoom) continue;
2587         EINA_LIST_FOREACH(ovl->members, ll, idol)
2588           {
2589              if (!idol->grp_in) _overlay_grouping(ovl->members, idol);
2590           }
2591      }
2592
2593    // Place overlays
2594    EINA_LIST_FOREACH(wd->overlays, l, overlay)
2595       if (overlay->type != ELM_MAP_OVERLAY_TYPE_CLASS)
2596          _overlay_display(wd, overlay);
2597
2598    // Place group overlays
2599    EINA_LIST_FOREACH(wd->overlays, l, overlay)
2600      {
2601         if (overlay->grp_boss) _overlay_default_show(wd, overlay->grp->ovl);
2602      }
2603 }
2604
2605 static Evas_Object *
2606 _overlay_obj_get(Elm_Map_Overlay *overlay)
2607 {
2608    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
2609    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
2610      {
2611         Overlay_Default *ovl = overlay->ovl;
2612         return ovl->layout;
2613      }
2614    else
2615      {
2616         ERR("Not supported overlay type: %d", overlay->type);
2617         return NULL;
2618      }
2619 }
2620
2621 static void
2622 _overlays_show(void *data)
2623 {
2624    EINA_SAFETY_ON_NULL_RETURN(data);
2625    Delayed_Data *dd = data;
2626
2627    int zoom;
2628    double max_lon, min_lon, max_lat, min_lat;
2629    Evas_Coord vw, vh;
2630
2631    _region_max_min_get(dd->overlays, &max_lon, &min_lon, &max_lat, &min_lat);
2632    dd->lon = (max_lon + min_lon) / 2;
2633    dd->lat = (max_lat + min_lat) / 2;
2634
2635    zoom = dd->wd->src_tile->zoom_min;
2636    _viewport_size_get(dd->wd, &vw, &vh);
2637    while (zoom <= dd->wd->src_tile->zoom_max)
2638      {
2639         Evas_Coord size, max_x, max_y, min_x, min_y;
2640         size = pow(2.0, zoom) * dd->wd->tsize;
2641         _geo_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
2642         _geo_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
2643         if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
2644         zoom++;
2645      }
2646    zoom--;
2647
2648    zoom_do(dd->wd, zoom);
2649    _region_show(dd);
2650    evas_object_smart_changed(dd->wd->pan_smart);
2651 }
2652
2653 static void
2654 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2655 {
2656    Pan *sd = evas_object_smart_data_get(obj);
2657    EINA_SAFETY_ON_NULL_RETURN(sd);
2658    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2659
2660    sd->wd->pan_x = x;
2661    sd->wd->pan_y = y;
2662    evas_object_smart_changed(obj);
2663 }
2664
2665 static void
2666 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2667 {
2668    Pan *sd = evas_object_smart_data_get(obj);
2669    EINA_SAFETY_ON_NULL_RETURN(sd);
2670    if (x) *x = sd->wd->pan_x;
2671    if (y) *y = sd->wd->pan_y;
2672 }
2673
2674 static void
2675 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2676 {
2677    Pan *sd = evas_object_smart_data_get(obj);
2678    EINA_SAFETY_ON_NULL_RETURN(sd);
2679    Evas_Coord ow, oh;
2680    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2681    ow = sd->wd->size.w - ow;
2682    oh = sd->wd->size.h - oh;
2683    if (ow < 0) ow = 0;
2684    if (oh < 0) oh = 0;
2685    if (x) *x = ow;
2686    if (y) *y = oh;
2687 }
2688
2689 static void
2690 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2691 {
2692    if (x) *x = 0;
2693    if (y) *y = 0;
2694 }
2695
2696 static void
2697 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2698 {
2699    Pan *sd = evas_object_smart_data_get(obj);
2700    EINA_SAFETY_ON_NULL_RETURN(sd);
2701    if (w) *w = sd->wd->size.w;
2702    if (h) *h = sd->wd->size.h;
2703 }
2704
2705 static void
2706 _pan_add(Evas_Object *obj)
2707 {
2708    Pan *sd;
2709    Evas_Object_Smart_Clipped_Data *cd;
2710    parent_sc.add(obj);
2711    cd = evas_object_smart_data_get(obj);
2712    EINA_SAFETY_ON_NULL_RETURN(cd);
2713    sd = ELM_NEW(Pan);
2714    sd->__clipped_data = *cd;
2715    free(cd);
2716    evas_object_smart_data_set(obj, sd);
2717 }
2718
2719 static void
2720 _pan_resize(Evas_Object *obj, Evas_Coord w __UNUSED__, Evas_Coord h __UNUSED__)
2721 {
2722    Pan *sd = evas_object_smart_data_get(obj);
2723    EINA_SAFETY_ON_NULL_RETURN(sd);
2724
2725    _sizing_eval(sd->wd);
2726    elm_map_zoom_mode_set(sd->wd->obj, sd->wd->mode);
2727    evas_object_smart_changed(obj);
2728 }
2729
2730 static void
2731 _pan_calculate(Evas_Object *obj)
2732 {
2733    Pan *sd = evas_object_smart_data_get(obj);
2734    EINA_SAFETY_ON_NULL_RETURN(sd);
2735
2736    Evas_Coord w, h;
2737    evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &w, &h);
2738    if (w <= 0 || h <= 0) return;
2739
2740    _grid_place(sd->wd);
2741    _marker_place(sd->wd);
2742    _overlay_place(sd->wd);
2743    _track_place(sd->wd);
2744    _delayed_do(sd->wd);
2745 }
2746
2747 static void
2748 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2749 {
2750    EINA_SAFETY_ON_NULL_RETURN(obj);
2751    evas_object_smart_changed(obj);
2752 }
2753
2754 static void
2755 _hold_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2756 {
2757    EINA_SAFETY_ON_NULL_RETURN(data);
2758    Widget_Data *wd = data;
2759    elm_smart_scroller_hold_set(wd->scr, 1);
2760 }
2761
2762 static void
2763 _hold_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2764 {
2765    EINA_SAFETY_ON_NULL_RETURN(data);
2766    Widget_Data *wd = data;
2767    elm_smart_scroller_hold_set(wd->scr, 0);
2768 }
2769
2770 static void
2771 _freeze_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2772 {
2773    EINA_SAFETY_ON_NULL_RETURN(data);
2774    Widget_Data *wd = data;
2775    elm_smart_scroller_freeze_set(wd->scr, 1);
2776 }
2777
2778 static void
2779 _freeze_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2780 {
2781    EINA_SAFETY_ON_NULL_RETURN(data);
2782    Widget_Data *wd = data;
2783    elm_smart_scroller_freeze_set(wd->scr, 0);
2784 }
2785
2786 static void
2787 _elm_map_marker_remove(Elm_Map_Marker *marker)
2788 {
2789 #ifdef HAVE_ELEMENTARY_ECORE_CON
2790    EINA_SAFETY_ON_NULL_RETURN(marker);
2791    Widget_Data *wd = marker->wd;
2792    EINA_SAFETY_ON_NULL_RETURN(wd);
2793
2794    if ((marker->content) && (marker->clas->func.del))
2795       marker->clas->func.del(wd->obj, marker, marker->data, marker->content);
2796
2797    if (marker->bubble) _bubble_free(marker->bubble);
2798    if (marker->group) _marker_group_free(marker->group);
2799
2800    if (marker->group_clas)
2801       marker->group_clas->markers = eina_list_remove(marker->group_clas->markers, marker);
2802    wd->markers = eina_list_remove(wd->markers, marker);
2803
2804    evas_object_del(marker->obj);
2805    free(marker);
2806
2807    evas_object_smart_changed(wd->pan_smart);
2808 #else
2809    (void) marker;
2810 #endif
2811 }
2812
2813 static void
2814 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2815 {
2816    ELM_CHECK_WIDTYPE(obj, widtype);
2817    Widget_Data *wd = elm_widget_data_get(obj);
2818    EINA_SAFETY_ON_NULL_RETURN(wd);
2819
2820    if (elm_widget_focus_get(obj))
2821      {
2822         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2823         evas_object_focus_set(wd->obj, EINA_TRUE);
2824      }
2825    else
2826      {
2827         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2828         evas_object_focus_set(wd->obj, EINA_FALSE);
2829      }
2830 }
2831
2832 static void
2833 _del_hook(Evas_Object *obj)
2834 {
2835    ELM_CHECK_WIDTYPE(obj, widtype);
2836    Widget_Data *wd = elm_widget_data_get(obj);
2837    EINA_SAFETY_ON_NULL_RETURN(wd);
2838
2839    if (wd->map) evas_map_free(wd->map);
2840    free(wd);
2841 }
2842
2843 static void
2844 _del_pre_hook(Evas_Object *obj)
2845 {
2846    ELM_CHECK_WIDTYPE(obj, widtype);
2847    Widget_Data *wd = elm_widget_data_get(obj);
2848    EINA_SAFETY_ON_NULL_RETURN(wd);
2849
2850    Eina_List *l, *ll;
2851    Elm_Map_Route *r;
2852    Elm_Map_Name *na;
2853    Evas_Object *track;
2854    Elm_Map_Marker *marker;
2855    Elm_Map_Group_Class *group_clas;
2856    Elm_Map_Marker_Class *clas;
2857    Elm_Map_Overlay *overlay;
2858    Delayed_Data *dd;
2859    int idx = 0;
2860    Source_Tile *ts;
2861    Source_Route *rs;
2862    Source_Name *ns;
2863
2864    EINA_LIST_FOREACH_SAFE(wd->routes, l, ll, r) elm_map_route_del(r);
2865    eina_list_free(wd->routes);
2866
2867    EINA_LIST_FOREACH_SAFE(wd->names, l, ll, na) elm_map_name_del(na);
2868    eina_list_free(wd->names);
2869
2870    EINA_LIST_FOREACH_SAFE(wd->overlays, l, ll, overlay)
2871       elm_map_overlay_del(overlay);
2872    eina_list_free(wd->overlays);
2873
2874    EINA_LIST_FREE(wd->track, track) evas_object_del(track);
2875
2876    EINA_LIST_FOREACH_SAFE(wd->markers, l, ll, marker)
2877      _elm_map_marker_remove(marker);
2878    eina_list_free(wd->markers);
2879
2880    EINA_LIST_FREE(wd->group_classes, group_clas)
2881      {
2882         eina_list_free(group_clas->markers);
2883         if (group_clas->style) eina_stringshare_del(group_clas->style);
2884         free(group_clas);
2885      }
2886    EINA_LIST_FREE(wd->marker_classes, clas)
2887      {
2888         if (clas->style) eina_stringshare_del(clas->style);
2889         free(clas);
2890      }
2891
2892    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2893    if (wd->long_timer) ecore_timer_del(wd->long_timer);
2894
2895    if (wd->delayed_jobs) EINA_LIST_FREE(wd->delayed_jobs, dd) free(dd);
2896
2897    if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2898    if (wd->ua) eina_hash_free(wd->ua);
2899
2900    if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
2901    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2902
2903    _grid_all_clear(wd);
2904    // Removal of download list should be after grid clear.
2905    if (wd->download_idler) ecore_idler_del(wd->download_idler);
2906    eina_list_free(wd->download_list);
2907
2908    for (idx = 0; wd->src_tile_names[idx]; idx++)
2909       eina_stringshare_del(wd->src_tile_names[idx]);
2910    EINA_LIST_FREE(wd->src_tiles, ts) free(ts);
2911
2912    for (idx = 0; wd->src_route_names[idx]; idx++)
2913       eina_stringshare_del(wd->src_route_names[idx]);
2914    EINA_LIST_FREE(wd->src_routes, rs) free(rs);
2915
2916    for (idx = 0; wd->src_name_names[idx]; idx++)
2917       eina_stringshare_del(wd->src_name_names[idx]);
2918    EINA_LIST_FREE(wd->src_names, ns) free(ns);
2919
2920    if (!ecore_file_recursive_rm(CACHE_ROOT))
2921       ERR("Deletion of %s failed", CACHE_ROOT);
2922 }
2923
2924 static void
2925 _theme_hook(Evas_Object *obj)
2926 {
2927    ELM_CHECK_WIDTYPE(obj, widtype);
2928    Widget_Data *wd = elm_widget_data_get(obj);
2929    EINA_SAFETY_ON_NULL_RETURN(wd);
2930
2931    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2932    _sizing_eval(wd);
2933 }
2934
2935 static Eina_Bool
2936 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2937 {
2938    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2939    Widget_Data *wd = elm_widget_data_get(obj);
2940    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
2941
2942    Evas_Coord x, y;
2943    Evas_Coord vh;
2944    Evas_Coord step_x, step_y, page_x, page_y;
2945
2946    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2947    Evas_Event_Key_Down *ev = event_info;
2948    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2949
2950    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2951    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2952    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2953    _viewport_size_get(wd, NULL, &vh);
2954
2955    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2956      {
2957         x -= step_x;
2958      }
2959    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2960      {
2961         x += step_x;
2962      }
2963    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
2964      {
2965         y -= step_y;
2966      }
2967    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2968      {
2969         y += step_y;
2970      }
2971    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2972      {
2973         if (page_y < 0)
2974           y -= -(page_y * vh) / 100;
2975         else
2976           y -= page_y;
2977      }
2978    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2979      {
2980         if (page_y < 0)
2981           y += -(page_y * vh) / 100;
2982         else
2983           y += page_y;
2984      }
2985    else if (!strcmp(ev->keyname, "KP_Add"))
2986      {
2987         zoom_with_animation(wd, wd->zoom + 1, 10);
2988         return EINA_TRUE;
2989      }
2990    else if (!strcmp(ev->keyname, "KP_Subtract"))
2991      {
2992         zoom_with_animation(wd, wd->zoom - 1, 10);
2993         return EINA_TRUE;
2994      }
2995    else return EINA_FALSE;
2996
2997    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2998    elm_smart_scroller_child_pos_set(wd->scr, x, y);
2999
3000    return EINA_TRUE;
3001 }
3002
3003 static Eina_Bool
3004 cb_dump_name_attrs(void *data, const char *key, const char *value)
3005 {
3006    Name_Dump *dump = (Name_Dump*)data;
3007    if (!dump) return EINA_FALSE;
3008
3009    if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
3010    else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
3011
3012    return EINA_TRUE;
3013 }
3014
3015 static Eina_Bool
3016 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
3017 {
3018    Route_Dump *dump = data;
3019    if (!dump) return EINA_FALSE;
3020
3021    switch (type)
3022      {
3023       case EINA_SIMPLE_XML_OPEN:
3024       case EINA_SIMPLE_XML_OPEN_EMPTY:
3025         {
3026            const char *attrs;
3027
3028            attrs = eina_simple_xml_tag_attributes_find(value, length);
3029            if (!attrs)
3030              {
3031                 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
3032                 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
3033                 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
3034                 else dump->id = ROUTE_XML_NONE;
3035              }
3036          }
3037         break;
3038       case EINA_SIMPLE_XML_DATA:
3039         {
3040            char *buf = malloc(length);
3041            if (!buf) return EINA_FALSE;
3042            snprintf(buf, length, "%s", value);
3043            if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
3044            else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
3045            else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
3046            free(buf);
3047         }
3048         break;
3049       default:
3050         break;
3051      }
3052
3053    return EINA_TRUE;
3054 }
3055
3056 static Eina_Bool
3057 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
3058 {
3059    Name_Dump *dump = data;
3060    if (!dump) return EINA_FALSE;
3061
3062    switch (type)
3063      {
3064       case EINA_SIMPLE_XML_OPEN:
3065       case EINA_SIMPLE_XML_OPEN_EMPTY:
3066         {
3067            const char *attrs;
3068            attrs = eina_simple_xml_tag_attributes_find(value, length);
3069            if (attrs)
3070              {
3071                 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
3072                 else dump->id = NAME_XML_NONE;
3073
3074                 eina_simple_xml_attributes_parse
3075                   (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
3076              }
3077         }
3078         break;
3079       case EINA_SIMPLE_XML_DATA:
3080         {
3081            char *buf = malloc(length + 1);
3082            if (!buf) return EINA_FALSE;
3083            snprintf(buf, length + 1, "%s", value);
3084            if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
3085            free(buf);
3086         }
3087         break;
3088       default:
3089         break;
3090      }
3091
3092    return EINA_TRUE;
3093 }
3094
3095 static void
3096 _kml_parse(Elm_Map_Route *r)
3097 {
3098    EINA_SAFETY_ON_NULL_RETURN(r);
3099    EINA_SAFETY_ON_NULL_RETURN(r->fname);
3100
3101    FILE *f;
3102    char **str;
3103    unsigned int ele, idx;
3104    double lon, lat;
3105
3106    Route_Dump dump = {0, r->fname, 0.0, NULL, NULL};
3107
3108    f = fopen(r->fname, "rb");
3109    if (f)
3110      {
3111         long sz;
3112
3113         fseek(f, 0, SEEK_END);
3114         sz = ftell(f);
3115         if (sz > 0)
3116           {
3117              char *buf;
3118
3119              fseek(f, 0, SEEK_SET);
3120              buf = malloc(sz);
3121              if (buf)
3122                {
3123                   if (fread(buf, 1, sz, f))
3124                     {
3125                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump,
3126                                              &dump);
3127                        free(buf);
3128                     }
3129                }
3130           }
3131         fclose(f);
3132
3133         if (dump.distance) r->info.distance = dump.distance;
3134         if (dump.description)
3135           {
3136              eina_stringshare_replace(&r->info.waypoints, dump.description);
3137              str = eina_str_split_full(dump.description, "\n", 0, &ele);
3138              r->info.waypoint_count = ele;
3139              for (idx = 0; idx < ele; idx++)
3140                {
3141                   Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
3142                   if (wp)
3143                     {
3144                        wp->wd = r->wd;
3145                        wp->point = eina_stringshare_add(str[idx]);
3146                        DBG("%s", str[idx]);
3147                        r->waypoint = eina_list_append(r->waypoint, wp);
3148                     }
3149                }
3150              if (str && str[0])
3151                {
3152                   free(str[0]);
3153                   free(str);
3154                }
3155           }
3156         else WRN("description is not found !");
3157
3158         if (dump.coordinates)
3159           {
3160              eina_stringshare_replace(&r->info.nodes, dump.coordinates);
3161              str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
3162              r->info.node_count = ele;
3163              for (idx = 0; idx < ele; idx++)
3164                {
3165                   sscanf(str[idx], "%lf,%lf", &lon, &lat);
3166                   Path_Node *n = ELM_NEW(Path_Node);
3167                   if (n)
3168                     {
3169                        n->wd = r->wd;
3170                        n->pos.lon = lon;
3171                        n->pos.lat = lat;
3172                        n->idx = idx;
3173                        DBG("%lf:%lf", lon, lat);
3174                        n->pos.address = NULL;
3175                        r->nodes = eina_list_append(r->nodes, n);
3176                     }
3177                }
3178              if (str && str[0])
3179                {
3180                   free(str[0]);
3181                   free(str);
3182                }
3183           }
3184      }
3185 }
3186
3187 static void
3188 _name_parse(Elm_Map_Name *n)
3189 {
3190    EINA_SAFETY_ON_NULL_RETURN(n);
3191    EINA_SAFETY_ON_NULL_RETURN(n->fname);
3192
3193    FILE *f;
3194
3195    Name_Dump dump = {0, NULL, 0.0, 0.0};
3196
3197    f = fopen(n->fname, "rb");
3198    if (f)
3199      {
3200         long sz;
3201
3202         fseek(f, 0, SEEK_END);
3203         sz = ftell(f);
3204         if (sz > 0)
3205           {
3206              char *buf;
3207
3208              fseek(f, 0, SEEK_SET);
3209              buf = malloc(sz);
3210              if (buf)
3211                {
3212                   if (fread(buf, 1, sz, f))
3213                     {
3214                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3215                        free(buf);
3216                     }
3217                }
3218           }
3219         fclose(f);
3220
3221         if (dump.address)
3222           {
3223              INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3224              n->address = strdup(dump.address);
3225           }
3226         n->lon = dump.lon;
3227         n->lat = dump.lat;
3228      }
3229 }
3230
3231 Grid *_get_current_grid(Widget_Data *wd)
3232 {
3233    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
3234    Eina_List *l;
3235    Grid *g = NULL, *ret = NULL;
3236    EINA_LIST_FOREACH(wd->grids, l, g)
3237      {
3238         if (wd->zoom == g->zoom)
3239           {
3240              ret = g;
3241              break;
3242           }
3243      }
3244    return ret;
3245 }
3246
3247 static void
3248 _route_cb(void *data, const char *file,  int status)
3249 {
3250    EINA_SAFETY_ON_NULL_RETURN(data);
3251    EINA_SAFETY_ON_NULL_RETURN(file);
3252
3253    Elm_Map_Route *route = data;
3254    Widget_Data *wd = route->wd;
3255    EINA_SAFETY_ON_NULL_RETURN(wd);
3256
3257    route->job = NULL;
3258    if (status == 200)
3259      {
3260         _kml_parse(route);
3261         INF("Route request success from (%lf, %lf) to (%lf, %lf)",
3262             route->flon, route->flat, route->tlon, route->tlat);
3263         if (route->cb) route->cb(route->data, wd->obj, route);
3264         evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3265      }
3266    else
3267      {
3268         ERR("Route request failed: %d", status);
3269         if (route->cb) route->cb(route->data, wd->obj, NULL);
3270         evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED_FAIL, NULL);
3271      }
3272
3273    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3274                            "elm,state,busy,stop", "elm");
3275 }
3276
3277 static void
3278 _name_cb(void *data, const char *file,  int status)
3279 {
3280    EINA_SAFETY_ON_NULL_RETURN(data);
3281    EINA_SAFETY_ON_NULL_RETURN(file);
3282
3283    Elm_Map_Name *name = data;
3284    Widget_Data *wd = name->wd;
3285    EINA_SAFETY_ON_NULL_RETURN(wd);
3286
3287    name->job = NULL;
3288    if (status == 200)
3289      {
3290         _name_parse(name);
3291         INF("Name request success address:%s, lon:%lf, lat:%lf",
3292             name->address, name->lon, name->lat);
3293         if (name->cb) name->cb(name->data, wd->obj, name);
3294         evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3295      }
3296    else
3297      {
3298         ERR("Name request failed: %d", status);
3299         if (name->cb) name->cb(name->data, wd->obj, NULL);
3300         evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED_FAIL, NULL);
3301      }
3302    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3303                            "elm,state,busy,stop", "elm");
3304 }
3305
3306
3307
3308 static Elm_Map_Name *
3309 _name_request(const Evas_Object *obj, int method, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
3310 {
3311    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3312    Widget_Data *wd = elm_widget_data_get(obj);
3313    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
3314    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_name, NULL);
3315
3316
3317    char *url;
3318    char fname[PATH_MAX];
3319
3320    if (!ecore_file_exists(CACHE_NAME_ROOT)) ecore_file_mkpath(CACHE_NAME_ROOT);
3321
3322    url = wd->src_name->url_cb(wd->obj, method, address, lon, lat);
3323    if (!url)
3324      {
3325         ERR("Name URL is NULL");
3326         return NULL;
3327      }
3328
3329    Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3330    name->wd = wd;
3331    snprintf(fname, sizeof(fname), CACHE_NAME_ROOT"/%d", rand());
3332    name->fname = strdup(fname);
3333    name->method = method;
3334    if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3335    else if (method == ELM_MAP_NAME_METHOD_REVERSE)
3336      {
3337         name->lon = lon;
3338         name->lat = lat;
3339      }
3340    name->cb = name_cb;
3341    name->data = data;
3342
3343    if (!ecore_file_download_full(url, name->fname, _name_cb, NULL, name,
3344                                  &(name->job), wd->ua) || !(name->job))
3345      {
3346         ERR("Can't request Name from %s to %s", url, name->fname);
3347         if (name->address) free(name->address);
3348         free(name->fname);
3349         free(name);
3350         return NULL;
3351      }
3352    INF("Name requested from %s to %s", url, name->fname);
3353    free(url);
3354
3355    wd->names = eina_list_append(wd->names, name);
3356    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, name);
3357    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3358                            "elm,state,busy,start", "elm");
3359    return name;
3360 }
3361
3362 static Evas_Event_Flags
3363 _pinch_zoom_start_cb(void *data, void *event_info __UNUSED__)
3364 {
3365    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EVAS_EVENT_FLAG_NONE);
3366    Widget_Data *wd = data;
3367
3368    wd->pinch_zoom = wd->zoom_detail;
3369    return EVAS_EVENT_FLAG_NONE;
3370 }
3371
3372 static Evas_Event_Flags
3373 _pinch_zoom_cb(void *data, void *event_info)
3374 {
3375    Widget_Data *wd = data;
3376    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3377
3378    if (!wd->paused)
3379      {
3380         Elm_Gesture_Zoom_Info *ei = event_info;
3381         zoom_do(wd, wd->pinch_zoom + ei->zoom - 1);
3382      }
3383    return EVAS_EVENT_FLAG_NONE;
3384 }
3385
3386 static Evas_Event_Flags
3387 _pinch_rotate_cb(void *data, void *event_info)
3388 {
3389    Widget_Data *wd = data;
3390    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3391
3392    if (!wd->paused)
3393      {
3394         int x, y, w, h;
3395         Elm_Gesture_Rotate_Info *ei = event_info;
3396         evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
3397
3398         wd->rotate.d = wd->rotate.a + ei->angle - ei->base_angle;
3399         wd->rotate.cx = x + ((double)w * 0.5);
3400         wd->rotate.cy = y + ((double)h * 0.5);
3401
3402         evas_object_smart_changed(wd->pan_smart);
3403      }
3404    return EVAS_EVENT_FLAG_NONE;
3405 }
3406
3407 static Evas_Event_Flags
3408 _pinch_rotate_end_cb(void *data, void *event_info __UNUSED__)
3409 {
3410    Widget_Data *wd = data;
3411    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
3412
3413    wd->rotate.a = wd->rotate.d;
3414
3415    return EVAS_EVENT_FLAG_NONE;
3416 }
3417
3418 static Eina_Bool
3419 _source_tile_mod_cb(Eina_Module *m, void *data)
3420 {
3421    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3422
3423    Widget_Data *wd = data;
3424    Source_Tile *s;
3425    Elm_Map_Module_Source_Name_Func name_cb;
3426    Elm_Map_Module_Tile_Zoom_Min_Func zoom_min;
3427    Elm_Map_Module_Tile_Zoom_Max_Func zoom_max;
3428    Elm_Map_Module_Tile_Url_Func url_cb;
3429    Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
3430    Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
3431    const char *file;
3432
3433    file = eina_module_file_get(m);
3434    if (!eina_module_load(m))
3435      {
3436         ERR("Could not load module \"%s\": %s", file,
3437             eina_error_msg_get(eina_error_get()));
3438         return EINA_FALSE;
3439      }
3440
3441    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3442    zoom_min = eina_module_symbol_get(m, "map_module_tile_zoom_min_get");
3443    zoom_max = eina_module_symbol_get(m, "map_module_tile_zoom_max_get");
3444    url_cb = eina_module_symbol_get(m, "map_module_tile_url_get");
3445    geo_to_coord = eina_module_symbol_get(m, "map_module_tile_geo_to_coord");
3446    coord_to_geo = eina_module_symbol_get(m, "map_module_tile_coord_to_geo");
3447
3448    if ((!name_cb) || (!zoom_min) || (!zoom_max) || (!url_cb) ||
3449        (!geo_to_coord) || (!coord_to_geo))
3450      {
3451         WRN("Could not find map module functions from module \"%s\": %s",
3452             file, eina_error_msg_get(eina_error_get()));
3453         eina_module_unload(m);
3454         return EINA_FALSE;
3455      }
3456    s = ELM_NEW(Source_Tile);
3457    s->name = name_cb();
3458    s->zoom_min = zoom_min();
3459    s->zoom_max = zoom_max();
3460    s->url_cb = url_cb;
3461    s->geo_to_coord = geo_to_coord;
3462    s->coord_to_geo = coord_to_geo;
3463    wd->src_tiles = eina_list_append(wd->src_tiles, s);
3464
3465    eina_module_unload(m);
3466    return EINA_TRUE;
3467 }
3468
3469 static void
3470 _source_tile_load(Widget_Data *wd)
3471 {
3472    unsigned int idx;
3473    Eina_List *l;
3474    Source_Tile *s;
3475    Eina_Array *modules = NULL;
3476
3477    // Load from hard coded data
3478    for (idx = 0; idx < (sizeof(src_tiles) / sizeof(Source_Tile)); idx++)
3479      {
3480         s= ELM_NEW(Source_Tile);
3481         s->name = src_tiles[idx].name;
3482         s->zoom_min = src_tiles[idx].zoom_min;
3483         s->zoom_max = src_tiles[idx].zoom_max;
3484         s->url_cb = src_tiles[idx].url_cb;
3485         s->geo_to_coord = src_tiles[idx].geo_to_coord;
3486         s->coord_to_geo = src_tiles[idx].coord_to_geo;
3487         wd->src_tiles = eina_list_append(wd->src_tiles, s);
3488      }
3489
3490    // Load from modules
3491    modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_tile_mod_cb, wd);
3492    eina_array_free(modules);
3493
3494    // Set default source
3495    wd->src_tile = eina_list_nth(wd->src_tiles, 0);
3496
3497    // Make name strings
3498    idx = 0;
3499    wd->src_tile_names  = calloc((eina_list_count(wd->src_tiles) + 1),
3500                                 sizeof(char *));
3501    EINA_LIST_FOREACH(wd->src_tiles, l, s)
3502      {
3503         eina_stringshare_replace(&wd->src_tile_names[idx], s->name);
3504         INF("source : %s", wd->src_tile_names[idx]);
3505         idx++;
3506      }
3507 }
3508
3509 static void
3510 _source_tile_set(Widget_Data *wd, const char *source_name)
3511 {
3512    EINA_SAFETY_ON_NULL_RETURN(wd);
3513    EINA_SAFETY_ON_NULL_RETURN(source_name);
3514    Source_Tile *s;
3515    Eina_List *l;
3516
3517    if (wd->src_tile && !strcmp(wd->src_tile->name, source_name)) return;
3518
3519    EINA_LIST_FOREACH(wd->src_tiles, l, s)
3520      {
3521         if (!strcmp(s->name, source_name))
3522           {
3523              wd->src_tile = s;
3524              break;
3525           }
3526      }
3527    if (!wd->src_tile)
3528      {
3529         ERR("source name (%s) is not found", source_name);
3530         return;
3531      }
3532
3533    if (wd->src_tile->zoom_max < wd->zoom)
3534       wd->zoom = wd->src_tile->zoom_max;
3535    else if (wd->src_tile->zoom_min > wd->zoom)
3536       wd->zoom = wd->src_tile->zoom_min;
3537
3538    if (wd->src_tile->zoom_max < wd->zoom_max)
3539       wd->zoom_max = wd->src_tile->zoom_max;
3540    if (wd->src_tile->zoom_min > wd->zoom_min)
3541       wd->zoom_min = wd->src_tile->zoom_min;
3542
3543    _grid_all_clear(wd);
3544    _grid_all_create(wd);
3545    zoom_do(wd, wd->zoom);
3546 }
3547
3548 static Eina_Bool
3549 _source_route_mod_cb(Eina_Module *m, void *data)
3550 {
3551    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3552
3553    Widget_Data *wd = data;
3554    Source_Route *s;
3555    Elm_Map_Module_Source_Name_Func name_cb;
3556    Elm_Map_Module_Route_Url_Func url_cb;
3557    const char *file;
3558
3559    file = eina_module_file_get(m);
3560    if (!eina_module_load(m))
3561      {
3562         ERR("Could not load module \"%s\": %s", file,
3563             eina_error_msg_get(eina_error_get()));
3564         return EINA_FALSE;
3565      }
3566
3567    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3568    url_cb = eina_module_symbol_get(m, "map_module_route_url_get");
3569
3570    if ((!name_cb) || (!url_cb))
3571      {
3572         WRN("Could not find map module functions from module \"%s\": %s",
3573             file, eina_error_msg_get(eina_error_get()));
3574         eina_module_unload(m);
3575         return EINA_FALSE;
3576      }
3577    s = ELM_NEW(Source_Tile);
3578    s->name = name_cb();
3579    s->url_cb = url_cb;
3580    wd->src_routes = eina_list_append(wd->src_routes, s);
3581
3582    eina_module_unload(m);
3583    return EINA_TRUE;
3584 }
3585
3586 static void
3587 _source_route_load(Widget_Data *wd)
3588 {
3589    unsigned int idx;
3590    Eina_List *l;
3591    Source_Route *s;
3592    Eina_Array *modules = NULL;
3593
3594    // Load from hard coded data
3595    for (idx = 0; idx < (sizeof(src_routes) / sizeof(Source_Route)); idx++)
3596      {
3597         s= ELM_NEW(Source_Route);
3598         s->name = src_routes[idx].name;
3599         s->url_cb = src_routes[idx].url_cb;
3600         wd->src_routes = eina_list_append(wd->src_routes, s);
3601      }
3602
3603    // Load from modules
3604    modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_route_mod_cb, wd);
3605    eina_array_free(modules);
3606
3607    // Set default source
3608    wd->src_route = eina_list_nth(wd->src_routes, 0);
3609
3610    // Make name strings
3611    idx = 0;
3612    wd->src_route_names  = calloc((eina_list_count(wd->src_routes) + 1),
3613                                    sizeof(char *));
3614    EINA_LIST_FOREACH(wd->src_routes, l, s)
3615      {
3616         eina_stringshare_replace(&wd->src_route_names[idx], s->name);
3617         INF("source : %s", wd->src_route_names[idx]);
3618         idx++;
3619      }
3620 }
3621
3622 static void
3623 _source_route_set(Widget_Data *wd, const char *source_name)
3624 {
3625    EINA_SAFETY_ON_NULL_RETURN(wd);
3626    EINA_SAFETY_ON_NULL_RETURN(source_name);
3627    Source_Route *s;
3628    Eina_List *l;
3629
3630    if (wd->src_route && !strcmp(wd->src_route->name, source_name)) return;
3631
3632    EINA_LIST_FOREACH(wd->src_routes, l, s)
3633      {
3634         if (!strcmp(s->name, source_name))
3635           {
3636              wd->src_route = s;
3637              break;
3638           }
3639      }
3640    if (!wd->src_route)
3641      {
3642         ERR("source name (%s) is not found", source_name);
3643         return;
3644      }
3645 }
3646
3647 static Eina_Bool
3648 _source_name_mod_cb(Eina_Module *m, void *data)
3649 {
3650    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
3651
3652    Widget_Data *wd = data;
3653    Source_Name *s;
3654    Elm_Map_Module_Source_Name_Func name_cb;
3655    Elm_Map_Module_Name_Url_Func url_cb;
3656    const char *file;
3657
3658    file = eina_module_file_get(m);
3659    if (!eina_module_load(m))
3660      {
3661         ERR("Could not load module \"%s\": %s", file,
3662             eina_error_msg_get(eina_error_get()));
3663         return EINA_FALSE;
3664      }
3665
3666    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
3667    url_cb = eina_module_symbol_get(m, "map_module_name_url_get");
3668
3669    if ((!name_cb) || (!url_cb))
3670      {
3671         WRN("Could not find map module functions from module \"%s\": %s",
3672             file, eina_error_msg_get(eina_error_get()));
3673         eina_module_unload(m);
3674         return EINA_FALSE;
3675      }
3676    s = ELM_NEW(Source_Tile);
3677    s->name = name_cb();
3678    s->url_cb = url_cb;
3679    wd->src_names = eina_list_append(wd->src_names, s);
3680
3681    eina_module_unload(m);
3682    return EINA_TRUE;
3683 }
3684
3685 static void
3686 _source_name_load(Widget_Data *wd)
3687 {
3688    unsigned int idx;
3689    Eina_List *l;
3690    Source_Name *s;
3691    Eina_Array *modules = NULL;
3692
3693    // Load from hard coded data
3694    for (idx = 0; idx < (sizeof(src_names) / sizeof(Source_Name)); idx++)
3695      {
3696         s= ELM_NEW(Source_Name);
3697         s->name = src_names[idx].name;
3698         s->url_cb = src_names[idx].url_cb;
3699         wd->src_names = eina_list_append(wd->src_names, s);
3700      }
3701
3702    // Load from modules
3703    modules = eina_module_list_get(modules, MODULES_PATH, 1, &_source_name_mod_cb, wd);
3704    eina_array_free(modules);
3705
3706    // Set default source
3707    wd->src_name = eina_list_nth(wd->src_names, 0);
3708
3709    // Make name strings
3710    idx = 0;
3711    wd->src_name_names  = calloc((eina_list_count(wd->src_names) + 1),
3712                                    sizeof(char *));
3713    EINA_LIST_FOREACH(wd->src_names, l, s)
3714      {
3715         eina_stringshare_replace(&wd->src_name_names[idx], s->name);
3716         INF("source : %s", wd->src_name_names[idx]);
3717         idx++;
3718      }
3719 }
3720
3721 static void
3722 _source_name_set(Widget_Data *wd, const char *source_name)
3723 {
3724    EINA_SAFETY_ON_NULL_RETURN(wd);
3725    EINA_SAFETY_ON_NULL_RETURN(source_name);
3726
3727    Source_Name *s;
3728    Eina_List *l;
3729
3730    if (wd->src_name && !strcmp(wd->src_name->name, source_name)) return;
3731
3732    EINA_LIST_FOREACH(wd->src_names, l, s)
3733      {
3734         if (!strcmp(s->name, source_name))
3735           {
3736              wd->src_name = s;
3737              break;
3738           }
3739      }
3740    if (!wd->src_name)
3741      {
3742         ERR("source name (%s) is not found", source_name);
3743         return;
3744      }
3745 }
3746
3747 static void
3748 _source_all_load(Widget_Data *wd)
3749 {
3750    EINA_SAFETY_ON_NULL_RETURN(wd);
3751    _source_tile_load(wd);
3752    _source_route_load(wd);
3753    _source_name_load(wd);
3754 }
3755
3756 static void
3757 _zoom_mode_set(void *data)
3758 {
3759    EINA_SAFETY_ON_NULL_RETURN(data);
3760    Delayed_Data *dd = data;
3761
3762    dd->wd->mode = dd->mode;
3763    if (dd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3764      {
3765         Evas_Coord w, h;
3766         Evas_Coord vw, vh;
3767
3768         double zoom;
3769         double diff;
3770
3771         w = dd->wd->size.w;
3772         h = dd->wd->size.h;
3773         zoom = dd->wd->zoom_detail;
3774         _viewport_size_get(dd->wd, &vw, &vh);
3775
3776         if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3777           {
3778              if ((w < vw) && (h < vh))
3779                {
3780                   diff = 0.01;
3781                   while ((w < vw) && (h < vh))
3782                   {
3783                      zoom += diff;
3784                      w = pow(2.0, zoom) * dd->wd->tsize;
3785                      h = pow(2.0, zoom) * dd->wd->tsize;
3786                   }
3787                }
3788              else
3789                {
3790                   diff = -0.01;
3791                   while ((w > vw) || (h > vh))
3792                   {
3793                      zoom += diff;
3794                      w = pow(2.0, zoom) * dd->wd->tsize;
3795                      h = pow(2.0, zoom) * dd->wd->tsize;
3796                   }
3797                }
3798
3799           }
3800         else if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3801           {
3802              if ((w < vw) || (h < vh))
3803                {
3804                   diff = 0.01;
3805                   while ((w < vw) || (h < vh))
3806                   {
3807                      zoom += diff;
3808                      w = pow(2.0, zoom) * dd->wd->tsize;
3809                      h = pow(2.0, zoom) * dd->wd->tsize;
3810                   }
3811                }
3812              else
3813                {
3814                   diff = -0.01;
3815                   while ((w > vw) && (h > vh))
3816                   {
3817                      zoom += diff;
3818                      w = pow(2.0, zoom) * dd->wd->tsize;
3819                      h = pow(2.0, zoom) * dd->wd->tsize;
3820                   }
3821                }
3822           }
3823        zoom_with_animation(dd->wd, zoom, 10);
3824      }
3825 }
3826
3827 static void
3828 _zoom_set(void *data)
3829 {
3830    EINA_SAFETY_ON_NULL_RETURN(data);
3831    Delayed_Data *dd = data;
3832
3833    if (dd->wd->paused) zoom_do(dd->wd, dd->zoom);
3834    else zoom_with_animation(dd->wd, dd->zoom, 10);
3835    evas_object_smart_changed(dd->wd->pan_smart);
3836 }
3837
3838 static void
3839 _region_bring_in(void *data)
3840 {
3841    EINA_SAFETY_ON_NULL_RETURN(data);
3842    Delayed_Data *dd = data;
3843    int x, y, w, h;
3844
3845    _geo_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
3846    _viewport_size_get(dd->wd, &w, &h);
3847    x = x - (w / 2);
3848    y = y - (h / 2);
3849    elm_smart_scroller_region_bring_in(dd->wd->scr, x, y, w, h);
3850    evas_object_smart_changed(dd->wd->pan_smart);
3851 }
3852
3853 static void
3854 _marker_list_show(void *data)
3855 {
3856    EINA_SAFETY_ON_NULL_RETURN(data);
3857    Delayed_Data *dd = data;
3858    int zoom;
3859    double max_lon = -180, min_lon = 180;
3860    double max_lat = -90, min_lat = 90;
3861    Evas_Coord vw, vh;
3862    Elm_Map_Marker *marker;
3863
3864    EINA_LIST_FREE(dd->markers, marker)
3865      {
3866         if (marker->longitude > max_lon) max_lon = marker->longitude;
3867         if (marker->longitude < min_lon) min_lon = marker->longitude;
3868         if (marker->latitude > max_lat) max_lat = marker->latitude;
3869         if (marker->latitude < min_lat) min_lat = marker->latitude;
3870      }
3871    dd->lon = (max_lon + min_lon) / 2;
3872    dd->lat = (max_lat + min_lat) / 2;
3873
3874    zoom = dd->wd->src_tile->zoom_min;
3875    _viewport_size_get(dd->wd, &vw, &vh);
3876    while (zoom <= dd->wd->src_tile->zoom_max)
3877      {
3878         Evas_Coord size, max_x, max_y, min_x, min_y;
3879         size = pow(2.0, zoom) * dd->wd->tsize;
3880         _geo_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
3881         _geo_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
3882         if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
3883         zoom++;
3884      }
3885    zoom--;
3886
3887    zoom_do(dd->wd, zoom);
3888    _region_show(dd);
3889    evas_object_smart_changed(dd->wd->pan_smart);
3890 }
3891
3892 static char *
3893 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3894 {
3895    char buf[PATH_MAX];
3896    // ((x+y+zoom)%3)+'a' is requesting map images from distributed tile servers (eg., a, b, c)
3897    snprintf(buf, sizeof(buf), "http://%c.tile.openstreetmap.org/%d/%d/%d.png",
3898             ((x + y + zoom) % 3) + 'a', zoom, x, y);
3899    return strdup(buf);
3900 }
3901
3902 static char *
3903 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3904 {
3905    char buf[PATH_MAX];
3906    snprintf(buf, sizeof(buf),
3907             "http://%c.tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
3908             ((x + y + zoom) % 3) + 'a', zoom, x, y);
3909    return strdup(buf);
3910 }
3911
3912 static char *
3913 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3914 {
3915    char buf[PATH_MAX];
3916    snprintf(buf, sizeof(buf),
3917             "http://%c.tile.opencyclemap.org/cycle/%d/%d/%d.png",
3918             (( x + y + zoom) % 3) + 'a', zoom, x, y);
3919    return strdup(buf);
3920 }
3921
3922 static char *
3923 _mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3924 {
3925    char buf[PATH_MAX];
3926    snprintf(buf, sizeof(buf),
3927             "http://otile%d.mqcdn.com/tiles/1.0.0/osm/%d/%d/%d.png",
3928             ((x + y + zoom) % 4) + 1, zoom, x, y);
3929    return strdup(buf);
3930 }
3931
3932 static char *
3933 _mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
3934 {
3935    char buf[PATH_MAX];
3936    snprintf(buf, sizeof(buf), "http://oatile%d.mqcdn.com/naip/%d/%d/%d.png",
3937            ((x + y + zoom) % 4) + 1, zoom, x, y);
3938    return strdup(buf);
3939 }
3940
3941 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat)
3942 {
3943    char buf[PATH_MAX];
3944    snprintf(buf, sizeof(buf),
3945             "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
3946             ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
3947
3948    return strdup(buf);
3949 }
3950
3951 // TODO: fix monav api
3952 /*
3953 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
3954 {
3955    char buf[PATH_MAX];
3956    snprintf(buf, sizeof(buf),
3957             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
3958             ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
3959
3960    return strdup(buf);
3961 }
3962 */
3963
3964 // TODO: fix ors api
3965 /*
3966 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
3967 {
3968    char buf[PATH_MAX];
3969    snprintf(buf, sizeof(buf),
3970             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
3971             ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
3972
3973    return strdup(buf);
3974 }
3975 */
3976
3977 static char *
3978 _nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat)
3979 {
3980    ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
3981    Widget_Data *wd = elm_widget_data_get(obj);
3982    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, strdup(""));
3983
3984    char **str;
3985    unsigned int ele, idx;
3986    char search_url[PATH_MAX];
3987    char buf[PATH_MAX];
3988
3989    if (method == ELM_MAP_NAME_METHOD_SEARCH)
3990      {
3991         search_url[0] = '\0';
3992         str = eina_str_split_full(name, " ", 0, &ele);
3993         for (idx = 0; idx < ele; idx++)
3994           {
3995              eina_strlcat(search_url, str[idx], sizeof(search_url));
3996              if (!(idx == (ele-1)))
3997                 eina_strlcat(search_url, "+", sizeof(search_url));
3998           }
3999         snprintf(buf, sizeof(buf),
4000                  "%s/search?q=%s&format=xml&polygon=0&addressdetails=0",
4001                  NAME_NOMINATIM_URL, search_url);
4002
4003         if (str && str[0])
4004           {
4005              free(str[0]);
4006              free(str);
4007           }
4008      }
4009    else if (method == ELM_MAP_NAME_METHOD_REVERSE)
4010       snprintf(buf, sizeof(buf),
4011                "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0",
4012                NAME_NOMINATIM_URL, lat, lon, (int)wd->zoom);
4013    else strcpy(buf, "");
4014
4015    return strdup(buf);
4016 }
4017
4018
4019
4020 #endif
4021
4022 EAPI Evas_Object *
4023 elm_map_add(Evas_Object *parent)
4024 {
4025 #ifdef HAVE_ELEMENTARY_ECORE_CON
4026    Evas *e;
4027    Widget_Data *wd;
4028    Evas_Object *obj;
4029    Evas_Coord minw, minh;
4030
4031    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
4032    ELM_SET_WIDTYPE(widtype, "map");
4033    elm_widget_type_set(obj, "map");
4034    elm_widget_sub_object_add(parent, obj);
4035    elm_widget_data_set(obj, wd);
4036    elm_widget_can_focus_set(obj, EINA_TRUE);
4037    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
4038    elm_widget_del_hook_set(obj, _del_hook);
4039    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
4040    elm_widget_theme_hook_set(obj, _theme_hook);
4041    elm_widget_event_hook_set(obj, _event_hook);
4042    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, wd);
4043    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, wd);
4044    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, wd);
4045    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, wd);
4046    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
4047                                   _mouse_down, wd);
4048    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
4049                                   _mouse_up, wd);
4050    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
4051                                   _mouse_wheel_cb,wd);
4052    wd->obj = obj;
4053
4054    wd->scr = elm_smart_scroller_add(e);
4055    elm_widget_sub_object_add(obj, wd->scr);
4056    elm_smart_scroller_widget_set(wd->scr, obj);
4057    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
4058    elm_widget_resize_object_set(obj, wd->scr);
4059    elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
4060    elm_smart_scroller_bounce_allow_set(wd->scr,
4061                                        _elm_config->thumbscroll_bounce_enable,
4062                                        _elm_config->thumbscroll_bounce_enable);
4063    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
4064                                   _changed_size_hints, wd);
4065    evas_object_smart_callback_add(wd->scr, "scroll", _scr, wd);
4066    evas_object_smart_callback_add(wd->scr, "drag", _scr, wd);
4067    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, wd);
4068    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, wd);
4069
4070    if (!smart)
4071      {
4072         evas_object_smart_clipped_smart_set(&parent_sc);
4073         sc = parent_sc;
4074         sc.name = "elm_map_pan";
4075         sc.version = EVAS_SMART_CLASS_VERSION;
4076         sc.add = _pan_add;
4077         sc.resize = _pan_resize;
4078         sc.move = _pan_move;
4079         sc.calculate = _pan_calculate;
4080         smart = evas_smart_class_new(&sc);
4081      }
4082    if (smart)
4083      {
4084         Pan *pan;
4085         wd->pan_smart = evas_object_smart_add(e, smart);
4086         pan = evas_object_smart_data_get(wd->pan_smart);
4087         pan->wd = wd;
4088      }
4089    elm_widget_sub_object_add(obj, wd->pan_smart);
4090
4091    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
4092                                      _pan_set, _pan_get, _pan_max_get,
4093                                      _pan_min_get, _pan_child_size_get);
4094    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
4095                              &minw, &minh);
4096    evas_object_size_hint_min_set(obj, minw, minh);
4097
4098    wd->ges = elm_gesture_layer_add(obj);
4099    if (!wd->ges) ERR("elm_gesture_layer_add() failed");
4100    elm_gesture_layer_attach(wd->ges, obj);
4101    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
4102                             _pinch_zoom_start_cb, wd);
4103    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
4104                             _pinch_zoom_cb, wd);
4105    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE,
4106                             _pinch_rotate_cb, wd);
4107    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END,
4108                             _pinch_rotate_end_cb, wd);
4109    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT,
4110                             _pinch_rotate_end_cb, wd);
4111
4112    wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
4113    elm_widget_sub_object_add(obj, wd->sep_maps_markers);
4114    evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
4115
4116    wd->map = evas_map_new(EVAS_MAP_POINT);
4117
4118    _source_all_load(wd);
4119    wd->zoom_min = wd->src_tile->zoom_min;
4120    wd->zoom_max = wd->src_tile->zoom_max;
4121    // FIXME: Tile Provider is better to provide tile size!
4122    wd->tsize = DEFAULT_TILE_SIZE;
4123
4124    srand(time(NULL));
4125
4126    wd->id = ((int)getpid() << 16) | idnum;
4127    idnum++;
4128    _grid_all_create(wd);
4129
4130    zoom_do(wd, 0);
4131
4132    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
4133    wd->markers_max_num = MARER_MAX_NUMBER;
4134
4135    // TODO: convert Elementary to subclassing of Evas_Smart_Class
4136    // TODO: and save some bytes, making descriptions per-class and not instance!
4137    evas_object_smart_callbacks_descriptions_set(obj, _signals);
4138
4139    if (!ecore_file_download_protocol_available("http://"))
4140       ERR("Ecore must be built with curl support for the map widget!");
4141
4142    return obj;
4143 #else
4144    (void) parent;
4145    return NULL;
4146 #endif
4147 }
4148
4149 EAPI void
4150 elm_map_zoom_set(Evas_Object *obj, int zoom)
4151 {
4152 #ifdef HAVE_ELEMENTARY_ECORE_CON
4153    ELM_CHECK_WIDTYPE(obj, widtype);
4154    Widget_Data *wd = elm_widget_data_get(obj);
4155    EINA_SAFETY_ON_NULL_RETURN(wd);
4156    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4157
4158    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL) return;
4159    if (zoom < 0) zoom = 0;
4160    if (wd->zoom == zoom) return;
4161    if (zoom > wd->src_tile->zoom_max) zoom = wd->src_tile->zoom_max;
4162    if (zoom < wd->src_tile->zoom_min) zoom = wd->src_tile->zoom_min;
4163
4164    Delayed_Data *data = ELM_NEW(Delayed_Data);
4165    data->func = _zoom_set;
4166    data->wd = wd;
4167    data->zoom = zoom;
4168    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4169    evas_object_smart_changed(data->wd->pan_smart);
4170 #else
4171    (void) obj;
4172    (void) zoom;
4173 #endif
4174 }
4175
4176 EAPI int
4177 elm_map_zoom_get(const Evas_Object *obj)
4178 {
4179 #ifdef HAVE_ELEMENTARY_ECORE_CON
4180    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4181    Widget_Data *wd = elm_widget_data_get(obj);
4182
4183    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, 0);
4184    return wd->zoom;
4185 #else
4186    (void) obj;
4187    return 0;
4188 #endif
4189 }
4190
4191 EAPI void
4192 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
4193 {
4194 #ifdef HAVE_ELEMENTARY_ECORE_CON
4195    ELM_CHECK_WIDTYPE(obj, widtype);
4196    Widget_Data *wd = elm_widget_data_get(obj);
4197    EINA_SAFETY_ON_NULL_RETURN(wd);
4198
4199    if ((mode == ELM_MAP_ZOOM_MODE_MANUAL) && (wd->mode == !!mode)) return;
4200
4201    Delayed_Data *data = ELM_NEW(Delayed_Data);
4202    data->mode = mode;
4203    data->func = _zoom_mode_set;
4204    data->wd = wd;
4205    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4206    evas_object_smart_changed(data->wd->pan_smart);
4207 #else
4208    (void) obj;
4209    (void) mode;
4210 #endif
4211 }
4212
4213 EAPI Elm_Map_Zoom_Mode
4214 elm_map_zoom_mode_get(const Evas_Object *obj)
4215 {
4216 #ifdef HAVE_ELEMENTARY_ECORE_CON
4217    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
4218    Widget_Data *wd = elm_widget_data_get(obj);
4219    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ELM_MAP_ZOOM_MODE_MANUAL);
4220
4221    return wd->mode;
4222 #else
4223    (void) obj;
4224    return ELM_MAP_ZOOM_MODE_MANUAL;
4225 #endif
4226 }
4227
4228 EAPI void
4229 elm_map_zoom_max_set(Evas_Object *obj, int zoom)
4230 {
4231 #ifdef HAVE_ELEMENTARY_ECORE_CON
4232    ELM_CHECK_WIDTYPE(obj, widtype);
4233    Widget_Data *wd = elm_widget_data_get(obj);
4234    EINA_SAFETY_ON_NULL_RETURN(wd);
4235    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4236
4237    if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
4238       return;
4239    wd->zoom_max = zoom;
4240 #else
4241    (void) obj;
4242    (void) zoom;
4243 #endif
4244 }
4245
4246 EAPI int
4247 elm_map_zoom_max_get(const Evas_Object *obj)
4248 {
4249 #ifdef HAVE_ELEMENTARY_ECORE_CON
4250    ELM_CHECK_WIDTYPE(obj, widtype) 18;
4251    Widget_Data *wd = elm_widget_data_get(obj);
4252    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
4253    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
4254
4255    return wd->zoom_max;
4256 #else
4257    (void) obj;
4258    return 18;
4259 #endif
4260 }
4261
4262 EAPI void
4263 elm_map_zoom_min_set(Evas_Object *obj, int zoom)
4264 {
4265 #ifdef HAVE_ELEMENTARY_ECORE_CON
4266    ELM_CHECK_WIDTYPE(obj, widtype);
4267    Widget_Data *wd = elm_widget_data_get(obj);
4268    EINA_SAFETY_ON_NULL_RETURN(wd);
4269    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
4270
4271    if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
4272       return;
4273    wd->zoom_min = zoom;
4274 #else
4275    (void) obj;
4276    (void) zoom;
4277 #endif
4278 }
4279
4280 EAPI int
4281 elm_map_zoom_min_get(const Evas_Object *obj)
4282 {
4283 #ifdef HAVE_ELEMENTARY_ECORE_CON
4284    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4285    Widget_Data *wd = elm_widget_data_get(obj);
4286    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
4287    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
4288
4289    return wd->zoom_min;
4290 #else
4291    (void) obj;
4292    return 0;
4293 #endif
4294 }
4295
4296
4297 EAPI void
4298 elm_map_region_bring_in(Evas_Object *obj, double lon, double lat)
4299 {
4300 #ifdef HAVE_ELEMENTARY_ECORE_CON
4301    ELM_CHECK_WIDTYPE(obj, widtype);
4302    Widget_Data *wd = elm_widget_data_get(obj);
4303
4304    Delayed_Data *data = ELM_NEW(Delayed_Data);
4305    data->func = _region_bring_in;
4306    data->wd = wd;
4307    data->lon = lon;
4308    data->lat = lat;
4309    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4310    evas_object_smart_changed(data->wd->pan_smart);
4311 #else
4312    (void) obj;
4313    (void) lon;
4314    (void) lat;
4315 #endif
4316 }
4317
4318 EAPI void
4319 elm_map_region_show(Evas_Object *obj, double lon, double lat)
4320 {
4321 #ifdef HAVE_ELEMENTARY_ECORE_CON
4322    ELM_CHECK_WIDTYPE(obj, widtype);
4323    Widget_Data *wd = elm_widget_data_get(obj);
4324
4325    Delayed_Data *data = ELM_NEW(Delayed_Data);
4326    data->func = _region_show;
4327    data->wd = wd;
4328    data->lon = lon;
4329    data->lat = lat;
4330    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
4331    evas_object_smart_changed(data->wd->pan_smart);
4332 #else
4333    (void) obj;
4334    (void) lon;
4335    (void) lat;
4336 #endif
4337 }
4338
4339 EAPI void
4340 elm_map_region_get(const Evas_Object *obj, double *lon, double *lat)
4341 {
4342 #ifdef HAVE_ELEMENTARY_ECORE_CON
4343    ELM_CHECK_WIDTYPE(obj, widtype);
4344    Widget_Data *wd = elm_widget_data_get(obj);
4345    EINA_SAFETY_ON_NULL_RETURN(wd);
4346
4347    double tlon, tlat;
4348    Evas_Coord px, py, vw, vh;
4349
4350    _pan_geometry_get(wd, &px, &py);
4351    _viewport_size_get(wd, &vw, &vh);
4352    _coord_to_region_convert(wd, vw/2 - px, vh/2 -py, wd->size.w, &tlon, &tlat);
4353    if (lon) *lon = tlon;
4354    if (lat) *lat = tlat;
4355 #else
4356    (void) obj;
4357    (void) lon;
4358    (void) lat;
4359 #endif
4360 }
4361
4362 EAPI void
4363 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
4364 {
4365 #ifdef HAVE_ELEMENTARY_ECORE_CON
4366    ELM_CHECK_WIDTYPE(obj, widtype);
4367    Widget_Data *wd = elm_widget_data_get(obj);
4368    EINA_SAFETY_ON_NULL_RETURN(wd);
4369
4370    if (wd->paused == !!paused) return;
4371    wd->paused = !!paused;
4372    if (wd->paused)
4373      {
4374         if (wd->zoom_animator)
4375           {
4376              if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
4377              wd->zoom_animator = NULL;
4378              zoom_do(wd, wd->zoom);
4379           }
4380         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4381                                 "elm,state,busy,stop", "elm");
4382      }
4383    else
4384      {
4385         if (wd->download_num >= 1)
4386            edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4387                                    "elm,state,busy,start", "elm");
4388      }
4389 #else
4390    (void) obj;
4391    (void) paused;
4392 #endif
4393 }
4394
4395 EAPI Eina_Bool
4396 elm_map_paused_get(const Evas_Object *obj)
4397 {
4398 #ifdef HAVE_ELEMENTARY_ECORE_CON
4399    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4400    Widget_Data *wd = elm_widget_data_get(obj);
4401    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
4402
4403    return wd->paused;
4404 #else
4405    (void) obj;
4406    return EINA_FALSE;
4407 #endif
4408 }
4409
4410 EAPI void
4411 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
4412 {
4413 #ifdef HAVE_ELEMENTARY_ECORE_CON
4414    ELM_CHECK_WIDTYPE(obj, widtype);
4415    Widget_Data *wd = elm_widget_data_get(obj);
4416    EINA_SAFETY_ON_NULL_RETURN(wd);
4417
4418    wd->rotate.d = degree;
4419    wd->rotate.cx = cx;
4420    wd->rotate.cy = cy;
4421
4422    evas_object_smart_changed(wd->pan_smart);
4423 #else
4424    (void) obj;
4425    (void) degree;
4426    (void) cx;
4427    (void) cy;
4428 #endif
4429 }
4430
4431 EAPI void
4432 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
4433 {
4434 #ifdef HAVE_ELEMENTARY_ECORE_CON
4435    ELM_CHECK_WIDTYPE(obj, widtype);
4436    Widget_Data *wd = elm_widget_data_get(obj);
4437    EINA_SAFETY_ON_NULL_RETURN(wd);
4438
4439    if (degree) *degree = wd->rotate.d;
4440    if (cx) *cx = wd->rotate.cx;
4441    if (cy) *cy = wd->rotate.cy;
4442 #else
4443    (void) obj;
4444    (void) degree;
4445    (void) cx;
4446    (void) cy;
4447 #endif
4448 }
4449
4450 EAPI void
4451 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4452 {
4453 #ifdef HAVE_ELEMENTARY_ECORE_CON
4454    ELM_CHECK_WIDTYPE(obj, widtype);
4455    Widget_Data *wd = elm_widget_data_get(obj);
4456    EINA_SAFETY_ON_NULL_RETURN(wd);
4457
4458    if ((!wd->wheel_disabled) && (disabled))
4459      evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4460    else if ((wd->wheel_disabled) && (!disabled))
4461      evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4462    wd->wheel_disabled = !!disabled;
4463 #else
4464    (void) obj;
4465    (void) disabled;
4466 #endif
4467 }
4468
4469 EAPI Eina_Bool
4470 elm_map_wheel_disabled_get(const Evas_Object *obj)
4471 {
4472 #ifdef HAVE_ELEMENTARY_ECORE_CON
4473    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4474    Widget_Data *wd = elm_widget_data_get(obj);
4475    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
4476
4477    return wd->wheel_disabled;
4478 #else
4479    (void) obj;
4480    return EINA_FALSE;
4481 #endif
4482 }
4483
4484 EAPI void
4485 elm_map_tile_load_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
4486 {
4487 #ifdef HAVE_ELEMENTARY_ECORE_CON
4488    ELM_CHECK_WIDTYPE(obj, widtype);
4489    Widget_Data *wd = elm_widget_data_get(obj);
4490    EINA_SAFETY_ON_NULL_RETURN(wd);
4491
4492    if (try_num) *try_num = wd->try_num;
4493    if (finish_num) *finish_num = wd->finish_num;
4494 #else
4495    (void) obj;
4496    (void) try_num;
4497    (void) finish_num;
4498 #endif
4499 }
4500
4501 EAPI void
4502 elm_map_canvas_to_region_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
4503 {
4504 #ifdef HAVE_ELEMENTARY_ECORE_CON
4505    ELM_CHECK_WIDTYPE(obj, widtype);
4506    Widget_Data *wd = elm_widget_data_get(obj);
4507    EINA_SAFETY_ON_NULL_RETURN(wd);
4508    EINA_SAFETY_ON_NULL_RETURN(lon);
4509    EINA_SAFETY_ON_NULL_RETURN(lat);
4510
4511    Evas_Coord px, py, vw, vh;
4512    _pan_geometry_get(wd, &px, &py);
4513    _viewport_size_get(wd, &vw, &vh);
4514    _coord_rotate(x - px, y - py, (vw / 2) - px, (vh / 2) - py, -wd->rotate.d,
4515                  &x, &y);
4516    _coord_to_region_convert(wd, x, y, wd->size.w, lon, lat);
4517 #else
4518    (void) obj;
4519    (void) x;
4520    (void) y;
4521    (void) lon;
4522    (void) lat;
4523 #endif
4524 }
4525
4526 // FIXME: Make it!
4527 /*
4528 EAPI void
4529 elm_map_region_to_canvas_convert(const Evas_Object *obj, double lon, double lat, Evas_Coord *x, Evas_Coord *y)
4530 {
4531 #ifdef HAVE_ELEMENTARY_ECORE_CON
4532    ELM_CHECK_WIDTYPE(obj, widtype);
4533    Widget_Data *wd = elm_widget_data_get(obj);
4534    EINA_SAFETY_ON_NULL_RETURN(wd);
4535    EINA_SAFETY_ON_NULL_RETURN(x);
4536    EINA_SAFETY_ON_NULL_RETURN(y);
4537
4538 #else
4539    (void) obj;
4540    (void) lon;
4541    (void) lat;
4542    (void) x;
4543    (void) y;
4544 #endif
4545 }*/
4546
4547 EAPI void
4548 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4549 {
4550 #ifdef HAVE_ELEMENTARY_ECORE_CON
4551    ELM_CHECK_WIDTYPE(obj, widtype);
4552    Widget_Data *wd = elm_widget_data_get(obj);
4553    EINA_SAFETY_ON_NULL_RETURN(wd);
4554    EINA_SAFETY_ON_NULL_RETURN(user_agent);
4555
4556    eina_stringshare_replace(&wd->user_agent, user_agent);
4557
4558    if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4559    eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4560 #else
4561    (void) obj;
4562    (void) user_agent;
4563 #endif
4564 }
4565
4566 EAPI const char *
4567 elm_map_user_agent_get(const Evas_Object *obj)
4568 {
4569 #ifdef HAVE_ELEMENTARY_ECORE_CON
4570    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4571    Widget_Data *wd = elm_widget_data_get(obj);
4572    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4573
4574    return wd->user_agent;
4575 #else
4576    (void) obj;
4577    return NULL;
4578 #endif
4579 }
4580
4581 EAPI void
4582 elm_map_source_set(Evas_Object *obj, Elm_Map_Source_Type type, const char *source_name)
4583 {
4584 #ifdef HAVE_ELEMENTARY_ECORE_CON
4585    ELM_CHECK_WIDTYPE(obj, widtype);
4586    Widget_Data *wd = elm_widget_data_get(obj);
4587    EINA_SAFETY_ON_NULL_RETURN(wd);
4588    EINA_SAFETY_ON_NULL_RETURN(source_name);
4589
4590    if (type == ELM_MAP_SOURCE_TYPE_TILE) _source_tile_set(wd, source_name);
4591    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE)
4592       _source_route_set(wd, source_name);
4593    else if (type == ELM_MAP_SOURCE_TYPE_NAME) _source_name_set(wd, source_name);
4594    else ERR("Not supported map source type: %d", type);
4595
4596 #else
4597    (void) obj;
4598    (void) source_name;
4599 #endif
4600 }
4601
4602 EAPI const char *
4603 elm_map_source_get(const Evas_Object *obj, Elm_Map_Source_Type type)
4604 {
4605 #ifdef HAVE_ELEMENTARY_ECORE_CON
4606    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4607    Widget_Data *wd = elm_widget_data_get(obj);
4608    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4609    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, NULL);
4610
4611    if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile->name;
4612    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route->name;
4613    else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_name->name;
4614    else ERR("Not supported map source type: %d", type);
4615    return NULL;
4616 #else
4617    (void) obj;
4618    return NULL;
4619 #endif
4620 }
4621
4622 EAPI const char **
4623 elm_map_sources_get(const Evas_Object *obj, Elm_Map_Source_Type type)
4624 {
4625 #ifdef HAVE_ELEMENTARY_ECORE_CON
4626    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4627    Widget_Data *wd = elm_widget_data_get(obj);
4628    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4629
4630    if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile_names;
4631    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route_names;
4632    else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_tile_names;
4633    else ERR("Not supported map source type: %d", type);
4634    return NULL;
4635 #else
4636    (void) obj;
4637    return NULL;
4638 #endif
4639 }
4640
4641 EAPI Elm_Map_Route *
4642 elm_map_route_add(Evas_Object *obj, Elm_Map_Route_Type type, Elm_Map_Route_Method method, double flon, double flat, double tlon, double tlat, Elm_Map_Route_Cb route_cb, void *data)
4643 {
4644 #ifdef HAVE_ELEMENTARY_ECORE_CON
4645    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4646    Widget_Data *wd = elm_widget_data_get(obj);
4647    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4648    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_route, NULL);
4649
4650    char *type_name;
4651    char *url;
4652    char fname[PATH_MAX];
4653
4654    if (!ecore_file_exists(CACHE_ROUTE_ROOT))
4655       ecore_file_mkpath(CACHE_ROUTE_ROOT);
4656
4657    if (type == ELM_MAP_ROUTE_TYPE_MOTOCAR)
4658       type_name = strdup(ROUTE_TYPE_MOTORCAR);
4659    else if (type == ELM_MAP_ROUTE_TYPE_BICYCLE)
4660       type_name = strdup(ROUTE_TYPE_BICYCLE);
4661    else if (type == ELM_MAP_ROUTE_TYPE_FOOT)
4662       type_name = strdup(ROUTE_TYPE_FOOT);
4663    else type_name = NULL;
4664
4665    url = wd->src_route->url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4666    if (!url)
4667      {
4668         ERR("Route URL is NULL");
4669         if (type_name) free(type_name);
4670         return NULL;
4671      }
4672    if (type_name) free(type_name);
4673
4674    Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4675    route->wd = wd;
4676    snprintf(fname, sizeof(fname), CACHE_ROUTE_ROOT"/%d", rand());
4677    route->fname = strdup(fname);
4678    route->type = type;
4679    route->method = method;
4680    route->flon = flon;
4681    route->flat = flat;
4682    route->tlon = tlon;
4683    route->tlat = tlat;
4684    route->cb = route_cb;
4685    route->data = data;
4686
4687    if (!ecore_file_download_full(url, route->fname, _route_cb, NULL, route,
4688                                  &(route->job), wd->ua) || !(route->job))
4689      {
4690         ERR("Can't request Route from %s to %s", url, route->fname);
4691         free(route->fname);
4692         free(route);
4693         return NULL;
4694      }
4695    INF("Route requested from %s to %s", url, route->fname);
4696    free(url);
4697
4698    wd->routes = eina_list_append(wd->routes, route);
4699    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, route);
4700    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4701                            "elm,state,busy,start", "elm");
4702    return route;
4703 #else
4704    (void) obj;
4705    (void) type;
4706    (void) method;
4707    (void) flon;
4708    (void) flat;
4709    (void) tlon;
4710    (void) tlat;
4711    (void) route_cb;
4712    (void) data;
4713    return NULL;
4714 #endif
4715 }
4716
4717
4718 EAPI void
4719 elm_map_route_del(Elm_Map_Route *route)
4720 {
4721 #ifdef HAVE_ELEMENTARY_ECORE_CON
4722    EINA_SAFETY_ON_NULL_RETURN(route);
4723    EINA_SAFETY_ON_NULL_RETURN(route->wd);
4724    ELM_CHECK_WIDTYPE(route->wd->obj, widtype);
4725
4726    Path_Waypoint *w;
4727    Path_Node *n;
4728
4729    if (route->job) ecore_file_download_abort(route->job);
4730
4731    EINA_LIST_FREE(route->waypoint, w)
4732      {
4733         if (w->point) eina_stringshare_del(w->point);
4734         free(w);
4735      }
4736
4737    EINA_LIST_FREE(route->nodes, n)
4738      {
4739         if (n->pos.address) eina_stringshare_del(n->pos.address);
4740         free(n);
4741      }
4742
4743    if (route->fname)
4744      {
4745         ecore_file_remove(route->fname);
4746         free(route->fname);
4747      }
4748
4749    route->wd->routes = eina_list_remove(route->wd->routes, route);
4750    free(route);
4751 #else
4752    (void) route;
4753 #endif
4754 }
4755
4756 EAPI double
4757 elm_map_route_distance_get(const Elm_Map_Route *route)
4758 {
4759 #ifdef HAVE_ELEMENTARY_ECORE_CON
4760    EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
4761    return route->info.distance;
4762 #else
4763    (void) route;
4764    return 0.0;
4765 #endif
4766 }
4767
4768 EAPI const char*
4769 elm_map_route_node_get(const Elm_Map_Route *route)
4770 {
4771 #ifdef HAVE_ELEMENTARY_ECORE_CON
4772    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4773    return route->info.nodes;
4774 #else
4775    (void) route;
4776    return NULL;
4777 #endif
4778 }
4779
4780 EAPI const char*
4781 elm_map_route_waypoint_get(const Elm_Map_Route *route)
4782 {
4783 #ifdef HAVE_ELEMENTARY_ECORE_CON
4784    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4785    return route->info.waypoints;
4786 #else
4787    (void) route;
4788    return NULL;
4789 #endif
4790 }
4791
4792 EAPI Elm_Map_Name *
4793 elm_map_name_add(const Evas_Object *obj, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
4794 {
4795 #ifdef HAVE_ELEMENTARY_ECORE_CON
4796    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4797
4798    if (address)
4799       return _name_request(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0, 0,
4800                            name_cb, data);
4801   else
4802      return _name_request(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat,
4803                           name_cb, data);
4804 #else
4805    (void) obj;
4806    (void) address;
4807    (void) lon;
4808    (void) lat;
4809    (void) name_cb;
4810    (void) data;
4811    return NULL;
4812 #endif
4813 }
4814
4815 EAPI void
4816 elm_map_name_del(Elm_Map_Name *name)
4817 {
4818 #ifdef HAVE_ELEMENTARY_ECORE_CON
4819    EINA_SAFETY_ON_NULL_RETURN(name);
4820    EINA_SAFETY_ON_NULL_RETURN(name->wd);
4821    ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
4822
4823    if (name->job) ecore_file_download_abort(name->job);
4824    if (name->address) free(name->address);
4825    if (name->fname)
4826      {
4827         ecore_file_remove(name->fname);
4828         free(name->fname);
4829      }
4830
4831    name->wd->names = eina_list_remove(name->wd->names, name);
4832    free(name);
4833 #else
4834    (void) name;
4835 #endif
4836 }
4837
4838 EAPI const char *
4839 elm_map_name_address_get(const Elm_Map_Name *name)
4840 {
4841 #ifdef HAVE_ELEMENTARY_ECORE_CON
4842    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
4843    EINA_SAFETY_ON_NULL_RETURN_VAL(name->wd, NULL);
4844    ELM_CHECK_WIDTYPE(name->wd->obj, widtype) NULL;
4845
4846    return name->address;
4847 #else
4848    (void) name;
4849    return NULL;
4850 #endif
4851 }
4852
4853 EAPI void
4854 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
4855 {
4856 #ifdef HAVE_ELEMENTARY_ECORE_CON
4857    EINA_SAFETY_ON_NULL_RETURN(name);
4858    EINA_SAFETY_ON_NULL_RETURN(name->wd);
4859    ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
4860
4861    if (lon) *lon = name->lon;
4862    if (lat) *lat = name->lat;
4863 #else
4864    (void) name;
4865    (void) lon;
4866    (void) lat;
4867 #endif
4868 }
4869
4870 EAPI Elm_Map_Overlay *
4871 elm_map_overlay_add(Evas_Object *obj, double lon, double lat)
4872 {
4873 #ifdef HAVE_ELEMENTARY_ECORE_CON
4874    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4875    Widget_Data *wd = elm_widget_data_get(obj);
4876    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4877
4878    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
4879    overlay->wd = wd;
4880    overlay->type = ELM_MAP_OVERLAY_TYPE_DEFAULT;
4881    overlay->ovl = _overlay_default_new(wd, lon, lat, "radio");
4882    _overlay_default_cb_add(overlay->ovl, _overlay_clicked_cb, overlay);
4883    overlay->grp = _overlay_group_new(wd);
4884    wd->overlays = eina_list_append(wd->overlays, overlay);
4885
4886    evas_object_smart_changed(wd->pan_smart);
4887    return overlay;
4888 #else
4889    (void) obj;
4890    (void) lon;
4891    (void) lat;
4892    return NULL;
4893 #endif
4894 }
4895
4896 EAPI void
4897 elm_map_overlay_del(Elm_Map_Overlay *overlay)
4898 {
4899 #ifdef HAVE_ELEMENTARY_ECORE_CON
4900    EINA_SAFETY_ON_NULL_RETURN(overlay);
4901    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4902    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4903
4904    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
4905      {
4906         _overlay_default_cb_del(overlay->ovl, _overlay_clicked_cb);
4907         _overlay_default_free(overlay->ovl);
4908      }
4909    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
4910      {
4911         _overlay_bubble_cb_del(overlay->ovl);
4912         _overlay_bubble_free(overlay->ovl);
4913      }
4914    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
4915       _overlay_class_free(overlay->ovl);
4916
4917    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
4918       _overlay_route_free(overlay->ovl);
4919
4920    if (overlay->grp)
4921      {
4922         _overlay_group_cb_del(overlay->grp);
4923         _overlay_group_free(overlay->grp, overlay);
4924      }
4925
4926    overlay->wd->overlays = eina_list_remove(overlay->wd->overlays, overlay);
4927    evas_object_smart_changed(overlay->wd->pan_smart);
4928
4929    free(overlay);
4930 #else
4931    (void) overlay;
4932 #endif
4933 }
4934
4935 EAPI Elm_Map_Overlay_Type
4936 elm_map_overlay_type_get(const Elm_Map_Overlay *overlay)
4937 {
4938 #ifdef HAVE_ELEMENTARY_ECORE_CON
4939    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, ELM_MAP_OVERLAY_TYPE_NONE);
4940    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, ELM_MAP_OVERLAY_TYPE_NONE);
4941    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) ELM_MAP_OVERLAY_TYPE_NONE;
4942
4943    return overlay->type;
4944 #else
4945    (void) overlay;
4946    return OVERLAY_TYPE_NONE;
4947 #endif
4948 }
4949
4950 EAPI void
4951 elm_map_overlay_data_set(Elm_Map_Overlay *overlay, void *data)
4952 {
4953 #ifdef HAVE_ELEMENTARY_ECORE_CON
4954    EINA_SAFETY_ON_NULL_RETURN(overlay);
4955    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4956    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4957
4958    overlay->data = data;
4959 #else
4960    (void) overlay;
4961    (void) data;
4962 #endif
4963 }
4964
4965 EAPI void *
4966 elm_map_overlay_data_get(const Elm_Map_Overlay *overlay)
4967 {
4968 #ifdef HAVE_ELEMENTARY_ECORE_CON
4969    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
4970    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
4971    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
4972
4973    return overlay->data;
4974 #else
4975    (void) overlay;
4976    return NULL;
4977 #endif
4978 }
4979
4980 EAPI void
4981 elm_map_overlay_hide_set(Elm_Map_Overlay *overlay, Eina_Bool hide)
4982 {
4983 #ifdef HAVE_ELEMENTARY_ECORE_CON
4984    EINA_SAFETY_ON_NULL_RETURN(overlay);
4985    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
4986    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
4987
4988    if (overlay->hide == !!hide) return;
4989    overlay->hide = hide;
4990
4991    evas_object_smart_changed(overlay->wd->pan_smart);
4992 #else
4993    (void) overlay;
4994    (void) hide;
4995 #endif
4996 }
4997
4998 EAPI Eina_Bool
4999 elm_map_overlay_hide_get(const Elm_Map_Overlay *overlay)
5000 {
5001 #ifdef HAVE_ELEMENTARY_ECORE_CON
5002    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
5003    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
5004    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
5005
5006    return overlay->hide;
5007 #else
5008    (void) overlay;
5009    return EINA_FALSE;
5010 #endif
5011 }
5012
5013 EAPI void
5014 elm_map_overlay_displayed_zoom_min_set(Elm_Map_Overlay *overlay, int zoom)
5015 {
5016 #ifdef HAVE_ELEMENTARY_ECORE_CON
5017    EINA_SAFETY_ON_NULL_RETURN(overlay);
5018    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5019    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5020
5021    overlay->zoom_min = zoom;
5022    evas_object_smart_changed(overlay->wd->pan_smart);
5023 #else
5024    (void) overlay;
5025    (void) zoom;
5026 #endif
5027 }
5028
5029 EAPI int
5030 elm_map_overlay_displayed_zoom_min_get(const Elm_Map_Overlay *overlay)
5031 {
5032 #ifdef HAVE_ELEMENTARY_ECORE_CON
5033    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, 0);
5034    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, 0);
5035    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) 0;
5036
5037    return overlay->zoom_min;
5038 #else
5039    (void) overlay;
5040    return 0;
5041 #endif
5042 }
5043
5044 EAPI void
5045 elm_map_overlay_paused_set(Elm_Map_Overlay *overlay, Eina_Bool paused)
5046 {
5047 #ifdef HAVE_ELEMENTARY_ECORE_CON
5048    EINA_SAFETY_ON_NULL_RETURN(overlay);
5049    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5050    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5051
5052    if (overlay->paused == !!paused) return;
5053    overlay->paused = paused;
5054
5055    evas_object_smart_changed(overlay->wd->pan_smart);
5056 #else
5057    (void) overlay;
5058    (void) paused;
5059 #endif
5060 }
5061
5062 EAPI Eina_Bool
5063 elm_map_overlay_paused_get(const Elm_Map_Overlay *overlay)
5064 {
5065 #ifdef HAVE_ELEMENTARY_ECORE_CON
5066    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
5067    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
5068    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
5069
5070    return overlay->paused;
5071 #else
5072    (void) overlay;
5073    return EINA_FALSE;
5074 #endif
5075 }
5076
5077 EAPI void
5078 elm_map_overlay_show(Elm_Map_Overlay *overlay)
5079 {
5080 #ifdef HAVE_ELEMENTARY_ECORE_CON
5081    EINA_SAFETY_ON_NULL_RETURN(overlay);
5082    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5083    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5084
5085    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5086      {
5087         Overlay_Default *ovl = overlay->ovl;
5088         elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
5089      }
5090    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5091      {
5092         Overlay_Bubble *ovl = overlay->ovl;
5093         elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
5094      }
5095    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5096      {
5097         Overlay_Class *ovl = overlay->ovl;
5098         double lon, lat, max_lo, min_lo, max_la, min_la;
5099         _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la, &min_la);
5100         lon = (max_lo + min_lo) / 2;
5101         lat = (max_la + min_la) / 2;
5102         elm_map_region_show(overlay->wd->obj, lon, lat);
5103      }
5104    else ERR("Not supported overlay type: %d", overlay->type);
5105
5106    evas_object_smart_changed(overlay->wd->pan_smart);
5107 #else
5108    (void) overlay;
5109 #endif
5110 }
5111
5112 EAPI void
5113 elm_map_overlays_show(Eina_List *overlays)
5114 {
5115 #ifdef HAVE_ELEMENTARY_ECORE_CON
5116    EINA_SAFETY_ON_NULL_RETURN(overlays);
5117    EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(overlays));
5118
5119    Elm_Map_Overlay *overlay;
5120    overlay = eina_list_data_get(overlays);
5121
5122    Delayed_Data *data = ELM_NEW(Delayed_Data);
5123    data->func = _overlays_show;
5124    data->wd = overlay->wd;
5125    data->overlays = eina_list_clone(overlays);
5126    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
5127    evas_object_smart_changed(data->wd->pan_smart);
5128 #else
5129    (void) overlays;
5130 #endif
5131 }
5132
5133 EAPI void
5134 elm_map_overlay_region_set(Elm_Map_Overlay *overlay, double lon, double lat)
5135 {
5136 #ifdef HAVE_ELEMENTARY_ECORE_CON
5137    EINA_SAFETY_ON_NULL_RETURN(overlay);
5138    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5139    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5140
5141    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5142      {
5143         Overlay_Default *ovl = overlay->ovl;
5144         ovl->lon = lon;
5145         ovl->lat = lat;
5146      }
5147    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5148      {
5149         Overlay_Bubble *ovl = overlay->ovl;
5150         ovl->lon = lon;
5151         ovl->lat = lat;
5152      }
5153    else ERR("Not supported overlay type: %d", overlay->type);
5154
5155    evas_object_smart_changed(overlay->wd->pan_smart);
5156 #else
5157    (void) overlay;
5158    (void) lon;
5159    (void) lat;
5160 #endif
5161 }
5162
5163 EAPI void
5164 elm_map_overlay_region_get(const Elm_Map_Overlay *overlay, double *lon, double *lat)
5165 {
5166 #ifdef HAVE_ELEMENTARY_ECORE_CON
5167    EINA_SAFETY_ON_NULL_RETURN(overlay);
5168    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5169    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5170
5171    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5172      {
5173         const Overlay_Default *ovl = overlay->ovl;
5174         if (lon) *lon = ovl->lon;
5175         if (lat) *lat = ovl->lat;
5176      }
5177    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5178      {
5179         const Overlay_Bubble *ovl = overlay->ovl;
5180         if (lon) *lon = ovl->lon;
5181         if (lat) *lat = ovl->lat;
5182      }
5183    else ERR("Not supported overlay type: %d", overlay->type);
5184 #else
5185    (void) overlay;
5186    (void) lon;
5187    (void) lat;
5188 #endif
5189 }
5190
5191 EAPI void
5192 elm_map_overlay_icon_set(Elm_Map_Overlay *overlay, Evas_Object *icon)
5193 {
5194 #ifdef HAVE_ELEMENTARY_ECORE_CON
5195    EINA_SAFETY_ON_NULL_RETURN(overlay);
5196    EINA_SAFETY_ON_NULL_RETURN(icon);
5197    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5198    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5199
5200    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5201       _overlay_default_update(overlay->wd, overlay->ovl, NULL, icon,
5202                               NULL, NULL, NULL);
5203    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5204       _overlay_class_update(overlay->wd, overlay->ovl, NULL, icon);
5205    else ERR("Not supported overlay type: %d", overlay->type);
5206
5207    evas_object_smart_changed(overlay->wd->pan_smart);
5208 #else
5209    (void) overlay;
5210    (void) icon;
5211 #endif
5212 }
5213
5214 EAPI const Evas_Object *
5215 elm_map_overlay_icon_get(const Elm_Map_Overlay *overlay)
5216 {
5217 #ifdef HAVE_ELEMENTARY_ECORE_CON
5218    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
5219    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
5220    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
5221
5222    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5223      {
5224         const Overlay_Default *ovl = overlay->ovl;
5225         return elm_object_part_content_get(ovl->layout, "elm.icon");
5226      }
5227    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5228      {
5229         const Overlay_Class *ovl = overlay->ovl;
5230         return ovl->icon;
5231      }
5232    else
5233      {
5234         ERR("Not supported overlay type: %d", overlay->type);
5235         return NULL;
5236      }
5237 #else
5238    (void) overlay;
5239    return NULL;
5240 #endif
5241 }
5242
5243 EAPI void
5244 elm_map_overlay_content_set(Elm_Map_Overlay *overlay, Evas_Object *obj)
5245 {
5246 #ifdef HAVE_ELEMENTARY_ECORE_CON
5247    EINA_SAFETY_ON_NULL_RETURN(overlay);
5248    EINA_SAFETY_ON_NULL_RETURN(obj);
5249    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5250    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5251
5252    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5253       _overlay_default_update(overlay->wd, overlay->ovl, obj, NULL, NULL,
5254                                  NULL, NULL);
5255    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5256       _overlay_class_update(overlay->wd, overlay->ovl, obj, NULL);
5257    else ERR("Not supported overlay type: %d", overlay->type);
5258
5259    evas_object_smart_changed(overlay->wd->pan_smart);
5260 #else
5261    (void) overlay;
5262    (void) obj;
5263 #endif
5264 }
5265
5266 EAPI const Evas_Object *
5267 elm_map_overlay_content_get(const Elm_Map_Overlay *overlay)
5268 {
5269 #ifdef HAVE_ELEMENTARY_ECORE_CON
5270    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
5271    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
5272    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
5273
5274    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5275      {
5276         const Overlay_Default *ovl = overlay->ovl;
5277         return elm_object_part_content_get(ovl->layout, "elm.icon");
5278      }
5279    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
5280      {
5281         const Overlay_Class *ovl = overlay->ovl;
5282         return ovl->icon;
5283      }
5284    else
5285      {
5286         ERR("Not supported overlay type: %d", overlay->type);
5287         return NULL;
5288      }
5289 #else
5290    (void) overlay;
5291    return NULL;
5292 #endif
5293 }
5294
5295 EAPI void
5296 elm_map_overlay_color_set(Elm_Map_Overlay *overlay, int r, int g , int b, int a)
5297 {
5298 #ifdef HAVE_ELEMENTARY_ECORE_CON
5299    EINA_SAFETY_ON_NULL_RETURN(overlay);
5300    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5301    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5302
5303    if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
5304      {
5305         Overlay_Route *route = overlay->ovl;
5306         route->color.r = r;
5307         route->color.g = g;
5308         route->color.b = b;
5309         route->color.a = a;
5310      }
5311    else ERR("Not supported overlay type: %d", overlay->type);
5312 #else
5313    (void) overlay;
5314    (void) r;
5315    (void) g;
5316    (void) b;
5317    (void) a;
5318 #endif
5319 }
5320
5321 EAPI void
5322 elm_map_overlay_color_get(const Elm_Map_Overlay *overlay, int *r, int *g , int *b, int *a)
5323 {
5324 #ifdef HAVE_ELEMENTARY_ECORE_CON
5325    EINA_SAFETY_ON_NULL_RETURN(overlay);
5326    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5327    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5328
5329    int rr, gg, bb, aa;
5330
5331    if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
5332      {
5333         Overlay_Route *route = overlay->ovl;
5334         rr = route->color.r;
5335         gg = route->color.g;
5336         bb = route->color.b;
5337         aa = route->color.a;
5338      }
5339    else
5340      {
5341         ERR("Not supported overlay type: %d", overlay->type);
5342         return;
5343      }
5344    if (r) *r = rr;
5345    if (g) *g = gg;
5346    if (b) *b = bb;
5347    if (a) *a = aa;
5348 #else
5349    (void) overlay;
5350    (void) r;
5351    (void) g;
5352    (void) b;
5353    (void) a;
5354 #endif
5355 }
5356
5357 EAPI void
5358 elm_map_overlay_get_cb_set(Elm_Map_Overlay *overlay, Elm_Map_Overlay_Get_Cb get_cb, void *data)
5359 {
5360 #ifdef HAVE_ELEMENTARY_ECORE_CON
5361    EINA_SAFETY_ON_NULL_RETURN(overlay);
5362    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
5363    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
5364
5365    overlay->cb = get_cb;
5366    overlay->cb_data = data;
5367 #else
5368    (void) overlay;
5369    (void) get_cb;
5370    (void) data;
5371 #endif
5372 }
5373
5374 EAPI Elm_Map_Overlay *
5375 elm_map_overlay_class_add(Evas_Object *obj)
5376 {
5377 #ifdef HAVE_ELEMENTARY_ECORE_CON
5378    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5379    Widget_Data *wd = elm_widget_data_get(obj);
5380    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5381
5382    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5383    overlay->wd = wd;
5384    overlay->type = ELM_MAP_OVERLAY_TYPE_CLASS;
5385    overlay->ovl = _overlay_class_new(wd, overlay);
5386    overlay->grp = NULL;
5387    wd->overlays = eina_list_append(wd->overlays, overlay);
5388
5389    evas_object_smart_changed(wd->pan_smart);
5390    return overlay;
5391 #else
5392    (void) obj;
5393    return NULL;
5394 #endif
5395 }
5396
5397 EAPI void
5398 elm_map_overlay_class_append(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
5399 {
5400 #ifdef HAVE_ELEMENTARY_ECORE_CON
5401    EINA_SAFETY_ON_NULL_RETURN(group);
5402    EINA_SAFETY_ON_NULL_RETURN(overlay);
5403    EINA_SAFETY_ON_NULL_RETURN(group->wd);
5404    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5405    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5406
5407    if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
5408      {
5409         ERR("Currently group supports only default overlays");
5410         return;
5411      }
5412
5413    Overlay_Class *ovl = group->ovl;
5414    if (eina_list_data_find(ovl->members, overlay))
5415      {
5416         ERR("Already added overlay into group");
5417         return;
5418      }
5419    ovl->members = eina_list_append(ovl->members, overlay);
5420    overlay->grp->clas = group;
5421
5422   evas_object_smart_changed(group->wd->pan_smart);
5423 #else
5424    (void) group;
5425    (void) overlay;
5426 #endif
5427 }
5428
5429 EAPI void
5430 elm_map_overlay_class_remove(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
5431 {
5432 #ifdef HAVE_ELEMENTARY_ECORE_CON
5433    EINA_SAFETY_ON_NULL_RETURN(group);
5434    EINA_SAFETY_ON_NULL_RETURN(overlay);
5435    EINA_SAFETY_ON_NULL_RETURN(group->wd);
5436    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5437    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5438
5439     if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
5440      {
5441         ERR("Currently group supports only default overlays");
5442         return;
5443      }
5444    Overlay_Class *ovl = group->ovl;
5445    ovl->members = eina_list_remove(ovl->members, overlay);
5446    overlay->grp->clas = NULL;
5447    _overlay_group_update(group->wd, overlay->grp, NULL);
5448
5449   evas_object_smart_changed(group->wd->pan_smart);
5450 #else
5451    (void) group;
5452    (void) overlay;
5453 #endif
5454 }
5455
5456 EAPI void
5457 elm_map_overlay_class_zoom_max_set(Elm_Map_Overlay *group, int zoom)
5458 {
5459 #ifdef HAVE_ELEMENTARY_ECORE_CON
5460    EINA_SAFETY_ON_NULL_RETURN(group);
5461    EINA_SAFETY_ON_NULL_RETURN(group->wd);
5462    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
5463    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
5464
5465    Overlay_Class *ovl = group->ovl;
5466    if (ovl->zoom_max == !!zoom) return;
5467    ovl->zoom_max = zoom;
5468
5469    evas_object_smart_changed(group->wd->pan_smart);
5470 #else
5471    (void) group;
5472    (void) zoom;
5473 #endif
5474 }
5475
5476 EAPI int
5477 elm_map_overlay_class_zoom_max_get(const Elm_Map_Overlay *group)
5478 {
5479 #ifdef HAVE_ELEMENTARY_ECORE_CON
5480    EINA_SAFETY_ON_NULL_RETURN_VAL(group, OVERLAY_CLASS_ZOOM_MAX);
5481    EINA_SAFETY_ON_NULL_RETURN_VAL(group->wd, OVERLAY_CLASS_ZOOM_MAX);
5482    ELM_CHECK_WIDTYPE(group->wd->obj, widtype) OVERLAY_CLASS_ZOOM_MAX;
5483    EINA_SAFETY_ON_FALSE_RETURN_VAL(group->type == ELM_MAP_OVERLAY_TYPE_CLASS, OVERLAY_CLASS_ZOOM_MAX);
5484
5485    const Overlay_Class *ovl = group->ovl;
5486    return ovl->zoom_max;
5487 #else
5488    (void) group;
5489    return OVERLAY_CLASS_ZOOM_MAX;
5490 #endif
5491 }
5492
5493 EAPI Elm_Map_Overlay *
5494 elm_map_overlay_bubble_add(Evas_Object *obj)
5495 {
5496 #ifdef HAVE_ELEMENTARY_ECORE_CON
5497    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5498    Widget_Data *wd = elm_widget_data_get(obj);
5499    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5500
5501    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5502    overlay->wd = wd;
5503    overlay->type = ELM_MAP_OVERLAY_TYPE_BUBBLE;
5504    overlay->ovl =  _overlay_bubble_new(wd);
5505    _overlay_bubble_cb_add(overlay->ovl, overlay);
5506    overlay->grp = _overlay_group_new(wd);
5507    wd->overlays = eina_list_append(wd->overlays, overlay);
5508
5509    evas_object_smart_changed(wd->pan_smart);
5510    return overlay;
5511 #else
5512    (void) obj;
5513    return NULL;
5514 #endif
5515 }
5516
5517 EAPI void
5518 elm_map_overlay_bubble_follow(Elm_Map_Overlay *bubble, Elm_Map_Overlay *parent)
5519 {
5520 #ifdef HAVE_ELEMENTARY_ECORE_CON
5521    EINA_SAFETY_ON_NULL_RETURN(bubble);
5522    EINA_SAFETY_ON_NULL_RETURN(parent);
5523    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5524    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5525
5526    Overlay_Bubble *ovl = bubble->ovl;
5527    Evas_Object *pobj = _overlay_obj_get(parent);
5528    if (!pobj) return;
5529
5530    if (ovl->pobj)
5531      {
5532         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_HIDE,
5533                                             _overlay_bubble_hide_cb, ovl);
5534         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_SHOW,
5535                                             _overlay_bubble_chase_cb, ovl);
5536         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_MOVE,
5537                                             _overlay_bubble_chase_cb, ovl);
5538      }
5539
5540    ovl->pobj = pobj;
5541    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_HIDE,
5542                                   _overlay_bubble_hide_cb, ovl);
5543    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_SHOW,
5544                                   _overlay_bubble_chase_cb, ovl);
5545    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_MOVE,
5546                                   _overlay_bubble_chase_cb, ovl);
5547
5548    _overlay_bubble_chase(ovl);
5549    evas_object_smart_changed(bubble->wd->pan_smart);
5550 #else
5551    (void) bubble;
5552    (void) parent;
5553 #endif
5554 }
5555
5556 EAPI void
5557 elm_map_overlay_bubble_content_append(Elm_Map_Overlay *bubble, Evas_Object *content)
5558 {
5559 #ifdef HAVE_ELEMENTARY_ECORE_CON
5560    EINA_SAFETY_ON_NULL_RETURN(bubble);
5561    EINA_SAFETY_ON_NULL_RETURN(content);
5562    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5563    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5564
5565    Overlay_Bubble *bb = bubble->ovl;
5566    elm_box_pack_end(bb->bx, content);
5567
5568    evas_object_smart_changed(bubble->wd->pan_smart);
5569 #else
5570    (void) bubble;
5571    (void) content;
5572 #endif
5573 }
5574
5575 EAPI void
5576 elm_map_overlay_bubble_content_clear(Elm_Map_Overlay *bubble)
5577 {
5578 #ifdef HAVE_ELEMENTARY_ECORE_CON
5579    EINA_SAFETY_ON_NULL_RETURN(bubble);
5580    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
5581    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
5582
5583    Overlay_Bubble *bb = bubble->ovl;
5584    elm_box_clear(bb->bx);
5585
5586    evas_object_smart_changed(bubble->wd->pan_smart);
5587 #else
5588    (void) bubble;
5589 #endif
5590 }
5591
5592 EAPI Elm_Map_Overlay *
5593 elm_map_overlay_route_add(Evas_Object *obj, const Elm_Map_Route *route)
5594 {
5595 #ifdef HAVE_ELEMENTARY_ECORE_CON
5596    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5597    Widget_Data *wd = elm_widget_data_get(obj);
5598    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5599    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5600    EINA_SAFETY_ON_NULL_RETURN_VAL(route->wd, NULL);
5601    EINA_SAFETY_ON_FALSE_RETURN_VAL(obj == route->wd->obj, NULL);
5602
5603    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
5604    overlay->wd = wd;
5605    overlay->type = ELM_MAP_OVERLAY_TYPE_ROUTE;
5606    overlay->ovl =  _overlay_route_new(wd, route);
5607    overlay->grp = _overlay_group_new(wd);
5608    wd->overlays = eina_list_append(wd->overlays, overlay);
5609
5610    evas_object_smart_changed(wd->pan_smart);
5611    return overlay;
5612 #else
5613    (void) obj;
5614    (void) route;
5615    return NULL;
5616 #endif
5617 }
5618
5619 #ifdef ELM_EMAP
5620 EAPI Evas_Object *
5621 elm_map_track_add(Evas_Object *obj, void *emap)
5622 {
5623 #ifdef HAVE_ELEMENTARY_ECORE_CON
5624    EMap_Route *emapr = emap;
5625    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5626    Widget_Data *wd = elm_widget_data_get(obj);
5627    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
5628
5629    Evas_Object *route = elm_route_add(obj);
5630    elm_route_emap_set(route, emapr);
5631    wd->track = eina_list_append(wd->track, route);
5632
5633    return route;
5634 #else
5635    (void) obj;
5636    (void) emap;
5637    return NULL;
5638 #endif
5639 }
5640
5641 EAPI void
5642 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
5643 {
5644 #ifdef HAVE_ELEMENTARY_ECORE_CON
5645    ELM_CHECK_WIDTYPE(obj, widtype) ;
5646    Widget_Data *wd = elm_widget_data_get(obj);
5647    EINA_SAFETY_ON_NULL_RETURN(wd);
5648
5649    wd->track = eina_list_remove(wd->track, route);
5650    evas_object_del(route);
5651 #else
5652    (void) obj;
5653    (void) route;
5654 #endif
5655 }
5656 #else
5657 EAPI Evas_Object *
5658 elm_map_track_add(Evas_Object *obj __UNUSED__, void *emap __UNUSED__)
5659 {
5660    return NULL;
5661 }
5662
5663 EAPI void
5664 elm_map_track_remove(Evas_Object *obj __UNUSED__, Evas_Object *route __UNUSED__)
5665 {
5666 }
5667 #endif
5668
5669 /************************* Belows are deprecated APIs *************************/
5670 EAPI void
5671 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
5672 {
5673    elm_map_zoom_max_set(obj, zoom);
5674 }
5675
5676 EAPI int
5677 elm_map_source_zoom_max_get(const Evas_Object *obj)
5678 {
5679    return elm_map_zoom_max_get(obj);
5680 }
5681
5682 EAPI void
5683 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
5684 {
5685    elm_map_zoom_min_set(obj, zoom);
5686 }
5687
5688 EAPI int
5689 elm_map_source_zoom_min_get(const Evas_Object *obj)
5690 {
5691    return elm_map_zoom_min_get(obj);
5692 }
5693
5694 EAPI void
5695 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
5696 {
5697 #ifdef HAVE_ELEMENTARY_ECORE_CON
5698    ELM_CHECK_WIDTYPE(obj, widtype);
5699    Widget_Data *wd = elm_widget_data_get(obj);
5700    EINA_SAFETY_ON_NULL_RETURN(wd);
5701
5702    _coord_to_region_convert(wd, x, y, size, lon, lat);
5703 #else
5704    (void) obj;
5705    (void) x;
5706    (void) y;
5707    (void) size;
5708    (void) lon;
5709    (void) lat;
5710 #endif
5711 }
5712
5713 EAPI void
5714 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
5715 {
5716 #ifdef HAVE_ELEMENTARY_ECORE_CON
5717    ELM_CHECK_WIDTYPE(obj, widtype);
5718    Widget_Data *wd = elm_widget_data_get(obj);
5719    EINA_SAFETY_ON_NULL_RETURN(wd);
5720
5721    _geo_to_coord_convert(wd, lon, lat, size, x, y);
5722 #else
5723    (void) obj;
5724    (void) lon;
5725    (void) lat;
5726    (void) size;
5727    (void) x;
5728    (void) y;
5729 #endif
5730 }
5731
5732 EAPI void
5733 elm_map_utils_rotate_coord(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord cx, const Evas_Coord cy, double degree, Evas_Coord *xx, Evas_Coord *yy)
5734 {
5735 #ifdef HAVE_ELEMENTARY_ECORE_CON
5736    ELM_CHECK_WIDTYPE(obj, widtype);
5737    _coord_rotate(x, y, cx, cy, degree, xx, yy);
5738 #else
5739    (void) x;
5740    (void) y;
5741    (void) cx;
5742    (void) cy;
5743    (void) degree;
5744    (void) xx;
5745    (void) yy;
5746 #endif
5747 }
5748
5749 EAPI void
5750 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
5751 {
5752    elm_map_tile_load_status_get(obj, try_num, finish_num);
5753 }
5754
5755 EAPI void
5756 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
5757 {
5758    elm_map_region_bring_in(obj, lon, lat);
5759 }
5760
5761 EAPI void
5762 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
5763 {
5764    elm_map_region_show(obj, lon, lat);
5765 }
5766
5767 EAPI void
5768 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
5769 {
5770    elm_map_region_get(obj, lon, lat);
5771 }
5772
5773 EAPI Elm_Map_Name *
5774 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
5775 {
5776    return elm_map_name_add(obj, NULL, lon, lat, NULL, NULL);
5777 }
5778
5779 EAPI Elm_Map_Name *
5780 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
5781 {
5782    return elm_map_name_add(obj, address, 0, 0, NULL, NULL);
5783 }
5784
5785 EAPI void
5786 elm_map_canvas_to_geo_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
5787 {
5788    elm_map_canvas_to_region_convert(obj, x, y, lon, lat);
5789 }
5790
5791 EAPI Elm_Map_Marker *
5792 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *group_clas, void *data)
5793 {
5794 #ifdef HAVE_ELEMENTARY_ECORE_CON
5795    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5796    Widget_Data *wd = elm_widget_data_get(obj);
5797
5798    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5799    EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
5800
5801    Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
5802    marker->wd = wd;
5803    marker->clas = clas;
5804    marker->group_clas = group_clas;
5805    marker->longitude = lon;
5806    marker->latitude = lat;
5807    marker->data = data;
5808    marker->x = 0;
5809    marker->y = 0;
5810    _edj_marker_size_get(wd, &marker->w, &marker->h);
5811
5812    marker->obj = elm_layout_add(wd->obj);
5813    evas_object_smart_member_add(marker->obj, wd->pan_smart);
5814    evas_object_stack_above(marker->obj, wd->sep_maps_markers);
5815
5816    edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
5817                                    "open", "elm", _marker_bubble_open_cb,
5818                                    marker);
5819    edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
5820                                    "bringin", "elm", _marker_bringin_cb,
5821                                    marker);
5822
5823    wd->markers = eina_list_append(wd->markers, marker);
5824    if (marker->group_clas) group_clas->markers = eina_list_append(group_clas->markers,
5825                                                                   marker);
5826    evas_object_smart_changed(wd->pan_smart);
5827    return marker;
5828 #else
5829    (void) obj;
5830    (void) lon;
5831    (void) lat;
5832    (void) clas;
5833    (void) group_clas;
5834    (void) data;
5835    return NULL;
5836 #endif
5837 }
5838
5839 EAPI void
5840 elm_map_marker_remove(Elm_Map_Marker *marker)
5841 {
5842    _elm_map_marker_remove(marker);
5843 }
5844
5845 EAPI void
5846 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
5847 {
5848 #ifdef HAVE_ELEMENTARY_ECORE_CON
5849    EINA_SAFETY_ON_NULL_RETURN(marker);
5850    if (lon) *lon = marker->longitude;
5851    if (lat) *lat = marker->latitude;
5852 #else
5853    (void) marker;
5854    (void) lon;
5855    (void) lat;
5856 #endif
5857 }
5858
5859 EAPI void
5860 elm_map_marker_bring_in(Elm_Map_Marker *marker)
5861 {
5862 #ifdef HAVE_ELEMENTARY_ECORE_CON
5863    EINA_SAFETY_ON_NULL_RETURN(marker);
5864    elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
5865 #else
5866    (void) marker;
5867 #endif
5868 }
5869
5870 EAPI void
5871 elm_map_marker_show(Elm_Map_Marker *marker)
5872 {
5873 #ifdef HAVE_ELEMENTARY_ECORE_CON
5874    EINA_SAFETY_ON_NULL_RETURN(marker);
5875    elm_map_region_show(marker->wd->obj, marker->longitude, marker->latitude);
5876 #else
5877    (void) marker;
5878 #endif
5879 }
5880
5881 EAPI void
5882 elm_map_markers_list_show(Eina_List *markers)
5883 {
5884 #ifdef HAVE_ELEMENTARY_ECORE_CON
5885    EINA_SAFETY_ON_NULL_RETURN(markers);
5886    EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(markers));
5887
5888    Elm_Map_Marker *marker;
5889    marker = eina_list_data_get(markers);
5890
5891    Delayed_Data *data = ELM_NEW(Delayed_Data);
5892    data->func = _marker_list_show;
5893    data->wd = marker->wd;
5894    data->markers = eina_list_clone(markers);
5895    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
5896    evas_object_smart_changed(data->wd->pan_smart);
5897 #else
5898    (void) markers;
5899 #endif
5900 }
5901
5902 EAPI void
5903 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
5904 {
5905 #ifdef HAVE_ELEMENTARY_ECORE_CON
5906    ELM_CHECK_WIDTYPE(obj, widtype);
5907    Widget_Data *wd = elm_widget_data_get(obj);
5908    EINA_SAFETY_ON_NULL_RETURN(wd);
5909
5910    if (wd->paused_markers == !!paused) return;
5911    wd->paused_markers = paused;
5912 #else
5913    (void) obj;
5914    (void) paused;
5915 #endif
5916 }
5917
5918 EAPI Eina_Bool
5919 elm_map_paused_markers_get(const Evas_Object *obj)
5920 {
5921 #ifdef HAVE_ELEMENTARY_ECORE_CON
5922    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5923    Widget_Data *wd = elm_widget_data_get(obj);
5924    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
5925
5926    return wd->paused_markers;
5927 #else
5928    (void) obj;
5929    return EINA_FALSE;
5930 #endif
5931 }
5932
5933 EAPI void
5934 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
5935 {
5936 #ifdef HAVE_ELEMENTARY_ECORE_CON
5937    ELM_CHECK_WIDTYPE(obj, widtype);
5938    Widget_Data *wd = elm_widget_data_get(obj);
5939    EINA_SAFETY_ON_NULL_RETURN(wd);
5940
5941    wd->markers_max_num = max;
5942 #else
5943    (void) obj;
5944    (void) max;
5945 #endif
5946 }
5947
5948 EAPI Evas_Object *
5949 elm_map_marker_object_get(const Elm_Map_Marker *marker)
5950 {
5951 #ifdef HAVE_ELEMENTARY_ECORE_CON
5952    EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
5953    return marker->content;
5954 #else
5955    (void) marker;
5956    return NULL;
5957 #endif
5958 }
5959
5960 EAPI void
5961 elm_map_marker_update(Elm_Map_Marker *marker)
5962 {
5963 #ifdef HAVE_ELEMENTARY_ECORE_CON
5964    EINA_SAFETY_ON_NULL_RETURN(marker);
5965    Widget_Data *wd = marker->wd;
5966    EINA_SAFETY_ON_NULL_RETURN(wd);
5967
5968    _marker_update(marker);
5969 #else
5970    (void) marker;
5971 #endif
5972 }
5973
5974 EAPI void
5975 elm_map_bubbles_close(Evas_Object *obj)
5976 {
5977 #ifdef HAVE_ELEMENTARY_ECORE_CON
5978    ELM_CHECK_WIDTYPE(obj, widtype);
5979    Widget_Data *wd = elm_widget_data_get(obj);
5980    EINA_SAFETY_ON_NULL_RETURN(wd);
5981
5982    Eina_List *l;
5983    Elm_Map_Marker *marker;
5984    EINA_LIST_FOREACH(wd->markers, l, marker)
5985      {
5986         if (marker->bubble) _bubble_free(marker->bubble);
5987         marker->bubble = NULL;
5988
5989         if (marker->group)
5990           {
5991              if (marker->group->bubble) _bubble_free(marker->group->bubble);
5992              marker->group->bubble = NULL;
5993           }
5994      }
5995 #else
5996    (void) obj;
5997 #endif
5998 }
5999
6000 EAPI Elm_Map_Group_Class *
6001 elm_map_group_class_new(Evas_Object *obj)
6002 {
6003 #ifdef HAVE_ELEMENTARY_ECORE_CON
6004    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
6005    Widget_Data *wd = elm_widget_data_get(obj);
6006    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6007
6008    Elm_Map_Group_Class *clas = ELM_NEW(Elm_Map_Group_Class);
6009    clas->wd = wd;
6010    clas->zoom_displayed = 0;
6011    clas->zoom_grouped = 255;
6012    eina_stringshare_replace(&clas->style, "radio");
6013
6014    wd->group_classes = eina_list_append(wd->group_classes, clas);
6015
6016    return clas;
6017 #else
6018    (void) obj;
6019    return NULL;
6020 #endif
6021 }
6022
6023 EAPI void
6024 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
6025 {
6026 #ifdef HAVE_ELEMENTARY_ECORE_CON
6027    EINA_SAFETY_ON_NULL_RETURN(clas);
6028    eina_stringshare_replace(&clas->style, style);
6029 #else
6030    (void) clas;
6031    (void) style;
6032 #endif
6033 }
6034
6035 EAPI void
6036 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, Elm_Map_Group_Icon_Get_Func icon_get)
6037 {
6038 #ifdef HAVE_ELEMENTARY_ECORE_CON
6039    EINA_SAFETY_ON_NULL_RETURN(clas);
6040    clas->func.icon_get = icon_get;
6041 #else
6042    (void) clas;
6043    (void) icon_get;
6044 #endif
6045 }
6046
6047 EAPI void
6048 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
6049 {
6050 #ifdef HAVE_ELEMENTARY_ECORE_CON
6051    EINA_SAFETY_ON_NULL_RETURN(clas);
6052    clas->data = data;
6053 #else
6054    (void) clas;
6055    (void) data;
6056 #endif
6057 }
6058
6059 EAPI void
6060 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
6061 {
6062 #ifdef HAVE_ELEMENTARY_ECORE_CON
6063    EINA_SAFETY_ON_NULL_RETURN(clas);
6064    clas->zoom_displayed = zoom;
6065 #else
6066    (void) clas;
6067    (void) zoom;
6068 #endif
6069 }
6070
6071 EAPI void
6072 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
6073 {
6074 #ifdef HAVE_ELEMENTARY_ECORE_CON
6075    EINA_SAFETY_ON_NULL_RETURN(clas);
6076    clas->zoom_grouped = zoom;
6077 #else
6078    (void) clas;
6079    (void) zoom;
6080 #endif
6081 }
6082
6083 EAPI void
6084 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
6085 {
6086 #ifdef HAVE_ELEMENTARY_ECORE_CON
6087    ELM_CHECK_WIDTYPE(obj, widtype);
6088    Widget_Data *wd = elm_widget_data_get(obj);
6089    EINA_SAFETY_ON_NULL_RETURN(wd);
6090    EINA_SAFETY_ON_NULL_RETURN(clas);
6091
6092    clas->hide = hide;
6093    evas_object_smart_changed(wd->pan_smart);
6094 #else
6095    (void) obj;
6096    (void) clas;
6097    (void) hide;
6098 #endif
6099 }
6100
6101 EAPI Elm_Map_Marker_Class *
6102 elm_map_marker_class_new(Evas_Object *obj)
6103 {
6104 #ifdef HAVE_ELEMENTARY_ECORE_CON
6105    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
6106    Widget_Data *wd = elm_widget_data_get(obj);
6107    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6108
6109    Elm_Map_Marker_Class *clas = ELM_NEW(Elm_Map_Marker_Class);
6110    eina_stringshare_replace(&clas->style, "radio");
6111
6112    wd->marker_classes = eina_list_append(wd->marker_classes, clas);
6113    return clas;
6114 #else
6115    (void) obj;
6116    return NULL;
6117 #endif
6118 }
6119
6120 EAPI void
6121 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
6122 {
6123 #ifdef HAVE_ELEMENTARY_ECORE_CON
6124    EINA_SAFETY_ON_NULL_RETURN(clas);
6125    eina_stringshare_replace(&clas->style, style);
6126 #else
6127    (void) clas;
6128    (void) style;
6129 #endif
6130 }
6131
6132 EAPI void
6133 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Icon_Get_Func icon_get)
6134 {
6135 #ifdef HAVE_ELEMENTARY_ECORE_CON
6136    EINA_SAFETY_ON_NULL_RETURN(clas);
6137    clas->func.icon_get = icon_get;
6138 #else
6139    (void) clas;
6140    (void) icon_get;
6141 #endif
6142 }
6143
6144 EAPI void
6145 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Get_Func get)
6146 {
6147 #ifdef HAVE_ELEMENTARY_ECORE_CON
6148    EINA_SAFETY_ON_NULL_RETURN(clas);
6149    clas->func.get = get;
6150 #else
6151    (void) clas;
6152    (void) get;
6153 #endif
6154 }
6155
6156 EAPI void
6157 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Del_Func del)
6158 {
6159 #ifdef HAVE_ELEMENTARY_ECORE_CON
6160    EINA_SAFETY_ON_NULL_RETURN(clas);
6161    clas->func.del = del;
6162 #else
6163    (void) clas;
6164    (void) del;
6165 #endif
6166 }
6167
6168 EAPI void
6169 elm_map_route_color_set(Elm_Map_Route *route __UNUSED__, int r  __UNUSED__, int g  __UNUSED__, int b  __UNUSED__, int a  __UNUSED__)
6170 {
6171    return;
6172 }
6173
6174 EAPI void
6175 elm_map_route_color_get(const Elm_Map_Route *route __UNUSED__, int *r  __UNUSED__, int *g  __UNUSED__, int *b  __UNUSED__, int *a  __UNUSED__)
6176 {
6177    return;
6178 }
6179
6180 EAPI void
6181 elm_map_route_remove(Elm_Map_Route *route)
6182 {
6183    elm_map_route_del(route);
6184 }
6185
6186 EAPI void
6187 elm_map_name_remove(Elm_Map_Name *name)
6188 {
6189    elm_map_name_del(name);
6190 }
6191