我正在尝试允许用户使用xamarin forms iOS在地图上选择多边形,并对他们选择的多边形应用笔划。我不知道如何在c#中以这种方式创建点击手势。
我正在通过创建多边形
var blockOverlay = MKPolygon.FromCoordinates(coords);
Constants.nativeMap.AddOverlay(blockOverlay);理想情况下,我希望它看起来像我的Android Map
发布于 2019-04-17 12:05:45
您可以将UITapGestureRecognizer添加到MKMapView中,并将捕获的点击坐标转换为地图点,然后测试它是否存在于任何覆盖中。
示例:
var uiTapGesture = new UITapGestureRecognizer(tappedGesture =>
{
foreach (MKPolygon polygon in (tappedGesture.View as MKMapView).Overlays)
{
using (var render = new MKPolygonRenderer(polygon))
{
var coord2D = nativeMap.ConvertPoint(tappedGesture.LocationInView(nativeMap), nativeMap);
var mapPoint = MKMapPoint.FromCoordinate(coord2D);
var polyTouched = render.Path.ContainsPoint(render.PointForMapPoint(mapPoint), true);
if (polyTouched)
Console.WriteLine($"tapped: {polygon}");
}
}
});
nativeMap.AddGestureRecognizer(uiTapGesture);注意:这是假设您使用MKPolygon覆盖,如果不是,相应地调整。
https://stackoverflow.com/questions/55719145
复制相似问题