Esempio n. 1
0
        /// <summary>Calculates the coordinates of the specifed point.</summary>
        /// <param name="point">A point, in pixels, relative to the top left corner of the control.</param>
        /// <returns>A Point filled with the Latitude (Y) and Longitude (X) of the specifide point.</returns>
        public Point GetLocation(Point point)
        {
            Point output = new Point();

            output.X = TileGenerator.GetLongitude((_offsetX.Pixels + point.X) / TileGenerator.TileSize, this.Zoom);
            output.Y = TileGenerator.GetLatitude((_offsetY.Pixels + point.Y) / TileGenerator.TileSize, this.Zoom);
            return(output);
        }
Esempio n. 2
0
 /// <summary>Centers the map on the specified coordinates.</summary>
 /// <param name="latitude">The latitude cooridinate.</param>
 /// <param name="longitude">The longitude coordinates.</param>
 /// <param name="zoom">The zoom level for the map.</param>
 public void Center(double latitude, double longitude, int zoom)
 {
     this.BeginUpdate();
     this.Zoom = zoom;
     _offsetX.CenterOn(TileGenerator.GetTileX(longitude, this.Zoom));
     _offsetY.CenterOn(TileGenerator.GetTileY(latitude, this.Zoom));
     this.EndUpdate();
 }
Esempio n. 3
0
        private void LoadTileInBackground(object state)
        {
            ImageSource image = TileGenerator.GetTileImage(_zoom, _tileX, _tileY);

            if (image != null) // We've already set the Source to null before calling this method.
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.Source = image;
                }));
            }
        }
Esempio n. 4
0
        /// <summary>Alters the zoom of the map, maintaing the same point underneath the mouse at the new zoom level.</summary>
        /// <param name="e">The MouseWheelEventArgs that contains the event data.</param>
        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            base.OnMouseWheel(e);

            int   newZoom = TileGenerator.GetValidZoom(this.Zoom + (e.Delta / Mouse.MouseWheelDeltaForOneLine));
            Point mouse   = e.GetPosition(this);

            this.BeginUpdate();
            _offsetX.ChangeZoom(newZoom, mouse.X);
            _offsetY.ChangeZoom(newZoom, mouse.Y);
            this.Zoom = newZoom; // Set this after we've altered the offsets
            this.EndUpdate();
        }
Esempio n. 5
0
        /// <summary>Centers the map on the specified coordinates, calculating the required zoom level.</summary>
        /// <param name="latitude">The latitude cooridinate.</param>
        /// <param name="longitude">The longitude coordinates.</param>
        /// <param name="size">The minimum size that must be visible, centered on the coordinates.</param>
        public void Center(double latitude, double longitude, Size size)
        {
            double left   = TileGenerator.GetTileX(longitude - (size.Width / 2.0), 0);
            double right  = TileGenerator.GetTileX(longitude + (size.Width / 2.0), 0);
            double top    = TileGenerator.GetTileY(latitude - (size.Height / 2.0), 0);
            double bottom = TileGenerator.GetTileY(latitude + (size.Height / 2.0), 0);

            double height = (top - bottom) * TileGenerator.TileSize;
            double width  = (right - left) * TileGenerator.TileSize;
            int    zoom   = Math.Min(TileGenerator.GetZoom(this.ActualHeight / height), TileGenerator.GetZoom(this.ActualWidth / width));

            this.Center(latitude, longitude, zoom);
        }
Esempio n. 6
0
 private void RepositionChildren()
 {
     foreach (UIElement element in this.Children)
     {
         double latitude  = GetLatitude(element);
         double longitude = GetLongitude(element);
         if (latitude != double.PositiveInfinity && longitude != double.PositiveInfinity)
         {
             double x = (TileGenerator.GetTileX(longitude, this.Zoom) - _offsetX.Tile) * TileGenerator.TileSize;
             double y = (TileGenerator.GetTileY(latitude, this.Zoom) - _offsetY.Tile) * TileGenerator.TileSize;
             Canvas.SetLeft(element, x);
             Canvas.SetTop(element, y);
             element.RenderTransform = _translate;
         }
     }
 }
Esempio n. 7
0
            /// <summary>Updates the starting tile index based on the zoom level.</summary>
            /// <param name="zoom">The zoom level.</param>
            /// <param name="offset">The distance from the edge to keep the same when changing zoom.</param>
            public void ChangeZoom(int zoom, double offset)
            {
                int currentZoom = TileGenerator.GetZoom(_mapSize / TileGenerator.TileSize);

                if (currentZoom != zoom)
                {
                    _animating = false;

                    double scale    = Math.Pow(2, zoom - currentZoom);           // 2^delta
                    double location = ((this.Pixels + offset) * scale) - offset; // Bias new location on the offset

                    _mapSize     = TileGenerator.GetSize(zoom);
                    _maximumTile = (int)((_mapSize - _size) / TileGenerator.TileSize);

                    this.Translate(this.Pixels - location);
                }
            }
Esempio n. 8
0
 private static object OnZoomPropertyCoerceValue(DependencyObject d, object baseValue)
 {
     return(TileGenerator.GetValidZoom((int)baseValue));
 }