Ejemplo n.º 1
0
        /// <summary>
        /// Finds the map tile that contains the given point on the given zoom level. The point must be within <see cref="MapLeaf.GridBounds"/>.
        /// </summary>
        /// <param name="point">the point that should reside inside the returned map tile</param>
        /// <param name="zoomLevel">the zoom level of the returned map tile</param>
        /// <returns>the map tile that contains the given point</returns>
        /// <exception cref="ArgumentOutOfRangeException">if the point is outside the grid bounds</exception>
        public static MapTile FindMapTileContainingPoint(EtrsTm35FinPoint point, MapTileZoomLevel zoomLevel)
        {
            if (!MapLeaf.GridBounds.Contains(point))
            {
                throw new ArgumentOutOfRangeException("point");
            }

            double width  = zoomLevel.PixelsToMetersOnXAxis(TileSizeInPixels);
            double height = zoomLevel.PixelsToMetersOnYAxis(TileSizeInPixels);

            int column = (int)((point.Easting - MapLeaf.WestGridBound) / width);
            int row    = (int)((point.Northing - MapLeaf.SouthGridBound) / height);

            return(new MapTile(zoomLevel, column, row));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new map tile.
        /// </summary>
        /// <param name="zoomLevel">the zoom level of the tile</param>
        /// <param name="column">the column of the tile</param>
        /// <param name="row">the row of the tile</param>
        public MapTile(MapTileZoomLevel zoomLevel, int column, int row)
        {
            ZoomLevel = zoomLevel;

            if (column < 0)
            {
                throw new ArgumentOutOfRangeException("column");
            }
            Column = column;

            if (row < 0)
            {
                throw new ArgumentOutOfRangeException("row");
            }
            Row = row;

            double width  = ZoomLevel.PixelsToMetersOnXAxis(TileSizeInPixels);
            double height = ZoomLevel.PixelsToMetersOnYAxis(TileSizeInPixels);

            var southWestPoint = new EtrsTm35FinPoint(
                MapLeaf.SouthGridBound + row * height,
                MapLeaf.WestGridBound + column * width);

            if (!MapLeaf.GridBounds.ContainsX(southWestPoint.X))
            {
                throw new ArgumentOutOfRangeException("column");
            }
            if (!MapLeaf.GridBounds.ContainsY(southWestPoint.Y))
            {
                throw new ArgumentOutOfRangeException("row");
            }

            var northEastPoint = new EtrsTm35FinPoint(
                southWestPoint.Northing + height,
                southWestPoint.Easting + width);

            Bounds = new GeoRect <EtrsTm35FinPoint>(southWestPoint, northEastPoint);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new map leaf with the given identifier. Its bounds will be automatically calculated based on the identifier.
        /// </summary>
        /// <param name="identifier">the map leaf identifier</param>
        public MapLeaf(MapLeafIdentifier identifier)
        {
            Identifier = identifier;
            var identifierString = identifier.Identifier;
            var rowIdentifier    = identifierString[0];
            var columnIdentifier = identifierString[1];

            // We know for sure that the identifier is valid. Now we just have to calculate the bounds.
            double height = LeafHeightInMaxScale * identifier.HeightScale;
            double width  = LeafWidthInMaxScale * identifier.WidthScale;

            // Calculate south-west point of the top leaf
            double southOrigo = SouthGridBound + LeafHeightInMaxScale * Array.IndexOf(RowLetters, rowIdentifier);
            double westOrigo  = WestGridBound + LeafWidthInMaxScale * ((int)Char.GetNumericValue(columnIdentifier) - 2);

            double southOffset = 0;
            double westOffset  = 0;

            if (identifierString.Length >= 3) // E.g. V31
            {
                var c2 = identifierString[2];
                southOffset += AdjustSouthOffset(c2, 2);
                westOffset  += AdjustWestOffset(c2, 2);

                if (identifierString.Length >= 4) // E.g. V313
                {
                    var c3 = identifierString[3];
                    southOffset += AdjustSouthOffset(c3, 4);
                    westOffset  += AdjustWestOffset(c3, 4);

                    if (identifierString.Length >= 5) // E.g. V3133
                    {
                        var c4 = identifierString[4];
                        southOffset += AdjustSouthOffset(c4, 8);
                        westOffset  += AdjustWestOffset(c4, 8);

                        if (identifierString.Length >= 6) // E.g. V3133A
                        {
                            var c5 = identifierString[5];
                            southOffset += AdjustSouthOffset(c5, 16);
                            westOffset  += AdjustWestOffset(c5, 32);

                            if (identifierString.Length == 7) // E.g. V3133A1
                            {
                                var c6 = identifierString[6];
                                southOffset += AdjustSouthOffset(c6, 32);
                                westOffset  += AdjustWestOffset(c6, 64);
                            }
                        }
                    }
                }
            }
            // The leaves in columns 2 and 6 have only half the width. We only need this correction on the top-level tiles.
            else if (columnIdentifier == '2')
            {
                width /= 2;
                // Column 2 contains the second half of the leaf
                westOrigo += width;
            }
            else if (columnIdentifier == '6')
            {
                width /= 2;
                // Column 6 contains the first half of the leaf
            }

            var southWestPoint = new EtrsTm35FinPoint(southOrigo + southOffset, westOrigo + westOffset);
            var northEastPoint = new EtrsTm35FinPoint(southOrigo + southOffset + height, westOrigo + westOffset + width);

            Bounds = new GeoRect <EtrsTm35FinPoint>(southWestPoint, northEastPoint);
        }