I am rendering state counties for a selected US state, by creating a polygon and filling in the color based on data values. The first time it does this for any given state (drawing the county outline, etc.) it is fine. Selecting a different state also works usually without issue.
When selecting the first state for the first time, here is the code flow:
2016-01-27 08:15:47.287 Otezla Dashboard[13493:4733614] drawCounties - county: MARION
2016-01-27 08:15:47.287 Otezla Dashboard[13493:4733614] rendererForOverlay - county: MARION
2016-01-27 08:15:47.287 Otezla Dashboard[13493:4733614] drawCounties - county: MANATEE
2016-01-27 08:15:47.288 Otezla Dashboard[13493:4733614] rendererForOverlay - county: MANATEE
2016-01-27 08:15:47.288 Otezla Dashboard[13493:4733614] drawCounties - county: GILCHRIST
2016-01-27 08:15:47.288 Otezla Dashboard[13493:4733614] rendererForOverlay - county: GILCHRIST
When selecting the first state again, the behavior is such:
2016-01-27 08:15:51.740 Otezla Dashboard[13493:4733614] drawCounties - county: MARION
2016-01-27 08:15:51.740 Otezla Dashboard[13493:4733614] drawCounties - county: MANATEE
2016-01-27 08:15:51.740 Otezla Dashboard[13493:4733614] drawCounties - county: GILCHRIST
and then
2016-01-27 08:15:51.853 Otezla Dashboard[13493:4733614] drawCounties - county: MONROE
2016-01-27 08:15:51.853 Otezla Dashboard[13493:4733614] drawCounties - county: HERNANDO
2016-01-27 08:15:51.853 Otezla Dashboard[13493:4733614] drawCounties - county: INDIAN RIVER
2016-01-27 08:15:51.854 Otezla Dashboard[13493:4733614] rendererForOverlay - county: INDIAN RIVER
2016-01-27 08:15:51.854 Otezla Dashboard[13493:4733614] rendererForOverlay - county: INDIAN RIVER
So basically, the 2nd time in, when viewForOverlay is called, renderForOverlay is not called until all counties in Florida are looped through the call to viewForOverlay, then it is as though all those requests were queued up and then renderForOverlay is called all x many times for the county, but it only uses the last county name cached. Thus, it is not view and render but view view view ... render render render.
Here is the view code:
MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coordinates count:coords.count];
polygon.title = currentCounty;
[mapCountyOverlays setObject:polygon forKey:key];
[mapView addOverlay:polygon];
and the render code:
- (MKOverlayView *) mapView :(MKMapView *) mapViewSent rendererForOverlay:(nonnull id<MKOverlay>)overlay
{
NSLog(@"rendererForOverlay - county: %@", currentCounty);
return [self buildPolygonForMap:mapViewSent viewForOverlay:overlay];
}
/
* build polygon
*/
- (MKPolygonView *) buildPolygonForMap :(MKMapView *) mapView viewForOverlay :(id) overlay
{
readyToRender = NO;
MKPolygonView *polygonView = [[MKPolygonView alloc] initWithPolygon:overlay];
polygonView.strokeColor = [UIColor blackColor];
polygonView.lineWidth = 1.5;
if(stateRecentlySelected)
{
polygonView.fillColor = [self colorizeState];
}
else
{
if(currentCounty != nil)
{
NSNumber *tier = [countiesDistributed objectForKey:currentCounty];
if(tier == nil)
{
return polygonView;
}
polygonView.strokeColor = [UIColor whiteColor];
polygonView.fillColor = [self colorizeCounty :[tier intValue]];
}
else
{
NSLog(@"currentCounty is nil");
}
}
readyToRender = YES;
[mapView setNeedsDisplay];
return polygonView;
}
Thanks.