[英]How to destroy heatmap.js instance?
I'm using patrick wied's heatmapjs . 我正在使用patrick wied的heatmapjs 。 I want to know how to destroy an instance and remove the canvas div created by h337.create(configObject)
function. 我想知道如何销毁实例并删除由h337.create(configObject)
函数创建的canvas div。
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. 我想仅为heatmapInstance1
实例销毁和删除canvas div。
Currently there is no method to destroy a heatmapjs
instance, but we can do that manually. 目前没有方法可以销毁heatmapjs
实例,但我们可以手动完成。
First we have to remove the canvas element from DOM
and than unset or destroy the heatmapjs
instance. 首先,我们必须从DOM
删除canvas元素,然后取消设置或销毁heatmapjs
实例。
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 component then you may have to do this in your componentWillReceiveProps(newProps) when dynamically sending new data to heatmap component. 如果您正在使用React组件,则在将新数据动态发送到热图组件时,可能必须在componentWillReceiveProps(newProps)中执行此操作。
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: 您可以将此函数添加到CesiumHeatmap.js并使用它清除热图:
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);
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.