计算 Google Earth KML LookAt 元素的范围和高度以适合所有要素(多边形)

发布于 2024-10-27 20:38:52 字数 527 浏览 11 评论 0原文

我在谷歌地球插件的表面上绘制了几个多边形。我从它们生成一个 KML。

问题是如何计算 LookAt 的参数,以便在桌面 Google Earth 中打开时视图包含所有多边形? 对于纬度和经度来说,这非常简单 - 只需计算边界框的中心,但是高度和范围参数呢?

例如,我们有两个多边形:

1:
    40.724536 -74.001914
    40.724102 -74.001091
    40.723003 -74.002067
    40.723392 -74.002891
2:
    40.723186 -74.003112
    40.722843 -74.002311
    40.721977 -74.003036
    40.722320 -74.003738

那么 lon 和 lat 将是
长=(40.724536+40.721977)/2=40.7232565
lat=-(74.001091+74.003738)/2=-74.0024145

现在如何计算范围和高度?

I have several polygons drawn on the surface in google earth plugin. I generate a KML from them.

Question is how can I calculate parameters for the LookAt so that the view includes all the polygons when open in the desktop Google Earth?
For lat and lon it's quite simple - just calculate the center of bounding box, but what about altitude and range parameters?

For example we have two polygons:

1:
    40.724536 -74.001914
    40.724102 -74.001091
    40.723003 -74.002067
    40.723392 -74.002891
2:
    40.723186 -74.003112
    40.722843 -74.002311
    40.721977 -74.003036
    40.722320 -74.003738

Then lon and lat will be
lon=(40.724536+40.721977)/2=40.7232565
lat=-(74.001091+74.003738)/2=-74.0024145

Now how to calculate the range and altitude?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙味迷妹 2024-11-03 20:38:52

查看 Google 地球 API 实用程序库。它增强了 Earth API 的功能,提供了有用的帮助方法,为您封装了常用的任务。

它包含 createBoundsView() 方法 将为您构建一个 LookAt 对象,该对象配置为适合视口内给定的边界框。我认为正是您所需要的。例如

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

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));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文