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

时间:2014-03-17 04:17:08

标签: javascript kml google-earth google-earth-plugin kmz

据我所知,没有opportunity将3D对象添加到Google地球中,因此该工具还提供了在本地GE(?)中添加对象的机会。我们正在寻找什么。我们尝试从official page做一些示例,但没有成功添加精确的3D对象并将其放置在所需的坐标中。我的问题是:

  1. 是否足以让GE插件拥有本地版本的GE或我们究竟需要什么?
  2. 是否真的可以将3D对象添加到GE本地插件?
  3. 如何使用所需坐标运行此示例(约:51.02 lat :71.08)?
  4. 如果需要添加.dae文件,如何更改其位置坐标?

  5. 这是我们带有JS脚本(kmz-file)的完整html文件:

    <!--
    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>
    

1 个答案:

答案 0 :(得分:1)

尝试使用此演示 https://code.google.com/apis/ajax/playground/#creating_3d_models

它使用当前视点将模型置于此位代码

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

删除第一行并将下两行更改为

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