Sencha xtype методы - PullRequest
       6

Sencha xtype методы

2 голосов
/ 04 апреля 2011

У меня вопрос по xtypes.Когда я делаю это:

// 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));

Все хорошо, карта отображается.

Теперь, когда я работаю с xtypes, переменная 'map' не распознает 'setCenter'-недвижимость.Код: 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));

С этимкод, я получаю это в консоли:

Uncaught TypeError: Невозможно вызвать метод 'setCenter' из неопределенного

Я надеюсь, что кто-то может мне помочь.Заранее спасибо!

1 Ответ

3 голосов
/ 04 апреля 2011

Когда вы звоните map.map.setCenter(), объект вашей карты уже создан. При определении вашей карты с помощью xtype используется ленивая реализация.

Вы можете попробовать что-нибудь вроде:

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