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;
25 public class Polygon : MapObject
27 private List<Geocoordinates> _coordinateList;
29 public Polygon(IEnumerable<Geocoordinates> coordinates, Color color) : base(CreateNativeHandle(coordinates, color))
31 var err = Interop.ErrorCode.InvalidParameter;
32 if (coordinates == null || coordinates.Count() < 3)
34 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
36 _coordinateList = coordinates.ToList();
39 internal Polygon(Interop.ViewObjectHandle nativeHandle) : base(nativeHandle)
43 public IEnumerable<Geocoordinates> Coordinates
47 if (_coordinateList == null)
49 _coordinateList = new List<Geocoordinates>();
50 Interop.ViewObject.CoordinatesCallback callback = (index, nativeHandle, userData) =>
52 _coordinateList.Add(new Geocoordinates(nativeHandle));
55 Interop.ViewObject.PolygonForeachPoint(handle, callback, IntPtr.Zero);
57 return _coordinateList;
61 var coordinates = value.ToList();
63 var err = Interop.ErrorCode.InvalidParameter;
64 if (coordinates == null || coordinates.Count() < 3)
66 err.ThrowIfFailed("given coordinates list should contain at least 3 coordinates");
69 var coordinateList = new GeocoordinatesList(coordinates, false);
70 if (Interop.ViewObject.PolygonSetPolygon(handle, coordinateList.handle).IsSuccess())
72 _coordinateList = coordinates;
77 public Color FillColor
82 Interop.ViewObject.PolygonGetFillColor(handle, out r, out g, out b, out a);
83 return new Color(r, g, b, a);
87 Interop.ViewObject.PolygonSetFillColor(handle, (byte)value.R, (byte)value.G, (byte)value.B, (byte)value.A);
91 private static Interop.ViewObjectHandle CreateNativeHandle(IEnumerable<Geocoordinates> coordinates, Color color)
93 if (coordinates == null || coordinates.Count() < 3) return new Interop.ViewObjectHandle(IntPtr.Zero);
96 var geocoordinateList = new GeocoordinatesList(coordinates.ToList(), false);
97 var err = Interop.ViewObject.CreatePolygon(geocoordinateList.handle, (byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A, out nativeHandle);
98 err.ThrowIfFailed("Failed to create native handle for polygon");
99 return new Interop.ViewObjectHandle(nativeHandle);