Example #1
0
        /// <summary>
        /// Convert a geo-coordinate to a coordinate on the device's display.
        /// </summary>
        /// <param name="location">Geo-coordinate to convert.</param>
        /// <returns>Screen position which represents the geo-coordinate.</returns>
        public Vector2 ConvertGeoCoordinateToScreenPosition(GeoCoordinate location)
        {
            Vector2 locationPixelXY = TileSystem.LatLongToPixelXY(location, ZoomLevel);

            Vector2 pixelXYCenterToLocationScaled = (locationPixelXY - ScreenCenterPixelXY) * zoomScale;

            // Get vector to the screen center (remember that tiles are the size of the screen, ignoring zoom)
            Vector2 vectorToScreenCenter = screenCenterVector;

            return(vectorToScreenCenter + pixelXYCenterToLocationScaled);
        }
Example #2
0
        /// <summary>
        /// Initializes the active tile plane by requesting images centered at the specified geo-coordinate.
        /// </summary>
        /// <param name="centerCoordinate">The geo-coordinate which will serve as the center of the
        /// middle tile.</param>
        private void GetActivePlaneImages(GeoCoordinate centerCoordinate)
        {
            Vector2 centerPixelXY = TileSystem.LatLongToPixelXY(centerCoordinate, zoomLevel);

            int planeCenterIndex = PlaneCenterIndex;

            for (int xIndex = 0; xIndex < ActiveTilePlaneSize; xIndex++)
            {
                int xDelta = xIndex - planeCenterIndex;

                for (int yIndex = 0; yIndex < ActiveTilePlaneSize; yIndex++)
                {
                    int yDelta = yIndex - planeCenterIndex;

                    TileInformation cellInformation = activeTilePlane[xIndex, yIndex];

                    // Initialize or clean the active tile cube cell
                    if (cellInformation == null)
                    {
                        cellInformation = new TileInformation(TileServerRequestCompleted);
                        activeTilePlane[xIndex, yIndex] = cellInformation;
                    }
                    else
                    {
                        cellInformation.Dispose();
                    }

                    // Calculate the center geo-coordinate for the current tile
                    Vector2       tileCenterPixelXY = centerPixelXY + tileDimensions * new Vector2(xDelta, yDelta);
                    GeoCoordinate tileCenterGeoCoordinate;

                    try
                    {
                        tileCenterGeoCoordinate = TileSystem.PixelXYToLatLong(tileCenterPixelXY, zoomLevel);
                        GetImageFromServer(cellInformation, tileCenterGeoCoordinate, zoomLevel, ViewType);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        cellInformation.Image = unavailableImage;
                    }
                }
            }
        }