簡體   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