mapPanel topToolbar函数不起作用

时间:2012-07-29 10:39:33

标签: extjs

我在我的应用程序中使用geoExt和ExtJs3.4!。我创建了一个mapPanel,并使用下面的代码将openlayers map添加到其中。

var mapPanel = new GeoExt.MapPanel({
        renderTo: 'gxmap',
        height: 500,
        width: 800,
        map: map,
        title: 'Map'
    });

之后我创建了extjs切换按钮

var button = new Ext.Button({
text: 'Measure Things',
enableToggle: true,
handler: function(toggled){
    if (toggled) {
        polygon.activate();
    } else {
        polygon.deactivate();
    }
}
});

当我想将此按钮添加到地图面板时,我获得了mapPanel的topPanel,之后当我想使用topPanel函数时,这些函数不起作用!

mapPanel.getTopToolbar().addButton(button);

或以下代码

topToolbar = mapPanel.getTopToolbar();
topToolbar.addButton(button);

当我看到chrome developer工具时,我看到addButton函数或topToolbar面板的其他函数的这个错误! 的错误:

uncaught typeError: cannot call method 'addButton' of undefined

为什么我不能使用topToolbar功能?
使用mapPanel.getTToolbar().addButton(button);的geoext教程的链接
Adding Buttons to map

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题。您必须在mapPanel创建之前添加此额外行:

var toolbar = new Ext.Toolbar();

在mapPanel中添加以下属性:

tbar: toolbar

您现在可以将按钮添加到工具栏中:

mapPanel.getTopToolbar().addButton(button);
相关问题