I am designing a transit app that overlays several routes in the form of MKPolyLines on a map. Currently the colors of the various routes are set as the title property of MKPolyLine. I'm wondering if there is a way to detect when lines of different colors overlap, and then change the color. Currently when two routes are added on top of each other, the color is simply the last one added.

My attempt at the pseudocode

 - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    MKPolyline *polyline = (MKPolyline *)overlay;
    UIColor *color = [self colorWithHexString:polyline.title];
    MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];

    if the polyline matches an already existing polyline{
      color = new color
    }
    polylineView.strokeColor = color;
    polylineView.lineWidth = 5.0;
}

Seems simple enough? Not sure if it is possible to compare polylines and see if one is already on the map, might not be an exact enough identifier. Thanks for your help.

有帮助吗?

解决方案

I ended up using the lineDashPattern property of MKPolylineView. Applying this to one of the overlapping lines achieves the desired effect.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top