hello team!
In my application scenario, I need to load a batch of time-based images to create a piece of animation. To achieve this, I create and attach an image material to a polygon, which forms a packet in my czml. The following code works great for me, except one thing: there is always a white flash on the polygon when its material image is loaded for the first time. When the first animation run ends and all images are loaded, it goes smoothly without any flash in next runs.
////////////////////// code start //////////////////////////
var mike21OutputCzml = ;
var imgUrl = “/images/MIKE21-outputs/OK2_withoutBuildings_500m2Elements ####.png”;
var startTimeString = “2014-02-01-11-00”;
var st = moment(startTimeString, “YYYY-MM-DD-HH-mm”);
var loopHours = 20;
for (var i = 0; i < loopHours; i++){
var template = ‘{“id”: “ITEM-ID”,“availability”: “ITEM-AVAILABILITY”,“polygon”: {“material”:{“image”:{“image”:{“image”:“ITEM-IMAGE”}}}},“vertexPositions”: {“cartographicDegrees”: [144.8814041758, -37.7535683243, 0, 144.9064154011, -37.7535683243, 0, 144.9064154011, -37.7778272223, 0, 144.8814041758, -37.7778272223, 0]}}’;
availabilityFrom = st.format(“YYYYMMDDTHHmmss”);
curTimeString = st.add(“hours”,i==0?0:1).format(“YYYY-MM-DD-HH-mm”);
availabilityTo = st.format(“YYYYMMDDTHHmmss”);
curImgUrl = imgUrl;
curImgUrl = curImgUrl.replace("####", curTimeString);
availabilityStr = availabilityFrom+"/"+availabilityTo;
var newCZMLData = template.replace(“ITEM-ID”, rec.get(“simcode”)+"_"+i);
newCZMLData = newCZMLData.replace(“ITEM-AVAILABILITY”,availabilityStr);
newCZMLData = newCZMLData.replace(“ITEM-IMAGE”,curImgUrl);
console.log("===url: "+curImgUrl);
mike21OutputCzml.push(JSON.parse(newCZMLData));
}
var czmlDataSource = new Cesium.CzmlDataSource();
czmlDataSource.load(mike21OutputCzml, “mike21”);
//finally put it into the scene
mainViewer.dataSources.add(czmlDataSource);
mainViewer.clock.multiplier = 30*100.0;
////////////////////// code end //////////////////////////
Really wanna get rid of the annoying flash. Is there any way I can preload these images to be used in czml? I have tried the following means but the flash still exists and it seems that the images just cannot be cached in these ways.
(1) call Cesium.loadImage before the above czml code
Cesium.when.all([
Cesium.loadImage(’/images/MIKE21-outputs/OK2_withoutBuildings_500m2Elements 2014-02-01-11-00.png’),
Cesium.loadImage(’/images/MIKE21-outputs/OK2_withoutBuildings_500m2Elements 2014-02-01-12-00.png’),
Cesium.loadImage(’/images/MIKE21-outputs/OK2_withoutBuildings_500m2Elements 2014-02-01-13-00.png’)
],function(images) {
console.log("==== all images loaded");
});
(2) first create polygon primitives (with image material) and add them to the scene, then run the above czml code.
Tons of thanks in advance! Any hints or tips are greatly appreciated
Benny