我有一小段KML代码,当点击地标时显示图像,我拥有的所有图像都存储在本地,并且在使用.kml文件时它可以正常工作。 将文件压缩成.kmz后,我会在CDATA的第一行收到警告(黄色标记),覆盖我的部分文字。
它说:“此气球可能使用格式不正确的图片网址”
我的所有图片都运行正常,它们没有丢失,相对URL正确,但语法不正确。
那里的任何人都知道解决这个硬编码消息的解决方案吗?甚至更好地如何“调整”代码,所以这个警告不显示:)
我见过几个例子,说它应该有所帮助,但不幸的是,没有一个适合我的需要。
这是我看过的一些解决方案,但仍然无法正常工作。
Option 1: Fix the URLs
Your base URL is one directory down from where you thought it was, so you can simply add “../” to the beginning of each offending relative URL. This works fine in earlier versions of Google Earth as well, because older versions will look in both directories (and as a bonus, your content will render faster in older versions).
To fix the above example, we’d change:
<img src="images/image.png”>
to
<img src="../images/image.png">
Option 2: Add a <base> tag
As with any other browser, you can add a <base> tag to your HTML to set the base URL of that content. The href parameter of the <base> tag must be an absolute URL, so you’ll have to hard-code your server name and path. Adding the <base> tag to your BalloonStyle can fix all of your URLs in one go.
To fix the above example, we’d add: <base href="http://host.example.com/kmz/somelayer/"> to the BalloonStyle (or description, if we only have a few affected placemarks).
Option 3: Move the files
If you can’t change the balloon content, you can still correct it by moving the resources it points to into the correct locations. Depending on the URL, there are a couple of ways to do this. In our example, you’d move or copy the “images” folder and its contents to the KMZ archive. If the offending URL was “../files/another_image.png” (which should have been “../../files/another_image.png”), you could move or copy the files folder into the somelayer folder to fix the problem.
In many cases, though, there will be many layers all referencing the files folder, so moving the files folder into each layer folder can get tedious. If you have access to the web server configuration, you can solve this by adding an HTTP redirect from each incorrect location that redirects up a directory. You could also move the KMZ file up a directory, but this will change the URL that people must use to access your KMZ file.
答案 0 :(得分:0)
我想查看你的KML,看它是否格式正确,并在我的最后测试。