【问题标题】:KML tags <Camera> and <LookAt> - doesn't work in Google Earth pluginKML 标签 <Camera> 和 <LookAt> - 在 Google 地球插件中不起作用
【发布时间】:2014-11-04 13:08:46
【问题描述】:

首先,我要感谢您为回答所做的努力。

其次,我创建了一个包含Google Earth插件的站点,并使用KML字符串显示两个坐标。我想看看经度-122.084075,纬度37.4220033612141。 当我加载我的网站时,我没有看到任何变化。

我的 html 代码 + kml 字符串:

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<script type="text/javascript">
    var ge;
    google.load("earth", "1", {"other_params":"sensor=false"});

    function init() 
    {
        google.earth.createInstance('map3d', initCB, failureCB);    
    }

    function initCB(instance) 
    {
        ge = instance;
        ge.getWindow().setVisibility(true);
        addKmlFromString(
                            '<?xml version="1.0" encoding="UTF-8"?>' +
                            '<kml xmlns="http://earth.google.com/kml/2.0">' +
                            '<Document>' +
                            '<Placemark>' +
                            '    <name>Floating placemark</name>' +
                            '        <visibility>1</visibility>' +
                            '        <description>Floats a defined distance above the ground.</description>' +
                            '   <LookAt>' +
                            '      <longitude>-122.084075</longitude>' +
                            '      <latitude>37.4220033612141</latitude>' +
                            '      <altitude>45</altitude>' +
                            '       <heading>0</heading>' +
                            '       <tilt>90</tilt>' +
                            '       <range>100</range>' +
                            '       <altitudeMode>relativeToGround</altitudeMode>' +
                            '   </LookAt>' +
                            '   <Style>' +
                            '    <IconStyle>' +
                            '      <Icon>' +
                            '       <href>https://cdn1.iconfinder.com/data/icons/future/512/drones_watching-64.png</href> ' +
                            '      </Icon>' +
                            '     </IconStyle>' +
                            '    </Style>' +
                            '    <Point>' +
                            '     <altitudeMode>relativeToGround</altitudeMode>' +
                            '      <coordinates>-122.0822035425683,37.42228990140251,50</coordinates>' +
                            '    </Point>' +
                            '</Placemark>' +
                            '    <Placemark>' +
                            '      <name>Flight Line</name>' +
                            '      <visibility>1</visibility>' +
                            '      <description>Black line (10 pixels wide), height tracks terrain</description>' +
                            '      <styleUrl>#thickBlackLine</styleUrl>' +
                            '      <LineString>' +
                            '        <tessellate>1</tessellate>' +
                            '        <altitudeMode>relativeToGround</altitudeMode>' +
                            '       <coordinates>' +
                            '         -122.0822035425683,37.42228990140251,0' +
                            '         -122,37.8,0' +
                            '       </coordinates>' +
                            '     </LineString>' +
                            '   </Placemark>' +
                            '<Placemark><name>From</name><Point><coordinates>-122.0822035425683,37.42228990140251,0</coordinates></Point></Placemark>' +
                            '<Placemark><name>To</name><Point><coordinates>-122,37.8,0</coordinates></Point></Placemark>' +
                            '</Document>' +
                            '</kml>'
                          );
    }

    function addKmlFromString(kmlString)
        {
            var kmlObject = ge.parseKml(kmlString);

            ge.getFeatures().appendChild(kmlObject);
        }

        function failureCB(errorCode) 
        {

        }



        google.setOnLoadCallback(init);
</script>

</head>
<body>
<div id="map3d" style="height: 300px; width: 400px;"></div>
</body>
</html>

请指导我。我究竟做错了什么? 非常感谢!

【问题讨论】:

    标签: html tags kml google-earth-plugin


    【解决方案1】:

    我在这里找到了答案: https://developers.google.com/earth/documentation/camera_control#flytospeed

    缩放相机

    放大和缩小由 LookAt 的范围属性和相机的高度属性控制。

    请注意,更改 LookAt 的高度属性会更改正在查看的点的高度。因为观察者的范围是相对于这个点的,所以观察者的高度也发生了变化。

    看看:

    // Get the current view.
    var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    
    // Zoom out to twice the current range.
    lookAt.setRange(lookAt.getRange() * 2.0);
    
    // Update the view in Google Earth.
    ge.getView().setAbstractView(lookAt);
    

    【讨论】:

      【解决方案2】:

      参考此链接https://developers.google.com/earth/documentation/kml

      你错过了一行ge.getView().setAbstractView(kmlObject.getAbstractView()); 将此行放在ge.getFeatures().appendChild(kmlObject); 之后

      【讨论】:

      • 谢谢,但我使用了我在这里写的答案。
      猜你喜欢
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 2015-02-19
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多