0

我们在我们的应用程序中使用带有 ExtJS3.2 的 Mapfish 工具栏。现在我们正在尝试将 ExtJS3.2 升级到 ExtJS4。但是 mapfish 不能使用 ExtJS4。因此,我们正在使用 ExtJS4 工具栏,但是为工具栏中的按钮编写的 openlayers 代码没有执行。

ExtJS4 代码为:

var extoolbar = Ext.create('Ext.toolbar.Toolbar',{
    border : true,
    width : 100,
    height : 40,
    layout : hbox
});

var btn1 = {
    xtype : 'button',
    enableToggle : true,
    tooltip : "Zoom In",
    id : 'zoominbtn',
    listeners : {
        'click' : fucntion(){
            new OpenLayers.Control.ZoomBox({
                alwaysZoom : true,
                draw : function(){
                    this.handler = new OpenLayers.Handler.Box(
                        this, {done: this.zoomBox}, {keyMask: this.keyMask});
                }
            });
        }
    }
};
extoolbar.add(btn1);

在这里,如果我们单击放大按钮控件将进入OpenLayers.Control.ZoomBox但该draw方法未执行。我的问题是:

  1. 代码有什么问题吗?
  2. 有没有其他方法可以使用 ExtJS4 接近 OpenLayers?
4

1 回答 1

1

我也在使用 MapFish,带有 Ext 3.4。

首先你有一个fucntion()而不是function():)

那么,可能是我不明白你想要做什么,但我认为 -IMAO- 这不是使用 ZoomBox 控件的好方法......你应该在创建地图时将 ZoomBox 控件添加到地图中给控件一个 id,然后使用监听器来监听切换事件,如下所示:

listeners: {
    'toggle': function(button, pressed) {
        var ctrl = map.getControl('yourid');
        if(pressed){
            // Activate the control
            ctrl.activate();
        } else {
            // Deactivate the control
            ctrl.deactivate();
        }
    }
}

这样,当您按下按钮时,您启用控件,当您再次按下它时,您将其禁用。请记住,ZoomBox 控件一旦处于活动状态,也可以通过按住 shift 始终可用

或者你也可以使用 GeoExt,这很简单,像这样

GeoExt.Action({
    map: map,
    text: "Zoom Box",
    control: new OpenLayers.Control.ZoomBox()
});

但我不知道 GeoExt 是否或如何与 Ext 4 一起使用

至于您问题的第 2 点,我很抱歉,但我无法回答,因为我没有使用 Ext 4 的经验。

于 2011-08-04T10:25:28.453 回答