[Maps] Add doxygen for map view classes
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Polygon.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20
21 using Color = ElmSharp.Color;
22
23 namespace Tizen.Maps
24 {
25     /// <summary>
26     /// Polygon map object
27     /// </summary>
28     public class Polygon : MapObject
29     {
30         private List<Geocoordinates> _coordinateList;
31
32         /// <summary>
33         /// Creates a polygon visual object
34         /// </summary>
35         /// <param name="coordinates">list of geographical coordinates</param>
36         /// <param name="color">background color</param>
37         public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base(CreateNativeHandle(coordinates, color))
38         {
39             var err = Interop.ErrorCode.InvalidParameter;
40             if (coordinates == null || coordinates.Count() < 3)
41             {
42                 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
43             }
44             _coordinateList = coordinates.ToList();
45         }
46
47         internal Polygon(Interop.ViewObjectHandle nativeHandle) : base(nativeHandle)
48         {
49         }
50
51         /// <summary>
52         /// List of geographical coordinates of polygon vertices
53         /// </summary>
54         public IEnumerable<Geocoordinates> Coordinates
55         {
56             get
57             {
58                 if (_coordinateList == null)
59                 {
60                     _coordinateList = new List<Geocoordinates>();
61                     Interop.ViewObject.CoordinatesCallback callback = (index, nativeHandle, userData) =>
62                     {
63                         _coordinateList.Add(new Geocoordinates(nativeHandle));
64                         return true;
65                     };
66                     Interop.ViewObject.PolygonForeachPoint(handle, callback, IntPtr.Zero);
67                 }
68                 return _coordinateList;
69             }
70             set
71             {
72                 var coordinates = value.ToList();
73
74                 var err = Interop.ErrorCode.InvalidParameter;
75                 if (coordinates == null || coordinates.Count() < 3)
76                 {
77                     err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
78                 }
79
80                 var coordinateList = new GeocoordinatesList(coordinates, false);
81                 if (Interop.ViewObject.PolygonSetPolygon(handle, coordinateList.handle).IsSuccess())
82                 {
83                     _coordinateList = coordinates;
84                 }
85             }
86         }
87
88         /// <summary>
89         /// Background fill color
90         /// </summary>
91         public Color FillColor
92         {
93             get
94             {
95                 byte r, g, b, a;
96                 Interop.ViewObject.PolygonGetFillColor(handle, out r, out g, out b, out a);
97                 return new Color(r, g, b, a);
98             }
99             set
100             {
101                 Interop.ViewObject.PolygonSetFillColor(handle, (byte)value.R, (byte)value.G, (byte)value.B, (byte)value.A);
102             }
103         }
104
105         private static Interop.ViewObjectHandle CreateNativeHandle(IEnumerable<Geocoordinates> coordinates, Color color)
106         {
107             if (coordinates == null || coordinates.Count() < 3) return new Interop.ViewObjectHandle(IntPtr.Zero);
108
109             IntPtr nativeHandle;
110             var geocoordinateList = new GeocoordinatesList(coordinates.ToList(), false);
111             var err = Interop.ViewObject.CreatePolygon(geocoordinateList.handle, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A, out nativeHandle);
112             err.ThrowIfFailed("Failed to create native handle for polygon");
113             return new Interop.ViewObjectHandle(nativeHandle);
114         }
115     }
116 }