开发者

Sencha Touch: Can't add listener to Map. Please Help?

After solving my problem with the markers I got another problem. This time, I can't add a listener (using either on or addListenermethods) after creating the panel with the map.

Any help would be much appreciated. Here's the code:

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],
    });
 }
});

I keep getting this error on the line with the MapHome.on code:

Uncaught TypeError: Cannot read property 'element' of undefined


I think it should be

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

See if that works. If it doesnt lemme know here and il paste in the perfect code for you :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜