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