繁体   English   中英

如何在Sencha-Touch 2中将Google Maps逻辑放在哪里? 多个标记

[英]Where do I put Google Maps logic in Sencha-Touch 2? Multiple markers

我有一个在Google Appengine上运行的Google Map。

我想通过使用(也许) Sencha Touch 2将其变成适合移动设备使用的界面。 也许我也应该知道Sencha EXT JS4 ,但我看不到他们文档中的任何地方。

我不太了解JavaScript。 这是我的“边做边学”的应用程序。

我一直在阅读Sencha Touch 2文档中的示例,但是在获得了一些带有基本html和图像的TabPanel之后,它很快就停了下来。

github上还有其他一些我想处理的Sencha Touch 2 MVC和表单示例,但第一步是重新创建我的功能图。

我已经包含了当前工作的Google Maps循环:

for(var i = 0; i < pubs.length; ++i) {
    (function (address, name, phone, price, icon, lat, lng, boing) {
        var posi = new google.maps.LatLng(lat, lng);
        if(boing == 'true') {
            var bounce = google.maps.Animation.BOUNCE;
        };
        var marker = new google.maps.Marker({
            animation: bounce,
            map: beerMap.map,
            //changed this to beerMap
            icon: icon,
            shadow: shadow,
            position: posi,
            title: name
        });
        google.maps.event.addListener(marker, 'click', function () {
            content_string = '<div id=content>' + '<div id="infoWindow">' + '</div>' + '<h2 id="pubName" class="pubName">' + name + '</h2>' + '<div id="pubAddress">' + '<p><b>' + address + '</b>' + '<div id="pubPhone" class="pubPhone">' + '<p>Phone: ' + phone + '<p>Halvliterpris: NOK <b>' + price + '</b>';
            bubble.setContent(content_string);
            bubble.open(beerMap.map, marker);
        });
    })(pubs[i], pub_name[i], pub_phone[i], beer_price[i], marker_icon[i], pub_lat[i], pub_lng[i], pub_bounce[i]);
}

./app/app.js

Ext.Loader.setConfig({
    enabled: true
});
Ext.application({
    name: 'app',
    appFolder: 'static/app',
    controllers: ['Home'],
    launch: function () {
        console.log('Ext.application ~ launch');
        Ext.create('Ext.tab.Panel', {
            fullscreen: true,
            tabBarPosition: 'bottom',
            items: [{
                title: 'Home',
                iconCls: 'home'
            }, {
                title: 'Beer',
                iconCls: 'locate',
                xtype: 'map'
            }, {
                title: 'Gigs',
                iconCls: 'star'
            }]
        });
    }
});

./app/controller/Home.js

Ext.define('app.controller.Home', {
    extend: 'Ext.app.Controller',
    views: ['HomePage'],
    init: function() {

        console.log('Home controller init method...');
    }
});

./app/view/HomePage.js

Ext.define('app.view.HomePage', {
    extend: 'Ext.Panel',
    alias: 'widget.homepage',
    config: {
        html: '<img src="http://staging.sencha.com/img/sencha.png" />'
    },
    initialize: function () {
        console.log("InitComponent for homepage");
        this.callParent();
    }
});

在演示APP中,我将标记逻辑放入了maprender方法中:

首先,控制器的init方法:

/**
  * The init method will be executed first. Here we define how this controller should behave.
  */
init: function() {
    this.control({
        'viewport' : {
            activeitemchange : 'handleItemChange'
        },
        'map' : {
            maprender : 'onGMapRender'
        }
    });
},

然后我的方法GMapRender()

/**
  * This method will be invoked after the google maps is rendered.
  * Here we will define the current user location.
  */
onGMapRender: function(comp, map) {

},

在方法GMapRender中(实际上是方法maprender),您有一个map对象,您可以在其中使用Google Maps对象做一些有趣的事情。

希望这对正确的方向有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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