[英]Deconstructing an Open Layers 3 map
So, I am using Open Layers 3 with Ember.js to make a dashboard, and I've made the map load dynamically but I want it do be destroyed when I leave the route, the only thing I found was map.destroy() but its for an old version of the API and there don't seem to be one in the new version. 所以,我正在使用Open Layers 3和Ember.js制作一个仪表板,我已经动态地加载了地图,但我希望它在我离开路线时被销毁,我发现的唯一一件事就是map.destroy()但是对于旧版本的API而言,新版本似乎没有。
I used the chrome debugger after going to the map page a couple of times and found that I had 29 ol.Map objects. 我在进入地图页面几次后使用了chrome调试器,发现我有29个ol.Map对象。
This is what I have so far 这就是我到目前为止所拥有的
App.MapView = Ember.View.extend({
map: null,
didInsertElement: function() {
this.map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
})
],
view: new ol.View({
center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});
},
willDestroyElement: function() {
// destroy this.map
}
});
I cant find anything in the docs about removing maps. 我无法在有关删除地图的文档中找到任何内容。
Thanks in advance. 提前致谢。
You should try to do something like this: 你应该尝试做这样的事情:
App.MapView = Ember.View.extend({
// if you are not using Ember.get/set you'd better make this "private"
_map: null,
didInsertElement: function() {
this._map = new ol.Map(...);
},
willDestroyElement: function() {
this._map.setTarget(null);
this._map = null;
}
});
It detach the map from its element and allows correct garbage collection. 它将地图与其元素分离,并允许正确的垃圾收集。 Don't forget to remove any other references to the map object too if any. 如果有的话,不要忘记删除对地图对象的任何其他引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.