1

I am currently creating an application which uses Google Maps with a lot of polygons rendered on it. My problem is, when two polygons overlap (which may happen quite often in my data set) the lower one will become a little darker. What I want to do is to clear what is beneath the polygon before rendering it.

In iOS I did it like this:

class MyMKRenderer : MKPolygonRenderer {
    override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) {
        context.saveGState()
        context.setBlendMode(.clear)
        context.setFillColor(self.fillColor!.cgColor)
        context.setStrokeColor(UIColor.white.cgColor)
        context.setLineWidth(1.0)

        if polygon.pointCount > 1 {
            context.beginPath()

            let firstPoint = point(for: polygon.points()[0])
            context.move(to: CGPoint(x: CGFloat(firstPoint.x), y: CGFloat(firstPoint.y)))
            for i in 1 ..< polygon.pointCount {
                let secondPoint = point(for: polygon.points()[i])
                context.addLine(to: CGPoint(x: CGFloat(secondPoint.x), y: CGFloat(secondPoint.y)))
            }

            context.closePath()
            context.drawPath(using: .fillStroke)
        }

        context.restoreGState()
        super.draw(mapRect, zoomScale: zoomScale, in: context)
    }
}

But I can't seem to find a similar way to do it in Android.

Picture of the issue:

Should not have darker red color

Does anybody know a way?

Bruno
  • 3,872
  • 4
  • 20
  • 37
Guus
  • 399
  • 2
  • 15
  • Seems there is no "from the box" solution an only one way is to implement algorithm for polygon intersection [this](https://stackoverflow.com/q/2272179/6950238) thread. – Andrii Omelchenko Oct 08 '18 at 10:41
  • Looks awfully likely yes. I think ill try the Sutherland algorithm and add the the clip data as holes in PolygonOptions – Guus Oct 08 '18 at 11:05
  • If your cases like shown on picture, you can use [`PolyUtil.containsLocation`](http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/PolyUtil.html#containsLocation-LatLng-java.util.List-boolean-) for determining points laying inside other polygon. – Andrii Omelchenko Oct 08 '18 at 11:09

0 Answers0