Sencha Touch:无法将Marker添加到Map。请帮忙?

时间:2011-08-02 18:38:50

标签: javascript google-maps mobile sencha-touch extjs

我很开心学习Sencha Touch,但在我看来,有些事情应该更简单或者有些错误。我现在要做的是添加标记以显示地图上的当前位置

我有一个带顶部工具栏和一个TabPanel的视口,第一张卡片(标签)上有一张地图,我可以毫无问题地获取当前位置。我遇到的问题是标记的创建表明我在哪里。

我已经在地图和它的父容器上尝试了事件监听器,但仍然无法使其工作。也许这是一个范围问题?!任何帮助将不胜感激......

CODE:

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

    var TopBar, Tabs, MapHome, Viewport, Homecard;

    /* 
     *      HOME
     */

    MapHome = new Ext.Map({
        title: 'Map',
        useCurrentLocation: true
    });


    Homecard = new Ext.Panel({
        title: "home",
        iconCls: "home",
        items: [MapHome],
        listeners: {
            activate: function() {
                var marker = new google.maps.Marker({
                    position: MapHome.map.center,
                    title : 'testing',
                    map: MapHome.map
                });
            }
        }
    });

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

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

2 个答案:

答案 0 :(得分:2)

centerchange的事件监听器是我找到的最佳解决方案。由于我的地图没有任何互动,这似乎对我有用。

以下是代码:

Ext.setup({
fullscreen: true,
tabletStartupScreen: 'splash.png',
phoneStartupScreen: 'splash.png',
icon: 'icon.png',
glossOnIcon: true,
onReady: function() {

var refreshMap = function(themap){
// It should clear all markers first, but that is not important right now since the map has all interaction disabled
    var marker = new google.maps.Marker({
        position: themap.center,
        title : 'testing',
        map: themap
    });
}


    var TopBar, Tabs, MapHome, Viewport, Homecard;

    /* 
     *         HOME
     */

    MapHome = new Ext.Map({
        title: 'Map',
        useCurrentLocation: true,
        listeners: {
            centerchange : function(comp, map){
                refreshMap(map);
            }
       },
        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",
        iconCls: "home",
        items: [MapHome]
    });

    /*
     *         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, Waypointscard, Shopcard, Searchcard]
    });


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

答案 1 :(得分:0)

在您的地图有机会呈现到屏幕并准备就绪之前,您的activate事件将会被调用。尝试使用Map组件触发的maprender事件触发Marker代码。