056c8b922c417d54ac9ab52583e1f3427252c434
[platform/core/api/maps-service.git] / src / view / polygon_constructor.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include "polygon_constructor.h"
19
20 extern int _maps_view_object_create(const maps_view_object_type_e type,
21                               maps_view_object_h *object);
22
23 maps_view_object_h view::polygon_constructor::construct(const maps_coordinates_list_h
24                                                   coordinates,
25                                                   const unsigned char r,
26                                                   const unsigned char g,
27                                                   const unsigned char b,
28                                                   const unsigned char a)
29 {
30         if (!coordinates) {
31                 __error = MAPS_ERROR_INVALID_PARAMETER;
32                 return NULL;
33         }
34
35         __error = MAPS_ERROR_NONE;
36
37         maps_view_object_h polygon = NULL;
38         do {
39                 /* 1. Create a visual object for marker */
40                 __error = _maps_view_object_create(MAPS_VIEW_OBJECT_POLYGON,
41                                                  &polygon);
42                 if (__error != MAPS_ERROR_NONE)
43                         break;
44
45                 /* 2. Set the polygon points */
46                 __error = maps_view_object_polygon_set_polygon(polygon, coordinates);
47                 if (__error != MAPS_ERROR_NONE)
48                         break;
49
50                 /* 3. Set the polygon color */
51                 __error = maps_view_object_polygon_set_fill_color(polygon,
52                                                                  r, g, b, a);
53                 if (__error != MAPS_ERROR_NONE)
54                         break;
55
56                 /* 5. Set the polygon visible */
57                 __error = maps_view_object_set_visible(polygon, true);
58                 if (__error != MAPS_ERROR_NONE)
59                         break;
60
61                 /* SUCCESS */
62                 return polygon;
63         } while (false);
64
65         /* FAILURE: Releasing objects */
66         maps_view_object_destroy(polygon);
67         return NULL;
68 }