コード例 #1
0
        /// <summary>
        /// Updates the bounds of a <see cref="GpxFile"/> object according to internal data
        /// </summary>
        /// <param name="gpx">The <see cref="GpxFile"/></param>
        /// <returns>An updated <see cref="GpxFile"/></returns>
        public static GpxFile UpdateBounds(this GpxFile gpx)
        {
            if (gpx.Metadata?.Bounds != null &&
                gpx.Metadata.Bounds.MinLatitude.Value != 0.0 &&
                gpx.Metadata.Bounds.MaxLatitude.Value != 0.0 &&
                gpx.Metadata.Bounds.MinLongitude.Value != 0.0 &&
                gpx.Metadata.Bounds.MaxLongitude.Value != 0.0)
            {
                return(gpx);
            }
            var points = (gpx.Routes ?? new List <GpxRoute>()).Where(r => r.Waypoints != null).SelectMany(r => r.Waypoints).ToArray();

            points = points.Concat(gpx.Waypoints ?? new List <GpxWaypoint>()).ToArray();
            points = points.Concat((gpx.Tracks ?? new List <GpxTrack>()).Where(r => r.Segments != null).SelectMany(t => t.Segments).SelectMany(s => s.Waypoints)).ToArray();
            if (!points.Any())
            {
                return(gpx);
            }

            var boundingBox = new GpxBoundingBox(
                minLatitude: new GpxLatitude(points.Min(p => p.Latitude.Value)),
                maxLatitude: new GpxLatitude(points.Max(p => p.Latitude.Value)),
                minLongitude: new GpxLongitude(points.Min(p => p.Longitude.Value)),
                maxLongitude: new GpxLongitude(points.Max(p => p.Longitude.Value))
                );

            gpx.Metadata = gpx.Metadata == null
                ? new GpxMetadata(null, null, null, null, null, ImmutableArray <GpxWebLink> .Empty, null, null, boundingBox, null)
                : new GpxMetadata(gpx.Metadata.Creator, gpx.Metadata.Name, gpx.Metadata.Description, gpx.Metadata.Author, gpx.Metadata.Copyright, gpx.Metadata.Links, gpx.Metadata.CreationTimeUtc, gpx.Metadata.Keywords, boundingBox, gpx.Metadata.Extensions);
            return(gpx);
        }
コード例 #2
0
        private void UpdateBoundingBox(DataContainer container, GpxBoundingBox bounds)
        {
            container.NorthEast = new LatLng
            {
                Lat = bounds.MaxLatitude,
                Lng = bounds.MaxLongitude
            };

            container.SouthWest = new LatLng
            {
                Lat = bounds.MinLatitude,
                Lng = bounds.MinLongitude
            };
        }