在Google地球客户端中使用气球内的JavaScript

时间:2017-01-06 12:38:20

标签: kml google-earth

I've found a resource suggesting there is a method do this,但引用的链接引发了Google代码错误。有没有人有任何在气球中使用javascript的例子?

我有几个例子:

<Placemark>
    <name>Object</name>
    <description><![CDATA[<br><br><br>
        <input value="Test" onchange="this.value=this.value.toUpperCase()">
    ]]></description>
<gx:balloonVisibility>1</gx:balloonVisibility>
    <Polygon>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <outerBoundaryIs>
            <LinearRing>
                <coordinates>
                    -1.278059,53.020596,0 -1.278079,53.02062700000001,0 -1.278115,53.02065200000001,0 -1.278164,53.020667,0 -1.278219,53.02067,0 -1.278272,53.020662,0 -1.278316,53.020642,0 -1.278345,53.02061400000001,0 -1.278356,53.020582,0 -1.278346,53.020549,0 -1.278318,53.020521,0 -1.278274,53.020501,0 -1.278222,53.020491,0 -1.278167,53.020494,0 -1.278118,53.020508,0 -1.27808,53.020533,0 -1.27806,53.020563,0 -1.278059,53.020596,0 
                </coordinates>
            </LinearRing>
        </outerBoundaryIs>
    </Polygon>
</Placemark>

然而,我所能做的所有例子都不是很复杂。我无法弄清楚如何探索&#39;它要么......因为没有开发人员工具......

1 个答案:

答案 0 :(得分:0)

我在这里找到了一些信息: JavaScript In KML Ignored By Google Earth Plugin

代码:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Folder>
        <name>South Florida</name>
        <open>1</open>
        <Document>
            <name>Miami</name>
            <Style id="miami_style">
                <IconStyle>
                    <Icon>
                        <href>http://i.imgur.com/CNrRU.gif</href>
                    </Icon>
                </IconStyle>
                <BalloonStyle>
                    <text><![CDATA[<font face="Arial">$[description]</font>]]></text>
                </BalloonStyle>
            </Style>
            <Folder>
                <name>Miami</name>
                <open>1</open>
                <Placemark id="Miami">
                    <name>Miami</name>
                    <description><![CDATA[
                        <script type="text/javascript">
                            function hideImage() {
                                var image = document.getElementById("image");
                                image.style.opacity = 0;
                                image.style.MozOpacity = 0;
                                image.style.KhtmlOpacity = 0;
                                image.filter = "alpha(opacity=0)";
                            }
                        </script>
                        <button id='clicker' onclick='hideImage();'>Click Me</button>
                        <img id="image" src="http://i.imgur.com/4rhT7.png">
                    ]]></description>
                    <styleUrl>#miami_style</styleUrl>
                    <Point>
                        <coordinates>-80.22643611111111,25.788952777777777,0</coordinates>
                    </Point>
                </Placemark>
            </Folder>
        </Document>
    </Folder>
</kml>

最终它是沼泽标准HTML。但是有一些限制。

  • alert()不起作用 - 必须将所有消息写入元素。
  • VBS和其他脚本语言不起作用。 (因为它不是IE控件)
  • 范围非常有限 - 它看不到邻近地标/与之相互作用。
  • 无法获取窗口对象
  • 似乎无法创建objectURLs