Exemple #1
0
    /// <summary>
    /// Called by Unity engine when the player finish dragging mouse
    /// </summary>
    void IEndDragHandler.OnEndDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
        // If Left mouse button, add last point and validate
        case PointerEventData.InputButton.Left:
        {
            // Determine active Track Segment
            TrackSegment currentTrack = _track.Last();

            // Add current point
            currentTrack.AddPoint(eventData.position.ScreenToWorld());

            // If new Track doesn't have enough points, remove it
            if (!currentTrack.IsValid)
            {
                _track.Remove(currentTrack);
                Destroy(currentTrack.gameObject);
            }

            break;
        }

        // If right button is pressed, switch back to default mouse cursor
        case PointerEventData.InputButton.Right:
        {
            Cursor.SetCursor(DrawingCursor, new Vector2(0, 64), CursorMode.ForceSoftware);
            break;
        }
        }
    }
        public void ReadGpxData(GpxFile gpxFile, Stream stream)
        {
            XmlSerializer serializer = new XmlSerializer (typeof (gpx));
            gpx gpx = (gpx)serializer.Deserialize (stream);

            if (gpx.trk != null)
            {
                foreach (gpxTrk trkType in gpx.trk)
                {
                    Track track = new Track ();

                    foreach (gpxTrkTrkseg trkseg in trkType.trkseg)
                    {
                        if (trkseg.trkpt.Length > 0)
                        {
                            TrackSegment segment = new TrackSegment ();
                            foreach (gpxTrkTrksegTrkpt trkpt in trkseg.trkpt)
                            {
                                TrackPoint waypoint = ReadTrackPoint (trkpt);
                                segment.AddPoint (waypoint);
                            }

                            track.AddSegment (segment);
                        }
                    }

                    gpxFile.AddTrack (track);
                }
            }

            if (gpx.wpt != null)
            {
                foreach (gpxWpt wptType in gpx.wpt)
                {
                    TrackPoint waypoint = ReadWayoint(wptType);
                    gpxFile.AddWaypoint (waypoint);
                }
            }

            if (gpx.rte != null)
            {
                foreach (gpxRte rteType in gpx.rte)
                {
                    Track route = new Track ();

                    if (rteType.rtept != null)
                    {
                        TrackSegment segment = new TrackSegment ();
                        foreach (gpxRteRtept wptType in rteType.rtept)
                        {
                            TrackPoint waypoint = ReadRoutePoint (wptType);
                            segment.AddPoint (waypoint);
                        }
                    }

                    gpxFile.AddRoute (route);
                }
            }
        }
Exemple #3
0
    /// <summary>
    /// Called by Unity engine when the player start mouse drag
    /// </summary>
    void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
        // If Left mouse button, start a new Track Segment
        case PointerEventData.InputButton.Left:
        {
            // Convert position from Screen Coordinates into World ones
            Vector2 position = eventData.pressPosition.ScreenToWorld();

            // Check whether to snap to a previous point
            if (_track.Count > 0)
            {
                for (int ti = _track.Count - 1; ti >= 0; ti--)
                {
                    TrackSegment currentTrack = _track[ti];
                    for (int pi = currentTrack.PointCount - 1; pi >= 0; pi--)
                    {
                        if ((currentTrack[pi] - position).magnitude < SnapRange)
                        {
                            position = currentTrack[pi];
                            break;
                        }
                    }
                }
            }

            // Create a new Game Object for the new Track Segment
            GameObject newTrackSegmentGo = new GameObject("Track segment");

            // Set it as a child of this one
            newTrackSegmentGo.transform.parent = transform;

            // Add a Track Segment component to the newly created Game Object
            TrackSegment newTrackSegment = newTrackSegmentGo.AddComponent <TrackSegment>();

            // Set Line Renderer material
            newTrackSegment.GroundMaterial = GroundMaterial;

            // Add starting point
            newTrackSegment.AddPoint(position);

            // Add this new Track Segment to the whole Track
            _track.Add(newTrackSegment);
            break;
        }

        // If right button is pressed, switch mouse cursor to move
        case PointerEventData.InputButton.Right:
        {
            Cursor.SetCursor(MoveCursor, new Vector2(32, 32), CursorMode.ForceSoftware);
            break;
        }
        }
    }
Exemple #4
0
        private void OpenGpxRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            Gpx    gpxFile     = new Gpx();
            string gpxFilename = OpenGpxDialog();

            if (gpxFilename == null)
            {
                return;
            }
            XElement gpxXe = XElement.Load(gpxFilename);

            var trkList = gpxXe.Elements().Where(el => el.Name.LocalName == "trk").ToList();

            foreach (var trkXe in trkList)
            {
                Track track = new Track();
                foreach (var trksegXe in trkXe.Elements().Where(el => el.Name.LocalName == "trkseg").ToList())
                {
                    TrackSegment segment = new TrackSegment();
                    foreach (var trkptXe in trksegXe.Elements().Where(el => el.Name.LocalName == "trkpt").ToList())
                    {
                        double   latValue  = double.Parse(trkptXe.Attribute("lat").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        double   longValue = double.Parse(trkptXe.Attribute("lon").Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        DateTime time      = DateTime.Parse(trkptXe.Elements().First(el => el.Name.LocalName == "time").Value);
                        segment.AddPoint(new TrackPoint {
                            Latitude = latValue, Longtitude = longValue, Time = time
                        });
                    }
                    track.AddSegment(segment);

                    LocationCollection locations = new LocationCollection();
                    foreach (var point in segment.GetPoints())
                    {
                        locations.Add(new Location {
                            Latitude = point.Latitude, Longitude = point.Longtitude
                        });
                    }
                    MapPolyline line = CreateMapLine(locations);
                    TracksMap.Children.Add(line);
                }
                gpxFile.AddTrack(track);
            }
        }
Exemple #5
0
        private void Waypoints2TrackRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            Gpx    gpxFile     = new Gpx();
            string gpxFilename = OpenGpxDialog();

            if (gpxFilename == null)
            {
                return;
            }
            XElement     gpxXe   = XElement.Load(gpxFilename);
            Track        track   = new Track();
            TrackSegment segment = new TrackSegment();

            var rteList = gpxXe.Elements().Where(el => el.Name.LocalName == "rte").ToList();

            if (rteList.Count != 0)
            {
                foreach (var rteXe in rteList)
                {
                    var rteptList = rteXe.Elements().Where(el => el.Name.LocalName == "rtept").ToList();
                    foreach (var rteptXe in rteptList)
                    {
                        double latValue = double.Parse(rteptXe.Attribute("lat").Value,
                                                       System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        double longValue = double.Parse(rteptXe.Attribute("lon").Value,
                                                        System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        segment.AddPoint(new TrackPoint {
                            Latitude = latValue, Longtitude = longValue
                        });
                    }
                }
                track.AddSegment(segment);
                gpxFile.AddTrack(track);
            }
            var trkList = gpxXe.Elements().Where(el => el.Name.LocalName == "trk").ToList();

            foreach (var trkXe in trkList)
            {
                var trksegList = trkXe.Elements().Where(el => el.Name.LocalName == "trkseg").ToList();
                foreach (var trksegXe in trksegList)
                {
                    var trkptList = trksegXe.Elements().Where(el => el.Name.LocalName == "trkpt").ToList();
                    foreach (var trkptXe in trkptList)
                    {
                        double latValue = double.Parse(trkptXe.Attribute("lat").Value,
                                                       System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        double longValue = double.Parse(trkptXe.Attribute("lon").Value,
                                                        System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
                        segment.AddPoint(new TrackPoint {
                            Latitude = latValue, Longtitude = longValue
                        });
                    }
                }
                track.AddSegment(segment);
                gpxFile.AddTrack(track);
            }

            LocationCollection locations = new LocationCollection();

            foreach (var point in segment.GetPoints())
            {
                locations.Add(new Location {
                    Latitude = point.Latitude, Longitude = point.Longtitude
                });
            }
            MapPolyline line = CreateMapLine(locations);

            TracksMap.Children.Add(line);

            StartEndDateWindow window = new StartEndDateWindow(track);

            window.ShowDialog();
        }
Exemple #6
0
    /// <summary>
    /// Called by Unity engine when the player is dragging mouse
    /// </summary>
    void IDragHandler.OnDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
        // If Left mouse button, look for new points
        case PointerEventData.InputButton.Left:
        {
            // Determine active Track Segment
            TrackSegment currentTrack = _track.Last();

            // Convert position from Screen Coordinates into World ones
            Vector2 newPosition = eventData.position.ScreenToWorld();

            // Update Line Renderer preview accordingly
            currentTrack.SetCurrentPoint(newPosition);

            // Check min distance has been passed
            Vector2 lastTrackPoint  = currentTrack.LastPoint;
            float   currentDistance = (lastTrackPoint - newPosition).magnitude;
            if (currentDistance < MinDistance)
            {
                return;
            }

            // Boost first point assignment (it cannot snap due to angle comparison)
            if (currentTrack.PointCount <= 1)
            {
                currentDistance *= 3f;
            }

            // Check if max distance has been passed..
            if (currentDistance > MaxDistance)
            {
                // ..create a new point
                currentTrack.AddPoint(newPosition);
                return;
            }

            // Check angle is over min threshold..
            if (currentTrack.PointCount <= 1)
            {
                return;
            }

            Vector2 currentDirection  = newPosition - lastTrackPoint;
            Vector2 previousDirection = lastTrackPoint - currentTrack[currentTrack.PointCount - 2];
            float   currentAngle      = currentDirection.GetZAngle();
            float   previousAngle     = previousDirection.GetZAngle();
            if (Mathf.Abs(Mathf.DeltaAngle(previousAngle, currentAngle)) > MaxAngleDifference)
            {
                // ..create a new point
                currentTrack.AddPoint(newPosition);
            }

            break;
        }

        // If right button is pressed, drag camera
        case PointerEventData.InputButton.Right:
        {
            // Convert new and previous positions from Screen Coordinates into World ones
            Vector2 currentPosition  = eventData.position.ScreenToWorld();
            Vector2 previousPosition = (eventData.position - eventData.delta).ScreenToWorld();

            // Drag camera based in their World-space distance
            Vector3 distance = currentPosition - previousPosition;
            Camera.main.transform.position -= distance;
            break;
        }
        }
    }
Exemple #7
0
            private void _GetTracks(ArrayList TrackInformation, GPX gpxfile)
            {
                //Die passende SQLite Tabelle lasen
                System.Data.DataTable datatableWP = _sqlitebase.ExecuteQuery("SELECT * FROM \"WP\"");
                System.Data.DataTable datatableGPS= _sqlitebase.ExecuteQuery("SELECT * FROM \"GPSLog\"");

                //Für jeden Track ausführen:
                foreach (SQLiteTracks sqlitetrack in TrackInformation)
                {
                    //Tracksegment erstellen
                    TrackSegment tracksegment = new TrackSegment();

                    //Variablen erstellen
                    double latitude,longitude,elevation;
                    DateTime gpxdatetime;

                    //Alle Punkte in der DB ablaufen
                    for (int i = sqlitetrack.FirstWP; i < sqlitetrack.LastWP; i++)
                    {
                        //Punktdaten holen
                        latitude = (float) (datatableWP.Rows[i][9]);
                        longitude = (float) datatableWP.Rows[i][8];
                        elevation = (float) datatableWP.Rows[i][10];
                        gpxdatetime = DateTime.FromFileTime((((long)(int)datatableGPS.Rows[i][2]) << 32)+(int)datatableGPS.Rows[i][3]);

                        //Wenn Sommerzeit war, dann ziehe eine Stunde ab
                        TimeZone localZone = TimeZone.CurrentTimeZone;
                        if(localZone.IsDaylightSavingTime(gpxdatetime))
                        {
                            gpxdatetime = gpxdatetime.AddHours(-1);
                        }

                        //Zu UTC konvertieren
                        gpxdatetime = gpxdatetime.ToUniversalTime();

                        //Punkt erstellen
                        DanielLibrary.GPXWriter.Utils.Point pointtmp = new Point(latitude,longitude,elevation,gpxdatetime);

                        //Punkt zum Segment hinzufügen
                        tracksegment.AddPoint(pointtmp);
                    }

                    //Track erstellen
                    Track track = new Track();

                    //Track, Segment und GPX verbinden
                    track.AddSegment(tracksegment);
                    gpxfile.AddTrack(track);
                }
            }