2 * Copyright (c) 2016 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.
18 using System.Collections.Generic;
21 using Color = ElmSharp.Color;
26 /// The polygon map object.
28 /// <since_tizen> 3 </since_tizen>
29 public class Polygon : MapObject, IDisposable
31 internal Interop.PolygonHandle handle;
32 private List<Geocoordinates> _coordinateList;
35 /// Creates a polygon visual object.
37 /// <since_tizen> 3 </since_tizen>
38 /// <param name="coordinates">List of geographical coordinates.</param>
39 /// <param name="color">Background color.</param>
40 /// <exception cref="ArgumentException">Thrown when input values are invalid.</exception>
41 public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base()
43 var err = Interop.ErrorCode.InvalidParameter;
44 if (coordinates == null || coordinates.Count() < 3)
46 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
48 _coordinateList = coordinates.ToList();
49 var geocoordinateList = new GeocoordinatesList(_coordinateList, false);
50 handle = new Interop.PolygonHandle(geocoordinateList.handle, color);
54 /// Adds or removes the clicked event handlers.
56 /// <since_tizen> 3 </since_tizen>
57 public event EventHandler Clicked;
60 /// Gets or sets visibility for the polygon.
62 /// <since_tizen> 3 </since_tizen>
63 public override bool IsVisible
65 get { return handle.IsVisible; }
66 set { handle.IsVisible = value; }
70 /// Gets or sets a list of geographical coordinates for polygon vertices.
72 /// <since_tizen> 3 </since_tizen>
73 public IEnumerable<Geocoordinates> Coordinates
77 return _coordinateList;
81 var coordinates = value.ToList();
82 var err = Interop.ErrorCode.InvalidParameter;
83 if (coordinates == null || coordinates.Count() < 3)
85 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
88 var geocoordinateList = new GeocoordinatesList(coordinates, false);
89 if (handle.SetPolygon(geocoordinateList.handle).IsSuccess())
91 _coordinateList = coordinates;
97 /// Gets or sets a background color to fill the polygon.
99 /// <since_tizen> 3 </since_tizen>
100 public Color FillColor
104 return handle.FillColor;
108 handle.FillColor = value;
112 internal override void HandleClickedEvent()
114 Clicked?.Invoke(this, EventArgs.Empty);
117 internal override void InvalidateMapObject()
122 internal override Interop.ViewObjectHandle GetHandle()
127 #region IDisposable Support
128 private bool _disposedValue = false;
131 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
133 /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
134 /// <since_tizen> 3 </since_tizen>
135 protected virtual void Dispose(bool disposing)
141 _coordinateList.Clear();
144 _disposedValue = true;
149 /// Releases all the resources used by this object.
151 /// <since_tizen> 3 </since_tizen>
152 public void Dispose()
155 GC.SuppressFinalize(this);