如何在不连接的情况下在MapView上绘制两个MKPolygon?

由于某种原因,当我尝试在mapView(MKMapView)上绘制两个MKPolygons时,我最终将两个多边形连接在一起。分别绘制每个多边形效果很好。而且我已经验证了每个多边形不包含任何形成两者之间连接的坐标。 I've attached an image with the two polygons connected

作为参考,我在这里打电话添加多边形。

Content

这是我的DataTemplate代码:

<Label HorizontalAlignment="Center" Content="{Binding RecordCount}" >
     <Label.ContentTemplate>
          <DataTemplate>
               <StackPanel Orientation="Horizontal" Width="100">
                    <TextBlock Text="{Binding}"/>
                    <TextBlock Text=" Cars"/>
               </StackPanel>
          </DataTemplate>
     </Label.ContentTemplate>
</Label>
wanglili19860813 回答:如何在不连接的情况下在MapView上绘制两个MKPolygon?

似乎您要制作由两个多边形组成的一个叠加层。您不能使用MKPolygonRenderer来做到这一点;您将看到一个多边形。

您将需要单独的叠加层,每个多边形一个。除非您使用的是iOS 13!在这种情况下,您很幸运:iOS 13中的新增功能,可以将多个多边形或折线合并到MKMultiPolygon或MKMultiPolyline中,并通过MKMultiPolygonRenderer或MKMultiPolylineRenderer进行绘制。

,

我忘记检查/发布正在调用addPeakTimePolygon的代码。这是下面有问题的代码:

var locationList: [CLLocationCoordinate2D] = []
        var title = 0
        if let peakTimeCampaignList = data["PeakTimeRewardCampaignList"] as? [[AnyHashable:Any]]{
            for campaign in peakTimeCampaignList{
                if let polygonPoints = campaign["CampaignPolygon"] as? [[AnyHashable:Any]]{
                    for polygonPoint in polygonPoints{
                        let polygonPoint = CLLocationCoordinate2D(latitude: polygonPoint["Latitude"] as! CLLocationDegrees,longitude: polygonPoint["Longitude"] as! CLLocationDegrees)
                        locationList.append(polygonPoint)
                    }
                }
                if let id = campaign["Id"] as? Int{
                    title = id
                }
                mapBundle.addPeakTimePolygon(from: locationList,title: title)
            }
        }

如您所见,locationList并没有在循环中被清除,这导致我们发送到addPeakTimePolygon的任何东西都具有来自两个多边形的坐标,而MapKit试图最好在两个多边形之间形成一个多边形他们。

这是一个愚蠢的错误,但是希望其他人也能看到同样的问题!

本文链接:https://www.f2er.com/2768075.html

大家都在问