繁体   English   中英

解构一个开放的图层3地图

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM