Esempio n. 1
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. 2
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));

            // todo, hacer un combinador o algo asi.
            Debug.WriteLine(String.Format("CenterSize: aw={0} ah={1} l={2} r={3} t={4} b={5} h={6} w={7} z={8} lat={9} lon={10}",
                                          (int)this.ActualWidth, (int)this.ActualHeight,
                                          left, right, top,
                                          bottom, height, width,
                                          zoom, latitude, longitude));

            this.Center(latitude, longitude, zoom);
        }