コード例 #1
0
 public MapModel(Microsoft.Maps.MapControl.WPF.Map map)
 {
     StrokeThickness = 2;
     Polygons        = new Collection <MapPolygon>();
     Marks           = new GeoCoordinateCollection();
     _map            = map;
 }
コード例 #2
0
        /// <summary>
        /// Change the polylines on the map.
        /// </summary>
        private static void ShapesChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            MapControl mapControl = (MapControl)dependencyObject;

            if (args.OldValue != null)
            {
                // remove all old polylines from the map:
                mapControl.map.MapElements.Clear();
            }

            if (args.NewValue != null)
            {
                List <Shape> shapes = (List <Shape>)args.NewValue;
                foreach (var shape in shapes)
                {
                    MapPolyline polyline = new MapPolyline();
                    polyline.StrokeColor     = Color.FromArgb(255, 0x4f, 0x64, 0xba);
                    polyline.StrokeThickness = 6;

                    GeoCoordinateCollection locations = new GeoCoordinateCollection();
                    foreach (var point in shape.Points)
                    {
                        locations.Add(new GeoCoordinate(point.Latitude, point.Longitude));
                    }

                    polyline.Path = locations;
                    mapControl.map.MapElements.Add(polyline);
                }
            }
        }
コード例 #3
0
        public void CarregarDados(Int32 pLinhaId)
        {
            this.LayerPontosOnibus = new MapLayer();
            this.ShapeRota         = new MapPolyline();

            App.LinhaSelecionada = LinhaFacade.Instance.ObterPorId(pLinhaId);

            #region Shape da linha

            var listaRotas = RotaFacade.Instance.ListarRotaPorLinha(App.LinhaSelecionada.Codigo);

            var CoordenadasRota  = new GeoCoordinateCollection();
            var listaCoordenadas = listaRotas.Select(rota => new GeoCoordinate(Convert.ToDouble(rota.Latitude), Convert.ToDouble(rota.Longitude))).ToList();
            foreach (var item in listaCoordenadas)
            {
                CoordenadasRota.Add(item);
            }
            ShapeRota.StrokeColor     = App.LinhaSelecionada.ObjetoCor;
            ShapeRota.StrokeThickness = 4;
            ShapeRota.Path            = CoordenadasRota;

            LayoutRota = LocationRectangle.CreateBoundingRectangle(CoordenadasRota);
            #endregion

            #region Pontos da linha
            //Desenha os pontos da linha no layer

            var listaPontos = PontoFacade.Instance.ListarPontosPorLinha(App.LinhaSelecionada.Codigo);
            foreach (var ponto in listaPontos)
            {
                double latitude = 0, longitude = 0;

                Double.TryParse(ponto.Latitude, out latitude);
                Double.TryParse(ponto.Longitude, out longitude);

                var coordenada = new GeoCoordinate(latitude, longitude);

                var imgPontoOnibus = PinMaker.PontoDeOnibus(ponto) as Image;
                imgPontoOnibus.Tap += (sender, e) =>
                {
                    MessageBox.Show(ponto.Nome);
                };

                var mapOver = new MapOverlay();
                mapOver.GeoCoordinate  = coordenada;
                mapOver.Content        = imgPontoOnibus;
                mapOver.PositionOrigin = new Point(0.5, 1);

                LayerPontosOnibus.Add(mapOver);
            }
            #endregion

            if (CarregamentoCompleto != null)
            {
                CarregamentoCompleto(this, null);
            }
        }
コード例 #4
0
        void DrawRoute(RunData item)
        {
            JustRunDataContext db = new JustRunDataContext(JustRunDataContext.ConnectionString);
            GeoCoordinateCollection geoCollection = new GeoCoordinateCollection();
            var geoCords = db.GeoCords.Where(p => p.No == item.No);
            foreach(var gc in geoCords)
            {
                GeoCoordinate _geoCord=new GeoCoordinate();
                _geoCord.Longitude=gc.Longitude;
                _geoCord.Latitude=gc.Latitude;
                geoCollection.Add(_geoCord);
            }
            if (geoCollection.Count != 0)
                Map.Center = geoCollection[0];
            else
            {
                MessageBox.Show(AppResources.NoGeoFoundMsg);
                NavigationService.GoBack();
                return;
            }
            Map.ZoomLevel = 16;
            Time.Text = item.Datetime.ToShortTimeString();
            Date.Text = item.Datetime.ToShortDateString();
            foreach (var geoCord in geoCollection)
            {
                _line.Path.Add(geoCord);
            }
            MapOverlay myLocationOverlay = new MapOverlay();
            BitmapImage tn = new BitmapImage();
            tn.SetSource(Application.GetResourceStream(new Uri(@"Assets/finishflag.png", UriKind.Relative)).Stream);
            Image img = new Image();
            img.Source = tn;
            img.Height = 80;
            img.Width = 80;
            myLocationOverlay.Content = img;
            myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
            myLocationOverlay.GeoCoordinate = geoCollection[geoCollection.Count - 1];

            MapLayer myLocationLayer = new MapLayer();
            myLocationLayer.Add(myLocationOverlay);

            myLocationOverlay = new MapOverlay();
            tn = new BitmapImage();
            tn.SetSource(Application.GetResourceStream(new Uri(@"Assets/GreenBall.png", UriKind.Relative)).Stream);
            img = new Image();
            img.Source = tn;
            img.Height = 25;
            img.Width = 25;
            myLocationOverlay.Content = img;
            myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
            myLocationOverlay.GeoCoordinate = geoCollection[0];

            myLocationLayer.Add(myLocationOverlay);
            Map.Layers.Add(myLocationLayer);
            Map.Center = geoCollection[geoCollection.Count / 2];
        }
コード例 #5
0
        /// <summary>
        /// Gets a LocationCollection representing an enumeration of points.
        /// </summary>
        /// <param name="ezp"></param>
        /// <returns></returns>
        public static GeoCoordinateCollection ToGeoCoordinateCollection(this IEnumerable <ZonePoint> ezp)
        {
            GeoCoordinateCollection coll = new GeoCoordinateCollection();

            foreach (ZonePoint p in ezp)
            {
                coll.Add(p.ToGeoCoordinate());
            }

            return(coll);
        }
コード例 #6
0
        public static GeoCoordinateCollection CreateRectangle(GeoCoordinate topLeft, GeoCoordinate bottomRight)
        {
            var locations = new GeoCoordinateCollection();

            locations.Add(new GeoCoordinate(topLeft.Latitude, topLeft.Longitude));
            locations.Add(new GeoCoordinate(topLeft.Latitude, bottomRight.Longitude));
            locations.Add(new GeoCoordinate(bottomRight.Latitude, bottomRight.Longitude));
            locations.Add(new GeoCoordinate(bottomRight.Latitude, topLeft.Longitude));

            return(locations);
        }
コード例 #7
0
        /// <summary>
        /// Converts a LocationCollection into a CoordinateCollection object.
        /// </summary>
        /// <param name="locations">A Bing Maps LocationCollection object</param>
        /// <returns>A CoordinateCollection representation of the LocationCollection object</returns>
        public static CoordinateCollection ToGeometry(this GeoCoordinateCollection locations)
        {
            CoordinateCollection coords = new CoordinateCollection();

            for (int i = 0; i < locations.Count; i++)
            {
                coords.Add(new Coordinate(locations[i].Latitude, locations[i].Longitude, locations[i].Altitude));
            }

            return(coords);
        }
コード例 #8
0
ファイル: Serializer.cs プロジェクト: JeffKarmy/RipTrail
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public GeoCoordinateCollection ReadGPXFile(Stream stream)
        {
            XElement allData = XElement.Load(stream);
            GeoCoordinateCollection geoCollection = new GeoCoordinateCollection();

            XNamespace xn = allData.GetDefaultNamespace();

            var routesAndTracks = (from e in allData.DescendantsAndSelf()
                                   select new
            {
                RouteElements = e.Descendants(xn + "rte"),
                TrackElements = e.Descendants(xn + "trk")
            }).FirstOrDefault();

            List <XElement> mapPoints;

            if (routesAndTracks.RouteElements.Count() > 0)
            {
                mapPoints = (from p in routesAndTracks.RouteElements.First().Descendants(xn + "rtept")
                             select p).ToList();
            }
            else if (routesAndTracks.TrackElements.Count() > 0)
            {
                mapPoints = (from p in routesAndTracks.TrackElements.First().Descendants(xn + "trkpt")
                             select p).ToList();
            }
            else
            {
                MessageBox.Show("The GPX file contains no route data; missing the <rte> or <trk> element.");
                return(null);
            }

            for (int i = 0; i < mapPoints.Count(); i++)
            {
                XElement xe   = mapPoints[i];
                double   dLat = 0;
                double   dLon = 0;

                if (xe.Attribute("lat") != null)
                {
                    dLat = double.Parse(xe.Attribute("lat").Value);
                }
                if (xe.Attribute("lon") != null)
                {
                    dLon = double.Parse(xe.Attribute("lon").Value);
                }

                geoCollection.Add(new GeoCoordinate(dLat, dLon));
            }
            return(geoCollection);
        }
コード例 #9
0
ファイル: GeoHelper.cs プロジェクト: Reedman/WinPhoneApp
        public static GeoCoordinateCollection ParsePointsFromString(String pts,Char pairSplitChar,Char coordinateSplitChar)
        {
            var geoPts = new GeoCoordinateCollection();
            if(pts != null && pts != "")
            {
                var ptArray = pts.Split(pairSplitChar);
                foreach(var pt  in ptArray)
                {
                    geoPts.Add(new System.Device.Location.GeoCoordinate(double.Parse(pt.Split(coordinateSplitChar)[1]),double.Parse(pt.Split(coordinateSplitChar)[0])));
                }
            }

            return geoPts;
        }
コード例 #10
0
ファイル: MapFunctions.cs プロジェクト: JeffKarmy/RipTrail
        /// <summary>
        ///
        /// </summary>
        /// <param name="track"></param>
        public void LoadTrackInMap(GeoCoordinateCollection track)
        {
            MapPolyline line = new MapPolyline();

            line.StrokeColor     = _miscFunctions.GetAccentColor();
            line.StrokeThickness = 4;
            line.Path            = track;

            LocationRectangle locRect = new LocationRectangle(track.Max((p) => p.Latitude),
                                                              track.Min((p) => p.Longitude),
                                                              track.Min((p) => p.Latitude),
                                                              track.Max((p) => p.Longitude));

            App.MyMap.MapElements.Add(line);
            App.MyMap.SetView(locRect);
        }
コード例 #11
0
ファイル: GeoHelper.cs プロジェクト: Reedman/WinPhoneApp
        /// <summary>
        /// 判断多边形edge是否为顺时针
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static bool IsClockWise(GeoCoordinateCollection points)
        {
            if (points.Count() < 4)
                throw new ArgumentException("多边形构成错误");
            
            double area = 0;
            for (var i = 1; i < points.Count(); i++)
            {
                area += (points[i].Longitude - points[i - 1].Longitude) * (points[i].Latitude + points[i - 1].Latitude);
            }

            if(area == 0)
                throw new ArgumentException("多边形构成错误");
            
            //正数,顺时针
            return area > 0 ? true : false;
        }
コード例 #12
0
ファイル: MapHelper.cs プロジェクト: kbo4sho/graffiti
        public static GeoCoordinateCollection CreateCircle(GeoCoordinate center, double radius)
        {
            var earthRadius = 6367.0; // radius in kilometers
            var lat = MathHelper.ToRadians((float)center.Latitude); //radians
            var lng = MathHelper.ToRadians((float)center.Longitude); //radians
            var d = radius / earthRadius; // d = angular distance covered on earth's surface
            var locations = new GeoCoordinateCollection();

            for (var x = 0; x <= 360; x++)
            {
                var brng = MathHelper.ToRadians(x);
                var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
                var lngRadians = lng + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));
                locations.Add(new GeoCoordinate(MathHelper.ToDegrees((float)latRadians), MathHelper.ToDegrees((float)lngRadians)));
            }

            return locations;
        }
コード例 #13
0
        public static GeoCoordinateCollection CreateCircle(GeoCoordinate center, double radius)
        {
            var earthRadius = 6367000;                    // radius in meters
            var lat         = ToRadian(center.Latitude);  //radians
            var lng         = ToRadian(center.Longitude); //radians
            var d           = radius / earthRadius;       // d = angular distance covered on earth's surface
            var locations   = new GeoCoordinateCollection();

            for (var x = 0; x <= 360; x++)
            {
                var brng       = ToRadian(x);
                var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
                var lngRadians = lng + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));

                locations.Add(new GeoCoordinate(ToDegrees(latRadians), ToDegrees(lngRadians)));
            }

            return(locations);
        }
コード例 #14
0
        public Flight(Collection <LocationMark> detectedFires, GeoCoordinateCollection coveredArea, string filePath, MapModel mapModel)
        {
            Folder   = filePath;
            MapModel = mapModel;
            Images   = coveredArea.Count;
            Date     = DateTime.Now;

            if (MapModel != null)
            {
                if (detectedFires.Any())
                {
                    MapModel.Shading = MapPolygonExtensions.RED_AREA_SHADING;
                    MapModel.Stroke  = MapPolygonExtensions.RED_AREA_STROKE;
                }
                else
                {
                    MapModel.Shading = MapPolygonExtensions.GREEN_AREA_SHADING;
                    MapModel.Stroke  = MapPolygonExtensions.GREEN_AREA_STROKE;
                }

                var allCoveredArea = coveredArea.ConvexHull();

                MapPolygon analizedArea = null;
                if (allCoveredArea != null && allCoveredArea.Count > 2)
                {
                    MapModel.StartNewPolygon();

                    foreach (var point in allCoveredArea)
                    {
                        MapModel.AddPointToPolygon(point);
                    }

                    analizedArea = MapModel.FinishCurrentPolygon();
                    CoveredArea  = analizedArea.CoveredArea();
                }

                foreach (var loc in detectedFires)
                {
                    MapModel.Marks.Add(loc);
                }
            }
        }
コード例 #15
0
        private void DoCreateTheAreaCircle()
        {
            GeoCoordinateCollection boundingLocations = CreateCircle(oneMarker.GeoCoordinate, areaRadius);

            if (PolyCircle == null)
            {
                PolyCircle = new MapPolygon();

                PolyCircle.Path            = boundingLocations;
                PolyCircle.FillColor       = Color.FromArgb(0x55, 0xFF, 0xFF, 0x00);
                PolyCircle.StrokeColor     = Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF);
                PolyCircle.StrokeThickness = 1;

                map1.MapElements.Add(PolyCircle);
            }
            else
            {
                PolyCircle.Path = boundingLocations;
            }
        }
コード例 #16
0
        public AnalyzeImages()
        {
            InitializeComponent();

            IsWarmingUp    = true;
            ServiceRunning = true;
            DetectedFires  = new Collection <LocationMark>();
            CoveredArea    = new GeoCoordinateCollection();

            _serviceUrl = ConfigurationManager.AppSettings["prometheusWebServiceUrl"].ToString() + "/score";
            _worker     = new BackgroundWorker()
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };
            _worker.DoWork             += _worker_DoWorkByBatch;
            _worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
            _worker.ProgressChanged    += _worker_ProgressChanged;

            DataContext = this;
        }
コード例 #17
0
        /// <summary>
        /// Converts a CoordinateCollection into a Bing Maps GeoCoordinateCollection.
        /// </summary>
        /// <param name="coordinates">CoordinateCollection to convert.</param>
        /// <returns>GeoCoordinateCollection of the converted CoordinateCollection.</returns>
        public static GeoCoordinateCollection ToBMGeometry(this CoordinateCollection coordinates)
        {
            var locs = new GeoCoordinateCollection();

            if (coordinates.Count > 0 && coordinates[0].Altitude.HasValue)
            {
                foreach (var c in coordinates)
                {
                    locs.Add(new GeoCoordinate(c.Latitude, c.Longitude, c.Altitude.Value));
                }
            }
            else
            {
                foreach (var c in coordinates)
                {
                    locs.Add(new GeoCoordinate(c.Latitude, c.Longitude));
                }
            }

            return(locs);
        }
コード例 #18
0
        public DistancePathAnimation(List <PathPoint> path, IntervalCallback intervalCallback, bool isGeodesic, int?duration)
#endif
        {
            _path       = path;
            _isGeodesic = isGeodesic;
            _duration   = duration;



            _timerId          = new DispatcherTimer();
            _timerId.Interval = new TimeSpan(0, 0, 0, 0, _delay);
            double _distance = 0;

            _timerId.Tick += (s, a) =>
            {
                if (!_isPaused)
                {
                    double progress = (double)(_frameIdx * _delay) / (double)_duration.Value;

                    if (progress > 1)
                    {
                        progress = 1;
                    }

                    if (intervalCallback != null)
                    {
                        List <PathPoint> temppath = path.FindAll(o => o.distance >= _distance);
                        intervalCallback(new Location(temppath[0].latitude, temppath[0].longitude, (double)temppath[0].height), path.Count - temppath.Count, _frameIdx);
                    }

                    if (progress == 1)
                    {
                        _timerId.Stop();
                    }

                    _distance += 100;
                }
            };
        }
コード例 #19
0
        private void RefreshMapElements()
        {
            // Clears map elements.
            System.Collections.ObjectModel.Collection <MapElement> elements = MapControl.MapElements;
            elements.Clear();

            // Refresh player accuracy polygon.
            GeoCoordinateCollection playerAccuracyArea = ViewModel.PlayerAccuracyArea;

            if (playerAccuracyArea != null)
            {
                elements.Add(new MapPolygon()
                {
                    Path            = playerAccuracyArea,
                    StrokeThickness = 2,
                    FillColor       = _playerAccuracyFillColor,
                    StrokeColor     = _playerAccuracyStrokeColor
                });
            }

            // Refreshes zones.
            IEnumerable <GameMapViewModel.ZoneData> zones = ViewModel.Zones;

            if (zones != null)
            {
                foreach (GameMapViewModel.ZoneData zone in zones)
                {
                    elements.Add(new MapPolygon()
                    {
                        Path            = zone.Points,
                        FillColor       = _polygonFillColor,
                        StrokeColor     = _polygonStrokeColor,
                        StrokeThickness = 2
                    });
                }
            }
        }
コード例 #20
0
ファイル: PathAnimation.cs プロジェクト: inigofu/biketrainer
        public PathAnimation(LocationCollection path, IntervalCallback intervalCallback, bool isGeodesic, int?duration)
#endif
        {
            _path       = path;
            _isGeodesic = isGeodesic;
            _duration   = duration;

            PreCalculate();

            _timerId          = new DispatcherTimer();
            _timerId.Interval = new TimeSpan(0, 0, 0, 0, _delay);

            _timerId.Tick += (s, a) =>
            {
                if (!_isPaused)
                {
                    double progress = (double)(_frameIdx * _delay) / (double)_duration.Value;

                    if (progress > 1)
                    {
                        progress = 1;
                    }

                    if (intervalCallback != null)
                    {
                        intervalCallback(_intervalLocs[_frameIdx], _intervalIdx[_frameIdx], _frameIdx);
                    }

                    if (progress == 1)
                    {
                        _timerId.Stop();
                    }

                    _frameIdx++;
                }
            };
        }
コード例 #21
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _locationTracker = Mvx.Resolve <ILocationTrackerService>();
            _locationTracker.Subscribe();

            var messenger = Mvx.Resolve <IMvxMessenger>();

            _locationToken = messenger.Subscribe <LocationMessage>(message =>
            {
                if (!message.IsError)
                {
                    var coords = new GeoCoordinate(message.Lat, message.Lng)
                    {
                        HorizontalAccuracy = message.Accuracy ?? 0
                    };
                    InitializeUserPositionIfNeeded(coords);
                    ShowLocation(coords);

                    AddressPushPin.Content       = message.Address;
                    AddressPushPin.GeoCoordinate = coords;
                    if (message.Accuracy.HasValue)
                    {
                        var coordinates         = GeoHelper.CalculatePolygon(coords.Latitude, coords.Longitude, coords.HorizontalAccuracy).Select(c => c.ToNative());
                        var geoCoordsCollection = new GeoCoordinateCollection();

                        foreach (var coord in coordinates)
                        {
                            geoCoordsCollection.Add(coord);
                        }
                        _mapPolygon.Path = geoCoordsCollection;
                    }
                }
            });
        }
コード例 #22
0
        void AddItem()
        {
            if (selected_shape == "Polygon")
            {
                if (poly == null)
                {
                    poly = new MapPolygon();
                    
                    //Define the polygon vertices
                    GeoCoordinateCollection boundingLocations = new GeoCoordinateCollection();
                    boundingLocations.Add(new GeoCoordinate(-1.22, -2.81));
                    boundingLocations.Add(new GeoCoordinate(60.22, 24.81));
                    boundingLocations.Add(new GeoCoordinate(60.30, 24.70));
                    boundingLocations.Add(new GeoCoordinate(60.14, 24.57));

                    //Set the polygon properties
                    poly.Path = boundingLocations;
                    poly.FillColor = Color.FromArgb(0x55, 0x00, 0xFF, 0x00);
                    poly.StrokeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
                    poly.StrokeThickness = 20;


                    //Add the polygon to the map
                    map1.MapElements.Add(poly);
                }
            }
            else if (selected_shape == "Polyline")
            {
                if (polyline == null)
                {
                    polyline = new MapPolyline();
                    polyline.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
                    polyline.StrokeThickness = 10;

                    polyline.Path = new GeoCoordinateCollection() { 
                            new GeoCoordinate(60.27, 24.81), 
                            new GeoCoordinate(60.35, 24.70), 
                            new GeoCoordinate(60.19, 24.57), 
                            new GeoCoordinate(60.27, 24.81) 
                        };

                    map1.MapElements.Add(polyline);
                }
            }
            else if (selected_shape == "Markers")
            {
                if (markerLayer == null)
                {
                    markerLayer = new MapLayer();

                    MapOverlay pin1 = new MapOverlay();
                    pin1.GeoCoordinate = new GeoCoordinate(60.27, 24.80);

                    Ellipse Circhegraphic = new Ellipse();
                    Circhegraphic.Fill = new SolidColorBrush(Colors.Green);
                    Circhegraphic.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    Circhegraphic.StrokeThickness = 5;
                    Circhegraphic.Opacity = 0.8;
                    Circhegraphic.Height = 40;
                    Circhegraphic.Width = 40;

                    pin1.Content = Circhegraphic;
                    pin1.PositionOrigin = new Point(0.5, 0.5);

                  
                    MapOverlay pin2 = new MapOverlay();
                    pin2.GeoCoordinate = new GeoCoordinate(60.22, 24.70);

                    Ellipse circ2 = new Ellipse();
                    circ2.Fill = new SolidColorBrush(Colors.Green);
                    circ2.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    circ2.StrokeThickness = 5;
                    circ2.Opacity = 0.8;
                    circ2.Height = 40;
                    circ2.Width = 40;
                    pin2.Content = circ2;
                    pin2.PositionOrigin = new Point(0.5, 0.5);

                    MapOverlay pin3 = new MapOverlay();
                    pin3.GeoCoordinate = new GeoCoordinate(60.27, 24.70);
                    Ellipse circ3 = new Ellipse();
                    circ3.Fill = new SolidColorBrush(Colors.Green);
                    circ3.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    circ3.StrokeThickness = 5;
                    circ3.Opacity = 0.8;
                    circ3.Height = 40;
                    circ3.Width = 40;
                    pin3.Content = circ3;

                    pin3.PositionOrigin = new Point(0.5, 0.5);

                    markerLayer.Add(pin1);
                    markerLayer.Add(pin2);
                    markerLayer.Add(pin3);
                    map1.Layers.Add(markerLayer);
                }
            }
        }
コード例 #23
0
        void AddItem()
        {
            if (selected_shape == "Polygon")
            {
                if (poly == null)
                {
                    poly = new MapPolygon();

                    //Define the polygon vertices
                    GeoCoordinateCollection boundingLocations = new GeoCoordinateCollection();
                    boundingLocations.Add(new GeoCoordinate(-1.22, -2.81));
                    boundingLocations.Add(new GeoCoordinate(60.22, 24.81));
                    boundingLocations.Add(new GeoCoordinate(60.30, 24.70));
                    boundingLocations.Add(new GeoCoordinate(60.14, 24.57));

                    //Set the polygon properties
                    poly.Path            = boundingLocations;
                    poly.FillColor       = Color.FromArgb(0x55, 0x00, 0xFF, 0x00);
                    poly.StrokeColor     = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
                    poly.StrokeThickness = 20;


                    //Add the polygon to the map
                    map1.MapElements.Add(poly);
                }
            }
            else if (selected_shape == "Polyline")
            {
                if (polyline == null)
                {
                    polyline                 = new MapPolyline();
                    polyline.StrokeColor     = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00);
                    polyline.StrokeThickness = 10;

                    polyline.Path = new GeoCoordinateCollection()
                    {
                        new GeoCoordinate(60.27, 24.81),
                        new GeoCoordinate(60.35, 24.70),
                        new GeoCoordinate(60.19, 24.57),
                        new GeoCoordinate(60.27, 24.81)
                    };

                    map1.MapElements.Add(polyline);
                }
            }
            else if (selected_shape == "Markers")
            {
                if (markerLayer == null)
                {
                    markerLayer = new MapLayer();

                    MapOverlay pin1 = new MapOverlay();
                    pin1.GeoCoordinate = new GeoCoordinate(60.27, 24.80);

                    Ellipse Circhegraphic = new Ellipse();
                    Circhegraphic.Fill            = new SolidColorBrush(Colors.Green);
                    Circhegraphic.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    Circhegraphic.StrokeThickness = 5;
                    Circhegraphic.Opacity         = 0.8;
                    Circhegraphic.Height          = 40;
                    Circhegraphic.Width           = 40;

                    pin1.Content        = Circhegraphic;
                    pin1.PositionOrigin = new Point(0.5, 0.5);


                    MapOverlay pin2 = new MapOverlay();
                    pin2.GeoCoordinate = new GeoCoordinate(60.22, 24.70);

                    Ellipse circ2 = new Ellipse();
                    circ2.Fill            = new SolidColorBrush(Colors.Green);
                    circ2.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    circ2.StrokeThickness = 5;
                    circ2.Opacity         = 0.8;
                    circ2.Height          = 40;
                    circ2.Width           = 40;
                    pin2.Content          = circ2;
                    pin2.PositionOrigin   = new Point(0.5, 0.5);

                    MapOverlay pin3 = new MapOverlay();
                    pin3.GeoCoordinate = new GeoCoordinate(60.27, 24.70);
                    Ellipse circ3 = new Ellipse();
                    circ3.Fill            = new SolidColorBrush(Colors.Green);
                    circ3.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Purple);
                    circ3.StrokeThickness = 5;
                    circ3.Opacity         = 0.8;
                    circ3.Height          = 40;
                    circ3.Width           = 40;
                    pin3.Content          = circ3;

                    pin3.PositionOrigin = new Point(0.5, 0.5);

                    markerLayer.Add(pin1);
                    markerLayer.Add(pin2);
                    markerLayer.Add(pin3);
                    map1.Layers.Add(markerLayer);
                }
            }
        }
コード例 #24
0
ファイル: Serializer.cs プロジェクト: JeffKarmy/RipTrail
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        ///  /// <param name="name"></param>
        /// <returns></returns>
        public Track ReadGpxFileStastics(Stream stream, string name)
        {
            GeoCoordinateCollection geoCollection = new GeoCoordinateCollection();
            List <DateTime>         lstDateTime   = new List <DateTime>();
            List <string>           lstTimeString = new List <string>();
            Track    track   = new Track();
            XElement allData = XElement.Load(stream);

            track.name        = name;
            track.description = "Imported: " + DateTime.Now.ToString("dddd, MMMM M, yyyy");

            XNamespace xn = allData.GetDefaultNamespace();

            // Look for route <rte> and track <trk> elements in the route data.
            var routesAndTracks = (from e in allData.DescendantsAndSelf()
                                   select new
            {
                RouteElements = e.Descendants(xn + "rte"),
                TrackElements = e.Descendants(xn + "trk")
            }).FirstOrDefault();

            // Create a list of map points from the route <rte> element, otherwise use the track <trk> element.
            List <XElement> mapPoints;

            if (routesAndTracks.RouteElements.Count() > 0)
            {
                mapPoints = (from p in routesAndTracks.RouteElements.First().Descendants(xn + "rtept")
                             select p).ToList();
            }
            else if (routesAndTracks.TrackElements.Count() > 0)
            {
                mapPoints = (from p in routesAndTracks.TrackElements.First().Descendants(xn + "trkpt")
                             select p).ToList();
            }
            else
            {
                // Route data contains no route <rte> or track <trk> elements.
                MessageBox.Show("The GPX file contains no route data; missing the <rte> or <trk> element.");
                return(null);
            }

            // Convert the GPX map points to coordinates that can be mapped.
            for (int i = 0; i < mapPoints.Count(); i++)
            {
                XElement xe = mapPoints[i];

                if (xe.Attribute("lat") != null && xe.Attribute("lon") != null && xe.Element(xn + "ele") != null)
                {
                    geoCollection.Add(new GeoCoordinate(double.Parse(xe.Attribute("lat").Value),
                                                        double.Parse(xe.Attribute("lon").Value),
                                                        double.Parse(xe.Element(xn + "ele").Value)));
                }
                else if (xe.Attribute("lat") != null && xe.Attribute("lon") != null && xe.Element(xn + "ele") == null)
                {
                    geoCollection.Add(new GeoCoordinate(double.Parse(xe.Attribute("lat").Value),
                                                        double.Parse(xe.Attribute("lon").Value)));
                }
                else
                {
                    return(null);
                }

                if (xe.Element(xn + "time") != null)
                {
                    lstDateTime.Add(DateTimeOffset.Parse(xe.Element(xn + "time").Value).UtcDateTime);
                    lstTimeString.Add(xe.Element(xn + "time").Value);
                }
            }

            if (geoCollection.Count > 0)
            {
                for (int i = 1; i < geoCollection.Count - 1; i++)
                {
                    track.TotalMeters += geoCollection[i - 1].GetDistanceTo(geoCollection[i]);

                    if (track.MaxAltitude < geoCollection[i].Altitude)
                    {
                        track.MaxAltitude = geoCollection[i].Altitude;
                    }
                }
            }
            track.line      = new MapPolyline();
            track.line.Path = geoCollection;
            track.UTC       = new List <string>();
            track.UTC       = lstTimeString;
            TimeSpan t = lstDateTime.Last() - lstDateTime.First();

            if (track.TotalMeters > 0 && t.TotalSeconds > 0)
            {
                track.AVGSpeed = track.TotalMeters / t.TotalSeconds;
            }
            else
            {
                track.AVGSpeed = 0.0;
            }

            track.TotalTime = t.ToString(@"hh\:mm\:ss");

            if (geoCollection.Count != lstTimeString.Count)
            {
                throw new System.ArgumentException("Route is corrupt or missing elements.");
            }

            return(track);
        }
コード例 #25
0
        public static void ToGeoCordTable(GeoCoordinateCollection geoCordCollection, int No)
        {
            using (JustRunDataContext db = new JustRunDataContext(JustRunDataContext.ConnectionString))
            {
                db.CreateIfNotExists();
                db.LogDebug = true;
                foreach (var _geoCord in geoCordCollection)
                {
                    GeoCord geoCord = new GeoCord();
                    geoCord.No = No;
                    geoCord.Latitude = _geoCord.Latitude;
                    geoCord.Longitude = _geoCord.Longitude;
                    db.GeoCords.InsertOnSubmit(geoCord);
                }
                db.SubmitChanges();
                
            }

        }
コード例 #26
0
 public ZoneData(GeoCoordinateCollection points, GeoCoordinate anchor, string name)
 {
     Points     = points;
     NameAnchor = anchor;
     Name       = name;
 }
コード例 #27
0
        public static GeoCoordinateCollection CreateRectangle(GeoCoordinate topLeft, GeoCoordinate bottomRight)
        {
            var locations = new GeoCoordinateCollection();

            locations.Add(new GeoCoordinate(topLeft.Latitude, topLeft.Longitude));
            locations.Add(new GeoCoordinate(topLeft.Latitude, bottomRight.Longitude));
            locations.Add(new GeoCoordinate(bottomRight.Latitude, bottomRight.Longitude));
            locations.Add(new GeoCoordinate(bottomRight.Latitude, topLeft.Longitude));

            return locations;
        }
コード例 #28
0
        /// <summary>This class extends from the BaseAnimation class and cycles through a set of coordinates over a period of time, calculating mid-point coordinates along the way.</summary>
        /// <param name="path">An array of locations to cycle through.</param>
        /// <param name="intervalCallback">A function that is called when a frame is to be rendered. This callback function recieves four values; current cordinate, index on path and frame index.</param>
        /// <param name="isGeodesic">Indicates if the path should follow the curve of the earth.</param>
        /// <param name="duration">Length of time in ms that the animation should run for. Default is 1000 ms.</param>
#if WINDOWS_PHONE
        public PathAnimation(GeoCoordinateCollection path, IntervalCallback intervalCallback, bool isGeodesic, int?duration)
コード例 #29
0
        void AddItem()
        {
            if (selected_shape == "Rectangle")
            {
                if (Rectangle1 == null)
                {
                    Rectangle1 = new MapLayer();

                    Rectangle rectanggle = new Rectangle();
                    rectanggle.Opacity = 0.7;

                    //Set the Rectangle properties
                    rectanggle.Name            = "jukka";
                    rectanggle.Fill            = new SolidColorBrush(Colors.Green);
                    rectanggle.Stroke          = new SolidColorBrush(Colors.Blue);
                    rectanggle.StrokeThickness = 4;
                    rectanggle.Width           = 200;
                    rectanggle.Height          = 200;

                    Rectangepoint = new GeoCoordinate(60.22, 24.81);

                    MapOverlay pin1 = new MapOverlay();
                    pin1.GeoCoordinate = Rectangepoint;
                    // pin1.PositionOrigin = PositionOrigin.Center;
                    pin1.Content = rectanggle;

                    Rectangle1.Add(pin1);
                    map1.Layers.Add(Rectangle1);
                }
            }
            else if (selected_shape == "Circle")
            {
                if (Circle == null)
                {
                    Circle = new MapLayer();

                    Ellipse Circhegraphic = new Ellipse();
                    Circhegraphic.Fill            = new SolidColorBrush(Colors.Yellow);
                    Circhegraphic.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                    Circhegraphic.StrokeThickness = 10;
                    Circhegraphic.Opacity         = 0.8;
                    Circhegraphic.Height          = 100;
                    Circhegraphic.Width           = 100;

                    Circlepoint = new GeoCoordinate(60.22, 24.81);

                    MapOverlay circc = new MapOverlay();
                    circc.GeoCoordinate = Circlepoint;
                    // pin1.PositionOrigin = PositionOrigin.Center;
                    circc.Content = Circhegraphic;

                    Circle.Add(circc);
                    map1.Layers.Add(Circle);
                }
            }
            else if (selected_shape == "Polygons")
            {
                if (PolyCircle == null)
                {
                    PolyCircle = new MapPolygon();

                    GeoCoordinateCollection boundingLocations = CreateCircle(new GeoCoordinate(60.30, 24.70), 10);

                    //Set the polygon properties
                    PolyCircle.Path            = boundingLocations;
                    PolyCircle.FillColor       = Color.FromArgb(0x55, 0xFF, 0xFF, 0x00);
                    PolyCircle.StrokeColor     = Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF);
                    PolyCircle.StrokeThickness = 4;

                    map1.MapElements.Add(PolyCircle);

                    PolyRect = new MapPolygon();

                    GeoCoordinateCollection RectLocations = CreateRectangle(new GeoCoordinate(60.35, 24.60), new GeoCoordinate(60.25, 24.80));

                    //Set the polygon properties
                    PolyRect.Path            = RectLocations;
                    PolyRect.FillColor       = Color.FromArgb(0x55, 0x00, 0x00, 0x00);
                    PolyRect.StrokeColor     = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
                    PolyRect.StrokeThickness = 4;

                    map1.MapElements.Add(PolyRect);
                }
            }
        }
コード例 #30
0
		/// <summary>
		/// Gets a LocationCollection representing an enumeration of points.
		/// </summary>
		/// <param name="ezp"></param>
		/// <returns></returns>
		public static GeoCoordinateCollection ToGeoCoordinateCollection(this IEnumerable<ZonePoint> ezp)
		{
            GeoCoordinateCollection coll = new GeoCoordinateCollection();

			foreach (ZonePoint p in ezp)
			{
				coll.Add(p.ToGeoCoordinate());
			}

			return coll;
		}
コード例 #31
0
        public TrackingViewModel(ILog log, IAccount account, ILocalize localize, IApplication application,
                                 IGeoPositionWatcher<GeoCoordinate> coordinateProvider, IHistory history,
                                 IRepository repository, ISettings settings)
        {
            _log = log;
            _localize = localize;
            _application = application;
            _coordinateProvider = coordinateProvider;
            _history = history;
            _repository = repository;
            _settings = settings;
            Account = account;

            _started = false;
            _startTime = System.Environment.TickCount;

            _coordinateProvider.PositionChanged += _coordinateProvider_PositionChanged;
            _coordinateProvider.Start();
            UICoordinates = new GeoCoordinateCollection();
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick += Timer_Tick;

            MapCenter = new GeoCoordinate(0, 0);
            Heading = 0;
            ZoomLevel = 15;
            Pitch = 55;
            PedestrianFeaturesEnabled = true;
            LandmarksEnabled = true;

            DistanceDisplay = "0 km";
            if (!_settings.IsMetric) DistanceDisplay = "0 mi";
            PaceDisplay = "00:00";
            CaloriesDisplay = "0";
            TimeDisplay = "00:00";

            StrokeColor = System.Windows.Media.Colors.Red;
            StrokeThickness = 5;
            Coordinates.Clear();

            StartVisibility = (!_started ? Visibility.Visible : Visibility.Collapsed);
            StopVisibility = (_started ? Visibility.Visible : Visibility.Collapsed);
            PauseVisibility = (!_paused ? Visibility.Visible : Visibility.Collapsed);
            ResumeVisibility = (_paused ? Visibility.Visible : Visibility.Collapsed);

        }
コード例 #32
0
ファイル: PathAnimation.cs プロジェクト: inigofu/biketrainer
        private void PreCalculate()
        {
            //Stop the timer
            if (_timerId != null && _timerId.IsEnabled)
            {
                _timerId.Stop();
            }

            _duration = (_duration.HasValue && _duration.Value > 0) ? _duration : 150;

#if WINDOWS_PHONE
            _intervalLocs = new GeoCoordinateCollection();
#elif WINDOWS_PHONE_APP
            _intervalLocs = new List <BasicGeoposition>();
#else
            _intervalLocs = new LocationCollection();
#endif
            _intervalIdx = new List <int>();

            _intervalLocs.Add(_path[0]);
            _intervalIdx.Add(0);

            double dlat, dlon;
            double totalDistance = 0;

            if (_isGeodesic)
            {
                //Calcualte the total distance along the path in KM's.
                for (var i = 0; i < _path.Count - 1; i++)
                {
                    totalDistance += SpatialTools.HaversineDistance(_path[i].ToGeometry(), _path[i + 1].ToGeometry(), DistanceUnits.KM);
                }
            }
            else
            {
                //Calcualte the total distance along the path in degrees.
                for (var i = 0; i < _path.Count - 1; i++)
                {
                    dlat = _path[i + 1].Latitude - _path[i].Latitude;
                    dlon = _path[i + 1].Longitude - _path[i].Longitude;

                    totalDistance += Math.Sqrt(dlat * dlat + dlon * dlon);
                }
            }

            int    frameCount = (int)Math.Ceiling((double)_duration.Value / (double)_delay);
            int    idx        = 0;
            double progress;

            //Pre-calculate step points for smoother rendering.
            for (var f = 0; f < frameCount; f++)
            {
                progress = (double)(f * _delay) / (double)_duration.Value;

                double travel = progress * totalDistance;
                double alpha  = 0;
                double dist   = 0;
                double dx     = travel;

                for (var i = 0; i < _path.Count - 1; i++)
                {
                    if (_isGeodesic)
                    {
                        dist += SpatialTools.HaversineDistance(_path[i].ToGeometry(), _path[i + 1].ToGeometry(), DistanceUnits.KM);
                    }
                    else
                    {
                        dlat  = _path[i + 1].Latitude - _path[i].Latitude;
                        dlon  = _path[i + 1].Longitude - _path[i].Longitude;
                        alpha = Math.Atan2(dlat * Math.PI / 180, dlon * Math.PI / 180);
                        dist += Math.Sqrt(dlat * dlat + dlon * dlon);
                    }

                    if (dist >= travel)
                    {
                        idx = i;
                        break;
                    }

                    dx = travel - dist;
                }

                if (dx != 0 && idx < _path.Count - 1)
                {
                    if (_isGeodesic)
                    {
                        var bearing = SpatialTools.CalculateHeading(_path[idx].ToGeometry(), _path[idx + 1].ToGeometry());
                        _intervalLocs.Add(SpatialTools.CalculateDestinationCoordinate(_path[idx].ToGeometry(), bearing, dx, DistanceUnits.KM).ToBMGeometry());
                    }
                    else
                    {
                        dlat = dx * Math.Sin(alpha);
                        dlon = dx * Math.Cos(alpha);

#if WINDOWS_PHONE
                        _intervalLocs.Add(new GeoCoordinate(_path[idx].Latitude + dlat, _path[idx].Longitude + dlon));
#elif WINDOWS_PHONE_APP
                        _intervalLocs.Add(new BasicGeoposition()
                        {
                            Latitude  = _path[idx].Latitude + dlat,
                            Longitude = _path[idx].Longitude + dlon
                        });
#else
                        _intervalLocs.Add(new Location(_path[idx].Latitude + dlat, _path[idx].Longitude + dlon));
#endif
                    }

                    _intervalIdx.Add(idx);
                }
            }

            //Ensure the last location is the last coordinate in the path.
            _intervalLocs.Add(_path[_path.Count - 1]);
            _intervalIdx.Add(_path.Count - 1);
        }