private void CalculateMapView()

in CSharp/BotBuilderLocation/Azure/AzureMapsSpatialService.cs [110:138]


        private void CalculateMapView(List<double> boundaryBox, double mapWidth, double mapHeight, int buffer, out LatLng center, out int zoom)
        {
            if(boundaryBox == null || boundaryBox.Count < 4)
            {
                center = new LatLng() { Latitude = 0, Longitude = 0 };
                zoom = 1;
                return;
            }

            center = new LatLng();
            double maxLat = boundaryBox[2];
            double minLat = boundaryBox[0];
            double maxLon = boundaryBox[3];
            double minLon = boundaryBox[1];

            center.Latitude = (maxLat + minLat) / 2;
            center.Longitude = (maxLon + minLon) / 2;
            double zoom1 = 1, zoom2 = 1;
            //Determine the best zoom level based on the map scale and bounding coordinate information
            if (maxLon != minLon && maxLat != minLat)
            {
                //best zoom level based on map width
                zoom1 = Math.Log(360.0 / 256.0 * (mapWidth - 2 * buffer) / (maxLon - minLon)) / Math.Log(2);
                //best zoom level based on map height
                zoom2 = Math.Log(180.0 / 256.0 * (mapHeight - 2 * buffer) / (maxLat - minLat)) / Math.Log(2);
            }
            //use the most zoomed out of the two zoom levels
            zoom = (int)Math.Floor((zoom1 < zoom2) ? zoom1 : zoom2);
        }