gpt4 book ai didi

ios - GMSMapView 中的倒多边形

转载 作者:可可西里 更新时间:2023-11-01 03:19:41 25 4
gpt4 key购买 nike

我必须为我的 iPhone 项目使用 Google map ,我正在使用 GMSPolygon 绘制多边形,但我如何填充 map 上除多边形内部以外的所有地方。就像下图一样。

谢谢。

sample

最佳答案

我试过你的问题。主要想法是用多边形填充整个地球,然后为您的特定区域打洞。这是示例代码,但问题是我无法创建多边形来覆盖整个地球。第一种方法是为每个季度创建 4 个多边形。

PGeoCountry 是一个在 boundariesPaths:[GMSPath] 中具有所需区域的结构

func locateCountry(country: PGeoCountry) {
// 1. Create one quarter earth filling polygon
let fillingPath = GMSMutablePath()
fillingPath.addLatitude(90.0, longitude: -90.0)
fillingPath.addLatitude(90.0, longitude: 90.0)
fillingPath.addLatitude(0, longitude: 90.0)
fillingPath.addLatitude(0, longitude: -90.0)

let fillingPolygon = GMSPolygon(path:fillingPath)
let fillColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 0.6)
fillingPolygon.fillColor = fillColor
fillingPolygon.map = self.mapView

// 2. Add prepared array of GMSPath
fillingPolygon.holes = country.boundariesPaths

// 3. Add lines for boundaries
for path in country.boundariesPaths {
let line = GMSPolyline(path: path)
line.map = self.mapView
line.strokeColor = UIColor.blackColor()
}

}

结果如下:

enter image description here

关于ios - GMSMapView 中的倒多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com