【问题标题】:Google Chart visualization not working in google earth popup谷歌图表可视化在谷歌地球弹出窗口中不起作用
【发布时间】:2017-01-11 04:44:11
【问题描述】:

我在 kml 文件中的弹出气球的描述标签中有用于谷歌图表可视化的 javascript 代码。该图表在浏览器中显示正常,但在 Google 地球中显示不正常。 kml 文件在 Google 地球中打开,但显示的弹出窗口没有图表,显示中缺少图表。我不知道为什么这不起作用。

它在 Google 地球中的外观如下:Google Earth Image

示例代码:

<?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'>
<Document>
<name>Chart Test</name>
<Placemark id='ABBEY'>
<Snippet maxLines='0'></Snippet>
<description>
<![CDATA[
<head>
<style type=text/css>
p {text-align:left; font-family:'Comic Sans MS'; font-size:10pt; line-height:120%; padding:0pt; margin-top:0pt;}
.center {text-align:center;}
.space {margin-top:6pt;}
</style>
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
<script type='text/javascript'>
google.charts.load('current', {packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
 ['Task', 'Hours per Day'],
 ['Work',     11],
 ['Eat',      2],
 ['Commute',  2],
 ['Watch TV', 2],
 ['Sleep',    7]
]);
var options = {
title: 'My Daily Activities',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
</head>
<div style='height:300px; width:350px; overflow:auto'>
<body>
<table colspan='1'>
<tr>
<td colspan='1' align='center'>
<h2 align='center'>Chart Test</h2>
</td>
</tr>
<tr>
<td colspan='1' align='center'>
<h2>ABBEY</h2>
</td>
</tr>
<tr>
<td colspan='1' align='center'>
<div id='piechart_3d' style='width: 150px; height: 150px;'></div>
</td>
</tr>
<tr>
<td colspan='1' align='center'>
<h3 class='center'>Chart should appear in space above</h3>
</tr>
</table>
</body>
</div>
]]>
</description>
<Point>
<coordinates>-73.059764,44.03325</coordinates>
</Point>
</Placemark>
</Document>
</kml>

之前有人问过这个问题,但没有发布答案:https://stackoverflow.com/questions/36936891/google-chart-api-not-working-inside-kml-balloon

感谢您的帮助!

【问题讨论】:

    标签: google-visualization google-earth


    【解决方案1】:

    出于安全考虑,Google 地球会删除气球描述中的所有 javascript。一种常见的解决方法是侦听地标上的单击事件(或更一般的气球打开事件),然后以编程方式使用完整内容重新创建 HtmlDivBalloon。更多详情请查看http://code.google.com/apis/earth/documentation/balloons.html#getballoonhtmlunsafe

    【讨论】:

    • 感谢您的帮助,但您发布的链接没有帮助。它只是将我带到一个页面,上面说 Google 地球 API 不再可用。过去,我使用过使用 URL 字符串创建图表的 Google Chart API,但我的理解是正在逐步淘汰,因此我需要学习使用 javascript 版本。但是,我太新手了,无法真正理解如何监听地标上的点击事件,然后以编程方式创建气球。如果您有任何其他更详细的信息来源,我将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多