Matthew,
I followed your hints to fix the issue when using dynamic billboards. I was successfully able to update 10,000 dynamic billboards (200 updates every 200 milliseconds). Before the fix the map was crashing after 10 seconds of updates. Please let me know if I missed something.
I did the following (see code below):
Entity billboard:
- Added a custom isDynamic boolean property when creating new billboard graphics to identify dynamic billboards. I’m tagging a billboard as dynamic when using image of type canvas (not for URL). The canvas are the ones my application constantly updates.
TextureAtlas class:
- Addded wrapper functions to handle the _idHash.
- Added an updateImage (imageId, image) function that is called for billboards tagged as dynamic. This function is the one that interacts with the _idHash to add indexes, check for the presence of indexes, and store new indexes. If an index is already present in the hash then that index is reused when calling the textureAtlas addImage(that, image, index);
Billboard:
- Modified the _loadImage() function to check is the billboard is dynamic. If it is dynamic the textureAtlas updateImage (imageId, image) is called, else the addImage((imageId, image) is called. Inside this function I also have a modification to add a default icon when rendering KML containing icon URLs that are not accessible (like the X icon in google Earth).
texture atlas overflow fix:
TextureAtlas class:
/global define/
define([
‘…/Core/BoundingRectangle’,
‘…/Core/Cartesian2’,
‘…/Core/createGuid’,
‘…/Core/defaultValue’,
‘…/Core/defined’,
‘…/Core/defineProperties’,
‘…/Core/destroyObject’,
‘…/Core/DeveloperError’,
‘…/Core/loadImage’,
‘…/Core/PixelFormat’,
‘…/Core/RuntimeError’,
‘…/Renderer/Framebuffer’,
‘…/Renderer/RenderState’,
‘…/Renderer/Texture’,
‘…/ThirdParty/when’
], function(
BoundingRectangle,
Cartesian2,
createGuid,
defaultValue,
defined,
defineProperties,
destroyObject,
DeveloperError,
loadImage,
PixelFormat,
RuntimeError,
Framebuffer,
RenderState,
Texture,
when) {
“use strict”;
// The atlas is made up of regions of space called nodes that contain images or child nodes.
function TextureAtlasNode(bottomLeft, topRight, childNode1, childNode2, imageIndex) {
this.bottomLeft = defaultValue(bottomLeft, Cartesian2.ZERO);
this.topRight = defaultValue(topRight, Cartesian2.ZERO);
this.childNode1 = childNode1;
this.childNode2 = childNode2;
this.imageIndex = imageIndex;
}
var defaultInitialSize = new Cartesian2(16.0, 16.0);
/**
* A TextureAtlas stores multiple images in one square texture and keeps
* track of the texture coordinates for each image. TextureAtlas is dynamic,
* meaning new images can be added at any point in time.
* Texture coordinates are subject to change if the texture atlas resizes, so it is
* important to check {@link TextureAtlas#getGUID} before using old values.