/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Linq; using Color = ElmSharp.Color; namespace Tizen.Maps { /// /// The polyline map object. /// /// 3 public class Polyline : MapObject, IDisposable { internal Interop.PolylineHandle handle; private List _coordinateList; /// /// Creates polyline visual object. /// /// 3 /// List of geographical coordinates. /// Line color. /// The width of line [1 ~ 100] (pixels). /// Thrown when input values are invalid. public Polyline(List coordinates, Color color, int width) : base() { var err = Interop.ErrorCode.InvalidParameter; if (coordinates == null || coordinates.Count() < 2) { err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates"); } _coordinateList = coordinates.ToList(); var geocoordinateList = new GeocoordinatesList(_coordinateList); handle = new Interop.PolylineHandle(geocoordinateList.handle, color, width); } /// /// Adds or removes the clicked event handlers. /// /// 3 public event EventHandler Clicked; /// /// Gets or sets the visibility for polyline. /// /// 3 public override bool IsVisible { get { return handle.IsVisible; } set { handle.IsVisible = value; } } /// /// Gets or sets a list of geographical coordinates for polyline vertices. /// /// 3 public IEnumerable Coordinates { get { return _coordinateList; } set { var coordinates = value.ToList(); var err = Interop.ErrorCode.InvalidParameter; if (coordinates == null || coordinates.Count() < 2) { err.ThrowIfFailed("given coordinates list should contain at least 2 coordinates"); } var geocoordinateList = new GeocoordinatesList(coordinates, false); if (handle.SetPolyline(geocoordinateList.handle).IsSuccess()) { _coordinateList = coordinates; } } } /// /// Gets or sets the line color. /// /// 3 public Color LineColor { get { return handle.LineColor; } set { handle.LineColor = value; } } /// /// Gets or sets the line width from 1 to 100 pixels. /// /// 3 public int Width { get { return handle.LineWidth; } set { handle.LineWidth = value; } } internal override void HandleClickedEvent() { Clicked?.Invoke(this, EventArgs.Empty); } internal override void InvalidateMapObject() { handle = null; } internal override Interop.ViewObjectHandle GetHandle() { return handle; } #region IDisposable Support private bool _disposedValue = false; protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _coordinateList.Clear(); } handle.Dispose(); _disposedValue = true; } } /// /// Releases all the resources used by this object. /// /// 3 public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion } }