1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "maps_view_object.h"
20 #include "maps_view_object_plugin.h"
21 #include "maps_error.h"
22 #include "maps_util.h"
23 #include "maps_view.h"
24 #include "maps_extra_types.h"
25 #include "maps_condition.h"
26 #include "marker_constructor.h"
27 #include "polyline_constructor.h"
28 #include "polygon_constructor.h"
29 #include "overlay_constructor.h"
32 #define M_PI 3.14159265358979323846
36 * This represents marker visual object information
38 typedef struct _maps_view_marker_data_s {
39 maps_coordinates_h coordinates;
43 maps_view_marker_type_e type;
45 } maps_view_marker_data_s;
47 const gsize _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
50 * This represents polyline visual object information
52 typedef struct _maps_view_polyline_data_s {
53 /* The list of maps_coordinates_h points, comprising the polyline */
54 maps_coordinates_list_h points;
64 } maps_view_polyline_data_s;
67 * This represents polygon visual object information
69 typedef struct _maps_view_polygon_data_s {
70 /* The list of maps_coordinates_h points, comprising the polygon */
71 maps_coordinates_list_h points;
73 /* The polygon backgraund color */
78 } maps_view_polygon_data_s;
80 typedef struct _maps_view_overlay_data_s {
81 maps_coordinates_h coordinates;
85 maps_view_overlay_type_e type;
88 } maps_view_overlay_data_s;
90 const int _OVERLAY_BUBBLE_MARGIN = 20;
91 const int _OVERLAY_BUBBLE_PIN_SIZE = 20;
94 * This represents visual object information
96 typedef struct _maps_view_object_s {
97 maps_view_object_type_e type; /* marker, polyline, polygon, group */
98 void *shape_data; /* Pointer to the visual object data, such as
99 maps_view_marker_data_s or maps_view_polyline_data_s */
101 maps_view_object_h parent_group; /* The group, owning the object */
102 maps_view_h view; /* Link with the parent Map View */
103 } maps_view_object_s;
105 int _maps_view_on_object_operation(maps_view_h view, maps_view_object_h object,
106 maps_view_object_operation_e operation);
107 int _maps_view_get_parent(const maps_view_h view, Evas_Object **parent);
108 int _maps_view_get_clipper(const maps_view_h view, Evas_Object **clipper);
110 static maps_view_h __get_view(const maps_view_object_h object);
111 static maps_view_polyline_data_s *__get_polyline_data(const maps_view_object_h object);
112 static maps_view_polygon_data_s *__get_polygon_data(const maps_view_object_h object);
113 static maps_view_marker_data_s *__get_marker_data(const maps_view_object_h object);
114 static maps_view_overlay_data_s *__get_overlay_data(const maps_view_object_h object);
116 static int __maps_view_polyline_data_create(void **polyline);
117 static int __maps_view_polygon_data_create(void **polygon);
118 static int __maps_view_marker_data_create(void **marker);
119 static int __maps_view_overlay_data_create(void **marker);
121 static int __maps_view_polyline_data_destroy(void *polyline);
122 static int __maps_view_polygon_data_destroy(void *polygon);
123 static int __maps_view_marker_data_destroy(void *marker);
124 static int __maps_view_overlay_data_destroy(void *marker);
126 static maps_view_h __get_view(const maps_view_object_h object)
130 maps_view_object_s *o = (maps_view_object_s *)object;
134 static maps_view_polyline_data_s *__get_polyline_data(const maps_view_object_h object)
136 maps_view_object_s *o = (maps_view_object_s *)object;
137 if (!o || (o->type != MAPS_VIEW_OBJECT_POLYLINE))
139 return (maps_view_polyline_data_s *)o->shape_data;
142 static int __maps_view_polyline_data_create(void **polyline)
145 return MAPS_ERROR_INVALID_PARAMETER;
147 int error = MAPS_ERROR_NONE;
148 maps_view_polyline_data_s *p = NULL;
151 p = g_slice_new0(maps_view_polyline_data_s);
154 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
155 MAPS_ERROR_OUT_OF_MEMORY);
156 return MAPS_ERROR_OUT_OF_MEMORY;
160 error = maps_coordinates_list_create(&p->points);
161 if (error != MAPS_ERROR_NONE)
164 *polyline = (maps_view_polyline_data_s *) p;
165 return MAPS_ERROR_NONE;
169 __maps_view_polyline_data_destroy(p);
174 static int __maps_view_polyline_data_destroy(void *polyline)
177 return MAPS_ERROR_INVALID_PARAMETER;
179 maps_view_polyline_data_s *p = (maps_view_polyline_data_s *)polyline;
181 maps_coordinates_list_destroy(p->points);
183 g_slice_free(maps_view_polyline_data_s, p);
185 return MAPS_ERROR_NONE;
188 static maps_view_polygon_data_s *__get_polygon_data(const maps_view_object_h object)
190 maps_view_object_s *o = (maps_view_object_s *)object;
191 if (!o || (o->type != MAPS_VIEW_OBJECT_POLYGON))
193 return (maps_view_polygon_data_s *)o->shape_data;
196 static int __maps_view_polygon_data_create(void **polygon)
199 return MAPS_ERROR_INVALID_PARAMETER;
201 int error = MAPS_ERROR_NONE;
202 maps_view_polygon_data_s *p = NULL;
205 p = g_slice_new0(maps_view_polygon_data_s);
208 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
209 MAPS_ERROR_OUT_OF_MEMORY);
210 return MAPS_ERROR_OUT_OF_MEMORY;
214 error = maps_coordinates_list_create(&p->points);
215 if (error != MAPS_ERROR_NONE)
218 *polygon = (maps_view_polygon_data_s *) p;
219 return MAPS_ERROR_NONE;
223 __maps_view_polygon_data_destroy(p);
228 static int __maps_view_polygon_data_destroy(void *polygon)
231 return MAPS_ERROR_INVALID_PARAMETER;
233 maps_view_polygon_data_s *p = (maps_view_polygon_data_s *)polygon;
235 maps_coordinates_list_destroy(p->points);
237 g_slice_free(maps_view_polygon_data_s, p);
239 return MAPS_ERROR_NONE;
242 static maps_view_marker_data_s *__get_marker_data(const maps_view_object_h object)
244 maps_view_object_s *o = (maps_view_object_s *)object;
245 if (!o || (o->type != MAPS_VIEW_OBJECT_MARKER))
247 return (maps_view_marker_data_s *)o->shape_data;
250 static int __maps_view_marker_data_create(void **marker)
253 return MAPS_ERROR_INVALID_PARAMETER;
256 int error = MAPS_ERROR_NONE;
257 maps_view_marker_data_s *m = NULL;
260 m = g_slice_new0(maps_view_marker_data_s);
263 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
264 MAPS_ERROR_OUT_OF_MEMORY);
265 return MAPS_ERROR_OUT_OF_MEMORY;
269 error = maps_coordinates_create(.0, .0, &m->coordinates);
270 if (error != MAPS_ERROR_NONE)
273 m->type = MAPS_VIEW_MARKER_PIN;
277 *marker = (maps_view_marker_data_s *) m;
278 return MAPS_ERROR_NONE;
282 __maps_view_marker_data_destroy(m);
287 static int __maps_view_marker_data_destroy(void *marker)
290 return MAPS_ERROR_INVALID_PARAMETER;
292 maps_view_marker_data_s *m = (maps_view_marker_data_s *)marker;
294 maps_coordinates_destroy(m->coordinates);
297 g_free(m->file_path);
299 g_slice_free(maps_view_marker_data_s, m);
301 return MAPS_ERROR_NONE;
304 static maps_view_overlay_data_s *__get_overlay_data(const maps_view_object_h object)
306 maps_view_object_s *o = (maps_view_object_s *)object;
307 if (!o || (o->type != MAPS_VIEW_OBJECT_OVERLAY))
309 return (maps_view_overlay_data_s *)o->shape_data;
312 static int __maps_view_overlay_data_create(void **overlay)
315 return MAPS_ERROR_INVALID_PARAMETER;
317 int error = MAPS_ERROR_NONE;
318 maps_view_overlay_data_s *m = NULL;
321 m = g_slice_new0(maps_view_overlay_data_s);
324 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
325 MAPS_ERROR_OUT_OF_MEMORY);
326 return MAPS_ERROR_OUT_OF_MEMORY;
330 error = maps_coordinates_create(.0, .0, &m->coordinates);
331 if (error != MAPS_ERROR_NONE)
334 *overlay = (maps_view_overlay_data_s *) m;
335 return MAPS_ERROR_NONE;
339 __maps_view_overlay_data_destroy(m);
344 static int __maps_view_overlay_data_destroy(void *overlay)
347 return MAPS_ERROR_INVALID_PARAMETER;
349 maps_view_overlay_data_s *m = (maps_view_overlay_data_s *)overlay;
352 maps_coordinates_destroy(m->coordinates);
355 evas_object_del(m->object);
358 evas_object_del(m->bubble);
361 const Eina_List *clipees = evas_object_clipees_get(m->clipper);
362 if (!clipees || eina_list_count(clipees) == 0) {
363 evas_object_hide(m->clipper);
364 MAPS_LOGD("hide clipper");
368 g_slice_free(maps_view_overlay_data_s, m);
370 return MAPS_ERROR_NONE;
373 int _maps_view_object_create(maps_view_object_type_e type, maps_view_object_h *object)
376 return MAPS_ERROR_INVALID_PARAMETER;
377 if (type < MAPS_VIEW_OBJECT_POLYLINE || type > MAPS_VIEW_OBJECT_OVERLAY)
378 return MAPS_ERROR_INVALID_PARAMETER;
380 int error = MAPS_ERROR_NONE;
381 maps_view_object_s *o = NULL;
384 o = g_slice_new0(maps_view_object_s);
387 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
388 MAPS_ERROR_OUT_OF_MEMORY);
389 return MAPS_ERROR_OUT_OF_MEMORY;
397 int error = MAPS_ERROR_NONE;
399 case MAPS_VIEW_OBJECT_POLYLINE:
400 error = __maps_view_polyline_data_create(&o->shape_data);
402 case MAPS_VIEW_OBJECT_POLYGON:
403 error = __maps_view_polygon_data_create(&o->shape_data);
405 case MAPS_VIEW_OBJECT_MARKER:
406 error = __maps_view_marker_data_create(&o->shape_data);
408 case MAPS_VIEW_OBJECT_OVERLAY:
409 error = __maps_view_overlay_data_create(&o->shape_data);
415 if ((!o->shape_data) || (error != MAPS_ERROR_NONE))
418 /* Notify view, that the object was constructed */
420 _maps_view_on_object_operation(view,
422 MAPS_VIEW_OBJECT_ADD);*/
424 *object = (maps_view_object_h) o;
425 return MAPS_ERROR_NONE;
428 maps_view_object_destroy(o);
433 int _maps_view_object_set_view(maps_view_object_h object, maps_view_h view)
435 if (!object || !view)
436 return MAPS_ERROR_INVALID_PARAMETER;
438 maps_view_object_s *o = (maps_view_object_s *) object;
441 maps_view_object_type_e type;
442 maps_view_object_get_type(object, &type);
443 if (type == MAPS_VIEW_OBJECT_OVERLAY) {
444 int min_zoom = 0, max_zoom = 0;
445 maps_view_object_overlay_get_min_zoom_level(object, &min_zoom);
446 maps_view_object_overlay_get_max_zoom_level(object, &max_zoom);
448 maps_view_get_min_zoom_level(view, &min_zoom);
449 maps_view_object_overlay_set_min_zoom_level(object, min_zoom);
452 maps_view_get_max_zoom_level(view, &max_zoom);
453 maps_view_object_overlay_set_max_zoom_level(object, max_zoom);
456 return MAPS_ERROR_NONE;
459 EXPORT_API int maps_view_object_create_marker(maps_coordinates_h coordinates,
460 const char *image_file_path, maps_view_marker_type_e type, maps_view_object_h *marker)
462 if (!maps_condition_check_maps_feature())
463 return MAPS_ERROR_NOT_SUPPORTED;
464 if (!coordinates || !marker)
465 return MAPS_ERROR_INVALID_PARAMETER;
466 if (type < MAPS_VIEW_MARKER_PIN || type > MAPS_VIEW_MARKER_STICKER)
467 return MAPS_ERROR_INVALID_PARAMETER;
469 /* Create a Marker Visual Object */
470 view::marker_constructor mc;
471 *marker = mc.construct(coordinates, image_file_path, type);
472 if (mc.get_error() == MAPS_ERROR_NONE)
473 return mc.get_error();
475 /* Marker create failure */
476 maps_view_object_destroy(*marker);
478 return mc.get_error();
481 EXPORT_API int maps_view_object_create_polyline(maps_coordinates_list_h coordinates,
482 unsigned char r, unsigned char g, unsigned char b, unsigned char a, int width,
483 maps_view_object_h *polyline)
485 if (!maps_condition_check_maps_feature())
486 return MAPS_ERROR_NOT_SUPPORTED;
487 if (!coordinates || !polyline || width < 1 || width > 100)
488 return MAPS_ERROR_INVALID_PARAMETER;
490 /* Create a Polyline Visual Object */
491 view::polyline_constructor pc;
492 *polyline = pc.construct(coordinates, r, g, b, a, width);
493 if (pc.get_error() == MAPS_ERROR_NONE)
494 return pc.get_error();
496 /* Polyline create failure */
498 maps_view_object_destroy(*polyline);
500 return pc.get_error();
504 EXPORT_API int maps_view_object_create_polygon(maps_coordinates_list_h coordinates,
505 unsigned char r, unsigned char g, unsigned char b, unsigned char a, maps_view_object_h *polygon)
507 if (!maps_condition_check_maps_feature())
508 return MAPS_ERROR_NOT_SUPPORTED;
509 if (!coordinates || !polygon)
510 return MAPS_ERROR_INVALID_PARAMETER;
512 /* Create a Polygon Visual Object */
513 view::polygon_constructor pc;
514 *polygon = pc.construct(coordinates, r, g, b, a);
515 if (pc.get_error() == MAPS_ERROR_NONE)
516 return pc.get_error();
518 /* Polygon create failure */
520 maps_view_object_destroy(*polygon);
522 return pc.get_error();
526 EXPORT_API int maps_view_object_create_overlay(maps_coordinates_h coordinates,
527 Evas_Object *object, maps_view_overlay_type_e type, maps_view_object_h *overlay)
529 if (!maps_condition_check_maps_feature())
530 return MAPS_ERROR_NOT_SUPPORTED;
531 if (!overlay || !coordinates)
532 return MAPS_ERROR_INVALID_PARAMETER;
533 if (type < MAPS_VIEW_OVERLAY_NORMAL || type > MAPS_VIEW_OVERLAY_BOX)
534 return MAPS_ERROR_INVALID_PARAMETER;
537 maps_coordinates_get_latitude_longitude(coordinates, &lat, &lon);
539 /* Create a Overlay Visual Object */
540 view::overlay_constructor pc;
541 *overlay = pc.construct(coordinates, object, type);
542 if (pc.get_error() == MAPS_ERROR_NONE)
543 return pc.get_error();
545 /* Overlay create failure */
547 maps_view_object_destroy(*overlay);
549 return pc.get_error();
553 EXPORT_API int maps_view_object_destroy(maps_view_object_h object)
555 if (!maps_condition_check_maps_feature())
556 return MAPS_ERROR_NOT_SUPPORTED;
558 return MAPS_ERROR_INVALID_PARAMETER;
560 maps_view_object_s *o = (maps_view_object_s *) object;
562 /* Notify view, that the object is to be destroyed shortly */
563 _maps_view_on_object_operation(o->view, o, MAPS_VIEW_OBJECT_REMOVE);
565 int error = MAPS_ERROR_NONE;
567 case MAPS_VIEW_OBJECT_POLYLINE:
568 error = __maps_view_polyline_data_destroy(o->shape_data);
570 case MAPS_VIEW_OBJECT_POLYGON:
571 error = __maps_view_polygon_data_destroy(o->shape_data);
573 case MAPS_VIEW_OBJECT_MARKER:
574 error = __maps_view_marker_data_destroy(o->shape_data);
576 case MAPS_VIEW_OBJECT_OVERLAY:
577 error = __maps_view_overlay_data_destroy(o->shape_data);
582 g_slice_free(maps_view_object_s, object);
586 EXPORT_API int maps_view_object_get_type(maps_view_object_h object, maps_view_object_type_e *type)
588 if (!maps_condition_check_maps_feature())
589 return MAPS_ERROR_NOT_SUPPORTED;
590 if (!object || !type)
591 return MAPS_ERROR_INVALID_PARAMETER;
592 *type = ((maps_view_object_s *)object)->type;
593 return MAPS_ERROR_NONE;
598 * Visual Object Operations
601 EXPORT_API int maps_view_object_set_visible(maps_view_object_h object, bool visible)
603 if (!maps_condition_check_maps_feature())
604 return MAPS_ERROR_NOT_SUPPORTED;
606 return MAPS_ERROR_INVALID_PARAMETER;
607 maps_view_object_s *o = (maps_view_object_s *)object;
608 o->visible = visible;
610 /* Notify view, that the object visibility is changed */
611 _maps_view_on_object_operation(o->view, o, MAPS_VIEW_OBJECT_SET_VISIBLE);
613 return MAPS_ERROR_NONE;
616 EXPORT_API int maps_view_object_get_visible(const maps_view_object_h object, bool *visible)
618 if (!maps_condition_check_maps_feature())
619 return MAPS_ERROR_NOT_SUPPORTED;
620 if (!object || !visible)
621 return MAPS_ERROR_INVALID_PARAMETER;
622 maps_view_object_s *o = (maps_view_object_s *)object;
623 *visible = o->visible;
624 return MAPS_ERROR_NONE;
628 /*----------------------------------------------------------------------------*/
633 EXPORT_API int maps_view_object_polyline_set_polyline(maps_view_object_h polyline,
634 maps_coordinates_list_h points)
636 if (!maps_condition_check_maps_feature())
637 return MAPS_ERROR_NOT_SUPPORTED;
638 if (!polyline || !points)
639 return MAPS_ERROR_INVALID_PARAMETER;
641 /* Get the polyline data pointer */
642 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
644 return MAPS_ERROR_INVALID_PARAMETER;
646 /* Set new polyline trajectory */
647 if (p->points != points) {
648 maps_coordinates_list_destroy(p->points);
652 /* Notify view, that the object specific preferences is changed */
653 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
655 return MAPS_ERROR_NONE;
658 EXPORT_API int maps_view_object_polyline_foreach_point(maps_view_object_h polyline,
659 maps_coordinates_cb callback, void *user_data)
661 if (!maps_condition_check_maps_feature())
662 return MAPS_ERROR_NOT_SUPPORTED;
663 if (!polyline || !callback)
664 return MAPS_ERROR_INVALID_PARAMETER;
666 /* Get the polyline data pointer */
667 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
669 return MAPS_ERROR_INVALID_PARAMETER;
671 return MAPS_ERROR_NOT_FOUND;
673 /* Iterate over polyline trajectory */
674 return maps_coordinates_list_foreach(p->points, callback, user_data);
677 EXPORT_API int maps_view_object_polyline_set_color(maps_view_object_h polyline,
678 unsigned char r, unsigned char g, unsigned char b, unsigned char a)
680 if (!maps_condition_check_maps_feature())
681 return MAPS_ERROR_NOT_SUPPORTED;
683 return MAPS_ERROR_INVALID_PARAMETER;
685 /* Get the polyline data pointer */
686 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
688 return MAPS_ERROR_INVALID_PARAMETER;
696 /* Notify view, that the object specific preferences is changed */
697 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
699 return MAPS_ERROR_NONE;
702 EXPORT_API int maps_view_object_polyline_get_color(const maps_view_object_h polyline,
703 unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
705 if (!maps_condition_check_maps_feature())
706 return MAPS_ERROR_NOT_SUPPORTED;
707 if (!polyline || (!r && !g && !b && !a))
708 return MAPS_ERROR_INVALID_PARAMETER;
710 /* Get the polyline data pointer */
711 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
713 return MAPS_ERROR_INVALID_PARAMETER;
715 /* Retrieve the color */
724 return MAPS_ERROR_NONE;
728 EXPORT_API int maps_view_object_polyline_set_width(maps_view_object_h polyline, int width)
730 if (!maps_condition_check_maps_feature())
731 return MAPS_ERROR_NOT_SUPPORTED;
733 return MAPS_ERROR_INVALID_PARAMETER;
734 if (width < 0 || width > 100)
735 return MAPS_ERROR_INVALID_PARAMETER;
737 /* Get the polyline data pointer */
738 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
740 return MAPS_ERROR_INVALID_PARAMETER;
742 /* Update the width of polyline */
745 /* Notify view, that the object specific preferences is changed */
746 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
748 return MAPS_ERROR_NONE;
751 EXPORT_API int maps_view_object_polyline_get_width(const maps_view_object_h polyline, int *width)
753 if (!maps_condition_check_maps_feature())
754 return MAPS_ERROR_NOT_SUPPORTED;
755 if (!polyline || !width)
756 return MAPS_ERROR_INVALID_PARAMETER;
758 /* Get the polyline data pointer */
759 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
761 return MAPS_ERROR_INVALID_PARAMETER;
763 /* Retrieve the width of the polyline */
765 return MAPS_ERROR_NONE;
768 /*----------------------------------------------------------------------------*/
773 EXPORT_API int maps_view_object_polygon_set_polygon(maps_view_object_h polygon, maps_coordinates_list_h points)
775 if (!maps_condition_check_maps_feature())
776 return MAPS_ERROR_NOT_SUPPORTED;
777 if (!polygon || !points)
778 return MAPS_ERROR_INVALID_PARAMETER;
780 /* Get the polygon data pointer */
781 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
783 return MAPS_ERROR_INVALID_PARAMETER;
785 /* Set new polygon border */
786 if (p->points != points) {
787 maps_coordinates_list_destroy(p->points);
791 /* Notify view, that the object specific preferences is changed */
792 _maps_view_on_object_operation(__get_view(polygon), polygon, MAPS_VIEW_OBJECT_CHANGE);
794 return MAPS_ERROR_NONE;
797 EXPORT_API int maps_view_object_polygon_foreach_point(maps_view_object_h polygon,
798 maps_coordinates_cb callback, void *user_data)
800 if (!maps_condition_check_maps_feature())
801 return MAPS_ERROR_NOT_SUPPORTED;
802 if (!polygon || !callback)
803 return MAPS_ERROR_INVALID_PARAMETER;
805 /* Get the polygon data pointer */
806 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
808 return MAPS_ERROR_INVALID_PARAMETER;
810 return MAPS_ERROR_NOT_FOUND;
812 /* Iterate over polygon border */
813 return maps_coordinates_list_foreach(p->points, callback, user_data);
817 EXPORT_API int maps_view_object_polygon_set_fill_color(maps_view_object_h polygon,
818 unsigned char r, unsigned char g, unsigned char b, unsigned char a)
820 if (!maps_condition_check_maps_feature())
821 return MAPS_ERROR_NOT_SUPPORTED;
823 return MAPS_ERROR_INVALID_PARAMETER;
825 /* Get the polygon data pointer */
826 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
828 return MAPS_ERROR_INVALID_PARAMETER;
830 /* Set new background color */
836 /* Notify view, that the object specific preferences is changed */
837 _maps_view_on_object_operation(__get_view(polygon), polygon, MAPS_VIEW_OBJECT_CHANGE);
839 return MAPS_ERROR_NONE;
842 EXPORT_API int maps_view_object_polygon_get_fill_color(const maps_view_object_h polygon,
843 unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
845 if (!maps_condition_check_maps_feature())
846 return MAPS_ERROR_NOT_SUPPORTED;
847 if (!polygon || (!r && !g && !b && !a))
848 return MAPS_ERROR_INVALID_PARAMETER;
850 /* Get the polygon data pointer */
851 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
853 return MAPS_ERROR_INVALID_PARAMETER;
855 /* Retrieve the background color */
864 return MAPS_ERROR_NONE;
868 /*----------------------------------------------------------------------------*/
873 EXPORT_API int maps_view_object_marker_set_coordinates(maps_view_object_h marker,
874 maps_coordinates_h coordinates)
876 if (!maps_condition_check_maps_feature())
877 return MAPS_ERROR_NOT_SUPPORTED;
878 if (!marker || !coordinates)
879 return MAPS_ERROR_INVALID_PARAMETER;
880 maps_view_marker_data_s *m = __get_marker_data(marker);
882 return MAPS_ERROR_INVALID_PARAMETER;
884 /* Set new coordinates */
885 if (m->coordinates != coordinates) {
886 maps_coordinates_destroy(m->coordinates);
887 m->coordinates = coordinates;
890 /* Notify view, that the object specific preferences is changed */
891 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
893 return MAPS_ERROR_NONE;
896 EXPORT_API int maps_view_object_marker_resize(maps_view_object_h marker, int width, int height)
898 if (!maps_condition_check_maps_feature())
899 return MAPS_ERROR_NOT_SUPPORTED;
900 if (!marker || width < 0 || height < 0)
901 return MAPS_ERROR_INVALID_PARAMETER;
902 maps_view_marker_data_s *m = __get_marker_data(marker);
904 return MAPS_ERROR_INVALID_PARAMETER;
908 /* Notify view, that the object specific preferences is changed */
909 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
911 return MAPS_ERROR_NONE;
914 EXPORT_API int maps_view_object_marker_set_image_file(maps_view_object_h marker, const char *file_path)
916 if (!maps_condition_check_maps_feature())
917 return MAPS_ERROR_NOT_SUPPORTED;
918 if (!marker || !file_path)
919 return MAPS_ERROR_INVALID_PARAMETER;
920 maps_view_marker_data_s *m = __get_marker_data(marker);
922 return MAPS_ERROR_INVALID_PARAMETER;
923 const int error = maps_set_string(file_path, _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH, &m->file_path);
925 /* Notify view, that the object specific preferences is changed */
926 if (error == MAPS_ERROR_NONE) {
927 maps_view_object_marker_set_size(marker, 0, 0);
928 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
934 EXPORT_API int maps_view_object_marker_get_image_file(const maps_view_object_h marker, char **file_path)
936 if (!maps_condition_check_maps_feature())
937 return MAPS_ERROR_NOT_SUPPORTED;
938 if (!marker || !file_path)
939 return MAPS_ERROR_INVALID_PARAMETER;
940 maps_view_marker_data_s *m = __get_marker_data(marker);
942 return MAPS_ERROR_INVALID_PARAMETER;
943 return maps_get_string(m->file_path, _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH, file_path);
946 EXPORT_API int maps_view_object_marker_get_coordinates(const maps_view_object_h marker, maps_coordinates_h *coordinates)
948 if (!maps_condition_check_maps_feature())
949 return MAPS_ERROR_NOT_SUPPORTED;
950 if (!marker || !coordinates)
951 return MAPS_ERROR_INVALID_PARAMETER;
952 maps_view_marker_data_s *m = __get_marker_data(marker);
954 return MAPS_ERROR_INVALID_PARAMETER;
955 return maps_coordinates_clone(m->coordinates, coordinates);
958 EXPORT_API int maps_view_object_marker_set_size(maps_view_object_h marker, int width, int height)
960 if (!maps_condition_check_maps_feature())
961 return MAPS_ERROR_NOT_SUPPORTED;
962 if (!marker || width < 0 || height < 0)
963 return MAPS_ERROR_INVALID_PARAMETER;
964 maps_view_marker_data_s *m = __get_marker_data(marker);
966 return MAPS_ERROR_INVALID_PARAMETER;
969 return MAPS_ERROR_NONE;
972 EXPORT_API int maps_view_object_marker_get_size(const maps_view_object_h marker, int *width, int *height)
974 if (!maps_condition_check_maps_feature())
975 return MAPS_ERROR_NOT_SUPPORTED;
976 if (!marker || (!width && !height))
977 return MAPS_ERROR_INVALID_PARAMETER;
978 maps_view_marker_data_s *m = __get_marker_data(marker);
980 return MAPS_ERROR_INVALID_PARAMETER;
985 return MAPS_ERROR_NONE;
988 int _maps_view_object_marker_set_type(maps_view_object_h marker, maps_view_marker_type_e type)
991 return MAPS_ERROR_INVALID_PARAMETER;
992 if ((type < MAPS_VIEW_MARKER_PIN) || (type > MAPS_VIEW_MARKER_STICKER))
993 return MAPS_ERROR_INVALID_PARAMETER;
994 maps_view_marker_data_s *m = __get_marker_data(marker);
996 return MAPS_ERROR_INVALID_PARAMETER;
998 return MAPS_ERROR_NONE;
1001 EXPORT_API int maps_view_object_marker_get_type(const maps_view_object_h marker, maps_view_marker_type_e *type)
1003 if (!maps_condition_check_maps_feature())
1004 return MAPS_ERROR_NOT_SUPPORTED;
1005 if (!marker || !type)
1006 return MAPS_ERROR_INVALID_PARAMETER;
1007 maps_view_marker_data_s *m = __get_marker_data(marker);
1009 return MAPS_ERROR_INVALID_PARAMETER;
1011 return MAPS_ERROR_NONE;
1014 EXPORT_API int maps_view_object_marker_set_z_order(maps_view_object_h marker, int z_order)
1016 if (!maps_condition_check_maps_feature())
1017 return MAPS_ERROR_NOT_SUPPORTED;
1018 if (!marker || (z_order > 100 || z_order < -100))
1019 return MAPS_ERROR_INVALID_PARAMETER;
1020 maps_view_marker_data_s *m = __get_marker_data(marker);
1022 return MAPS_ERROR_INVALID_PARAMETER;
1024 /* Notify view, that the object specific preferences is changed */
1025 if (m->z_order != z_order) {
1026 m->z_order = z_order;
1027 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
1030 return MAPS_ERROR_NONE;
1033 EXPORT_API int maps_view_object_marker_get_z_order(const maps_view_object_h marker, int *z_order)
1035 if (!maps_condition_check_maps_feature())
1036 return MAPS_ERROR_NOT_SUPPORTED;
1037 if (!marker || !z_order)
1038 return MAPS_ERROR_INVALID_PARAMETER;
1039 maps_view_marker_data_s *m = __get_marker_data(marker);
1041 return MAPS_ERROR_INVALID_PARAMETER;
1043 *z_order = m->z_order;
1044 return MAPS_ERROR_NONE;
1047 int _maps_view_object_overlay_set_type(maps_view_object_h overlay, maps_view_overlay_type_e type)
1049 if (!overlay || (type < MAPS_VIEW_OVERLAY_NORMAL || type > MAPS_VIEW_OVERLAY_BOX))
1050 return MAPS_ERROR_INVALID_PARAMETER;
1051 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1053 return MAPS_ERROR_INVALID_PARAMETER;
1055 return MAPS_ERROR_NONE;
1059 int _maps_view_object_overlay_get_bubble(maps_view_object_h overlay, Evas_Object **object)
1061 if (!overlay || !object)
1062 return MAPS_ERROR_INVALID_PARAMETER;
1063 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1065 return MAPS_ERROR_INVALID_PARAMETER;
1066 *object = m->bubble;
1067 return MAPS_ERROR_NONE;
1071 int _maps_view_object_overlay_set_bubble(maps_view_object_h overlay)
1074 return MAPS_ERROR_INVALID_PARAMETER;
1075 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1077 return MAPS_ERROR_INVALID_PARAMETER;
1080 evas_object_geometry_get(m->object, &x, &y, &w, &h);
1082 w += _OVERLAY_BUBBLE_MARGIN * 2;
1083 h += _OVERLAY_BUBBLE_MARGIN * 2 + _OVERLAY_BUBBLE_PIN_SIZE;
1085 m->bubble = evas_object_image_filled_add(evas_object_evas_get(m->object));
1086 evas_object_stack_below(m->bubble, m->object);
1087 evas_object_move(m->bubble, x, y);
1088 evas_object_resize(m->bubble, w, h);
1089 evas_object_show(m->bubble);
1091 unsigned char *pixels;
1094 cairo_surface_t *surface;
1096 evas_object_image_alpha_set(m->bubble, EINA_TRUE);
1097 evas_object_image_colorspace_set(m->bubble, EVAS_COLORSPACE_ARGB8888);
1098 evas_object_image_size_set(m->bubble, w, h);
1099 evas_object_image_fill_set(m->bubble, 0, 0, w, h);
1101 pixels = (unsigned char *)evas_object_image_data_get(m->bubble, EINA_TRUE);
1102 row_stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w);
1103 surface = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32,
1105 /* Create the cairo context */
1106 cairo = cairo_create(surface);
1109 cairo_set_source_rgba(cairo, 0, 0, 0, 0);
1110 cairo_paint_with_alpha(cairo, 0);
1112 /* set the size of bubble */
1115 int bw = w - bx * 2;
1116 int bh = h - by - _OVERLAY_BUBBLE_PIN_SIZE;
1119 cairo_new_path(cairo);
1120 if (m->type == MAPS_VIEW_OVERLAY_BUBBLE) {
1122 double d = M_PI / 180.;
1123 cairo_arc(cairo, bx + bw - r, by + r, r, -90 * d, 0 * d);
1124 cairo_arc(cairo, bx + bw - r, by + bh - r, r, 0 * d, 90 * d);
1125 cairo_line_to(cairo, bx + bw / 2 + _OVERLAY_BUBBLE_PIN_SIZE, by + bh);
1126 cairo_line_to(cairo, bx + bw / 2, by + bh + _OVERLAY_BUBBLE_PIN_SIZE);
1127 cairo_line_to(cairo, bx + bw / 2 - _OVERLAY_BUBBLE_PIN_SIZE, by + bh);
1128 cairo_arc(cairo, bx + r, by + bh - r, r, 90 * d, 180 * d);
1129 cairo_arc(cairo, bx + r, by + r, r, 180 * d, 270 * d);
1131 cairo_move_to(cairo, 1., 1.);
1132 cairo_line_to(cairo, 1., bh);
1133 cairo_line_to(cairo, bw / 2 - _OVERLAY_BUBBLE_PIN_SIZE, bh);
1134 cairo_line_to(cairo, bw / 2, bh + _OVERLAY_BUBBLE_PIN_SIZE);
1135 cairo_line_to(cairo, bw / 2 + _OVERLAY_BUBBLE_PIN_SIZE, bh);
1136 cairo_line_to(cairo, bw, bh);
1137 cairo_line_to(cairo, bw, 1);
1139 cairo_close_path(cairo);
1142 cairo_clip_preserve(cairo);
1143 cairo_set_source_rgb(cairo, 1., 1., 1.);
1144 cairo_fill_preserve(cairo);
1145 cairo_set_source_rgb(cairo, .1, .1, .1);
1146 cairo_set_line_width(cairo, 3);
1149 cairo_stroke(cairo);
1150 cairo_destroy(cairo);
1151 cairo_surface_destroy(surface);
1153 evas_object_image_data_set(m->bubble, pixels);
1154 evas_object_image_data_update_add(m->bubble, 0, 0, w, h);
1156 return MAPS_ERROR_NONE;
1159 EXPORT_API int maps_view_object_overlay_get_object(maps_view_object_h overlay, Evas_Object **object)
1161 if (!maps_condition_check_maps_feature())
1162 return MAPS_ERROR_NOT_SUPPORTED;
1163 if (!overlay || !object)
1164 return MAPS_ERROR_INVALID_PARAMETER;
1165 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1167 return MAPS_ERROR_INVALID_PARAMETER;
1168 *object = m->object;
1169 return MAPS_ERROR_NONE;
1172 int _maps_view_object_overlay_set_object(maps_view_object_h overlay, Evas_Object *object)
1174 if (!overlay || !object)
1175 return MAPS_ERROR_INVALID_PARAMETER;
1176 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1178 return MAPS_ERROR_INVALID_PARAMETER;
1180 if (m->type != MAPS_VIEW_OVERLAY_NORMAL)
1181 _maps_view_object_overlay_set_bubble(overlay);
1183 return MAPS_ERROR_NONE;
1186 EXPORT_API int maps_view_object_overlay_set_coordinates(maps_view_object_h overlay, maps_coordinates_h coordinates)
1188 if (!maps_condition_check_maps_feature())
1189 return MAPS_ERROR_NOT_SUPPORTED;
1190 if (!overlay || !coordinates)
1191 return MAPS_ERROR_INVALID_PARAMETER;
1192 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1194 return MAPS_ERROR_INVALID_PARAMETER;
1196 if (m->coordinates != coordinates) {
1197 maps_coordinates_destroy(m->coordinates);
1198 m->coordinates = coordinates;
1201 /* Notify view, that the object specific preferences is changed */
1202 _maps_view_on_object_operation(__get_view(overlay), overlay, MAPS_VIEW_OBJECT_CHANGE);
1204 return MAPS_ERROR_NONE;
1207 EXPORT_API int maps_view_object_overlay_get_coordinates(const maps_view_object_h overlay, maps_coordinates_h *coordinates)
1209 if (!maps_condition_check_maps_feature())
1210 return MAPS_ERROR_NOT_SUPPORTED;
1211 if (!overlay || !coordinates)
1212 return MAPS_ERROR_INVALID_PARAMETER;
1213 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1215 return MAPS_ERROR_INVALID_PARAMETER;
1216 return maps_coordinates_clone(m->coordinates, coordinates);
1219 EXPORT_API int maps_view_object_overlay_set_min_zoom_level(maps_view_object_h overlay, int zoom)
1221 if (!maps_condition_check_maps_feature())
1222 return MAPS_ERROR_NOT_SUPPORTED;
1223 if (!overlay || zoom < 0)
1224 return MAPS_ERROR_INVALID_PARAMETER;
1225 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1227 return MAPS_ERROR_INVALID_PARAMETER;
1228 int map_min_zoom_level = 0;
1229 maps_view_get_min_zoom_level(__get_view(overlay), &map_min_zoom_level);
1230 if (zoom < map_min_zoom_level)
1231 m->min_zoom_level = map_min_zoom_level;
1233 m->min_zoom_level = zoom;
1234 return MAPS_ERROR_NONE;
1237 EXPORT_API int maps_view_object_overlay_get_max_zoom_level(const maps_view_object_h overlay, int *zoom)
1239 if (!maps_condition_check_maps_feature())
1240 return MAPS_ERROR_NOT_SUPPORTED;
1241 if (!overlay || !zoom)
1242 return MAPS_ERROR_INVALID_PARAMETER;
1243 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1245 return MAPS_ERROR_INVALID_PARAMETER;
1246 *zoom = m->max_zoom_level;
1247 return MAPS_ERROR_NONE;
1250 EXPORT_API int maps_view_object_overlay_set_max_zoom_level(maps_view_object_h overlay, int zoom)
1252 if (!maps_condition_check_maps_feature())
1253 return MAPS_ERROR_NOT_SUPPORTED;
1254 if (!overlay || zoom < 0)
1255 return MAPS_ERROR_INVALID_PARAMETER;
1256 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1258 return MAPS_ERROR_INVALID_PARAMETER;
1259 int map_max_zoom_level = 0;
1260 maps_view_get_max_zoom_level(__get_view(overlay), &map_max_zoom_level);
1261 if (zoom < map_max_zoom_level)
1262 m->max_zoom_level = map_max_zoom_level;
1264 m->max_zoom_level = zoom;
1265 return MAPS_ERROR_NONE;
1268 EXPORT_API int maps_view_object_overlay_get_min_zoom_level(const maps_view_object_h overlay, int *zoom)
1270 if (!maps_condition_check_maps_feature())
1271 return MAPS_ERROR_NOT_SUPPORTED;
1272 if (!overlay || !zoom)
1273 return MAPS_ERROR_INVALID_PARAMETER;
1274 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1276 return MAPS_ERROR_INVALID_PARAMETER;
1277 *zoom = m->min_zoom_level;
1278 return MAPS_ERROR_NONE;
1281 static bool __maps_view_object_overlay_set_visible(maps_view_object_h overlay)
1286 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1290 maps_view_object_s *o = (maps_view_object_s *)overlay;
1293 maps_view_get_zoom_level(__get_view(overlay), &zoom);
1294 if (zoom < m->min_zoom_level || zoom > m->max_zoom_level) {
1295 evas_object_hide(m->object);
1297 evas_object_hide(m->bubble);
1299 evas_object_show(m->object);
1301 evas_object_show(m->bubble);
1304 evas_object_hide(m->object);
1306 evas_object_hide(m->bubble);
1311 static bool __maps_view_object_overlay_clip(maps_view_object_h overlay, Evas_Object *clipper)
1313 if (!overlay || !clipper)
1317 maps_view_get_screen_location(__get_view(overlay), &x, &y, &w, &h);
1318 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1321 evas_object_color_set(clipper, 255, 255, 255, 255);
1322 evas_object_move(clipper, x, y);
1323 evas_object_resize(clipper, w, h);
1324 evas_object_clip_set(m->object, clipper);
1326 evas_object_clip_set(m->bubble, clipper);
1327 evas_object_show(clipper);
1329 m->clipper = clipper;
1333 static bool __maps_view_object_overlay_move(maps_view_object_h overlay, maps_coordinates_h coordinates)
1335 if (!overlay || !coordinates)
1339 maps_view_geolocation_to_screen(__get_view(overlay), coordinates, &x, &y);
1340 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1343 evas_object_geometry_get(m->object, NULL, NULL, &w, &h);
1348 if (m->type != MAPS_VIEW_OVERLAY_NORMAL) {
1349 y -= _OVERLAY_BUBBLE_MARGIN + _OVERLAY_BUBBLE_PIN_SIZE;
1350 evas_object_move(m->object, x, y);
1353 x -= _OVERLAY_BUBBLE_MARGIN;
1354 y -= _OVERLAY_BUBBLE_MARGIN ;
1355 evas_object_move(m->bubble, x, y);
1358 evas_object_move(m->object, x, y);
1363 static bool __maps_view_object_overlay_update(maps_view_object_h overlay, Evas_Object *clipper)
1365 if (!overlay || !clipper)
1369 maps_coordinates_h coordinates = NULL;
1372 ret = __maps_view_object_overlay_set_visible(overlay);
1375 ret = __maps_view_object_overlay_clip(overlay, clipper);
1378 maps_view_object_overlay_get_coordinates(overlay, &coordinates);
1379 ret = __maps_view_object_overlay_move(overlay, coordinates);
1383 maps_coordinates_destroy(coordinates);
1389 bool _maps_view_object_overlay_cb(int index, int total, maps_view_object_h object, void *user_data)
1391 if (!object || !user_data)
1394 maps_view_object_type_e type;
1395 maps_view_object_get_type(object, &type);
1396 if (type != MAPS_VIEW_OBJECT_OVERLAY)
1398 return __maps_view_object_overlay_update(object, (Evas_Object*)user_data);
1402 int _maps_view_object_overlay_operation(maps_view_h view, maps_view_object_h object, maps_view_object_operation_e operation)
1404 if (!view || !object)
1405 return MAPS_ERROR_INVALID_PARAMETER;
1407 Evas_Object *parent = NULL, *clipper = NULL;
1408 maps_view_overlay_data_s *o = __get_overlay_data(object);
1411 return MAPS_ERROR_INVALID_PARAMETER;
1413 if (operation == MAPS_VIEW_OBJECT_ADD) {
1414 _maps_view_get_parent(view, &parent);
1415 evas_object_smart_member_add(o->bubble, parent);
1416 evas_object_smart_member_add(o->object, parent);
1419 if (operation != MAPS_VIEW_OBJECT_REMOVE) {
1420 _maps_view_get_clipper(view, &clipper);
1421 __maps_view_object_overlay_update(object, clipper);
1424 return MAPS_ERROR_NONE;