[英]Deconstructing an Open Layers 3 map
所以,我正在使用Open Layers 3和Ember.js制作一個儀表板,我已經動態地加載了地圖,但我希望它在我離開路線時被銷毀,我發現的唯一一件事就是map.destroy()但是對於舊版本的API而言,新版本似乎沒有。
我在進入地圖頁面幾次后使用了chrome調試器,發現我有29個ol.Map對象。
這就是我到目前為止所擁有的
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
}
});
我無法在有關刪除地圖的文檔中找到任何內容。
提前致謝。
你應該嘗試做這樣的事情:
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;
}
});
它將地圖與其元素分離,並允許正確的垃圾收集。 如果有的話,不要忘記刪除對地圖對象的任何其他引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.