我创建了扩展的 Ext.Panel.panel 组件,其中包含通过 openlayers 显示的地图,该组件位于 Ext.Window.window 中。但加载页面后,地图仅显示部分: http ://habrastorage.org/storage2/17f/1be/3bd/17f1be3bdc2a9765c1852d93a95ee1b8.png
Ext.define('MA.view.components.OpenlayersPanel',
{
extend: 'Ext.panel.Panel',
alias: 'widget.openlayerspanel',
multiSelect: true,
initComponent: function()
{
this.callParent(arguments);
this.on('afterrender', this.afterRender, this);
},
afterRender: function()
{
this.map = new OpenLayers.Map(this.body.dom.id);
this.layer = new OpenLayers.Layer.OSM('OSM Map');
this.fromProjection = new OpenLayers.Projection("EPSG:4326");
this.toProjection = new OpenLayers.Projection("EPSG:900913");
this.position = new OpenLayers.LonLat(75.1, 61.15).transform(this.fromProjection, this.toProjection);
this.zoom = 12;
this.map.addLayer(this.layer);
this.layer.setIsBaseLayer(true);
this.map.setCenter(this.position, this.zoom);
}
});
应用程序.js:
Ext.application(
{
requires: ['Ext.container.Viewport'],
name: 'MA',
appFolder: 'app',
controllers:
[
'Map'
],
launch: function()
{
Ext.create('Ext.window.Window',
{
layout:
{
type: 'vbox'
},
items:
[
{
xtype: 'openlayerspanel'
},
{
xtype: 'button',
text: 'Load',
}
]
}).show();
}
});
当我调整浏览器大小时,地图会刷新并正常显示。有什么办法让它工作?