我正在使用Mapbox for Xamarin.Forms NuGet在Xamarin表单上实现MapBox。
但是我无法在地图上绘制多边形。
代码:
https://stackoverflow.com/questions/50197347/how-to-reset-only-specific-fields-of-form-in-angular-5
我在这里尝试添加多边形。 坐标是变量,其中包含要处理的所需数据。请帮助我。谢谢。
答案 0 :(得分:0)
包括Naxam nuget包,并使用Polyline绘制多边形。最后需要添加一条定制线以完成折线区域。
Naxam.Controls.Mapbox.Forms.PolylineAnnotation polyline = null;
ObservableCollection<Naxam.Controls.Mapbox.Forms.Annotation> annotations;
annotations = new ObservableCollection<Naxam.Controls.Mapbox.Forms.Annotation>();
//Add Polygon
if (polyline == null)
{
polyline = new Naxam.Controls.Mapbox.Forms.PolylineAnnotation
{
Id = "my_polyline",
Title = "Polygon",
HexColor = "#ff1234",
Width = 1
};
}
foreach (var cordinate in cordinates)
{
if (polyline.Coordinates == null)
{
polyline.Coordinates = new ObservableCollection<Naxam.Controls.Mapbox.Forms.Position>
{ new Naxam.Controls.Mapbox.Forms.Position(cordinate.Latitude, cordinate.Longitude) };
}
else
{
(polyline.Coordinates as ObservableCollection<Naxam.Controls.Mapbox.Forms.Position>)
.Add(new Naxam.Controls.Mapbox.Forms.Position(cordinate.Latitude, cordinate.Longitude));
}
}
//We are using polylines so we have to add ending point to line.
if (polyline.Coordinates != null)
(polyline.Coordinates as ObservableCollection<Naxam.Controls.Mapbox.Forms.Position>)
.Add(new Naxam.Controls.Mapbox.Forms.Position(cordinates[0].Latitude, cordinates[0].Longitude));
annotations.Add(polyline);
mapview.Annotations = annotations;