简体   繁体   中英

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 addListener methods) 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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM