d5e98ffbd6c0c8732d5e5fe0c9443026fc1b14d5
[platform/core/csapi/maps.git] / 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         public Polyline(List<Geocoordinates> coordinates, Color color, int width) : base()
40         {
41             var err = Interop.ErrorCode.InvalidParameter;
42             if (coordinates == null || coordinates.Count() < 2)
43             {
44                 err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
45             }
46             _coordinateList = coordinates.ToList();
47             var geocoordinateList = new GeocoordinatesList(_coordinateList);
48             handle = new Interop.PolylineHandle(geocoordinateList.handle, color, width);
49         }
50
51         /// <summary>
52         /// Clicked event
53         /// </summary>
54         public event EventHandler Clicked;
55
56         public override bool IsVisible
57         {
58             get { return handle.IsVisible; }
59             set { handle.IsVisible = value; }
60         }
61
62         /// <summary>
63         /// List of geographical coordinates for polyline vertices
64         /// </summary>
65         public IEnumerable<Geocoordinates> Coordinates
66         {
67             get
68             {
69                 return _coordinateList;
70             }
71             set
72             {
73                 var coordinates = value.ToList();
74                 var err = Interop.ErrorCode.InvalidParameter;
75                 if (coordinates == null || coordinates.Count() < 2)
76                 {
77                     err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
78                 }
79
80                 var geocoordinateList = new GeocoordinatesList(coordinates, false);
81                 if (handle.SetPolyline(geocoordinateList.handle).IsSuccess())
82                 {
83                     _coordinateList = coordinates;
84                 }
85             }
86         }
87
88         /// <summary>
89         /// Line color
90         /// </summary>
91         public Color LineColor
92         {
93             get
94             {
95                 return handle.LineColor;
96             }
97             set
98             {
99                 handle.LineColor = value;
100             }
101         }
102
103         /// <summary>
104         /// line width [1 ~ 100 pixels]
105         /// </summary>
106         public int Width
107         {
108             get
109             {
110                 return handle.LineWidth;
111             }
112             set
113             {
114                 handle.LineWidth = value;
115             }
116         }
117
118         internal override void HandleClickedEvent()
119         {
120             Clicked?.Invoke(this, EventArgs.Empty);
121         }
122
123         internal override void InvalidateMapObject()
124         {
125             handle = null;
126         }
127
128         internal override Interop.ViewObjectHandle GetHandle()
129         {
130             return handle;
131         }
132
133         #region IDisposable Support
134         private bool _disposedValue = false;
135
136         protected virtual void Dispose(bool disposing)
137         {
138             if (!_disposedValue)
139             {
140                 if (disposing)
141                 {
142                     _coordinateList.Clear();
143                 }
144                 handle.Dispose();
145                 _disposedValue = true;
146             }
147         }
148
149         public void Dispose()
150         {
151             Dispose(true);
152         }
153         #endregion
154     }
155 }