admin管理员组文章数量:1435859
I'm using patrick wied's heatmapjs.
I want to know how to destroy an instance and remove the canvas div created by h337.create(configObject)
function.
Example:
var config = {
container: document.getElementById('heatmapContainer'),
radius: 10
};
var config2 = {
container: document.getElementById('heatmapContainer'),
radius: 5
};
var heatmapInstance1 = h337.create(config);
var heatmapInstance2 = h337.create(config);
var heatmapInstance3 = h337.create(config2);
I want to destroy and delete canvas div only for heatmapInstance1
instance.
I'm using patrick wied's heatmapjs.
I want to know how to destroy an instance and remove the canvas div created by h337.create(configObject)
function.
Example:
var config = {
container: document.getElementById('heatmapContainer'),
radius: 10
};
var config2 = {
container: document.getElementById('heatmapContainer'),
radius: 5
};
var heatmapInstance1 = h337.create(config);
var heatmapInstance2 = h337.create(config);
var heatmapInstance3 = h337.create(config2);
I want to destroy and delete canvas div only for heatmapInstance1
instance.
3 Answers
Reset to default 8Currently there is no method to destroy a heatmapjs
instance, but we can do that manually.
First we have to remove the canvas element from DOM
and than unset or destroy the heatmapjs
instance.
Example:
//find corresponding canvas element
var canvas = heatmapInstance1._renderer.canvas;
//remove the canvas from DOM
$(canvas).remove();
//than unset the variable
heatmapInstance1 = undefined;
//or
heatmapInstance1 = null;
If you are using React ponent then you may have to do this in your ponentWillReceiveProps(newProps) when dynamically sending new data to heatmap ponent.
this.heatmap._renderer.canvas.remove()
this.heatmap = Heatmap.create({container: ReactDOM.findDOMNode(this)})
this.setData(newProps.max, newProps.data);
You can add this function to CesiumHeatmap.js and use it to clear the heatmap:
CHInstance.prototype.deleteLayer = function () {
if (CesiumHeatmap.defaults.useEntitiesIfAvailable && this._cesium.entities) {
if (this._layer) {
this._cesium.entities.remove(this._layer);
}
} else {
if (this._layer) {
this._cesium.scene.imageryLayers.remove(this._layer);
}
}
};
本文标签: javascriptHow to destroy heatmapjs instanceStack Overflow
版权声明:本文标题:javascript - How to destroy heatmap.js instance? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744420785a2605441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论