Beispiel #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);
        }
Beispiel #2
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();
        }
Beispiel #3
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;
            var tilex = TileGenerator.GetTileX(longitude, this.Zoom);

            _offsetX.CenterOn(tilex);
            var tiley = TileGenerator.GetTileY(latitude, this.Zoom);

            _offsetY.CenterOn(tiley);

            Debug.WriteLine(String.Format("CenterZoom: ty={0} tx={1} z={2} lat={3} lon={4}",
                                          tilex, tiley,
                                          zoom, latitude, longitude));
            this.EndUpdate();
        }
Beispiel #4
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);
                }
            }
Beispiel #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));

            // 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);
        }
Beispiel #6
0
 private void RepositionChildren()
 {
     if (LoadingQuadtree)
     {
         return;
     }
     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;
         }
         else
         {
             Debug.WriteLine("Descartando Objeto por Type=" + element.GetType().ToString());
         }
     }
 }
Beispiel #7
0
 private void LoadTile()
 {
     this.Source = TileGenerator.GetTileImage(_zoom, _tileX, _tileY);
 }
Beispiel #8
0
 private static object OnZoomPropertyCoerceValue(DependencyObject d, object baseValue)
 {
     return(TileGenerator.GetValidZoom((int)baseValue));
 }