private void CreatePolylinesFromLocations() { if (Locations.Count <= 1) { return; } // Only need one line if no colours are involved if (!showRideFeatures) { AddPolyLine(Locations.Cast <ILatLng>().ToList(), Color.Blue); return; } var maxSpeed = Locations.Max(i => i.Mph); var lastColour = Color.Blue; var polylineLocations = new List <ILatLng> { Locations.First(), }; for (int i = 1; i < Locations.Count; i++) { var colour = showRideFeatures ? GetMaxSpeedColour(Locations[i].Mph, maxSpeed) : Color.Blue; if (colour != lastColour) { AddPolyLine(polylineLocations, lastColour); polylineLocations.Clear(); polylineLocations.Add(Locations[i - 1]); lastColour = colour; } polylineLocations.Add(Locations[i]); bool isMaxSpeed = Locations[i].Mph == maxSpeed; bool hasJump = Locations[i].Jump != null; bool hasMultiplePins = isMaxSpeed && hasJump; if (isMaxSpeed) { AddMaxSpeedPin(Locations[i], hasMultiplePins); } if (hasJump) { AddJumpPin(Locations[i], hasMultiplePins); } } AddPolyLine(polylineLocations, lastColour); }