Modify documentation of APIs
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Polyline.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     /// Polyline map object
27     /// </summary>
28     public class Polyline : MapObject, IDisposable
29     {
30         internal Interop.PolylineHandle handle;
31         private List<Geocoordinates> _coordinateList;
32
33         /// <summary>
34         /// Creates polyline visual object.
35         /// </summary>
36         /// <param name="coordinates">List of geographical coordinates</param>
37         /// <param name="color">Line color</param>
38         /// <param name="width">The width of line [1 ~ 100] (pixels)</param>
39         /// <exception cref="ArgumentException">Thrown when input values are invalid</exception>
40         public Polyline(List<Geocoordinates> coordinates, Color color, int width) : base()
41         {
42             var err = Interop.ErrorCode.InvalidParameter;
43             if (coordinates == null || coordinates.Count() < 2)
44             {
45                 err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
46             }
47             _coordinateList = coordinates.ToList();
48             var geocoordinateList = new GeocoordinatesList(_coordinateList);
49             handle = new Interop.PolylineHandle(geocoordinateList.handle, color, width);
50         }
51
52         /// <summary>
53         /// Adds or removes clicked event handlers.
54         /// </summary>
55         public event EventHandler Clicked;
56
57         public override bool IsVisible
58         {
59             get { return handle.IsVisible; }
60             set { handle.IsVisible = value; }
61         }
62
63         /// <summary>
64         /// Gets or sets a list of geographical coordinates for polyline vertices.
65         /// </summary>
66         public IEnumerable<Geocoordinates> Coordinates
67         {
68             get
69             {
70                 return _coordinateList;
71             }
72             set
73             {
74                 var coordinates = value.ToList();
75                 var err = Interop.ErrorCode.InvalidParameter;
76                 if (coordinates == null || coordinates.Count() < 2)
77                 {
78                     err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
79                 }
80
81                 var geocoordinateList = new GeocoordinatesList(coordinates, false);
82                 if (handle.SetPolyline(geocoordinateList.handle).IsSuccess())
83                 {
84                     _coordinateList = coordinates;
85                 }
86             }
87         }
88
89         /// <summary>
90         /// Gets or sets line color.
91         /// </summary>
92         public Color LineColor
93         {
94             get
95             {
96                 return handle.LineColor;
97             }
98             set
99             {
100                 handle.LineColor = value;
101             }
102         }
103
104         /// <summary>
105         /// Gets or sets line width from 1 to 100 pixels.
106         /// </summary>
107         public int Width
108         {
109             get
110             {
111                 return handle.LineWidth;
112             }
113             set
114             {
115                 handle.LineWidth = value;
116             }
117         }
118
119         internal override void HandleClickedEvent()
120         {
121             Clicked?.Invoke(this, EventArgs.Empty);
122         }
123
124         internal override void InvalidateMapObject()
125         {
126             handle = null;
127         }
128
129         internal override Interop.ViewObjectHandle GetHandle()
130         {
131             return handle;
132         }
133
134         #region IDisposable Support
135         private bool _disposedValue = false;
136
137         protected virtual void Dispose(bool disposing)
138         {
139             if (!_disposedValue)
140             {
141                 if (disposing)
142                 {
143                     _coordinateList.Clear();
144                 }
145                 handle.Dispose();
146                 _disposedValue = true;
147             }
148         }
149
150         /// <summary>
151         /// Releases all resources used by this object.
152         /// </summary>
153         public void Dispose()
154         {
155             Dispose(true);
156             GC.SuppressFinalize(this);
157         }
158         #endregion
159     }
160 }