Карты Google накладывают несколько полигонов в быстрой - PullRequest
0 голосов
/ 08 мая 2018

Существует отличный ответ на SO о слиянии полигонов в картах Google для javascript. Теперь я взял это и преобразовал это, чтобы быстро. В основном это работает, но в некоторых кругах я сталкиваюсь с пробелами, поэтому я не уверен, является ли преобразование полностью правильным или нет.

enter image description here

Быстрый код преобразованного JS выглядит так

func setFloodPolygons(mData: Floods) {    
    let rect = GMSMutablePath()
    var circCoordinates: [CLLocationCoordinate2D] = []
    for flood in mData.Floods {
        circCoordinates.append(contentsOf: drawPolygonCircle(coord: CLLocationCoordinate2D.init(latitude: flood.lat, longitude: flood.lng), radius: 3.0, dir: 1))
    }

    for coo in circCoordinates {
        rect.add(coo)
    }

    // Create the polygon, and assign it to the map.
    let polygon = GMSPolygon(path: rect)
    polygon.fillColor = UIColor(red: 144/255, green: 195/255, blue: 212/255, alpha: 0.75)
    polygon.strokeColor = UIColor(red: 144/255, green: 195/255, blue: 212/255, alpha: 0.75)
    polygon.strokeWidth = 1
    polygon.zIndex = 1
    polygon.map = mapView
}

и функция круга

func drawPolygonCircle(coord: CLLocationCoordinate2D, radius: Double, dir: Int) -> [CLLocationCoordinate2D]{
    let d2r = Double.pi / 180   // degrees to radians
    let r2d = 180 / Double.pi   // radians to degrees
    let earthsradius = 3963.0 // 3963 is the radius of the earth in miles
    let points = 32
    let rlat = (radius / earthsradius) * r2d
    let rlng = rlat / cos(coord.latitude * d2r)

    var extp: [CLLocationCoordinate2D] = []
    let start = 0
    let end = points

    for i in start...end {
        let j = i + dir
        let theta = Double.pi * (Double(j) / Double(points / 2));
        let ey = coord.longitude + (rlng * cos(theta)); // center a + radius x * cos(theta)
        let ex = coord.latitude + (rlat * sin(theta)); // center b + radius y * sin(theta)
        extp.append(CLLocationCoordinate2D.init(latitude: ex, longitude: ey))
    }
    return extp;
}

Когда то же самое делается с использованием идентичных координат на веб-странице, круги отображаются правильно.

Пробелы, которые я определил, - это то, как полигон будет выглядеть, если не пройти функцию круга.

Может кто-нибудь увидеть, что может потребовать корректировки, чтобы заполнить пробелы, или иметь представление о том, что я сделал неправильно в преобразовании?

UPDATE:

Это признанная ошибка Google. Вы можете посмотреть отчет об ошибке по адресу https://issuetracker.google.com/issues/79475939. Возможно, добавьте комментарий, чтобы поощрить Google взглянуть на него раньше.

...