/// <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)); }
/// <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); }