首页 > 解决方案 > ol-ext 控制栏和Controller中的功能

问题描述

我有一个 extjs 应用程序,我在其中使用 ol-ext 控制栏。控制栏位于文件MyApp.js中,单击属于控制栏的按钮我想调用的函数位于相关控制器MyAppController中。在 MyApp.js 中:

var testFuction = function(){
   return this.getController().updateImages;
};

var mainbar = new ol.control.Bar();
var first = new ol.control.Button (
 {
       html: '1',
       //handler: 'updateImages',
       //reference: 'locationShowImageButton',
        handleClick: testFuction,
 });
       
//Standard Controls
mainbar.addControl (first);
mainbar.setPosition('bottom-right');
this.map.addControl(mainbar);

在 MyAppController 中:

updateImages: function (obj) {
            var self = this;
            this.getView().cleanImageLayers();
            var selectedFloors = ; //it should be the value of the  ol.control.Button, so 1
            if (this.lookupReference('locationShowImageButton').pressed) {
               .....

标签: javascriptextjssencha-touchopenlayers

解决方案


首先检查是否this.getController()MyApp.js参考MyAppController

您不能使用ol.control.Buttonlike sencha 组件。

你应该this在你的MyApp.js范围内使用。

var mainbar = new ol.control.Bar();
var me = this;
var first = new ol.control.Button (
 {
        html: '1',
        handleClick: function () {
            me.getController().updateImages();
        }
 });

//Standard Controls
mainbar.addControl (first);
mainbar.setPosition('bottom-right');
this.map.addControl(mainbar);

推荐阅读