Sencha touch Sencha Touch-如何从控制器重新初始化地图视图

Sencha touch Sencha Touch-如何从控制器重新初始化地图视图,sencha-touch,sencha-touch-2,leaflet,Sencha Touch,Sencha Touch 2,Leaflet,在控制器中执行特定操作后,我想重新初始化地图视图 这是我的地图视图: Ext.define("App.view.MapView", { extend: 'Ext.Container', requires: [ 'Ext.device.Geolocation', 'Ext.MessageBox' ], xtype: 'mapview', constructor: function () { this.callParent(arguments); this.elem

在控制器中执行特定操作后,我想重新初始化地图视图

这是我的地图视图:

Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: [
    'Ext.device.Geolocation',
    'Ext.MessageBox'
],
xtype: 'mapview',

constructor: function () {
    this.callParent(arguments);
    this.element.setVisibilityMode(Ext.Element.OFFSETS);
    this.on('painted', this.renderMap, this);
},

renderMap: function(){
        var me = this,
            lat = localStorage.getItem('latitude'),
            lng = localStorage.getItem('longitude'), 
            geo = [lat, lng];

        var map = L.map('map', {
            center: geo, 
            zoom: 13
        });

        var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);    

        var marker = L.marker(geo, {
            draggable: true,
            title: 'Your position'
        }).addTo(map);
}
});
然后这样称呼它:

this.getApplication().getMapCmp.reset();
但它不起作用-我得到“函数未定义”。基本上,我需要它再次初始化,就像应用程序启动时一样

请告知。

您收到的函数是未定义的消息,因为视图中未定义
reset()
函数

但是,如果要初始化MapView,则需要使用
initialize()
函数。将其添加到您的文件中:

Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: [
    'Ext.device.Geolocation',
    'Ext.MessageBox'
],
xtype: 'mapview',

constructor: function () {
    this.callParent(arguments);
    this.element.setVisibilityMode(Ext.Element.OFFSETS);
    this.on('painted', this.renderMap, this);
},

initialize: function() {
    // This function is launched each time the application starts up
}

renderMap: function(){
        var me = this,
            lat = localStorage.getItem('latitude'),
            lng = localStorage.getItem('longitude'), 
            geo = [lat, lng];

        var map = L.map('map', {
            center: geo, 
            zoom: 13
        });

        var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);    

        var marker = L.marker(geo, {
            draggable: true,
            title: 'Your position'
        }).addTo(map);
},
});
Ext.define(“App.view.MapView”{
扩展:“Ext.Container”,
要求:[
“外部设备地理位置”,
“Ext.MessageBox”
],
xtype:“地图视图”,
构造函数:函数(){
this.callParent(参数);
this.element.setVisibilityMode(Ext.element.offset);
this.on('painted',this.renderMap,this);
},
初始化:函数(){
//每次应用程序启动时都会启动此功能
}
renderMap:function(){
var me=这个,
lat=localStorage.getItem('latitude'),
lng=localStorage.getItem('longitude'),
geo=[拉丁美洲,液化天然气];
var map=L.map('map'{
中心:geo,,
缩放:13
});
var layer=L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
}).addTo(地图);
var标记=L.标记(地理{
真的,
标题:“你的职位”
}).addTo(地图);
},
});
Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: [
    'Ext.device.Geolocation',
    'Ext.MessageBox'
],
xtype: 'mapview',

constructor: function () {
    this.callParent(arguments);
    this.element.setVisibilityMode(Ext.Element.OFFSETS);
    this.on('painted', this.renderMap, this);
},

initialize: function() {
    // This function is launched each time the application starts up
}

renderMap: function(){
        var me = this,
            lat = localStorage.getItem('latitude'),
            lng = localStorage.getItem('longitude'), 
            geo = [lat, lng];

        var map = L.map('map', {
            center: geo, 
            zoom: 13
        });

        var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);    

        var marker = L.marker(geo, {
            draggable: true,
            title: 'Your position'
        }).addTo(map);
},
});