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);
        }
Exemple #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);
                }
            }
        }
        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);
            }
        }
        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];
        }
Exemple #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);
        }
Exemple #6
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);
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        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;
        }
Exemple #9
0
        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;
        }
        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);
        }
Exemple #11
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;
                    }
                }
            });
        }
Exemple #12
0
        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);
        }
		/// <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;
		}
        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;
        }
Exemple #15
0
        /// <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);
        }
        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);
                }
            }
        }
        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);
                }
            }
        }