我正在尝试为 GE 插件中的点设置动画。问题是,每次我更改底层几何图形时,它似乎都会重新渲染自身,这最终会卡住插件。
var lineString = ge.createLineString(''),
placemark = ge.createPlacemark(''),
coords = lineString.getCoordinates(),
features = ge.getFeatures();
placemark.setGeometry(lineString);
features.appendChild(placemark);
myPoints.forEach(function(point) {
// google earth re-renders on every one of these calls
coords.pushLatLngAlt(point.lat, point.lng, 0);
});
// I want something explicit, like this, instead
placemark.redraw();
它不是将所有更改应用到 LineString 坐标,然后在地标上调用重新渲染方法,而是每次都会重新渲染。
我的第一个想法是进行某种类型的双缓冲。但我正在加载很多点,而且我无法承受双倍的内存使用量。
有什么办法可以解决这个问题吗?
编辑:
我尝试删除几何图形,对其进行编辑,然后将其添加回来。地标刚刚闪烁...:/
placemark.setGeometry(null);
myPoints.forEach(function(point) {
coords.pushLatLngAlt(point.lat, point.lng, 0);
});
placemark.setGeometry(lineString);
编辑:
通过使用google.earth.executeBatch,我确实获得了显着的速度提升。
google.earth.executeBatch(ge, function() {
myPoints.forEach(function(point) {
coords.pushLatLngAlt(point.lat, point.lng, 0);
});
});
最佳答案
一些想法:
- 使用 google.earth.executeBatch 最小化 javascript/插件互操作
- 使用frameend event修改几何图形的时间。
- 一种类似的技术,更多的是一种 hack,但可能是当 frameend 不够时的替代方案,是 do geometry manipulation in the
fetchKml
callback .
- 一种类似的技术,更多的是一种 hack,但可能是当 frameend 不够时的替代方案,是 do geometry manipulation in the
- 如果您要连接行字符串(或者可以预先生成多个行字符串段),请尝试使用 KmlCoordArray.push(KmlObjectBase coordOrList) 来最小化 javascript/插件互操作。而不是一次插入一个。
我看到您编辑了您的问题,说您找到了executeBatch 函数并且这有帮助。您必须在每次迭代期间插入很多点才能看到插件挂起。
关于javascript - Google 地球插件渴望重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13274865/