static WebMercatorUtility() { MaxAllowableLatitude = 85.05112877822864; MaxIsometricLatitude = MapProjects.GeodeticLatitudeToIsometricLatitude(MaxAllowableLatitude, FirstEccentricity); MinIsometricLatitude = MapProjects.GeodeticLatitudeToIsometricLatitude(-MaxAllowableLatitude, FirstEccentricity); ZoomLevels = Enumerable.Range(0, 24).Reverse().Select(i => new ZoomScale(i, 591657550.50 / Math.Pow(2, i))).ToList(); minZoomLevel = 1; maxZoomLevel = 22; //ZoomLevels = new List<ZoomScale>(); //24: 591657550.50 / 2 ^ (24 - 1) = 70.5311 //23: 591657550.50 / 2 ^ (23 - 1) = 141.0622 //22: 591657550.50 / 2 ^ (22 - 1) = 282.1243 //21: 591657550.50 / 2 ^ (21 - 1) = 564.2486 //20: 591657550.50 / 2 ^ (20 - 1) = 1128.4972 //TO SUPPORT CORRECT ZOOM LEVEL //ZoomLevels.Add(new ZoomScale(20, double.Epsilon)); //ZoomLevels.Add(new ZoomScale(19, 1128.497220)); //ZoomLevels.Add(new ZoomScale(18, 2256.994440)); //ZoomLevels.Add(new ZoomScale(17, 4513.988880)); //ZoomLevels.Add(new ZoomScale(16, 9027.977761)); //ZoomLevels.Add(new ZoomScale(15, 18055.955520)); //ZoomLevels.Add(new ZoomScale(14, 36111.911040)); //ZoomLevels.Add(new ZoomScale(13, 72223.822090)); //ZoomLevels.Add(new ZoomScale(12, 144447.644200)); //ZoomLevels.Add(new ZoomScale(11, 288895.288400)); //ZoomLevels.Add(new ZoomScale(10, 577790.576700)); //ZoomLevels.Add(new ZoomScale(9, 1155581.153000)); //ZoomLevels.Add(new ZoomScale(8, 2311162.307000)); //ZoomLevels.Add(new ZoomScale(7, 4622324.614000)); //ZoomLevels.Add(new ZoomScale(6, 9244649.227000)); //ZoomLevels.Add(new ZoomScale(5, 18489298.450000)); //ZoomLevels.Add(new ZoomScale(4, 36978596.910000)); //ZoomLevels.Add(new ZoomScale(3, 73957193.820000)); //ZoomLevels.Add(new ZoomScale(2, 147914387.600000)); //ZoomLevels.Add(new ZoomScale(1, 295828775.300000)); //ZoomLevels.Add(new ZoomScale(0, 591657550.500000)); }
public static Point LatLonToImageNumber(double geocentricLatitude, double geocentricLongitude, int zoom) { var tempLongitude = geocentricLongitude % 360; if (tempLongitude > 180) { tempLongitude -= 180; } else { tempLongitude += 180; } //This is not the total number of images. It's the number of images per row/column int numberOfImages = (int)Math.Pow(2, zoom); var xUnit = 360.0 / numberOfImages; var yUnit = (MaxIsometricLatitude - MinIsometricLatitude) / numberOfImages; var columnNumber = Math.Floor(tempLongitude / xUnit); var isoY = MapProjects.GeodeticLatitudeToIsometricLatitude(geocentricLatitude, FirstEccentricity); var rowNumber = isoY / yUnit; if (rowNumber < 0) { rowNumber = Math.Ceiling(-rowNumber) + Math.Ceiling(MaxIsometricLatitude / yUnit) - 1; } else { rowNumber = Math.Ceiling(MaxIsometricLatitude / yUnit) - Math.Ceiling(rowNumber); } return(new Point(columnNumber, rowNumber)); }