private void UpdateARView() { if (_currentLocation != null) { ItemCanvas.Children.Clear(); if (_poiLocations != null && _poiLocations.Length > 0) { var center = new Coordinate(_currentLocation.Position.Latitude, _currentLocation.Position.Longitude); foreach (var poi in _poiLocations) { var c = new Coordinate(poi.Latitude, poi.Longitude); var poiHeading = SpatialTools.CalculateHeading(center, c); var diff = _currentHeading - poiHeading; if (diff > 180) { diff = _currentHeading - (poiHeading + 360); } else if (diff < -180) { diff = _currentHeading + 360 - poiHeading; } if (Math.Abs(diff) <= 22.5) { var distance = SpatialTools.HaversineDistance(center, c, DistanceUnits.KM); double left = 0; if (diff > 0) { left = ItemCanvas.ActualWidth / 2 * ((22.5 - diff) / 22.5); } else { left = ItemCanvas.ActualWidth / 2 * (1 + -diff / 22.5); } double top = ItemCanvas.ActualHeight * (1 - distance / _defaultSeatchRadius); var tb = new TextBlock() { Text = poi.Name, FontSize = 24, TextAlignment = TextAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; Canvas.SetLeft(tb, left); Canvas.SetTop(tb, top); ItemCanvas.Children.Add(tb); } } } } }
private void UpdateARView() { if (_currentLocation != null) { ItemCanvas.Children.Clear(); if (_poiLocations != null && _poiLocations.Count > 0) { var currentCoord = new Coordinate(_currentLocation.Position.Latitude, _currentLocation.Position.Longitude); foreach (var poi in _poiLocations) { if (Math.Abs(poi.Location.Latitude) > 90 || Math.Abs(poi.Location.Longitude) > 180) { continue; } var poiCoord = new Coordinate(poi.Location.Latitude, poi.Location.Longitude); var poiHeading = SpatialTools.CalculateHeading(currentCoord, poiCoord); var diff = _currentHeading - poiHeading; if (diff > 180) { diff = _currentHeading - (poiHeading + 360); } else if (diff < -180) { diff = _currentHeading + 360 - poiHeading; } if (Math.Abs(diff) <= (_angleOfView / 2)) { var distance = SpatialTools.HaversineDistance(currentCoord, poiCoord, DistanceUnits.Meters); double left = 0; if (diff > 0) { left = ItemCanvas.ActualWidth / 2 * (((_angleOfView / 2) - diff) / (_angleOfView / 2)); } else { left = ItemCanvas.ActualWidth / 2 * (1 + -diff / (_angleOfView / 2)); } double top = (ItemCanvas.ActualHeight - 90) * (1 - distance / RadiusSlider.Value) + 45; var converter = new CategoryToPinSignConverter(); var symbol = (Symbol)converter.Convert(poi.Category, null, null, null); var pin = new ArPin() { PinSign = symbol, PinDist = ((int)distance).ToString() }; Canvas.SetLeft(pin, left - 32); Canvas.SetTop(pin, top - 45); ItemCanvas.Children.Add(pin); } } } } }
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); }