ndequeker
ndequeker

Reputation: 7990

Sencha xtype methods

I have a question about xtypes. When I do this:

// map

var map = new Ext.map({
    fullscreen: true,
    getLocation: true,
    mapOptions: {
        zoom: 12
    }
});

map.map.setCenter(new google.maps.LatLng(record.attributes.record.data.latitude, record.attributes.record.data.longitude));

Everything is fine, the map is showing up.

Now, when I work with xtypes, the 'map'-variable won't recognize the 'setCenter'-property. Code: var map = { fullscreen: true, xtype: 'map', title: 'Map', getLocation: true, useCurrentLocation: true, mapOptions: { zoom: 12 } };

map.map.setCenter(new google.maps.LatLng(record.attributes.record.data.latitude, record.attributes.record.data.longitude));

With this code, I get this in the console:

Uncaught TypeError: Cannot call method 'setCenter' of undefined

I hope someone can help me. Thanks in advance!

Upvotes: 2

Views: 2931

Answers (1)

Nicodemuz
Nicodemuz

Reputation: 4114

When you are calling map.map.setCenter(), your map object has already been instantiated. By defining your map with xtype, lazy instantiation is used.

You could try somethign along the lines of:

{
    xtype: 'map',
    fullscreen: true,
    getLocation: true,
    mapOptions: {
        zoom: 12
    },
    listeners: {
        maprender: function(component, map) {
            map.setCenter( ... )
        }
    }
}

Upvotes: 3

Related Questions