一些背景。
在GE插件中,有几种方法可以使事物生动活泼。我能想到:
这是我的代码:
<script src="https://www.google.com/jsapi"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
google.load("earth", "1")
var originalUrl = 'http://localhost/original.xml'
var tourUrl = 'http://localhost/tour.xml'
var ge
$(function() {
google.earth.createInstance('ge', function(instance) {
ge = instance
google.earth.fetchKml(ge, originalUrl, function(o) {
ge.getFeatures().appendChild(o)
})
})
})
function tour(t) {
ge.getTourPlayer().setTour(t)
ge.getTourPlayer().play()
}
function fetchKml() {
google.earth.fetchKml(ge, tourUrl, tour)
}
function parseKml() {
$.get(tourUrl, function(kml) {
tour(ge.parseKml(kml))
}, 'text')
}
</script>
<div id="ge"></div>
<button onclick="fetchKml()">fetchKml</button>
<button onclick="parseKml()">parseKml</button>original.xml:
<Folder>
<Placemark><name>A</name><Point id="a"></Point></Placemark>
<Placemark><name>B</name><Point id="b"></Point></Placemark>
</Folder>和tour.xml:
<?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">
<gx:Tour>
<gx:Playlist>
<gx:FlyTo>
<gx:duration>2</gx:duration>
<LookAt><range>50</range></LookAt>
</gx:FlyTo>
<gx:AnimatedUpdate>
<gx:duration>10</gx:duration>
<Update>
<targetHref>http://localhost/original.xml</targetHref>
<Change>
<Point targetId="b"><coordinates>0.0001,0.0001,0</coordinates></Point>
</Change>
</Update>
</gx:AnimatedUpdate>
<gx:FlyTo>
<gx:duration>10</gx:duration>
<LookAt><range>50</range><latitude>0.0001</latitude><longitude>0.0001</longitude></LookAt>
</gx:FlyTo>
</gx:Playlist>
</gx:Tour>
</kml>按"fetchKml“移动B的A,相机跟随-正确。按"parseKml“只移动相机,A和B留在原地-不正确。
还有我的问题。
Q1。我的代码有什么问题吗,或者#4根本无法工作w/o服务器交互?
Q2。我在#1-#4中对你说的话有错误吗?
Q3。还有什么其他动画方法可以尝试呢?
Q4。有什么一般性建议吗?
谢谢。
发布于 2013-06-22 19:58:31
Q1 -是的。
使用parseKml将无法工作,原因很简单:创建的元素将不再引用您指定的目标href。
为了解释-当您通过fetchKml将数据加载到插件中时,每个对象的id都是唯一的,方法是将其附加到加载kml的url中。所以在你的例子中,点ID应该是http://localhost/original.xml#b
但是,您正在以文本的形式加载kml --然后将其解析到插件中--所以从插件的角度来看,数据不是来自http://localhost/original.xml的--这些对象是使用API创建的,就像调用了createPoint一样,所以点ID只是b。
这意味着<targetHref>http://localhost/original.xml</targetHref>是错误的--因为数据不是来自http://localhost/original.xml,而是来自于在某些文本上调用parseKml --插件所不知道的url。
本质上,您正在尝试更新http://localhost/original.xml#b,但该对象并不存在-因为对象不是从该URL创建的。
Q2 -是的。
"...parseKml就是不接受NetworkLinkControl。“
您不能通过NetworkLinkControl创建parseKml,因为您不能在api中创建NetworkLinkControl对象。不存在像KmlNetworkLinkControl这样的东西,所以如果解析包含NetworkLinkControl的kml文件,就不会创建对象。它与“服务器交互”无关。
第三和第四季度
至于一般的建议--简单地使用API更新对象的几何是最简单的方法之一,在executeBatch中包装对API的调用可以大大降低处理成本。
https://stackoverflow.com/questions/17230120
复制相似问题