حساب نطاق وارتفاع عنصر Lookat Lookat من Google Earth KML لتناسب جميع الميزات (المضلعات)
-
14-11-2019 - |
سؤال
لدي العديد من المضلعات مرسومة على السطح في البرنامج المساعد Google Earth.أنا توليد KML منها.
السؤال هو كيف يمكنني حساب المعلمات ل Lookat بحيث يشمل العرض جميع المضلعات عند فتحه في سطح المكتب Google Earth؟ بالنسبة ل Lat و Lon، فهو بسيط للغاية - فقط احسب مركز المربع المحيط، ولكن ماذا عن الارتفاع والمعلمات النطاق؟
على سبيل المثال لدينا اثنين من المضلعات: giveacodicetagpre.
ثم lon و lat سيكون
LON= (40.724536 + 40.721977) / 2=40.7232565
LAT= - (74.001091 + 74.003738) / 22-74.0024145
الآن كيفية حساب النطاق والارتفاع؟
المحلول
Take a look at the Google Earth API Utility Library. It augments the functionality of the Earth API providing useful helper methods which wrap up commonly needed tasks for you.
It includes a createBoundsView() method which will build you a LookAt
object configured to fit a given bounding box within the viewport. Does exactly what you need I think. e.g.
function flyToBox(max_x, max_y, min_x, min_y) {
var bounds = new geo.Bounds([min_y, min_x], [max_y, max_x]);
var options = {aspectRatio : $('#map3d').width() / $('#map3d').height(), scaleRange : 2};
ge.getView().setAbstractView(gex.view.createBoundsView(bounds, options));
}