2011-08-04 58 views
1

解決了標記問題後,我又遇到了另一個問題。這次,在創建帶有地圖的面板後,我無法添加收聽者(使用onaddListener方法)。Sencha Touch:無法將偵聽器添加到地圖。請幫忙?

任何幫助將不勝感激。下面的代碼:

Ext.setup({ 
... 
onReady: function() { 

    var TopBar, Tabs, MapHome, Viewport, Homecard, Nearbycard, updateNearby; 

    /* 
    *  HOME 
    */ 
    var markersHome = []; 
    MapHome = new Ext.Map({ 
     id: "maphome", 
     title: 'Map', 
     useCurrentLocation: true, 
     listeners: { 
      centerchange: function(comp, map){ 
       deleteOverlays(markersHome); //defined on another file 
       addMarker(markersHome,map.center); //defined on another file 
       showOverlays(markersHome,map); //defined on another file 
      } 
     }, 
     mapOptions : { 
      mapTypeControl : false, 
      navigationControl : false, 
      streetViewControl : false, 
      backgroundColor: 'transparent', 
      disableDoubleClickZoom: true, 
      zoom: 17, 
      draggable: false, 
      keyboardShortcuts: false, 
      scrollwheel: false, 
      mapTypeId: google.maps.MapTypeId.HYBRID 
     } 
    }); 


    Homecard = new Ext.Panel({ 
     title: "home", 
     id: "homecard", 
     iconCls: "home", 
     items: [MapHome] 
    }); 

    /* 
    *  NEARBY 
    */ 
    Nearby = new Ext.List({ 
     scroll: 'vertical', 
     height: '100%', 
     styleHtml: true, 
     store: new Ext.data.Store({ 
      model: 'Places', //defined on another file 
      sorters: 'title', 
      data: [] 
     }), 
     itemTpl:['<div class="nearby-item" id="{id}">', 
        '<img alt="{title}" src="{imageUrl}" />', 
        '<h2>{title}</h2>', 
        '<p>{excerpt}</p>', 
       '</div>'] 
    }); 

    Nearbycard = new Ext.Panel({ 
     fullscreen: true, 
     iconCls: "list", 
     title: "nearby", 
     id: "nearbycard", 
     items: [Nearby] 
    }); 

    updateNearby = function() { 
     console.log('updating!'); //debug purposes 
     } 
    MapHome.on('locationupdate',updateNearby); // <-- Here is the problem 



    /* 
    *  MAIN 
    */ 

    TopBar = new Ext.Toolbar({ 
     dock: 'top', 
     xtype: "toolbar", 
     title: "<img class='titleLogo' src='css/images/logo.png' />", 
     items: [ 

      { xtype: 'spacer' }, 
      { 
       iconCls: 'settings9', 
       iconMask: true, 
       text: 'options' 
      } 
     ] 
    }); 

    Tabs = new Ext.TabPanel({ 
     id: 'tabs', 
     //fullscreen:true, 
     dock: 'bottom', 
     flex: 1, 
     tabBar: { 
      dock: 'bottom', 
      layout: { 
       pack: 'center' 
      } 
     }, 
     items: [ Homecard, Nearbycard ] 
    }); 

    Viewport = new Ext.Panel({ 
     fullscreen:true, 
     layout:{type:'vbox',align: 'stretch'}, 
     ui:'dark', 
     items: [TopBar,Tabs], 
    }); 
} 
}); 

我一直在與MapHome.on代碼行收到此錯誤:

Uncaught TypeError: Cannot read property 'element' of undefined

+0

修復它。我有一個定義變量的錯誤。上面的代碼現在是正確的。 – vascomotaborges

回答

0

我覺得應該是

MapHome.map.on(……………………); 

看看是否能工程。如果它不知道在這裏和il粘貼在你完美的代碼:)

相關問題