Merge branch 'intefl/svn_merge' of ssh://165.213.149.219:21922/slp/pkgs/e/elementary...
[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 <<<<<<< HEAD
16 typedef struct _Marker_Group Marker_Group;
17 typedef struct _Event Event;
18 =======
19 typedef struct _Overlay_Default Overlay_Default;
20 typedef struct _Overlay_Group Overlay_Group;
21 typedef struct _Overlay_Class Overlay_Class;
22 typedef struct _Overlay_Bubble Overlay_Bubble;
23 typedef struct _Overlay_Route Overlay_Route;
24 typedef struct _Marker_Group Marker_Group;
25 typedef struct _Marker_Bubble Marker_Bubble;
26 >>>>>>> remotes/origin/upstream
27 typedef struct _Path_Node Path_Node;
28 typedef struct _Path_Waypoint Path_Waypoint;
29 typedef struct _Url_Data Url_Data;
30 typedef struct _Route_Dump Route_Dump;
31 typedef struct _Name_Dump Name_Dump;
32 <<<<<<< HEAD
33 typedef struct _Track_Dump Track_Dump;
34
35 #define CACHE_ROOT_PATH   "/tmp/elm_map"
36 #define CACHE_PATH        CACHE_ROOT_PATH"/%d/%d/%d"
37 #define CACHE_FILE_PATH   "%s/%d.png"
38 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
39 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
40
41 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
42 #define ROUTE_TYPE_MOTORCAR "motocar"
43 #define ROUTE_TYPE_BICYCLE "bicycle"
44 #define ROUTE_TYPE_FOOT "foot"
45 #define YOURS_DISTANCE "distance"
46 #define YOURS_DESCRIPTION "description"
47 #define YOURS_COORDINATES "coordinates"
48
49 // TODO: fix monav & ors url
50 #define ROUTE_MONAV_URL "http://"
51 #define ROUTE_ORS_URL "http:///"
52
53 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
54 #define NOMINATIM_RESULT "result"
55 #define NOMINATIM_PLACE "place"
56 #define NOMINATIM_ATTR_LON "lon"
57 #define NOMINATIM_ATTR_LAT "lat"
58
59 #define PINCH_ZOOM_MIN 0.25
60 #define PINCH_ZOOM_MAX 4.0
61 #define MAX_CONCURRENT_DOWNLOAD 10
62
63 #define GPX_NAME "name>"
64 #define GPX_COORDINATES "trkpt "
65 #define GPX_LON "lon"
66 #define GPX_LAT "lat"
67 #define GPX_ELE "ele>"
68 #define GPX_TIME "time>"
69
70 // Map sources
71 // Currently the size of a tile must be 256*256
72 // and the size of the map must be pow(2.0, z)*tile_size
73 typedef struct _Map_Sources_Tab
74 =======
75 typedef struct _Delayed_Data Delayed_Data;
76 typedef struct _Source_Tile Source_Tile;
77 typedef struct _Source_Route Source_Route;
78 typedef struct _Source_Name Source_Name;
79
80 typedef char                      *(*Elm_Map_Module_Source_Name_Func)(void);
81 typedef int                        (*Elm_Map_Module_Tile_Zoom_Min_Func)(void);
82 typedef int                        (*Elm_Map_Module_Tile_Zoom_Max_Func)(void);
83 typedef char                      *(*Elm_Map_Module_Tile_Url_Func)(Evas_Object *obj, int x, int y, int zoom);
84 typedef Eina_Bool                  (*Elm_Map_Module_Tile_Geo_to_Coord_Func)(const Evas_Object *obj, int zoom, double lon, double lat, int size, int *x, int *y);
85 typedef Eina_Bool                  (*Elm_Map_Module_Tile_Coord_to_Geo_Func)(const Evas_Object *obj, int zoom, int x, int y, int size, double *lon, double *lat);
86 typedef char                      *(*Elm_Map_Module_Route_Url_Func)(Evas_Object *obj, const char *type_name, int method, double flon, double flat, double tlon, double tlat);
87 typedef char                      *(*Elm_Map_Module_Name_Url_Func)(Evas_Object *obj, int method, const char *name, double lon, double lat);
88
89 #define ROUND(z)                (((z) < 0) ? (int)ceil((z) - 0.005) : (int)floor((z) + 0.005))
90 #define EVAS_MAP_POINT          4
91 #define DEFAULT_TILE_SIZE       256
92 #define MAX_CONCURRENT_DOWNLOAD 10
93 #define MARER_MAX_NUMBER        30
94 #define OVERLAY_CLASS_ZOOM_MAX 255
95 #define OVERLAY_GROUPING_SCALE 2
96
97 #define CACHE_ROOT          "/tmp/elm_map"
98 #define CACHE_TILE_ROOT     CACHE_ROOT"/%d/%d/%d"
99 #define CACHE_TILE_PATH     "%s/%d.png"
100 #define CACHE_ROUTE_ROOT    CACHE_ROOT"/route"
101 #define CACHE_NAME_ROOT     CACHE_ROOT"/name"
102
103 #define ROUTE_YOURS_URL     "http://www.yournavigation.org/api/dev/route.php"
104 #define ROUTE_TYPE_MOTORCAR "motocar"
105 #define ROUTE_TYPE_BICYCLE  "bicycle"
106 #define ROUTE_TYPE_FOOT     "foot"
107 #define YOURS_DISTANCE      "distance"
108 #define YOURS_DESCRIPTION   "description"
109 #define YOURS_COORDINATES   "coordinates"
110
111 #define NAME_NOMINATIM_URL  "http://nominatim.openstreetmap.org"
112 #define NOMINATIM_RESULT    "result"
113 #define NOMINATIM_PLACE     "place"
114 #define NOMINATIM_ATTR_LON  "lon"
115 #define NOMINATIM_ATTR_LAT  "lat"
116
117 enum _Route_Xml_Attribute
118 {
119    ROUTE_XML_NONE,
120    ROUTE_XML_DISTANCE,
121    ROUTE_XML_DESCRIPTION,
122    ROUTE_XML_COORDINATES,
123    ROUTE_XML_LAST
124 } Route_Xml_Attibute;
125
126 enum _Name_Xml_Attribute
127 {
128    NAME_XML_NONE,
129    NAME_XML_NAME,
130    NAME_XML_LON,
131    NAME_XML_LAT,
132    NAME_XML_LAST
133 } Name_Xml_Attibute;
134
135 enum _Track_Xml_Attribute
136 {
137    TRACK_XML_NONE,
138    TRACK_XML_COORDINATES,
139    TRACK_XML_LAST
140 } Track_Xml_Attibute;
141
142 struct _Delayed_Data
143 {
144    void (*func)(void *data);
145    Widget_Data *wd;
146    Elm_Map_Zoom_Mode mode;
147    int zoom;
148    double lon, lat;
149    Eina_List *markers;
150    Eina_List *overlays;
151 };
152
153 // Map Tile source
154 // FIXME: Currently tile size must be 256*256
155 // and the map size is pow(2.0, z) * (tile size)
156 struct _Source_Tile
157 >>>>>>> remotes/origin/upstream
158 {
159    const char *name;
160    int zoom_min;
161    int zoom_max;
162 <<<<<<< HEAD
163    ElmMapModuleUrlFunc url_cb;
164    Elm_Map_Route_Sources route_source;
165    ElmMapModuleRouteUrlFunc route_url_cb;
166    ElmMapModuleNameUrlFunc name_url_cb;
167    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
168    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
169 } Map_Sources_Tab;
170
171 //Zemm min is supposed to be 0
172 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
173 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
174 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
175 static char *_mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
176 static char *_mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
177
178 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
179 /*
180 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
181 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
182  */
183 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
184
185 static Map_Sources_Tab default_map_sources_tab[] =
186 {
187      {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
188      {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
189      {"CycleMap", 0, 16, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
190      {"MapQuest", 0, 18, _mapquest_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
191      {"MapQuest Open Aerial", 0, 11, _mapquest_aerial_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
192 =======
193    Elm_Map_Module_Tile_Url_Func url_cb;
194    Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
195    Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
196 };
197
198 // Map Route Source
199 struct _Source_Route
200 {
201    const char *name;
202    Elm_Map_Module_Route_Url_Func url_cb;
203 };
204
205 // Map Name Source
206 struct _Source_Name
207 {
208    const char *name;
209    Elm_Map_Module_Name_Url_Func url_cb;
210 >>>>>>> remotes/origin/upstream
211 };
212
213 struct _Url_Data
214 {
215    Ecore_Con_Url *con_url;
216
217    FILE *fd;
218    char *fname;
219 };
220
221 <<<<<<< HEAD
222 struct _Elm_Map_Marker_Class
223 {
224    const char *style;
225    int zoom_displayed;
226
227    struct _Elm_Map_Marker_Class_Func
228      {
229         ElmMapMarkerGetFunc get;
230         ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
231         ElmMapMarkerIconGetFunc icon_get;
232      } func;
233
234    struct
235      { //this part is private, do not modify these values
236         Eina_Bool set : 1;
237         Evas_Coord edje_w, edje_h;
238      } priv;
239 };
240
241 struct _Elm_Map_Marker
242 {
243    Widget_Data *wd;
244    Elm_Map_Marker_Class *clas;
245    Elm_Map_Group_Class *clas_group;
246    double longitude, latitude;
247
248    Evas_Coord map_size;
249    Evas_Coord *x, *y;
250    void *data;
251    Marker_Group **groups;
252    Evas_Object *content;
253 =======
254 struct _Overlay_Default
255 {
256    Evas_Coord w, h;
257
258    // Display priority is obj > icon > clas_obj > clas_icon > layout
259    Evas_Object *obj;
260    Evas_Object *icon;
261
262    // if obj or icon exists, do not inherit from class
263    Evas_Object *clas_obj;      // Duplicated from class icon
264    Evas_Object *clas_obj_ref;  // Checking fro class icon is changed
265    Evas_Object *clas_icon;     // Duplicated from class icon
266    Evas_Object *clas_icon_ref; // Checking for class icon is changed
267
268    char *style;
269    Evas_Object *layout;
270    double lon, lat;
271    Evas_Coord x, y;
272 };
273
274 struct _Overlay_Group
275 {
276    Overlay_Default *ovl;
277    Evas_Object *clas_icon;
278    Elm_Map_Overlay *clas;
279    Eina_List *members;
280 };
281
282 struct _Overlay_Class
283 {
284    Elm_Map_Overlay *clas;
285    Evas_Object *obj;
286    char *style;
287    Evas_Object *icon;
288    Eina_List *members;
289    int zoom_max;
290 };
291
292 struct _Overlay_Bubble
293 {
294    Widget_Data *wd;
295    Evas_Object *pobj;
296    Evas_Object *obj, *sc, *bx;
297    double lon, lat;
298    Evas_Coord x, y, w, h;
299 };
300
301 struct _Overlay_Route
302 {
303    Widget_Data *wd;
304
305    Eina_Bool inbound : 1;
306    struct
307      {
308         int r;
309         int g;
310         int b;
311         int a;
312      } color;
313
314    Eina_List *paths;
315    Eina_List *nodes;
316    int x, y;
317 };
318
319 struct _Elm_Map_Overlay
320 {
321    Widget_Data *wd;
322
323    Eina_Bool paused : 1;
324    Eina_Bool hide : 1;
325    Evas_Coord zoom_min;
326
327     void *data;               // user set data
328
329    Elm_Map_Overlay_Type type;
330    void *ovl;                 // Overlay Data for each type
331
332    // These are not used if overlay type is class
333    Eina_Bool grp_in : 1;
334    Eina_Bool grp_boss : 1;
335    Overlay_Group *grp;
336
337    Elm_Map_Overlay_Get_Cb cb;
338    void *cb_data;
339 };
340
341 struct _Elm_Map_Marker_Class
342 {
343    const char *style;
344    struct _Elm_Map_Marker_Class_Func
345      {
346         Elm_Map_Marker_Get_Func get;
347         Elm_Map_Marker_Del_Func del; //if NULL the object will be destroyed with evas_object_del()
348         Elm_Map_Marker_Icon_Get_Func icon_get;
349      } func;
350 >>>>>>> remotes/origin/upstream
351 };
352
353 struct _Elm_Map_Group_Class
354 {
355 <<<<<<< HEAD
356    const char *style;
357    void *data;
358    int zoom_displayed; // display the group if the zoom is >= to zoom_display
359    int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
360    Eina_Bool hide : 1;
361
362    struct
363      {
364         ElmMapGroupIconGetFunc icon_get;
365      } func;
366
367    struct
368      { //this part is private, do not modify these values
369         Eina_Bool set : 1;
370         Evas_Coord edje_w, edje_h;
371         Evas_Coord edje_max_w, edje_max_h;
372
373         Eina_List *objs_used;
374         Eina_List *objs_notused;
375      } priv;
376 =======
377    Widget_Data *wd;
378
379    Eina_List *markers;
380    int zoom_displayed; // display the group if the zoom is >= to zoom_display
381    int zoom_grouped;   // group the markers only if the zoom is <= to zoom_groups
382    const char *style;
383    void *data;
384    struct
385      {
386         Elm_Map_Group_Icon_Get_Func icon_get;
387      } func;
388
389    Eina_Bool hide : 1;
390 };
391
392 struct _Marker_Bubble
393 {
394    Widget_Data *wd;
395    Evas_Object *pobj;
396    Evas_Object *obj, *sc, *bx;
397 };
398
399 struct _Elm_Map_Marker
400 {
401    Widget_Data *wd;
402    Elm_Map_Marker_Class *clas;
403    Elm_Map_Group_Class *group_clas;
404    double longitude, latitude;
405    Evas_Coord w, h;
406    Evas_Object *obj;
407
408    Evas_Coord x, y;
409    Eina_Bool grouped : 1;
410    Eina_Bool leader : 1; // if marker is group leader
411    Marker_Group *group;
412
413    Marker_Bubble *bubble;
414    Evas_Object *content;
415    void *data;
416 >>>>>>> remotes/origin/upstream
417 };
418
419 struct _Marker_Group
420 {
421    Widget_Data *wd;
422 <<<<<<< HEAD
423    Eina_Matrixsparse_Cell *cell;
424    Elm_Map_Group_Class *clas;
425
426    Eina_List *markers;
427    long long sum_x, sum_y;
428    Evas_Coord x, y;
429    Evas_Coord w, h;
430
431    Evas_Object *obj, *bubble, *sc, *bx, *rect;
432    Eina_Bool open : 1;
433    Eina_Bool bringin : 1;
434    Eina_Bool update_nbelems : 1;
435    Eina_Bool update_resize : 1;
436    Eina_Bool update_raise : 1;
437    Eina_Bool delete_object : 1;
438 =======
439    Elm_Map_Group_Class *clas;
440    Evas_Coord w, h;
441    Evas_Object *obj;
442
443    Evas_Coord x, y;
444    Eina_List *markers;
445
446    Marker_Bubble *bubble;
447 >>>>>>> remotes/origin/upstream
448 };
449
450 struct _Elm_Map_Route
451 {
452    Widget_Data *wd;
453
454 <<<<<<< HEAD
455    Path_Node *n;
456    Path_Waypoint *w;
457    Ecore_Con_Url *con_url;
458
459    int type;
460    int method;
461    int x, y;
462    double flon, flat, tlon, tlat;
463
464    Eina_List *nodes, *path;
465    Eina_List *waypoint;
466
467 =======
468    char *fname;
469    Elm_Map_Route_Type type;
470    Elm_Map_Route_Method method;
471    double flon, flat, tlon, tlat;
472    Elm_Map_Route_Cb cb;
473    void *data;
474    Ecore_File_Download_Job *job;
475
476
477    Eina_List *nodes;
478    Eina_List *waypoint;
479 >>>>>>> remotes/origin/upstream
480    struct
481      {
482         int node_count;
483         int waypoint_count;
484         const char *nodes;
485         const char *waypoints;
486         double distance; /* unit : km */
487      } info;
488
489 <<<<<<< HEAD
490    Eina_List *handlers;
491    Url_Data ud;
492
493    struct
494      {
495         int r;
496         int g;
497         int b;
498         int a;
499      } color;
500
501    Eina_Bool inbound : 1;
502 =======
503    Path_Node *n;
504    Path_Waypoint *w;
505
506 >>>>>>> remotes/origin/upstream
507 };
508
509 struct _Path_Node
510 {
511    Widget_Data *wd;
512
513    int idx;
514    struct
515      {
516         double lon, lat;
517         char *address;
518      } pos;
519 };
520
521 struct _Path_Waypoint
522 {
523    Widget_Data *wd;
524
525    const char *point;
526 };
527
528 struct _Elm_Map_Name
529 {
530    Widget_Data *wd;
531
532 <<<<<<< HEAD
533    Ecore_Con_Url *con_url;
534    int method;
535    char *address;
536    double lon, lat;
537    Url_Data ud;
538    Ecore_Event_Handler *handler;
539 =======
540    int method;
541    char *address;
542    double lon, lat;
543
544    char *fname;
545    Ecore_File_Download_Job *job;
546    Elm_Map_Name_Cb cb;
547    void *data;
548 };
549
550 struct _Route_Dump
551 {
552    int id;
553    char *fname;
554    double distance;
555    char *description;
556    char *coordinates;
557 };
558
559 struct _Name_Dump
560 {
561    int id;
562    char *address;
563    double lon;
564    double lat;
565 >>>>>>> remotes/origin/upstream
566 };
567
568 struct _Grid_Item
569 {
570 <<<<<<< HEAD
571    Widget_Data *wd;
572    Grid *g;
573    int zoom;
574    Evas_Object *img;
575    //Evas_Object *txt;
576    const char *file;
577    const char *source;
578    struct
579      {
580         int x, y, w, h;
581      } src, out;
582
583    Eina_Bool file_have : 1;
584    Ecore_File_Download_Job *job;
585    int try_num;
586 =======
587    Grid *g;
588
589    Widget_Data *wd;
590    Evas_Object *img;
591    const char *file;
592    const char *url;
593    int x, y;  // Tile coordinate
594    Eina_Bool file_have : 1;
595
596    Ecore_File_Download_Job *job;
597 >>>>>>> remotes/origin/upstream
598 };
599
600 struct _Grid
601 {
602    Widget_Data *wd;
603 <<<<<<< HEAD
604    int tsize; // size of tile (tsize x tsize pixels)
605    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
606    int iw, ih; // size of image in pixels
607    int w, h; // size of grid image in pixels (represented by grid)
608    int gw, gh; // size of grid in tiles
609    Eina_Matrixsparse *grid;
610 };
611
612 =======
613    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
614    int tw, th; // size of grid in tiles
615    Eina_Matrixsparse *grid;
616 };
617
618 struct _Pan
619 {
620    Evas_Object_Smart_Clipped_Data __clipped_data;
621    Widget_Data *wd;
622 };
623
624 >>>>>>> remotes/origin/upstream
625 struct _Widget_Data
626 {
627    Evas_Object *obj;
628    Evas_Object *scr;
629    Evas_Object *ges;
630    Evas_Object *pan_smart;
631 <<<<<<< HEAD
632    Evas_Object *rect;
633    Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
634    Pan *pan;
635    Evas_Coord pan_x, pan_y, minw, minh;
636
637    int id;
638    int zoom;
639    int zoom_method;
640    Elm_Map_Zoom_Mode mode;
641
642    Ecore_Job *calc_job;
643    Ecore_Timer *scr_timer;
644    Ecore_Timer *long_timer;
645    Ecore_Animator *zoom_animator;
646    double t;
647    struct
648      {
649         int w, h;
650         int ow, oh, nw, nh;
651         struct
652           {
653              double x, y;
654           } spos;
655      } size;
656    struct
657      {
658         Eina_Bool show : 1;
659         Evas_Coord x, y ,w ,h;
660      } show;
661    int tsize;
662    int nosmooth;
663    Eina_List *grids;
664    Eina_Bool resized : 1;
665    Eina_Bool on_hold : 1;
666    Eina_Bool paused : 1;
667    Eina_Bool paused_markers : 1;
668
669    struct
670      {
671         Eina_Bool enabled;
672         double lon, lat;
673      } center_on;
674
675    Ecore_Job *markers_place_job;
676    Eina_Matrixsparse **markers;
677    Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
678    Evas_Coord markers_max_num;
679    int marker_max_w, marker_max_h;
680    int marker_zoom;
681    Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
682
683    Eina_List *groups_clas; // list of Elm_Map_Group_Class*
684    Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
685
686    Elm_Map_Route_Sources route_source;
687    Eina_List *s_event_list;
688    int try_num;
689    int finish_num;
690
691    Eina_Hash *ua;
692    const char *user_agent;
693    Eina_List *route;
694    Eina_List *track;
695    Evas_Event_Mouse_Down ev;
696    Eina_List *names;
697    int multi_count;
698
699    struct
700      {
701         Evas_Coord cx, cy;
702         double level, diff;
703      } pinch;
704
705 =======
706    Evas_Object *sep_maps_markers; // Tiles are below this and overlays are on top
707    Evas_Map *map;
708
709    Eina_Array *src_tile_mods;
710    Source_Tile *src_tile;
711    Eina_List *src_tiles;
712    const char **src_tile_names;
713
714    Eina_Array *src_route_mods;
715    Source_Route *src_route;
716    Eina_List *src_routes;
717    const char **src_route_names;
718
719    Eina_Array *src_name_mods;
720    Source_Name *src_name;
721    Eina_List *src_names;
722    const char **src_name_names;
723
724    int zoom_min, zoom_max;
725    int tsize;
726
727    int id;
728    Eina_List *grids;
729
730    int zoom;
731    double zoom_detail;
732    double prev_lon, prev_lat;
733    Evas_Coord ox, oy;
734    struct
735      {
736         int w, h;  // Current pixel width, heigth of a grid
737         int tile;  // Current pixel size of a grid item
738      } size;
739    Elm_Map_Zoom_Mode mode;
740    struct
741      {
742         double zoom;
743         double diff;
744         int cnt;
745      } ani;
746    Ecore_Timer *zoom_timer;
747    Ecore_Animator *zoom_animator;
748
749    int try_num;
750    int finish_num;
751    int download_num;
752    Eina_List *download_list;
753    Ecore_Idler *download_idler;
754    Eina_Hash *ua;
755    const char *user_agent;
756
757    Evas_Coord pan_x, pan_y;
758    Eina_List *delayed_jobs;
759
760    Ecore_Timer *scr_timer;
761    Ecore_Timer *long_timer;
762    Evas_Event_Mouse_Down ev;
763    Eina_Bool on_hold : 1;
764    Eina_Bool paused : 1;
765
766    double pinch_zoom;
767 >>>>>>> remotes/origin/upstream
768    struct
769      {
770         Evas_Coord cx, cy;
771         double a, d;
772      } rotate;
773
774 <<<<<<< HEAD
775    int wheel_diff;
776    Eina_Bool wheel_disabled : 1;
777    Eina_Bool scr_started : 1;
778
779    Eina_Array *modules;
780    Eina_List *map_sources_tab;
781    const char **source_names;
782    Evas_Map *map;
783    Ecore_Timer *zoom_timer;
784    Map_Sources_Tab *src;
785    const char *gpx_file;
786    int zoom_min, zoom_max;
787    Eina_List *download_list;
788    int download_num;
789 };
790
791 struct _Pan
792 {
793    Evas_Object_Smart_Clipped_Data __clipped_data;
794    Widget_Data *wd;
795 };
796
797 struct _Event
798 {
799    int device;
800
801    struct
802      {
803         Evas_Coord x, y;
804      } start;
805
806    struct
807      {
808         Evas_Coord x, y;
809      } prev;
810
811    Evas_Coord x, y, w, h;
812
813    Evas_Object *object;
814
815    int pinch_start_dis;
816    int pinch_dis;
817 };
818
819 struct _Route_Dump
820 {
821    int id;
822    char *fname;
823    double distance;
824    char *description;
825    char *coordinates;
826 };
827
828 enum _Route_Xml_Attribute
829 {
830    ROUTE_XML_NONE,
831    ROUTE_XML_DISTANCE,
832    ROUTE_XML_DESCRIPTION,
833    ROUTE_XML_COORDINATES,
834    ROUTE_XML_LAST
835 } Route_Xml_Attibute;
836
837 struct _Name_Dump
838 {
839    int id;
840    char *address;
841    double lon;
842    double lat;
843 };
844
845 enum _Name_Xml_Attribute
846 {
847    NAME_XML_NONE,
848    NAME_XML_NAME,
849    NAME_XML_LON,
850    NAME_XML_LAT,
851    NAME_XML_LAST
852 } Name_Xml_Attibute;
853
854 enum _Zoom_Method
855 {
856    ZOOM_METHOD_NONE,
857    ZOOM_METHOD_IN,
858    ZOOM_METHOD_OUT,
859    ZOOM_METHOD_LAST
860 } Zoom_Mode;
861
862 enum _Track_Xml_Attribute
863 {
864    TRACK_XML_NONE,
865    TRACK_XML_COORDINATES,
866    TRACK_XML_LAST
867 } Track_Xml_Attibute;
868
869 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
870 static const char *widtype = NULL;
871 static int idnum = 1;
872
873 static const char SIG_CHANGED[] = "changed";
874 static const char SIG_CLICKED[] = "clicked";
875 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
876 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
877 static const char SIG_LOAD_DETAIL[] = "load,detail";
878 static const char SIG_LONGPRESSED[] = "longpressed";
879 static const char SIG_PRESS[] = "press";
880 static const char SIG_SCROLL[] = "scroll";
881 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
882 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
883 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
884 static const char SIG_ZOOM_START[] = "zoom,start";
885 static const char SIG_ZOOM_STOP[] = "zoom,stop";
886 static const char SIG_DOWNLOADED[] = "downloaded";
887 static const char SIG_ROUTE_LOAD[] = "route,load";
888 static const char SIG_ROUTE_LOADED[] = "route,loaded";
889 static const char SIG_NAME_LOAD[] = "name,load";
890 static const char SIG_NAME_LOADED[] = "name,loaded";
891 static const Evas_Smart_Cb_Description _signals[] = {
892        {SIG_CHANGED, ""},
893        {SIG_CLICKED, ""},
894        {SIG_CLICKED_DOUBLE, ""},
895        {SIG_LOADED_DETAIL, ""},
896        {SIG_LOAD_DETAIL, ""},
897        {SIG_LONGPRESSED, ""},
898        {SIG_PRESS, ""},
899        {SIG_SCROLL, ""},
900        {SIG_SCROLL_DRAG_START, ""},
901        {SIG_SCROLL_DRAG_STOP, ""},
902        {SIG_ZOOM_CHANGE, ""},
903        {SIG_ZOOM_START, ""},
904        {SIG_ZOOM_STOP, ""},
905        {SIG_DOWNLOADED, ""},
906        {SIG_ROUTE_LOAD, ""},
907        {SIG_ROUTE_LOADED, ""},
908        {SIG_NAME_LOAD, ""},
909        {SIG_NAME_LOADED, ""},
910        {NULL, NULL}
911 };
912
913 static void _pan_calculate(Evas_Object *obj);
914
915 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
916 static void _del_hook(Evas_Object *obj);
917 static void _theme_hook(Evas_Object *obj);
918 static void _on_focus_hook(void *data, Evas_Object *obj);
919 static void _sizing_eval(Evas_Object *obj);
920 static void _calc_job(void *data);
921 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
922                              Evas_Callback_Type type, void *event_info);
923 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
924 static void grid_load(Evas_Object *obj, Grid *g);
925
926 static void _process_download_list(Evas_Object *obj);
927 static void _add_download_list(Evas_Object *obj, Grid_Item *gi);
928
929 static void _group_object_create(Marker_Group *group);
930 static void _group_object_free(Marker_Group *group);
931 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
932 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
933 static void _group_bubble_create(Marker_Group *group);
934 static void _group_bubble_free(Marker_Group *group);
935 static void _group_bubble_place(Marker_Group *group);
936
937 static int _group_bubble_content_update(Marker_Group *group);
938 static void _group_bubble_content_free(Marker_Group *group);
939 static void marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
940 static void _bubble_sc_hints_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
941
942 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
943 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
944
945 static void route_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
946 static void track_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
947
948 static Eina_Bool
949 module_list_cb(Eina_Module *m, void *data)
950 {
951    ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
952    Widget_Data *wd = elm_widget_data_get(data);
953    Map_Sources_Tab *s;
954    ElmMapModuleSourceFunc source;
955    ElmMapModuleZoomMinFunc zoom_min;
956    ElmMapModuleZoomMaxFunc zoom_max;
957    ElmMapModuleUrlFunc url;
958    ElmMapModuleRouteSourceFunc route_source;
959    ElmMapModuleRouteUrlFunc route_url;
960    ElmMapModuleNameUrlFunc name_url;
961    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
962    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
963    const char *file;
964
965    if (!wd) return EINA_FALSE;
966
967    file = eina_module_file_get(m);
968    if (!eina_module_load(m))
969      {
970         ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
971         return EINA_FALSE;
972      }
973
974    source = eina_module_symbol_get(m, "map_module_source_get");
975    zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
976    zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
977    url = eina_module_symbol_get(m, "map_module_url_get");
978    route_source = eina_module_symbol_get(m, "map_module_route_source_get");
979    route_url = eina_module_symbol_get(m, "map_module_route_url_get");
980    name_url = eina_module_symbol_get(m, "map_module_name_url_get");
981    geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
982    coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
983    if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
984      {
985         WRN("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
986         eina_module_unload(m);
987         return EINA_FALSE;
988      }
989    s = calloc(1, sizeof(Map_Sources_Tab));
990    EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
991    s->name = source();
992    s->zoom_min = zoom_min();
993    s->zoom_max = zoom_max();
994    s->url_cb = url;
995    s->route_source = route_source();
996    s->route_url_cb = route_url;
997    s->name_url_cb = name_url;
998    s->geo_into_coord = geo_into_coord;
999    s->coord_into_geo = coord_into_geo;
1000    wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
1001
1002    return EINA_TRUE;
1003 }
1004
1005 static void
1006 module_init(void *data)
1007 {
1008    ELM_CHECK_WIDTYPE(data, widtype);
1009    Widget_Data *wd = elm_widget_data_get(data);
1010
1011    if (!wd) return;
1012    wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
1013 }
1014
1015 static void
1016 source_init(void *data)
1017 {
1018    ELM_CHECK_WIDTYPE(data, widtype);
1019    Widget_Data *wd = elm_widget_data_get(data);
1020    Map_Sources_Tab *s;
1021    Eina_List *l;
1022    unsigned int idx;
1023
1024    if (!wd) return;
1025    for (idx = 0; idx < sizeof(default_map_sources_tab)/sizeof(Map_Sources_Tab); idx++)
1026      {
1027         s = calloc(1, sizeof(Map_Sources_Tab));
1028         EINA_SAFETY_ON_NULL_RETURN(s);
1029         s->name = default_map_sources_tab[idx].name;
1030         s->zoom_min = default_map_sources_tab[idx].zoom_min;
1031         s->zoom_max = default_map_sources_tab[idx].zoom_max;
1032         s->url_cb = default_map_sources_tab[idx].url_cb;
1033         s->route_source = default_map_sources_tab[idx].route_source;
1034         s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
1035         s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
1036         s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
1037         s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
1038         wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
1039         if (!idx) wd->src = s;
1040      }
1041    module_init(data);
1042
1043    int n = eina_list_count(wd->map_sources_tab);
1044    wd->source_names = malloc(sizeof(char *) * (n + 1));
1045    if (!wd->source_names)
1046      {
1047         ERR("init source names failed.");
1048         return;
1049      }
1050    idx = 0;
1051    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
1052      {
1053         wd->source_names[idx] = strdup(s->name);
1054         INF("source : %s", wd->source_names[idx]);
1055         if (s->zoom_min < wd->zoom_min) wd->zoom_min = s->zoom_min;
1056         if (s->zoom_max > wd->zoom_max) wd->zoom_max = s->zoom_max;
1057         idx++;
1058      }
1059    wd->source_names[idx] = NULL;
1060 }
1061
1062 static void
1063 obj_rotate_zoom(void *data, Evas_Object *obj)
1064 {
1065    ELM_CHECK_WIDTYPE(data, widtype);
1066    Widget_Data *wd = elm_widget_data_get(data);
1067    int ow, oh, iw, ih;
1068    if ((!wd->pinch.cx) && (!wd->pinch.cy))
1069      {
1070         wd->pinch.cx = wd->rotate.cx;
1071         wd->pinch.cy = wd->rotate.cy;
1072      }
1073
1074    evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
1075    evas_object_image_size_get(obj, &iw, &ih);
1076    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1077    if ((ow < iw) || (oh < ih))
1078      {
1079         ow *= (double)iw / ow;
1080         oh *= (double)ih / oh;
1081         evas_map_point_image_uv_set(wd->map, 1, ow, 0);
1082         evas_map_point_image_uv_set(wd->map, 2, ow, oh);
1083         evas_map_point_image_uv_set(wd->map, 3, 0, oh);
1084      }
1085    evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
1086    evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
1087    evas_object_map_enable_set(obj, EINA_TRUE);
1088    evas_object_map_set(obj, wd->map);
1089 }
1090
1091 static void
1092 #ifdef ELM_EMAP
1093 track_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
1094 #else
1095 track_place(Evas_Object *obj __UNUSED__, Grid *g __UNUSED__, Evas_Coord px __UNUSED__, Evas_Coord py __UNUSED__, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow __UNUSED__, Evas_Coord oh __UNUSED__)
1096 #endif
1097 {
1098 #ifdef ELM_EMAP
1099    ELM_CHECK_WIDTYPE(obj, widtype);
1100    Widget_Data *wd = elm_widget_data_get(obj);
1101    Eina_List *l;
1102    Evas_Object *route;
1103    int xmin, xmax, ymin, ymax;
1104
1105    if (!wd) return;
1106    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
1107
1108    EINA_LIST_FOREACH(wd->track, l, route)
1109      {
1110         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
1111         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
1112
1113         if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
1114         {
1115            if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
1116            {
1117               //display the route
1118               evas_object_move(route, xmin - px + ox, ymin - py + oy);
1119               evas_object_resize(route, xmax - xmin, ymax - ymin);
1120
1121               evas_object_raise(route);
1122               obj_rotate_zoom(obj, route);
1123               evas_object_show(route);
1124
1125               continue;
1126            }
1127         }
1128         //the route is not display
1129         evas_object_hide(route);
1130      }
1131 #endif
1132 }
1133 static void
1134 route_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
1135 {
1136    ELM_CHECK_WIDTYPE(obj, widtype);
1137    Widget_Data *wd = elm_widget_data_get(obj);
1138    Eina_List *lr, *lp, *ln;
1139    Path_Node *n;
1140    Evas_Object *p;
1141    Elm_Map_Route *r;
1142    int nodes;
1143    int x, y, rx, ry;
1144    double a;
1145
1146    if (!wd) return;
1147    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
1148
1149    EINA_LIST_FOREACH(wd->route, lr, r)
1150      {
1151         EINA_LIST_FOREACH(r->path, lp, p)
1152           {
1153              evas_object_polygon_points_clear(p);
1154           }
1155
1156         evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
1157         nodes = eina_list_count(r->nodes);
1158
1159         EINA_LIST_FOREACH(r->nodes, ln, n)
1160           {
1161              if ((!wd->zoom) || ((n->idx) &&
1162                  ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
1163              if (r->inbound)
1164                {
1165                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
1166                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
1167                       (y >= py - oh) && (y <= (py + oh*2)))
1168                     {
1169                        x = x - px + rx;
1170                        y = y - py + ry;
1171
1172                        p = eina_list_nth(r->path, n->idx);
1173                        a = (double)(y - r->y) / (double)(x - r->x);
1174                        if ((abs(a) >= 1) || (r->x == x))
1175                          {
1176                             evas_object_polygon_point_add(p, r->x - 3, r->y);
1177                             evas_object_polygon_point_add(p, r->x + 3, r->y);
1178                             evas_object_polygon_point_add(p, x + 3, y);
1179                             evas_object_polygon_point_add(p, x - 3, y);
1180                          }
1181                        else
1182                          {
1183                             evas_object_polygon_point_add(p, r->x, r->y - 3);
1184                             evas_object_polygon_point_add(p, r->x, r->y + 3);
1185                             evas_object_polygon_point_add(p, x, y + 3);
1186                             evas_object_polygon_point_add(p, x, y - 3);
1187                          }
1188
1189                        evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
1190                        evas_object_raise(p);
1191                        obj_rotate_zoom(obj, p);
1192                        evas_object_show(p);
1193                        r->x = x;
1194                        r->y = y;
1195                     }
1196                   else r->inbound = EINA_FALSE;
1197                }
1198              else
1199                {
1200                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
1201                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
1202                       (y >= py - oh) && (y <= (py + oh*2)))
1203                     {
1204                        r->x = x - px + rx;
1205                        r->y = y - py + ry;
1206                        r->inbound = EINA_TRUE;
1207                     }
1208                   else r->inbound = EINA_FALSE;
1209                }
1210           }
1211           r->inbound = EINA_FALSE;
1212      }
1213 }
1214
1215 static void
1216 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1217 {
1218    ELM_CHECK_WIDTYPE(obj, widtype);
1219    Widget_Data *wd = elm_widget_data_get(obj);
1220    Evas_Coord ax, ay, gw, gh, hh, ww;
1221
1222    if (!wd) return;
1223    evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
1224
1225    ax = 0;
1226    ay = 0;
1227    gw = wd->size.w;
1228    gh = wd->size.h;
1229
1230    if ((ww == gw) && (hh == gh)) return;
1231
1232    if (ow > gw) ax = (ow - gw) / 2;
1233    if (oh > gh) ay = (oh - gh) / 2;
1234    evas_object_move(wd->rect,
1235                     ox + 0 - px + ax,
1236                     oy + 0 - py + ay);
1237    evas_object_resize(wd->rect, gw, gh);
1238
1239    if (wd->show.show)
1240      {
1241         wd->show.show = EINA_FALSE;
1242         elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
1243      }
1244 }
1245
1246 static void
1247 marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1248 {
1249    ELM_CHECK_WIDTYPE(obj, widtype);
1250    Widget_Data *wd = elm_widget_data_get(obj);
1251    Evas_Coord ax, ay, gw, gh, tx, ty;
1252    Eina_List *l, *markers;
1253    Eina_Matrixsparse_Cell *cell;
1254    Marker_Group *group;
1255    int xx, yy, ww, hh;
1256    char buf[PATH_MAX];
1257    int y, x;
1258    int g_xx, g_yy, g_hh, g_ww;
1259
1260    if (!wd) return;
1261
1262    ax = 0;
1263    ay = 0;
1264    gw = wd->size.w;
1265    gh = wd->size.h;
1266    if (ow > gw) ax = (ow - gw) / 2;
1267    if (oh > gh) ay = (oh - gh) / 2;
1268
1269    if (wd->zoom != wd->marker_zoom)
1270      {
1271         EINA_LIST_FREE(wd->cells_displayed, cell)
1272           {
1273              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1274                {
1275                   if (group->obj) _group_object_free(group);
1276                }
1277           }
1278      }
1279    wd->marker_zoom = wd->zoom;
1280
1281    if ((wd->paused_markers)
1282        && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
1283      return;
1284
1285    g_xx = wd->pan_x / wd->tsize;
1286    if (g_xx < 0) g_xx = 0;
1287    g_yy = wd->pan_y / wd->tsize;
1288    if (g_yy < 0) g_yy = 0;
1289    g_ww = (ow / wd->tsize) + 1;
1290    if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
1291    g_hh = (oh / wd->tsize) + 1;
1292    if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
1293
1294    //hide groups no more displayed
1295    EINA_LIST_FREE(wd->cells_displayed, cell)
1296      {
1297         eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
1298         if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
1299           {
1300              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
1301                {
1302                   if (group->obj) _group_object_free(group);
1303                }
1304           }
1305      }
1306
1307    if (!wd->marker_zoom)
1308      {
1309         g_ww = 0;
1310         g_hh = 0;
1311      }
1312
1313    for (y = g_yy; y <= g_yy + g_hh; y++)
1314      {
1315         for (x = g_xx; x <= g_xx + g_ww; x++)
1316           {
1317              if (!wd->markers[wd->zoom]) continue;
1318              eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1319              if (!cell) continue;
1320              wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1321              markers = eina_matrixsparse_cell_data_get(cell);
1322              EINA_LIST_FOREACH(markers, l, group)
1323                {
1324                   if (!group->markers) continue;
1325                   if (group->clas->zoom_displayed > wd->zoom) continue;
1326
1327                   xx = group->x;
1328                   yy = group->y;
1329                   ww = group->w;
1330                   hh = group->h;
1331
1332                   if (eina_list_count(group->markers) == 1)
1333                     {
1334                        Elm_Map_Marker *m = eina_list_data_get(group->markers);
1335                        ww = m->clas->priv.edje_w;
1336                        hh = m->clas->priv.edje_h;
1337                     }
1338
1339                   if (ww <= 0) ww = 1;
1340                   if (hh <= 0) hh = 1;
1341
1342                   if ((gw != g->w) && (g->w > 0))
1343                     {
1344                        tx = xx;
1345                        xx = ((long long )gw * xx) / g->w;
1346                        ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1347                     }
1348                   if ((gh != g->h) && (g->h > 0))
1349                     {
1350                        ty = yy;
1351                        yy = ((long long)gh * yy) / g->h;
1352                        hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1353                     }
1354
1355                   if ((!group->clas->hide)
1356                       && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1357                       && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1358                     {
1359                        if (!group->obj) _group_object_create(group);
1360
1361                        if (group->update_nbelems)
1362                          {
1363                             group->update_nbelems = EINA_FALSE;
1364                             if (eina_list_count(group->markers) > 1)
1365                               {
1366                                  snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1367                                  edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1368                               }
1369                             else
1370                               edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1371                          }
1372                        evas_object_move(group->obj,
1373                                         xx - px + ax + ox - ww/2,
1374                                         yy - py + ay + oy - hh/2);
1375                        if ((!wd->paused_markers) || (group->update_resize))
1376                          {
1377                             group->update_resize = EINA_FALSE;
1378                             evas_object_resize(group->obj, ww, hh);
1379                             obj_rotate_zoom(obj, group->obj);
1380                          }
1381                        if (group->update_raise)
1382                          {
1383                             group->update_raise = EINA_FALSE;
1384                             evas_object_raise(group->obj);
1385                             obj_rotate_zoom(obj, group->obj);
1386                             evas_object_show(group->obj);
1387                          }
1388                        if (group->bubble) _group_bubble_place(group);
1389                     }
1390                   else if (group->obj)
1391                     {
1392                        _group_object_free(group);
1393                     }
1394                }
1395           }
1396      }
1397 }
1398
1399 static void
1400 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1401 {
1402    ELM_CHECK_WIDTYPE(obj, widtype);
1403    Widget_Data *wd = elm_widget_data_get(obj);
1404    Evas_Coord ax, ay, gw, gh, tx, ty;
1405    int xx, yy, ww, hh;
1406
1407    if (!wd) return;
1408    ax = 0;
1409    ay = 0;
1410    gw = wd->size.w;
1411    gh = wd->size.h;
1412    if (ow > gw) ax = (ow - gw) / 2;
1413    if (oh > gh) ay = (oh - gh) / 2;
1414
1415    Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1416    Eina_Matrixsparse_Cell *cell;
1417
1418    EINA_ITERATOR_FOREACH(it, cell)
1419      {
1420         Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1421
1422         xx = gi->out.x;
1423         yy = gi->out.y;
1424         ww = gi->out.w;
1425         hh = gi->out.h;
1426         if ((gw != g->w) && (g->w > 0))
1427           {
1428              tx = xx;
1429              xx = ((long long )gw * xx) / g->w;
1430              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1431           }
1432         if ((gh != g->h) && (g->h > 0))
1433           {
1434              ty = yy;
1435              yy = ((long long)gh * yy) / g->h;
1436              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1437           }
1438         evas_object_move(gi->img,
1439                          xx - px + ax + ox,
1440                          yy - py + ay + oy);
1441
1442         evas_object_resize(gi->img, ww, hh);
1443
1444         obj_rotate_zoom(obj, gi->img);
1445         /*evas_object_move(gi->txt,
1446                            xx - px + ax + ox,
1447                            yy - py + ay + oy);
1448
1449           evas_object_resize(gi->txt, ww, hh);
1450          */
1451      }
1452    eina_iterator_free(it);
1453 }
1454
1455 static void
1456 _tile_update(Grid_Item *gi)
1457 {
1458    evas_object_image_file_set(gi->img, gi->file, NULL);
1459    Evas_Load_Error err = evas_object_image_load_error_get(gi->img);
1460    if (err != EVAS_LOAD_ERROR_NONE)
1461      {
1462         ERR("Image loading error (%s): %s", gi->file, evas_load_error_str(err));
1463         ecore_file_remove(gi->file);
1464         gi->file_have = EINA_FALSE;
1465      }
1466    else
1467      {
1468         obj_rotate_zoom(gi->wd->obj, gi->img);
1469         evas_object_show(gi->img);
1470         gi->file_have = EINA_TRUE;
1471         //evas_object_text_text_set(gi->txt, gi->file);
1472         //evas_object_show(gi->txt);
1473      }
1474 }
1475
1476 static void
1477 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1478 {
1479    Grid_Item *gi = data;
1480
1481    gi->job = NULL;
1482
1483    if (status == 200)
1484      {
1485         DBG("Download success from %s to %s", gi->source, gi->file);
1486         _tile_update(gi);
1487         gi->wd->finish_num++;
1488      }
1489    else
1490      {
1491         WRN("Download failed from %s to %s (%d) ", gi->source, gi->file, status);
1492         ecore_file_remove(gi->file);
1493         gi->file_have = EINA_FALSE;
1494      }
1495
1496    gi->wd->download_num--;
1497    evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1498    if (!gi->wd->download_num)
1499      {
1500         edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr), "elm,state,busy,stop", "elm");
1501         evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1502      }
1503    _process_download_list(gi->wd->obj);
1504 }
1505
1506 static void
1507 _process_download_list(Evas_Object *obj)
1508 {
1509    ELM_CHECK_WIDTYPE(obj, widtype);
1510    Widget_Data *wd = elm_widget_data_get(obj);
1511    Eina_List *l, *ll;
1512    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1513    Grid_Item *gi;
1514
1515    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1516    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1517
1518    gw = wd->size.w;
1519    gh = wd->size.h;
1520
1521    EINA_LIST_REVERSE_FOREACH_SAFE(wd->download_list, l, ll, gi)
1522      {
1523         xx = gi->out.x;
1524         yy = gi->out.y;
1525         ww = gi->out.w;
1526         hh = gi->out.h;
1527
1528         if ((gw != gi->g->w) && (gi->g->w > 0))
1529           {
1530              tx = xx;
1531              xx = ((long long )gw * xx) / gi->g->w;
1532              ww = (((long long)gw * (tx + ww)) / gi->g->w) - xx;
1533           }
1534         if ((gh != gi->g->h) && (gi->g->h > 0))
1535           {
1536              ty = yy;
1537              yy = ((long long)gh * yy) / gi->g->h;
1538              hh = (((long long)gh * (ty + hh)) / gi->g->h) - yy;
1539           }
1540         if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1541                                  yy  - wd->pan_y + oy,
1542                                  ww, hh,
1543                                  cvx, cvy, cvw, cvh) ||
1544            (gi->zoom != wd->zoom))
1545           {
1546              wd->download_list = eina_list_remove(wd->download_list, gi);
1547              continue;
1548           }
1549
1550         if (gi->wd->download_num >= MAX_CONCURRENT_DOWNLOAD) break;
1551
1552         Eina_Bool ret = ecore_file_download_full(gi->source, gi->file, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1553         if (!ret || !gi->job) ERR("Can't start to download from %s to %s", gi->source, gi->file);
1554         else
1555           {
1556              gi->wd->download_num++;
1557              wd->try_num++;
1558              wd->download_list = eina_list_remove(wd->download_list, gi);
1559              if (wd->download_num == 1)
1560                edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,state,busy,start", "elm");
1561           }
1562      }
1563 }
1564
1565 static void
1566 _add_download_list(Evas_Object *obj, Grid_Item *gi)
1567 {
1568    ELM_CHECK_WIDTYPE(obj, widtype);
1569    Widget_Data *wd = elm_widget_data_get(obj);
1570
1571    wd->download_list = eina_list_remove(wd->download_list, gi);
1572    wd->download_list = eina_list_append(wd->download_list, gi);
1573    _process_download_list(obj);
1574 }
1575
1576 static void
1577 grid_create_all(Evas_Object *obj)
1578 {
1579    ELM_CHECK_WIDTYPE(obj, widtype);
1580    Widget_Data *wd = elm_widget_data_get(obj);
1581    Grid *g;
1582    int zoom = 0;
1583
1584    EINA_SAFETY_ON_NULL_RETURN(wd);
1585    EINA_SAFETY_ON_NULL_RETURN(wd->src);
1586
1587    for (zoom = wd->src->zoom_min; zoom <= wd->src->zoom_max; zoom++)
1588      {
1589         g = calloc(1, sizeof(Grid));
1590         EINA_SAFETY_ON_NULL_RETURN(g);
1591         g->zoom = zoom;
1592         g->tsize = wd->tsize;
1593         g->wd = wd;
1594         int size =  pow(2.0, g->zoom);
1595         g->gw = size;
1596         g->gh = size;
1597         g->w = g->tsize * g->gw;
1598         g->h = g->tsize * g->gh;
1599
1600         g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1601         wd->grids = eina_list_append(wd->grids, g);
1602      }
1603 }
1604
1605 static void
1606 grid_clear_all(Evas_Object *obj)
1607 {
1608    ELM_CHECK_WIDTYPE(obj, widtype);
1609    Widget_Data *wd = elm_widget_data_get(obj);
1610    Grid *g;
1611    Grid_Item *gi;
1612
1613    EINA_SAFETY_ON_NULL_RETURN(wd);
1614
1615    EINA_LIST_FREE(wd->grids, g)
1616      {
1617         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1618         Eina_Matrixsparse_Cell *cell;
1619
1620         EINA_ITERATOR_FOREACH(it, cell)
1621           {
1622              gi = eina_matrixsparse_cell_data_get(cell);
1623              evas_object_del(gi->img);
1624              //evas_object_del(gi->txt);
1625
1626              if (gi->job)
1627                {
1628                   DBG("DOWNLOAD abort %s", gi->file);
1629                   ecore_file_download_abort(gi->job);
1630                   ecore_file_remove(gi->file);
1631                   gi->file_have = EINA_FALSE;
1632                   gi->job = NULL;
1633                   wd->try_num--;
1634                }
1635              if (gi->file)   eina_stringshare_del(gi->file);
1636              if (gi->source) eina_stringshare_del(gi->source);
1637              free(gi);
1638           }
1639         eina_matrixsparse_free(g->grid);
1640         eina_iterator_free(it);
1641         free(g);
1642      }
1643
1644    EINA_LIST_FREE(wd->download_list, gi);
1645    if (!ecore_file_recursive_rm("/tmp/elm_map/")) WRN("Deletion of /tmp/elm_map/ failed");
1646
1647 }
1648
1649 static void
1650 grid_unload(Evas_Object *obj, Grid *g)
1651 {
1652    ELM_CHECK_WIDTYPE(obj, widtype);
1653    Widget_Data *wd = elm_widget_data_get(obj);
1654
1655    Eina_Iterator *it;
1656    Eina_Matrixsparse_Cell *cell;
1657    Grid_Item *gi;
1658
1659    EINA_SAFETY_ON_NULL_RETURN(wd);
1660
1661    it = eina_matrixsparse_iterator_new(g->grid);
1662    EINA_ITERATOR_FOREACH(it, cell)
1663      {
1664         gi = eina_matrixsparse_cell_data_get(cell);
1665
1666         if (gi->file_have)
1667           {
1668              evas_object_hide(gi->img);
1669              //evas_object_hide(gi->txt);
1670              evas_object_image_file_set(gi->img, NULL, NULL);
1671           }
1672         else if (gi->job)
1673           {
1674              DBG("DOWNLOAD abort %s", gi->file);
1675              ecore_file_download_abort(gi->job);
1676              ecore_file_remove(gi->file);
1677              gi->job = NULL;
1678              wd->try_num--;
1679           }
1680      }
1681    eina_iterator_free(it);
1682 }
1683
1684
1685 static void
1686 grid_load(Evas_Object *obj, Grid *g)
1687 {
1688    ELM_CHECK_WIDTYPE(obj, widtype);
1689    Widget_Data *wd = elm_widget_data_get(obj);
1690    int x, y;
1691    int size;
1692    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1693    Eina_Iterator *it;
1694    Eina_Matrixsparse_Cell *cell;
1695    Grid_Item *gi;
1696
1697    EINA_SAFETY_ON_NULL_RETURN(wd);
1698    EINA_SAFETY_ON_NULL_RETURN(wd->src);
1699
1700    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1701    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1702
1703    gw = wd->size.w;
1704    gh = wd->size.h;
1705
1706    if ((gw <= 0) || (gh <= 0)) return;
1707
1708    size = g->tsize;
1709    if ((gw != g->w) && (g->w > 0))
1710      size = ((long long)gw * size) / g->w;
1711    if (size < (g->tsize / 2)) return; // else we will load to much tiles
1712
1713    it = eina_matrixsparse_iterator_new(g->grid);
1714
1715    EINA_ITERATOR_FOREACH(it, cell)
1716      {
1717         gi = eina_matrixsparse_cell_data_get(cell);
1718
1719         xx = gi->out.x;
1720         yy = gi->out.y;
1721         ww = gi->out.w;
1722         hh = gi->out.h;
1723
1724         if ((gw != g->w) && (g->w > 0))
1725           {
1726              tx = xx;
1727              xx = ((long long )gw * xx) / g->w;
1728              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1729           }
1730         if ((gh != g->h) && (g->h > 0))
1731           {
1732              ty = yy;
1733              yy = ((long long)gh * yy) / g->h;
1734              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1735           }
1736
1737         if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1738                                  yy  - wd->pan_y + oy,
1739                                  ww, hh,
1740                                  cvx, cvy, cvw, cvh))
1741           {
1742              if (gi->file_have)
1743                {
1744                   evas_object_hide(gi->img);
1745                   //evas_object_hide(gi->txt);
1746                   evas_object_image_file_set(gi->img, NULL, NULL);
1747                }
1748              else if (gi->job)
1749                {
1750                   DBG("Download abort %s", gi->file);
1751                   ecore_file_download_abort(gi->job);
1752                   ecore_file_remove(gi->file);
1753                   gi->job = NULL;
1754                   wd->try_num--;
1755                }
1756           }
1757      }
1758    eina_iterator_free(it);
1759
1760    xx = wd->pan_x / size - 1;
1761    if (xx < 0) xx = 0;
1762
1763    yy = wd->pan_y / size - 1;
1764    if (yy < 0) yy = 0;
1765
1766    ww = ow / size + 2;
1767    if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1768
1769    hh = oh / size + 2;
1770    if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1771
1772    for (y = yy; y <= yy + hh; y++)
1773      {
1774         for (x = xx; x <= xx + ww; x++)
1775           {
1776              gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1777
1778              if (!gi)
1779                {
1780                   char buf[PATH_MAX];
1781                   char buf2[PATH_MAX];
1782                   char *source;
1783
1784                   gi = calloc(1, sizeof(Grid_Item));
1785                   EINA_SAFETY_ON_NULL_RETURN(gi);
1786
1787                   gi->wd = wd;
1788                   gi->g = g;
1789                   gi->zoom = g->zoom;
1790                   gi->file_have = EINA_FALSE;
1791                   gi->job = NULL;
1792
1793                   gi->src.x = x * g->tsize;
1794                   gi->src.y = y * g->tsize;
1795                   gi->src.w = g->tsize;
1796                   gi->src.h = g->tsize;
1797
1798                   gi->out.x = gi->src.x;
1799                   gi->out.y = gi->src.y;
1800                   gi->out.w = gi->src.w;
1801                   gi->out.h = gi->src.h;
1802
1803                   gi->img = evas_object_image_add(evas_object_evas_get(obj));
1804                   evas_object_image_scale_hint_set(gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1805                   evas_object_image_filled_set(gi->img, 1);
1806
1807                   evas_object_smart_member_add(gi->img, wd->pan_smart);
1808                   elm_widget_sub_object_add(obj, gi->img);
1809                   evas_object_pass_events_set(gi->img, EINA_TRUE);
1810                   evas_object_stack_below(gi->img, wd->sep_maps_markers);
1811
1812 /*                gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1813                   evas_object_text_font_set(gi->txt, "Vera", 12);
1814                   evas_object_color_set(gi->txt, 100, 100, 100, 255);
1815                   evas_object_smart_member_add(gi->txt,
1816                                                wd->pan_smart);
1817                   elm_widget_sub_object_add(obj, gi->txt);
1818                   evas_object_pass_events_set(gi->txt, EINA_TRUE);
1819 */
1820                   snprintf(buf, sizeof(buf), CACHE_PATH, wd->id, g->zoom, x);
1821                   snprintf(buf2, sizeof(buf2), CACHE_FILE_PATH, buf, y);
1822                   if (!ecore_file_exists(buf)) ecore_file_mkpath(buf);
1823
1824                   eina_stringshare_replace(&gi->file, buf2);
1825                   source = wd->src->url_cb(obj, x, y, g->zoom);
1826                   if ((!source) || (strlen(source)==0))
1827                     {
1828                        eina_stringshare_replace(&gi->source, NULL);
1829                        WRN("Getting source url failed: %s", gi->file);
1830                     }
1831                   else eina_stringshare_replace(&gi->source, source);
1832                   if (source) free(source);
1833
1834                   eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1835                }
1836
1837                if (gi->file_have)
1838                  {
1839                     DBG("File exists: %s", gi->file);
1840                     _tile_update(gi);
1841                  }
1842                else if (!gi->job)
1843                  {
1844                     DBG("Added to download list: %s", gi->file);
1845                     _add_download_list(obj, gi);
1846                  }
1847 =======
1848    Eina_Bool wheel_disabled : 1;
1849
1850    unsigned int markers_max_num;
1851    Eina_Bool paused_markers : 1;
1852    Eina_List *group_classes;
1853    Eina_List *marker_classes;
1854    Eina_List *markers;
1855
1856    Eina_List *routes;
1857    Eina_List *track;
1858    Eina_List *names;
1859
1860    Eina_List *overlays;
1861 };
1862
1863 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
1864 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
1865 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
1866 static char *_mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
1867 static char *_mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
1868 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat);
1869 static char *_nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat);
1870 /*
1871 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
1872 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
1873 */
1874
1875 const Source_Tile src_tiles[] =
1876 {
1877    {"Mapnik", 0, 18, _mapnik_url_cb, NULL, NULL},
1878    {"Osmarender", 0, 17, _osmarender_url_cb, NULL, NULL},
1879    {"CycleMap", 0, 16, _cyclemap_url_cb, NULL, NULL},
1880    {"MapQuest", 0, 18, _mapquest_url_cb, NULL, NULL},
1881    {"MapQuest Open Aerial", 0, 11, _mapquest_aerial_url_cb, NULL, NULL},
1882 };
1883
1884 // FIXME: Fix more open sources
1885 const Source_Route src_routes[] =
1886 {
1887    {"Yours", _yours_url_cb}    // http://www.yournavigation.org/
1888    //{"Monav", _monav_url_cb},
1889    //{"ORS", _ors_url_cb},     // http://www.openrouteservice.org
1890 };
1891
1892 // FIXME: Add more open sources
1893 const Source_Name src_names[] =
1894 {
1895    {"Nominatim", _nominatim_url_cb}
1896 };
1897
1898 static const char *widtype = NULL;
1899 static Evas_Smart_Class parent_sc = EVAS_SMART_CLASS_INIT_NULL;
1900 static Evas_Smart_Class sc;
1901 static Evas_Smart *smart;
1902 static int idnum = 1;
1903
1904 static const char SIG_CLICKED[] =            "clicked";
1905 static const char SIG_CLICKED_DOUBLE[] =     "clicked,double";
1906 static const char SIG_PRESS[] =              "press";
1907 static const char SIG_LONGPRESSED[] =        "longpressed";
1908 static const char SIG_SCROLL[] =             "scroll";
1909 static const char SIG_SCROLL_DRAG_START[] =  "scroll,drag,start";
1910 static const char SIG_SCROLL_DRAG_STOP[] =   "scroll,drag,stop";
1911 static const char SIG_SCROLL_ANIM_START[] =  "scroll,anim,start";
1912 static const char SIG_SCROLL_ANIM_STOP[] =   "scroll,anim,stop";
1913 static const char SIG_ZOOM_START[] =         "zoom,start";
1914 static const char SIG_ZOOM_STOP[] =          "zoom,stop";
1915 static const char SIG_ZOOM_CHANGE[] =        "zoom,change";
1916 static const char SIG_TILE_LOAD[] =          "tile,load";
1917 static const char SIG_TILE_LOADED[] =        "tile,loaded";
1918 static const char SIG_TILE_LOADED_FAIL[] =   "tile,loaded,fail";
1919 static const char SIG_ROUTE_LOAD[] =         "route,load";
1920 static const char SIG_ROUTE_LOADED[] =       "route,loaded";
1921 static const char SIG_ROUTE_LOADED_FAIL[] =  "route,loaded,fail";
1922 static const char SIG_NAME_LOAD[] =          "name,load";
1923 static const char SIG_NAME_LOADED[] =        "name,loaded";
1924 static const char SIG_NAME_LOADED_FAIL[] =   "name,loaded,fail";
1925 static const char SIG_OVERLAY_CLICKED[] =    "overlay,clicked";
1926 static const Evas_Smart_Cb_Description _signals[] = {
1927        {SIG_CLICKED, ""},
1928        {SIG_CLICKED_DOUBLE, ""},
1929        {SIG_PRESS, ""},
1930        {SIG_LONGPRESSED, ""},
1931        {SIG_SCROLL, ""},
1932        {SIG_SCROLL_DRAG_START, ""},
1933        {SIG_SCROLL_DRAG_STOP, ""},
1934        {SIG_SCROLL_ANIM_START, ""},
1935        {SIG_SCROLL_ANIM_STOP, ""},
1936        {SIG_ZOOM_START, ""},
1937        {SIG_ZOOM_STOP, ""},
1938        {SIG_ZOOM_CHANGE, ""},
1939        {SIG_TILE_LOAD, ""},
1940        {SIG_TILE_LOADED, ""},
1941        {SIG_TILE_LOADED_FAIL, ""},
1942        {SIG_ROUTE_LOAD, ""},
1943        {SIG_ROUTE_LOADED, ""},
1944        {SIG_ROUTE_LOADED_FAIL, ""},
1945        {SIG_NAME_LOAD, ""},
1946        {SIG_NAME_LOADED, ""},
1947        {SIG_NAME_LOADED_FAIL, ""},
1948        {SIG_OVERLAY_CLICKED, ""},
1949        {NULL, NULL}
1950 };
1951
1952 static void
1953 _edj_marker_size_get(Widget_Data *wd, Evas_Coord *w, Evas_Coord *h)
1954 {
1955    EINA_SAFETY_ON_NULL_RETURN(wd);
1956    EINA_SAFETY_ON_NULL_RETURN(w);
1957    EINA_SAFETY_ON_NULL_RETURN(h);
1958
1959    Evas_Object *edj;
1960    const char *s;
1961
1962    edj = edje_object_add(evas_object_evas_get(wd->obj));
1963    _elm_theme_object_set(wd->obj, edj, "map/marker", "radio",
1964                          elm_widget_style_get(wd->obj));
1965    s = edje_object_data_get(edj, "size_w");
1966    if (s) *w = atoi(s);
1967    else   *w = 0;
1968    s = edje_object_data_get(edj, "size_h");
1969    if (s) *h = atoi(s);
1970    else   *h = 0;
1971    evas_object_del(edj);
1972 }
1973
1974 static void
1975 _coord_rotate(Evas_Coord x, Evas_Coord y, Evas_Coord cx, Evas_Coord cy, double degree, Evas_Coord *xx, Evas_Coord *yy)
1976 {
1977    EINA_SAFETY_ON_NULL_RETURN(xx);
1978    EINA_SAFETY_ON_NULL_RETURN(yy);
1979
1980    double r = (degree * M_PI) / 180.0;
1981
1982    if (xx) *xx = ((x - cx) * cos(r)) + ((y - cy) * cos(r + M_PI_2)) + cx;
1983    if (yy) *yy = ((x - cx) * sin(r)) + ((y - cy) * sin(r + M_PI_2)) + cy;
1984 }
1985
1986 static void
1987 _obj_rotate(Widget_Data *wd, Evas_Object *obj)
1988 {
1989    Evas_Coord w, h, ow, oh;
1990    evas_map_util_points_populate_from_object(wd->map, obj);
1991
1992    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1993    evas_object_image_size_get(obj, &w, &h);
1994    if ((w > ow) || (h > oh))
1995      {
1996         evas_map_point_image_uv_set(wd->map, 0, 0, 0);
1997         evas_map_point_image_uv_set(wd->map, 1, w, 0);
1998         evas_map_point_image_uv_set(wd->map, 2, w, h);
1999         evas_map_point_image_uv_set(wd->map, 3, 0, h);
2000      }
2001    evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
2002
2003    evas_object_map_set(obj, wd->map);
2004    evas_object_map_enable_set(obj, EINA_TRUE);
2005 }
2006
2007 static void
2008 _obj_place(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
2009 {
2010    EINA_SAFETY_ON_NULL_RETURN(obj);
2011
2012    evas_object_move(obj, x, y);
2013    evas_object_resize(obj, w, h);
2014    evas_object_show(obj);
2015 }
2016
2017 static void
2018 _coord_to_region_convert(Widget_Data *wd, Evas_Coord x, Evas_Coord y, Evas_Coord size, double *lon, double *lat)
2019 {
2020    EINA_SAFETY_ON_NULL_RETURN(wd);
2021
2022    int zoom = floor(log(size / wd->size.tile) / log(2));
2023    if ((wd->src_tile) && (wd->src_tile->coord_to_geo))
2024      {
2025         if (wd->src_tile->coord_to_geo(wd->obj, zoom, x, y, size, lon, lat))
2026            return;
2027      }
2028
2029    if (lon) *lon = (x / (double)size * 360.0) - 180;
2030    if (lat)
2031      {
2032         double n = ELM_PI - (2.0 * ELM_PI * y / size);
2033         *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
2034      }
2035 }
2036
2037 static void
2038 _region_to_coord_convert(Widget_Data *wd, double lon, double lat, Evas_Coord size, Evas_Coord *x, Evas_Coord *y)
2039 {
2040    EINA_SAFETY_ON_NULL_RETURN(wd);
2041
2042    int zoom = floor(log(size / 256) / log(2));
2043    if ((wd->src_tile) && (wd->src_tile->geo_to_coord))
2044      {
2045         if (wd->src_tile->geo_to_coord(wd->obj, zoom, lon, lat, size, x, y)) return;
2046      }
2047
2048    if (x) *x = floor((lon + 180.0) / 360.0 * size);
2049    if (y)
2050       *y = floor((1.0 - log(tan(lat * ELM_PI / 180.0) + (1.0 / cos(lat * ELM_PI / 180.0)))
2051                  / ELM_PI) / 2.0 * size);
2052 }
2053
2054 static void
2055 _viewport_size_get(Widget_Data *wd, Evas_Coord *vw, Evas_Coord *vh)
2056 {
2057    EINA_SAFETY_ON_NULL_RETURN(wd);
2058
2059    Evas_Coord x, y, w, h;
2060    evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2061    if (vw) *vw = (x * 2) + w;
2062    if (vh) *vh = (y * 2) + h;
2063 }
2064
2065 static void
2066 _pan_geometry_get(Widget_Data *wd, Evas_Coord *px, Evas_Coord *py)
2067 {
2068    EINA_SAFETY_ON_NULL_RETURN(wd);
2069
2070    Evas_Coord x, y, vx, vy, vw, vh;
2071    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2072    evas_object_geometry_get(wd->pan_smart, &vx, &vy, &vw, &vh);
2073    x = -x;
2074    y = -y;
2075    if (vw > wd->size.w) x += (((vw - wd->size.w) / 2) + vx);
2076    else x -= vx;
2077    if (vh > wd->size.h) y += (((vh - wd->size.h) / 2) + vy);
2078    else y -= vy;
2079    if (px) *px = x;
2080    if (py) *py = y;
2081  }
2082
2083 static void
2084 _region_show(void *data)
2085 {
2086    EINA_SAFETY_ON_NULL_RETURN(data);
2087    Delayed_Data *dd = data;
2088    int x, y, w, h;
2089
2090    _region_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
2091    _viewport_size_get(dd->wd, &w, &h);
2092    x = x - (w / 2);
2093    y = y - (h / 2);
2094    elm_smart_scroller_child_region_show(dd->wd->scr, x, y, w, h);
2095    evas_object_smart_changed(dd->wd->pan_smart);
2096 }
2097
2098 static void
2099 _bubble_update(Marker_Bubble *bubble, Eina_List *contents)
2100 {
2101    EINA_SAFETY_ON_NULL_RETURN(bubble);
2102    EINA_SAFETY_ON_NULL_RETURN(contents);
2103
2104    Eina_List *l;
2105    Evas_Object *c;
2106
2107    elm_box_clear(bubble->bx);
2108    EINA_LIST_FOREACH(contents, l, c) elm_box_pack_end(bubble->bx, c);
2109 }
2110
2111 static void
2112 _bubble_place(Marker_Bubble *bubble)
2113 {
2114    EINA_SAFETY_ON_NULL_RETURN(bubble);
2115
2116    Evas_Coord x, y, w, h;
2117    Evas_Coord xx, yy, ww, hh;
2118    const char *s;
2119
2120    if ((!bubble->obj) || (!bubble->pobj)) return;
2121    evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
2122
2123    s = edje_object_data_get(bubble->obj, "size_w");
2124    if (s) ww = atoi(s);
2125    else ww = 0;
2126
2127    edje_object_size_min_calc(bubble->obj, NULL, &hh);
2128    s = edje_object_data_get(bubble->obj, "size_h");
2129    if (s) h = atoi(s);
2130    else h = 0;
2131    if (hh < h) hh = h;
2132
2133    xx = x + (w / 2) - (ww / 2);
2134    yy = y - hh;
2135
2136    _obj_place(bubble->obj, xx, yy, ww, hh);
2137    evas_object_raise(bubble->obj);
2138 }
2139
2140 static void
2141 _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2142 {
2143    Marker_Bubble *bubble = data;
2144    EINA_SAFETY_ON_NULL_RETURN(bubble);
2145    _bubble_place(data);
2146 }
2147
2148 static void
2149 _bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2150 {
2151    Marker_Bubble *bubble = data;
2152    EINA_SAFETY_ON_NULL_RETURN(bubble);
2153    _bubble_place(bubble);
2154 }
2155
2156 static void
2157 _bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2158 {
2159    Marker_Bubble *bubble = data;
2160    EINA_SAFETY_ON_NULL_RETURN(bubble);
2161    evas_object_hide(bubble->obj);
2162 }
2163
2164 static void
2165 _bubble_show_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2166 {
2167    Marker_Bubble *bubble = data;
2168    EINA_SAFETY_ON_NULL_RETURN(bubble);
2169    _bubble_place(bubble);
2170 }
2171
2172 static void
2173 _bubble_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2174 {
2175    Marker_Bubble *bubble = data;
2176    EINA_SAFETY_ON_NULL_RETURN(bubble);
2177    _bubble_place(bubble);
2178 }
2179
2180 static void
2181 _bubble_free(Marker_Bubble* bubble)
2182 {
2183    EINA_SAFETY_ON_NULL_RETURN(bubble);
2184
2185    evas_object_del(bubble->bx);
2186    evas_object_del(bubble->sc);
2187    evas_object_del(bubble->obj);
2188    free(bubble);
2189 }
2190
2191 static Marker_Bubble*
2192 _bubble_create(Evas_Object *pobj, Widget_Data *wd)
2193 {
2194    EINA_SAFETY_ON_NULL_RETURN_VAL(pobj, NULL);
2195    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2196
2197    Marker_Bubble *bubble = ELM_NEW(Marker_Bubble);
2198    EINA_SAFETY_ON_NULL_RETURN_VAL(bubble, NULL);
2199
2200    bubble->wd = wd;
2201    bubble->pobj = pobj;
2202    evas_object_event_callback_add(pobj, EVAS_CALLBACK_HIDE, _bubble_hide_cb,
2203                                   bubble);
2204    evas_object_event_callback_add(pobj, EVAS_CALLBACK_SHOW, _bubble_show_cb,
2205                                   bubble);
2206    evas_object_event_callback_add(pobj, EVAS_CALLBACK_MOVE, _bubble_move_cb,
2207                                   bubble);
2208
2209    bubble->obj = edje_object_add(evas_object_evas_get(pobj));
2210    _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
2211                          elm_widget_style_get(wd->obj));
2212    evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
2213                                   _bubble_mouse_up_cb, bubble);
2214
2215    bubble->sc = elm_scroller_add(bubble->obj);
2216    elm_widget_style_set(bubble->sc, "map_bubble");
2217    elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
2218    elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
2219                            ELM_SCROLLER_POLICY_OFF);
2220    elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
2221                            EINA_FALSE);
2222    edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
2223    evas_object_event_callback_add(bubble->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2224                                   _bubble_sc_hints_changed_cb, bubble);
2225
2226    bubble->bx = elm_box_add(bubble->sc);
2227    evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2228    evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
2229                                     EVAS_HINT_EXPAND);
2230    elm_box_horizontal_set(bubble->bx, EINA_TRUE);
2231    elm_object_content_set(bubble->sc, bubble->bx);
2232
2233    return bubble;
2234 }
2235
2236 static void
2237 _marker_group_update(Marker_Group* group, Elm_Map_Group_Class *clas, Eina_List *markers)
2238 {
2239    EINA_SAFETY_ON_NULL_RETURN(group);
2240    EINA_SAFETY_ON_NULL_RETURN(clas);
2241    EINA_SAFETY_ON_NULL_RETURN(markers);
2242    Widget_Data *wd = clas->wd;
2243    EINA_SAFETY_ON_NULL_RETURN(wd);
2244
2245    char buf[PATH_MAX];
2246    Eina_List *l;
2247    Elm_Map_Marker *marker;
2248    int cnt = 0;
2249    int sum_x = 0, sum_y = 0;
2250
2251    EINA_LIST_FOREACH(markers, l, marker)
2252      {
2253         sum_x += marker->x;
2254         sum_y += marker->y;
2255         cnt++;
2256      }
2257
2258    group->x = sum_x / cnt;
2259    group->y = sum_y / cnt;
2260    _edj_marker_size_get(wd, &group->w, &group->h);
2261    group->w *=2;
2262    group->h *=2;
2263    group->clas = clas;
2264    group->markers = markers;
2265
2266    if (clas->style) elm_layout_theme_set(group->obj, "map/marker", clas->style,
2267                                          elm_widget_style_get(wd->obj));
2268    else elm_layout_theme_set(group->obj, "map/marker", "radio",
2269                              elm_widget_style_get(wd->obj));
2270
2271
2272    if (clas->func.icon_get)
2273      {
2274         Evas_Object *icon = NULL;
2275
2276         icon = elm_object_part_content_get(group->obj, "elm.icon");
2277         if (icon) evas_object_del(icon);
2278
2279         icon = clas->func.icon_get(wd->obj, clas->data);
2280         elm_object_part_content_set(group->obj, "elm.icon", icon);
2281      }
2282    snprintf(buf, sizeof(buf), "%d", cnt);
2283    edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
2284
2285    if (group->bubble)
2286       {
2287          Eina_List *contents = NULL;
2288
2289          EINA_LIST_FOREACH(group->markers, l, marker)
2290            {
2291               Evas_Object *c = marker->clas->func.get(marker->wd->obj,
2292                                                       marker, marker->data);
2293               if (c) contents = eina_list_append(contents, c);
2294            }
2295          _bubble_update(group->bubble, contents);
2296       }
2297 }
2298
2299 static void
2300 _marker_group_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2301 {
2302    EINA_SAFETY_ON_NULL_RETURN(data);
2303    Marker_Group *group = data;
2304    Eina_List *l;
2305    Elm_Map_Marker *marker;
2306    Eina_List *contents = NULL;
2307
2308    if (!group->bubble) group->bubble = _bubble_create(group->obj, group->wd);
2309
2310    EINA_LIST_FOREACH(group->markers, l, marker)
2311      {
2312         if (group->wd->markers_max_num <= eina_list_count(contents)) break;
2313         Evas_Object *c = marker->clas->func.get(marker->wd->obj,
2314                                                 marker, marker->data);
2315         if (c) contents = eina_list_append(contents, c);
2316      }
2317    _bubble_update(group->bubble, contents);
2318    _bubble_place(group->bubble);
2319 }
2320
2321 static void
2322 _marker_group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2323 {
2324    EINA_SAFETY_ON_NULL_RETURN(data);
2325
2326    double lon, lat;
2327    Marker_Group *group = data;
2328    _coord_to_region_convert(group->wd, group->x, group->y, group->wd->size.w,
2329                          &lon, &lat);
2330    elm_map_region_bring_in(group->wd->obj, lon, lat);
2331 }
2332
2333 static void
2334 _marker_group_free(Marker_Group* group)
2335 {
2336    EINA_SAFETY_ON_NULL_RETURN(group);
2337
2338    if (group->bubble) _bubble_free(group->bubble);
2339
2340    eina_list_free(group->markers);
2341    evas_object_del(group->obj);
2342
2343    free(group);
2344 }
2345
2346 static Marker_Group*
2347 _marker_group_create(Widget_Data *wd)
2348 {
2349    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
2350
2351    Marker_Group *group = ELM_NEW(Marker_Group);
2352
2353    group->wd = wd;
2354    group->obj = elm_layout_add(wd->obj);
2355    evas_object_smart_member_add(group->obj, wd->pan_smart);
2356    evas_object_stack_above(group->obj, wd->sep_maps_markers);
2357    elm_layout_theme_set(group->obj, "map/marker", "radio",
2358                         elm_widget_style_get(wd->obj));
2359    edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
2360                                    "open", "elm", _marker_group_bubble_open_cb,
2361                                    group);
2362    edje_object_signal_callback_add(elm_layout_edje_get(group->obj),
2363                                    "bringin", "elm", _marker_group_bringin_cb,
2364                                    group);
2365    return group;
2366 }
2367
2368 static void
2369 _marker_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2370 {
2371    Elm_Map_Marker *marker = data;
2372    EINA_SAFETY_ON_NULL_RETURN(marker);
2373    elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
2374 }
2375
2376 static void
2377 _marker_bubble_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2378 {
2379    EINA_SAFETY_ON_NULL_RETURN(data);
2380    Elm_Map_Marker *marker = data;
2381
2382    if (!marker->bubble) marker->bubble = _bubble_create(marker->obj, marker->wd);
2383    evas_object_smart_changed(marker->wd->pan_smart);
2384 }
2385
2386 static void
2387 _marker_update(Elm_Map_Marker *marker)
2388 {
2389    EINA_SAFETY_ON_NULL_RETURN(marker);
2390    Elm_Map_Marker_Class *clas = marker->clas;
2391    EINA_SAFETY_ON_NULL_RETURN(clas);
2392
2393    if (clas->style) elm_layout_theme_set(marker->obj, "map/marker", clas->style,
2394                                          elm_widget_style_get(marker->wd->obj));
2395    else elm_layout_theme_set(marker->obj, "map/marker", "radio",
2396                              elm_widget_style_get(marker->wd->obj));
2397
2398    if (clas->func.icon_get)
2399      {
2400         Evas_Object *icon = NULL;
2401
2402         icon = elm_object_part_content_get(marker->obj, "elm.icon");
2403         if (icon) evas_object_del(icon);
2404
2405         icon = clas->func.icon_get(marker->wd->obj, marker, marker->data);
2406         elm_object_part_content_set(marker->obj, "elm.icon", icon);
2407      }
2408    _region_to_coord_convert(marker->wd, marker->longitude, marker->latitude,
2409                          marker->wd->size.w, &(marker->x), &(marker->y));
2410
2411     if (marker->bubble)
2412       {
2413          if (marker->content) evas_object_del(marker->content);
2414          if (marker->clas->func.get)
2415             marker->content = marker->clas->func.get(marker->wd->obj, marker,
2416                                                      marker->data);
2417         if (marker->content)
2418           {
2419              Eina_List *contents = NULL;
2420              contents = eina_list_append(contents, marker->content);
2421              _bubble_update(marker->bubble, contents);
2422           }
2423       }
2424 }
2425
2426
2427
2428 static void
2429 _marker_place(Widget_Data *wd)
2430 {
2431    EINA_SAFETY_ON_NULL_RETURN(wd);
2432
2433    Eina_List *l;
2434
2435    Elm_Map_Marker *marker;
2436    Elm_Map_Group_Class *group_clas;
2437
2438    Evas_Coord gw, gh;
2439    Evas_Coord px, py;
2440
2441    if (wd->paused_markers || (!eina_list_count(wd->markers))) return;
2442
2443    _pan_geometry_get(wd, &px, &py);
2444
2445    _edj_marker_size_get(wd, &gw, &gh);
2446    gw *= 2;
2447    gh *= 2;
2448
2449    EINA_LIST_FOREACH(wd->markers, l, marker)
2450      {
2451         _marker_update(marker);
2452         marker->grouped = EINA_FALSE;
2453         marker->leader = EINA_FALSE;
2454      }
2455
2456    EINA_LIST_FOREACH(wd->group_classes, l, group_clas)
2457      {
2458         Eina_List *ll;
2459         EINA_LIST_FOREACH(group_clas->markers, ll, marker)
2460           {
2461              Eina_List *lll;
2462              Elm_Map_Marker *mm;
2463              Eina_List *markers = NULL;
2464
2465              if (marker->grouped) continue;
2466              if (group_clas->zoom_grouped < wd->zoom)
2467                {
2468                   marker->grouped = EINA_FALSE;
2469                   continue;
2470                }
2471
2472              EINA_LIST_FOREACH(group_clas->markers, lll, mm)
2473                {
2474                   if (marker == mm || mm->grouped) continue;
2475                   if (ELM_RECTS_INTERSECT(mm->x, mm->y, mm->w, mm->h,
2476                                           marker->x, marker->y, gw, gh))
2477                     {
2478                        // mm is group follower.
2479                        mm->leader = EINA_FALSE;
2480                        mm->grouped = EINA_TRUE;
2481                        markers = eina_list_append(markers, mm);
2482                     }
2483                }
2484               if (eina_list_count(markers) >= 1)
2485                 {
2486                    // marker is group leader.
2487                    marker->leader = EINA_TRUE;
2488                    marker->grouped = EINA_TRUE;
2489                    markers = eina_list_append(markers, marker);
2490
2491                    if (!marker->group) marker->group = _marker_group_create(wd);
2492                    _marker_group_update(marker->group, group_clas, markers);
2493                 }
2494           }
2495      }
2496
2497    EINA_LIST_FOREACH(wd->markers, l, marker)
2498      {
2499
2500         if (marker->grouped ||
2501            (marker->group_clas &&
2502             (marker->group_clas->hide ||
2503              marker->group_clas->zoom_displayed > wd->zoom)))
2504            evas_object_hide(marker->obj);
2505         else
2506           {
2507              Evas_Coord x, y;
2508              _coord_rotate(marker->x + px, marker->y + py, wd->rotate.cx,
2509                            wd->rotate.cy, wd->rotate.d, &x, &y);
2510              _obj_place(marker->obj, x - (marker->w / 2), y - (marker->h / 2),
2511                          marker->w, marker->h);
2512           }
2513      }
2514
2515    EINA_LIST_FOREACH(wd->markers, l, marker)
2516      {
2517         Marker_Group *group = marker->group;
2518         if (!group) continue;
2519
2520         if (!marker->leader || (group->clas->hide) ||
2521             (group->clas->zoom_displayed > wd->zoom))
2522            evas_object_hide(group->obj);
2523         else
2524           {
2525              Evas_Coord x, y;
2526              _coord_rotate(group->x + px, group->y + py, wd->rotate.cx,
2527                            wd->rotate.cy, wd->rotate.d, &x, &y);
2528              _obj_place(group->obj, x - (group->w / 2), y - (group->h / 2),
2529                          group->w, group->h);
2530 >>>>>>> remotes/origin/upstream
2531           }
2532      }
2533 }
2534
2535 static void
2536 <<<<<<< HEAD
2537 _smooth_update(Evas_Object *obj)
2538 {
2539    ELM_CHECK_WIDTYPE(obj, widtype);
2540    Widget_Data *wd = elm_widget_data_get(obj);
2541    Eina_List *l;
2542    Grid *g;
2543
2544    if (!wd) return;
2545    EINA_LIST_FOREACH(wd->grids, l, g)
2546      {
2547         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
2548         Eina_Matrixsparse_Cell *cell;
2549
2550         EINA_ITERATOR_FOREACH(it, cell)
2551           {
2552              Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
2553              evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
2554           }
2555         eina_iterator_free(it);
2556      }
2557 }
2558
2559 static Eina_Bool
2560 _scr_timeout(void *data)
2561 {
2562    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2563    Widget_Data *wd = elm_widget_data_get(data);
2564
2565    if (!wd) return ECORE_CALLBACK_CANCEL;
2566    wd->nosmooth--;
2567    if (!wd->nosmooth) _smooth_update(data);
2568    wd->scr_timer = NULL;
2569    return ECORE_CALLBACK_CANCEL;
2570 }
2571
2572 static void
2573 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2574 {
2575    ELM_CHECK_WIDTYPE(data, widtype);
2576    Widget_Data *wd = elm_widget_data_get(data);
2577
2578    if (!wd) return;
2579    if (!wd->scr_timer)
2580      {
2581         wd->nosmooth++;
2582         if (wd->nosmooth == 1) _smooth_update(data);
2583      }
2584    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2585    wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
2586 }
2587
2588 static void
2589 zoom_do(Evas_Object *obj)
2590 {
2591    ELM_CHECK_WIDTYPE(obj, widtype);
2592    Widget_Data *wd = elm_widget_data_get(obj);
2593    Evas_Coord xx, yy, ow, oh;
2594
2595    if (!wd) return;
2596    wd->size.w = wd->size.nw;
2597    wd->size.h = wd->size.nh;
2598
2599    elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
2600
2601    if (wd->center_on.enabled)
2602      {
2603         elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
2604         xx -= ow / 2;
2605         yy -= oh / 2;
2606      }
2607    else
2608      {
2609         xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
2610         yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
2611      }
2612
2613
2614    if (xx < 0) xx = 0;
2615    else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
2616    if (yy < 0) yy = 0;
2617    else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
2618
2619    wd->show.show = EINA_TRUE;
2620    wd->show.x = xx;
2621    wd->show.y = yy;
2622    wd->show.w = ow;
2623    wd->show.h = oh;
2624
2625    if (wd->calc_job) ecore_job_del(wd->calc_job);
2626    wd->calc_job = ecore_job_add(_calc_job, wd);
2627 }
2628
2629 static Eina_Bool
2630 _zoom_timeout(void *data)
2631 {
2632    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2633    Widget_Data *wd = elm_widget_data_get(data);
2634
2635    if (!wd) return ECORE_CALLBACK_CANCEL;
2636    wd->zoom_timer = NULL;
2637    wd->pinch.level = 1.0;
2638    zoom_do(data);
2639    evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
2640    return ECORE_CALLBACK_CANCEL;
2641 }
2642
2643 static Eina_Bool
2644 _zoom_anim(void *data)
2645 {
2646    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2647    Evas_Object *obj = data;
2648    Widget_Data *wd = elm_widget_data_get(obj);
2649
2650    if (!wd) return ECORE_CALLBACK_CANCEL;
2651    if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
2652    else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
2653    else
2654      {
2655         wd->zoom_animator = NULL;
2656         zoom_do(obj);
2657         evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
2658         return ECORE_CALLBACK_CANCEL;
2659      }
2660
2661    if (wd->t >= 2.0)
2662      {
2663         wd->zoom_animator = NULL;
2664         wd->pinch.level = 2.0;
2665         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
2666         wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
2667         return ECORE_CALLBACK_CANCEL;
2668      }
2669    else if (wd->t <= 0.5)
2670      {
2671         wd->zoom_animator = NULL;
2672         wd->pinch.level = 0.5;
2673         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
2674         wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
2675         return ECORE_CALLBACK_CANCEL;
2676      }
2677    else if (wd->t != 1.0)
2678      {
2679         Evas_Coord x, y, w, h;
2680         float half_w, half_h;
2681         evas_object_geometry_get(data, &x, &y, &w, &h);
2682         half_w = (float)w * 0.5;
2683         half_h = (float)h * 0.5;
2684         wd->pinch.cx = x + half_w;
2685         wd->pinch.cy = y + half_h;
2686         wd->pinch.level = wd->t;
2687         if (wd->calc_job) ecore_job_del(wd->calc_job);
2688         wd->calc_job = ecore_job_add(_calc_job, wd);
2689 =======
2690 _grid_item_coord_get(Grid_Item *gi, int *x, int *y, int *w, int *h)
2691 {
2692    EINA_SAFETY_ON_NULL_RETURN(gi);
2693
2694    if (x) *x = gi->x * gi->wd->size.tile;
2695    if (y) *y = gi->y * gi->wd->size.tile;
2696    if (w) *w = gi->wd->size.tile;
2697    if (h) *h = gi->wd->size.tile;
2698 }
2699
2700 static Eina_Bool
2701 _grid_item_intersect(Grid_Item *gi)
2702 {
2703    EINA_SAFETY_ON_NULL_RETURN_VAL(gi, EINA_FALSE);
2704
2705    Evas_Coord px, py;
2706    Evas_Coord vw, vh;
2707    Evas_Coord x, y, w, h;
2708
2709    _pan_geometry_get(gi->wd, &px, &py);
2710    _viewport_size_get(gi->wd, &vw, &vh);
2711    _grid_item_coord_get(gi, &x, &y, &w, &h);
2712    return ELM_RECTS_INTERSECT(x + px, y + py, w, h, 0, 0, vw, vh);
2713 }
2714
2715 static void
2716 _grid_item_update(Grid_Item *gi)
2717 {
2718    evas_object_image_file_set(gi->img, gi->file, NULL);
2719    if (!gi->wd->zoom_timer && !gi->wd->scr_timer)
2720       evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
2721    else evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
2722
2723    Evas_Load_Error err = evas_object_image_load_error_get(gi->img);
2724    if (err != EVAS_LOAD_ERROR_NONE)
2725      {
2726         ERR("Image loading error (%s): %s", gi->file, evas_load_error_str(err));
2727         ecore_file_remove(gi->file);
2728         gi->file_have = EINA_FALSE;
2729      }
2730    else
2731      {
2732         Evas_Coord px, py;
2733         Evas_Coord x, y, w, h;
2734
2735         _pan_geometry_get(gi->wd, &px, &py);
2736         _grid_item_coord_get(gi, &x, &y, &w, &h);
2737
2738         _obj_place(gi->img, x + px, y + py, w, h);
2739         _obj_rotate(gi->wd, gi->img);
2740         gi->file_have = EINA_TRUE;
2741      }
2742 }
2743
2744 static void
2745 _grid_item_load(Grid_Item *gi)
2746 {
2747    EINA_SAFETY_ON_NULL_RETURN(gi);
2748    if (gi->file_have) _grid_item_update(gi);
2749    else if (!gi->job)
2750      {
2751         gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
2752         gi->wd->download_list = eina_list_append(gi->wd->download_list, gi);
2753      }
2754 }
2755
2756 static void
2757 _grid_item_unload(Grid_Item *gi)
2758 {
2759    EINA_SAFETY_ON_NULL_RETURN(gi);
2760    if (gi->file_have)
2761      {
2762         evas_object_hide(gi->img);
2763         evas_object_image_file_set(gi->img, NULL, NULL);
2764      }
2765    else if (gi->job)
2766      {
2767         ecore_file_download_abort(gi->job);
2768         ecore_file_remove(gi->file);
2769         gi->job = NULL;
2770         gi->wd->try_num--;
2771      }
2772    else gi->wd->download_list = eina_list_remove(gi->wd->download_list, gi);
2773
2774 }
2775
2776 static Grid_Item *
2777 _grid_item_create(Grid *g, Evas_Coord x, Evas_Coord y)
2778 {
2779    EINA_SAFETY_ON_NULL_RETURN_VAL(g, NULL);
2780    char buf[PATH_MAX];
2781    char buf2[PATH_MAX];
2782    char *url;
2783    Grid_Item *gi;
2784
2785    gi = ELM_NEW(Grid_Item);
2786    gi->wd = g->wd;
2787    gi->g = g;
2788    gi->x = x;
2789    gi->y = y;
2790
2791    gi->file_have = EINA_FALSE;
2792    gi->job = NULL;
2793
2794    gi->img = evas_object_image_add(evas_object_evas_get(g->wd->obj));
2795    evas_object_image_smooth_scale_set(gi->img, EINA_FALSE);
2796    evas_object_image_scale_hint_set(gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
2797    evas_object_image_filled_set(gi->img, 1);
2798    evas_object_smart_member_add(gi->img, g->wd->pan_smart);
2799    evas_object_pass_events_set(gi->img, EINA_TRUE);
2800    evas_object_stack_below(gi->img, g->wd->sep_maps_markers);
2801
2802    snprintf(buf, sizeof(buf), CACHE_TILE_ROOT, g->wd->id, g->zoom, x);
2803    snprintf(buf2, sizeof(buf2), CACHE_TILE_PATH, buf, y);
2804    if (!ecore_file_exists(buf)) ecore_file_mkpath(buf);
2805
2806    eina_stringshare_replace(&gi->file, buf2);
2807    url = g->wd->src_tile->url_cb(g->wd->obj, x, y, g->zoom);
2808    if ((!url) || (!strlen(url)))
2809      {
2810         eina_stringshare_replace(&gi->url, NULL);
2811         ERR("Getting source url failed: %s", gi->file);
2812      }
2813    else eina_stringshare_replace(&gi->url, url);
2814    if (url) free(url);
2815    eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
2816    return gi;
2817 }
2818
2819 static void
2820 _grid_item_free(Grid_Item *gi)
2821 {
2822    EINA_SAFETY_ON_NULL_RETURN(gi);
2823    _grid_item_unload(gi);
2824    if (gi->g && gi->g->grid) eina_matrixsparse_data_idx_set(gi->g->grid,
2825                                                             gi->y, gi->x, NULL);
2826    if (gi->url) eina_stringshare_del(gi->url);
2827    if (gi->file) eina_stringshare_del(gi->file);
2828    if (gi->img) evas_object_del(gi->img);
2829    if (gi->file_have) ecore_file_remove(gi->file);
2830    free(gi);
2831 }
2832
2833 static void
2834 _downloaded_cb(void *data, const char *file __UNUSED__, int status)
2835 {
2836    Grid_Item *gi = data;
2837
2838    if (status == 200)
2839      {
2840         DBG("Download success from %s to %s", gi->url, gi->file);
2841         _grid_item_update(gi);
2842         gi->wd->finish_num++;
2843         evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED, NULL);
2844      }
2845    else
2846      {
2847         WRN("Download failed from %s to %s (%d) ", gi->url, gi->file, status);
2848         ecore_file_remove(gi->file);
2849         gi->file_have = EINA_FALSE;
2850         evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOADED_FAIL, NULL);
2851      }
2852
2853    gi->job = NULL;
2854    gi->wd->download_num--;
2855    if (!gi->wd->download_num)
2856       edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr),
2857                               "elm,state,busy,stop", "elm");
2858 }
2859
2860 static Eina_Bool
2861 _download_job(void *data)
2862 {
2863    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
2864    Widget_Data *wd = data;
2865
2866    Eina_List *l, *ll;
2867    Grid_Item *gi;
2868
2869    if (!eina_list_count(wd->download_list))
2870      {
2871         wd->download_idler = NULL;
2872         return ECORE_CALLBACK_CANCEL;
2873      }
2874
2875    EINA_LIST_REVERSE_FOREACH_SAFE(wd->download_list, l, ll, gi)
2876      {
2877         if (gi->g->zoom != wd->zoom || !_grid_item_intersect(gi))
2878           {
2879              wd->download_list = eina_list_remove(wd->download_list, gi);
2880              continue;
2881           }
2882         if (wd->download_num >= MAX_CONCURRENT_DOWNLOAD)
2883            return ECORE_CALLBACK_RENEW;
2884
2885         Eina_Bool ret = ecore_file_download_full(gi->url, gi->file,
2886                                                  _downloaded_cb, NULL,
2887                                                  gi, &(gi->job), wd->ua);
2888         if ((!ret) || (!gi->job))
2889            ERR("Can't start to download from %s to %s", gi->url, gi->file);
2890         else
2891           {
2892              wd->download_list = eina_list_remove(wd->download_list, gi);
2893              wd->try_num++;
2894              wd->download_num++;
2895              evas_object_smart_callback_call(gi->wd->obj, SIG_TILE_LOAD,
2896                                              NULL);
2897              if (wd->download_num == 1)
2898                 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
2899                                         "elm,state,busy,start", "elm");
2900
2901           }
2902 >>>>>>> remotes/origin/upstream
2903      }
2904    return ECORE_CALLBACK_RENEW;
2905 }
2906
2907 <<<<<<< HEAD
2908 static Eina_Bool
2909 _long_press(void *data)
2910 {
2911    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2912    Widget_Data *wd = elm_widget_data_get(data);
2913
2914    if (!wd) return ECORE_CALLBACK_CANCEL;
2915    wd->long_timer = NULL;
2916    evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
2917    return ECORE_CALLBACK_CANCEL;
2918 }
2919
2920 static void
2921 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2922 {
2923    ELM_CHECK_WIDTYPE(data, widtype);
2924    Widget_Data *wd = elm_widget_data_get(data);
2925    Evas_Event_Mouse_Down *ev = event_info;
2926
2927    if (ev->button != 1) return;
2928    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
2929    else wd->on_hold = EINA_FALSE;
2930    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
2931      evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
2932    else
2933      evas_object_smart_callback_call(data, SIG_PRESS, ev);
2934    if (wd->long_timer) ecore_timer_del(wd->long_timer);
2935    wd->ev = *ev;
2936    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
2937 }
2938
2939 static void
2940 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2941 {
2942    ELM_CHECK_WIDTYPE(data, widtype);
2943    Widget_Data *wd = elm_widget_data_get(data);
2944    EINA_SAFETY_ON_NULL_RETURN(wd);
2945
2946    Evas_Event_Mouse_Up *ev = event_info;
2947    EINA_SAFETY_ON_NULL_RETURN(ev);
2948
2949    if (ev->button != 1) return;
2950    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
2951    else wd->on_hold = EINA_FALSE;
2952    if (wd->long_timer)
2953      {
2954         ecore_timer_del(wd->long_timer);
2955         wd->long_timer = NULL;
2956      }
2957    if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
2958    wd->on_hold = EINA_FALSE;
2959 }
2960
2961 static void
2962 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2963 {
2964    ELM_CHECK_WIDTYPE(data, widtype);
2965    Widget_Data *wd = elm_widget_data_get(data);
2966    EINA_SAFETY_ON_NULL_RETURN(wd);
2967
2968    if (!wd->paused)
2969      {
2970         int zoom_diff = 0;
2971         Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
2972         Evas_Coord x, y, w, h;
2973
2974         evas_object_geometry_get(data, &x, &y, &w, &h);
2975
2976         if (wd->calc_job) ecore_job_del(wd->calc_job);
2977         wd->calc_job = ecore_job_add(_calc_job, wd);
2978
2979         wd->wheel_diff -= ev->z;
2980         wd->pinch.level = wd->pinch.diff * pow(2.0, (double)wd->wheel_diff/10);
2981         wd->pinch.cx = x + ((double)w * 0.5);
2982         wd->pinch.cy = y + ((double)h * 0.5);
2983
2984         if (wd->pinch.level > 1.99 || wd->pinch.level < 1.01)
2985           {
2986              wd->wheel_diff = 0;
2987              if (wd->pinch.level > 1.99)
2988                {
2989                   zoom_diff = 1;
2990                   wd->pinch.diff = wd->pinch.level / 2.0;
2991                   wd->pinch.level = wd->pinch.level / 2.0;
2992                }
2993              else if (wd->pinch.level < 1.01)
2994                {
2995                   zoom_diff = -1;
2996                   wd->pinch.diff = wd->pinch.level * 2.0;
2997                   wd->pinch.level = wd->pinch.level * 2.0;
2998                }
2999
3000              Elm_Map_Zoom_Mode temp;
3001              temp = wd->mode;
3002              wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3003              wd->paused = EINA_TRUE;
3004              elm_map_zoom_set(data, wd->zoom + zoom_diff);
3005              wd->paused = EINA_FALSE;
3006              wd->mode = temp;
3007           }
3008         else
3009           {
3010              if (wd->calc_job) ecore_job_del(wd->calc_job);
3011              wd->calc_job = ecore_job_add(_calc_job, wd);
3012 =======
3013 static void
3014 _grid_viewport_get(Grid *g, int *x, int *y, int *w, int *h)
3015 {
3016    EINA_SAFETY_ON_NULL_RETURN(g);
3017    int xx, yy, ww, hh;
3018    Evas_Coord px, py, vw, vh;
3019
3020    _pan_geometry_get(g->wd, &px, &py);
3021    _viewport_size_get(g->wd, &vw, &vh);
3022    if (px > 0) px = 0;
3023    if (py > 0) py = 0;
3024
3025    xx = (-px / g->wd->size.tile) - 1;
3026    if (xx < 0) xx = 0;
3027
3028    yy = (-py / g->wd->size.tile) - 1;
3029    if (yy < 0) yy = 0;
3030
3031    ww = (vw / g->wd->size.tile) + 3;
3032    if (xx + ww >= g->tw) ww = g->tw - xx;
3033
3034    hh = (vh / g->wd->size.tile) + 3;
3035    if (yy + hh >= g->th) hh = g->th - yy;
3036
3037    if (x) *x = xx;
3038    if (y) *y = yy;
3039    if (w) *w = ww;
3040    if (h) *h = hh;
3041 }
3042
3043 static void
3044 _grid_unload(Grid *g)
3045 {
3046    EINA_SAFETY_ON_NULL_RETURN(g);
3047    Eina_Iterator *it;
3048    Eina_Matrixsparse_Cell *cell;
3049    Grid_Item *gi;
3050
3051    it = eina_matrixsparse_iterator_new(g->grid);
3052    EINA_ITERATOR_FOREACH(it, cell)
3053      {
3054         gi = eina_matrixsparse_cell_data_get(cell);
3055         _grid_item_unload(gi);
3056      }
3057    eina_iterator_free(it);
3058 }
3059
3060 static void
3061 _grid_load(Grid *g)
3062 {
3063    EINA_SAFETY_ON_NULL_RETURN(g);
3064    int x, y, xx, yy, ww, hh;
3065    Eina_Iterator *it;
3066    Eina_Matrixsparse_Cell *cell;
3067    Grid_Item *gi;
3068
3069    it = eina_matrixsparse_iterator_new(g->grid);
3070    EINA_ITERATOR_FOREACH(it, cell)
3071      {
3072         gi = eina_matrixsparse_cell_data_get(cell);
3073         if (!_grid_item_intersect(gi)) _grid_item_unload(gi);
3074      }
3075    eina_iterator_free(it);
3076
3077    _grid_viewport_get(g, &xx, &yy, &ww, &hh);
3078    for (y = yy; y < yy + hh; y++)
3079      {
3080         for (x = xx; x < xx + ww; x++)
3081           {
3082              gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
3083              if (!gi) gi = _grid_item_create(g, x, y);
3084              _grid_item_load(gi);
3085 >>>>>>> remotes/origin/upstream
3086           }
3087      }
3088 }
3089
3090 static void
3091 <<<<<<< HEAD
3092 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3093 {
3094    ELM_CHECK_WIDTYPE(data, widtype);
3095    Widget_Data *wd = elm_widget_data_get(data);
3096    int x, y, w, h;
3097
3098    evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
3099    evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
3100    evas_object_resize(wd->rect, w, h);
3101    evas_object_move(wd->rect, x, y);
3102 }
3103
3104 static void
3105 _del_hook(Evas_Object *obj)
3106 {
3107    ELM_CHECK_WIDTYPE(obj, widtype);
3108    Widget_Data *wd = elm_widget_data_get(obj);
3109    Elm_Map_Group_Class *group_clas;
3110    Elm_Map_Marker_Class *marker_clas;
3111    Eina_List *l;
3112    Evas_Object *p;
3113    Path_Node *n;
3114    Path_Waypoint *w;
3115    Ecore_Event_Handler *h;
3116    Elm_Map_Route *r;
3117    Elm_Map_Name *na;
3118    Evas_Object *route;
3119
3120    if (!wd) return;
3121    EINA_LIST_FREE(wd->groups_clas, group_clas)
3122      {
3123         if (group_clas->style)
3124           eina_stringshare_del(group_clas->style);
3125         free(group_clas);
3126      }
3127
3128    EINA_LIST_FREE(wd->markers_clas, marker_clas)
3129      {
3130         if (marker_clas->style)
3131           eina_stringshare_del(marker_clas->style);
3132         free(marker_clas);
3133      }
3134
3135    EINA_LIST_FOREACH(wd->route, l, r)
3136      {
3137         EINA_LIST_FREE(r->path, p)
3138           {
3139              evas_object_del(p);
3140           }
3141
3142         EINA_LIST_FREE(r->waypoint, w)
3143           {
3144              if (w->point) eina_stringshare_del(w->point);
3145              free(w);
3146           }
3147
3148         EINA_LIST_FREE(r->nodes, n)
3149           {
3150              if (n->pos.address) eina_stringshare_del(n->pos.address);
3151              free(n);
3152           }
3153
3154         EINA_LIST_FREE(r->handlers, h)
3155           {
3156              ecore_event_handler_del(h);
3157           }
3158
3159         if (r->con_url) ecore_con_url_free(r->con_url);
3160         if (r->info.nodes) eina_stringshare_del(r->info.nodes);
3161         if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
3162      }
3163
3164    EINA_LIST_FREE(wd->names, na)
3165      {
3166         if (na->address) free(na->address);
3167         if (na->handler) ecore_event_handler_del(na->handler);
3168         if (na->ud.fname)
3169           {
3170              ecore_file_remove(na->ud.fname);
3171              free(na->ud.fname);
3172              na->ud.fname = NULL;
3173           }
3174      }
3175
3176    EINA_LIST_FREE(wd->track, route)
3177      {
3178         evas_object_del(route);
3179      }
3180
3181    if (wd->map) evas_map_free(wd->map);
3182    if (wd->source_names) free(wd->source_names);
3183    if (wd->calc_job) ecore_job_del(wd->calc_job);
3184    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
3185    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3186    if (wd->long_timer) ecore_timer_del(wd->long_timer);
3187    if (wd->user_agent) eina_stringshare_del(wd->user_agent);
3188    if (wd->ua) eina_hash_free(wd->ua);
3189    if (wd->markers) free(wd->markers);
3190
3191    free(wd);
3192 }
3193
3194 static void
3195 _del_pre_hook(Evas_Object *obj)
3196 {
3197    ELM_CHECK_WIDTYPE(obj, widtype);
3198    Widget_Data *wd = elm_widget_data_get(obj);
3199    Marker_Group *group;
3200    Elm_Map_Marker *marker;
3201    int i;
3202    Eina_Bool free_marker = EINA_TRUE;
3203    Eina_List *l;
3204
3205    if (!wd) return;
3206    grid_clear_all(obj);
3207    for (i = 0; i <= wd->zoom_max; i++)
3208      {
3209         if (!wd->markers[i]) continue;
3210         Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
3211 =======
3212 _grid_place(Widget_Data *wd)
3213 {
3214    EINA_SAFETY_ON_NULL_RETURN(wd);
3215    Eina_List *l;
3216    Grid *g;
3217
3218    EINA_LIST_FOREACH(wd->grids, l, g)
3219      {
3220         if (wd->zoom == g->zoom) _grid_load(g);
3221         else _grid_unload(g);
3222      }
3223   if (!wd->download_idler) wd->download_idler = ecore_idler_add(_download_job, wd);
3224 }
3225
3226 static void
3227 _grid_all_create(Widget_Data *wd)
3228 {
3229    EINA_SAFETY_ON_NULL_RETURN(wd);
3230    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
3231
3232    int zoom;
3233    for (zoom = wd->src_tile->zoom_min; zoom <= wd->src_tile->zoom_max; zoom++)
3234      {
3235         Grid *g;
3236         int tnum;
3237         g = ELM_NEW(Grid);
3238         g->wd = wd;
3239         g->zoom = zoom;
3240         tnum =  pow(2.0, g->zoom);
3241         g->tw = tnum;
3242         g->th = tnum;
3243         g->grid = eina_matrixsparse_new(g->th, g->tw, NULL, NULL);
3244         wd->grids = eina_list_append(wd->grids, g);
3245      }
3246 }
3247
3248 static void
3249 _grid_all_clear(Widget_Data *wd)
3250 {
3251    EINA_SAFETY_ON_NULL_RETURN(wd);
3252
3253    Grid *g;
3254    EINA_LIST_FREE(wd->grids, g)
3255      {
3256         Eina_Matrixsparse_Cell *cell;
3257         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
3258         EINA_ITERATOR_FOREACH(it, cell)
3259           {
3260              Grid_Item *gi;
3261              gi = eina_matrixsparse_cell_data_get(cell);
3262              if (gi) _grid_item_free(gi);
3263           }
3264         eina_iterator_free(it);
3265
3266         eina_matrixsparse_free(g->grid);
3267         free(g);
3268      }
3269 }
3270
3271 static void
3272 _track_place(Widget_Data *wd)
3273 {
3274 #ifdef ELM_EMAP
3275    EINA_SAFETY_ON_NULL_RETURN(wd);
3276
3277    Eina_List *l;
3278    Evas_Object *route;
3279    int xmin, xmax, ymin, ymax;
3280    Evas_Coord px, py, ow, oh;
3281    px = wd->pan_x;
3282    py = wd->pan_y;
3283    _viewport_size_get(wd, &ow, &oh);
3284
3285    Evas_Coord size = wd->size.w;
3286
3287    EINA_LIST_FOREACH(wd->track, l, route)
3288      {
3289         double lon_min, lon_max;
3290         double lat_min, lat_max;
3291         elm_route_longitude_min_max_get(route, &lon_min, &lon_max);
3292         elm_route_latitude_min_max_get(route, &lat_min, &lat_max);
3293         _region_to_coord_convert(wd, lon_min, lat_max, size, &xmin, &ymin);
3294         _region_to_coord_convert(wd, lon_max, lat_min, size, &xmax, &ymax);
3295
3296         if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
3297         {
3298            if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
3299            {
3300               //display the route
3301               evas_object_move(route, xmin - px, ymin - py);
3302               evas_object_resize(route, xmax - xmin, ymax - ymin);
3303
3304               evas_object_raise(route);
3305               _obj_rotate(wd, route);
3306               evas_object_show(route);
3307
3308               continue;
3309            }
3310         }
3311         //the route is not display
3312         evas_object_hide(route);
3313      }
3314 #else
3315    (void) wd;
3316 #endif
3317 }
3318
3319 static void
3320 _delayed_do(Widget_Data *wd)
3321 {
3322    Delayed_Data *dd;
3323    dd = eina_list_nth(wd->delayed_jobs, 0);
3324    if (dd && !dd->wd->zoom_animator)
3325      {
3326         dd->func(dd);
3327         wd->delayed_jobs = eina_list_remove(wd->delayed_jobs, dd);
3328         free(dd);
3329      }
3330 }
3331
3332 static void
3333 _smooth_update(Widget_Data *wd)
3334 {
3335    EINA_SAFETY_ON_NULL_RETURN(wd);
3336    Eina_List *l;
3337    Grid *g;
3338
3339    EINA_LIST_FOREACH(wd->grids, l, g)
3340      {
3341         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
3342 >>>>>>> remotes/origin/upstream
3343         Eina_Matrixsparse_Cell *cell;
3344
3345         EINA_ITERATOR_FOREACH(it, cell)
3346           {
3347 <<<<<<< HEAD
3348              l =  eina_matrixsparse_cell_data_get(cell);
3349              EINA_LIST_FREE(l, group)
3350                {
3351                   EINA_LIST_FREE(group->markers, marker)
3352                     {
3353                        evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3354                                                            _bubble_sc_hints_changed_cb, group);
3355                        if (free_marker) free(marker);
3356                     }
3357                   free(group);
3358                }
3359              free_marker = EINA_FALSE;
3360           }
3361         eina_iterator_free(it);
3362         eina_matrixsparse_free(wd->markers[i]);
3363      }
3364
3365    evas_object_del(wd->sep_maps_markers);
3366    evas_object_del(wd->pan_smart);
3367    wd->pan_smart = NULL;
3368 }
3369
3370 static void
3371 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
3372 {
3373    ELM_CHECK_WIDTYPE(obj, widtype);
3374    Widget_Data *wd = elm_widget_data_get(obj);
3375
3376    if (!wd) return;
3377    if (elm_widget_focus_get(obj))
3378      {
3379         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
3380         evas_object_focus_set(wd->obj, EINA_TRUE);
3381      }
3382    else
3383      {
3384         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
3385         evas_object_focus_set(wd->obj, EINA_FALSE);
3386 =======
3387              Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
3388              if (_grid_item_intersect(gi))
3389                 evas_object_image_smooth_scale_set(gi->img, EINA_TRUE);
3390           }
3391         eina_iterator_free(it);
3392      }
3393 }
3394
3395 static Eina_Bool
3396 _zoom_timeout(void *data)
3397 {
3398    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
3399    Widget_Data *wd = data;
3400    _smooth_update(wd);
3401    wd->zoom_timer = NULL;
3402    evas_object_smart_callback_call(wd->obj, SIG_ZOOM_STOP, NULL);
3403   return ECORE_CALLBACK_CANCEL;
3404 }
3405
3406 static void
3407 zoom_do(Widget_Data *wd, double zoom)
3408 {
3409    EINA_SAFETY_ON_NULL_RETURN(wd);
3410    if (zoom > wd->zoom_max) zoom = wd->zoom_max;
3411    else if (zoom < wd->zoom_min) zoom = wd->zoom_min;
3412
3413    Evas_Coord px, py, vw, vh;
3414    Evas_Coord ow, oh;
3415
3416    wd->zoom = ROUND(zoom);
3417    wd->zoom_detail = zoom;
3418    ow = wd->size.w;
3419    oh = wd->size.h;
3420    wd->size.tile = pow(2.0, (zoom - wd->zoom)) * wd->tsize;
3421    wd->size.w = pow(2.0, wd->zoom) * wd->size.tile;
3422    wd->size.h = wd->size.w;;
3423
3424    // Fix to zooming with (viewport center px, py) as the center to prevent
3425    // from zooming with (0,0) as the cetner. (scroller default behavior)
3426    _pan_geometry_get(wd, &px, &py);
3427    _viewport_size_get(wd, &vw, &vh);
3428    if ((vw > 0) && (vh > 0) && (ow > 0) && (oh > 0))
3429      {
3430         Evas_Coord xx, yy;
3431         double sx, sy;
3432         if (vw > ow) sx = 0.5;
3433         else         sx = (double)(-px + (vw / 2)) / ow;
3434         if (vh > oh) sy = 0.5;
3435         else         sy = (double)(-py + (vh / 2)) / oh;
3436
3437         if (sx > 1.0) sx = 1.0;
3438         if (sy > 1.0) sy = 1.0;
3439
3440         xx = (sx * wd->size.w) - (vw / 2);
3441         yy = (sy * wd->size.h) - (vh / 2);
3442         if (xx < 0) xx = 0;
3443         else if (xx > (wd->size.w - vw)) xx = wd->size.w - vw;
3444         if (yy < 0) yy = 0;
3445         else if (yy > (wd->size.h - vh)) yy = wd->size.h - vh;
3446         elm_smart_scroller_child_region_show(wd->scr, xx, yy, vw, vh);
3447      }
3448    if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
3449    else evas_object_smart_callback_call(wd->obj, SIG_ZOOM_START, NULL);
3450    wd->zoom_timer = ecore_timer_add(0.25, _zoom_timeout, wd);
3451    evas_object_smart_callback_call(wd->obj, SIG_ZOOM_CHANGE, NULL);
3452
3453    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3454    evas_object_smart_changed(wd->pan_smart);
3455 }
3456
3457 static Eina_Bool
3458 _zoom_anim(void *data)
3459 {
3460    Widget_Data *wd = data;
3461    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ECORE_CALLBACK_CANCEL);
3462
3463    if (wd->ani.cnt <= 0)
3464      {
3465         wd->zoom_animator = NULL;
3466         evas_object_smart_changed(wd->pan_smart);
3467         return ECORE_CALLBACK_CANCEL;
3468      }
3469    else
3470      {
3471         wd->ani.zoom += wd->ani.diff;
3472         wd->ani.cnt--;
3473         zoom_do(wd, wd->ani.zoom);
3474         return ECORE_CALLBACK_RENEW;
3475 >>>>>>> remotes/origin/upstream
3476      }
3477 }
3478
3479 static void
3480 <<<<<<< HEAD
3481 _theme_hook(Evas_Object *obj)
3482 {
3483    ELM_CHECK_WIDTYPE(obj, widtype);
3484    Widget_Data *wd = elm_widget_data_get(obj);
3485
3486    if (!wd) return;
3487    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
3488    //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
3489    _sizing_eval(obj);
3490 }
3491
3492 static void
3493 _sizing_eval(Evas_Object *obj)
3494 {
3495    ELM_CHECK_WIDTYPE(obj, widtype);
3496    Widget_Data *wd = elm_widget_data_get(obj);
3497    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
3498
3499    if (!wd) return;
3500    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
3501    evas_object_size_hint_min_set(obj, minw, minh);
3502    evas_object_size_hint_max_set(obj, maxw, maxh);
3503 }
3504
3505 static void
3506 _calc_job(void *data)
3507 {
3508    Widget_Data *wd = data;
3509    Evas_Coord minw, minh;
3510
3511    if (!wd) return;
3512    minw = wd->size.w;
3513    minh = wd->size.h;
3514    if (wd->resized)
3515      {
3516         wd->resized = EINA_FALSE;
3517         if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3518           {
3519              double tz = wd->zoom;
3520              wd->zoom = 0.0;
3521              elm_map_zoom_set(wd->obj, tz);
3522           }
3523      }
3524    if ((minw != wd->minw) || (minh != wd->minh))
3525      {
3526         wd->minw = minw;
3527         wd->minh = minh;
3528         evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
3529         _sizing_eval(wd->obj);
3530      }
3531    wd->calc_job = NULL;
3532    evas_object_smart_changed(wd->pan_smart);
3533 }
3534
3535 static void
3536 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
3537 {
3538    Pan *sd = evas_object_smart_data_get(obj);
3539    if (!sd) return;
3540    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
3541    sd->wd->pan_x = x;
3542    sd->wd->pan_y = y;
3543    evas_object_smart_changed(obj);
3544 }
3545
3546 static void
3547 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
3548 {
3549    Pan *sd = evas_object_smart_data_get(obj);
3550    if (!sd) return;
3551    if (x) *x = sd->wd->pan_x;
3552    if (y) *y = sd->wd->pan_y;
3553 }
3554
3555 static void
3556 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
3557 {
3558    Pan *sd = evas_object_smart_data_get(obj);
3559    Evas_Coord ow, oh;
3560    if (!sd) return;
3561    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
3562    ow = sd->wd->minw - ow;
3563    if (ow < 0) ow = 0;
3564    oh = sd->wd->minh - oh;
3565    if (oh < 0) oh = 0;
3566    if (x) *x = ow;
3567    if (y) *y = oh;
3568 }
3569
3570 static void
3571 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
3572 {
3573    if (x) *x = 0;
3574    if (y) *y = 0;
3575 }
3576
3577 static void
3578 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
3579 {
3580    Pan *sd = evas_object_smart_data_get(obj);
3581    if (!sd) return;
3582    if (w) *w = sd->wd->minw;
3583    if (h) *h = sd->wd->minh;
3584 }
3585
3586 static void
3587 _pan_add(Evas_Object *obj)
3588 {
3589    Pan *sd;
3590    Evas_Object_Smart_Clipped_Data *cd;
3591    _pan_sc.add(obj);
3592    cd = evas_object_smart_data_get(obj);
3593    if (!cd) return;
3594    sd = calloc(1, sizeof(Pan));
3595    if (!sd) return;
3596    sd->__clipped_data = *cd;
3597    free(cd);
3598    evas_object_smart_data_set(obj, sd);
3599 }
3600
3601 static void
3602 _pan_del(Evas_Object *obj)
3603 {
3604    Pan *sd = evas_object_smart_data_get(obj);
3605    if (!sd) return;
3606    _pan_sc.del(obj);
3607 }
3608
3609 static void
3610 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
3611 {
3612    Pan *sd = evas_object_smart_data_get(obj);
3613    Evas_Coord ow, oh;
3614    if (!sd) return;
3615    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
3616    if ((ow == w) && (oh == h)) return;
3617    sd->wd->resized = EINA_TRUE;
3618    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
3619    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
3620 }
3621
3622 static void
3623 _pan_calculate(Evas_Object *obj)
3624 {
3625    Pan *sd = evas_object_smart_data_get(obj);
3626    Evas_Coord ox, oy, ow, oh;
3627    Eina_List *l;
3628    Grid *g;
3629
3630    EINA_SAFETY_ON_NULL_RETURN(sd);
3631    EINA_SAFETY_ON_NULL_RETURN(sd->wd);
3632
3633    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3634    rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
3635    EINA_LIST_FOREACH(sd->wd->grids, l, g)
3636      {
3637         if (sd->wd->zoom == g->zoom) grid_load(sd->wd->obj, g);
3638         else if (sd->wd->zoom-1 != g->zoom && sd->wd->zoom+1 != g->zoom) grid_unload(sd->wd->obj, g); // remain only adjacent grids
3639         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
3640         if (sd->wd->zoom == g->zoom) marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
3641         if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
3642         if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
3643      }
3644 }
3645
3646 static void
3647 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
3648 {
3649    Pan *sd = evas_object_smart_data_get(obj);
3650    if (!sd) return;
3651    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
3652    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
3653 }
3654
3655 static void
3656 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
3657 {
3658    ELM_CHECK_WIDTYPE(obj, widtype);
3659    Widget_Data *wd = elm_widget_data_get(obj);
3660
3661    if (!wd) return;
3662    elm_smart_scroller_hold_set(wd->scr, 1);
3663 }
3664
3665 static void
3666 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
3667 {
3668    ELM_CHECK_WIDTYPE(obj, widtype);
3669    Widget_Data *wd = elm_widget_data_get(obj);
3670
3671    if (!wd) return;
3672    elm_smart_scroller_hold_set(wd->scr, 0);
3673 }
3674
3675 static void
3676 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
3677 {
3678    ELM_CHECK_WIDTYPE(obj, widtype);
3679    Widget_Data *wd = elm_widget_data_get(obj);
3680
3681    if (!wd) return;
3682    elm_smart_scroller_freeze_set(wd->scr, 1);
3683 }
3684
3685 static void
3686 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
3687 {
3688    ELM_CHECK_WIDTYPE(obj, widtype);
3689    Widget_Data *wd = elm_widget_data_get(obj);
3690
3691    if (!wd) return;
3692    elm_smart_scroller_freeze_set(wd->scr, 0);
3693 }
3694
3695 static void
3696 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3697 {
3698    evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
3699 }
3700
3701 static void
3702 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3703 {
3704    evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
3705 }
3706
3707 static void
3708 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3709 {
3710    Widget_Data *wd = elm_widget_data_get(data);
3711    EINA_SAFETY_ON_NULL_RETURN(wd);
3712    wd->center_on.enabled = EINA_FALSE;
3713
3714    // FIXME: els_scoller sometimes give start event again & again... it confuses app. (els_scr bug?)
3715    if (!wd->scr_started)
3716      {
3717         wd->scr_started = EINA_TRUE;
3718         evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
3719      }
3720 }
3721
3722 static void
3723 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3724 {
3725    Widget_Data *wd = elm_widget_data_get(data);
3726    EINA_SAFETY_ON_NULL_RETURN(wd);
3727    wd->center_on.enabled = EINA_FALSE;
3728
3729    // FIXME: els_scoller sometimes give start event again & again... it confuses app. (els_scr bug?)
3730    if (wd->scr_started)
3731      {
3732         wd->scr_started = EINA_FALSE;
3733         evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
3734      }
3735 }
3736
3737 static void
3738 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3739 {
3740    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
3741 }
3742
3743
3744 static void
3745 _group_object_create(Marker_Group *group)
3746 {
3747    const char *style = "radio";
3748    Evas_Object *icon = NULL;
3749
3750    if (group->obj) return;
3751    if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
3752      {
3753         //set icon and style
3754         if (eina_list_count(group->markers) == 1)
3755           {
3756              Elm_Map_Marker *m = eina_list_data_get(group->markers);
3757              if (m->clas->style)
3758                style = m->clas->style;
3759
3760              if (m->clas->func.icon_get)
3761                icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
3762
3763              group->delete_object = EINA_TRUE;
3764           }
3765         else
3766           {
3767              if (group->clas->style)
3768                style = group->clas->style;
3769
3770              if (group->clas->func.icon_get)
3771                icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
3772
3773              group->delete_object = EINA_FALSE;
3774           }
3775
3776         group->obj = elm_layout_add(group->wd->obj);
3777         elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
3778
3779         if (icon) elm_object_part_content_set(group->obj, "elm.icon", icon);
3780
3781         evas_object_smart_member_add(group->obj, group->wd->pan_smart);
3782         elm_widget_sub_object_add(group->wd->obj, group->obj);
3783         evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
3784
3785         if (!group->delete_object)
3786           group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
3787      }
3788    else
3789      {
3790         group->delete_object = EINA_FALSE;
3791
3792         group->obj = eina_list_data_get(group->clas->priv.objs_notused);
3793         group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
3794         group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
3795         evas_object_show(group->obj);
3796      }
3797
3798    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
3799    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
3800
3801    group->update_nbelems = EINA_TRUE;
3802    group->update_resize = EINA_TRUE;
3803    group->update_raise = EINA_TRUE;
3804
3805    if (group->open) _group_bubble_create(group);
3806 }
3807
3808 static void
3809 _group_object_free(Marker_Group *group)
3810 {
3811    if (!group->obj) return;
3812    if (!group->delete_object)
3813      {
3814         group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
3815         group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
3816         evas_object_hide(group->obj);
3817
3818         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
3819         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
3820      }
3821    else
3822      evas_object_del(group->obj);
3823
3824    group->obj = NULL;
3825    _group_bubble_free(group);
3826 }
3827
3828 static void
3829 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3830 {
3831    Marker_Group *group = data;
3832
3833    if (!evas_object_above_get(group->rect)) return;
3834    evas_object_raise(group->bubble);
3835    evas_object_raise(group->sc);
3836    evas_object_raise(group->rect);
3837 }
3838
3839 static void
3840 _group_bubble_create(Marker_Group *group)
3841 {
3842    if (group->bubble) return;
3843
3844    group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
3845    group->bubble = edje_object_add(evas_object_evas_get(group->obj));
3846    _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
3847                          elm_widget_style_get(group->wd->obj));
3848    evas_object_smart_member_add(group->bubble,
3849                                 group->wd->obj);
3850    elm_widget_sub_object_add(group->wd->obj, group->bubble);
3851
3852    _group_bubble_content_free(group);
3853    if (!_group_bubble_content_update(group))
3854      {
3855         //no content, we can delete the bubble
3856         _group_bubble_free(group);
3857         return;
3858      }
3859
3860    group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
3861    evas_object_color_set(group->rect, 0, 0, 0, 0);
3862    evas_object_repeat_events_set(group->rect, EINA_TRUE);
3863    evas_object_smart_member_add(group->rect, group->wd->obj);
3864    elm_widget_sub_object_add(group->wd->obj, group->rect);
3865
3866    evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
3867
3868    _group_bubble_place(group);
3869 }
3870
3871 static void _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
3872 {
3873    _group_bubble_place(data);
3874 }
3875
3876 static int
3877 _group_bubble_content_update(Marker_Group *group)
3878 {
3879    Eina_List *l;
3880    Elm_Map_Marker *marker;
3881    int i = 0;
3882
3883    if (!group->bubble) return 1;
3884
3885    if (!group->sc)
3886      {
3887         group->sc = elm_scroller_add(group->bubble);
3888         elm_widget_style_set(group->sc, "map_bubble");
3889         elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
3890         elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
3891         elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
3892         edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
3893         evas_object_show(group->sc);
3894         evas_object_smart_member_add(group->sc,
3895                                      group->wd->obj);
3896         elm_widget_sub_object_add(group->wd->obj, group->sc);
3897
3898         group->bx = elm_box_add(group->bubble);
3899         evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
3900         evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
3901         elm_box_horizontal_set(group->bx, EINA_TRUE);
3902         evas_object_show(group->bx);
3903
3904         elm_object_content_set(group->sc, group->bx);
3905
3906         evas_object_event_callback_add(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3907                                        _bubble_sc_hints_changed_cb, group);
3908      }
3909
3910    EINA_LIST_FOREACH(group->markers, l, marker)
3911      {
3912         if (i >= group->wd->markers_max_num) break;
3913         if ((!marker->content) && (marker->clas->func.get))
3914           marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
3915         else if (marker->content)
3916           elm_box_unpack(group->bx, marker->content);
3917         if (marker->content)
3918           {
3919              elm_box_pack_end(group->bx, marker->content);
3920              i++;
3921           }
3922      }
3923    return i;
3924 }
3925
3926 static void
3927 _group_bubble_content_free(Marker_Group *group)
3928 {
3929    Eina_List *l;
3930    Elm_Map_Marker *marker;
3931
3932    if (!group->sc) return;
3933    EINA_LIST_FOREACH(group->markers, l, marker)
3934      {
3935         if ((marker->content) && (marker->clas->func.del))
3936           marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
3937         else if (marker->content)
3938           evas_object_del(marker->content);
3939         marker->content = NULL;
3940      }
3941    evas_object_del(group->sc);
3942    group->sc = NULL;
3943 }
3944
3945 static void
3946 _group_bubble_free(Marker_Group *group)
3947 {
3948    if (!group->bubble) return;
3949    group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
3950    evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3951                                        _bubble_sc_hints_changed_cb, group);
3952    evas_object_del(group->bubble);
3953    evas_object_del(group->rect);
3954    group->bubble = NULL;
3955    _group_bubble_content_free(group);
3956 }
3957
3958 static void
3959 _group_bubble_place(Marker_Group *group)
3960 {
3961    Evas_Coord x, y, w;
3962    Evas_Coord xx, yy, ww, hh;
3963    const char *s;
3964
3965    if ((!group->bubble) || (!group->obj)) return;
3966
3967    evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
3968    edje_object_size_min_calc(group->bubble, NULL, &hh);
3969
3970    s = edje_object_data_get(group->bubble, "size_w");
3971    if (s) ww = atoi(s);
3972    else ww = 0;
3973    xx = x + w / 2 - ww / 2;
3974    yy = y-hh;
3975
3976    evas_object_move(group->bubble, xx, yy);
3977    evas_object_resize(group->bubble, ww, hh);
3978    obj_rotate_zoom(group->wd->obj, group->bubble);
3979    evas_object_show(group->bubble);
3980
3981    evas_object_move(group->rect, xx, yy);
3982    evas_object_resize(group->rect, ww, hh);
3983    obj_rotate_zoom(group->wd->obj, group->rect);
3984    evas_object_show(group->rect);
3985 }
3986
3987 static void
3988 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
3989 {
3990    Marker_Group *group = data;
3991    Elm_Map_Marker *marker = eina_list_data_get(group->markers);
3992    if (!marker) return;
3993    group->bringin = EINA_TRUE;
3994    elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
3995 }
3996
3997 static void
3998 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
3999 {
4000    Marker_Group *group = data;
4001
4002    if (group->bringin)
4003      {
4004         group->bringin = EINA_FALSE;
4005         return;
4006      }
4007
4008    if (group->bubble)
4009      {
4010         group->open = EINA_FALSE;
4011         _group_bubble_free(group);
4012         return;
4013      }
4014    group->open = EINA_TRUE;
4015    _group_bubble_create(group);
4016 }
4017
4018 static Eina_Bool
4019 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
4020 {
4021    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4022    Widget_Data *wd = elm_widget_data_get(obj);
4023    int zoom;
4024    Evas_Coord x = 0;
4025    Evas_Coord y = 0;
4026    Evas_Coord step_x = 0;
4027    Evas_Coord step_y = 0;
4028    Evas_Coord v_w = 0;
4029    Evas_Coord v_h = 0;
4030    Evas_Coord page_x = 0;
4031    Evas_Coord page_y = 0;
4032
4033    if (!wd) return EINA_FALSE;
4034    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
4035    Evas_Event_Key_Down *ev = event_info;
4036    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
4037
4038    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
4039    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
4040    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
4041    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
4042
4043    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
4044      {
4045         x -= step_x;
4046      }
4047    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
4048      {
4049         x += step_x;
4050      }
4051    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
4052      {
4053         y -= step_y;
4054      }
4055    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
4056      {
4057         y += step_y;
4058      }
4059    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
4060      {
4061         if (page_y < 0)
4062           y -= -(page_y * v_h) / 100;
4063         else
4064           y -= page_y;
4065      }
4066    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
4067      {
4068         if (page_y < 0)
4069           y += -(page_y * v_h) / 100;
4070         else
4071           y += page_y;
4072      }
4073    else if (!strcmp(ev->keyname, "KP_Add"))
4074      {
4075         zoom = elm_map_zoom_get(obj) + 1;
4076         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
4077         elm_map_zoom_set(obj, zoom);
4078         return EINA_TRUE;
4079      }
4080    else if (!strcmp(ev->keyname, "KP_Subtract"))
4081      {
4082         zoom = elm_map_zoom_get(obj) - 1;
4083         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
4084         elm_map_zoom_set(obj, zoom);
4085         return EINA_TRUE;
4086      }
4087    else return EINA_FALSE;
4088
4089    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
4090    elm_smart_scroller_child_pos_set(wd->scr, x, y);
4091
4092    return EINA_TRUE;
4093 }
4094
4095 static Eina_Bool
4096 cb_dump_name_attrs(void *data, const char *key, const char *value)
4097 {
4098    Name_Dump *dump = (Name_Dump*)data;
4099    if (!dump) return EINA_FALSE;
4100
4101    if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
4102    else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
4103
4104    return EINA_TRUE;
4105 }
4106
4107
4108 static Eina_Bool
4109 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
4110 {
4111    Route_Dump *dump = data;
4112    if (!dump) return EINA_FALSE;
4113
4114    switch (type)
4115      {
4116       case EINA_SIMPLE_XML_OPEN:
4117       case EINA_SIMPLE_XML_OPEN_EMPTY:
4118         {
4119            const char *attrs;
4120
4121            attrs = eina_simple_xml_tag_attributes_find(value, length);
4122            if (!attrs)
4123              {
4124                 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
4125                 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
4126                 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
4127                 else dump->id = ROUTE_XML_NONE;
4128              }
4129          }
4130         break;
4131       case EINA_SIMPLE_XML_DATA:
4132         {
4133            char *buf = malloc(length);
4134            if (!buf) return EINA_FALSE;
4135            snprintf(buf, length, "%s", value);
4136            if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
4137            else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
4138            else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
4139            free(buf);
4140         }
4141         break;
4142       default:
4143         break;
4144      }
4145
4146    return EINA_TRUE;
4147 }
4148
4149 static Eina_Bool
4150 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
4151 {
4152    Name_Dump *dump = data;
4153    if (!dump) return EINA_FALSE;
4154
4155    switch (type)
4156      {
4157       case EINA_SIMPLE_XML_OPEN:
4158       case EINA_SIMPLE_XML_OPEN_EMPTY:
4159         {
4160            const char *attrs;
4161            attrs = eina_simple_xml_tag_attributes_find(value, length);
4162            if (attrs)
4163              {
4164                 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
4165                 else dump->id = NAME_XML_NONE;
4166
4167                 eina_simple_xml_attributes_parse
4168                   (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
4169              }
4170         }
4171         break;
4172       case EINA_SIMPLE_XML_DATA:
4173         {
4174            char *buf = malloc(length + 1);
4175            if (!buf) return EINA_FALSE;
4176            snprintf(buf, length + 1, "%s", value);
4177            if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
4178            free(buf);
4179         }
4180         break;
4181       default:
4182         break;
4183      }
4184
4185    return EINA_TRUE;
4186 }
4187
4188 static void
4189 _parse_kml(void *data)
4190 {
4191    Elm_Map_Route *r = (Elm_Map_Route*)data;
4192    if (!r || !r->ud.fname) return;
4193
4194    FILE *f;
4195    char **str;
4196    unsigned int ele, idx;
4197    double lon, lat;
4198    Evas_Object *path;
4199
4200    Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
4201
4202    f = fopen(r->ud.fname, "rb");
4203    if (f)
4204      {
4205         long sz;
4206
4207         fseek(f, 0, SEEK_END);
4208         sz = ftell(f);
4209         if (sz > 0)
4210           {
4211              char *buf;
4212
4213              fseek(f, 0, SEEK_SET);
4214              buf = malloc(sz);
4215              if (buf)
4216                {
4217                   if (fread(buf, 1, sz, f))
4218                     {
4219                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
4220                        free(buf);
4221                     }
4222                }
4223           }
4224         fclose(f);
4225
4226         if (dump.distance) r->info.distance = dump.distance;
4227         if (dump.description)
4228           {
4229              eina_stringshare_replace(&r->info.waypoints, dump.description);
4230              str = eina_str_split_full(dump.description, "\n", 0, &ele);
4231              r->info.waypoint_count = ele;
4232              for (idx = 0 ; idx < ele ; idx++)
4233                {
4234                   Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
4235                   if (wp)
4236                     {
4237                        wp->wd = r->wd;
4238                        wp->point = eina_stringshare_add(str[idx]);
4239                        DBG("%s", str[idx]);
4240                        r->waypoint = eina_list_append(r->waypoint, wp);
4241                     }
4242                }
4243              if (str && str[0])
4244                {
4245                   free(str[0]);
4246                   free(str);
4247                }
4248           }
4249         else WRN("description is not found !");
4250
4251         if (dump.coordinates)
4252           {
4253              eina_stringshare_replace(&r->info.nodes, dump.coordinates);
4254              str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
4255              r->info.node_count = ele;
4256              for (idx = 0 ; idx < ele ; idx++)
4257                {
4258                   sscanf(str[idx], "%lf,%lf", &lon, &lat);
4259                   Path_Node *n = ELM_NEW(Path_Node);
4260                   if (n)
4261                     {
4262                        n->wd = r->wd;
4263                        n->pos.lon = lon;
4264                        n->pos.lat = lat;
4265                        n->idx = idx;
4266                        DBG("%lf:%lf", lon, lat);
4267                        n->pos.address = NULL;
4268                        r->nodes = eina_list_append(r->nodes, n);
4269
4270                        path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
4271                        evas_object_smart_member_add(path, r->wd->pan_smart);
4272                        r->path = eina_list_append(r->path, path);
4273                     }
4274                }
4275              if (str && str[0])
4276                {
4277                   free(str[0]);
4278                   free(str);
4279                }
4280           }
4281      }
4282 }
4283
4284 static void
4285 _parse_name(void *data)
4286 {
4287    Elm_Map_Name *n = (Elm_Map_Name*)data;
4288    if (!n || !n->ud.fname) return;
4289
4290    FILE *f;
4291
4292    Name_Dump dump = {0, NULL, 0.0, 0.0};
4293
4294    f = fopen(n->ud.fname, "rb");
4295    if (f)
4296      {
4297         long sz;
4298
4299         fseek(f, 0, SEEK_END);
4300         sz = ftell(f);
4301         if (sz > 0)
4302           {
4303              char *buf;
4304
4305              fseek(f, 0, SEEK_SET);
4306              buf = malloc(sz);
4307              if (buf)
4308                {
4309                   if (fread(buf, 1, sz, f))
4310                     {
4311                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
4312                        free(buf);
4313                     }
4314                }
4315           }
4316         fclose(f);
4317
4318         if (dump.address)
4319           {
4320              INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
4321              n->address = strdup(dump.address);
4322           }
4323         n->lon = dump.lon;
4324         n->lat = dump.lat;
4325      }
4326 }
4327
4328 Grid *_get_current_grid(Widget_Data *wd)
4329 {
4330    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4331    Eina_List *l;
4332    Grid *g = NULL, *ret = NULL;
4333    EINA_LIST_FOREACH(wd->grids, l, g)
4334      {
4335         if (wd->zoom == g->zoom)
4336           {
4337              ret = g;
4338              break;
4339           }
4340      }
4341    return ret;
4342 }
4343
4344 static Eina_Bool
4345 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
4346 {
4347    Ecore_Con_Event_Url_Complete *ev = event;
4348    Elm_Map_Route *r = (Elm_Map_Route*)data;
4349    Widget_Data *wd = r->wd;
4350
4351    if ((!r) || (!ev)) return EINA_TRUE;
4352    Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
4353    ecore_con_url_data_set(r->con_url, NULL);
4354    if (r!=rr) return EINA_TRUE;
4355
4356    if (r->ud.fd) fclose(r->ud.fd);
4357    _parse_kml(r);
4358
4359    if (wd->grids)
4360      {
4361         Grid *g;
4362         Evas_Coord ox, oy, ow, oh;
4363         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4364         g = _get_current_grid(wd);
4365         route_place(wd->obj, g, wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4366      }
4367    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4368                            "elm,state,busy,stop", "elm");
4369    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
4370    return EINA_TRUE;
4371 }
4372
4373 static Eina_Bool
4374 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
4375 {
4376    Ecore_Con_Event_Url_Complete *ev = event;
4377    Elm_Map_Name *n = (Elm_Map_Name*)data;
4378    Widget_Data *wd = n->wd;
4379
4380    if ((!n) || (!ev)) return EINA_TRUE;
4381    Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
4382    ecore_con_url_data_set(n->con_url, NULL);
4383    if (n!=nn) return EINA_TRUE;
4384
4385    if (n->ud.fd) fclose(n->ud.fd);
4386    _parse_name(n);
4387
4388    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4389                            "elm,state,busy,stop", "elm");
4390    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
4391    return EINA_TRUE;
4392 }
4393
4394 static Elm_Map_Name *
4395 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
4396 {
4397    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4398    Widget_Data *wd = elm_widget_data_get(obj);
4399    char buf[PATH_MAX];
4400    char *source;
4401    int fd;
4402
4403    if ((!wd) || (!wd->src)) return NULL;
4404    Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
4405    if (!name) return NULL;
4406
4407    snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
4408    fd = mkstemp(buf);
4409    if (fd < 0)
4410      {
4411         free(name);
4412         return NULL;
4413      }
4414
4415    name->con_url = ecore_con_url_new(NULL);
4416    name->ud.fname = strdup(buf);
4417    INF("xml file : %s", name->ud.fname);
4418
4419    name->ud.fd = fdopen(fd, "w+");
4420    if ((!name->con_url) || (!name->ud.fd))
4421      {
4422         ecore_con_url_free(name->con_url);
4423         free(name);
4424         return NULL;
4425      }
4426
4427    name->wd = wd;
4428    name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
4429    name->method = method;
4430    if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
4431    else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
4432    name->lon = lon;
4433    name->lat = lat;
4434
4435    source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
4436    INF("name url = %s", source);
4437
4438    wd->names = eina_list_append(wd->names, name);
4439    ecore_con_url_url_set(name->con_url, source);
4440    ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
4441    ecore_con_url_data_set(name->con_url, name);
4442
4443    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4444                            "elm,state,busy,start", "elm");
4445    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
4446    ecore_con_url_get(name->con_url);
4447    if (source) free(source);
4448
4449    return name;
4450
4451 }
4452
4453 static Evas_Event_Flags
4454 zoom_start_cb(void *data, void *event_info __UNUSED__)
4455 {
4456    Widget_Data *wd = data;
4457    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
4458
4459    // FIXME: scroller can be jumping strangely when resizing & scrolling at the sametime (els_scr bug?)
4460    elm_smart_scroller_hold_set(wd->scr, 1);
4461    elm_smart_scroller_freeze_set(wd->scr, 1);
4462    _scr_drag_start(wd->obj, NULL, NULL);
4463
4464    wd->pinch.diff += 0.001;
4465
4466    return EVAS_EVENT_FLAG_NONE;
4467 }
4468
4469 static Evas_Event_Flags
4470 zoom_end_cb(void *data, void *event_info __UNUSED__)
4471 {
4472    Widget_Data *wd = data;
4473    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
4474
4475    // FIXME: scroller can be jumping strangely when resizing & scrolling at the sametime (els_scr bug?)
4476    elm_smart_scroller_hold_set(wd->scr, 0);
4477    elm_smart_scroller_freeze_set(wd->scr, 0);
4478    _scr_drag_stop(wd->obj, NULL, NULL);
4479
4480    wd->pinch.diff = wd->pinch.level;
4481
4482    return EVAS_EVENT_FLAG_NONE;
4483 }
4484
4485 static Evas_Event_Flags
4486 zoom_cb(void *data, void *event_info)
4487 {
4488    Widget_Data *wd = data;
4489    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
4490
4491    if (!wd->paused)
4492      {
4493         int zoom_diff = 0;
4494         int x, y, w, h;
4495         Elm_Gesture_Zoom_Info *ei = event_info;
4496         evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
4497
4498         wd->pinch.level = wd->pinch.diff * ei->zoom;
4499         wd->pinch.cx = x + ((double)w * 0.5);
4500         wd->pinch.cy = y + ((double)h * 0.5);
4501
4502         if (wd->pinch.level > 1.999 || wd->pinch.level < 1.001)
4503           {
4504              if (wd->pinch.level > 1.999)
4505                {
4506                   zoom_diff = 1;
4507                   wd->pinch.diff = wd->pinch.level / 2.0;
4508                   wd->pinch.level = wd->pinch.level / 2.0;
4509                }
4510              else if (wd->pinch.level < 1.001)
4511                {
4512                   zoom_diff = -1;
4513                   wd->pinch.diff = wd->pinch.level * 2.0;
4514                   wd->pinch.level = wd->pinch.level * 2.0;
4515                }
4516              Elm_Map_Zoom_Mode temp;
4517              elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE, NULL, wd);  // ei->zoom is refreshed
4518              temp = wd->mode;
4519              wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
4520              wd->paused = EINA_TRUE;
4521              elm_map_zoom_set(wd->obj, wd->zoom + zoom_diff);
4522              wd->paused = EINA_FALSE;
4523              wd->mode = temp;
4524              elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE, zoom_cb, wd); // ei->zoom is refreshed
4525           }
4526         else
4527           {
4528              if (wd->calc_job) ecore_job_del(wd->calc_job);
4529              wd->calc_job = ecore_job_add(_calc_job, wd);
4530           }
4531         evas_object_smart_callback_call(wd->obj, SIG_ZOOM_CHANGE, NULL);
4532      }
4533
4534    // FIXME: scroller can be jumping strangely when resizing & scrolling at the sametime (els_scr bug?)
4535    _scr_scroll(wd->obj, NULL, NULL);
4536
4537    return EVAS_EVENT_FLAG_NONE;
4538 }
4539
4540 static Evas_Event_Flags
4541 rotate_cb(void *data, void *event_info)
4542 {
4543    Widget_Data *wd = data;
4544    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
4545
4546    if (!wd->paused)
4547      {
4548         int x, y, w, h;
4549         Elm_Gesture_Rotate_Info *ei = event_info;
4550         evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
4551
4552         wd->rotate.d = wd->rotate.a + ei->angle - ei->base_angle;
4553         wd->rotate.cx = x + ((double)w * 0.5);
4554         wd->rotate.cy = y + ((double)h * 0.5);
4555
4556         if (wd->calc_job) ecore_job_del(wd->calc_job);
4557         wd->calc_job = ecore_job_add(_calc_job, wd);
4558      }
4559    return EVAS_EVENT_FLAG_NONE;
4560 }
4561
4562 static Evas_Event_Flags
4563 rotate_end_cb(void *data, void *event_info __UNUSED__)
4564 {
4565    Widget_Data *wd = data;
4566    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
4567
4568    wd->rotate.a = wd->rotate.d;
4569
4570    return EVAS_EVENT_FLAG_NONE;
4571 }
4572
4573 static void
4574 _region_get(Widget_Data *wd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *w, Evas_Coord *h)
4575 {
4576    EINA_SAFETY_ON_NULL_RETURN(wd);
4577    Evas_Coord sx, sy, tx, ty, tcx, tcy, sw, sh, tw, th, rw, rh;
4578
4579    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
4580    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
4581    rw = wd->size.w * wd->pinch.level;
4582    rh = wd->size.h * wd->pinch.level;
4583
4584    if (wd->size.w < sw)
4585      {
4586         tw = rw;
4587         tcx = sx + tw/2;
4588         tx = sx + (sw - tw)/2;
4589      }
4590    else
4591      {
4592         tw = sw;
4593         tcx = (sx + tw/2) * wd->pinch.level;
4594         tx = tcx - tw/2;
4595
4596      }
4597    if (wd->size.h < sh)
4598      {
4599         th = rh;
4600         ty = sy + (sh - th)/2;
4601         tcy = sy + th/2;
4602      }
4603    else
4604      {
4605         th = sw;
4606         tcy = (sy + th/2) * wd->pinch.level;
4607         ty = tcy - th/2;
4608      }
4609
4610    if (x) *x = tx;
4611    if (y) *y = ty;
4612    if (cx) *cx= tcx;
4613    if (cy) *cy = tcy;
4614    if (w) *w = tw;
4615    if (h) *h = th;
4616 }
4617
4618 static void
4619 _coord_rotate(const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
4620 {
4621    EINA_SAFETY_ON_NULL_RETURN(xx);
4622    EINA_SAFETY_ON_NULL_RETURN(yy);
4623
4624    double r = (degree * M_PI) / 180.0;
4625    double tx, ty, ttx, tty;
4626
4627    tx = x - cx;
4628    ty = y - cy;
4629
4630    ttx = tx * cos(r);
4631    tty = tx * sin(r);
4632    tx = ttx + (ty * cos(r + M_PI_2));
4633    ty = tty + (ty * sin(r + M_PI_2));
4634
4635    *xx = tx + cx;
4636    *yy = ty + cy;
4637 }
4638
4639 =======
4640 zoom_with_animation(Widget_Data *wd, double zoom, int cnt)
4641 {
4642    EINA_SAFETY_ON_NULL_RETURN(wd);
4643    if (cnt == 0) return;
4644
4645    wd->ani.cnt = cnt;
4646    wd->ani.zoom = wd->zoom;
4647    wd->ani.diff = (double)(zoom - wd->zoom) / cnt;
4648    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
4649    wd->zoom_animator = ecore_animator_add(_zoom_anim, wd);
4650 }
4651
4652 static void
4653 _sizing_eval(Widget_Data *wd)
4654 {
4655    EINA_SAFETY_ON_NULL_RETURN(wd);
4656
4657    Evas_Coord maxw = -1, maxh = -1;
4658
4659    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
4660    evas_object_size_hint_max_set(wd->obj, maxw, maxh);
4661 }
4662
4663 static void
4664 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4665 {
4666    _sizing_eval(data);
4667 }
4668
4669 static Eina_Bool
4670 _scr_timeout(void *data)
4671 {
4672    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
4673    Widget_Data *wd = data;
4674    _smooth_update(wd);
4675    wd->scr_timer = NULL;
4676    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_STOP, NULL);
4677    return ECORE_CALLBACK_CANCEL;
4678 }
4679
4680 static void
4681 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4682 {
4683    EINA_SAFETY_ON_NULL_RETURN(data);
4684    Widget_Data *wd = data;
4685
4686    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
4687    else evas_object_smart_callback_call(wd->obj, SIG_SCROLL_DRAG_START, NULL);
4688    wd->scr_timer = ecore_timer_add(0.25, _scr_timeout, wd);
4689    evas_object_smart_callback_call(wd->obj, SIG_SCROLL, NULL);
4690 }
4691
4692 static void
4693 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4694 {
4695    EINA_SAFETY_ON_NULL_RETURN(data);
4696    Widget_Data *wd = data;
4697    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_START, NULL);
4698 }
4699
4700 static void
4701 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4702 {
4703    EINA_SAFETY_ON_NULL_RETURN(data);
4704    Widget_Data *wd = data;
4705    evas_object_smart_callback_call(wd->obj, SIG_SCROLL_ANIM_STOP, NULL);
4706 }
4707
4708 static Eina_Bool
4709 _long_press(void *data)
4710 {
4711    EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
4712    Widget_Data *wd = data;
4713
4714    wd->long_timer = NULL;
4715    evas_object_smart_callback_call(wd->obj, SIG_LONGPRESSED, &wd->ev);
4716    return ECORE_CALLBACK_CANCEL;
4717 }
4718
4719 static void
4720 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
4721 {
4722    EINA_SAFETY_ON_NULL_RETURN(data);
4723    Widget_Data *wd = data;
4724    Evas_Event_Mouse_Down *ev = event_info;
4725
4726    if (ev->button != 1) return;
4727
4728    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
4729    else wd->on_hold = EINA_FALSE;
4730
4731    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
4732      evas_object_smart_callback_call(wd->obj, SIG_CLICKED_DOUBLE, ev);
4733    else evas_object_smart_callback_call(wd->obj, SIG_PRESS, ev);
4734
4735    if (wd->long_timer) ecore_timer_del(wd->long_timer);
4736    wd->ev = *ev;
4737    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, wd);
4738 }
4739
4740 static void
4741 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
4742 {
4743    EINA_SAFETY_ON_NULL_RETURN(data);
4744    Widget_Data *wd = data;
4745
4746    Evas_Event_Mouse_Up *ev = event_info;
4747    EINA_SAFETY_ON_NULL_RETURN(ev);
4748
4749    if (ev->button != 1) return;
4750    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
4751    else wd->on_hold = EINA_FALSE;
4752    if (wd->long_timer)
4753      {
4754         ecore_timer_del(wd->long_timer);
4755         wd->long_timer = NULL;
4756      }
4757    if (!wd->on_hold) evas_object_smart_callback_call(wd->obj, SIG_CLICKED, ev);
4758    wd->on_hold = EINA_FALSE;
4759 }
4760
4761 static void
4762 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
4763 {
4764    EINA_SAFETY_ON_NULL_RETURN(data);
4765    Widget_Data *wd = data;
4766
4767    if (!wd->paused)
4768      {
4769         Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
4770         zoom_do(wd, wd->zoom_detail - ((double)ev->z / 10));
4771     }
4772 }
4773
4774 static void
4775 _region_max_min_get(Eina_List *overlays, double *max_longitude, double *min_longitude, double *max_latitude, double *min_latitude)
4776 {
4777    double max_lon = -180, min_lon = 180;
4778    double max_lat = -90, min_lat = 90;
4779    Elm_Map_Overlay *overlay;
4780    EINA_LIST_FREE(overlays, overlay)
4781      {
4782         double lon, lat;
4783         if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
4784           {
4785              Overlay_Default *ovl = overlay->ovl;
4786              lon = ovl->lon;
4787              lat = ovl->lat;
4788           }
4789         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
4790           {
4791              // FIXME: class center coord is alright??
4792              Overlay_Class *ovl = overlay->ovl;
4793              double max_lo, min_lo, max_la, min_la;
4794              _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la,
4795                                  &min_la);
4796              lon = (max_lo + min_lo) / 2;
4797              lat = (max_la + min_la) / 2;
4798           }
4799         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
4800           {
4801              Overlay_Bubble *ovl = overlay->ovl;
4802              lon = ovl->lon;
4803              lat = ovl->lat;
4804           }
4805         else
4806           {
4807              WRN("Not supported overlay type: %d", overlay->type);
4808              continue;
4809           }
4810         if (lon> max_lon) max_lon = lon;
4811         if (lon< min_lon) min_lon = lon;
4812         if (lat > max_lat) max_lat = lat;
4813         if (lat < min_lat) min_lat = lat;
4814      }
4815    if (max_longitude) *max_longitude = max_lon;
4816    if (min_longitude) *min_longitude = min_lon;
4817    if (max_latitude) *max_latitude = max_lat;
4818    if (min_latitude) *min_latitude = min_lat;
4819 }
4820
4821 static Evas_Object *
4822 _icon_dup(Evas_Object *icon, Evas_Object *parent)
4823 {
4824    if (!icon || !parent) return NULL;
4825    // Evas_Object do not support object duplication??
4826    const char *file = NULL, *group = NULL;
4827    Eina_Bool size_up, size_down;
4828    Evas_Object *dupp;
4829
4830    dupp = elm_icon_add(parent);
4831    elm_icon_file_get(icon, &file, &group);
4832    elm_icon_file_set(dupp, file, group);
4833    elm_icon_animated_set(dupp, elm_icon_animated_get(icon));
4834    elm_icon_animated_play_set(dupp, elm_icon_animated_play_get(icon));
4835    elm_icon_standard_set(dupp, elm_icon_standard_get(icon));
4836    elm_icon_order_lookup_set(dupp, elm_icon_order_lookup_get(icon));
4837    elm_icon_no_scale_set(dupp, elm_icon_no_scale_get(icon));
4838    elm_icon_resizable_get(icon, &size_up, &size_down);
4839    elm_icon_resizable_set(dupp, size_up, size_down);
4840    elm_icon_fill_outside_set(dupp, elm_icon_fill_outside_get(icon));
4841    elm_icon_prescale_set(dupp, elm_icon_prescale_get(icon));
4842    elm_icon_aspect_fixed_set(dupp, elm_icon_aspect_fixed_get(icon));
4843    return dupp;
4844 }
4845
4846 static Evas_Object *
4847 _overlay_layout_new(Widget_Data *wd, const char *group)
4848 {
4849    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
4850    EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
4851    Evas_Object *obj = elm_layout_add(wd->obj);
4852    evas_object_smart_member_add(obj, wd->pan_smart);
4853    evas_object_stack_above(obj, wd->sep_maps_markers);
4854    elm_layout_theme_set(obj, "map/marker", group,  elm_widget_style_get(wd->obj));
4855    return obj;
4856 }
4857
4858 static void
4859 _overlay_layout_update(Widget_Data *wd, Evas_Object *layout, Evas_Object *icon, const char *text, const char *group)
4860 {
4861    EINA_SAFETY_ON_NULL_RETURN(wd);
4862    EINA_SAFETY_ON_NULL_RETURN(layout);
4863
4864    Evas_Object *prev_icon = elm_object_part_content_get(layout, "elm.icon");
4865    if (icon && (prev_icon != icon))
4866      {
4867         elm_layout_theme_set(layout, "map/marker", "empty",
4868                              elm_widget_style_get(wd->obj));
4869         elm_object_part_content_set(layout, "elm.icon", icon);
4870      }
4871    else if (text)
4872      {
4873         if (group) elm_layout_theme_set(layout, "map/marker", group,
4874                                         elm_widget_style_get(wd->obj));
4875         edje_object_part_text_set(elm_layout_edje_get(layout), "elm.text", text);
4876      }
4877 }
4878
4879 static void
4880 _overlay_clicked_cb(void *data, Evas *e __UNUSED__,  Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
4881 {
4882    EINA_SAFETY_ON_NULL_RETURN(data);
4883    Elm_Map_Overlay *overlay = data;
4884
4885    evas_object_smart_callback_call(overlay->wd->obj, SIG_OVERLAY_CLICKED,
4886                                    overlay);
4887    if (overlay->cb) overlay->cb(overlay->cb_data, overlay->wd->obj,
4888                                 overlay);
4889 }
4890
4891 static void
4892 _overlay_default_cb_add(Overlay_Default *ovl, Evas_Object_Event_Cb cb, void *data)
4893 {
4894    EINA_SAFETY_ON_NULL_RETURN(ovl);
4895    EINA_SAFETY_ON_NULL_RETURN(data);
4896
4897    // FIXME: Add icon or object event callback
4898    evas_object_event_callback_add(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb,
4899                                   data);
4900 }
4901
4902 static void
4903 _overlay_default_cb_del(Overlay_Default *ovl, Evas_Object_Event_Cb cb)
4904 {
4905    EINA_SAFETY_ON_NULL_RETURN(ovl);
4906    // FIXME: Add icon or object event callback
4907    evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN, cb);
4908 }
4909
4910 static void
4911 _overlay_default_hide(Overlay_Default *ovl)
4912 {
4913    EINA_SAFETY_ON_NULL_RETURN(ovl);
4914    if (ovl->obj) evas_object_hide(ovl->obj);
4915    if (ovl->layout) evas_object_hide(ovl->layout);
4916 }
4917
4918 static void
4919 _overlay_default_show(Widget_Data *wd, Overlay_Default *ovl)
4920 {
4921    Evas_Object *disp;
4922    Evas_Coord px, py;
4923    Evas_Coord x, y, w, h;
4924
4925    if (ovl->obj)
4926      {
4927         disp = ovl->obj;
4928         evas_object_geometry_get(disp, NULL, NULL, &w, &h);
4929         if (w <= 0 || h <= 0) evas_object_size_hint_min_get(disp, &w, &h);
4930      }
4931    else
4932      {
4933         disp = ovl->layout;
4934         w = ovl->w;
4935         h = ovl->h;
4936      }
4937
4938    _pan_geometry_get(wd, &px, &py);
4939    _coord_rotate(ovl->x + px, ovl->y + py, wd->rotate.cx,  wd->rotate.cy,
4940                  wd->rotate.d, &x, &y);
4941    _obj_place(disp, x - (w / 2), y - (h / 2), w, h);
4942 }
4943
4944 static void
4945 _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)
4946 {
4947    EINA_SAFETY_ON_NULL_RETURN(wd);
4948    EINA_SAFETY_ON_NULL_RETURN(ovl);
4949
4950    _region_to_coord_convert(wd, ovl->lon, ovl->lat, wd->size.w, &ovl->x, &ovl->y);
4951
4952    if (obj)
4953      {
4954         if (ovl->obj == obj) return;
4955         if (ovl->obj) evas_object_del(ovl->obj);
4956         ovl->obj = obj;
4957      }
4958    else if (!(ovl->obj) && icon)
4959      {
4960         if (ovl->icon == icon) return;
4961         if (ovl->icon) evas_object_del(ovl->icon);
4962         ovl->icon = icon;
4963        _overlay_layout_update(wd, ovl->layout, ovl->icon, NULL, NULL);
4964
4965      }
4966    else if (!(ovl->obj) && !(ovl->icon) && (ovl_clas) &&
4967             ((ovl_clas->obj) || (ovl_clas->icon)))
4968      {
4969         // Inherit icon from group overlay's ojbect or icon
4970
4971         // FIXME: It is hard to duplicate evas object :-)
4972         /*
4973         if (ovl_clas->obj && (ovl_clas->obj != ovl->clas_obj_ref))
4974           {
4975              if (ovl->clas_obj) evas_object_del(ovl->clas_obj);
4976              ovl->clas_obj_ref = ovl_clas->obj;
4977              ovl->clas_obj = _obj_dup(ovl->clas_obj_ref, ovl->layout);
4978              _overlay_layout_update(wd, ovl->layout, ovl->clas_obj, NULL, NULL);
4979           }
4980         */
4981         if (ovl_clas->icon && (ovl_clas->icon != ovl->clas_icon_ref))
4982           {
4983              if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
4984              ovl->clas_icon_ref = ovl_clas->icon;
4985              ovl->clas_icon = _icon_dup(ovl->clas_icon_ref, ovl->layout);
4986              _overlay_layout_update(wd, ovl->layout, ovl->clas_icon, NULL, NULL);
4987         }
4988      }
4989    else if (!(ovl->obj) && !(ovl->icon) && !(ovl->clas_icon) && text)
4990      {
4991         _overlay_layout_update(wd, ovl->layout, NULL, text, group);
4992      }
4993 }
4994
4995 static void
4996 _overlay_default_free(Overlay_Default *ovl)
4997 {
4998    EINA_SAFETY_ON_NULL_RETURN(ovl);
4999    if (ovl->obj) evas_object_del(ovl->obj);
5000    if (ovl->icon) evas_object_del(ovl->icon);
5001    if (ovl->clas_icon) evas_object_del(ovl->clas_icon);
5002    evas_object_event_callback_del(ovl->layout, EVAS_CALLBACK_MOUSE_DOWN,
5003                                   _overlay_clicked_cb);
5004    if (ovl->layout) evas_object_del(ovl->layout);
5005    free(ovl);
5006 }
5007
5008 static Overlay_Default *
5009 _overlay_default_new(Widget_Data *wd, double lon, double lat, const char *group)
5010 {
5011    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5012    EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
5013
5014    Overlay_Default *ovl = ELM_NEW(Overlay_Default);
5015    _edj_marker_size_get(wd, &(ovl->w), &(ovl->h));
5016    ovl->layout = _overlay_layout_new(wd, group);
5017    ovl->lon = lon;
5018    ovl->lat = lat;
5019    return ovl;
5020 }
5021
5022 static void
5023 _overlay_group_clicked_cb(void *data, Evas *e __UNUSED__,  Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
5024 {
5025    EINA_SAFETY_ON_NULL_RETURN(data);
5026    Overlay_Group *ovl = data;
5027
5028    evas_object_smart_callback_call(ovl->clas->wd->obj, SIG_OVERLAY_CLICKED,
5029                                    ovl->clas);
5030    if (ovl->clas->cb) ovl->clas->cb(ovl->clas->cb_data, ovl->clas->wd->obj,
5031                                     ovl->clas);
5032 }
5033
5034 static void
5035 _overlay_group_cb_add(Overlay_Group *ovl)
5036 {
5037    EINA_SAFETY_ON_NULL_RETURN(ovl);
5038    _overlay_default_cb_add(ovl->ovl, _overlay_group_clicked_cb, ovl);
5039 }
5040
5041 static void
5042 _overlay_group_cb_del(Overlay_Group *ovl)
5043 {
5044    EINA_SAFETY_ON_NULL_RETURN(ovl);
5045    _overlay_default_cb_del(ovl->ovl, _overlay_group_clicked_cb);
5046 }
5047
5048 static void
5049 _overlay_group_update(Widget_Data *wd, Overlay_Group *grp, Eina_List *members)
5050 {
5051    EINA_SAFETY_ON_NULL_RETURN(wd);
5052    EINA_SAFETY_ON_NULL_RETURN(grp);
5053
5054    Eina_List *l;
5055    Elm_Map_Overlay *overlay;
5056    Evas_Coord sum_x = 0, sum_y = 0, cnt = 0;
5057
5058    if (grp->members) eina_list_free(grp->members);
5059    grp->members = members;
5060
5061    if (!grp->members || eina_list_count(grp->members) <= 0)
5062      {
5063         _overlay_default_hide(grp->ovl);
5064         return;
5065      }
5066    EINA_LIST_FOREACH(grp->members, l, overlay)
5067      {
5068         Overlay_Default *df = overlay->ovl;
5069         sum_x += df->x;
5070         sum_y += df->y;
5071         cnt++;
5072      }
5073
5074    Overlay_Class *ovl_clas = grp->clas->ovl;
5075
5076    char text[128];
5077    snprintf(text, sizeof(text), "%d", cnt);
5078    _overlay_default_update(wd, grp->ovl, NULL, NULL, ovl_clas, text, "radio2");
5079
5080    grp->ovl->x = sum_x / cnt;
5081    grp->ovl->y = sum_y / cnt;
5082 }
5083
5084 static void
5085 _overlay_group_free(Overlay_Group *grp, Elm_Map_Overlay *club_owner)
5086 {
5087    EINA_SAFETY_ON_NULL_RETURN(grp);
5088
5089    _overlay_default_cb_del(grp->ovl, _overlay_group_clicked_cb);
5090    _overlay_default_free(grp->ovl);
5091    if (grp->clas) elm_map_overlay_class_remove(grp->clas, club_owner);
5092    if (grp->members) eina_list_free(grp->members);
5093    free(grp);
5094 }
5095
5096 static Overlay_Group *
5097 _overlay_group_new(Widget_Data *wd)
5098 {
5099    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5100
5101    Overlay_Group *grp = ELM_NEW(Overlay_Group);
5102    grp->ovl = ELM_NEW(Overlay_Default);
5103    grp->ovl = _overlay_default_new(wd, -1, -1, "radio2");
5104    grp->ovl->w *= 2;
5105    grp->ovl->h *= 2;
5106    return grp;
5107 }
5108
5109 static void
5110 _overlay_class_update(Widget_Data *wd, Overlay_Class *clas, Evas_Object *obj, Evas_Object *icon)
5111 {
5112    EINA_SAFETY_ON_NULL_RETURN(wd);
5113    EINA_SAFETY_ON_NULL_RETURN(clas);
5114
5115    if (obj && (clas->obj != obj))
5116      {
5117         if (clas->obj) evas_object_del(clas->obj);
5118         clas->obj = icon;
5119      }
5120    else if (icon && (clas->icon != icon))
5121      {
5122         if (clas->icon) evas_object_del(clas->icon);
5123         clas->icon = icon;
5124      }
5125 }
5126
5127 static void
5128 _overlay_class_free(Overlay_Class *clas)
5129 {
5130    EINA_SAFETY_ON_NULL_RETURN(clas);
5131    if (clas->icon) evas_object_del(clas->icon);
5132    if (clas->members) eina_list_free(clas->members);
5133    free(clas);
5134 }
5135
5136 static Overlay_Class *
5137 _overlay_class_new(Widget_Data *wd, Elm_Map_Overlay *clas)
5138 {
5139    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5140    Overlay_Class *ovl = ELM_NEW(Overlay_Class);
5141    ovl->clas = clas;
5142    ovl->icon = NULL;
5143    ovl->zoom_max = OVERLAY_CLASS_ZOOM_MAX;
5144    return ovl;
5145 }
5146
5147 static void
5148 _overlay_bubble_cb_add(Overlay_Bubble *ovl, Elm_Map_Overlay *overlay)
5149 {
5150    EINA_SAFETY_ON_NULL_RETURN(ovl);
5151    EINA_SAFETY_ON_NULL_RETURN(overlay);
5152    evas_object_event_callback_add(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
5153                                   _overlay_clicked_cb, overlay);
5154 }
5155
5156 static void
5157 _overlay_bubble_cb_del(Overlay_Bubble *ovl)
5158 {
5159    EINA_SAFETY_ON_NULL_RETURN(ovl);
5160    evas_object_event_callback_del(ovl->obj, EVAS_CALLBACK_MOUSE_DOWN,
5161                                   _overlay_clicked_cb);
5162 }
5163
5164 static void
5165 _overlay_bubble_hide(Overlay_Bubble *bubble)
5166 {
5167    EINA_SAFETY_ON_NULL_RETURN(bubble);
5168    if (bubble->obj) evas_object_hide(bubble->obj);
5169 }
5170
5171 static void
5172 _overlay_bubble_update(Overlay_Bubble *bubble)
5173 {
5174    EINA_SAFETY_ON_NULL_RETURN(bubble);
5175    if ((!bubble->pobj) && (bubble->lon >= 0) && (bubble->lat >= 0))
5176      {
5177         _region_to_coord_convert(bubble->wd, bubble->lon, bubble->lat,
5178                               bubble->wd->size.w, &bubble->x, &bubble->y);
5179      }
5180 }
5181
5182 static void
5183 _overlay_bubble_show(Overlay_Bubble *bubble)
5184 {
5185    EINA_SAFETY_ON_NULL_RETURN(bubble);
5186    Evas_Coord x, y;
5187
5188    if ((bubble->x < 0) || (bubble->y < 0)) return;
5189    Evas_Coord px, py;
5190    _pan_geometry_get(bubble->wd, &px, &py);
5191    _coord_rotate(bubble->x + px, bubble->y + py, bubble->wd->rotate.cx,
5192                  bubble->wd->rotate.cy, bubble->wd->rotate.d, &x, &y);
5193    x = x - (bubble->w / 2);
5194    y = y - (bubble->h / 2);
5195    _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
5196    //evas_object_raise(bubble->obj);
5197 }
5198
5199 static void
5200 _overlay_bubble_chase(Overlay_Bubble *bubble)
5201 {
5202    EINA_SAFETY_ON_NULL_RETURN(bubble);
5203    EINA_SAFETY_ON_NULL_RETURN(bubble->pobj);
5204
5205    Evas_Coord x, y, w;
5206    evas_object_geometry_get(bubble->pobj, &x, &y, &w, NULL);
5207    x = x + (w / 2) - (bubble->w / 2);
5208    y = y - bubble->h;
5209    _obj_place(bubble->obj, x, y, bubble->w, bubble->h);
5210    evas_object_raise(bubble->obj);
5211 }
5212
5213 static void
5214 _overlay_bubble_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5215 {
5216    EINA_SAFETY_ON_NULL_RETURN(data);
5217    _overlay_bubble_hide(data);
5218 }
5219
5220 static void
5221 _overlay_bubble_chase_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5222 {
5223    EINA_SAFETY_ON_NULL_RETURN(data);
5224    _overlay_bubble_chase(data);
5225 }
5226
5227 static void
5228 _overlay_bubble_free(Overlay_Bubble* bubble)
5229 {
5230    EINA_SAFETY_ON_NULL_RETURN(bubble);
5231
5232    evas_object_del(bubble->bx);
5233    evas_object_del(bubble->sc);
5234    evas_object_del(bubble->obj);
5235    if (bubble->pobj)
5236      {
5237         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_HIDE,
5238                                             _overlay_bubble_hide_cb, bubble);
5239         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_SHOW,
5240                                             _overlay_bubble_chase_cb, bubble);
5241         evas_object_event_callback_del_full(bubble->pobj, EVAS_CALLBACK_MOVE,
5242                                             _overlay_bubble_chase_cb, bubble);
5243      }
5244    free(bubble);
5245 }
5246
5247 static Overlay_Bubble*
5248 _overlay_bubble_new(Widget_Data *wd)
5249 {
5250    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5251
5252    Evas_Coord h;
5253    const char *s;
5254    Overlay_Bubble *bubble = ELM_NEW(Overlay_Bubble);
5255    bubble->wd = wd;
5256
5257    bubble->obj = edje_object_add(evas_object_evas_get(wd->obj));
5258    _elm_theme_object_set(wd->obj, bubble->obj , "map", "marker_bubble",
5259                          elm_widget_style_get(wd->obj));
5260    evas_object_event_callback_add(bubble->obj, EVAS_CALLBACK_MOUSE_UP,
5261                                   _overlay_bubble_chase_cb, bubble);
5262
5263    bubble->sc = elm_scroller_add(bubble->obj);
5264    elm_widget_style_set(bubble->sc, "map_bubble");
5265    elm_scroller_content_min_limit(bubble->sc, EINA_FALSE, EINA_TRUE);
5266    elm_scroller_policy_set(bubble->sc, ELM_SCROLLER_POLICY_AUTO,
5267                            ELM_SCROLLER_POLICY_OFF);
5268    elm_scroller_bounce_set(bubble->sc, _elm_config->thumbscroll_bounce_enable,
5269                            EINA_FALSE);
5270    edje_object_part_swallow(bubble->obj, "elm.swallow.content", bubble->sc);
5271
5272    bubble->bx = elm_box_add(bubble->sc);
5273    evas_object_size_hint_align_set(bubble->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
5274    evas_object_size_hint_weight_set(bubble->bx, EVAS_HINT_EXPAND,
5275                                     EVAS_HINT_EXPAND);
5276    elm_box_horizontal_set(bubble->bx, EINA_TRUE);
5277    elm_object_content_set(bubble->sc, bubble->bx);
5278
5279    s = edje_object_data_get(bubble->obj, "size_w");
5280    if (s) bubble->w = atoi(s);
5281    else bubble->w = 0;
5282
5283    edje_object_size_min_calc(bubble->obj, NULL, &(bubble->h));
5284    s = edje_object_data_get(bubble->obj, "size_h");
5285    if (s) h = atoi(s);
5286    else h = 0;
5287    if (bubble->h < h) bubble->h = h;
5288
5289    bubble->lon = -1;
5290    bubble->lat = -1;
5291    bubble->x = -1;
5292    bubble->y = -1;
5293    return bubble;
5294 }
5295
5296 static void
5297 _overlay_route_hide(Overlay_Route *r)
5298 {
5299    EINA_SAFETY_ON_NULL_RETURN(r);
5300    Eina_List *l;
5301    Evas_Object *p;
5302    EINA_LIST_FOREACH(r->paths, l, p) evas_object_hide(p);
5303 }
5304
5305 static void
5306 _overlay_route_show(Overlay_Route *r)
5307 {
5308    EINA_SAFETY_ON_NULL_RETURN(r);
5309    EINA_SAFETY_ON_NULL_RETURN(r->wd);
5310
5311    Widget_Data *wd;
5312    Eina_List *l;
5313    Evas_Object *p;
5314    Path_Node *n;
5315    int cnt;
5316    int x, y;
5317    double a;
5318    Evas_Coord ow, oh, px, py, size;
5319
5320    wd = r->wd;
5321    _viewport_size_get(wd, &ow, &oh);
5322    px = wd->pan_x;
5323    py = wd->pan_y;
5324    size = wd->size.w;
5325
5326    EINA_LIST_FOREACH(r->paths, l, p) evas_object_polygon_points_clear(p);
5327
5328    cnt = eina_list_count(r->nodes);
5329    EINA_LIST_FOREACH(r->nodes, l, n)
5330      {
5331         if ((!wd->zoom) || ((n->idx) &&
5332             ((n->idx % (int)ceil((double)cnt/(double)size*100.0))))) continue;
5333         if (r->inbound)
5334           {
5335              _region_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
5336                                    &x, &y);
5337              if ((x >= px - ow) && (x <= (px + ow*2)) &&
5338                  (y >= py - oh) && (y <= (py + oh*2)))
5339                {
5340                   x = x - px;
5341                   y = y - py;
5342
5343                   p = eina_list_nth(r->paths, n->idx);
5344                   a = (double)(y - r->y) / (double)(x - r->x);
5345                   if ((abs(a) >= 1) || (r->x == x))
5346                     {
5347                        evas_object_polygon_point_add(p, r->x - 3, r->y);
5348                        evas_object_polygon_point_add(p, r->x + 3, r->y);
5349                        evas_object_polygon_point_add(p, x + 3, y);
5350                        evas_object_polygon_point_add(p, x - 3, y);
5351                     }
5352                   else
5353                     {
5354                        evas_object_polygon_point_add(p, r->x, r->y - 3);
5355                        evas_object_polygon_point_add(p, r->x, r->y + 3);
5356                        evas_object_polygon_point_add(p, x, y + 3);
5357                        evas_object_polygon_point_add(p, x, y - 3);
5358                     }
5359
5360                   evas_object_color_set(p, r->color.r, r->color.g, r->color.b,
5361                                         r->color.a);
5362                   evas_object_raise(p);
5363                   _obj_rotate(wd, p);
5364                   evas_object_show(p);
5365                   r->x = x;
5366                   r->y = y;
5367                }
5368
5369              else r->inbound = EINA_FALSE;
5370           }
5371         else
5372           {
5373              _region_to_coord_convert(wd, n->pos.lon, n->pos.lat, size,
5374                                    &x, &y);
5375              if ((x >= px - ow) && (x <= (px + ow*2)) &&
5376                  (y >= py - oh) && (y <= (py + oh*2)))
5377                {
5378                   r->x = x - px;
5379                   r->y = y - py;
5380                   r->inbound = EINA_TRUE;
5381                }
5382              else r->inbound = EINA_FALSE;
5383           }
5384      }
5385    r->inbound = EINA_FALSE;
5386 }
5387
5388 static void
5389 _overlay_route_free(Overlay_Route* route)
5390 {
5391    EINA_SAFETY_ON_NULL_RETURN(route);
5392    Evas_Object *p;
5393    Path_Node *n;
5394
5395    EINA_LIST_FREE(route->paths, p) evas_object_del(p);
5396    EINA_LIST_FREE(route->nodes, n)
5397      {
5398         if (n->pos.address) eina_stringshare_del(n->pos.address);
5399         free(n);
5400      }
5401    free(route);
5402 }
5403
5404 static Overlay_Route *
5405 _overlay_route_new(Widget_Data *wd, const Elm_Map_Route *route)
5406 {
5407    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
5408    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
5409
5410    Eina_List *l;
5411    Path_Node *n;
5412
5413    Overlay_Route *ovl = ELM_NEW(Overlay_Route);
5414    ovl->wd = wd;
5415    ovl->inbound = EINA_FALSE;
5416    ovl->color.r = 255;
5417    ovl->color.g = 0;
5418    ovl->color.b = 0;
5419    ovl->color.a = 255;
5420
5421     EINA_LIST_FOREACH(route->nodes, l, n)
5422      {
5423         Evas_Object *path;
5424         Path_Node *node;
5425
5426         node = ELM_NEW(Path_Node);
5427         node->idx = n->idx;
5428         node->pos.lon = n->pos.lon;
5429         node->pos.lat = n->pos.lat;
5430         if (n->pos.address) node->pos.address = strdup(n->pos.address);
5431         ovl->nodes = eina_list_append(ovl->nodes, node);
5432
5433         path = evas_object_polygon_add(evas_object_evas_get(wd->obj));
5434         evas_object_smart_member_add(path, wd->pan_smart);
5435         ovl->paths = eina_list_append(ovl->paths, path);
5436      }
5437    return ovl;
5438 }
5439
5440 static void
5441 _overlay_grouping(Eina_List *members, Elm_Map_Overlay *overlay)
5442 {
5443    EINA_SAFETY_ON_NULL_RETURN(members);
5444    EINA_SAFETY_ON_NULL_RETURN(overlay);
5445    // Currently support only basic overlay type
5446    EINA_SAFETY_ON_FALSE_RETURN(overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT);
5447
5448    Eina_List *l;
5449    Elm_Map_Overlay *overlay_memb;
5450    Eina_List *club_members = NULL;
5451
5452    // Grouping only supports overlay default
5453    Overlay_Default *ovl = (Overlay_Default *)overlay->ovl;
5454    EINA_LIST_FOREACH(members, l, overlay_memb)
5455      {
5456         Overlay_Default *ovl_memb = overlay_memb->ovl;
5457         if ((overlay_memb->hide) ||
5458             (overlay_memb->zoom_min > overlay_memb->wd->zoom)) continue;
5459         if (overlay == overlay_memb || overlay_memb->grp_in) continue;
5460         if (ELM_RECTS_INTERSECT(ovl_memb->x, ovl_memb->y, ovl_memb->w,
5461                                 ovl_memb->h, ovl->x, ovl->y,
5462                                 ovl->w * OVERLAY_GROUPING_SCALE,
5463                                 ovl->h * OVERLAY_GROUPING_SCALE))
5464           {
5465              // Join group.
5466              overlay_memb->grp_boss = EINA_FALSE;
5467              overlay_memb->grp_in = EINA_TRUE;
5468              club_members = eina_list_append(club_members, overlay_memb);
5469              _overlay_group_update(overlay_memb->wd, overlay_memb->grp, NULL);
5470              _overlay_group_cb_del(overlay_memb->grp);
5471           }
5472      }
5473
5474    if (eina_list_count(club_members) >= 1)
5475      {
5476         // Mark as boss
5477         overlay->grp_boss = EINA_TRUE;
5478         overlay->grp_in = EINA_TRUE;
5479         club_members = eina_list_append(club_members, overlay);
5480         _overlay_group_update(overlay->wd, overlay->grp, club_members);
5481         _overlay_group_cb_del(overlay->grp);
5482         _overlay_group_cb_add(overlay->grp);
5483      }
5484 }
5485
5486 static void
5487 _overlay_display(Widget_Data *wd, Elm_Map_Overlay *overlay)
5488 {
5489    Eina_Bool hide = EINA_FALSE;
5490
5491    if ((overlay->grp_in) || (overlay->hide) || (overlay->zoom_min > wd->zoom))
5492       hide = EINA_TRUE;
5493    if ((overlay->grp->clas) && ((overlay->grp->clas->hide) ||
5494                                 (overlay->grp->clas->zoom_min > wd->zoom)))
5495       hide = EINA_TRUE;
5496
5497    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5498      {
5499         if (hide) _overlay_default_hide(overlay->ovl);
5500         else _overlay_default_show(wd, overlay->ovl);
5501      }
5502    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5503      {
5504         if (hide) _overlay_bubble_hide(overlay->ovl);
5505         else _overlay_bubble_show(overlay->ovl);
5506      }
5507    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
5508      {
5509        if (hide) _overlay_route_hide(overlay->ovl);
5510        else _overlay_route_show(overlay->ovl);
5511      }
5512 }
5513
5514 static void
5515 _overlay_place(Widget_Data *wd)
5516 {
5517    EINA_SAFETY_ON_NULL_RETURN(wd);
5518
5519    Eina_List *l, *ll;
5520    Elm_Map_Overlay *overlay, *grp;
5521
5522    if (eina_list_count(wd->overlays) == 0) return;
5523
5524    // Reset overlays coord & grp except class type
5525    EINA_LIST_FOREACH(wd->overlays, l, overlay)
5526      {
5527
5528         if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS) continue;
5529         if (overlay->paused) continue;
5530         if ((overlay->grp) && (overlay->grp->clas) &&
5531             (overlay->grp->clas->paused)) continue;
5532         if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5533           {
5534              Overlay_Class *ovl_grp = NULL;
5535              if (overlay->grp->clas) ovl_grp = overlay->grp->clas->ovl;
5536              _overlay_default_update(wd, overlay->ovl, NULL, NULL, ovl_grp,
5537                                      NULL, NULL);
5538            }
5539         else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
5540            _overlay_bubble_update(overlay->ovl);
5541         // Reset grp flags
5542         overlay->grp_in = EINA_FALSE;
5543         overlay->grp_boss = EINA_FALSE;
5544         _overlay_group_update(wd, overlay->grp, NULL);
5545      }
5546
5547    // Classify into group idol or follwer
5548    EINA_LIST_FOREACH(wd->overlays, l, grp)
5549      {
5550         Elm_Map_Overlay *idol;
5551         Overlay_Class *ovl;
5552
5553         if (grp->type != ELM_MAP_OVERLAY_TYPE_CLASS) continue;
5554         if ((grp->hide) || (grp->zoom_min > wd->zoom)) continue;
5555
5556         ovl = grp->ovl;
5557         if (ovl->zoom_max < wd->zoom) continue;
5558         EINA_LIST_FOREACH(ovl->members, ll, idol)
5559           {
5560              if (!idol->grp_in) _overlay_grouping(ovl->members, idol);
5561           }
5562      }
5563
5564    // Place overlays
5565    EINA_LIST_FOREACH(wd->overlays, l, overlay)
5566       if (overlay->type != ELM_MAP_OVERLAY_TYPE_CLASS)
5567          _overlay_display(wd, overlay);
5568
5569    // Place group overlays
5570    EINA_LIST_FOREACH(wd->overlays, l, overlay)
5571      {
5572         if (overlay->grp_boss) _overlay_default_show(wd, overlay->grp->ovl);
5573      }
5574 }
5575
5576 static Evas_Object *
5577 _overlay_obj_get(Elm_Map_Overlay *overlay)
5578 {
5579    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
5580    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
5581      {
5582         Overlay_Default *ovl = overlay->ovl;
5583         return ovl->layout;
5584      }
5585    else
5586      {
5587         ERR("Not supported overlay type: %d", overlay->type);
5588         return NULL;
5589      }
5590 }
5591
5592 static void
5593 _overlays_show(void *data)
5594 {
5595    EINA_SAFETY_ON_NULL_RETURN(data);
5596    Delayed_Data *dd = data;
5597
5598    int zoom;
5599    double max_lon, min_lon, max_lat, min_lat;
5600    Evas_Coord vw, vh;
5601
5602    _region_max_min_get(dd->overlays, &max_lon, &min_lon, &max_lat, &min_lat);
5603    dd->lon = (max_lon + min_lon) / 2;
5604    dd->lat = (max_lat + min_lat) / 2;
5605
5606    zoom = dd->wd->src_tile->zoom_min;
5607    _viewport_size_get(dd->wd, &vw, &vh);
5608    while (zoom <= dd->wd->src_tile->zoom_max)
5609      {
5610         Evas_Coord size, max_x, max_y, min_x, min_y;
5611         size = pow(2.0, zoom) * dd->wd->tsize;
5612         _region_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
5613         _region_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
5614         if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
5615         zoom++;
5616      }
5617    zoom--;
5618
5619    zoom_do(dd->wd, zoom);
5620    _region_show(dd);
5621    evas_object_smart_changed(dd->wd->pan_smart);
5622 }
5623
5624 static void
5625 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
5626 {
5627    Pan *sd = evas_object_smart_data_get(obj);
5628    EINA_SAFETY_ON_NULL_RETURN(sd);
5629    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
5630
5631    sd->wd->pan_x = x;
5632    sd->wd->pan_y = y;
5633    evas_object_smart_changed(obj);
5634 }
5635
5636 static void
5637 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
5638 {
5639    Pan *sd = evas_object_smart_data_get(obj);
5640    EINA_SAFETY_ON_NULL_RETURN(sd);
5641    if (x) *x = sd->wd->pan_x;
5642    if (y) *y = sd->wd->pan_y;
5643 }
5644
5645 static void
5646 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
5647 {
5648    Pan *sd = evas_object_smart_data_get(obj);
5649    EINA_SAFETY_ON_NULL_RETURN(sd);
5650    Evas_Coord ow, oh;
5651    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
5652    ow = sd->wd->size.w - ow;
5653    oh = sd->wd->size.h - oh;
5654    if (ow < 0) ow = 0;
5655    if (oh < 0) oh = 0;
5656    if (x) *x = ow;
5657    if (y) *y = oh;
5658 }
5659
5660 static void
5661 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
5662 {
5663    if (x) *x = 0;
5664    if (y) *y = 0;
5665 }
5666
5667 static void
5668 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
5669 {
5670    Pan *sd = evas_object_smart_data_get(obj);
5671    EINA_SAFETY_ON_NULL_RETURN(sd);
5672    if (w) *w = sd->wd->size.w;
5673    if (h) *h = sd->wd->size.h;
5674 }
5675
5676 static void
5677 _pan_add(Evas_Object *obj)
5678 {
5679    Pan *sd;
5680    Evas_Object_Smart_Clipped_Data *cd;
5681    parent_sc.add(obj);
5682    cd = evas_object_smart_data_get(obj);
5683    EINA_SAFETY_ON_NULL_RETURN(cd);
5684    sd = ELM_NEW(Pan);
5685    sd->__clipped_data = *cd;
5686    free(cd);
5687    evas_object_smart_data_set(obj, sd);
5688 }
5689
5690 static void
5691 _pan_resize(Evas_Object *obj, Evas_Coord w __UNUSED__, Evas_Coord h __UNUSED__)
5692 {
5693    Pan *sd = evas_object_smart_data_get(obj);
5694    EINA_SAFETY_ON_NULL_RETURN(sd);
5695
5696    _sizing_eval(sd->wd);
5697    elm_map_zoom_mode_set(sd->wd->obj, sd->wd->mode);
5698    evas_object_smart_changed(obj);
5699 }
5700
5701 static void
5702 _pan_calculate(Evas_Object *obj)
5703 {
5704    Pan *sd = evas_object_smart_data_get(obj);
5705    EINA_SAFETY_ON_NULL_RETURN(sd);
5706
5707    Evas_Coord w, h;
5708    evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &w, &h);
5709    if (w <= 0 || h <= 0) return;
5710
5711    _grid_place(sd->wd);
5712    _marker_place(sd->wd);
5713    _overlay_place(sd->wd);
5714    _track_place(sd->wd);
5715    _delayed_do(sd->wd);
5716 }
5717
5718 static void
5719 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
5720 {
5721    EINA_SAFETY_ON_NULL_RETURN(obj);
5722    evas_object_smart_changed(obj);
5723 }
5724
5725 static void
5726 _hold_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5727 {
5728    EINA_SAFETY_ON_NULL_RETURN(data);
5729    Widget_Data *wd = data;
5730    elm_smart_scroller_hold_set(wd->scr, 1);
5731 }
5732
5733 static void
5734 _hold_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5735 {
5736    EINA_SAFETY_ON_NULL_RETURN(data);
5737    Widget_Data *wd = data;
5738    elm_smart_scroller_hold_set(wd->scr, 0);
5739 }
5740
5741 static void
5742 _freeze_on(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5743 {
5744    EINA_SAFETY_ON_NULL_RETURN(data);
5745    Widget_Data *wd = data;
5746    elm_smart_scroller_freeze_set(wd->scr, 1);
5747 }
5748
5749 static void
5750 _freeze_off(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
5751 {
5752    EINA_SAFETY_ON_NULL_RETURN(data);
5753    Widget_Data *wd = data;
5754    elm_smart_scroller_freeze_set(wd->scr, 0);
5755 }
5756
5757 static void
5758 _elm_map_marker_remove(Elm_Map_Marker *marker)
5759 {
5760 #ifdef HAVE_ELEMENTARY_ECORE_CON
5761    EINA_SAFETY_ON_NULL_RETURN(marker);
5762    Widget_Data *wd = marker->wd;
5763    EINA_SAFETY_ON_NULL_RETURN(wd);
5764
5765    if ((marker->content) && (marker->clas->func.del))
5766       marker->clas->func.del(wd->obj, marker, marker->data, marker->content);
5767
5768    if (marker->bubble) _bubble_free(marker->bubble);
5769    if (marker->group) _marker_group_free(marker->group);
5770
5771    if (marker->group_clas)
5772       marker->group_clas->markers = eina_list_remove(marker->group_clas->markers, marker);
5773    wd->markers = eina_list_remove(wd->markers, marker);
5774
5775    evas_object_del(marker->obj);
5776    free(marker);
5777
5778    evas_object_smart_changed(wd->pan_smart);
5779 #else
5780    (void) marker;
5781 #endif
5782 }
5783
5784 static Eina_Bool
5785 cb_dump_name_attrs(void *data, const char *key, const char *value)
5786 {
5787    Name_Dump *dump = (Name_Dump*)data;
5788    if (!dump) return EINA_FALSE;
5789
5790    if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
5791    else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
5792
5793    return EINA_TRUE;
5794 }
5795
5796 static Eina_Bool
5797 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
5798 {
5799    Route_Dump *dump = data;
5800    if (!dump) return EINA_FALSE;
5801
5802    switch (type)
5803      {
5804       case EINA_SIMPLE_XML_OPEN:
5805       case EINA_SIMPLE_XML_OPEN_EMPTY:
5806         {
5807            const char *attrs;
5808
5809            attrs = eina_simple_xml_tag_attributes_find(value, length);
5810            if (!attrs)
5811              {
5812                 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
5813                 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
5814                 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
5815                 else dump->id = ROUTE_XML_NONE;
5816              }
5817          }
5818         break;
5819       case EINA_SIMPLE_XML_DATA:
5820         {
5821            char *buf = malloc(length);
5822            if (!buf) return EINA_FALSE;
5823            snprintf(buf, length, "%s", value);
5824            if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
5825            else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
5826            else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
5827            free(buf);
5828         }
5829         break;
5830       default:
5831         break;
5832      }
5833
5834    return EINA_TRUE;
5835 }
5836
5837 static Eina_Bool
5838 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
5839 {
5840    Name_Dump *dump = data;
5841    if (!dump) return EINA_FALSE;
5842
5843    switch (type)
5844      {
5845       case EINA_SIMPLE_XML_OPEN:
5846       case EINA_SIMPLE_XML_OPEN_EMPTY:
5847         {
5848            const char *attrs;
5849            attrs = eina_simple_xml_tag_attributes_find(value, length);
5850            if (attrs)
5851              {
5852                 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
5853                 else dump->id = NAME_XML_NONE;
5854
5855                 eina_simple_xml_attributes_parse
5856                   (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
5857              }
5858         }
5859         break;
5860       case EINA_SIMPLE_XML_DATA:
5861         {
5862            char *buf = malloc(length + 1);
5863            if (!buf) return EINA_FALSE;
5864            snprintf(buf, length + 1, "%s", value);
5865            if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
5866            free(buf);
5867         }
5868         break;
5869       default:
5870         break;
5871      }
5872
5873    return EINA_TRUE;
5874 }
5875
5876 static void
5877 _kml_parse(Elm_Map_Route *r)
5878 {
5879    EINA_SAFETY_ON_NULL_RETURN(r);
5880    EINA_SAFETY_ON_NULL_RETURN(r->fname);
5881
5882    FILE *f;
5883    char **str;
5884    unsigned int ele, idx;
5885    double lon, lat;
5886
5887    Route_Dump dump = {0, r->fname, 0.0, NULL, NULL};
5888
5889    f = fopen(r->fname, "rb");
5890    if (f)
5891      {
5892         long sz;
5893
5894         fseek(f, 0, SEEK_END);
5895         sz = ftell(f);
5896         if (sz > 0)
5897           {
5898              char *buf;
5899
5900              fseek(f, 0, SEEK_SET);
5901              buf = malloc(sz);
5902              if (buf)
5903                {
5904                   if (fread(buf, 1, sz, f))
5905                     {
5906                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump,
5907                                              &dump);
5908                        free(buf);
5909                     }
5910                }
5911           }
5912         fclose(f);
5913
5914         if (dump.distance) r->info.distance = dump.distance;
5915         if (dump.description)
5916           {
5917              eina_stringshare_replace(&r->info.waypoints, dump.description);
5918              str = eina_str_split_full(dump.description, "\n", 0, &ele);
5919              r->info.waypoint_count = ele;
5920              for (idx = 0; idx < ele; idx++)
5921                {
5922                   Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
5923                   if (wp)
5924                     {
5925                        wp->wd = r->wd;
5926                        wp->point = eina_stringshare_add(str[idx]);
5927                        DBG("%s", str[idx]);
5928                        r->waypoint = eina_list_append(r->waypoint, wp);
5929                     }
5930                }
5931              if (str && str[0])
5932                {
5933                   free(str[0]);
5934                   free(str);
5935                }
5936           }
5937         else WRN("description is not found !");
5938
5939         if (dump.coordinates)
5940           {
5941              eina_stringshare_replace(&r->info.nodes, dump.coordinates);
5942              str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
5943              r->info.node_count = ele;
5944              for (idx = 0; idx < ele; idx++)
5945                {
5946                   sscanf(str[idx], "%lf,%lf", &lon, &lat);
5947                   Path_Node *n = ELM_NEW(Path_Node);
5948                   if (n)
5949                     {
5950                        n->wd = r->wd;
5951                        n->pos.lon = lon;
5952                        n->pos.lat = lat;
5953                        n->idx = idx;
5954                        DBG("%lf:%lf", lon, lat);
5955                        n->pos.address = NULL;
5956                        r->nodes = eina_list_append(r->nodes, n);
5957                     }
5958                }
5959              if (str && str[0])
5960                {
5961                   free(str[0]);
5962                   free(str);
5963                }
5964           }
5965      }
5966 }
5967
5968 static void
5969 _name_parse(Elm_Map_Name *n)
5970 {
5971    EINA_SAFETY_ON_NULL_RETURN(n);
5972    EINA_SAFETY_ON_NULL_RETURN(n->fname);
5973
5974    FILE *f;
5975
5976    Name_Dump dump = {0, NULL, 0.0, 0.0};
5977
5978    f = fopen(n->fname, "rb");
5979    if (f)
5980      {
5981         long sz;
5982
5983         fseek(f, 0, SEEK_END);
5984         sz = ftell(f);
5985         if (sz > 0)
5986           {
5987              char *buf;
5988
5989              fseek(f, 0, SEEK_SET);
5990              buf = malloc(sz);
5991              if (buf)
5992                {
5993                   if (fread(buf, 1, sz, f))
5994                     {
5995                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
5996                        free(buf);
5997                     }
5998                }
5999           }
6000         fclose(f);
6001
6002         if (dump.address)
6003           {
6004              INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
6005              n->address = strdup(dump.address);
6006           }
6007         n->lon = dump.lon;
6008         n->lat = dump.lat;
6009      }
6010 }
6011
6012 Grid *_get_current_grid(Widget_Data *wd)
6013 {
6014    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6015    Eina_List *l;
6016    Grid *g = NULL, *ret = NULL;
6017    EINA_LIST_FOREACH(wd->grids, l, g)
6018      {
6019         if (wd->zoom == g->zoom)
6020           {
6021              ret = g;
6022              break;
6023           }
6024      }
6025    return ret;
6026 }
6027
6028 static void
6029 _route_cb(void *data, const char *file,  int status)
6030 {
6031    EINA_SAFETY_ON_NULL_RETURN(data);
6032    EINA_SAFETY_ON_NULL_RETURN(file);
6033
6034    Elm_Map_Route *route = data;
6035    Widget_Data *wd = route->wd;
6036    EINA_SAFETY_ON_NULL_RETURN(wd);
6037
6038    route->job = NULL;
6039    if (status == 200)
6040      {
6041         _kml_parse(route);
6042         INF("Route request success from (%lf, %lf) to (%lf, %lf)",
6043             route->flon, route->flat, route->tlon, route->tlat);
6044         if (route->cb) route->cb(route->data, wd->obj, route);
6045         evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
6046      }
6047    else
6048      {
6049         ERR("Route request failed: %d", status);
6050         if (route->cb) route->cb(route->data, wd->obj, NULL);
6051         evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED_FAIL, NULL);
6052      }
6053
6054    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
6055                            "elm,state,busy,stop", "elm");
6056 }
6057
6058 static void
6059 _name_cb(void *data, const char *file,  int status)
6060 {
6061    EINA_SAFETY_ON_NULL_RETURN(data);
6062    EINA_SAFETY_ON_NULL_RETURN(file);
6063
6064    Elm_Map_Name *name = data;
6065    Widget_Data *wd = name->wd;
6066    EINA_SAFETY_ON_NULL_RETURN(wd);
6067
6068    name->job = NULL;
6069    if (status == 200)
6070      {
6071         _name_parse(name);
6072         INF("Name request success address:%s, lon:%lf, lat:%lf",
6073             name->address, name->lon, name->lat);
6074         if (name->cb) name->cb(name->data, wd->obj, name);
6075         evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
6076      }
6077    else
6078      {
6079         ERR("Name request failed: %d", status);
6080         if (name->cb) name->cb(name->data, wd->obj, NULL);
6081         evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED_FAIL, NULL);
6082      }
6083    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
6084                            "elm,state,busy,stop", "elm");
6085 }
6086
6087
6088
6089 static Elm_Map_Name *
6090 _name_request(const Evas_Object *obj, int method, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
6091 {
6092    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
6093    Widget_Data *wd = elm_widget_data_get(obj);
6094    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
6095    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_name, NULL);
6096
6097
6098    char *url;
6099    char fname[PATH_MAX];
6100
6101    if (!ecore_file_exists(CACHE_NAME_ROOT)) ecore_file_mkpath(CACHE_NAME_ROOT);
6102
6103    url = wd->src_name->url_cb(wd->obj, method, address, lon, lat);
6104    if (!url)
6105      {
6106         ERR("Name URL is NULL");
6107         return NULL;
6108      }
6109
6110    Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
6111    name->wd = wd;
6112    snprintf(fname, sizeof(fname), CACHE_NAME_ROOT"/%d", rand());
6113    name->fname = strdup(fname);
6114    name->method = method;
6115    if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
6116    else if (method == ELM_MAP_NAME_METHOD_REVERSE)
6117      {
6118         name->lon = lon;
6119         name->lat = lat;
6120      }
6121    name->cb = name_cb;
6122    name->data = data;
6123
6124    if (!ecore_file_download_full(url, name->fname, _name_cb, NULL, name,
6125                                  &(name->job), wd->ua) || !(name->job))
6126      {
6127         ERR("Can't request Name from %s to %s", url, name->fname);
6128         if (name->address) free(name->address);
6129         free(name->fname);
6130         free(name);
6131         return NULL;
6132      }
6133    INF("Name requested from %s to %s", url, name->fname);
6134    free(url);
6135
6136    wd->names = eina_list_append(wd->names, name);
6137    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, name);
6138    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
6139                            "elm,state,busy,start", "elm");
6140    return name;
6141 }
6142
6143 static Evas_Event_Flags
6144 _pinch_zoom_start_cb(void *data, void *event_info __UNUSED__)
6145 {
6146    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EVAS_EVENT_FLAG_NONE);
6147    Widget_Data *wd = data;
6148
6149    wd->pinch_zoom = wd->zoom_detail;
6150    return EVAS_EVENT_FLAG_NONE;
6151 }
6152
6153 static Evas_Event_Flags
6154 _pinch_zoom_cb(void *data, void *event_info)
6155 {
6156    Widget_Data *wd = data;
6157    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
6158
6159    if (!wd->paused)
6160      {
6161         Elm_Gesture_Zoom_Info *ei = event_info;
6162         zoom_do(wd, wd->pinch_zoom + ei->zoom - 1);
6163      }
6164    return EVAS_EVENT_FLAG_NONE;
6165 }
6166
6167 static Evas_Event_Flags
6168 _pinch_rotate_cb(void *data, void *event_info)
6169 {
6170    Widget_Data *wd = data;
6171    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
6172
6173    if (!wd->paused)
6174      {
6175         int x, y, w, h;
6176         Elm_Gesture_Rotate_Info *ei = event_info;
6177         evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
6178
6179         wd->rotate.d = wd->rotate.a + ei->angle - ei->base_angle;
6180         wd->rotate.cx = x + ((double)w * 0.5);
6181         wd->rotate.cy = y + ((double)h * 0.5);
6182
6183         evas_object_smart_changed(wd->pan_smart);
6184      }
6185    return EVAS_EVENT_FLAG_NONE;
6186 }
6187
6188 static Evas_Event_Flags
6189 _pinch_rotate_end_cb(void *data, void *event_info __UNUSED__)
6190 {
6191    Widget_Data *wd = data;
6192    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EVAS_EVENT_FLAG_NONE);
6193
6194    wd->rotate.a = wd->rotate.d;
6195
6196    return EVAS_EVENT_FLAG_NONE;
6197 }
6198
6199 static Eina_Bool
6200 _source_tile_mod_cb(Eina_Module *m, void *data)
6201 {
6202    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
6203
6204    Widget_Data *wd = data;
6205    Source_Tile *s;
6206    Elm_Map_Module_Source_Name_Func name_cb;
6207    Elm_Map_Module_Tile_Zoom_Min_Func zoom_min;
6208    Elm_Map_Module_Tile_Zoom_Max_Func zoom_max;
6209    Elm_Map_Module_Tile_Url_Func url_cb;
6210    Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
6211    Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
6212    const char *file;
6213
6214    file = eina_module_file_get(m);
6215    if (!eina_module_load(m))
6216      {
6217         ERR("Could not load module \"%s\": %s", file,
6218             eina_error_msg_get(eina_error_get()));
6219         return EINA_FALSE;
6220      }
6221
6222    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
6223    zoom_min = eina_module_symbol_get(m, "map_module_tile_zoom_min_get");
6224    zoom_max = eina_module_symbol_get(m, "map_module_tile_zoom_max_get");
6225    url_cb = eina_module_symbol_get(m, "map_module_tile_url_get");
6226    geo_to_coord = eina_module_symbol_get(m, "map_module_tile_geo_to_coord");
6227    coord_to_geo = eina_module_symbol_get(m, "map_module_tile_coord_to_geo");
6228
6229    if ((!name_cb) || (!zoom_min) || (!zoom_max) || (!url_cb) ||
6230        (!geo_to_coord) || (!coord_to_geo))
6231      {
6232         WRN("Could not find map module functions from module \"%s\": %s",
6233             file, eina_error_msg_get(eina_error_get()));
6234         eina_module_unload(m);
6235         return EINA_FALSE;
6236      }
6237    s = ELM_NEW(Source_Tile);
6238    s->name = name_cb();
6239    s->zoom_min = zoom_min();
6240    s->zoom_max = zoom_max();
6241    s->url_cb = url_cb;
6242    s->geo_to_coord = geo_to_coord;
6243    s->coord_to_geo = coord_to_geo;
6244    wd->src_tiles = eina_list_append(wd->src_tiles, s);
6245
6246    return EINA_TRUE;
6247 }
6248
6249 static void
6250 _source_tile_load(Widget_Data *wd)
6251 {
6252    unsigned int idx;
6253    Eina_List *l;
6254    Source_Tile *s;
6255
6256    // Load from hard coded data
6257    for (idx = 0; idx < (sizeof(src_tiles) / sizeof(Source_Tile)); idx++)
6258      {
6259         s= ELM_NEW(Source_Tile);
6260         s->name = src_tiles[idx].name;
6261         s->zoom_min = src_tiles[idx].zoom_min;
6262         s->zoom_max = src_tiles[idx].zoom_max;
6263         s->url_cb = src_tiles[idx].url_cb;
6264         s->geo_to_coord = src_tiles[idx].geo_to_coord;
6265         s->coord_to_geo = src_tiles[idx].coord_to_geo;
6266         wd->src_tiles = eina_list_append(wd->src_tiles, s);
6267      }
6268
6269    // Load from modules
6270    wd->src_tile_mods = eina_module_list_get(wd->src_tile_mods, MODULES_PATH, 1,
6271                                             &_source_tile_mod_cb, wd);
6272
6273    // Set default source
6274    wd->src_tile = eina_list_nth(wd->src_tiles, 0);
6275
6276    // Make name strings
6277    idx = 0;
6278    wd->src_tile_names  = calloc((eina_list_count(wd->src_tiles) + 1),
6279                                 sizeof(char *));
6280    EINA_LIST_FOREACH(wd->src_tiles, l, s)
6281      {
6282         eina_stringshare_replace(&wd->src_tile_names[idx], s->name);
6283         INF("source : %s", wd->src_tile_names[idx]);
6284         idx++;
6285      }
6286 }
6287
6288 static void
6289 _source_tile_unload(Widget_Data *wd)
6290 {
6291    int idx = 0;
6292    Source_Tile *s;
6293
6294    for (idx = 0; wd->src_tile_names[idx]; idx++)
6295       eina_stringshare_del(wd->src_tile_names[idx]);
6296    EINA_LIST_FREE(wd->src_tiles, s) free(s);
6297    eina_module_list_free(wd->src_tile_mods);
6298 }
6299
6300 static void
6301 _source_tile_set(Widget_Data *wd, const char *source_name)
6302 {
6303    EINA_SAFETY_ON_NULL_RETURN(wd);
6304    EINA_SAFETY_ON_NULL_RETURN(source_name);
6305    Source_Tile *s;
6306    Eina_List *l;
6307
6308    if (wd->src_tile && !strcmp(wd->src_tile->name, source_name)) return;
6309
6310    EINA_LIST_FOREACH(wd->src_tiles, l, s)
6311      {
6312         if (!strcmp(s->name, source_name))
6313           {
6314              wd->src_tile = s;
6315              break;
6316           }
6317      }
6318    if (!wd->src_tile)
6319      {
6320         ERR("source name (%s) is not found", source_name);
6321         return;
6322      }
6323
6324    if (wd->src_tile->zoom_max < wd->zoom)
6325       wd->zoom = wd->src_tile->zoom_max;
6326    else if (wd->src_tile->zoom_min > wd->zoom)
6327       wd->zoom = wd->src_tile->zoom_min;
6328
6329    if (wd->src_tile->zoom_max < wd->zoom_max)
6330       wd->zoom_max = wd->src_tile->zoom_max;
6331    if (wd->src_tile->zoom_min > wd->zoom_min)
6332       wd->zoom_min = wd->src_tile->zoom_min;
6333
6334    _grid_all_clear(wd);
6335    _grid_all_create(wd);
6336    zoom_do(wd, wd->zoom);
6337 }
6338
6339 static Eina_Bool
6340 _source_route_mod_cb(Eina_Module *m, void *data)
6341 {
6342    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
6343
6344    Widget_Data *wd = data;
6345    Source_Route *s;
6346    Elm_Map_Module_Source_Name_Func name_cb;
6347    Elm_Map_Module_Route_Url_Func url_cb;
6348    const char *file;
6349
6350    file = eina_module_file_get(m);
6351    if (!eina_module_load(m))
6352      {
6353         ERR("Could not load module \"%s\": %s", file,
6354             eina_error_msg_get(eina_error_get()));
6355         return EINA_FALSE;
6356      }
6357
6358    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
6359    url_cb = eina_module_symbol_get(m, "map_module_route_url_get");
6360
6361    if ((!name_cb) || (!url_cb))
6362      {
6363         WRN("Could not find map module functions from module \"%s\": %s",
6364             file, eina_error_msg_get(eina_error_get()));
6365         eina_module_unload(m);
6366         return EINA_FALSE;
6367      }
6368    s = ELM_NEW(Source_Tile);
6369    s->name = name_cb();
6370    s->url_cb = url_cb;
6371    wd->src_routes = eina_list_append(wd->src_routes, s);
6372
6373    eina_module_unload(m);
6374    return EINA_TRUE;
6375 }
6376
6377 static void
6378 _source_route_load(Widget_Data *wd)
6379 {
6380    unsigned int idx;
6381    Eina_List *l;
6382    Source_Route *s;
6383
6384    // Load from hard coded data
6385    for (idx = 0; idx < (sizeof(src_routes) / sizeof(Source_Route)); idx++)
6386      {
6387         s= ELM_NEW(Source_Route);
6388         s->name = src_routes[idx].name;
6389         s->url_cb = src_routes[idx].url_cb;
6390         wd->src_routes = eina_list_append(wd->src_routes, s);
6391      }
6392
6393    // Load from modules
6394    wd->src_route_mods = eina_module_list_get(wd->src_route_mods, MODULES_PATH,
6395                                             1, &_source_route_mod_cb, wd);
6396
6397    // Set default source
6398    wd->src_route = eina_list_nth(wd->src_routes, 0);
6399
6400    // Make name strings
6401    idx = 0;
6402    wd->src_route_names  = calloc((eina_list_count(wd->src_routes) + 1),
6403                                    sizeof(char *));
6404    EINA_LIST_FOREACH(wd->src_routes, l, s)
6405      {
6406         eina_stringshare_replace(&wd->src_route_names[idx], s->name);
6407         INF("source : %s", wd->src_route_names[idx]);
6408         idx++;
6409      }
6410 }
6411
6412 static void
6413 _source_route_unload(Widget_Data *wd)
6414 {
6415    int idx = 0;
6416    Source_Route *s;
6417
6418    for (idx = 0; wd->src_route_names[idx]; idx++)
6419       eina_stringshare_del(wd->src_route_names[idx]);
6420    EINA_LIST_FREE(wd->src_routes, s) free(s);
6421    eina_module_list_free(wd->src_route_mods);
6422 }
6423
6424 static void
6425 _source_route_set(Widget_Data *wd, const char *source_name)
6426 {
6427    EINA_SAFETY_ON_NULL_RETURN(wd);
6428    EINA_SAFETY_ON_NULL_RETURN(source_name);
6429    Source_Route *s;
6430    Eina_List *l;
6431
6432    if (wd->src_route && !strcmp(wd->src_route->name, source_name)) return;
6433
6434    EINA_LIST_FOREACH(wd->src_routes, l, s)
6435      {
6436         if (!strcmp(s->name, source_name))
6437           {
6438              wd->src_route = s;
6439              break;
6440           }
6441      }
6442    if (!wd->src_route)
6443      {
6444         ERR("source name (%s) is not found", source_name);
6445         return;
6446      }
6447 }
6448
6449 static Eina_Bool
6450 _source_name_mod_cb(Eina_Module *m, void *data)
6451 {
6452    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
6453
6454    Widget_Data *wd = data;
6455    Source_Name *s;
6456    Elm_Map_Module_Source_Name_Func name_cb;
6457    Elm_Map_Module_Name_Url_Func url_cb;
6458    const char *file;
6459
6460    file = eina_module_file_get(m);
6461    if (!eina_module_load(m))
6462      {
6463         ERR("Could not load module \"%s\": %s", file,
6464             eina_error_msg_get(eina_error_get()));
6465         return EINA_FALSE;
6466      }
6467
6468    name_cb = eina_module_symbol_get(m, "map_module_source_name_get");
6469    url_cb = eina_module_symbol_get(m, "map_module_name_url_get");
6470
6471    if ((!name_cb) || (!url_cb))
6472      {
6473         WRN("Could not find map module functions from module \"%s\": %s",
6474             file, eina_error_msg_get(eina_error_get()));
6475         eina_module_unload(m);
6476         return EINA_FALSE;
6477      }
6478    s = ELM_NEW(Source_Tile);
6479    s->name = name_cb();
6480    s->url_cb = url_cb;
6481    wd->src_names = eina_list_append(wd->src_names, s);
6482
6483    eina_module_unload(m);
6484    return EINA_TRUE;
6485 }
6486
6487 static void
6488 _source_name_load(Widget_Data *wd)
6489 {
6490    unsigned int idx;
6491    Eina_List *l;
6492    Source_Name *s;
6493
6494    // Load from hard coded data
6495    for (idx = 0; idx < (sizeof(src_names) / sizeof(Source_Name)); idx++)
6496      {
6497         s= ELM_NEW(Source_Name);
6498         s->name = src_names[idx].name;
6499         s->url_cb = src_names[idx].url_cb;
6500         wd->src_names = eina_list_append(wd->src_names, s);
6501      }
6502
6503    // Load from modules
6504    wd->src_name_mods = eina_module_list_get(wd->src_name_mods, MODULES_PATH, 1,
6505                                             &_source_name_mod_cb, wd);
6506
6507    // Set default source
6508    wd->src_name = eina_list_nth(wd->src_names, 0);
6509
6510    // Make name strings
6511    idx = 0;
6512    wd->src_name_names  = calloc((eina_list_count(wd->src_names) + 1),
6513                                    sizeof(char *));
6514    EINA_LIST_FOREACH(wd->src_names, l, s)
6515      {
6516         eina_stringshare_replace(&wd->src_name_names[idx], s->name);
6517         INF("source : %s", wd->src_name_names[idx]);
6518         idx++;
6519      }
6520 }
6521
6522 static void
6523 _source_name_unload(Widget_Data *wd)
6524 {
6525    int idx = 0;
6526    Source_Name *s;
6527
6528    for (idx = 0; wd->src_name_names[idx]; idx++)
6529       eina_stringshare_del(wd->src_name_names[idx]);
6530    EINA_LIST_FREE(wd->src_names, s) free(s);
6531    eina_module_list_free(wd->src_name_mods);
6532 }
6533
6534 static void
6535 _source_name_set(Widget_Data *wd, const char *source_name)
6536 {
6537    EINA_SAFETY_ON_NULL_RETURN(wd);
6538    EINA_SAFETY_ON_NULL_RETURN(source_name);
6539
6540    Source_Name *s;
6541    Eina_List *l;
6542
6543    if (wd->src_name && !strcmp(wd->src_name->name, source_name)) return;
6544
6545    EINA_LIST_FOREACH(wd->src_names, l, s)
6546      {
6547         if (!strcmp(s->name, source_name))
6548           {
6549              wd->src_name = s;
6550              break;
6551           }
6552      }
6553    if (!wd->src_name)
6554      {
6555         ERR("source name (%s) is not found", source_name);
6556         return;
6557      }
6558 }
6559
6560 static void
6561 _source_all_load(Widget_Data *wd)
6562 {
6563    EINA_SAFETY_ON_NULL_RETURN(wd);
6564    _source_tile_load(wd);
6565    _source_route_load(wd);
6566    _source_name_load(wd);
6567 }
6568
6569 static void
6570 _source_all_unload(Widget_Data *wd)
6571 {
6572    EINA_SAFETY_ON_NULL_RETURN(wd);
6573    _source_tile_unload(wd);
6574    _source_route_unload(wd);
6575    _source_name_unload(wd);
6576 }
6577
6578 static void
6579 _zoom_mode_set(void *data)
6580 {
6581    EINA_SAFETY_ON_NULL_RETURN(data);
6582    Delayed_Data *dd = data;
6583
6584    dd->wd->mode = dd->mode;
6585    if (dd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
6586      {
6587         Evas_Coord w, h;
6588         Evas_Coord vw, vh;
6589
6590         double zoom;
6591         double diff;
6592
6593         w = dd->wd->size.w;
6594         h = dd->wd->size.h;
6595         zoom = dd->wd->zoom_detail;
6596         _viewport_size_get(dd->wd, &vw, &vh);
6597
6598         if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
6599           {
6600              if ((w < vw) && (h < vh))
6601                {
6602                   diff = 0.01;
6603                   while ((w < vw) && (h < vh))
6604                   {
6605                      zoom += diff;
6606                      w = pow(2.0, zoom) * dd->wd->tsize;
6607                      h = pow(2.0, zoom) * dd->wd->tsize;
6608                   }
6609                }
6610              else
6611                {
6612                   diff = -0.01;
6613                   while ((w > vw) || (h > vh))
6614                   {
6615                      zoom += diff;
6616                      w = pow(2.0, zoom) * dd->wd->tsize;
6617                      h = pow(2.0, zoom) * dd->wd->tsize;
6618                   }
6619                }
6620
6621           }
6622         else if (dd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
6623           {
6624              if ((w < vw) || (h < vh))
6625                {
6626                   diff = 0.01;
6627                   while ((w < vw) || (h < vh))
6628                   {
6629                      zoom += diff;
6630                      w = pow(2.0, zoom) * dd->wd->tsize;
6631                      h = pow(2.0, zoom) * dd->wd->tsize;
6632                   }
6633                }
6634              else
6635                {
6636                   diff = -0.01;
6637                   while ((w > vw) && (h > vh))
6638                   {
6639                      zoom += diff;
6640                      w = pow(2.0, zoom) * dd->wd->tsize;
6641                      h = pow(2.0, zoom) * dd->wd->tsize;
6642                   }
6643                }
6644           }
6645        zoom_with_animation(dd->wd, zoom, 10);
6646      }
6647 }
6648
6649 static void
6650 _zoom_set(void *data)
6651 {
6652    EINA_SAFETY_ON_NULL_RETURN(data);
6653    Delayed_Data *dd = data;
6654
6655    if (dd->wd->paused) zoom_do(dd->wd, dd->zoom);
6656    else zoom_with_animation(dd->wd, dd->zoom, 10);
6657    evas_object_smart_changed(dd->wd->pan_smart);
6658 }
6659
6660 static void
6661 _region_bring_in(void *data)
6662 {
6663    EINA_SAFETY_ON_NULL_RETURN(data);
6664    Delayed_Data *dd = data;
6665    int x, y, w, h;
6666
6667    _region_to_coord_convert(dd->wd, dd->lon, dd->lat, dd->wd->size.w, &x, &y);
6668    _viewport_size_get(dd->wd, &w, &h);
6669    x = x - (w / 2);
6670    y = y - (h / 2);
6671    elm_smart_scroller_region_bring_in(dd->wd->scr, x, y, w, h);
6672    evas_object_smart_changed(dd->wd->pan_smart);
6673 }
6674
6675 static void
6676 _marker_list_show(void *data)
6677 {
6678    EINA_SAFETY_ON_NULL_RETURN(data);
6679    Delayed_Data *dd = data;
6680    int zoom;
6681    double max_lon = -180, min_lon = 180;
6682    double max_lat = -90, min_lat = 90;
6683    Evas_Coord vw, vh;
6684    Elm_Map_Marker *marker;
6685
6686    EINA_LIST_FREE(dd->markers, marker)
6687      {
6688         if (marker->longitude > max_lon) max_lon = marker->longitude;
6689         if (marker->longitude < min_lon) min_lon = marker->longitude;
6690         if (marker->latitude > max_lat) max_lat = marker->latitude;
6691         if (marker->latitude < min_lat) min_lat = marker->latitude;
6692      }
6693    dd->lon = (max_lon + min_lon) / 2;
6694    dd->lat = (max_lat + min_lat) / 2;
6695
6696    zoom = dd->wd->src_tile->zoom_min;
6697    _viewport_size_get(dd->wd, &vw, &vh);
6698    while (zoom <= dd->wd->src_tile->zoom_max)
6699      {
6700         Evas_Coord size, max_x, max_y, min_x, min_y;
6701         size = pow(2.0, zoom) * dd->wd->tsize;
6702         _region_to_coord_convert(dd->wd, min_lon, max_lat, size, &min_x, &max_y);
6703         _region_to_coord_convert(dd->wd, max_lon, min_lat, size, &max_x, &min_y);
6704         if ((max_x - min_x) > vw || (max_y - min_y) > vh) break;
6705         zoom++;
6706      }
6707    zoom--;
6708
6709    zoom_do(dd->wd, zoom);
6710    _region_show(dd);
6711    evas_object_smart_changed(dd->wd->pan_smart);
6712 }
6713
6714 static char *
6715 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
6716 {
6717    char buf[PATH_MAX];
6718    // ((x+y+zoom)%3)+'a' is requesting map images from distributed tile servers (eg., a, b, c)
6719    snprintf(buf, sizeof(buf), "http://%c.tile.openstreetmap.org/%d/%d/%d.png",
6720             ((x + y + zoom) % 3) + 'a', zoom, x, y);
6721    return strdup(buf);
6722 }
6723
6724 static char *
6725 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
6726 {
6727    char buf[PATH_MAX];
6728    snprintf(buf, sizeof(buf),
6729             "http://%c.tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
6730             ((x + y + zoom) % 3) + 'a', zoom, x, y);
6731    return strdup(buf);
6732 }
6733
6734 static char *
6735 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
6736 {
6737    char buf[PATH_MAX];
6738    snprintf(buf, sizeof(buf),
6739             "http://%c.tile.opencyclemap.org/cycle/%d/%d/%d.png",
6740             (( x + y + zoom) % 3) + 'a', zoom, x, y);
6741    return strdup(buf);
6742 }
6743
6744 static char *
6745 _mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
6746 {
6747    char buf[PATH_MAX];
6748    snprintf(buf, sizeof(buf),
6749             "http://otile%d.mqcdn.com/tiles/1.0.0/osm/%d/%d/%d.png",
6750             ((x + y + zoom) % 4) + 1, zoom, x, y);
6751    return strdup(buf);
6752 }
6753
6754 static char *
6755 _mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
6756 {
6757    char buf[PATH_MAX];
6758    snprintf(buf, sizeof(buf), "http://oatile%d.mqcdn.com/naip/%d/%d/%d.png",
6759            ((x + y + zoom) % 4) + 1, zoom, x, y);
6760    return strdup(buf);
6761 }
6762
6763 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, const char *type_name, int method, double flon, double flat, double tlon, double tlat)
6764 {
6765    char buf[PATH_MAX];
6766    snprintf(buf, sizeof(buf),
6767             "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
6768             ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
6769
6770    return strdup(buf);
6771 }
6772
6773 // TODO: fix monav api
6774 /*
6775 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
6776 {
6777    char buf[PATH_MAX];
6778    snprintf(buf, sizeof(buf),
6779             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
6780             ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
6781
6782    return strdup(buf);
6783 }
6784 */
6785
6786 // TODO: fix ors api
6787 /*
6788 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
6789 {
6790    char buf[PATH_MAX];
6791    snprintf(buf, sizeof(buf),
6792             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
6793             ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
6794
6795    return strdup(buf);
6796 }
6797 */
6798
6799 static char *
6800 _nominatim_url_cb(Evas_Object *obj, int method, const char *name, double lon, double lat)
6801 {
6802    ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
6803    Widget_Data *wd = elm_widget_data_get(obj);
6804    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, strdup(""));
6805
6806    char **str;
6807    unsigned int ele, idx;
6808    char search_url[PATH_MAX];
6809    char buf[PATH_MAX];
6810
6811    if (method == ELM_MAP_NAME_METHOD_SEARCH)
6812      {
6813         search_url[0] = '\0';
6814         str = eina_str_split_full(name, " ", 0, &ele);
6815         for (idx = 0; idx < ele; idx++)
6816           {
6817              eina_strlcat(search_url, str[idx], sizeof(search_url));
6818              if (!(idx == (ele-1)))
6819                 eina_strlcat(search_url, "+", sizeof(search_url));
6820           }
6821         snprintf(buf, sizeof(buf),
6822                  "%s/search?q=%s&format=xml&polygon=0&addressdetails=0",
6823                  NAME_NOMINATIM_URL, search_url);
6824
6825         if (str && str[0])
6826           {
6827              free(str[0]);
6828              free(str);
6829           }
6830      }
6831    else if (method == ELM_MAP_NAME_METHOD_REVERSE)
6832       snprintf(buf, sizeof(buf),
6833                "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0",
6834                NAME_NOMINATIM_URL, lat, lon, (int)wd->zoom);
6835    else strcpy(buf, "");
6836
6837    return strdup(buf);
6838 }
6839
6840 static void
6841 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
6842 {
6843    ELM_CHECK_WIDTYPE(obj, widtype);
6844    Widget_Data *wd = elm_widget_data_get(obj);
6845    EINA_SAFETY_ON_NULL_RETURN(wd);
6846
6847    if (elm_widget_focus_get(obj))
6848      {
6849         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
6850         evas_object_focus_set(wd->obj, EINA_TRUE);
6851      }
6852    else
6853      {
6854         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
6855         evas_object_focus_set(wd->obj, EINA_FALSE);
6856      }
6857 }
6858
6859 static void
6860 _del_hook(Evas_Object *obj)
6861 {
6862    ELM_CHECK_WIDTYPE(obj, widtype);
6863    Widget_Data *wd = elm_widget_data_get(obj);
6864    EINA_SAFETY_ON_NULL_RETURN(wd);
6865
6866    if (wd->map) evas_map_free(wd->map);
6867    free(wd);
6868 }
6869
6870 static void
6871 _del_pre_hook(Evas_Object *obj)
6872 {
6873    ELM_CHECK_WIDTYPE(obj, widtype);
6874    Widget_Data *wd = elm_widget_data_get(obj);
6875    EINA_SAFETY_ON_NULL_RETURN(wd);
6876
6877    Eina_List *l, *ll;
6878    Elm_Map_Route *r;
6879    Elm_Map_Name *na;
6880    Evas_Object *track;
6881    Elm_Map_Marker *marker;
6882    Elm_Map_Group_Class *group_clas;
6883    Elm_Map_Marker_Class *clas;
6884    Elm_Map_Overlay *overlay;
6885    Delayed_Data *dd;
6886
6887    EINA_LIST_FOREACH_SAFE(wd->routes, l, ll, r) elm_map_route_del(r);
6888    eina_list_free(wd->routes);
6889
6890    EINA_LIST_FOREACH_SAFE(wd->names, l, ll, na) elm_map_name_del(na);
6891    eina_list_free(wd->names);
6892
6893    EINA_LIST_FOREACH_SAFE(wd->overlays, l, ll, overlay)
6894       elm_map_overlay_del(overlay);
6895    eina_list_free(wd->overlays);
6896
6897    EINA_LIST_FREE(wd->track, track) evas_object_del(track);
6898
6899    EINA_LIST_FOREACH_SAFE(wd->markers, l, ll, marker)
6900       _elm_map_marker_remove(marker);
6901    eina_list_free(wd->markers);
6902
6903    EINA_LIST_FREE(wd->group_classes, group_clas)
6904      {
6905         eina_list_free(group_clas->markers);
6906         if (group_clas->style) eina_stringshare_del(group_clas->style);
6907         free(group_clas);
6908      }
6909    EINA_LIST_FREE(wd->marker_classes, clas)
6910      {
6911         if (clas->style) eina_stringshare_del(clas->style);
6912         free(clas);
6913      }
6914
6915    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
6916    if (wd->long_timer) ecore_timer_del(wd->long_timer);
6917
6918    if (wd->delayed_jobs) EINA_LIST_FREE(wd->delayed_jobs, dd) free(dd);
6919
6920    if (wd->user_agent) eina_stringshare_del(wd->user_agent);
6921    if (wd->ua) eina_hash_free(wd->ua);
6922
6923    if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
6924    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
6925
6926    _grid_all_clear(wd);
6927    // Removal of download list should be after grid clear.
6928    if (wd->download_idler) ecore_idler_del(wd->download_idler);
6929    eina_list_free(wd->download_list);
6930
6931    _source_all_unload(wd);
6932
6933    if (!ecore_file_recursive_rm(CACHE_ROOT))
6934       ERR("Deletion of %s failed", CACHE_ROOT);
6935 }
6936
6937 static void
6938 _theme_hook(Evas_Object *obj)
6939 {
6940    ELM_CHECK_WIDTYPE(obj, widtype);
6941    Widget_Data *wd = elm_widget_data_get(obj);
6942    EINA_SAFETY_ON_NULL_RETURN(wd);
6943
6944    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
6945    _sizing_eval(wd);
6946 }
6947
6948 static Eina_Bool
6949 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
6950 {
6951    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
6952    Widget_Data *wd = elm_widget_data_get(obj);
6953    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
6954
6955    Evas_Coord x, y;
6956    Evas_Coord vh;
6957    Evas_Coord step_x, step_y, page_x, page_y;
6958
6959    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
6960    Evas_Event_Key_Down *ev = event_info;
6961    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
6962
6963    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
6964    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
6965    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
6966    _viewport_size_get(wd, NULL, &vh);
6967
6968    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
6969      {
6970         x -= step_x;
6971      }
6972    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
6973      {
6974         x += step_x;
6975      }
6976    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
6977      {
6978         y -= step_y;
6979      }
6980    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
6981      {
6982         y += step_y;
6983      }
6984    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
6985      {
6986         if (page_y < 0)
6987           y -= -(page_y * vh) / 100;
6988         else
6989           y -= page_y;
6990      }
6991    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
6992      {
6993         if (page_y < 0)
6994           y += -(page_y * vh) / 100;
6995         else
6996           y += page_y;
6997      }
6998    else if (!strcmp(ev->keyname, "KP_Add"))
6999      {
7000         zoom_with_animation(wd, wd->zoom + 1, 10);
7001         return EINA_TRUE;
7002      }
7003    else if (!strcmp(ev->keyname, "KP_Subtract"))
7004      {
7005         zoom_with_animation(wd, wd->zoom - 1, 10);
7006         return EINA_TRUE;
7007      }
7008    else return EINA_FALSE;
7009
7010    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
7011    elm_smart_scroller_child_pos_set(wd->scr, x, y);
7012
7013    return EINA_TRUE;
7014 }
7015 >>>>>>> remotes/origin/upstream
7016 #endif
7017
7018 EAPI Evas_Object *
7019 elm_map_add(Evas_Object *parent)
7020 {
7021 #ifdef HAVE_ELEMENTARY_ECORE_CON
7022 <<<<<<< HEAD
7023    Evas *e;
7024    Widget_Data *wd;
7025    Evas_Coord minw, minh;
7026    Evas_Object *obj;
7027    static Evas_Smart *smart = NULL;
7028    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
7029
7030    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
7031
7032    ELM_SET_WIDTYPE(widtype, "map");
7033    elm_widget_type_set(obj, "map");
7034    elm_widget_sub_object_add(parent, obj);
7035    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
7036    elm_widget_data_set(obj, wd);
7037    elm_widget_del_hook_set(obj, _del_hook);
7038    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
7039    elm_widget_theme_hook_set(obj, _theme_hook);
7040    elm_widget_can_focus_set(obj, EINA_TRUE);
7041    elm_widget_event_hook_set(obj, _event_hook);
7042
7043    wd->scr = elm_smart_scroller_add(e);
7044    elm_smart_scroller_widget_set(wd->scr, obj);
7045    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
7046    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
7047    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
7048    elm_widget_resize_object_set(obj, wd->scr);
7049    elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
7050
7051    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
7052    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
7053    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
7054    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
7055    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
7056
7057    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
7058
7059    wd->zoom_min = 0xFF;
7060    wd->zoom_max = 0X00;
7061    source_init(obj);
7062
7063    wd->obj = obj;
7064    wd->map = evas_map_new(4);
7065    if (!wd->map) return NULL;
7066
7067    wd->markers_max_num = 30;
7068    wd->pinch.level = 1.0;
7069    wd->pinch.diff = 1.0;
7070    wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
7071
7072    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
7073    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
7074    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
7075    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
7076
7077    if (!smart)
7078      {
7079         static Evas_Smart_Class sc;
7080
7081         evas_object_smart_clipped_smart_set(&_pan_sc);
7082         sc = _pan_sc;
7083         sc.name = "elm_map_pan";
7084         sc.version = EVAS_SMART_CLASS_VERSION;
7085         sc.add = _pan_add;
7086         sc.del = _pan_del;
7087         sc.resize = _pan_resize;
7088         sc.move = _pan_move;
7089         sc.calculate = _pan_calculate;
7090         smart = evas_smart_class_new(&sc);
7091      }
7092    if (smart)
7093      {
7094         wd->pan_smart = evas_object_smart_add(e, smart);
7095         wd->pan = evas_object_smart_data_get(wd->pan_smart);
7096         wd->pan->wd = wd;
7097      }
7098
7099    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
7100                                      _pan_set, _pan_get, _pan_max_get,
7101                                      _pan_min_get, _pan_child_size_get);
7102
7103    wd->rect = evas_object_rectangle_add(e);
7104    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
7105                                   _rect_resize_cb, obj);
7106    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
7107                                   _mouse_down, obj);
7108    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
7109                                   _mouse_up, obj);
7110    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
7111                                   _mouse_wheel_cb, obj);
7112
7113    evas_object_smart_member_add(wd->rect, wd->pan_smart);
7114    elm_widget_sub_object_add(obj, wd->rect);
7115    evas_object_show(wd->rect);
7116    evas_object_color_set(wd->rect, 0, 0, 0, 0);
7117
7118    wd->ges = elm_gesture_layer_add(obj);
7119    if (!wd->ges) ERR("elm_gesture_layer_add() failed");
7120    elm_gesture_layer_attach(wd->ges, wd->rect);
7121    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
7122                             zoom_start_cb, wd);
7123    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
7124                             zoom_cb, wd);
7125    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END,
7126                             zoom_end_cb, wd);
7127    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT,
7128                             zoom_end_cb, wd);
7129    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE,
7130                             rotate_cb, wd);
7131    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END,
7132                             rotate_end_cb, wd);
7133    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT,
7134                             rotate_end_cb, wd);
7135
7136    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
7137    wd->id = ((int)getpid() << 16) | idnum;
7138    idnum++;
7139
7140    wd->tsize = 256;
7141    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
7142                              &minw, &minh);
7143    evas_object_size_hint_min_set(obj, minw, minh);
7144
7145    wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
7146    evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
7147
7148    grid_create_all(obj);
7149
7150    wd->paused = EINA_TRUE;
7151    elm_map_zoom_set(obj, 0);
7152    wd->paused = EINA_FALSE;
7153    _sizing_eval(obj);
7154
7155    // TODO: convert Elementary to subclassing of Evas_Smart_Class
7156    // TODO: and save some bytes, making descriptions per-class and not instance!
7157    evas_object_smart_callbacks_descriptions_set(obj, _signals);
7158
7159    if (!ecore_file_download_protocol_available("http://"))
7160      {
7161         ERR("Ecore must be built with curl support for the map widget!");
7162      }
7163
7164    return obj;
7165 #else
7166    (void) parent;
7167    return NULL;
7168 =======
7169    Evas *e;
7170    Widget_Data *wd;
7171    Evas_Object *obj;
7172    Evas_Coord minw, minh;
7173
7174    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
7175    ELM_SET_WIDTYPE(widtype, "map");
7176    elm_widget_type_set(obj, "map");
7177    elm_widget_sub_object_add(parent, obj);
7178    elm_widget_data_set(obj, wd);
7179    elm_widget_can_focus_set(obj, EINA_TRUE);
7180    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
7181    elm_widget_del_hook_set(obj, _del_hook);
7182    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
7183    elm_widget_theme_hook_set(obj, _theme_hook);
7184    elm_widget_event_hook_set(obj, _event_hook);
7185    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, wd);
7186    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, wd);
7187    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, wd);
7188    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, wd);
7189    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
7190                                   _mouse_down, wd);
7191    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
7192                                   _mouse_up, wd);
7193    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL,
7194                                   _mouse_wheel_cb,wd);
7195    wd->obj = obj;
7196
7197    wd->scr = elm_smart_scroller_add(e);
7198    elm_widget_sub_object_add(obj, wd->scr);
7199    elm_smart_scroller_widget_set(wd->scr, obj);
7200    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
7201    elm_widget_resize_object_set(obj, wd->scr);
7202    elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
7203    elm_smart_scroller_bounce_allow_set(wd->scr,
7204                                        _elm_config->thumbscroll_bounce_enable,
7205                                        _elm_config->thumbscroll_bounce_enable);
7206    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
7207                                   _changed_size_hints, wd);
7208    evas_object_smart_callback_add(wd->scr, "scroll", _scr, wd);
7209    evas_object_smart_callback_add(wd->scr, "drag", _scr, wd);
7210    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, wd);
7211    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, wd);
7212
7213    if (!smart)
7214      {
7215         evas_object_smart_clipped_smart_set(&parent_sc);
7216         sc = parent_sc;
7217         sc.name = "elm_map_pan";
7218         sc.version = EVAS_SMART_CLASS_VERSION;
7219         sc.add = _pan_add;
7220         sc.resize = _pan_resize;
7221         sc.move = _pan_move;
7222         sc.calculate = _pan_calculate;
7223         smart = evas_smart_class_new(&sc);
7224      }
7225    if (smart)
7226      {
7227         Pan *pan;
7228         wd->pan_smart = evas_object_smart_add(e, smart);
7229         pan = evas_object_smart_data_get(wd->pan_smart);
7230         pan->wd = wd;
7231      }
7232    elm_widget_sub_object_add(obj, wd->pan_smart);
7233
7234    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
7235                                      _pan_set, _pan_get, _pan_max_get,
7236                                      _pan_min_get, _pan_child_size_get);
7237    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
7238                              &minw, &minh);
7239    evas_object_size_hint_min_set(obj, minw, minh);
7240
7241    wd->ges = elm_gesture_layer_add(obj);
7242    if (!wd->ges) ERR("elm_gesture_layer_add() failed");
7243    elm_gesture_layer_attach(wd->ges, obj);
7244    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
7245                             _pinch_zoom_start_cb, wd);
7246    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
7247                             _pinch_zoom_cb, wd);
7248    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE,
7249                             _pinch_rotate_cb, wd);
7250    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END,
7251                             _pinch_rotate_end_cb, wd);
7252    elm_gesture_layer_cb_set(wd->ges, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT,
7253                             _pinch_rotate_end_cb, wd);
7254
7255    wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
7256    elm_widget_sub_object_add(obj, wd->sep_maps_markers);
7257    evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
7258
7259    wd->map = evas_map_new(EVAS_MAP_POINT);
7260
7261    _source_all_load(wd);
7262    wd->zoom_min = wd->src_tile->zoom_min;
7263    wd->zoom_max = wd->src_tile->zoom_max;
7264    // FIXME: Tile Provider is better to provide tile size!
7265    wd->tsize = DEFAULT_TILE_SIZE;
7266
7267    srand(time(NULL));
7268
7269    wd->id = ((int)getpid() << 16) | idnum;
7270    idnum++;
7271    _grid_all_create(wd);
7272
7273    zoom_do(wd, 0);
7274
7275    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
7276    wd->markers_max_num = MARER_MAX_NUMBER;
7277
7278    // TODO: convert Elementary to subclassing of Evas_Smart_Class
7279    // TODO: and save some bytes, making descriptions per-class and not instance!
7280    evas_object_smart_callbacks_descriptions_set(obj, _signals);
7281
7282    if (!ecore_file_download_protocol_available("http://"))
7283       ERR("Ecore must be built with curl support for the map widget!");
7284
7285    return obj;
7286 #else
7287    (void) parent;
7288    return NULL;
7289 #endif
7290 }
7291
7292 EAPI void
7293 elm_map_zoom_set(Evas_Object *obj, int zoom)
7294 {
7295 #ifdef HAVE_ELEMENTARY_ECORE_CON
7296    ELM_CHECK_WIDTYPE(obj, widtype);
7297    Widget_Data *wd = elm_widget_data_get(obj);
7298    EINA_SAFETY_ON_NULL_RETURN(wd);
7299    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
7300
7301    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL) return;
7302    if (zoom < 0) zoom = 0;
7303    if (wd->zoom == zoom) return;
7304    if (zoom > wd->src_tile->zoom_max) zoom = wd->src_tile->zoom_max;
7305    if (zoom < wd->src_tile->zoom_min) zoom = wd->src_tile->zoom_min;
7306
7307    Delayed_Data *data = ELM_NEW(Delayed_Data);
7308    data->func = _zoom_set;
7309    data->wd = wd;
7310    data->zoom = zoom;
7311    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
7312    evas_object_smart_changed(data->wd->pan_smart);
7313 #else
7314    (void) obj;
7315    (void) zoom;
7316 #endif
7317 }
7318
7319 EAPI int
7320 elm_map_zoom_get(const Evas_Object *obj)
7321 {
7322 #ifdef HAVE_ELEMENTARY_ECORE_CON
7323    ELM_CHECK_WIDTYPE(obj, widtype) 0;
7324    Widget_Data *wd = elm_widget_data_get(obj);
7325
7326    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, 0);
7327    return wd->zoom;
7328 #else
7329    (void) obj;
7330    return 0;
7331 #endif
7332 }
7333
7334 EAPI void
7335 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
7336 {
7337 #ifdef HAVE_ELEMENTARY_ECORE_CON
7338    ELM_CHECK_WIDTYPE(obj, widtype);
7339    Widget_Data *wd = elm_widget_data_get(obj);
7340    EINA_SAFETY_ON_NULL_RETURN(wd);
7341
7342    if ((mode == ELM_MAP_ZOOM_MODE_MANUAL) && (wd->mode == !!mode)) return;
7343
7344    Delayed_Data *data = ELM_NEW(Delayed_Data);
7345    data->mode = mode;
7346    data->func = _zoom_mode_set;
7347    data->wd = wd;
7348    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
7349    evas_object_smart_changed(data->wd->pan_smart);
7350 #else
7351    (void) obj;
7352    (void) mode;
7353 #endif
7354 }
7355
7356 EAPI Elm_Map_Zoom_Mode
7357 elm_map_zoom_mode_get(const Evas_Object *obj)
7358 {
7359 #ifdef HAVE_ELEMENTARY_ECORE_CON
7360    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
7361    Widget_Data *wd = elm_widget_data_get(obj);
7362    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, ELM_MAP_ZOOM_MODE_MANUAL);
7363
7364    return wd->mode;
7365 #else
7366    (void) obj;
7367    return ELM_MAP_ZOOM_MODE_MANUAL;
7368 #endif
7369 }
7370
7371 EAPI void
7372 elm_map_zoom_max_set(Evas_Object *obj, int zoom)
7373 {
7374 #ifdef HAVE_ELEMENTARY_ECORE_CON
7375    ELM_CHECK_WIDTYPE(obj, widtype);
7376    Widget_Data *wd = elm_widget_data_get(obj);
7377    EINA_SAFETY_ON_NULL_RETURN(wd);
7378    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
7379
7380    if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
7381       return;
7382    wd->zoom_max = zoom;
7383 #else
7384    (void) obj;
7385    (void) zoom;
7386 #endif
7387 }
7388
7389 EAPI int
7390 elm_map_zoom_max_get(const Evas_Object *obj)
7391 {
7392 #ifdef HAVE_ELEMENTARY_ECORE_CON
7393    ELM_CHECK_WIDTYPE(obj, widtype) 18;
7394    Widget_Data *wd = elm_widget_data_get(obj);
7395    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
7396    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
7397
7398    return wd->zoom_max;
7399 #else
7400    (void) obj;
7401    return 18;
7402 #endif
7403 }
7404
7405 EAPI void
7406 elm_map_zoom_min_set(Evas_Object *obj, int zoom)
7407 {
7408 #ifdef HAVE_ELEMENTARY_ECORE_CON
7409    ELM_CHECK_WIDTYPE(obj, widtype);
7410    Widget_Data *wd = elm_widget_data_get(obj);
7411    EINA_SAFETY_ON_NULL_RETURN(wd);
7412    EINA_SAFETY_ON_NULL_RETURN(wd->src_tile);
7413
7414    if ((zoom > wd->src_tile->zoom_max) || (zoom < wd->src_tile->zoom_min))
7415       return;
7416    wd->zoom_min = zoom;
7417 #else
7418    (void) obj;
7419    (void) zoom;
7420 #endif
7421 }
7422
7423 EAPI int
7424 elm_map_zoom_min_get(const Evas_Object *obj)
7425 {
7426 #ifdef HAVE_ELEMENTARY_ECORE_CON
7427    ELM_CHECK_WIDTYPE(obj, widtype) 0;
7428    Widget_Data *wd = elm_widget_data_get(obj);
7429    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, -1);
7430    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, -1);
7431
7432    return wd->zoom_min;
7433 #else
7434    (void) obj;
7435    return 0;
7436 #endif
7437 }
7438
7439
7440 EAPI void
7441 elm_map_region_bring_in(Evas_Object *obj, double lon, double lat)
7442 {
7443 #ifdef HAVE_ELEMENTARY_ECORE_CON
7444    ELM_CHECK_WIDTYPE(obj, widtype);
7445    Widget_Data *wd = elm_widget_data_get(obj);
7446
7447    Delayed_Data *data = ELM_NEW(Delayed_Data);
7448    data->func = _region_bring_in;
7449    data->wd = wd;
7450    data->lon = lon;
7451    data->lat = lat;
7452    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
7453    evas_object_smart_changed(data->wd->pan_smart);
7454 #else
7455    (void) obj;
7456    (void) lon;
7457    (void) lat;
7458 #endif
7459 }
7460
7461 EAPI void
7462 elm_map_region_show(Evas_Object *obj, double lon, double lat)
7463 {
7464 #ifdef HAVE_ELEMENTARY_ECORE_CON
7465    ELM_CHECK_WIDTYPE(obj, widtype);
7466    Widget_Data *wd = elm_widget_data_get(obj);
7467
7468    Delayed_Data *data = ELM_NEW(Delayed_Data);
7469    data->func = _region_show;
7470    data->wd = wd;
7471    data->lon = lon;
7472    data->lat = lat;
7473    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
7474    evas_object_smart_changed(data->wd->pan_smart);
7475 #else
7476    (void) obj;
7477    (void) lon;
7478    (void) lat;
7479 #endif
7480 }
7481
7482 EAPI void
7483 elm_map_region_get(const Evas_Object *obj, double *lon, double *lat)
7484 {
7485 #ifdef HAVE_ELEMENTARY_ECORE_CON
7486    ELM_CHECK_WIDTYPE(obj, widtype);
7487    Widget_Data *wd = elm_widget_data_get(obj);
7488    EINA_SAFETY_ON_NULL_RETURN(wd);
7489
7490    double tlon, tlat;
7491    Evas_Coord px, py, vw, vh;
7492
7493    _pan_geometry_get(wd, &px, &py);
7494    _viewport_size_get(wd, &vw, &vh);
7495    _coord_to_region_convert(wd, vw/2 - px, vh/2 -py, wd->size.w, &tlon, &tlat);
7496    if (lon) *lon = tlon;
7497    if (lat) *lat = tlat;
7498 #else
7499    (void) obj;
7500    (void) lon;
7501    (void) lat;
7502 #endif
7503 }
7504
7505 EAPI void
7506 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
7507 {
7508 #ifdef HAVE_ELEMENTARY_ECORE_CON
7509    ELM_CHECK_WIDTYPE(obj, widtype);
7510    Widget_Data *wd = elm_widget_data_get(obj);
7511    EINA_SAFETY_ON_NULL_RETURN(wd);
7512
7513    if (wd->paused == !!paused) return;
7514    wd->paused = !!paused;
7515    if (wd->paused)
7516      {
7517         if (wd->zoom_animator)
7518           {
7519              if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
7520              wd->zoom_animator = NULL;
7521              zoom_do(wd, wd->zoom);
7522           }
7523         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
7524                                 "elm,state,busy,stop", "elm");
7525      }
7526    else
7527      {
7528         if (wd->download_num >= 1)
7529            edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
7530                                    "elm,state,busy,start", "elm");
7531      }
7532 #else
7533    (void) obj;
7534    (void) paused;
7535 #endif
7536 }
7537
7538 EAPI Eina_Bool
7539 elm_map_paused_get(const Evas_Object *obj)
7540 {
7541 #ifdef HAVE_ELEMENTARY_ECORE_CON
7542    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
7543    Widget_Data *wd = elm_widget_data_get(obj);
7544    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
7545
7546    return wd->paused;
7547 #else
7548    (void) obj;
7549    return EINA_FALSE;
7550 #endif
7551 }
7552
7553 EAPI void
7554 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
7555 {
7556 #ifdef HAVE_ELEMENTARY_ECORE_CON
7557    ELM_CHECK_WIDTYPE(obj, widtype);
7558    Widget_Data *wd = elm_widget_data_get(obj);
7559    EINA_SAFETY_ON_NULL_RETURN(wd);
7560
7561    wd->rotate.d = degree;
7562    wd->rotate.cx = cx;
7563    wd->rotate.cy = cy;
7564
7565    evas_object_smart_changed(wd->pan_smart);
7566 #else
7567    (void) obj;
7568    (void) degree;
7569    (void) cx;
7570    (void) cy;
7571 #endif
7572 }
7573
7574 EAPI void
7575 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
7576 {
7577 #ifdef HAVE_ELEMENTARY_ECORE_CON
7578    ELM_CHECK_WIDTYPE(obj, widtype);
7579    Widget_Data *wd = elm_widget_data_get(obj);
7580    EINA_SAFETY_ON_NULL_RETURN(wd);
7581
7582    if (degree) *degree = wd->rotate.d;
7583    if (cx) *cx = wd->rotate.cx;
7584    if (cy) *cy = wd->rotate.cy;
7585 #else
7586    (void) obj;
7587    (void) degree;
7588    (void) cx;
7589    (void) cy;
7590 #endif
7591 }
7592
7593 EAPI void
7594 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
7595 {
7596 #ifdef HAVE_ELEMENTARY_ECORE_CON
7597    ELM_CHECK_WIDTYPE(obj, widtype);
7598    Widget_Data *wd = elm_widget_data_get(obj);
7599    EINA_SAFETY_ON_NULL_RETURN(wd);
7600
7601    if ((!wd->wheel_disabled) && (disabled))
7602      evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
7603    else if ((wd->wheel_disabled) && (!disabled))
7604      evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
7605    wd->wheel_disabled = !!disabled;
7606 #else
7607    (void) obj;
7608    (void) disabled;
7609 #endif
7610 }
7611
7612 EAPI Eina_Bool
7613 elm_map_wheel_disabled_get(const Evas_Object *obj)
7614 {
7615 #ifdef HAVE_ELEMENTARY_ECORE_CON
7616    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
7617    Widget_Data *wd = elm_widget_data_get(obj);
7618    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
7619
7620    return wd->wheel_disabled;
7621 #else
7622    (void) obj;
7623    return EINA_FALSE;
7624 #endif
7625 }
7626
7627 EAPI void
7628 elm_map_tile_load_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
7629 {
7630 #ifdef HAVE_ELEMENTARY_ECORE_CON
7631    ELM_CHECK_WIDTYPE(obj, widtype);
7632    Widget_Data *wd = elm_widget_data_get(obj);
7633    EINA_SAFETY_ON_NULL_RETURN(wd);
7634
7635    if (try_num) *try_num = wd->try_num;
7636    if (finish_num) *finish_num = wd->finish_num;
7637 #else
7638    (void) obj;
7639    (void) try_num;
7640    (void) finish_num;
7641 #endif
7642 }
7643
7644 EAPI void
7645 elm_map_canvas_to_region_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
7646 {
7647 #ifdef HAVE_ELEMENTARY_ECORE_CON
7648    ELM_CHECK_WIDTYPE(obj, widtype);
7649    Widget_Data *wd = elm_widget_data_get(obj);
7650    EINA_SAFETY_ON_NULL_RETURN(wd);
7651    EINA_SAFETY_ON_NULL_RETURN(lon);
7652    EINA_SAFETY_ON_NULL_RETURN(lat);
7653
7654    Evas_Coord px, py, vw, vh;
7655    _pan_geometry_get(wd, &px, &py);
7656    _viewport_size_get(wd, &vw, &vh);
7657    _coord_rotate(x - px, y - py, (vw / 2) - px, (vh / 2) - py, -wd->rotate.d,
7658                  &x, &y);
7659    _coord_to_region_convert(wd, x, y, wd->size.w, lon, lat);
7660 #else
7661    (void) obj;
7662    (void) x;
7663    (void) y;
7664    (void) lon;
7665    (void) lat;
7666 #endif
7667 }
7668
7669 EAPI void
7670 elm_map_region_to_canvas_convert(const Evas_Object *obj, double lon, double lat, Evas_Coord *x, Evas_Coord *y)
7671 {
7672 #ifdef HAVE_ELEMENTARY_ECORE_CON
7673    ELM_CHECK_WIDTYPE(obj, widtype);
7674    Widget_Data *wd = elm_widget_data_get(obj);
7675    EINA_SAFETY_ON_NULL_RETURN(wd);
7676    EINA_SAFETY_ON_NULL_RETURN(x);
7677    EINA_SAFETY_ON_NULL_RETURN(y);
7678
7679    Evas_Coord px, py, vw, vh;
7680    _pan_geometry_get(wd, &px, &py);
7681    _viewport_size_get(wd, &vw, &vh);
7682    _region_to_coord_convert(wd, lon, lat, wd->size.w, x, y);
7683    _coord_rotate(*x, *y, (vw / 2) - px, (vh / 2) - py, wd->rotate.d,
7684                  x, y);
7685    *x += px;
7686    *y += py;
7687 #else
7688    (void) obj;
7689    (void) lon;
7690    (void) lat;
7691    (void) x;
7692    (void) y;
7693 >>>>>>> remotes/origin/upstream
7694 #endif
7695 }
7696
7697 EAPI void
7698 <<<<<<< HEAD
7699 elm_map_zoom_set(Evas_Object *obj, int zoom)
7700 =======
7701 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
7702 >>>>>>> remotes/origin/upstream
7703 {
7704 #ifdef HAVE_ELEMENTARY_ECORE_CON
7705    ELM_CHECK_WIDTYPE(obj, widtype);
7706    Widget_Data *wd = elm_widget_data_get(obj);
7707 <<<<<<< HEAD
7708    Eina_List *l;
7709    Evas_Coord rx, ry, rw, rh;
7710    Evas_Object *p;
7711    Elm_Map_Route *r;
7712    Evas_Object *route;
7713    int z = 0;
7714
7715    EINA_SAFETY_ON_NULL_RETURN(wd);
7716    EINA_SAFETY_ON_NULL_RETURN(wd->src);
7717    if (wd->zoom_animator) return;
7718
7719    if (zoom < 0) zoom = 0;
7720    if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
7721    if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
7722
7723    if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
7724    else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
7725    else wd->zoom_method = ZOOM_METHOD_NONE;
7726
7727    wd->zoom = zoom;
7728    wd->size.ow = wd->size.w;
7729    wd->size.oh = wd->size.h;
7730    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
7731    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
7732
7733    EINA_LIST_FOREACH(wd->route, l, r)
7734      {
7735         if (r)
7736           {
7737              EINA_LIST_FOREACH(r->path, l, p)
7738                {
7739                   evas_object_polygon_points_clear(p);
7740                }
7741           }
7742      }
7743
7744    EINA_LIST_FOREACH(wd->track, l, route)
7745      {
7746        evas_object_hide(route);
7747      }
7748
7749    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
7750      {
7751         int p2w, p2h;
7752         int cumulw, cumulh;
7753
7754         cumulw = wd->tsize;
7755         p2w = 0;
7756         while (cumulw <= rw)
7757           {
7758              p2w++;
7759              cumulw *= 2;
7760           }
7761         p2w--;
7762
7763         cumulh = wd->tsize;
7764         p2h = 0;
7765         while (cumulh <= rh)
7766           {
7767              p2h++;
7768              cumulh *= 2;
7769           }
7770         p2h--;
7771
7772         if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
7773           {
7774              if (p2w < p2h) z = p2w;
7775              else z = p2h;
7776           }
7777         else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
7778           {
7779              if (p2w > p2h) z = p2w;
7780              else z = p2h;
7781           }
7782         wd->zoom = z;
7783      }
7784
7785    wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
7786    wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
7787    wd->t = 1.0;
7788
7789    if ((wd->size.w > 0) && (wd->size.h > 0))
7790      {
7791         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
7792         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
7793      }
7794    else
7795      {
7796         wd->size.spos.x = 0.5;
7797         wd->size.spos.y = 0.5;
7798      }
7799
7800    if (rw > wd->size.ow) wd->size.spos.x = 0.5;
7801    if (rh > wd->size.oh) wd->size.spos.y = 0.5;
7802    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
7803    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
7804
7805    if (wd->paused)
7806      {
7807         zoom_do(obj);
7808      }
7809    else
7810      {
7811         if (!wd->zoom_animator)
7812           {
7813              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
7814              wd->nosmooth++;
7815              if (wd->nosmooth == 1) _smooth_update(obj);
7816              evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
7817           }
7818      }
7819
7820    if (wd->zoom_method != ZOOM_METHOD_NONE) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
7821 #else
7822    (void) obj;
7823    (void) zoom;
7824 #endif
7825 }
7826
7827 EAPI int
7828 elm_map_zoom_get(const Evas_Object *obj)
7829 {
7830 #ifdef HAVE_ELEMENTARY_ECORE_CON
7831    ELM_CHECK_WIDTYPE(obj, widtype) 0;
7832    Widget_Data *wd = elm_widget_data_get(obj);
7833
7834    if (!wd) return 0;
7835    return wd->zoom;
7836 #else
7837    (void) obj;
7838    return 0;
7839 =======
7840    EINA_SAFETY_ON_NULL_RETURN(wd);
7841    EINA_SAFETY_ON_NULL_RETURN(user_agent);
7842
7843    eina_stringshare_replace(&wd->user_agent, user_agent);
7844
7845    if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
7846    eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
7847 #else
7848    (void) obj;
7849    (void) user_agent;
7850 #endif
7851 }
7852
7853 EAPI const char *
7854 elm_map_user_agent_get(const Evas_Object *obj)
7855 {
7856 #ifdef HAVE_ELEMENTARY_ECORE_CON
7857    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
7858    Widget_Data *wd = elm_widget_data_get(obj);
7859    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
7860
7861    return wd->user_agent;
7862 #else
7863    (void) obj;
7864    return NULL;
7865 >>>>>>> remotes/origin/upstream
7866 #endif
7867 }
7868
7869 EAPI void
7870 <<<<<<< HEAD
7871 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
7872 =======
7873 elm_map_source_set(Evas_Object *obj, Elm_Map_Source_Type type, const char *source_name)
7874 >>>>>>> remotes/origin/upstream
7875 {
7876 #ifdef HAVE_ELEMENTARY_ECORE_CON
7877    ELM_CHECK_WIDTYPE(obj, widtype);
7878    Widget_Data *wd = elm_widget_data_get(obj);
7879 <<<<<<< HEAD
7880
7881    if (!wd) return;
7882    if (wd->mode == mode) return;
7883    wd->mode = mode;
7884
7885    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
7886      {
7887         int tz = wd->zoom;
7888         wd->zoom = 0;
7889         elm_map_zoom_set(wd->obj, tz);
7890      }
7891 #else
7892    (void) obj;
7893    (void) mode;
7894 #endif
7895 }
7896
7897 EAPI Elm_Map_Zoom_Mode
7898 elm_map_zoom_mode_get(const Evas_Object *obj)
7899 {
7900 #ifdef HAVE_ELEMENTARY_ECORE_CON
7901    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
7902    Widget_Data *wd = elm_widget_data_get(obj);
7903
7904    if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
7905    return wd->mode;
7906 #else
7907    (void) obj;
7908    return ELM_MAP_ZOOM_MODE_MANUAL;
7909 #endif
7910 }
7911
7912 EAPI void
7913 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
7914 {
7915 #ifdef HAVE_ELEMENTARY_ECORE_CON
7916    ELM_CHECK_WIDTYPE(obj, widtype);
7917    Widget_Data *wd = elm_widget_data_get(obj);
7918    int rx, ry, rw, rh;
7919
7920    if (!wd) return;
7921    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
7922    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
7923
7924    rx = rx - rw / 2;
7925    ry = ry - rh / 2;
7926
7927    if (wd->zoom_animator)
7928      {
7929         wd->nosmooth--;
7930         if (!wd->nosmooth) _smooth_update(obj);
7931         ecore_animator_del(wd->zoom_animator);
7932         wd->zoom_animator = NULL;
7933         zoom_do(obj);
7934         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
7935      }
7936    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
7937
7938    wd->center_on.enabled = EINA_TRUE;
7939    wd->center_on.lon = lon;
7940    wd->center_on.lat = lat;
7941 #else
7942    (void) obj;
7943    (void) lon;
7944    (void) lat;
7945 #endif
7946 }
7947
7948 EAPI void
7949 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
7950 {
7951 #ifdef HAVE_ELEMENTARY_ECORE_CON
7952    ELM_CHECK_WIDTYPE(obj, widtype);
7953    Widget_Data *wd = elm_widget_data_get(obj);
7954    int rx, ry, rw, rh;
7955
7956    if (!wd) return;
7957    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
7958    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
7959
7960    rx = rx - rw / 2;
7961    ry = ry - rh / 2;
7962
7963    if (wd->zoom_animator)
7964      {
7965         wd->nosmooth--;
7966         ecore_animator_del(wd->zoom_animator);
7967         wd->zoom_animator = NULL;
7968         zoom_do(obj);
7969         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
7970      }
7971    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
7972
7973    wd->center_on.enabled = EINA_TRUE;
7974    wd->center_on.lon = lon;
7975    wd->center_on.lat = lat;
7976 #else
7977    (void) obj;
7978    (void) lon;
7979    (void) lat;
7980 #endif
7981 }
7982
7983 EAPI void
7984 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
7985 {
7986 #ifdef HAVE_ELEMENTARY_ECORE_CON
7987    ELM_CHECK_WIDTYPE(obj, widtype);
7988    Widget_Data *wd = elm_widget_data_get(obj);
7989    Evas_Coord cx, cy;
7990    int rw;
7991    double tlon, tlat;
7992    EINA_SAFETY_ON_NULL_RETURN(wd);
7993
7994    _region_get(wd, NULL, NULL, &cx, &cy, NULL, NULL);
7995    rw = wd->size.w * wd->pinch.level;
7996    elm_map_utils_convert_coord_into_geo(obj, cx, cy, rw, &tlon, &tlat);
7997    if (lon) *lon = tlon;
7998    if (lat) *lat = tlat;
7999 #else
8000    (void) obj;
8001    (void) lon;
8002    (void) lat;
8003 =======
8004    EINA_SAFETY_ON_NULL_RETURN(wd);
8005    EINA_SAFETY_ON_NULL_RETURN(source_name);
8006
8007    if (type == ELM_MAP_SOURCE_TYPE_TILE) _source_tile_set(wd, source_name);
8008    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE)
8009       _source_route_set(wd, source_name);
8010    else if (type == ELM_MAP_SOURCE_TYPE_NAME) _source_name_set(wd, source_name);
8011    else ERR("Not supported map source type: %d", type);
8012
8013 #else
8014    (void) obj;
8015    (void) source_name;
8016 #endif
8017 }
8018
8019 EAPI const char *
8020 elm_map_source_get(const Evas_Object *obj, Elm_Map_Source_Type type)
8021 {
8022 #ifdef HAVE_ELEMENTARY_ECORE_CON
8023    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8024    Widget_Data *wd = elm_widget_data_get(obj);
8025    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
8026    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_tile, NULL);
8027
8028    if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile->name;
8029    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route->name;
8030    else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_name->name;
8031    else ERR("Not supported map source type: %d", type);
8032    return NULL;
8033 #else
8034    (void) obj;
8035    return NULL;
8036 #endif
8037 }
8038
8039 EAPI const char **
8040 elm_map_sources_get(const Evas_Object *obj, Elm_Map_Source_Type type)
8041 {
8042 #ifdef HAVE_ELEMENTARY_ECORE_CON
8043    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8044    Widget_Data *wd = elm_widget_data_get(obj);
8045    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
8046
8047    if (type == ELM_MAP_SOURCE_TYPE_TILE) return wd->src_tile_names;
8048    else if (type == ELM_MAP_SOURCE_TYPE_ROUTE) return wd->src_route_names;
8049    else if (type == ELM_MAP_SOURCE_TYPE_NAME) return wd->src_tile_names;
8050    else ERR("Not supported map source type: %d", type);
8051    return NULL;
8052 #else
8053    (void) obj;
8054    return NULL;
8055 #endif
8056 }
8057
8058 EAPI Elm_Map_Route *
8059 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)
8060 {
8061 #ifdef HAVE_ELEMENTARY_ECORE_CON
8062    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8063    Widget_Data *wd = elm_widget_data_get(obj);
8064    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
8065    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->src_route, NULL);
8066
8067    char *type_name;
8068    char *url;
8069    char fname[PATH_MAX];
8070
8071    if (!ecore_file_exists(CACHE_ROUTE_ROOT))
8072       ecore_file_mkpath(CACHE_ROUTE_ROOT);
8073
8074    if (type == ELM_MAP_ROUTE_TYPE_MOTOCAR)
8075       type_name = strdup(ROUTE_TYPE_MOTORCAR);
8076    else if (type == ELM_MAP_ROUTE_TYPE_BICYCLE)
8077       type_name = strdup(ROUTE_TYPE_BICYCLE);
8078    else if (type == ELM_MAP_ROUTE_TYPE_FOOT)
8079       type_name = strdup(ROUTE_TYPE_FOOT);
8080    else type_name = NULL;
8081
8082    url = wd->src_route->url_cb(obj, type_name, method, flon, flat, tlon, tlat);
8083    if (!url)
8084      {
8085         ERR("Route URL is NULL");
8086         if (type_name) free(type_name);
8087         return NULL;
8088      }
8089    if (type_name) free(type_name);
8090
8091    Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
8092    route->wd = wd;
8093    snprintf(fname, sizeof(fname), CACHE_ROUTE_ROOT"/%d", rand());
8094    route->fname = strdup(fname);
8095    route->type = type;
8096    route->method = method;
8097    route->flon = flon;
8098    route->flat = flat;
8099    route->tlon = tlon;
8100    route->tlat = tlat;
8101    route->cb = route_cb;
8102    route->data = data;
8103
8104    if (!ecore_file_download_full(url, route->fname, _route_cb, NULL, route,
8105                                  &(route->job), wd->ua) || !(route->job))
8106      {
8107         ERR("Can't request Route from %s to %s", url, route->fname);
8108         free(route->fname);
8109         free(route);
8110         return NULL;
8111      }
8112    INF("Route requested from %s to %s", url, route->fname);
8113    free(url);
8114
8115    wd->routes = eina_list_append(wd->routes, route);
8116    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, route);
8117    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
8118                            "elm,state,busy,start", "elm");
8119    return route;
8120 #else
8121    (void) obj;
8122    (void) type;
8123    (void) method;
8124    (void) flon;
8125    (void) flat;
8126    (void) tlon;
8127    (void) tlat;
8128    (void) route_cb;
8129    (void) data;
8130    return NULL;
8131 #endif
8132 }
8133
8134
8135 EAPI void
8136 elm_map_route_del(Elm_Map_Route *route)
8137 {
8138 #ifdef HAVE_ELEMENTARY_ECORE_CON
8139    EINA_SAFETY_ON_NULL_RETURN(route);
8140    EINA_SAFETY_ON_NULL_RETURN(route->wd);
8141    ELM_CHECK_WIDTYPE(route->wd->obj, widtype);
8142
8143    Path_Waypoint *w;
8144    Path_Node *n;
8145
8146    if (route->job) ecore_file_download_abort(route->job);
8147
8148    EINA_LIST_FREE(route->waypoint, w)
8149      {
8150         if (w->point) eina_stringshare_del(w->point);
8151         free(w);
8152      }
8153
8154    EINA_LIST_FREE(route->nodes, n)
8155      {
8156         if (n->pos.address) eina_stringshare_del(n->pos.address);
8157         free(n);
8158      }
8159
8160    if (route->fname)
8161      {
8162         ecore_file_remove(route->fname);
8163         free(route->fname);
8164      }
8165
8166    route->wd->routes = eina_list_remove(route->wd->routes, route);
8167    free(route);
8168 #else
8169    (void) route;
8170 #endif
8171 }
8172
8173 EAPI double
8174 elm_map_route_distance_get(const Elm_Map_Route *route)
8175 {
8176 #ifdef HAVE_ELEMENTARY_ECORE_CON
8177    EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
8178    return route->info.distance;
8179 #else
8180    (void) route;
8181    return 0.0;
8182 #endif
8183 }
8184
8185 EAPI const char*
8186 elm_map_route_node_get(const Elm_Map_Route *route)
8187 {
8188 #ifdef HAVE_ELEMENTARY_ECORE_CON
8189    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
8190    return route->info.nodes;
8191 #else
8192    (void) route;
8193    return NULL;
8194 #endif
8195 }
8196
8197 EAPI const char*
8198 elm_map_route_waypoint_get(const Elm_Map_Route *route)
8199 {
8200 #ifdef HAVE_ELEMENTARY_ECORE_CON
8201    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
8202    return route->info.waypoints;
8203 #else
8204    (void) route;
8205    return NULL;
8206 #endif
8207 }
8208
8209 EAPI Elm_Map_Name *
8210 elm_map_name_add(const Evas_Object *obj, const char *address, double lon, double lat, Elm_Map_Name_Cb name_cb, void *data)
8211 {
8212 #ifdef HAVE_ELEMENTARY_ECORE_CON
8213    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8214
8215    if (address)
8216       return _name_request(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0, 0,
8217                            name_cb, data);
8218   else
8219      return _name_request(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat,
8220                           name_cb, data);
8221 #else
8222    (void) obj;
8223    (void) address;
8224    (void) lon;
8225    (void) lat;
8226    (void) name_cb;
8227    (void) data;
8228    return NULL;
8229 >>>>>>> remotes/origin/upstream
8230 #endif
8231 }
8232
8233 EAPI void
8234 <<<<<<< HEAD
8235 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
8236 {
8237 #ifdef HAVE_ELEMENTARY_ECORE_CON
8238    ELM_CHECK_WIDTYPE(obj, widtype);
8239    Widget_Data *wd = elm_widget_data_get(obj);
8240
8241    if (!wd) return;
8242    if (wd->paused == !!paused) return;
8243    wd->paused = !!paused;
8244    if (wd->paused)
8245      {
8246         if (wd->zoom_animator)
8247           {
8248              if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
8249              wd->zoom_animator = NULL;
8250              zoom_do(obj);
8251              evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
8252           }
8253         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
8254                                 "elm,state,busy,stop", "elm");
8255      }
8256    else
8257      {
8258         if (wd->download_num >= 1)
8259            edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
8260                                    "elm,state,busy,start", "elm");
8261      }
8262 #else
8263    (void) obj;
8264    (void) paused;
8265 #endif
8266 }
8267
8268 EAPI void
8269 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
8270 {
8271 #ifdef HAVE_ELEMENTARY_ECORE_CON
8272    ELM_CHECK_WIDTYPE(obj, widtype);
8273    Widget_Data *wd = elm_widget_data_get(obj);
8274
8275    if (!wd) return;
8276    if (wd->paused_markers == !!paused) return;
8277    wd->paused_markers = paused;
8278 #else
8279    (void) obj;
8280    (void) paused;
8281 #endif
8282 }
8283
8284 EAPI Eina_Bool
8285 elm_map_paused_get(const Evas_Object *obj)
8286 {
8287 #ifdef HAVE_ELEMENTARY_ECORE_CON
8288    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
8289    Widget_Data *wd = elm_widget_data_get(obj);
8290
8291    if (!wd) return EINA_FALSE;
8292    return wd->paused;
8293 #else
8294    (void) obj;
8295    return EINA_FALSE;
8296 #endif
8297 }
8298
8299 EAPI Eina_Bool
8300 elm_map_paused_markers_get(const Evas_Object *obj)
8301 {
8302 #ifdef HAVE_ELEMENTARY_ECORE_CON
8303    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
8304    Widget_Data *wd = elm_widget_data_get(obj);
8305
8306    if (!wd) return EINA_FALSE;
8307    return wd->paused_markers;
8308 #else
8309    (void) obj;
8310    return EINA_FALSE;
8311 =======
8312 elm_map_name_del(Elm_Map_Name *name)
8313 {
8314 #ifdef HAVE_ELEMENTARY_ECORE_CON
8315    EINA_SAFETY_ON_NULL_RETURN(name);
8316    EINA_SAFETY_ON_NULL_RETURN(name->wd);
8317    ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
8318
8319    if (name->job) ecore_file_download_abort(name->job);
8320    if (name->address) free(name->address);
8321    if (name->fname)
8322      {
8323         ecore_file_remove(name->fname);
8324         free(name->fname);
8325      }
8326
8327    name->wd->names = eina_list_remove(name->wd->names, name);
8328    free(name);
8329 #else
8330    (void) name;
8331 #endif
8332 }
8333
8334 EAPI const char *
8335 elm_map_name_address_get(const Elm_Map_Name *name)
8336 {
8337 #ifdef HAVE_ELEMENTARY_ECORE_CON
8338    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
8339    EINA_SAFETY_ON_NULL_RETURN_VAL(name->wd, NULL);
8340    ELM_CHECK_WIDTYPE(name->wd->obj, widtype) NULL;
8341
8342    return name->address;
8343 #else
8344    (void) name;
8345    return NULL;
8346 #endif
8347 }
8348
8349 EAPI void
8350 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
8351 {
8352 #ifdef HAVE_ELEMENTARY_ECORE_CON
8353    EINA_SAFETY_ON_NULL_RETURN(name);
8354    EINA_SAFETY_ON_NULL_RETURN(name->wd);
8355    ELM_CHECK_WIDTYPE(name->wd->obj, widtype);
8356
8357    if (lon) *lon = name->lon;
8358    if (lat) *lat = name->lat;
8359 #else
8360    (void) name;
8361    (void) lon;
8362    (void) lat;
8363 #endif
8364 }
8365
8366 EAPI Elm_Map_Overlay *
8367 elm_map_overlay_add(Evas_Object *obj, double lon, double lat)
8368 {
8369 #ifdef HAVE_ELEMENTARY_ECORE_CON
8370    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8371    Widget_Data *wd = elm_widget_data_get(obj);
8372    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
8373
8374    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
8375    overlay->wd = wd;
8376    overlay->type = ELM_MAP_OVERLAY_TYPE_DEFAULT;
8377    overlay->ovl = _overlay_default_new(wd, lon, lat, "radio");
8378    _overlay_default_cb_add(overlay->ovl, _overlay_clicked_cb, overlay);
8379    overlay->grp = _overlay_group_new(wd);
8380    wd->overlays = eina_list_append(wd->overlays, overlay);
8381
8382    evas_object_smart_changed(wd->pan_smart);
8383    return overlay;
8384 #else
8385    (void) obj;
8386    (void) lon;
8387    (void) lat;
8388    return NULL;
8389 >>>>>>> remotes/origin/upstream
8390 #endif
8391 }
8392
8393 EAPI void
8394 <<<<<<< HEAD
8395 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
8396 {
8397 #ifdef HAVE_ELEMENTARY_ECORE_CON
8398    ELM_CHECK_WIDTYPE(obj, widtype);
8399    Widget_Data *wd = elm_widget_data_get(obj);
8400
8401    if (!wd) return;
8402    if (try_num)
8403      {
8404         *try_num = wd->try_num;
8405      }
8406
8407    if (finish_num)
8408      {
8409         *finish_num = wd->finish_num;
8410      }
8411 #else
8412    (void) obj;
8413    (void) try_num;
8414    (void) finish_num;
8415 #endif
8416 }
8417
8418 EAPI void
8419 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
8420 {
8421 #ifdef HAVE_ELEMENTARY_ECORE_CON
8422    ELM_CHECK_WIDTYPE(obj, widtype);
8423    Widget_Data *wd = elm_widget_data_get(obj);
8424
8425    if (!wd) return;
8426    int zoom = floor(log(size / 256) / log(2));
8427    if ((wd->src) && (wd->src->coord_into_geo))
8428      {
8429         if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
8430      }
8431
8432    if (lon)
8433      {
8434         *lon = x / (double)size * 360.0 - 180;
8435      }
8436    if (lat)
8437      {
8438         double n = ELM_PI - 2.0 * ELM_PI * y / size;
8439         *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
8440      }
8441 #else
8442    (void) obj;
8443    (void) x;
8444    (void) y;
8445    (void) size;
8446    (void) lon;
8447    (void) lat;
8448 =======
8449 elm_map_overlay_del(Elm_Map_Overlay *overlay)
8450 {
8451 #ifdef HAVE_ELEMENTARY_ECORE_CON
8452    EINA_SAFETY_ON_NULL_RETURN(overlay);
8453    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8454    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8455
8456    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
8457      {
8458         _overlay_default_cb_del(overlay->ovl, _overlay_clicked_cb);
8459         _overlay_default_free(overlay->ovl);
8460      }
8461    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
8462      {
8463         _overlay_bubble_cb_del(overlay->ovl);
8464         _overlay_bubble_free(overlay->ovl);
8465      }
8466    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
8467       _overlay_class_free(overlay->ovl);
8468
8469    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
8470       _overlay_route_free(overlay->ovl);
8471
8472    if (overlay->grp)
8473      {
8474         _overlay_group_cb_del(overlay->grp);
8475         _overlay_group_free(overlay->grp, overlay);
8476      }
8477
8478    overlay->wd->overlays = eina_list_remove(overlay->wd->overlays, overlay);
8479    evas_object_smart_changed(overlay->wd->pan_smart);
8480
8481    free(overlay);
8482 #else
8483    (void) overlay;
8484 #endif
8485 }
8486
8487 EAPI Elm_Map_Overlay_Type
8488 elm_map_overlay_type_get(const Elm_Map_Overlay *overlay)
8489 {
8490 #ifdef HAVE_ELEMENTARY_ECORE_CON
8491    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, ELM_MAP_OVERLAY_TYPE_NONE);
8492    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, ELM_MAP_OVERLAY_TYPE_NONE);
8493    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) ELM_MAP_OVERLAY_TYPE_NONE;
8494
8495    return overlay->type;
8496 #else
8497    (void) overlay;
8498    return OVERLAY_TYPE_NONE;
8499 >>>>>>> remotes/origin/upstream
8500 #endif
8501 }
8502
8503 EAPI void
8504 <<<<<<< HEAD
8505 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
8506 {
8507 #ifdef HAVE_ELEMENTARY_ECORE_CON
8508    ELM_CHECK_WIDTYPE(obj, widtype);
8509    Widget_Data *wd = elm_widget_data_get(obj);
8510
8511    if (!wd) return;
8512    int zoom = floor(log(size / 256) / log(2));
8513    if ((wd->src) && (wd->src->geo_into_coord))
8514      {
8515         if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
8516      }
8517
8518    if (x)
8519      *x = floor((lon + 180.0) / 360.0 * size);
8520    if (y)
8521      *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
8522 #else
8523    (void) obj;
8524    (void) lon;
8525    (void) lat;
8526    (void) size;
8527    (void) x;
8528    (void) y;
8529 #endif
8530 }
8531
8532 EAPI Elm_Map_Name *
8533 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
8534 {
8535 #ifdef HAVE_ELEMENTARY_ECORE_CON
8536    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8537    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
8538 #else
8539    (void) obj;
8540    (void) lon;
8541    (void) lat;
8542 =======
8543 elm_map_overlay_data_set(Elm_Map_Overlay *overlay, void *data)
8544 {
8545 #ifdef HAVE_ELEMENTARY_ECORE_CON
8546    EINA_SAFETY_ON_NULL_RETURN(overlay);
8547    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8548    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8549
8550    overlay->data = data;
8551 #else
8552    (void) overlay;
8553    (void) data;
8554 #endif
8555 }
8556
8557 EAPI void *
8558 elm_map_overlay_data_get(const Elm_Map_Overlay *overlay)
8559 {
8560 #ifdef HAVE_ELEMENTARY_ECORE_CON
8561    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
8562    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
8563    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
8564
8565    return overlay->data;
8566 #else
8567    (void) overlay;
8568 >>>>>>> remotes/origin/upstream
8569    return NULL;
8570 #endif
8571 }
8572
8573 <<<<<<< HEAD
8574 EAPI Elm_Map_Name *
8575 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
8576 {
8577 #ifdef HAVE_ELEMENTARY_ECORE_CON
8578    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8579    if (!address) return NULL;
8580    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
8581 #else
8582    (void) obj;
8583    (void) address;
8584    return NULL;
8585 #endif
8586 }
8587
8588 EINA_DEPRECATED EAPI void
8589 elm_map_utils_rotate_coord(const Evas_Object *obj, const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
8590 {
8591 #ifdef HAVE_ELEMENTARY_ECORE_CON
8592    ELM_CHECK_WIDTYPE(obj, widtype);
8593    _coord_rotate(x, y, cx, cy, degree, xx, yy);
8594 #else
8595    (void) x;
8596    (void) y;
8597    (void) cx;
8598    (void) cy;
8599    (void) degree;
8600    (void) xx;
8601    (void) yy;
8602 =======
8603 EAPI void
8604 elm_map_overlay_hide_set(Elm_Map_Overlay *overlay, Eina_Bool hide)
8605 {
8606 #ifdef HAVE_ELEMENTARY_ECORE_CON
8607    EINA_SAFETY_ON_NULL_RETURN(overlay);
8608    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8609    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8610
8611    if (overlay->hide == !!hide) return;
8612    overlay->hide = hide;
8613
8614    evas_object_smart_changed(overlay->wd->pan_smart);
8615 #else
8616    (void) overlay;
8617    (void) hide;
8618 #endif
8619 }
8620
8621 EAPI Eina_Bool
8622 elm_map_overlay_hide_get(const Elm_Map_Overlay *overlay)
8623 {
8624 #ifdef HAVE_ELEMENTARY_ECORE_CON
8625    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
8626    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
8627    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
8628
8629    return overlay->hide;
8630 #else
8631    (void) overlay;
8632    return EINA_FALSE;
8633 >>>>>>> remotes/origin/upstream
8634 #endif
8635 }
8636
8637 EAPI void
8638 <<<<<<< HEAD
8639 elm_map_canvas_to_geo_convert(const Evas_Object *obj, const Evas_Coord x, const Evas_Coord y, double *lon, double *lat)
8640 {
8641 #ifdef HAVE_ELEMENTARY_ECORE_CON
8642    ELM_CHECK_WIDTYPE(obj, widtype);
8643    Widget_Data *wd = elm_widget_data_get(obj);
8644    EINA_SAFETY_ON_NULL_RETURN(lon);
8645    EINA_SAFETY_ON_NULL_RETURN(lat);
8646    EINA_SAFETY_ON_NULL_RETURN(wd);
8647
8648    Evas_Coord xx, yy, w, h, mw, tx, ty, cx, cy;
8649    double d;
8650
8651    _region_get(wd, &xx, &yy, &cx, &cy, &w, &h);
8652    mw = wd->size.w * wd->pinch.level;
8653    if (w < mw)
8654      {
8655         xx += x;
8656         yy += y;
8657      }
8658    else
8659      {
8660         xx = x - xx;
8661         yy = y - yy;
8662      }
8663
8664    elm_map_rotate_get(obj, &d, NULL, NULL);
8665    _coord_rotate(xx, yy, cx, cy, -d, &tx, &ty);
8666    elm_map_utils_convert_coord_into_geo(obj, tx, ty, mw, lon, lat);
8667 #else
8668    (void) obj;
8669    (void) x;
8670    (void) y;
8671    (void) lon;
8672    (void) lat;
8673 #endif
8674 }
8675
8676 EAPI Elm_Map_Marker *
8677 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
8678 {
8679 #ifdef HAVE_ELEMENTARY_ECORE_CON
8680    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
8681    Widget_Data *wd = elm_widget_data_get(obj);
8682    int i, j;
8683    Eina_List *l;
8684    Marker_Group *group;
8685    int mpi, mpj;
8686    int tabi[9];
8687    int tabj[9];
8688    const char *s;
8689    const char *style;
8690    Evas_Object *o;
8691
8692    if (!wd) return NULL;
8693    EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
8694    EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
8695
8696    Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
8697
8698    marker->wd = wd;
8699    marker->clas = clas;
8700    marker->clas_group = clas_group;
8701    marker->longitude = lon;
8702    marker->latitude = lat;
8703    marker->data = data;
8704    marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
8705    marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
8706    marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
8707
8708    tabi[1] = tabi[4] = tabi[6] = -1;
8709    tabi[2] = tabi[0] = tabi[7] = 0;
8710    tabi[3] = tabi[5] = tabi[8] = 1;
8711
8712    tabj[1] = tabj[2] = tabj[3] = -1;
8713    tabj[4] = tabj[0] = tabj[5] = 0;
8714    tabj[6] = tabj[7] = tabj[8] = 1;
8715
8716    if (!clas_group->priv.set)
8717      {
8718         style = "radio";
8719         if (marker->clas_group && marker->clas_group->style)
8720           style = marker->clas_group->style;
8721
8722         o = edje_object_add(evas_object_evas_get(obj));
8723         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
8724         s = edje_object_data_get(o, "size_w");
8725         if (s) clas_group->priv.edje_w = atoi(s);
8726         else clas_group->priv.edje_w = 0;
8727         s = edje_object_data_get(o, "size_h");
8728         if (s) clas_group->priv.edje_h = atoi(s);
8729         else clas_group->priv.edje_h = 0;
8730         s = edje_object_data_get(o, "size_max_w");
8731         if (s) clas_group->priv.edje_max_w = atoi(s);
8732         else clas_group->priv.edje_max_w = 0;
8733         s = edje_object_data_get(o, "size_max_h");
8734         if (s) clas_group->priv.edje_max_h = atoi(s);
8735         else clas_group->priv.edje_max_h = 0;
8736         evas_object_del(o);
8737
8738         clas_group->priv.set = EINA_TRUE;
8739      }
8740
8741    if (!clas->priv.set)
8742      {
8743         style = "radio";
8744         if (marker->clas && marker->clas->style)
8745           style = marker->clas->style;
8746
8747         o = edje_object_add(evas_object_evas_get(obj));
8748         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
8749         s = edje_object_data_get(o, "size_w");
8750         if (s) clas->priv.edje_w = atoi(s);
8751         else clas->priv.edje_w = 0;
8752         s = edje_object_data_get(o, "size_h");
8753         if (s) clas->priv.edje_h = atoi(s);
8754         else clas->priv.edje_h = 0;
8755         evas_object_del(o);
8756
8757         clas->priv.set = EINA_TRUE;
8758      }
8759
8760    for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
8761      {
8762         elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
8763                                              &(marker->x[i]), &(marker->y[i]));
8764
8765         //search in the matrixsparse the region where the marker will be
8766         mpi = marker->x[i] / wd->tsize;
8767         mpj = marker->y[i] / wd->tsize;
8768
8769         if (!wd->markers[i])
8770           {
8771              int size =  pow(2.0, i);
8772              wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
8773           }
8774
8775         group = NULL;
8776         if (i <= clas_group->zoom_grouped)
8777           {
8778              for (j = 0, group = NULL; j < 9 && !group; j++)
8779                {
8780                   EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
8781                                     l, group)
8782                     {
8783                        if (group->clas == marker->clas_group
8784                            && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
8785                                                   marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
8786                                                   group->x-group->w/4, group->y-group->h/4, group->w, group->h))
8787                          {
8788                             group->markers = eina_list_append(group->markers, marker);
8789                             group->update_nbelems = EINA_TRUE;
8790                             group->update_resize = EINA_TRUE;
8791
8792                             group->sum_x += marker->x[i];
8793                             group->sum_y += marker->y[i];
8794                             group->x = group->sum_x / eina_list_count(group->markers);
8795                             group->y = group->sum_y / eina_list_count(group->markers);
8796
8797                             group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
8798                                * eina_list_count(group->markers);
8799                             group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
8800                                * eina_list_count(group->markers);
8801                             if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
8802                             if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
8803
8804                             if (group->obj && eina_list_count(group->markers) == 2)
8805                               {
8806                                  _group_object_free(group);
8807                                  _group_object_create(group);
8808                               }
8809                             if (group->bubble)
8810                               _group_bubble_content_update(group);
8811
8812                             break;
8813                          }
8814                     }
8815                }
8816           }
8817         if (!group)
8818           {
8819              group = calloc(1, sizeof(Marker_Group));
8820              group->wd = wd;
8821              group->sum_x = marker->x[i];
8822              group->sum_y = marker->y[i];
8823              group->x = marker->x[i];
8824              group->y = marker->y[i];
8825              group->w = clas_group->priv.edje_w;
8826              group->h = clas_group->priv.edje_h;
8827              group->clas = clas_group;
8828
8829              group->markers = eina_list_append(group->markers, marker);
8830              group->update_nbelems = EINA_TRUE;
8831              group->update_resize = EINA_TRUE;
8832
8833              eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
8834
8835              if (!group->cell)
8836                {
8837                   l = eina_list_append(NULL, group);
8838                   eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
8839                   eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
8840                }
8841              else
8842                {
8843                   l = eina_matrixsparse_cell_data_get(group->cell);
8844                   l = eina_list_append(l, group);
8845                   eina_matrixsparse_cell_data_set(group->cell, l);
8846                }
8847           }
8848         marker->groups[i] = group;
8849      }
8850
8851    if (wd->grids)
8852      {
8853         Grid *g;
8854         Evas_Coord ox, oy, ow, oh;
8855         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
8856         g = _get_current_grid(wd);
8857         marker_place(obj, g, wd->pan_x, wd->pan_y, ox, oy, ow, oh);
8858      }
8859
8860    return marker;
8861 #else
8862    (void) obj;
8863    (void) lon;
8864    (void) lat;
8865    (void) clas;
8866    (void) clas_group;
8867    (void) data;
8868    return NULL;
8869 =======
8870 elm_map_overlay_displayed_zoom_min_set(Elm_Map_Overlay *overlay, int zoom)
8871 {
8872 #ifdef HAVE_ELEMENTARY_ECORE_CON
8873    EINA_SAFETY_ON_NULL_RETURN(overlay);
8874    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8875    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8876
8877    overlay->zoom_min = zoom;
8878    evas_object_smart_changed(overlay->wd->pan_smart);
8879 #else
8880    (void) overlay;
8881    (void) zoom;
8882 #endif
8883 }
8884
8885 EAPI int
8886 elm_map_overlay_displayed_zoom_min_get(const Elm_Map_Overlay *overlay)
8887 {
8888 #ifdef HAVE_ELEMENTARY_ECORE_CON
8889    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, 0);
8890    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, 0);
8891    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) 0;
8892
8893    return overlay->zoom_min;
8894 #else
8895    (void) overlay;
8896    return 0;
8897 #endif
8898 }
8899
8900 EAPI void
8901 elm_map_overlay_paused_set(Elm_Map_Overlay *overlay, Eina_Bool paused)
8902 {
8903 #ifdef HAVE_ELEMENTARY_ECORE_CON
8904    EINA_SAFETY_ON_NULL_RETURN(overlay);
8905    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8906    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8907
8908    if (overlay->paused == !!paused) return;
8909    overlay->paused = paused;
8910
8911    evas_object_smart_changed(overlay->wd->pan_smart);
8912 #else
8913    (void) overlay;
8914    (void) paused;
8915 #endif
8916 }
8917
8918 EAPI Eina_Bool
8919 elm_map_overlay_paused_get(const Elm_Map_Overlay *overlay)
8920 {
8921 #ifdef HAVE_ELEMENTARY_ECORE_CON
8922    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, EINA_FALSE);
8923    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, EINA_FALSE);
8924    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) EINA_FALSE;
8925
8926    return overlay->paused;
8927 #else
8928    (void) overlay;
8929    return EINA_FALSE;
8930 #endif
8931 }
8932
8933 EAPI void
8934 elm_map_overlay_show(Elm_Map_Overlay *overlay)
8935 {
8936 #ifdef HAVE_ELEMENTARY_ECORE_CON
8937    EINA_SAFETY_ON_NULL_RETURN(overlay);
8938    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8939    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8940
8941    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
8942      {
8943         Overlay_Default *ovl = overlay->ovl;
8944         elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
8945      }
8946    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
8947      {
8948         Overlay_Bubble *ovl = overlay->ovl;
8949         elm_map_region_show(overlay->wd->obj, ovl->lon, ovl->lat);
8950      }
8951    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
8952      {
8953         Overlay_Class *ovl = overlay->ovl;
8954         double lon, lat, max_lo, min_lo, max_la, min_la;
8955         _region_max_min_get(ovl->members, &max_lo, &min_lo, &max_la, &min_la);
8956         lon = (max_lo + min_lo) / 2;
8957         lat = (max_la + min_la) / 2;
8958         elm_map_region_show(overlay->wd->obj, lon, lat);
8959      }
8960    else ERR("Not supported overlay type: %d", overlay->type);
8961
8962    evas_object_smart_changed(overlay->wd->pan_smart);
8963 #else
8964    (void) overlay;
8965 #endif
8966 }
8967
8968 EAPI void
8969 elm_map_overlays_show(Eina_List *overlays)
8970 {
8971 #ifdef HAVE_ELEMENTARY_ECORE_CON
8972    EINA_SAFETY_ON_NULL_RETURN(overlays);
8973    EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(overlays));
8974
8975    Elm_Map_Overlay *overlay;
8976    overlay = eina_list_data_get(overlays);
8977
8978    Delayed_Data *data = ELM_NEW(Delayed_Data);
8979    data->func = _overlays_show;
8980    data->wd = overlay->wd;
8981    data->overlays = eina_list_clone(overlays);
8982    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
8983    evas_object_smart_changed(data->wd->pan_smart);
8984 #else
8985    (void) overlays;
8986 #endif
8987 }
8988
8989 EAPI void
8990 elm_map_overlay_region_set(Elm_Map_Overlay *overlay, double lon, double lat)
8991 {
8992 #ifdef HAVE_ELEMENTARY_ECORE_CON
8993    EINA_SAFETY_ON_NULL_RETURN(overlay);
8994    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
8995    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
8996
8997    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
8998      {
8999         Overlay_Default *ovl = overlay->ovl;
9000         ovl->lon = lon;
9001         ovl->lat = lat;
9002      }
9003    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
9004      {
9005         Overlay_Bubble *ovl = overlay->ovl;
9006         ovl->lon = lon;
9007         ovl->lat = lat;
9008      }
9009    else ERR("Not supported overlay type: %d", overlay->type);
9010
9011    evas_object_smart_changed(overlay->wd->pan_smart);
9012 #else
9013    (void) overlay;
9014    (void) lon;
9015    (void) lat;
9016 >>>>>>> remotes/origin/upstream
9017 #endif
9018 }
9019
9020 EAPI void
9021 <<<<<<< HEAD
9022 elm_map_marker_remove(Elm_Map_Marker *marker)
9023 {
9024 #ifdef HAVE_ELEMENTARY_ECORE_CON
9025    int i;
9026    Eina_List *groups;
9027    Widget_Data *wd;
9028
9029    EINA_SAFETY_ON_NULL_RETURN(marker);
9030    wd = marker->wd;
9031    if (!wd) return;
9032    for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
9033      {
9034         marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
9035         if (!eina_list_count(marker->groups[i]->markers))
9036           {
9037              groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
9038              groups = eina_list_remove(groups, marker->groups[i]);
9039              eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
9040
9041              _group_object_free(marker->groups[i]);
9042              _group_bubble_free(marker->groups[i]);
9043              free(marker->groups[i]);
9044           }
9045         else
9046           {
9047              marker->groups[i]->sum_x -= marker->x[i];
9048              marker->groups[i]->sum_y -= marker->y[i];
9049
9050              marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
9051              marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
9052
9053              marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
9054                 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
9055              marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
9056                 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
9057              if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
9058                marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
9059              if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
9060                marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
9061
9062              if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
9063                {
9064                   _group_object_free(marker->groups[i]);
9065                   _group_object_create(marker->groups[i]);
9066                }
9067           }
9068      }
9069
9070    if ((marker->content) && (marker->clas->func.del))
9071      marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
9072    else if (marker->content)
9073      evas_object_del(marker->content);
9074
9075    if (marker->x) free(marker->x);
9076    if (marker->y) free(marker->y);
9077    if (marker->groups) free(marker->groups);
9078
9079    free(marker);
9080
9081    if (wd->grids)
9082      {
9083         Grid *g;
9084         Evas_Coord ox, oy, ow, oh;
9085         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
9086         g = _get_current_grid(wd);
9087         marker_place(wd->obj, g, wd->pan_x, wd->pan_y, ox, oy, ow, oh);
9088      }
9089 #else
9090    (void) marker;
9091 =======
9092 elm_map_overlay_region_get(const Elm_Map_Overlay *overlay, double *lon, double *lat)
9093 {
9094 #ifdef HAVE_ELEMENTARY_ECORE_CON
9095    EINA_SAFETY_ON_NULL_RETURN(overlay);
9096    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9097    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9098
9099    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
9100      {
9101         const Overlay_Default *ovl = overlay->ovl;
9102         if (lon) *lon = ovl->lon;
9103         if (lat) *lat = ovl->lat;
9104      }
9105    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_BUBBLE)
9106      {
9107         const Overlay_Bubble *ovl = overlay->ovl;
9108         if (lon) *lon = ovl->lon;
9109         if (lat) *lat = ovl->lat;
9110      }
9111    else ERR("Not supported overlay type: %d", overlay->type);
9112 #else
9113    (void) overlay;
9114    (void) lon;
9115    (void) lat;
9116 >>>>>>> remotes/origin/upstream
9117 #endif
9118 }
9119
9120 EAPI void
9121 <<<<<<< HEAD
9122 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
9123 {
9124 #ifdef HAVE_ELEMENTARY_ECORE_CON
9125    EINA_SAFETY_ON_NULL_RETURN(marker);
9126    if (lon) *lon = marker->longitude;
9127    if (lat) *lat = marker->latitude;
9128 #else
9129    (void) marker;
9130    (void) lon;
9131    (void) lat;
9132 #endif
9133 }
9134
9135 EAPI void
9136 elm_map_marker_bring_in(Elm_Map_Marker *marker)
9137 {
9138 #ifdef HAVE_ELEMENTARY_ECORE_CON
9139    EINA_SAFETY_ON_NULL_RETURN(marker);
9140    elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
9141 #else
9142    (void) marker;
9143 =======
9144 elm_map_overlay_icon_set(Elm_Map_Overlay *overlay, Evas_Object *icon)
9145 {
9146 #ifdef HAVE_ELEMENTARY_ECORE_CON
9147    EINA_SAFETY_ON_NULL_RETURN(overlay);
9148    EINA_SAFETY_ON_NULL_RETURN(icon);
9149    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9150    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9151
9152    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
9153       _overlay_default_update(overlay->wd, overlay->ovl, NULL, icon,
9154                               NULL, NULL, NULL);
9155    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
9156       _overlay_class_update(overlay->wd, overlay->ovl, NULL, icon);
9157    else ERR("Not supported overlay type: %d", overlay->type);
9158
9159    evas_object_smart_changed(overlay->wd->pan_smart);
9160 #else
9161    (void) overlay;
9162    (void) icon;
9163 #endif
9164 }
9165
9166 EAPI const Evas_Object *
9167 elm_map_overlay_icon_get(const Elm_Map_Overlay *overlay)
9168 {
9169 #ifdef HAVE_ELEMENTARY_ECORE_CON
9170    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
9171    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
9172    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
9173
9174    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
9175      {
9176         const Overlay_Default *ovl = overlay->ovl;
9177         return elm_object_part_content_get(ovl->layout, "elm.icon");
9178      }
9179    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
9180      {
9181         const Overlay_Class *ovl = overlay->ovl;
9182         return ovl->icon;
9183      }
9184    else
9185      {
9186         ERR("Not supported overlay type: %d", overlay->type);
9187         return NULL;
9188      }
9189 #else
9190    (void) overlay;
9191    return NULL;
9192 >>>>>>> remotes/origin/upstream
9193 #endif
9194 }
9195
9196 EAPI void
9197 <<<<<<< HEAD
9198 elm_map_marker_show(Elm_Map_Marker *marker)
9199 {
9200 #ifdef HAVE_ELEMENTARY_ECORE_CON
9201    EINA_SAFETY_ON_NULL_RETURN(marker);
9202    elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
9203 #else
9204    (void) marker;
9205 =======
9206 elm_map_overlay_content_set(Elm_Map_Overlay *overlay, Evas_Object *obj)
9207 {
9208 #ifdef HAVE_ELEMENTARY_ECORE_CON
9209    EINA_SAFETY_ON_NULL_RETURN(overlay);
9210    EINA_SAFETY_ON_NULL_RETURN(obj);
9211    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9212    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9213
9214    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
9215       _overlay_default_update(overlay->wd, overlay->ovl, obj, NULL, NULL,
9216                                  NULL, NULL);
9217    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
9218       _overlay_class_update(overlay->wd, overlay->ovl, obj, NULL);
9219    else ERR("Not supported overlay type: %d", overlay->type);
9220
9221    evas_object_smart_changed(overlay->wd->pan_smart);
9222 #else
9223    (void) overlay;
9224    (void) obj;
9225 #endif
9226 }
9227
9228 EAPI const Evas_Object *
9229 elm_map_overlay_content_get(const Elm_Map_Overlay *overlay)
9230 {
9231 #ifdef HAVE_ELEMENTARY_ECORE_CON
9232    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay, NULL);
9233    EINA_SAFETY_ON_NULL_RETURN_VAL(overlay->wd, NULL);
9234    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype) NULL;
9235
9236    if (overlay->type == ELM_MAP_OVERLAY_TYPE_DEFAULT)
9237      {
9238         const Overlay_Default *ovl = overlay->ovl;
9239         return elm_object_part_content_get(ovl->layout, "elm.icon");
9240      }
9241    else if (overlay->type == ELM_MAP_OVERLAY_TYPE_CLASS)
9242      {
9243         const Overlay_Class *ovl = overlay->ovl;
9244         return ovl->icon;
9245      }
9246    else
9247      {
9248         ERR("Not supported overlay type: %d", overlay->type);
9249         return NULL;
9250      }
9251 #else
9252    (void) overlay;
9253    return NULL;
9254 >>>>>>> remotes/origin/upstream
9255 #endif
9256 }
9257
9258 EAPI void
9259 <<<<<<< HEAD
9260 elm_map_markers_list_show(Eina_List *markers)
9261 {
9262 #ifdef HAVE_ELEMENTARY_ECORE_CON
9263    int zoom;
9264    double lon, lat;
9265    Eina_List *l;
9266    Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
9267    Evas_Coord rw, rh, xc, yc;
9268    Widget_Data *wd;
9269
9270    EINA_SAFETY_ON_NULL_RETURN(markers);
9271    EINA_LIST_FOREACH(markers, l, marker)
9272      {
9273         wd = marker->wd;
9274
9275         if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
9276           m_min_lon = marker;
9277
9278         if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
9279           m_max_lon = marker;
9280
9281         if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
9282           m_min_lat = marker;
9283
9284         if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
9285           m_max_lat = marker;
9286      }
9287
9288    lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
9289    lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
9290
9291    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
9292    for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
9293      {
9294         Evas_Coord size = pow(2.0, zoom)*wd->tsize;
9295         elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
9296
9297         if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
9298             && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
9299             && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
9300             && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
9301           break;
9302      }
9303
9304    elm_map_geo_region_show(wd->obj, lon, lat);
9305    elm_map_zoom_set(wd->obj, zoom);
9306 #else
9307    (void) markers;
9308 =======
9309 elm_map_overlay_color_set(Elm_Map_Overlay *overlay, int r, int g , int b, int a)
9310 {
9311 #ifdef HAVE_ELEMENTARY_ECORE_CON
9312    EINA_SAFETY_ON_NULL_RETURN(overlay);
9313    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9314    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9315
9316    if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
9317      {
9318         Overlay_Route *route = overlay->ovl;
9319         route->color.r = r;
9320         route->color.g = g;
9321         route->color.b = b;
9322         route->color.a = a;
9323      }
9324    else ERR("Not supported overlay type: %d", overlay->type);
9325 #else
9326    (void) overlay;
9327    (void) r;
9328    (void) g;
9329    (void) b;
9330    (void) a;
9331 #endif
9332 }
9333
9334 EAPI void
9335 elm_map_overlay_color_get(const Elm_Map_Overlay *overlay, int *r, int *g , int *b, int *a)
9336 {
9337 #ifdef HAVE_ELEMENTARY_ECORE_CON
9338    EINA_SAFETY_ON_NULL_RETURN(overlay);
9339    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9340    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9341
9342    int rr, gg, bb, aa;
9343
9344    if (overlay->type == ELM_MAP_OVERLAY_TYPE_ROUTE)
9345      {
9346         Overlay_Route *route = overlay->ovl;
9347         rr = route->color.r;
9348         gg = route->color.g;
9349         bb = route->color.b;
9350         aa = route->color.a;
9351      }
9352    else
9353      {
9354         ERR("Not supported overlay type: %d", overlay->type);
9355         return;
9356      }
9357    if (r) *r = rr;
9358    if (g) *g = gg;
9359    if (b) *b = bb;
9360    if (a) *a = aa;
9361 #else
9362    (void) overlay;
9363    (void) r;
9364    (void) g;
9365    (void) b;
9366    (void) a;
9367 >>>>>>> remotes/origin/upstream
9368 #endif
9369 }
9370
9371 EAPI void
9372 <<<<<<< HEAD
9373 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
9374 {
9375 #ifdef HAVE_ELEMENTARY_ECORE_CON
9376    ELM_CHECK_WIDTYPE(obj, widtype);
9377    Widget_Data *wd = elm_widget_data_get(obj);
9378
9379    if (!wd) return;
9380    wd->markers_max_num = max;
9381 #else
9382    (void) obj;
9383    (void) max;
9384 #endif
9385 }
9386
9387 EAPI Evas_Object *
9388 elm_map_marker_object_get(const Elm_Map_Marker *marker)
9389 {
9390 #ifdef HAVE_ELEMENTARY_ECORE_CON
9391    EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
9392    return marker->content;
9393 #else
9394    (void) marker;
9395 =======
9396 elm_map_overlay_get_cb_set(Elm_Map_Overlay *overlay, Elm_Map_Overlay_Get_Cb get_cb, void *data)
9397 {
9398 #ifdef HAVE_ELEMENTARY_ECORE_CON
9399    EINA_SAFETY_ON_NULL_RETURN(overlay);
9400    EINA_SAFETY_ON_NULL_RETURN(overlay->wd);
9401    ELM_CHECK_WIDTYPE(overlay->wd->obj, widtype);
9402
9403    overlay->cb = get_cb;
9404    overlay->cb_data = data;
9405 #else
9406    (void) overlay;
9407    (void) get_cb;
9408    (void) data;
9409 #endif
9410 }
9411
9412 EAPI Elm_Map_Overlay *
9413 elm_map_overlay_class_add(Evas_Object *obj)
9414 {
9415 #ifdef HAVE_ELEMENTARY_ECORE_CON
9416    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9417    Widget_Data *wd = elm_widget_data_get(obj);
9418    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
9419
9420    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
9421    overlay->wd = wd;
9422    overlay->type = ELM_MAP_OVERLAY_TYPE_CLASS;
9423    overlay->ovl = _overlay_class_new(wd, overlay);
9424    overlay->grp = NULL;
9425    wd->overlays = eina_list_append(wd->overlays, overlay);
9426
9427    evas_object_smart_changed(wd->pan_smart);
9428    return overlay;
9429 #else
9430    (void) obj;
9431 >>>>>>> remotes/origin/upstream
9432    return NULL;
9433 #endif
9434 }
9435
9436 EAPI void
9437 <<<<<<< HEAD
9438 elm_map_marker_update(Elm_Map_Marker *marker)
9439 {
9440 #ifdef HAVE_ELEMENTARY_ECORE_CON
9441    EINA_SAFETY_ON_NULL_RETURN(marker);
9442    if (marker->content)
9443      {
9444         if (marker->clas->func.del)
9445           marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
9446         else
9447           evas_object_del(marker->content);
9448         marker->content = NULL;
9449         _group_bubble_content_update(marker->groups[marker->wd->zoom]);
9450      }
9451 #else
9452    (void) marker;
9453 =======
9454 elm_map_overlay_class_append(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
9455 {
9456 #ifdef HAVE_ELEMENTARY_ECORE_CON
9457    EINA_SAFETY_ON_NULL_RETURN(group);
9458    EINA_SAFETY_ON_NULL_RETURN(overlay);
9459    EINA_SAFETY_ON_NULL_RETURN(group->wd);
9460    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
9461    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
9462
9463    if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
9464      {
9465         ERR("Currently group supports only default overlays");
9466         return;
9467      }
9468
9469    Overlay_Class *ovl = group->ovl;
9470    if (eina_list_data_find(ovl->members, overlay))
9471      {
9472         ERR("Already added overlay into group");
9473         return;
9474      }
9475    ovl->members = eina_list_append(ovl->members, overlay);
9476    overlay->grp->clas = group;
9477
9478   evas_object_smart_changed(group->wd->pan_smart);
9479 #else
9480    (void) group;
9481    (void) overlay;
9482 >>>>>>> remotes/origin/upstream
9483 #endif
9484 }
9485
9486 EAPI void
9487 <<<<<<< HEAD
9488 elm_map_bubbles_close(Evas_Object *obj)
9489 {
9490 #ifdef HAVE_ELEMENTARY_ECORE_CON
9491    ELM_CHECK_WIDTYPE(obj, widtype);
9492    Widget_Data *wd = elm_widget_data_get(obj);
9493    Marker_Group *group;
9494    Eina_List *l, *l_next;
9495
9496    if (!wd) return;
9497    EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
9498       _group_bubble_free(group);
9499 #else
9500    (void) obj;
9501 #endif
9502 }
9503
9504 EAPI Elm_Map_Group_Class *
9505 elm_map_group_class_new(Evas_Object *obj)
9506 {
9507 #ifdef HAVE_ELEMENTARY_ECORE_CON
9508    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9509    Widget_Data *wd = elm_widget_data_get(obj);
9510
9511    if (!wd) return NULL;
9512    Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
9513    clas->zoom_grouped = wd->zoom_max;
9514    wd->groups_clas = eina_list_append(wd->groups_clas, clas);
9515    return clas;
9516 #else
9517    (void) obj;
9518    return NULL;
9519 #endif
9520 }
9521
9522 EAPI void
9523 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
9524 {
9525 #ifdef HAVE_ELEMENTARY_ECORE_CON
9526    EINA_SAFETY_ON_NULL_RETURN(clas);
9527    eina_stringshare_replace(&clas->style, style);
9528 #else
9529    (void) clas;
9530    (void) style;
9531 #endif
9532 }
9533
9534 EAPI void
9535 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
9536 {
9537 #ifdef HAVE_ELEMENTARY_ECORE_CON
9538    EINA_SAFETY_ON_NULL_RETURN(clas);
9539    clas->func.icon_get = icon_get;
9540 #else
9541    (void) clas;
9542    (void) icon_get;
9543 =======
9544 elm_map_overlay_class_remove(Elm_Map_Overlay *group, Elm_Map_Overlay *overlay)
9545 {
9546 #ifdef HAVE_ELEMENTARY_ECORE_CON
9547    EINA_SAFETY_ON_NULL_RETURN(group);
9548    EINA_SAFETY_ON_NULL_RETURN(overlay);
9549    EINA_SAFETY_ON_NULL_RETURN(group->wd);
9550    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
9551    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
9552
9553     if (overlay->type != ELM_MAP_OVERLAY_TYPE_DEFAULT)
9554      {
9555         ERR("Currently group supports only default overlays");
9556         return;
9557      }
9558    Overlay_Class *ovl = group->ovl;
9559    ovl->members = eina_list_remove(ovl->members, overlay);
9560    overlay->grp->clas = NULL;
9561    _overlay_group_update(group->wd, overlay->grp, NULL);
9562
9563   evas_object_smart_changed(group->wd->pan_smart);
9564 #else
9565    (void) group;
9566    (void) overlay;
9567 #endif
9568 }
9569
9570 EAPI void
9571 elm_map_overlay_class_zoom_max_set(Elm_Map_Overlay *group, int zoom)
9572 {
9573 #ifdef HAVE_ELEMENTARY_ECORE_CON
9574    EINA_SAFETY_ON_NULL_RETURN(group);
9575    EINA_SAFETY_ON_NULL_RETURN(group->wd);
9576    ELM_CHECK_WIDTYPE(group->wd->obj, widtype);
9577    EINA_SAFETY_ON_FALSE_RETURN(group->type == ELM_MAP_OVERLAY_TYPE_CLASS);
9578
9579    Overlay_Class *ovl = group->ovl;
9580    if (ovl->zoom_max == !!zoom) return;
9581    ovl->zoom_max = zoom;
9582
9583    evas_object_smart_changed(group->wd->pan_smart);
9584 #else
9585    (void) group;
9586    (void) zoom;
9587 #endif
9588 }
9589
9590 EAPI int
9591 elm_map_overlay_class_zoom_max_get(const Elm_Map_Overlay *group)
9592 {
9593 #ifdef HAVE_ELEMENTARY_ECORE_CON
9594    EINA_SAFETY_ON_NULL_RETURN_VAL(group, OVERLAY_CLASS_ZOOM_MAX);
9595    EINA_SAFETY_ON_NULL_RETURN_VAL(group->wd, OVERLAY_CLASS_ZOOM_MAX);
9596    ELM_CHECK_WIDTYPE(group->wd->obj, widtype) OVERLAY_CLASS_ZOOM_MAX;
9597    EINA_SAFETY_ON_FALSE_RETURN_VAL(group->type == ELM_MAP_OVERLAY_TYPE_CLASS, OVERLAY_CLASS_ZOOM_MAX);
9598
9599    const Overlay_Class *ovl = group->ovl;
9600    return ovl->zoom_max;
9601 #else
9602    (void) group;
9603    return OVERLAY_CLASS_ZOOM_MAX;
9604 #endif
9605 }
9606
9607 EAPI Elm_Map_Overlay *
9608 elm_map_overlay_bubble_add(Evas_Object *obj)
9609 {
9610 #ifdef HAVE_ELEMENTARY_ECORE_CON
9611    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9612    Widget_Data *wd = elm_widget_data_get(obj);
9613    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
9614
9615    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
9616    overlay->wd = wd;
9617    overlay->type = ELM_MAP_OVERLAY_TYPE_BUBBLE;
9618    overlay->ovl =  _overlay_bubble_new(wd);
9619    _overlay_bubble_cb_add(overlay->ovl, overlay);
9620    overlay->grp = _overlay_group_new(wd);
9621    wd->overlays = eina_list_append(wd->overlays, overlay);
9622
9623    evas_object_smart_changed(wd->pan_smart);
9624    return overlay;
9625 #else
9626    (void) obj;
9627    return NULL;
9628 >>>>>>> remotes/origin/upstream
9629 #endif
9630 }
9631
9632 EAPI void
9633 <<<<<<< HEAD
9634 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
9635 {
9636 #ifdef HAVE_ELEMENTARY_ECORE_CON
9637    EINA_SAFETY_ON_NULL_RETURN(clas);
9638    clas->data = data;
9639 #else
9640    (void) clas;
9641    (void) data;
9642 =======
9643 elm_map_overlay_bubble_follow(Elm_Map_Overlay *bubble, Elm_Map_Overlay *parent)
9644 {
9645 #ifdef HAVE_ELEMENTARY_ECORE_CON
9646    EINA_SAFETY_ON_NULL_RETURN(bubble);
9647    EINA_SAFETY_ON_NULL_RETURN(parent);
9648    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
9649    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
9650
9651    Overlay_Bubble *ovl = bubble->ovl;
9652    Evas_Object *pobj = _overlay_obj_get(parent);
9653    if (!pobj) return;
9654
9655    if (ovl->pobj)
9656      {
9657         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_HIDE,
9658                                             _overlay_bubble_hide_cb, ovl);
9659         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_SHOW,
9660                                             _overlay_bubble_chase_cb, ovl);
9661         evas_object_event_callback_del_full(ovl->pobj, EVAS_CALLBACK_MOVE,
9662                                             _overlay_bubble_chase_cb, ovl);
9663      }
9664
9665    ovl->pobj = pobj;
9666    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_HIDE,
9667                                   _overlay_bubble_hide_cb, ovl);
9668    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_SHOW,
9669                                   _overlay_bubble_chase_cb, ovl);
9670    evas_object_event_callback_add(ovl->pobj, EVAS_CALLBACK_MOVE,
9671                                   _overlay_bubble_chase_cb, ovl);
9672
9673    _overlay_bubble_chase(ovl);
9674    evas_object_smart_changed(bubble->wd->pan_smart);
9675 #else
9676    (void) bubble;
9677    (void) parent;
9678 >>>>>>> remotes/origin/upstream
9679 #endif
9680 }
9681
9682 EAPI void
9683 <<<<<<< HEAD
9684 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
9685 {
9686 #ifdef HAVE_ELEMENTARY_ECORE_CON
9687    EINA_SAFETY_ON_NULL_RETURN(clas);
9688    clas->zoom_displayed = zoom;
9689 #else
9690    (void) clas;
9691    (void) zoom;
9692 =======
9693 elm_map_overlay_bubble_content_append(Elm_Map_Overlay *bubble, Evas_Object *content)
9694 {
9695 #ifdef HAVE_ELEMENTARY_ECORE_CON
9696    EINA_SAFETY_ON_NULL_RETURN(bubble);
9697    EINA_SAFETY_ON_NULL_RETURN(content);
9698    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
9699    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
9700
9701    Overlay_Bubble *bb = bubble->ovl;
9702    elm_box_pack_end(bb->bx, content);
9703
9704    evas_object_smart_changed(bubble->wd->pan_smart);
9705 #else
9706    (void) bubble;
9707    (void) content;
9708 >>>>>>> remotes/origin/upstream
9709 #endif
9710 }
9711
9712 EAPI void
9713 <<<<<<< HEAD
9714 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
9715 {
9716 #ifdef HAVE_ELEMENTARY_ECORE_CON
9717    EINA_SAFETY_ON_NULL_RETURN(clas);
9718    clas->zoom_grouped = zoom;
9719 #else
9720    (void) clas;
9721    (void) zoom;
9722 #endif
9723 }
9724
9725 EAPI void
9726 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
9727 {
9728 #ifdef HAVE_ELEMENTARY_ECORE_CON
9729    ELM_CHECK_WIDTYPE(obj, widtype);
9730    Widget_Data *wd = elm_widget_data_get(obj);
9731
9732    if (!wd) return;
9733    EINA_SAFETY_ON_NULL_RETURN(clas);
9734    if (clas->hide == hide) return;
9735    clas->hide = hide;
9736    if (wd->grids)
9737      {
9738         Grid *g;
9739         Evas_Coord ox, oy, ow, oh;
9740         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
9741         g = _get_current_grid(wd);
9742         marker_place(obj, g, wd->pan_x, wd->pan_y, ox, oy, ow, oh);
9743      }
9744 #else
9745    (void) obj;
9746    (void) clas;
9747    (void) hide;
9748 #endif
9749 }
9750
9751 EAPI Elm_Map_Marker_Class *
9752 elm_map_marker_class_new(Evas_Object *obj)
9753 {
9754 #ifdef HAVE_ELEMENTARY_ECORE_CON
9755    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9756    Widget_Data *wd = elm_widget_data_get(obj);
9757
9758    if (!wd) return NULL;
9759    Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
9760    wd->markers_clas = eina_list_append(wd->markers_clas, clas);
9761    return clas;
9762 #else
9763    (void) obj;
9764 =======
9765 elm_map_overlay_bubble_content_clear(Elm_Map_Overlay *bubble)
9766 {
9767 #ifdef HAVE_ELEMENTARY_ECORE_CON
9768    EINA_SAFETY_ON_NULL_RETURN(bubble);
9769    ELM_CHECK_WIDTYPE(bubble->wd->obj, widtype);
9770    EINA_SAFETY_ON_FALSE_RETURN(bubble->type == ELM_MAP_OVERLAY_TYPE_BUBBLE);
9771
9772    Overlay_Bubble *bb = bubble->ovl;
9773    elm_box_clear(bb->bx);
9774
9775    evas_object_smart_changed(bubble->wd->pan_smart);
9776 #else
9777    (void) bubble;
9778 #endif
9779 }
9780
9781 EAPI Elm_Map_Overlay *
9782 elm_map_overlay_route_add(Evas_Object *obj, const Elm_Map_Route *route)
9783 {
9784 #ifdef HAVE_ELEMENTARY_ECORE_CON
9785    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9786    Widget_Data *wd = elm_widget_data_get(obj);
9787    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
9788    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
9789    EINA_SAFETY_ON_NULL_RETURN_VAL(route->wd, NULL);
9790    EINA_SAFETY_ON_FALSE_RETURN_VAL(obj == route->wd->obj, NULL);
9791
9792    Elm_Map_Overlay *overlay = ELM_NEW(Elm_Map_Overlay);
9793    overlay->wd = wd;
9794    overlay->type = ELM_MAP_OVERLAY_TYPE_ROUTE;
9795    overlay->ovl =  _overlay_route_new(wd, route);
9796    overlay->grp = _overlay_group_new(wd);
9797    wd->overlays = eina_list_append(wd->overlays, overlay);
9798
9799    evas_object_smart_changed(wd->pan_smart);
9800    return overlay;
9801 #else
9802    (void) obj;
9803    (void) route;
9804    return NULL;
9805 #endif
9806 }
9807
9808 #ifdef ELM_EMAP
9809 EAPI Evas_Object *
9810 elm_map_track_add(Evas_Object *obj, void *emap)
9811 {
9812 #ifdef HAVE_ELEMENTARY_ECORE_CON
9813    EMap_Route *emapr = emap;
9814    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9815    Widget_Data *wd = elm_widget_data_get(obj);
9816    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
9817
9818    Evas_Object *route = elm_route_add(obj);
9819    elm_route_emap_set(route, emapr);
9820    wd->track = eina_list_append(wd->track, route);
9821
9822    return route;
9823 #else
9824    (void) obj;
9825    (void) emap;
9826 >>>>>>> remotes/origin/upstream
9827    return NULL;
9828 #endif
9829 }
9830
9831 EAPI void
9832 <<<<<<< HEAD
9833 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
9834 {
9835 #ifdef HAVE_ELEMENTARY_ECORE_CON
9836    EINA_SAFETY_ON_NULL_RETURN(clas);
9837    eina_stringshare_replace(&clas->style, style);
9838 #else
9839    (void) clas;
9840    (void) style;
9841 #endif
9842 }
9843
9844 EAPI void
9845 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
9846 {
9847 #ifdef HAVE_ELEMENTARY_ECORE_CON
9848    EINA_SAFETY_ON_NULL_RETURN(clas);
9849    clas->func.icon_get = icon_get;
9850 #else
9851    (void) clas;
9852    (void) icon_get;
9853 #endif
9854 }
9855
9856 EAPI void
9857 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
9858 {
9859 #ifdef HAVE_ELEMENTARY_ECORE_CON
9860    EINA_SAFETY_ON_NULL_RETURN(clas);
9861    clas->func.get = get;
9862 #else
9863    (void) clas;
9864    (void) get;
9865 #endif
9866 }
9867
9868 EAPI void
9869 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
9870 {
9871 #ifdef HAVE_ELEMENTARY_ECORE_CON
9872    EINA_SAFETY_ON_NULL_RETURN(clas);
9873    clas->func.del = del;
9874 #else
9875    (void) clas;
9876    (void) del;
9877 #endif
9878 }
9879
9880 EAPI const char **
9881 elm_map_source_names_get(const Evas_Object *obj)
9882 {
9883 #ifdef HAVE_ELEMENTARY_ECORE_CON
9884    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
9885    Widget_Data *wd = elm_widget_data_get(obj);
9886
9887    if (!wd) return NULL;
9888    return wd->source_names;
9889 #else
9890    (void) obj;
9891    return NULL;
9892 =======
9893 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
9894 {
9895 #ifdef HAVE_ELEMENTARY_ECORE_CON
9896    ELM_CHECK_WIDTYPE(obj, widtype) ;
9897    Widget_Data *wd = elm_widget_data_get(obj);
9898    EINA_SAFETY_ON_NULL_RETURN(wd);
9899
9900    wd->track = eina_list_remove(wd->track, route);
9901    evas_object_del(route);
9902 #else
9903    (void) obj;
9904    (void) route;
9905 #endif
9906 }
9907 #else
9908 EAPI Evas_Object *
9909 elm_map_track_add(Evas_Object *obj __UNUSED__, void *emap __UNUSED__)
9910 {
9911    return NULL;
9912 }
9913
9914 EAPI void
9915 elm_map_track_remove(Evas_Object *obj __UNUSED__, Evas_Object *route __UNUSED__)
9916 {
9917 }
9918 #endif
9919
9920 /************************* Belows are deprecated APIs *************************/
9921 EAPI void
9922 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
9923 {
9924    elm_map_zoom_max_set(obj, zoom);
9925 }
9926
9927 EAPI int
9928 elm_map_source_zoom_max_get(const Evas_Object *obj)
9929 {
9930    return elm_map_zoom_max_get(obj);
9931 }
9932
9933 EAPI void
9934 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
9935 {
9936    elm_map_zoom_min_set(obj, zoom);
9937 }
9938
9939 EAPI int
9940 elm_map_source_zoom_min_get(const Evas_Object *obj)
9941 {
9942    return elm_map_zoom_min_get(obj);
9943 }
9944
9945 EAPI void
9946 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
9947 {
9948 #ifdef HAVE_ELEMENTARY_ECORE_CON
9949    ELM_CHECK_WIDTYPE(obj, widtype);
9950    Widget_Data *wd = elm_widget_data_get(obj);
9951    EINA_SAFETY_ON_NULL_RETURN(wd);
9952
9953    _coord_to_region_convert(wd, x, y, size, lon, lat);
9954 #else
9955    (void) obj;
9956    (void) x;
9957    (void) y;
9958    (void) size;
9959    (void) lon;
9960    (void) lat;
9961 #endif
9962 }
9963
9964 EAPI void
9965 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
9966 {
9967 #ifdef HAVE_ELEMENTARY_ECORE_CON
9968    ELM_CHECK_WIDTYPE(obj, widtype);
9969    Widget_Data *wd = elm_widget_data_get(obj);
9970    EINA_SAFETY_ON_NULL_RETURN(wd);
9971
9972    _region_to_coord_convert(wd, lon, lat, size, x, y);
9973 #else
9974    (void) obj;
9975    (void) lon;
9976    (void) lat;
9977    (void) size;
9978    (void) x;
9979    (void) y;
9980 >>>>>>> remotes/origin/upstream
9981 #endif
9982 }
9983
9984 EAPI void
9985 <<<<<<< HEAD
9986 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
9987 {
9988 #ifdef HAVE_ELEMENTARY_ECORE_CON
9989    ELM_CHECK_WIDTYPE(obj, widtype);
9990    Widget_Data *wd = elm_widget_data_get(obj);
9991    Map_Sources_Tab *s;
9992    Eina_List *l;
9993    int zoom;
9994
9995    if (!wd) return;
9996    if (wd->src)
9997      {
9998         if (!strcmp(wd->src->name, source_name)) return;
9999         if (!wd->src->url_cb) return;
10000      }
10001
10002    grid_clear_all(obj);
10003    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
10004      {
10005         if (!strcmp(s->name, source_name))
10006           {
10007              wd->src = s;
10008              break;
10009           }
10010      }
10011    zoom = wd->zoom;
10012    wd->zoom = -1;
10013
10014    if (wd->src)
10015      {
10016         if (wd->src->zoom_max < zoom)
10017           zoom = wd->src->zoom_max;
10018         if (wd->src->zoom_min > zoom)
10019           zoom = wd->src->zoom_min;
10020      }
10021    grid_create_all(obj);
10022    elm_map_zoom_set(obj, zoom);
10023 #else
10024    (void) obj;
10025    (void) source_name;
10026 #endif
10027 }
10028
10029 EAPI const char *
10030 elm_map_source_name_get(const Evas_Object *obj)
10031 {
10032 #ifdef HAVE_ELEMENTARY_ECORE_CON
10033    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10034    Widget_Data *wd = elm_widget_data_get(obj);
10035
10036    if ((!wd) || (!wd->src)) return NULL;
10037    return wd->src->name;
10038 #else
10039    (void) obj;
10040    return NULL;
10041 #endif
10042 }
10043
10044 EAPI void
10045 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
10046 {
10047 #ifdef HAVE_ELEMENTARY_ECORE_CON
10048    ELM_CHECK_WIDTYPE(obj, widtype);
10049    Widget_Data *wd = elm_widget_data_get(obj);
10050
10051    if (!wd) return;
10052    wd->route_source = source;
10053 #else
10054    (void) obj;
10055    (void) source;
10056 #endif
10057 }
10058
10059 EAPI Elm_Map_Route_Sources
10060 elm_map_route_source_get(const Evas_Object *obj)
10061 {
10062 #ifdef HAVE_ELEMENTARY_ECORE_CON
10063    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
10064    Widget_Data *wd = elm_widget_data_get(obj);
10065
10066    if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
10067    return wd->route_source;
10068 #else
10069    (void) obj;
10070    return ELM_MAP_ROUTE_SOURCE_YOURS;
10071 =======
10072 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)
10073 {
10074 #ifdef HAVE_ELEMENTARY_ECORE_CON
10075    ELM_CHECK_WIDTYPE(obj, widtype);
10076    _coord_rotate(x, y, cx, cy, degree, xx, yy);
10077 #else
10078    (void) x;
10079    (void) y;
10080    (void) cx;
10081    (void) cy;
10082    (void) degree;
10083    (void) xx;
10084    (void) yy;
10085 #endif
10086 }
10087
10088 EAPI void
10089 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
10090 {
10091    elm_map_tile_load_status_get(obj, try_num, finish_num);
10092 }
10093
10094 EAPI void
10095 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
10096 {
10097    elm_map_region_bring_in(obj, lon, lat);
10098 }
10099
10100 EAPI void
10101 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
10102 {
10103    elm_map_region_show(obj, lon, lat);
10104 }
10105
10106 EAPI void
10107 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
10108 {
10109    elm_map_region_get(obj, lon, lat);
10110 }
10111
10112 EAPI Elm_Map_Name *
10113 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
10114 {
10115    return elm_map_name_add(obj, NULL, lon, lat, NULL, NULL);
10116 }
10117
10118 EAPI Elm_Map_Name *
10119 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
10120 {
10121    return elm_map_name_add(obj, address, 0, 0, NULL, NULL);
10122 }
10123
10124 EAPI void
10125 elm_map_canvas_to_geo_convert(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, double *lon, double *lat)
10126 {
10127    elm_map_canvas_to_region_convert(obj, x, y, lon, lat);
10128 }
10129
10130 EAPI Elm_Map_Marker *
10131 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *group_clas, void *data)
10132 {
10133 #ifdef HAVE_ELEMENTARY_ECORE_CON
10134    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10135    Widget_Data *wd = elm_widget_data_get(obj);
10136
10137    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
10138    EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
10139
10140    Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
10141    marker->wd = wd;
10142    marker->clas = clas;
10143    marker->group_clas = group_clas;
10144    marker->longitude = lon;
10145    marker->latitude = lat;
10146    marker->data = data;
10147    marker->x = 0;
10148    marker->y = 0;
10149    _edj_marker_size_get(wd, &marker->w, &marker->h);
10150
10151    marker->obj = elm_layout_add(wd->obj);
10152    evas_object_smart_member_add(marker->obj, wd->pan_smart);
10153    evas_object_stack_above(marker->obj, wd->sep_maps_markers);
10154
10155    edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
10156                                    "open", "elm", _marker_bubble_open_cb,
10157                                    marker);
10158    edje_object_signal_callback_add(elm_layout_edje_get(marker->obj),
10159                                    "bringin", "elm", _marker_bringin_cb,
10160                                    marker);
10161
10162    wd->markers = eina_list_append(wd->markers, marker);
10163    if (marker->group_clas) group_clas->markers = eina_list_append(group_clas->markers,
10164                                                                   marker);
10165    evas_object_smart_changed(wd->pan_smart);
10166    return marker;
10167 #else
10168    (void) obj;
10169    (void) lon;
10170    (void) lat;
10171    (void) clas;
10172    (void) group_clas;
10173    (void) data;
10174    return NULL;
10175 >>>>>>> remotes/origin/upstream
10176 #endif
10177 }
10178
10179 EAPI void
10180 <<<<<<< HEAD
10181 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
10182 {
10183 #ifdef HAVE_ELEMENTARY_ECORE_CON
10184    ELM_CHECK_WIDTYPE(obj, widtype);
10185    Widget_Data *wd = elm_widget_data_get(obj);
10186
10187    if ((!wd) || (!wd->src)) return;
10188    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
10189    wd->src->zoom_max = zoom;
10190 #else
10191    (void) obj;
10192    (void) zoom;
10193 #endif
10194 }
10195
10196 EAPI int
10197 elm_map_source_zoom_max_get(const Evas_Object *obj)
10198 {
10199 #ifdef HAVE_ELEMENTARY_ECORE_CON
10200    ELM_CHECK_WIDTYPE(obj, widtype) 18;
10201    Widget_Data *wd = elm_widget_data_get(obj);
10202
10203    if ((!wd) || (!wd->src)) return 18;
10204    return wd->src->zoom_max;
10205 #else
10206    (void) obj;
10207    return 18;
10208 =======
10209 elm_map_marker_remove(Elm_Map_Marker *marker)
10210 {
10211    _elm_map_marker_remove(marker);
10212 }
10213
10214 EAPI void
10215 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
10216 {
10217 #ifdef HAVE_ELEMENTARY_ECORE_CON
10218    EINA_SAFETY_ON_NULL_RETURN(marker);
10219    if (lon) *lon = marker->longitude;
10220    if (lat) *lat = marker->latitude;
10221 #else
10222    (void) marker;
10223    (void) lon;
10224    (void) lat;
10225 >>>>>>> remotes/origin/upstream
10226 #endif
10227 }
10228
10229 EAPI void
10230 <<<<<<< HEAD
10231 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
10232 {
10233 #ifdef HAVE_ELEMENTARY_ECORE_CON
10234    ELM_CHECK_WIDTYPE(obj, widtype);
10235    Widget_Data *wd = elm_widget_data_get(obj);
10236
10237    if ((!wd) || (!wd->src)) return;
10238    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
10239    wd->src->zoom_min = zoom;
10240 #else
10241    (void) obj;
10242    (void) zoom;
10243 #endif
10244 }
10245
10246 EAPI int
10247 elm_map_source_zoom_min_get(const Evas_Object *obj)
10248 {
10249 #ifdef HAVE_ELEMENTARY_ECORE_CON
10250    ELM_CHECK_WIDTYPE(obj, widtype) 0;
10251    Widget_Data *wd = elm_widget_data_get(obj);
10252
10253    if ((!wd) || (!wd->src)) return 0;
10254    return wd->src->zoom_min;
10255 #else
10256    (void) obj;
10257    return 0;
10258 =======
10259 elm_map_marker_bring_in(Elm_Map_Marker *marker)
10260 {
10261 #ifdef HAVE_ELEMENTARY_ECORE_CON
10262    EINA_SAFETY_ON_NULL_RETURN(marker);
10263    elm_map_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
10264 #else
10265    (void) marker;
10266 #endif
10267 }
10268
10269 EAPI void
10270 elm_map_marker_show(Elm_Map_Marker *marker)
10271 {
10272 #ifdef HAVE_ELEMENTARY_ECORE_CON
10273    EINA_SAFETY_ON_NULL_RETURN(marker);
10274    elm_map_region_show(marker->wd->obj, marker->longitude, marker->latitude);
10275 #else
10276    (void) marker;
10277 >>>>>>> remotes/origin/upstream
10278 #endif
10279 }
10280
10281 EAPI void
10282 <<<<<<< HEAD
10283 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
10284 {
10285 #ifdef HAVE_ELEMENTARY_ECORE_CON
10286    ELM_CHECK_WIDTYPE(obj, widtype);
10287    Widget_Data *wd = elm_widget_data_get(obj);
10288
10289    if (!wd) return;
10290    if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
10291    else eina_stringshare_replace(&wd->user_agent, user_agent);
10292
10293    if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
10294    eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
10295 #else
10296    (void) obj;
10297    (void) user_agent;
10298 #endif
10299 }
10300
10301 EAPI const char *
10302 elm_map_user_agent_get(const Evas_Object *obj)
10303 {
10304 #ifdef HAVE_ELEMENTARY_ECORE_CON
10305    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10306    Widget_Data *wd = elm_widget_data_get(obj);
10307
10308    if (!wd) return NULL;
10309    return wd->user_agent;
10310 #else
10311    (void) obj;
10312    return NULL;
10313 #endif
10314 }
10315
10316 EAPI Elm_Map_Route *
10317 elm_map_route_add(Evas_Object *obj,
10318                   Elm_Map_Route_Type type,
10319                   Elm_Map_Route_Method method,
10320                   double flon,
10321                   double flat,
10322                   double tlon,
10323                   double tlat)
10324 {
10325 #ifdef HAVE_ELEMENTARY_ECORE_CON
10326    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10327    Widget_Data *wd = elm_widget_data_get(obj);
10328    char buf[PATH_MAX];
10329    char *source;
10330    char *type_name = NULL;
10331    int fd;
10332
10333    if ((!wd) || (!wd->src)) return NULL;
10334
10335    Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
10336    if (!route) return NULL;
10337
10338    snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
10339    fd = mkstemp(buf);
10340    if (fd < 0)
10341      {
10342         free(route);
10343         return NULL;
10344      }
10345
10346    route->con_url = ecore_con_url_new(NULL);
10347    route->ud.fname = strdup(buf);
10348    INF("xml file : %s", route->ud.fname);
10349
10350    route->ud.fd = fdopen(fd, "w+");
10351    if ((!route->con_url) || (!route->ud.fd))
10352      {
10353         ecore_con_url_free(route->con_url);
10354         free(route);
10355         return NULL;
10356      }
10357
10358    route->wd = wd;
10359    route->color.r = 255;
10360    route->color.g = 0;
10361    route->color.b = 0;
10362    route->color.a = 255;
10363    route->handlers = eina_list_append
10364      (route->handlers, (void *)ecore_event_handler_add
10365          (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
10366
10367    route->inbound = EINA_FALSE;
10368    route->type = type;
10369    route->method = method;
10370    route->flon = flon;
10371    route->flat = flat;
10372    route->tlon = tlon;
10373    route->tlat = tlat;
10374
10375    switch (type)
10376      {
10377       case ELM_MAP_ROUTE_TYPE_MOTOCAR:
10378         type_name = strdup(ROUTE_TYPE_MOTORCAR);
10379         break;
10380       case ELM_MAP_ROUTE_TYPE_BICYCLE:
10381         type_name = strdup(ROUTE_TYPE_BICYCLE);
10382         break;
10383       case ELM_MAP_ROUTE_TYPE_FOOT:
10384         type_name = strdup(ROUTE_TYPE_FOOT);
10385         break;
10386       default:
10387         break;
10388      }
10389
10390    source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
10391    INF("route url = %s", source);
10392
10393    wd->route = eina_list_append(wd->route, route);
10394
10395    ecore_con_url_url_set(route->con_url, source);
10396    ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
10397    ecore_con_url_data_set(route->con_url, route);
10398    ecore_con_url_get(route->con_url);
10399    if (type_name) free(type_name);
10400    if (source) free(source);
10401
10402    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
10403                            "elm,state,busy,start", "elm");
10404    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
10405    return route;
10406 #else
10407    (void) obj;
10408    (void) type;
10409    (void) method;
10410    (void) flon;
10411    (void) flat;
10412    (void) tlon;
10413    (void) tlat;
10414    return NULL;
10415 =======
10416 elm_map_markers_list_show(Eina_List *markers)
10417 {
10418 #ifdef HAVE_ELEMENTARY_ECORE_CON
10419    EINA_SAFETY_ON_NULL_RETURN(markers);
10420    EINA_SAFETY_ON_FALSE_RETURN(eina_list_count(markers));
10421
10422    Elm_Map_Marker *marker;
10423    marker = eina_list_data_get(markers);
10424
10425    Delayed_Data *data = ELM_NEW(Delayed_Data);
10426    data->func = _marker_list_show;
10427    data->wd = marker->wd;
10428    data->markers = eina_list_clone(markers);
10429    data->wd->delayed_jobs = eina_list_append(data->wd->delayed_jobs, data);
10430    evas_object_smart_changed(data->wd->pan_smart);
10431 #else
10432    (void) markers;
10433 #endif
10434 }
10435
10436 EAPI void
10437 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
10438 {
10439 #ifdef HAVE_ELEMENTARY_ECORE_CON
10440    ELM_CHECK_WIDTYPE(obj, widtype);
10441    Widget_Data *wd = elm_widget_data_get(obj);
10442    EINA_SAFETY_ON_NULL_RETURN(wd);
10443
10444    if (wd->paused_markers == !!paused) return;
10445    wd->paused_markers = paused;
10446 #else
10447    (void) obj;
10448    (void) paused;
10449 #endif
10450 }
10451
10452 EAPI Eina_Bool
10453 elm_map_paused_markers_get(const Evas_Object *obj)
10454 {
10455 #ifdef HAVE_ELEMENTARY_ECORE_CON
10456    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
10457    Widget_Data *wd = elm_widget_data_get(obj);
10458    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
10459
10460    return wd->paused_markers;
10461 #else
10462    (void) obj;
10463    return EINA_FALSE;
10464 >>>>>>> remotes/origin/upstream
10465 #endif
10466 }
10467
10468 EAPI void
10469 <<<<<<< HEAD
10470 elm_map_route_remove(Elm_Map_Route *route)
10471 {
10472 #ifdef HAVE_ELEMENTARY_ECORE_CON
10473    EINA_SAFETY_ON_NULL_RETURN(route);
10474
10475    Path_Waypoint *w;
10476    Path_Node *n;
10477    Evas_Object *p;
10478    Ecore_Event_Handler *h;
10479
10480    EINA_LIST_FREE(route->path, p)
10481      {
10482         evas_object_del(p);
10483      }
10484
10485    EINA_LIST_FREE(route->waypoint, w)
10486      {
10487         if (w->point) eina_stringshare_del(w->point);
10488         free(w);
10489      }
10490
10491    EINA_LIST_FREE(route->nodes, n)
10492      {
10493         if (n->pos.address) eina_stringshare_del(n->pos.address);
10494         free(n);
10495      }
10496
10497    EINA_LIST_FREE(route->handlers, h)
10498      {
10499         ecore_event_handler_del(h);
10500      }
10501
10502    if (route->ud.fname)
10503      {
10504         ecore_file_remove(route->ud.fname);
10505         free(route->ud.fname);
10506         route->ud.fname = NULL;
10507      }
10508 #else
10509    (void) route;
10510 #endif
10511 }
10512
10513 EAPI void
10514 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
10515 {
10516 #ifdef HAVE_ELEMENTARY_ECORE_CON
10517    EINA_SAFETY_ON_NULL_RETURN(route);
10518    route->color.r = r;
10519    route->color.g = g;
10520    route->color.b = b;
10521    route->color.a = a;
10522 #else
10523    (void) route;
10524    (void) r;
10525    (void) g;
10526    (void) b;
10527    (void) a;
10528 =======
10529 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
10530 {
10531 #ifdef HAVE_ELEMENTARY_ECORE_CON
10532    ELM_CHECK_WIDTYPE(obj, widtype);
10533    Widget_Data *wd = elm_widget_data_get(obj);
10534    EINA_SAFETY_ON_NULL_RETURN(wd);
10535
10536    wd->markers_max_num = max;
10537 #else
10538    (void) obj;
10539    (void) max;
10540 #endif
10541 }
10542
10543 EAPI Evas_Object *
10544 elm_map_marker_object_get(const Elm_Map_Marker *marker)
10545 {
10546 #ifdef HAVE_ELEMENTARY_ECORE_CON
10547    EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
10548    return marker->content;
10549 #else
10550    (void) marker;
10551    return NULL;
10552 >>>>>>> remotes/origin/upstream
10553 #endif
10554 }
10555
10556 EAPI void
10557 <<<<<<< HEAD
10558 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
10559 {
10560 #ifdef HAVE_ELEMENTARY_ECORE_CON
10561    EINA_SAFETY_ON_NULL_RETURN(route);
10562    if (r) *r = route->color.r;
10563    if (g) *g = route->color.g;
10564    if (b) *b = route->color.b;
10565    if (a) *a = route->color.a;
10566 #else
10567    (void) route;
10568    (void) r;
10569    (void) g;
10570    (void) b;
10571    (void) a;
10572 #endif
10573 }
10574
10575 EAPI double
10576 elm_map_route_distance_get(const Elm_Map_Route *route)
10577 {
10578 #ifdef HAVE_ELEMENTARY_ECORE_CON
10579    EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
10580    return route->info.distance;
10581 #else
10582    (void) route;
10583    return 0.0;
10584 #endif
10585 }
10586
10587 EAPI const char*
10588 elm_map_route_node_get(const Elm_Map_Route *route)
10589 {
10590 #ifdef HAVE_ELEMENTARY_ECORE_CON
10591    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
10592    return route->info.nodes;
10593 #else
10594    (void) route;
10595    return NULL;
10596 #endif
10597 }
10598
10599 EAPI const char*
10600 elm_map_route_waypoint_get(const Elm_Map_Route *route)
10601 {
10602 #ifdef HAVE_ELEMENTARY_ECORE_CON
10603    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
10604    return route->info.waypoints;
10605 #else
10606    (void) route;
10607    return NULL;
10608 #endif
10609 }
10610
10611 EAPI const char *
10612 elm_map_name_address_get(const Elm_Map_Name *name)
10613 {
10614 #ifdef HAVE_ELEMENTARY_ECORE_CON
10615    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
10616    return name->address;
10617 #else
10618    (void) name;
10619 =======
10620 elm_map_marker_update(Elm_Map_Marker *marker)
10621 {
10622 #ifdef HAVE_ELEMENTARY_ECORE_CON
10623    EINA_SAFETY_ON_NULL_RETURN(marker);
10624    Widget_Data *wd = marker->wd;
10625    EINA_SAFETY_ON_NULL_RETURN(wd);
10626
10627    _marker_update(marker);
10628 #else
10629    (void) marker;
10630 #endif
10631 }
10632
10633 EAPI void
10634 elm_map_bubbles_close(Evas_Object *obj)
10635 {
10636 #ifdef HAVE_ELEMENTARY_ECORE_CON
10637    ELM_CHECK_WIDTYPE(obj, widtype);
10638    Widget_Data *wd = elm_widget_data_get(obj);
10639    EINA_SAFETY_ON_NULL_RETURN(wd);
10640
10641    Eina_List *l;
10642    Elm_Map_Marker *marker;
10643    EINA_LIST_FOREACH(wd->markers, l, marker)
10644      {
10645         if (marker->bubble) _bubble_free(marker->bubble);
10646         marker->bubble = NULL;
10647
10648         if (marker->group)
10649           {
10650              if (marker->group->bubble) _bubble_free(marker->group->bubble);
10651              marker->group->bubble = NULL;
10652           }
10653      }
10654 #else
10655    (void) obj;
10656 #endif
10657 }
10658
10659 EAPI Elm_Map_Group_Class *
10660 elm_map_group_class_new(Evas_Object *obj)
10661 {
10662 #ifdef HAVE_ELEMENTARY_ECORE_CON
10663    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10664    Widget_Data *wd = elm_widget_data_get(obj);
10665    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
10666
10667    Elm_Map_Group_Class *clas = ELM_NEW(Elm_Map_Group_Class);
10668    clas->wd = wd;
10669    clas->zoom_displayed = 0;
10670    clas->zoom_grouped = 255;
10671    eina_stringshare_replace(&clas->style, "radio");
10672
10673    wd->group_classes = eina_list_append(wd->group_classes, clas);
10674
10675    return clas;
10676 #else
10677    (void) obj;
10678 >>>>>>> remotes/origin/upstream
10679    return NULL;
10680 #endif
10681 }
10682
10683 EAPI void
10684 <<<<<<< HEAD
10685 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
10686 {
10687 #ifdef HAVE_ELEMENTARY_ECORE_CON
10688    EINA_SAFETY_ON_NULL_RETURN(name);
10689    if (lon) *lon = name->lon;
10690    if (lat) *lat = name->lat;
10691 #else
10692    (void) name;
10693    (void) lon;
10694    (void) lat;
10695 =======
10696 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
10697 {
10698 #ifdef HAVE_ELEMENTARY_ECORE_CON
10699    EINA_SAFETY_ON_NULL_RETURN(clas);
10700    eina_stringshare_replace(&clas->style, style);
10701 #else
10702    (void) clas;
10703    (void) style;
10704 >>>>>>> remotes/origin/upstream
10705 #endif
10706 }
10707
10708 EAPI void
10709 <<<<<<< HEAD
10710 elm_map_name_remove(Elm_Map_Name *name)
10711 {
10712 #ifdef HAVE_ELEMENTARY_ECORE_CON
10713    EINA_SAFETY_ON_NULL_RETURN(name);
10714    if (name->address)
10715      {
10716         free(name->address);
10717         name->address = NULL;
10718      }
10719    if (name->handler)
10720      {
10721         ecore_event_handler_del(name->handler);
10722         name->handler = NULL;
10723      }
10724    if (name->ud.fname)
10725      {
10726         ecore_file_remove(name->ud.fname);
10727         free(name->ud.fname);
10728         name->ud.fname = NULL;
10729      }
10730 #else
10731    (void) name;
10732 =======
10733 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, Elm_Map_Group_Icon_Get_Func icon_get)
10734 {
10735 #ifdef HAVE_ELEMENTARY_ECORE_CON
10736    EINA_SAFETY_ON_NULL_RETURN(clas);
10737    clas->func.icon_get = icon_get;
10738 #else
10739    (void) clas;
10740    (void) icon_get;
10741 >>>>>>> remotes/origin/upstream
10742 #endif
10743 }
10744
10745 EAPI void
10746 <<<<<<< HEAD
10747 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
10748 {
10749 #ifdef HAVE_ELEMENTARY_ECORE_CON
10750    ELM_CHECK_WIDTYPE(obj, widtype);
10751    Widget_Data *wd = elm_widget_data_get(obj);
10752
10753    if (!wd) return;
10754    wd->rotate.d = degree;
10755    wd->rotate.cx = cx;
10756    wd->rotate.cy = cy;
10757    wd->calc_job = ecore_job_add(_calc_job, wd);
10758 #else
10759    (void) obj;
10760    (void) degree;
10761    (void) cx;
10762    (void) cy;
10763 =======
10764 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
10765 {
10766 #ifdef HAVE_ELEMENTARY_ECORE_CON
10767    EINA_SAFETY_ON_NULL_RETURN(clas);
10768    clas->data = data;
10769 #else
10770    (void) clas;
10771    (void) data;
10772 >>>>>>> remotes/origin/upstream
10773 #endif
10774 }
10775
10776 EAPI void
10777 <<<<<<< HEAD
10778 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
10779 {
10780 #ifdef HAVE_ELEMENTARY_ECORE_CON
10781    ELM_CHECK_WIDTYPE(obj, widtype);
10782    Widget_Data *wd = elm_widget_data_get(obj);
10783
10784    if (!wd) return;
10785    if (degree) *degree = wd->rotate.d;
10786    if (cx) *cx = wd->rotate.cx;
10787    if (cy) *cy = wd->rotate.cy;
10788 #else
10789    (void) obj;
10790    (void) degree;
10791    (void) cx;
10792    (void) cy;
10793 =======
10794 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
10795 {
10796 #ifdef HAVE_ELEMENTARY_ECORE_CON
10797    EINA_SAFETY_ON_NULL_RETURN(clas);
10798    clas->zoom_displayed = zoom;
10799 #else
10800    (void) clas;
10801    (void) zoom;
10802 >>>>>>> remotes/origin/upstream
10803 #endif
10804 }
10805
10806 EAPI void
10807 <<<<<<< HEAD
10808 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
10809 {
10810 #ifdef HAVE_ELEMENTARY_ECORE_CON
10811    ELM_CHECK_WIDTYPE(obj, widtype);
10812    Widget_Data *wd = elm_widget_data_get(obj);
10813
10814    if (!wd) return;
10815    if ((!wd->wheel_disabled) && (disabled))
10816      evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
10817    else if ((wd->wheel_disabled) && (!disabled))
10818      evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
10819    wd->wheel_disabled = !!disabled;
10820 #else
10821    (void) obj;
10822    (void) disabled;
10823 #endif
10824 }
10825
10826 EAPI Eina_Bool
10827 elm_map_wheel_disabled_get(const Evas_Object *obj)
10828 {
10829 #ifdef HAVE_ELEMENTARY_ECORE_CON
10830    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
10831    Widget_Data *wd = elm_widget_data_get(obj);
10832
10833    if (!wd) return EINA_FALSE;
10834    return wd->wheel_disabled;
10835 #else
10836    (void) obj;
10837    return EINA_FALSE;
10838 #endif
10839 }
10840
10841 #ifdef ELM_EMAP
10842 EAPI Evas_Object *
10843 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
10844 =======
10845 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
10846 {
10847 #ifdef HAVE_ELEMENTARY_ECORE_CON
10848    EINA_SAFETY_ON_NULL_RETURN(clas);
10849    clas->zoom_grouped = zoom;
10850 #else
10851    (void) clas;
10852    (void) zoom;
10853 #endif
10854 }
10855
10856 EAPI void
10857 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
10858 {
10859 #ifdef HAVE_ELEMENTARY_ECORE_CON
10860    ELM_CHECK_WIDTYPE(obj, widtype);
10861    Widget_Data *wd = elm_widget_data_get(obj);
10862    EINA_SAFETY_ON_NULL_RETURN(wd);
10863    EINA_SAFETY_ON_NULL_RETURN(clas);
10864
10865    clas->hide = hide;
10866    evas_object_smart_changed(wd->pan_smart);
10867 #else
10868    (void) obj;
10869    (void) clas;
10870    (void) hide;
10871 #endif
10872 }
10873
10874 EAPI Elm_Map_Marker_Class *
10875 elm_map_marker_class_new(Evas_Object *obj)
10876 >>>>>>> remotes/origin/upstream
10877 {
10878 #ifdef HAVE_ELEMENTARY_ECORE_CON
10879    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
10880    Widget_Data *wd = elm_widget_data_get(obj);
10881 <<<<<<< HEAD
10882
10883    if (!wd) return EINA_FALSE;
10884
10885    Evas_Object *route = elm_route_add(obj);
10886    elm_route_emap_set(route, emap);
10887    wd->track = eina_list_append(wd->track, route);
10888
10889    return route;
10890 #else
10891    (void) obj;
10892    (void) emap;
10893    return NULL;
10894 #endif
10895 }
10896 #endif
10897
10898 EAPI void
10899 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
10900 {
10901 #ifdef HAVE_ELEMENTARY_ECORE_CON
10902    ELM_CHECK_WIDTYPE(obj, widtype) ;
10903    Widget_Data *wd = elm_widget_data_get(obj);
10904
10905    if (!wd) return ;
10906
10907    wd->track = eina_list_remove(wd->track, route);
10908    evas_object_del(route);
10909 #else
10910    (void) obj;
10911    (void) route;
10912 #endif
10913 }
10914
10915 #ifdef HAVE_ELEMENTARY_ECORE_CON
10916
10917 static char *
10918 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
10919 {
10920    char buf[PATH_MAX];
10921    // ((x+y+zoom)%3)+'a' is requesting map images from distributed tile servers (eg., a, b, c)
10922    snprintf(buf, sizeof(buf), "http://%c.tile.openstreetmap.org/%d/%d/%d.png", ((x+y+zoom)%3)+'a', zoom, x, y);
10923    return strdup(buf);
10924 }
10925
10926 static char *
10927 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
10928 {
10929    char buf[PATH_MAX];
10930    snprintf(buf, sizeof(buf), "http://%c.tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png", ((x+y+zoom)%3)+'a', zoom, x, y);
10931    return strdup(buf);
10932 }
10933
10934 static char *
10935 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
10936 {
10937    char buf[PATH_MAX];
10938    snprintf(buf, sizeof(buf), "http://%c.tile.opencyclemap.org/cycle/%d/%d/%d.png", ((x+y+zoom)%3)+'a', zoom, x, y);
10939    return strdup(buf);
10940 }
10941
10942 static char *
10943 _mapquest_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
10944 {
10945    char buf[PATH_MAX];
10946    snprintf(buf, sizeof(buf), "http://otile%d.mqcdn.com/tiles/1.0.0/osm/%d/%d/%d.png", ((x+y+zoom)%4)+1, zoom, x, y);
10947    return strdup(buf);
10948 }
10949
10950 static char *
10951 _mapquest_aerial_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
10952 {
10953    char buf[PATH_MAX];
10954    snprintf(buf, sizeof(buf), "http://oatile%d.mqcdn.com/naip/%d/%d/%d.png", ((x+y+zoom)%4)+1, zoom, x, y);
10955    return strdup(buf);
10956 }
10957
10958 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
10959 {
10960    char buf[PATH_MAX];
10961    snprintf(buf, sizeof(buf),
10962             "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
10963             ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
10964
10965    return strdup(buf);
10966 }
10967
10968 // TODO: fix monav api
10969 /*
10970 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
10971 {
10972    char buf[PATH_MAX];
10973    snprintf(buf, sizeof(buf),
10974             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
10975             ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
10976
10977    return strdup(buf);
10978 }
10979 */
10980
10981 // TODO: fix ors api
10982 /*
10983 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
10984 {
10985    char buf[PATH_MAX];
10986    snprintf(buf, sizeof(buf),
10987             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
10988             ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
10989
10990    return strdup(buf);
10991 }
10992 */
10993
10994 static char *
10995 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
10996 {
10997    ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
10998    Widget_Data *wd = elm_widget_data_get(obj);
10999    char **str;
11000    unsigned int ele, idx;
11001    char search_url[PATH_MAX];
11002    char buf[PATH_MAX];
11003
11004    if (!wd) return strdup("");
11005    if (method == ELM_MAP_NAME_METHOD_SEARCH)
11006      {
11007         search_url[0] = '\0';
11008         str = eina_str_split_full(name, " ", 0, &ele);
11009         for (idx = 0 ; idx < ele ; idx++)
11010           {
11011              eina_strlcat(search_url, str[idx], sizeof(search_url));
11012              if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
11013           }
11014         snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
11015
11016         if (str && str[0])
11017           {
11018              free(str[0]);
11019              free(str);
11020           }
11021      }
11022    else if (method == ELM_MAP_NAME_METHOD_REVERSE) snprintf(buf, sizeof(buf), "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0", NAME_NOMINATIM_URL, lat, lon, wd->zoom);
11023    else strcpy(buf, "");
11024
11025    return strdup(buf);
11026 }
11027
11028 #endif
11029 =======
11030    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
11031
11032    Elm_Map_Marker_Class *clas = ELM_NEW(Elm_Map_Marker_Class);
11033    eina_stringshare_replace(&clas->style, "radio");
11034
11035    wd->marker_classes = eina_list_append(wd->marker_classes, clas);
11036    return clas;
11037 #else
11038    (void) obj;
11039    return NULL;
11040 #endif
11041 }
11042
11043 EAPI void
11044 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
11045 {
11046 #ifdef HAVE_ELEMENTARY_ECORE_CON
11047    EINA_SAFETY_ON_NULL_RETURN(clas);
11048    eina_stringshare_replace(&clas->style, style);
11049 #else
11050    (void) clas;
11051    (void) style;
11052 #endif
11053 }
11054
11055 EAPI void
11056 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Icon_Get_Func icon_get)
11057 {
11058 #ifdef HAVE_ELEMENTARY_ECORE_CON
11059    EINA_SAFETY_ON_NULL_RETURN(clas);
11060    clas->func.icon_get = icon_get;
11061 #else
11062    (void) clas;
11063    (void) icon_get;
11064 #endif
11065 }
11066
11067 EAPI void
11068 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Get_Func get)
11069 {
11070 #ifdef HAVE_ELEMENTARY_ECORE_CON
11071    EINA_SAFETY_ON_NULL_RETURN(clas);
11072    clas->func.get = get;
11073 #else
11074    (void) clas;
11075    (void) get;
11076 #endif
11077 }
11078
11079 EAPI void
11080 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, Elm_Map_Marker_Del_Func del)
11081 {
11082 #ifdef HAVE_ELEMENTARY_ECORE_CON
11083    EINA_SAFETY_ON_NULL_RETURN(clas);
11084    clas->func.del = del;
11085 #else
11086    (void) clas;
11087    (void) del;
11088 #endif
11089 }
11090
11091 EAPI void
11092 elm_map_route_color_set(Elm_Map_Route *route __UNUSED__, int r  __UNUSED__, int g  __UNUSED__, int b  __UNUSED__, int a  __UNUSED__)
11093 {
11094    return;
11095 }
11096
11097 EAPI void
11098 elm_map_route_color_get(const Elm_Map_Route *route __UNUSED__, int *r  __UNUSED__, int *g  __UNUSED__, int *b  __UNUSED__, int *a  __UNUSED__)
11099 {
11100    return;
11101 }
11102
11103 EAPI void
11104 elm_map_route_remove(Elm_Map_Route *route)
11105 {
11106    elm_map_route_del(route);
11107 }
11108
11109 EAPI void
11110 elm_map_name_remove(Elm_Map_Name *name)
11111 {
11112    elm_map_name_del(name);
11113 }
11114
11115 >>>>>>> remotes/origin/upstream