apps/web-app-template/app.js
// sectors' diagonal, and set that as the range (altitude) of the camera.
sectors' diagonal, and set that as the range (altitude) of the camera.
sectors ' diagonal and set that as the range ( altitude ) of the camera .
function computeZoomRange(layerSector) {
                var verticalBoundary = layerSector.maxLatitude - layerSector.minLatitude;
                var horizontalBoundary = layerSector.maxLongitude - layerSector.minLongitude;
                var diagonalAngle = Math.sqrt(Math.pow(verticalBoundary, 2) + Math.pow(horizontalBoundary, 2));
                if (diagonalAngle >= 180) {
                    return null;
                } else {
                    var diagonalArcLength = (diagonalAngle / 360) * (2 * 3.1416 * 6371000);
                    return diagonalArcLength;
                }
            }
function computeZoomRange ( layerSector ) { var verticalBoundary = layerSector . maxLatitude - layerSector . minLatitude ; var horizontalBoundary = layerSector . maxLongitude - layerSector . minLongitude ; var diagonalAngle = Math . sqrt ( Math . pow ( verticalBoundary , 2 ) + Math . pow ( horizontalBoundary , 2 ) ) ; if ( diagonalAngle >= 180 ) { return null ; } else { var diagonalArcLength = ( diagonalAngle / 360 ) * ( 2 * 3.1416 * 6371000 ) ; return diagonalArcLength ; } }
sectors' diagonal, and set that as the range (altitude) of the camera.
sectors ' diagonal and set that as the range ( altitude ) of the camera .
// Calculate diagonal angle between boundaries (simple pythagoras formula, we don't need to // consider vectors or great circles). // If the diagonal angle is equal or more than an hemisphere (180°) don't change zoom level. // Else, use the diagonal arc length as camera altitude. // Gross approximation of longitude of arc in km // (assuming spherical Earth with radius of 6,371 km. Accuracy is not needed for this).