ter*_*reb 6 sencha-touch sencha-touch-2 leaflet
我想使用Leaflet.js API与Sencha Touch 2.3.1和leaflet.js给出此错误:
Uncaught Error: Map container not found.
Run Code Online (Sandbox Code Playgroud)
这些链接包含在index.html中
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
Run Code Online (Sandbox Code Playgroud)
这是我的主视图代码:
Ext.define('App.view.Main', {
extend: 'Ext.Container',
xtype: 'main',
requires: [
'App.view.MapView',
],
config: {
layout: 'card',
items: [
{
itemId: 'mapview',
xtype: 'mapview',
id : 'map'
}
]
}
});
Run Code Online (Sandbox Code Playgroud)
这是'App.view.MapView'代码:
Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: ['Ext.device.Geolocation'],
xtype: 'mapview',
initialize: function(){
var map = L.map('map').setView([47.36865, 8.539183], 13);
var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
map.on('click', function() {
console.log('Click-Event on map / Time: ' + Date.now());
});
},
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?请帮忙.
好吧,看来我找到了解决方案。我改变了这一行:
var map = L.map('map').setView([47.36865, 8.539183], 13);
Run Code Online (Sandbox Code Playgroud)
到
var map = L.map(this.element.dom).setView([47.36865, 8.539183], 13);
Run Code Online (Sandbox Code Playgroud)