Пример #1
0
        private void parametersChanged()
        {
            string text;

            if (m_wpt != null)
            {
                this.Text = "Photo: " + m_wpt.Desc;
                text      = m_wpt.toStringPopup();
            }
            else if (m_photoDescr != null)
            {
                this.Text = "Photo: " + m_photoDescr.imageName;
                text      = "" + m_photoDescr.imageName + "\n\n" + m_photoDescr.imageSource;
                if (m_photoDescr.DTOrig.CompareTo(new DateTime(1, 1, 1, 0, 0, 0)) > 0)
                {
                    text += "\n\n" + m_photoDescr.DTOrig + " (local before shift)    " + m_photoDescr.Width + " x " + m_photoDescr.Height;

                    TimeSpan photoTimeShift = Project.photoTimeShiftCurrent;
                    TimeSpan timeZoneSpan   = MyTimeZone.timeSpanById(Project.photoTimeZoneIdCurrent);
                    DateTime timeStamp      = m_photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan;

                    text += "\n" + timeStamp + " (local after shift - must match a trackpoint)";
                }
                else
                {
                    text += "\n\n[no time stamp]   " + m_photoDescr.Width + " x " + m_photoDescr.Height;
                }
                text += "\n\n[this photo is not related to any trackpoint]";
            }
            else
            {
                text      = "no image or waypoint";
                this.Text = "Photo Preview";
            }

            infoLabel.Text = text;

            drawLinkLabel.Enabled = (m_photoDescr != null);
        }
Пример #2
0
        public static Waypoint createPhotoTrackpoint(PhotoDescr photoDescr, TimeSpan photoTimeShift, int tzId)
        {
            if (photoDescr.hasCoordinates)
            {
                // There is EXIF coordinates set, use it.
                GeoCoord loc    = new GeoCoord(photoDescr.Longitude, photoDescr.Latitude, photoDescr.Altitude);
                string   name   = photoDescr.imageName;
                string   source = photoDescr.imageSource;
                string   url    = photoDescr.imageUrl;
                Waypoint wpt0   = new Waypoint(loc, Project.localToZulu(photoDescr.DTOrig),
                                               LiveObjectTypes.LiveObjectTypeWaypoint, -1, name, source, url);
                wpt0.Desc           = photoDescr.imageName;
                wpt0.ThumbImage     = photoDescr.ThumbnailImage;
                wpt0.ThumbSource    = photoDescr.imageThumbSource;
                wpt0.ThumbPosition  = Project.thumbPosition;
                wpt0.imageWidth     = photoDescr.Width;
                wpt0.imageHeight    = photoDescr.Height;
                wpt0.PhotoTimeShift = new TimeSpan(0L);
                // we need to shift the timestamp a bit if the spot is taken:
                while (WaypointsWithThumbs.ContainsKey(wpt0.DateTime))
                {
                    DateTime tmp = wpt0.DateTime;
                    wpt0.DateTime = tmp.AddMilliseconds(1);
                }
                // make sure the new waypoint is accounted for in the cache:
                WaypointsWithThumbs.Add(wpt0.DateTime, wpt0);
                CurrentWptIndex = WaypointsWithThumbs.Count - 1;
                WaypointsCache.addWaypoint(wpt0);

                return(wpt0);
            }

            if (photoDescr.DTOrig.Equals(DateTime.MinValue))
            {
                // try to get it from file name:
                photoDescr.ensureImageExists();
                Waypoint wpt0 = WaypointsCache.getWaypointByName(photoDescr.imageName);
                if (wpt0 != null)
                {
                    //wpt0.Desc = photoDescr.imageName;
                    wpt0.ThumbImage     = photoDescr.ThumbnailImage;
                    wpt0.ThumbSource    = photoDescr.imageThumbSource;
                    wpt0.ThumbPosition  = Project.thumbPosition;
                    wpt0.imageWidth     = photoDescr.Width;
                    wpt0.imageHeight    = photoDescr.Height;
                    wpt0.PhotoTimeShift = new TimeSpan(0L);
                    // we need to shift the timestamp a bit if the spot is taken:
                    while (WaypointsWithThumbs.ContainsKey(wpt0.DateTime))
                    {
                        DateTime tmp = wpt0.DateTime;
                        wpt0.DateTime = tmp.AddMilliseconds(1);
                    }
                    // make sure the new waypoint is accounted for in the cache:
                    WaypointsWithThumbs.Add(wpt0.DateTime, wpt0);
                    CurrentWptIndex = WaypointsWithThumbs.Count - 1;

                    return(wpt0);
                }
                else
                {
                    registerUnrelatedPhoto(photoDescr);
                }
                return(null);
            }

            TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(tzId);
            DateTime timeStamp    = Project.localToZulu(photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan);

            //LibSys.StatusBar.Trace("adjusted zulu time=" + timeStamp);
            registerImageTimestamp(timeStamp);

            if (photoDescr.imageSourceIsLocal && photoDescr.image == null)
            {
                // try to get it from file name:
                photoDescr.ensureImageExists();
                registerUnrelatedPhoto(photoDescr);
                return(null);
            }
            Waypoint wpt = null;
            Waypoint wpt1;
            Waypoint wpt2;

            // wpt2 is hit if exact match on the timestamp; wpt1 may turn null, but not wpt2.
            if (WaypointsCache.trackpointByTime(timeStamp, out wpt1, out wpt2))
            {
                // create duplicate waypoint and add it to the same track - to hold the image
                wpt = new Waypoint(wpt2);
                if (wpt1 == null)
                {
                    // exact match on wpt2
                }
                else
                {
                    // somewhere between wpt1 and wpt2
                    double dt  = (wpt2.DateTime - wpt1.DateTime).Ticks;
                    double dt1 = (timeStamp - wpt1.DateTime).Ticks;
                    if (dt > 0)
                    {
                        double ratio = dt1 / dt;
                        wpt.Location.Lat = wpt1.Location.Lat + (wpt2.Location.Lat - wpt1.Location.Lat) * ratio;
                        wpt.Location.Lng = wpt1.Location.Lng + (wpt2.Location.Lng - wpt1.Location.Lng) * ratio;
                    }
                }
                wpt.DateTime = timeStamp;
                wpt.Desc     = photoDescr.imageName;
                Track trk = WaypointsCache.getTrackById(wpt.TrackId);
                // we need to shift the timestamp a bit if the spot is taken:
                while (WaypointsWithThumbs.ContainsKey(wpt.DateTime) || trk.Trackpoints.ContainsKey(wpt.DateTime))
                {
                    DateTime tmp = wpt.DateTime;
                    wpt.DateTime = tmp.AddMilliseconds(1);
                }
                trk.insertWaypoint(wpt);
                wpt.ThumbImage     = photoDescr.ThumbnailImage;
                wpt.ThumbSource    = photoDescr.imageThumbSource;
                wpt.ThumbPosition  = Project.thumbPosition;
                wpt.imageWidth     = photoDescr.Width;
                wpt.imageHeight    = photoDescr.Height;
                wpt.PhotoTimeShift = photoTimeShift;
                // make sure the new waypoint is accounted for in the cache:
                WaypointsWithThumbs.Add(wpt.DateTime, wpt);
                CurrentWptIndex = WaypointsWithThumbs.Count - 1;
            }
            else
            {
                registerUnrelatedPhoto(photoDescr);
            }
            return(wpt);
        }