所以,我使用 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;
}
});
它将映射与其元素分离并允许正确的垃圾收集。不要忘记删除对地图对象的任何其他引用(如果有)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)