Domanda

I have an array with polygons created from a data file with coordinates per polygon.

So when I plot them on my map I use:

[mapView addOverlays:polygonArray];

and in my viewForOverlay:

if ([overlay isKindOfClass:[MKPolygon class]]) {
    MKPolygonView *polyView = [[MKPolygonView alloc] initWithPolygon:overlay];
    polyView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    polyView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.1];
    polyView.lineWidth = 1;
    return polyView;
  }
else {
  return nil;
}

The problem is that regarding my "colorWithAlphaComponent" the code seems to reuse and recreate the polyView for each Polygon. Therefore the first one is with alpha 0.1 but the second is 2x and so on.. So the last few Polygons aren't "seethrough" anymore.

Here's how it looks:

enter image description here

È stato utile?

Soluzione

Based on the problem description and picture, it sounds like you are adding the same polygon multiple times so it gets overlapped with itself.

When overlays overlap, the map view blends their colors together resulting in a darker appearance.


If polygonArray contains unique polygons itself but addOverlays is called multiple times, you should call removeOverlays before addOverlays if the existing polygons on the map are already included in polygonArray.


Another possibility is that polygonArray itself contains duplicate polygons.
Even if addOverlays is called only once, the map will add multiple instances of the same polygon resulting in those overlays overlapping themselves giving them a darker color than expected.

To fix this, you should eliminate the duplication in polygonArray.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top