我必须在我的 iPhone 项目中使用 Google 地图,并且我正在使用 GMSPolygon 来绘制多边形,但是如何填充地图上除多边形内部之外的所有位置。就像下图一样。
谢谢。
我玩过你的问题。主要思想是用多边形填充整个地球,然后为您的特定区域打孔。这是示例代码,但问题是我无法创建多边形来覆盖整个地球。第一种方法是为每个季度创建 4 个多边形。
PGeoCountry 是一个结构体,其边界路径中包含所需区域:[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()
}
}
结果如下:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)