GE plugin appears not to render completely on page refresh (late-arriving elevation data)

StackOverflow https://stackoverflow.com/questions/17948468

  •  04-06-2022
  •  | 
  •  

سؤال

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);
هل كانت مفيدة؟

المحلول

Is there something wrong with my code?

No the code is correct.

In your example you are setting the polygon ALTITUDE_RELATIVE_TO_GROUND at 100m but sometimes the the ground altitude data hasn't finished streaming when the element is drawn. This is what accounts for the differing rendering you are seeing.

Is it a bug that should be reported to Google?

Yes, I think it is a bug with how relatively positioned elements work with streamed elevation data.

I have seen a similar issue with flying to a model's relative location, see this report: https://code.google.com/p/earth-api-samples/issues/detail?id=263

I would file a new bug report and reference that one in it.

Is there a way to prevent this from happening?

I think the work-around given in that bug-report could be applicable here too. Simply set the polygons altitude to a known value and its mode to ALTITUDE_ABSOLUTE.

Failing that you can also force the terrain to redraw by calling something like the following.

function redrawTerrain() {
  var current = ge.getOptions().getTerrainExaggeration();
  ge.getOptions().setTerrainExaggeration(0);
  ge.getOptions().setTerrainExaggeration(current);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top