简体   繁体   English

使用JavaScript将XML数据加载到KML文件中

[英]Load XML data into a KML file with JavaScript

I'm trying to load information from a .xml file (located in a .kmz archive) into the description of a placemark using javascript. 我正在尝试使用javascript将.xml文件(位于.kmz存档中)中的信息加载到地标的描述中。 The goal is to display the information from the .xml file in an html table in the description. 目标是在描述中的html表中显示.xml文件中的信息。 I've gotten everything working, with the exception that I can't seem to access the .xml file from the .kml file. 我已经完成了所有工作,但我似乎无法从.kml文件访问.xml文件。 I'm trying to use an XMLHttpRequest() to load the file from the .kmz. 我正在尝试使用XMLHttpRequest()从.kmz加载文件。 It works just fine as an html file, but when i put the html/javascript into a description tag of the .kml, nothing loads at all. 它作为一个html文件工作得很好,但是当我把html / javascript放到.kml的描述标签中时,什么都没有加载。

Does anyone know if this is even possible to do? 有谁知道这是否可能吗? If so, how? 如果是这样,怎么样? If not, any other suggestions? 如果没有,还有其他建议吗?

Thanks in advance for the help! 先谢谢您的帮助!

Is this using the Google Earth API? 这是使用Google Earth API吗? If so, note that script tags, amongst others, are stripped out by default. 如果是这样,请注意默认情况下会删除脚本标记等。 You can work around this if needed as described at https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe 如果需要,您可以按照https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe中的说明解决此问题。

If this is KML being loaded into the Google Earth client, javascript is allowed (with the exception of things like alerts which bring up a browser dialog). 如果这是KML加载到Google地球客户端,则允许使用javascript(除了显示浏览器对话框的警报之外)。

However it's quite possible, for example if you are loading a separate KMZ in your XHR request, amongst a variety of other reasons, that you're getting a cross domain error (basically because you'll be loading a local file with file:// versus http://). 但是很有可能,例如,如果你在XHR请求中加载一个单独的KMZ,由于各种其他原因,你得到一个跨域错误(主要是因为你将加载一个带文件的本地文件:/ /与http://)。 To test this, I would recommend hosting the XML on a server somewhere, and trying to see if that works. 为了测试这个,我建议在某个地方的服务器上托管XML,并试着看看它是否有效。

If so, but it does not work locally, please paste a link to your KMZ, or at least paste your main KML within the KMZ, and the associated file structure within the KMZ. 如果是这样,但它在本地不起作用,请将链接粘贴到您的KMZ,或者至少将您的主要KML粘贴到KMZ中,以及KMZ中的相关文件结构。

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

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