我必须为我的 iPhone 项目使用 Google map ,我正在使用 GMSPolygon 绘制多边形,但我如何填充 map 上除多边形内部以外的所有地方。就像下图一样。
谢谢。
最佳答案
我试过你的问题。主要想法是用多边形填充整个地球,然后为您的特定区域打洞。这是示例代码,但问题是我无法创建多边形来覆盖整个地球。第一种方法是为每个季度创建 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()
}
}
结果如下:
关于ios - GMSMapView 中的倒多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772500/