javascript - Sencha Touch : Can't add Marker to Map. 请帮忙?

标签 javascript google-maps mobile sencha-touch extjs

我学习 Sencha Touch 很开心,但在我看来,有些东西应该更简单,否则就会有问题。我现在想做的是添加一个标记以在 map 上显示当前位置

我有一个带有顶部工具栏和选项卡面板的视口(viewport),第一个卡片(选项卡)上有一个 map ,我可以毫无问题地获取当前位置。我遇到的问题是创建指示我所在位置的标记。

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

代码:

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

最佳答案

centerchange 的事件监听器是我发现的最佳解决方案。由于我的 map 没有任何交互,这似乎对我有用。

代码如下:

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

关于javascript - Sencha Touch : Can't add Marker to Map. 请帮忙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6916904/

相关文章:

javascript - Phantomjs - 获取 html 页面的屏幕截图

javascript - 单击手机/平板电脑,将鼠标悬停在其他设备上(面向 future )

authentication - 使用 MPL 的 PayPal iOS 应用程序 - 身份验证失败

java - 我如何将保存的项目添加到 Flutter 中的 Collection 夹部分?

javascript - 如何避免在不同行中显示重复的数据?

android - 如何在 Google map 上绘制静态目标圆圈?

javascript - 谷歌地图地理编码和setCenter

android - 无法显示 MapView

javascript - 如何在 JavaScript 中创建模常量

javascript - 为什么我会收到此错误消息? "Uncaught Initmap is not a function"