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 /// Polygon map object
28 public class Polygon : MapObject, IDisposable
30 internal Interop.PolygonHandle handle;
31 private List<Geocoordinates> _coordinateList;
34 /// Creates a polygon visual object
36 /// <param name="coordinates">list of geographical coordinates</param>
37 /// <param name="color">background color</param>
38 /// <exception cref="ArgumentException">Throws if input values are invalid</exception>
39 public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base()
41 var err = Interop.ErrorCode.InvalidParameter;
42 if (coordinates == null || coordinates.Count() < 3)
44 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
46 _coordinateList = coordinates.ToList();
47 var geocoordinateList = new GeocoordinatesList(_coordinateList, false);
48 handle = new Interop.PolygonHandle(geocoordinateList.handle, color);
54 public event EventHandler Clicked;
56 public override bool IsVisible
58 get { return handle.IsVisible; }
59 set { handle.IsVisible = value; }
63 /// List of geographical coordinates of polygon vertices
65 public IEnumerable<Geocoordinates> Coordinates
69 return _coordinateList;
73 var coordinates = value.ToList();
74 var err = Interop.ErrorCode.InvalidParameter;
75 if (coordinates == null || coordinates.Count() < 3)
77 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
80 var geocoordinateList = new GeocoordinatesList(coordinates, false);
81 if (handle.SetPolygon(geocoordinateList.handle).IsSuccess())
83 _coordinateList = coordinates;
89 /// Background fill color
91 public Color FillColor
95 return handle.FillColor;
99 handle.FillColor = value;
103 internal override void HandleClickedEvent()
105 Clicked?.Invoke(this, EventArgs.Empty);
108 internal override void InvalidateMapObject()
113 internal override Interop.ViewObjectHandle GetHandle()
118 #region IDisposable Support
119 private bool _disposedValue = false;
121 protected virtual void Dispose(bool disposing)
127 _coordinateList.Clear();
130 _disposedValue = true;
134 public void Dispose()
137 GC.SuppressFinalize(this);