简体   繁体   English

如何在本地Google Earth插件中添加3D对象?

[英]How to add a 3D object into local Google Earth plugin?

As I understand there is no opportunity to add 3D object into the Google Earth, therefore the instrument yet provide chance to add objects in local GE (?). 据我了解,没有机会将3D对象添加到Google Earth中,因此该仪器仍提供了在本地GE(?)中添加对象的机会。 And what is exactly what we are looking for. 而正是我们想要的。 We tried to do some examples from official page without success in adding exactly 3D object and placed it in required coordinates. 我们尝试在官方页面上做一些示例,但未成功添加精确的3D对象并将其放置在所需的坐标中。 And my questions are: 我的问题是:

  1. Is it enough to have GE plugin to have a local version of GE or what exactly we need? 使用GE插件拥有GE的本地版本就足够了还是我们真正需要的是什么?
  2. Is it really possible to add 3D object to GE local plugin? 是否真的可以将3D对象添加到GE本地插件?
  3. How to run this example with required coordinates (approximately long : 51.02 lat :71.08)? 如何使用所需的坐标(大约 :51.02 lat :71.08)运行此示例?
  4. If it's necessary to add .dae file, how to change their location coordinates? 如果需要添加.dae文件,如何更改其位置坐标?

Here is our full html file with JS script ( kmz-file ): 这是带有JS脚本的完整html文件( kmz-file ):

<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Earth API Sample</title>    
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    var ge;

    google.load("earth", "1");

    function init() {
      google.earth.createInstance('map3d', initCallback, failureCallback);
    }

    function initCallback(pluginInstance) {
      ge = pluginInstance;
      ge.getWindow().setVisibility(true);

      // add a navigation control
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

      // add some layers
      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
      ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

      // just for debugging purposes
      document.getElementById('installed-plugin-version').innerHTML =
        ge.getPluginVersion().toString();

    var href = 'The_Pentagon.kmz';
    //var href = 'http://localhost/Users/k.bazaraly/Desktop/GoogleEarthTest/kml_example.kml';
    google.earth.fetchKml(ge, href, function(kmlObject) {
        if (kmlObject)
            ge.getFeatures().appendChild(kmlObject);
        if (kmlObject.getAbstractView() !== null)
            ge.getView().setAbstractView(kmlObject.getAbstractView());
    }); 

    }

    function failureCallback(errorCode) {
    }

    </script>
  </head>
  <body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">
    <div id="map3d" style="width: 500px; height: 380px;"></div>
    <br>
    <div>Installed Plugin Version: <span id="installed-plugin-version" style="font-weight: bold;">Loading...</span></div>
  </body>
</html>

Try using this demo instead https://code.google.com/apis/ajax/playground/#creating_3d_models 尝试使用此演示代替https://code.google.com/apis/ajax/playground/#creating_3d_models

It uses the current viewpoint to place the model with this bit of code 它使用当前视点通过此代码段放置模型

var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
loc.setLatitude(la.getLatitude());
loc.setLongitude(la.getLongitude());

remove first line and change next two to 删除第一行并更改下两个

loc.setLatitude(71.08);
loc.setLongitude(51.02);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM