铯广告牌帆布变黑

时间:2016-10-28 22:02:56

标签: javascript canvas cesium

所以我在Cesium应用程序中动态创建和更新弹出窗口,效果很好。但是,在应用程序运行一段时间后,广告牌会变黑并保持黑色,直到我刷新页面。有没有人对如何修复这个bug有任何建议?

以下代码是我正在做的事情的基础,loadPopup()负责生成广告牌,画布作为其图像元素。当应用程序运行时,updatePopup()会同步调用,以更新billboard元素的位置。



//creates the popup first
function loadPopup(id, type, name, data) {
  viewer.entities.add({
    id : id,
    name : name,
    position : data.position,
    billboard :  {
      image : createPopupCanvas(id, type, name, data),
      verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
      scaleByDistance : new Cesium.NearFarScalar(1500, 2, 80000000, 0.25)
    }
  });  
}

//updates popup synchronously
function updatePopup(id, type, name, data) {
  var newPosition = Cesium.Cartesian3.fromDegrees(data.lon, data.lat, 99999);
  var currPopup = viewer.entities.getById(id);
  
  if (currPopup != undefined) {
    currPopup.position = newPosition;
  }
}

//creates a canvas element to display some stuff from the data table
function createPopupCanvas(id, type, name, data) {
   var canvas = document.createElement('canvas');
   var context = canvas.getContext('2d');
  
   context.fillText(data.stuff1, id, 105, 60);
   context.fillText(data.stuff2, id, 105, 70);
  
  return canvas;
}




0 个答案:

没有答案