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 /// Polyline map object
28 public class Polyline : MapObject, IDisposable
30 internal Interop.PolylineHandle handle;
31 private List<Geocoordinates> _coordinateList;
34 /// Creates polyline visual object.
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()
42 var err = Interop.ErrorCode.InvalidParameter;
43 if (coordinates == null || coordinates.Count() < 2)
45 err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
47 _coordinateList = coordinates.ToList();
48 var geocoordinateList = new GeocoordinatesList(_coordinateList);
49 handle = new Interop.PolylineHandle(geocoordinateList.handle, color, width);
53 /// Adds or removes clicked event handlers.
55 public event EventHandler Clicked;
57 public override bool IsVisible
59 get { return handle.IsVisible; }
60 set { handle.IsVisible = value; }
64 /// Gets or sets a list of geographical coordinates for polyline vertices.
66 public IEnumerable<Geocoordinates> Coordinates
70 return _coordinateList;
74 var coordinates = value.ToList();
75 var err = Interop.ErrorCode.InvalidParameter;
76 if (coordinates == null || coordinates.Count() < 2)
78 err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates");
81 var geocoordinateList = new GeocoordinatesList(coordinates, false);
82 if (handle.SetPolyline(geocoordinateList.handle).IsSuccess())
84 _coordinateList = coordinates;
90 /// Gets or sets line color.
92 public Color LineColor
96 return handle.LineColor;
100 handle.LineColor = value;
105 /// Gets or sets line width from 1 to 100 pixels.
111 return handle.LineWidth;
115 handle.LineWidth = value;
119 internal override void HandleClickedEvent()
121 Clicked?.Invoke(this, EventArgs.Empty);
124 internal override void InvalidateMapObject()
129 internal override Interop.ViewObjectHandle GetHandle()
134 #region IDisposable Support
135 private bool _disposedValue = false;
137 protected virtual void Dispose(bool disposing)
143 _coordinateList.Clear();
146 _disposedValue = true;
151 /// Releases all resources used by this object.
153 public void Dispose()
156 GC.SuppressFinalize(this);