Berechnen Sie Reichweite und Höhe des Google Earth KML Lookat-Elements, um alle Funktionen (Polygone) anzupassen

StackOverflow https://stackoverflow.com/questions/5491315

  •  14-11-2019
  •  | 
  •  

Frage

Ich habe mehrere Polygone auf der Oberfläche in Google Earth-Plugin.Ich erwirtschaftete ein KML von ihnen.

Frage ist, wie kann ich Parameter für den Lookat berechnen, sodass die Ansicht alle Polygone enthält, wenn sie in der Desktop-Google Earth geöffnet sind? Für Lat und Lon ist es ziemlich einfach - Berechnen Sie einfach das Zentrum der Begrenzungskiste, aber was ist mit Höhen- und Range-Parametern?

Zum Beispiel haben wir zwei Polygone: generasacodicetagpre.

dann wird lon und lat sein, da LON= (40.724536 + 40.721977) /2=40.7232565
Lat= - (74.001091 + 74.003738) /2=-74.0024145

So berechnen Sie jetzt den Bereich und die Höhe?

War es hilfreich?

Lösung

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));
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top