1

I'm seeing rendering differences between the first time a page is loaded and subsequent reloads (caused by pressing the browser refresh button). In the latter case, often features (such as placemarks or polygons) are rendered as if with altitudes based upon terrain elevation data that is current at the time of feature rendering but will later be updated as more granular elev data arrives -- but the rendering/altitudes for the features will not be updated.

This seems to happen on reloads, not on the initial page load. The effect is most obvious in rough terrains, where subsequently-arriving elev data can be quite different from early data.

Here's a demonstration: http://jsfiddle.net/x4PEM/1/ Note the shape of the polygon on the initial load, then press 'run' to cause a refresh. Note rendering differences.

If the feature happens to get an altitude that is below the final terrain elevation, the feature may not be rendered at all (until the user maybe causes a re-rendering by tilting, etc).

Is there something wrong with my code (which is based upon Google samples)? Is there a way to prevent this from happening (maybe an event I need to catch to delay feature rendering until elev data has been received)? Is it a bug that should be reported to Google?

(I noticed this because I've been writing code with a text editor and then press refresh on a browser to see the results; similar to pressing 'run' on jsFiddle. End-users wouldn't be doing refreshes as intensively, but still, they may press refresh.)

Here's the code:

var ge;
google.load("earth", "1");

function init() {
    google.earth.createInstance('map3d', initCB, failureCB);
}

function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);

    var lat = 37.204193;
    var lon = -112.934429;
    var dlat = 0.005;
    var dlon = 0.005;
    var alt = 100;

    var la = ge.createLookAt('');
    la.set(lat, lon, 0, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 45, 2000);
    ge.getView().setAbstractView(la);

    var polygonPlacemark = ge.createPlacemark('');
    var polygon = ge.createPolygon('');
    polygon.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
    polygonPlacemark.setGeometry(polygon);

    var outer = ge.createLinearRing('');
    outer.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
    outer.getCoordinates().pushLatLngAlt(lat + dlat, lon - dlon, alt);
    outer.getCoordinates().pushLatLngAlt(lat + dlat, lon + dlon, alt);
    outer.getCoordinates().pushLatLngAlt(lat - dlat, lon + dlon, alt);
    outer.getCoordinates().pushLatLngAlt(lat - dlat, lon - dlon, alt);
    polygon.setOuterBoundary(outer);

    polygonPlacemark.setStyleSelector(ge.createStyle(''));
    polygonPlacemark.getStyleSelector().getPolyStyle().getColor().set('ff008000');
    ge.getFeatures().appendChild(polygonPlacemark);
}

function failureCB(errorCode) {
    alert("GE init failed");
}

google.setOnLoadCallback(init);
4

1 回答 1

0

我的代码有问题吗?

不,代码是正确的。

在您的示例中,您将多边形设置ALTITUDE_RELATIVE_TO_GROUND为 100m,但有时在绘制元素时地面高度数据尚未完成流式传输。这就是您看到的不同渲染的原因。

这是一个应该报告给谷歌的错误吗?

是的,我认为相对定位的元素如何与流式高程数据一起工作是一个错误。

我在飞往模型的相对位置时看到了类似的问题,请参阅此报告:https ://code.google.com/p/earth-api-samples/issues/detail?id=263

我会提交一份新的错误报告并在其中引用该报告。

有没有办法防止这种情况发生?

我认为该错误报告中给出的解决方法也适用于此。只需将多边形高度设置为已知值,并将其模式设置为ALTITUDE_ABSOLUTE.

如果不这样做,您还可以通过调用以下内容来强制重新绘制地形。

function redrawTerrain() {
  var current = ge.getOptions().getTerrainExaggeration();
  ge.getOptions().setTerrainExaggeration(0);
  ge.getOptions().setTerrainExaggeration(current);
}
于 2013-07-31T12:28:24.877 回答