GMSMapView中的倒多边形 [英] Inverted Polygon in GMSMapView

查看:133
本文介绍了GMSMapView中的倒多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为我的iPhone项目使用Google Map,并且正在使用GMSPolygon绘制多边形,但是如何填充除多边形内部之外的地图上的所有位置.如下图所示.

I have to use Google Map for my iPhone project and I'am using GMSPolygon to draw a polygon but How can I fill everywhere on my map except the interior of the polygon. Like the image below.

谢谢.

推荐答案

我已经解决了您的问题.主要思想是用多边形填充整个地球,然后为您的特定区域开孔.这是示例代码,但是问题是我无法创建覆盖整个地球的多边形.第一种方法是为每个季度创建4个多边形.

I have played with your question. Main idea is to fill all Earth with polygon and then make holes for your particular area. Here is example code, but problem is that I can`t create polygon to cover whole Earth. First approach is to create 4 polygons for each quarter.

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

PGeoCountry is a struct with desired areas in 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()
    }

}

这是结果:

这篇关于GMSMapView中的倒多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆