예제 #1
0
        public void InsertCoordinate(int index, CLLocationCoordinate2D coord)
        {
            var indexOverlay = GetOverlayIndex(ZIndex);

            if (_polylines.Count == 0)
            {
                // no position yet
                var polyline = MKPolyline.FromCoordinates(new[] { coord });
                _map.InsertOverlay(polyline, indexOverlay);
                _polylines.Add(polyline);
            }
            else
            {
                // find the polyline to extend with the new coordinate
                // add position to the las polyline
                var polyline = _polylines.Last();
                _map.RemoveOverlay(polyline);
                _polylines.Remove(polyline);
                var points = new List <CLLocationCoordinate2D>(polyline.GetCoordinates(0, (int)polyline.PointCount));
                points.Add(coord);
                polyline = MKPolyline.FromCoordinates(points.ToArray());
                _polylines.Add(polyline);
                _map.InsertOverlay(polyline, indexOverlay);

                if (polyline.PointCount == PolylineSegmentLength + 1)
                {
                    // Polyline is full
                    var nextPolyline = MKPolyline.FromCoordinates(new[] { coord });
                    _map.InsertOverlay(nextPolyline, indexOverlay);
                    _polylines.Add(nextPolyline);
                }
            }
        }