开发者

Calculate range and altitude of the Google Earth KML LookAt element to fit all features (polygons)

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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜