Exemplo n.º 1
0
        /// <summary>
        /// Updates my location
        /// </summary>
        /// <param name="newLocation">New location</param>
        public void UpdateMyLocation(Position newLocation)
        {
            if (!MyLocation.Equals(newLocation))
            {
                // We have a location update, so abort last animation
                if (mapView.AnimationIsRunning(animationMyLocationName))
                {
                    mapView.AbortAnimation(animationMyLocationName);
                }

                // Save values for new animation
                animationMyLocationStart = MyLocation;
                animationMyLocationEnd   = newLocation;

                var animation = new Animation((v) =>
                {
                    var deltaLat = (animationMyLocationEnd.Latitude - animationMyLocationStart.Latitude) * v;
                    var deltaLon = (animationMyLocationEnd.Longitude - animationMyLocationStart.Longitude) * v;
                    var modified = InternalUpdateMyLocation(new Position(animationMyLocationStart.Latitude + deltaLat, animationMyLocationStart.Longitude + deltaLon));
                    // Update viewport
                    if (modified && mapView.MyLocationFollow && mapView.MyLocationEnabled)
                    {
                        mapView._mapControl.Navigator.CenterOn(MyLocation.ToMapsui());
                    }
                    // Refresh map
                    if (mapView.MyLocationEnabled && modified)
                    {
                        mapView.Refresh();
                    }
                }, 0.0, 1.0);

                // At the end, update viewport
                animation.Commit(mapView, animationMyLocationName, 100, 3000, finished: (s, v) => mapView.Map.RefreshData(mapView._mapControl.Viewport.Extent, mapView._mapControl.Viewport.Resolution, true));
            }
        }